KFLOP Spindle Control with PWM Converter?

Moderators: TomKerekes, dynomotion

Tim G
Posts: 38
Joined: Wed Jan 13, 2021 9:51 pm

KFLOP Spindle Control with PWM Converter?

Post by Tim G » Tue Jul 22, 2025 12:07 am

Good afternoon everybody,

I was hoping I could pick some of your brains to help me with my router. I have a custom CNC router made for me by Carl Bruce and it came setup with manual spindle speed control through the VFD, though the FOR and DCM pins in the VFD are connected to the KFLOP board and do allow the spindle to turn on and off automatically during jobs. I've been attempting to get things set up for automatic spindle speed control via gcode, but have been having a lot of trouble. My post processor is kicking out M3 and S speed commands already. I read that the KFLOP board puts out PWM spindle control signals via pins on JT6, but my Huanyang VFD requires an analog signal for speed control. My breakout board doesn't have built in PWM to analog converters, so I read that you can purchase a simple PWM to analog converter board to still be able to control it with the KFLOP board. I've purchased 3 little boards off of Amazon to play with, hoping I could get one of them to work.

Here's the link to the one I'm currently working with: https://www.amazon.com/dp/B08JGH2Y2Z?re ... title&th=1

The pins on this little board come in pairs, each with its own ground. Right now I have it wired up as follows:

PWM pin to I026 (JT6, pin 5) on the KFLOP board
GND pin to a nearby ground on the KFLOP (JT6, pin 8)

V-OUT pin to the VI pin on the VFD
GND pin to the ACM pin on the VFD

VCC pin to 12v on a nearby power supply
GND pin to the ground on the 12v power supply

Note: I've read this board might need 15v minimum input at VCC, so I have an adjustable power supply coming, but I've seen forum descriptions of people claiming it worked with a raspberry pi GRBL setup using a 12v source.

VFD Changes:
1. I moved the J1 pin in the VFD to the 1&2 pin side of the jumper for external board control instead of potentiometer control.
2. I followed a tutorial to make program changes to PD001/PD002 (both set to 1), and PD0070 (set to 0 for 0-10v control range), PD0072/PD0073 (set to 400hz and 0hz respectively, though I've heard I should change the 0hz to roughly 120hz as a minimum setting).

Note: I've also tried connecting the VCC and GND pins from the converter board to the VFD instead of the power supply, using the 10v pin on the VFD for VCC on the converter board, and the ACM pin in the VFD for GND on the converter board. Neither of these setups have worked, though the one I just mentioned here allowed the spindle to be turned on/off via M3 commands, while my current wiring (shown above) won't even allow that.

C Program Changes: Carl helped me load C program changes that should allow for spindle control via the KFLOP board, but I don't really understand enough here to know what my current set up is. We couldn't get it to work. I do recall seeing some code that was reminiscent of the SpindlePWM.c example code in the examples files though. I've attached a picture of the section that I believe was modified, though there may have been other code added elsewhere.

So far nothing has worked. I always attempt an M3 command with various speed commands (S12000, S16000, etc.) to test it each time and never get speed control. The first set of connections described resulted in the M3 command not working at all. When I changed it over to the VFD connections for source voltage described in the note above, the M3 commands worked again, but no spindle speed control. I plan to test it again with a higher input voltage when that power supply arrives to see if that could be the issues, however, I'm not sure I'm on the right track with that.

Has anyone out there gotten a CNC router using the KFLOP board to have software speed control? Would love to hear how you pulled it off:).
Attachments
Spindle Code.png

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

Re: KFLOP Spindle Control with PWM Converter?

Post by TomKerekes » Tue Jul 22, 2025 1:13 am

Hi Tim,

I think you should break things down step-by-step to get this working. Such as:

#1 - test your board: verify you can write a value to a PWM and see a corresponding voltage out of the board with a voltmeter.
#2 - Configure the S Action to call a C Program to write the value to the PWM. Verify entering S Commands controls the voltage appropriately
#3 - Connect analog signal to VFD and verify VFD responds to voltage appropriately

So start with the PWM1KHz.c example to do Step #1

HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

Tim G
Posts: 38
Joined: Wed Jan 13, 2021 9:51 pm

Re: KFLOP Spindle Control with PWM Converter?

Post by Tim G » Tue Jul 22, 2025 2:05 am

TomKerekes wrote:
Tue Jul 22, 2025 1:13 am
Hi Tim,

I think you should break things down step-by-step to get this working. Such as:

#1 - test your board: verify you can write a value to a PWM and see a corresponding voltage out of the board with a voltmeter.
#2 - Configure the S Action to call a C Program to write the value to the PWM. Verify entering S Commands controls the voltage appropriately
#3 - Connect analog signal to VFD and verify VFD responds to voltage appropriately

So start with the PWM1KHz.c example to do Step #1

