Enabling PWM for spindle control on K2CNC

Moderators: TomKerekes, dynomotion

amowry
Posts: 51
Joined: Fri Jan 26, 2018 1:00 am

Enabling PWM for spindle control on K2CNC

Post by amowry » Wed Jul 01, 2020 6:26 pm

I'm trying to add spindle speed control to my K2CNC. I've read the lengthy thread about this on CNCZone, though my K2 is an earlier one with a different board-- I think it was one of their first ones that used KFLOP, and there's no documentation whatsoever.

I'm using the attached C program from K2, which seems to run correctly and appears to enable PWM on pin 33.

I traced pin 33 from KFLOP, and on K2's custom board it runs through an optocoupler, then a MOSFET, to a (unlabeled) connector. I assume that this means that they are just outputting PWM rather than an analog voltage, which is okay if I can get it to work.

In the digital I/O display in KMotion, pin 33 is enabled as an output, and if I set the spindle speed in KMotionCNC to the minimum (S0) the state on the Digital I/O changes to ON. If I set the spindle speed to max (S18000), the state changes to OFF.

This all seems correct, however, I'm not able to measure any voltage on the output of the K2 board or on pin 33 itself on KFLOP using a digital multimeter. I assume that I should be able to measure a voltage on the pin based on the PWM value, correct?

Thanks!
Attachments
K2_SpindlePWM.c
(688 Bytes) Downloaded 131 times

User avatar
TomKerekes
Posts: 2677
Joined: Mon Dec 04, 2017 1:49 am

Re: Enabling PWM for spindle control on K2CNC

Post by TomKerekes » Wed Jul 01, 2020 7:06 pm

Hi amowry,
This all seems correct, however, I'm not able to measure any voltage on the output of the K2 board or on pin 33 itself on KFLOP using a digital multimeter. I assume that I should be able to measure a voltage on the pin based on the PWM value, correct?
PWM 7 is actually IO Bit 33 which is KFLOP JP6 Pin 14. I assume that is what you meant.

KMotion's digital IO Screen requests KFLOP to read the actual state of KFLOP's inputs to display on the screen. So it would be very unusual that the Digital IO Screen bit goes on and off yet you don't ever measure any voltage on KFLOP JP6 Pin 14. Are you sure you measured correctly relative to a KFLOP GND?
Regards,

Tom Kerekes
Dynomotion, Inc.

amowry
Posts: 51
Joined: Fri Jan 26, 2018 1:00 am

Re: Enabling PWM for spindle control on K2CNC

Post by amowry » Wed Jul 01, 2020 8:29 pm

Ah, I thought I was reading pin 14 but I had it backwards and was reading 13, the one across from it. The PWM on KFLOP is working correctly.

I haven't figured out what K2, did, though, as their output seems to be 0V for zero PWM and 24V for all other PWM values... I guess I'll investigate further.

By the way, today I finally got up the nerve to upgrade to the newest KMotion after years of worrying that I would mess up my K2 setup. It all went as smoothly as could be. I believe on my K2 (control board rev. 3.5) they flashed the main driver C program to thread 6 and had that run at startup. There doesn't seem to be a need to flash anything else to get me back to my original state. If anyone with this rev. of K2 needs help upgrading or reviving an ailing machine, I'm happy to tell them what I did.

User avatar
TomKerekes
Posts: 2677
Joined: Mon Dec 04, 2017 1:49 am

Re: Enabling PWM for spindle control on K2CNC

Post by TomKerekes » Wed Jul 01, 2020 9:50 pm

Hi amowry,
I haven't figured out what K2, did, though, as their output seems to be 0V for zero PWM and 24V for all other PWM values... I guess I'll investigate further.
I would guess they are just switching the 24V. It might be your meter showing 24V regardless of any duty cycle. You might try adding an RC filter. It might also be isolated so you would need to be referencing to the proper ground.

Thanks for sharing and the offer. The next K2CNC guy that comes to me I'll send to you :)
Regards,

Tom Kerekes
Dynomotion, Inc.

amowry
Posts: 51
Joined: Fri Jan 26, 2018 1:00 am

Re: Enabling PWM for spindle control on K2CNC

Post by amowry » Wed Jul 01, 2020 10:00 pm

Thanks-- I think I'll just use the PWM directly from KFLOP and bypass the K2 board. I'm using it for a laser that has an opto-coupled TTL input, so I think it should work fine.

amowry
Posts: 51
Joined: Fri Jan 26, 2018 1:00 am

Re: Enabling PWM for spindle control on K2CNC

Post by amowry » Wed Jul 01, 2020 10:12 pm

One more question-- can I use the DAC control in the Tool Setup screen to control the KFLOP PWM even though I don't have a KAnalog attached? If so, is there somewhere that lists the corresponding KFLOP bits for DAC 0-7?

User avatar
TomKerekes
Posts: 2677
Joined: Mon Dec 04, 2017 1:49 am

Re: Enabling PWM for spindle control on K2CNC

Post by TomKerekes » Wed Jul 01, 2020 11:05 pm

No. You must use a C Program something like what you posted earlier.
Regards,

Tom Kerekes
Dynomotion, Inc.

amowry
Posts: 51
Joined: Fri Jan 26, 2018 1:00 am

Re: Enabling PWM for spindle control on K2CNC

Post by amowry » Wed Jul 01, 2020 11:17 pm

Okay, no problem. Thanks!

amowry
Posts: 51
Joined: Fri Jan 26, 2018 1:00 am

Re: Enabling PWM for spindle control on K2CNC

Post by amowry » Fri Jul 03, 2020 3:20 pm

Tom, if I wanted to make the PWM occur as fast as possible (say for grayscale laser engraving), would it be better to flash the C program to KFLOP? Or, does that just increase the speed the first time the program is run after powering on the machine? Or is there a better way to make the PWM occur synchronously, like you can with an I/O bit using M codes?

User avatar
TomKerekes
Posts: 2677
Joined: Mon Dec 04, 2017 1:49 am

Re: Enabling PWM for spindle control on K2CNC

Post by TomKerekes » Fri Jul 03, 2020 5:02 pm

Hi amowry,

I can't think of a simple way to control PWM synchronously.

MCodes configured with an Execute Action and no file name will re-execute an existing Program within a Thread after downloading any P Q R Parameter which should be quite fast (typically several milliseconds but at the mercy of Windows). Motion will still be flushed, completed, and stopped beforehand, so that probably isn't what you desire. Programs can either be Flashed into the Thread or Initially loaded into the Thread by a different MCode or other Action.

You might use a dummy axis, ie. Z to be commanded where a looping program in KFLOP would monitor the Commanded Z Destination and output a function of it to the PWM. Sudden changes in Z might cause the XY feed rates to change so I'm not sure how well that would work. Maybe an angular axis like A set with very high Velocity and Acceleration might work best.

Will you be raster scanning the image? If so, probably the best approach would be to download the entire image, or possibly individual raster lines, then have a real-time program in KFLOP monitor the XY speed and position and control the PWM power in real time. For this a small PC App would be needed to download the data to KFLOP's 8MB gather buffer. An MCode could be configured to execute the App with possibly a passed P Parameter to inform the App which raster line to download.

Can you provide more details on your process and requirements? Speeds? Resolution?
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply