Generate RC servo PWM signal from CNC controller motor PWM signal - Page 1
Forum section: electronics / projects

author: CambridgeMart
author_rank: Regular Contributor
timestamp: December 30, 2019, 11:54:47 pm
content: I'm playing around with a CNC3018 Pro engraver and find the spindle motor supplied to be very limiting; I'm replacing the motor with a brushless motor with a much higher speed and torque rating and an RC model aircraft electronic speed controller. The PWM output from the CNC control board is 1kHz variable from ~10% to 100% and the ESC needs a standard RC servo signal PWM signal of 1.5ms to 2.5ms at 166Hz. I've tried a couple of approaches, firstly by low pass filtering the signal then driving a 555 in PWM configuation, but it's difficult to get the range of output pulse lengths I need, mainly due to trying to run opamps in the filter from a single +5V supply.My next approach was to divide the PWM signal by six then use the resulting clock to gate the original PWM signal then stretch the pulses to a more useful length using an RC network and a Schmitt NAND gate. This circuit sort of works, but I can't get the pulses long enough reliably and the design is using 4 CMOS logic devices.Anyone have a better idea than mine or done the same thing I'm trying to do?

author: langwadt
author_rank: Super Contributor
timestamp: December 31, 2019, 12:07:06 am
content: guessing it uses GRBL, so you can change that prescaler and max/min pwm and recompile to get what you wanthttps://github.com/gnea/grbl/

author: LukeW
author_rank: Frequent Contributor
timestamp: December 31, 2019, 12:53:07 am
content: RC filter the PWM signal, and generate a triangle wave, and feed both the triangle wave and variable DC level into a comparator? Should require 3 opamps and some passives.

author: CambridgeMart
author_rank: Regular Contributor
timestamp: December 31, 2019, 12:56:42 am
content: LukeW - that's exactly what's sketched on the piece of paper on my desk right now!

author: Ian.M
author_rank: Super Contributor
timestamp: December 31, 2019, 02:06:14 am
content: If the CNC controller is to remain unmodified, it sounds like a job for a MCU with input capture to measure the input PWM pulse width and output compare to generate a jitter-free servo pulse, with the main loop running software mapping between the input and output pulse widths. Any Microchip PIC with two CCP or ECCP modules could do it fairly easily, and I suspect that many ATmega AVRs could also handle it.Another option - if there's open source firmware for the ESC you are planning to use, you could probably compile a version to accept the 1KHz PWM control signal directly.However if you don't have the embedded development background and a suitable toolchain you are already familiar with, sticking to the analog OPAMP based approach may be preferable. The analog solution is helped by the fact you don't need a great deal of accuracy - a few percent error in the spindle speed isn't an issue as long as it remains reasonably stable once set.

author: David Hess
author_rank: Super Contributor
timestamp: December 31, 2019, 02:46:06 am
content: There are a couple of tricks which will make the analog method more effective.Instead of driving a 166Hz PWM generator directly from the averaged 1kHz output, average the output of the 166Hz PWM generator and compare it to the averaged 1kHz output inside the feedback loop of an operational amplifier which drives the 166Hz PWM generator. Now accuracy of the 166Hz PWM generator is irrelevant and the operational amplifier can accurately control the relationship between the input and output with easy gain and offset adjustments.Another thing I would probably do is phase lock the 166Hz PWM to the 1000Hz PWM to eliminate jitter although this may not matter. The RC servo signal has considerable leeway in frequency so maybe just divide the 1000Hz reference by 8 to 125Hz although any integer division is practical if something closer is required.

author: CambridgeMart
author_rank: Regular Contributor
timestamp: December 31, 2019, 02:48:07 am
content: Yes, it's GRBL; I'm now looking through the source code to find out where the PWM output is set up.

author: langwadt
author_rank: Super Contributor
timestamp: December 31, 2019, 03:03:58 am
content: Quote from: CambridgeMart on December 31, 2019, 02:48:07 amhttps://github.com/gnea/grbl/blob/master/grbl/cpu_map.hyou need to set the prescaler to get the ~166Hz, it is usually not very critical something like 50-300Hz should to workThen set the max pwm and min pwm to match the 1.5/2.5ms

author: Benta
author_rank: Super Contributor
timestamp: December 31, 2019, 05:24:59 pm
content: I wonder a bit about your specs.The RC servo systems I know use a 20 ms (50 Hz) period with 1...2 ms pulses, 1.5 ms being neutral.Is this a different system?

author: Ian.M
author_rank: Super Contributor
timestamp: January 01, 2020, 01:10:24 am
content: Although the classic Futaba servo signal is as you describe, modern high performance servos (and servo input ESCs) commonly accept a faster pulse repetition rate to reduce the response lag.

author: TheSteve
author_rank: Unknown
timestamp: January 01, 2020, 02:10:11 am
content: What processor does your ESC have, you might want to look into flashing it with BLHeli if it is supported which would then allow you to drive the ESC input with the regular PWM(assuming the correct logic levels). You can also convert the PWM to PPM with a "brushless converter". This was done in RC helicopters all the time 5-10 years ago when people wanted to install a brushless ESC but only had the regular PWM motor output to drive the ESC. The converters I used were based on an Atmel tiny13v processor.

author: Benta
author_rank: Super Contributor
timestamp: January 01, 2020, 12:08:35 pm
content: Quote from: Ian.M on January 01, 2020, 01:10:24 amAh. Thank you for clarifying.

author: CambridgeMart
author_rank: Regular Contributor
timestamp: January 02, 2020, 10:28:59 pm
content: Cheers! After a couple of false starts due to the slightly confusing compilation process for GRBL, I've been able to get a frame length of 16ms with a pulse width of between 1.6 and 2.6ms. I'm in the process of hooking up the ESC to ensure I'm able to initialise it with GRBL.Regarding the 166ms frame length I mentioned, that comes from the old analogue RC systems that supported 6 or more channels; of course with digital RC gear, the pulse train is generated in the receiver so the frame rate can be higher and support many more channels.

author: CambridgeMart
author_rank: Regular Contributor
timestamp: January 12, 2020, 09:18:50 pm
content: For future reference, I found setting the prescaler to 128 to give a period of just over 2ms worked best, giving me the maximum resolution in pulse width. I can now use about 1/2 of the scale available within grbl or roughly 120 steps in the speed control ramp. I may benefit from rewriting the code in the ESC which is running a 32 bit ARM processor to be able to get a wider control range, but that's for another day.