HTH
Thanks, Tom! I apologize for my ignorance, but I've never tried running a C file to the KFLOP before. I tried opening Kmotion, clicking the C Programs tab, then opening that file you mentioned. I took a quick reading across the VI and ACM pins on the VFD (read 0v), then clicked the "Run" option on the C program file (the one with the double right arrows) and then took a reading again. It still read 0v. I'm hoping reading it at the VFD pins is sufficient because I haven't found a way to run the KFLOP and the converter board together without them being installed in the control box (no longer accessible with a volt meter). Those pins are tied to the converter board V-Out and GND pins though, so I'm thinking any voltage output should register at the VFD pins. Does that sound like I did things correctly? If so, I don't think it's working as wired.

As far as the 2nd step, sadly, I don't have a clue how to do that. Any chance you could point me in the right direction there?

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

Re: KFLOP Spindle Control with PWM Converter?

Post by TomKerekes » Tue Jul 22, 2025 4:31 pm

Hi Tim,

Let's do one step at a time.

Here is the example below. KFLOP's PWMs use an 8-bit counter so the PWM value is 0-255. The 128 in the program sets the duty cycle to 50% which should correspond to 5V. So yes, if you measured 0V then something isn't working. Cycle power on KFLOP to be sure nothing else is configured. Then Compile/Download/Execute the example. Using this Button:
CompileDownloadExecute.png
CompileDownloadExecute.png (388 Bytes) Viewed 22739 times

Code: Select all

#include "KMotionDef.h"

int main()
{
	SetBitDirection(26,1);  // define bit as an output
	FPGA(IO_PWMS_PRESCALE) = 65;  	// divide clock by 65 (1 KHz)
	FPGA(IO_PWMS) = 128;  			// square wave
	FPGA(IO_PWMS+1) = 1;  			// Enable
}

You might also look at KMotion's Digital Io Screen Bit 26. It should be somewhat randomly toggling on and off as the screen only updates a few times per second with a 50% probability of high or low. Changing the Duty cycle to 0 should make it always low, 255 always high. After changing the C Program you must push the button again for it to Change.

HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

Tim G
Posts: 38
Joined: Wed Jan 13, 2021 9:51 pm

Re: KFLOP Spindle Control with PWM Converter?

Post by Tim G » Tue Jul 22, 2025 7:50 pm

TomKerekes wrote:
Tue Jul 22, 2025 4:31 pm
Hi Tim,

Let's do one step at a time.

Here is the example below. KFLOP's PWMs use an 8-bit counter so the PWM value is 0-255. The 128 in the program sets the duty cycle to 50% which should correspond to 5V. So yes, if you measured 0V then something isn't working. Cycle power on KFLOP to be sure nothing else is configured. Then Compile/Download/Execute the example. Using this Button:

CompileDownloadExecute.png

Code: Select all

#include "KMotionDef.h"

int main()
{
	SetBitDirection(26,1);  // define bit as an output
	FPGA(IO_PWMS_PRESCALE) = 65;  	// divide clock by 65 (1 KHz)
	FPGA(IO_PWMS) = 128;  			// square wave
	FPGA(IO_PWMS+1) = 1;  			// Enable
}

You might also look at KMotion's Digital Io Screen Bit 26. It should be somewhat randomly toggling on and off as the screen only updates a few times per second with a 50% probability of high or low. Changing the Duty cycle to 0 should make it always low, 255 always high. After changing the C Program you must push the button again for it to Change.

HTH

Really appreciate it! Just tried it exactly as you described and was able to get the control box set up in a way that I can have it out and read the pins directly on the board. Unfortunately, no voltage detected on the V-OUT and GND pins. I even tried reading the pins directly on the KFLOP board with no luck (though I'm not sure if a multimeter can detect PWM signals or not). I do see that the Digital I/O screen shows pin 26 blinking, so I tried changing the clock to 255 and that did register as a solid checkmark in the Digital I/O screen. I took a reading again on the converter board, but it still shows 0v.

I included a picture of my setup just in case it's helpful. I do have a unique breakout board that seems to be called the "KBOT," however I can't find any literature on it. It seems to offer simple pinouts for everything though. I've been connecting to "TB6," which looks to represent the JP6 header. I was able to read continuity between pins to confirm those pins do, in fact, represent pin 5 and 8 on the KFLOP.

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

Re: KFLOP Spindle Control with PWM Converter?

Post by TomKerekes » Tue Jul 22, 2025 8:15 pm

Hi Tim,

The Digital IO Screen proves the software and PWM are working correctly. The Bit 26 checkbox is actually reading back the voltage on JP6 Pin5 so it is virtually certain that the PWM signal is actually on the pin. The KFLOP output pin is a 3.3V signal so when high should read around 3V and when low something like 0.1V. If you connect a DC Voltmeter to a switching signal what it reads can be indeterminate, but I think most meters will show the average voltage. But the first thing to test would be to set the PWM duty cycle to 255 (100% on). This will place the pin in a solid high state around 3V. With nothing connected to KFLOP use the multimeter to check JP6 pins 5 to 8. You should read 3V. Take care not to short pins with the meter probe or you may damage KFLOP. If you read 3V then repeat with it connected to your converter board and check pin 1 (DIN+) to pin2 (DIN-) at the converter board it also read around 3V. Make sure with the meter's red probe on pin1 and black on pin 2 the meter voltage is positive.

Your photo didn't show up.

I don't know anything about a KBOT board?
Regards,

Tom Kerekes
Dynomotion, Inc.

Tim G
Posts: 38
Joined: Wed Jan 13, 2021 9:51 pm

Re: KFLOP Spindle Control with PWM Converter?

Post by Tim G » Tue Jul 22, 2025 9:59 pm

TomKerekes wrote:
Tue Jul 22, 2025 8:15 pm
Hi Tim,

The Digital IO Screen proves the software and PWM are working correctly. The Bit 26 checkbox is actually reading back the voltage on JP6 Pin5 so it is virtually certain that the PWM signal is actually on the pin. The KFLOP output pin is a 3.3V signal so when high should read around 3V and when low something like 0.1V. If you connect a DC Voltmeter to a switching signal what it reads can be indeterminate, but I think most meters will show the average voltage. But the first thing to test would be to set the PWM duty cycle to 255 (100% on). This will place the pin in a solid high state around 3V. With nothing connected to KFLOP use the multimeter to check JP6 pins 5 to 8. You should read 3V. Take care not to short pins with the meter probe or you may damage KFLOP. If you read 3V then repeat with it connected to your converter board and check pin 1 (DIN+) to pin2 (DIN-) at the converter board it also read around 3V. Make sure with the meter's red probe on pin1 and black on pin 2 the meter voltage is positive.

Your photo didn't show up.

I don't know anything about a KBOT board?
Oops, looks like the file size was too big. Tried making it a smaller image size, so hopefully that worked. I figured out part of the issue! This little breakout board is mislabeled. It mixed up the labelling for the JP4 and JP6 headers, so the pinouts for those are mislabeled as well. I was able to trace down which pins truly corresponded to pins 5 and 8 for JP6, and was able to read voltages that varied based upon the clock rate I uploaded via that C file. I put it all back together, but it still doesn't work yet. At least I know the signal is being converted to a steady voltage now. It put out 10.04 volts when clocked to 255, and 5.4v when clocked to 128. The voltage was positive on the converter board pins as well.

Thanks again! What do you think I should check next?
20250722_135606 (1).jpg

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

Re: KFLOP Spindle Control with PWM Converter?

Post by TomKerekes » Tue Jul 22, 2025 11:09 pm

Hi Tim,

Good. It’s not clear what you mean it doesn’t work. What are you doing?

The next step would be to command something like 128 to the PWM. Verify with a Volt meter there really is about 5V on I guess the VI to ACM pins right at the VFD. The VFD should then run at 50% speed. If not there is something wrong with the VFD. Maybe missing an Enable, or Forward, or Reverse input? Or with the configuration.
Regards,

Tom Kerekes
Dynomotion, Inc.

Tim G
Posts: 38
Joined: Wed Jan 13, 2021 9:51 pm

Re: KFLOP Spindle Control with PWM Converter?

Post by Tim G » Wed Jul 23, 2025 12:02 am

TomKerekes wrote:
Tue Jul 22, 2025 11:09 pm
Hi Tim,

Good. It’s not clear what you mean it doesn’t work. What are you doing?

The next step would be to command something like 128 to the PWM. Verify with a Volt meter there really is about 5V on I guess the VI to ACM pins right at the VFD. The VFD should then run at 50% speed. If not there is something wrong with the VFD. Maybe missing an Enable, or Forward, or Reverse input? Or with the configuration.
I think I may have figured things out. I forgot I had another PWM converter board in there that required 0-5V output and had changed it from 0-10v to 0-5v for the speed control voltages in the VFD. This made it seem like the speed commands weren't working because every speed command was above 5v, resulting in full speed at the spindle. After changing the VFD back to 0-10v speed control voltages, I can now control the speed manually by entering an M3 S12000 or similar speed code. The varying speeds are working now, however, they're not super accurate. If I adjust the little potentiometer on the converter board so that S24000 is right at 24000 rpm, then when I try S12000, it's hovering around 13,500rpm. Not sure if there's a way to calibrate this so that the speeds are more accurate, but it does seem to be working now:). I assume that means it should work okay when I try it with a CAM file, but I haven't confirmed this yet. I have the whole control box out for testing, so I'll have to put it all back together before confirming this.

Do you know of a way I can get the lower speed commands to be a bit more accurate? Seems like that potentiometer forces me to have fairly accurate high speeds and or fairly accurate lower speeds, sacrificing accuracy quite a bit at the opposite end. Thanks again for all of the help so far!

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

Re: KFLOP Spindle Control with PWM Converter?

Post by TomKerekes » Wed Jul 23, 2025 12:17 am

Hi Tim,

Very good.

Is there an encoder on the Spindle? If so, that could be used as feedback to make the speed very accurate as well as maintain speed under load.

If not, you could make a lookup table or formula to determine the PWM as a function of desired speed.

Do you know how to use Microsoft Excel? Command like 16 different PWM settings (in 16 count increments) and measure the corresponding RPMs. Enter in Excel, plot, and ask Excel to fit a 2nd order trendline to it and see how well it fits. If it fits well, put the formula in to your Spindle program.
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply