× Forum Header

PWM not quite working

More
02 Nov 2011 21:46 #14531 by andypugh
Replied by andypugh on topic Re:PWM not quite working
jpka wrote:

But after Wizard finishes, PWM output (i set it at pin 2) not work: This pin only now act as On-Off switch.


The HAL looks correct. What do you have connected to the PWM output?

Q3 (complex): There is common standard method and timing of PWM control exists for wide class of Electronic Speed Control (ESC) taken from radio-controlled toys world, and these ESCs used by some CNC DIYers for spindle motors. It all uses pulses like 1 ms = full reverse speed, 1.5 ms = stop, 2 ms = full forward speed. [/quote]

You can do that with PWMgen, though it is not ideal. wiki.linuxcnc.org/emcinfo.pl?RC_Servo_Test

Please Log in or Create an account to join the conversation.

More
03 Nov 2011 10:18 #14537 by jpka
Replied by jpka on topic Re:PWM not quite working
Hi!
It was my misuse of Axis GUI, i'm very sorry. I should never touch 'Spindle Override' slider, after which i get strange behaviour. But if i don't touch it, PWM is well controlled from both '+' and '-' buttons from GUI, as well as via telnet and MDI mode. So Stepconf Wizard not contain an error.
But...
I found that i can't fine tune pulse width. :-( When i set duty cycle range from 0.2 to 0.8 (default), it is looks to be well controlled (but not useable by RC car ESC). But when i try to set in in 0.075 to 0.1 range, i get pulse width steps change which is not precise enough. I try to change 'setp pwmgen.0.dither-pwm true', when it's 'true' it is helpful to smooth the integral long-term duty cycle (which can be measured also as output DC voltage), but not affect pulse witdh change step.
In other words, it looks that main clock frequency of the PWM generator is too low.
Can it be as high as at least 20 kHz? Then i can get i hope ten different pulse width in range 1.5 to 2 ms, i.e. i need 1.5, 1.55, 1.6, ..., 2.0 ms.
Thank you very much!
:-)

Please Log in or Create an account to join the conversation.

More
03 Nov 2011 10:25 #14539 by jpka
Replied by jpka on topic Re:PWM not quite working

wiki.linuxcnc.org/emcinfo.pl?RC_Servo_Test

This example contains some timings like
loadrt threads name1=fast period1=10000 name2=slow period2=1000000 # fast period of
    # 10000 gives 1 degree per period, or 1 degree resolution, but many PC's may
    # crash with this setting. 20000 gives 2 degrees per fast period, or 2 degree resolution.
...but it looks that, if i use it, then other than PWM stops to work in EMC?...

Please Log in or Create an account to join the conversation.

More
03 Nov 2011 10:50 #14540 by andypugh
Replied by andypugh on topic Re:PWM not quite working
jpka wrote:

In other words, it looks that main clock frequency of the PWM generator is too low.
Can it be as high as at least 20 kHz?


That depends on your PC. if you have a base_period of 25,000nS then the PWM base frequency is 40kHz, so you can get the resolution you want.

What base period do you have (it is in your INI file) and what is your latency test result?

If you want a 1% resolution in 0.5mS pulse width then I think you need 200kHz, and you are never going to get that with software step generation.
A 16-bit hardware PWM should have no problems, you get 15nS resolution on a 1mS base frequency. You could use a Mesa card (but they cost money) or perhaps set up a microcontroller (an Arduino is easy to use) which measures an incoming 0-100% duty cycle PWM and outputs a 0-0.2% duty cycle.

Please Log in or Create an account to join the conversation.

More
03 Nov 2011 16:20 - 03 Nov 2011 16:21 #14554 by jpka
Replied by jpka on topic Re:PWM not quite working
So i now understand why people uses microcontroller here, instead of cheap DIY-like glueless connect :-)

What base period do you have (it is in your INI file) and what is your latency test result?

Max jitter, ns, Servo thread: ~9000; Base thread: ~7000.

What base period do you have (it is in your INI file)

BASE_PERIOD = 100000
SERVO_PERIOD = 1000000

I also set 'Base period maximum jitter' in StepconfWizard to 10K instead of default 15K. (This lead to very rare 'unexpected realtime problems')
So i get some useful results. While step tune is still too coarse, hopefully my aircraft ESC have ability to use entire 1...2 mS range to drive in only one direction, in compare to 1.5...2mS default / typical, but i think it is quite non-standard. (maybe it standard for aircraft but not car ESCs, because aircrafts never use reverse :P )
(my esc is 'TUR 150A Brushless Motor Speed Controller RC ESC BEC' from Ebay). It is gluelessly connects to LPT port. So this setup can be useful in real life.
My PWM settings are:
PWM Rate  100
Speed1 0
Speed2 1000
PWM1 0.1
PWM2 0.2
and removed 'setp pwmgen.0.dither-pwm true' from .hal file.
I also attach waveforms taken from Xoscope via line input sound card directly connected to PWM input of ESC. At left is EMC out, at right is signal taken from small RC car.
Note the overrun pulse lengths which occurs if i press '+' spindle speed in Axis GUI more than 10 times.

Hope it helps someone who try to use brushless motor! :-)

You could use a Mesa card (but they cost money) or perhaps set up a microcontroller

I try to use in future some ATtiny's i have.
Attachments:
Last edit: 03 Nov 2011 16:21 by jpka. Reason: add image

Please Log in or Create an account to join the conversation.

More
28 Feb 2012 22:00 #18186 by dieselpilot
Did anyone get this to work with an RC ESC? I'm trying to set one up and am not sure what goes where.

I added this to the HAL file
loadrt pwmgen output_type=0
addf pwmgen.update servo-thread
addf pwmgen.make-pulses base-thread
net spindle-cmd <= motion.spindle-speed-out => pwmgen.0.value
net spindle-enable <= motion.spindle-on => pwmgen.0.enable
net spindle-pwm <= pwmgen.0.pwm
setp  pwmgen.0.min-dc 0.06 #0.0625=1.25ms/20ms frame (Castle Creations ESC fixed endpoint off value)
setp  pwmgen.0.max-dc 0.091 #0.091=1.8ms/20ms frame (Castle Creations ESC fixed endpoint on value)
setp pwmgen.0.pwm-freq 50.0
setp pwmgen.0.scale 30000.0
setp pwmgen.0.offset 0.0
setp parport.1.pin-01-out-invert 1
net spindle-pwm => parport.1.pin-08-out

This is on my 2.2.8 machine. This gives me the expected 1-2ms pulse range required by the RC hobby ESC (Electronic Speed Control). The problem is with scaling. It gives me a nice proportional increase in pulse width, except it reaches full pulse width at S3000, not the expcted S30000. I could actually live with this if I remember to program my spindle speed at 1/10th the required value. I really only will operate at 10-30kRPM. It's probably not linear,but I didn't check. Actually, thinking it over this is how the scaling is designed to work. Too bad the scale can't be applied between the pwm limits.

I still need to initialize the ESC manually by turning it on in Axis GUI. It looks like it's possible to just leave pwngen running all the time? other wise I was thinking about using spindle soft start to pass through the initializing PWM range. The tip from another thread doesn't give the desired result. It gives an error saying the axis pin is already assigned when it gets to initailizing the axis.

Greg

Please Log in or Create an account to join the conversation.

More
29 Feb 2012 14:32 #18204 by jpka
Replied by jpka on topic Re:PWM not quite working
Hi! Maybe you can try to play with 'Speed2 (1000)' parameter in Stepconf Wizard, it exist in PWM setting of it, to obtain correct scaling.

Please Log in or Create an account to join the conversation.

More
29 Feb 2012 15:05 #18206 by dieselpilot
I'm fairly certain "Speed 2" defines pwmgen.0.scale. What does "Speed 1" look like in the HAL file?

In the Hal manual it says PWM = (value/scale)+offset. that is (commanded RPM / maximum RPM)+offset in ms. Then the PWM limits are applied. So in my case 3,000/30,000=0.1, and 0.1 is the ~maximum pulse width available. If the available PWM range was scaled, that would be great. Of course, a $35 gadget gets around this, but money is tight. Here's my spindle. I have plenty of RC controllers so it would be nice to use one if possible. I hope to actually test it on the machine today.

Greg

Please Log in or Create an account to join the conversation.

More
26 Apr 2012 12:55 #19554 by CptanPanic
Replied by CptanPanic on topic Re:PWM not quite working
dieselpilot wrote:

Did anyone get this to work with an RC ESC? I'm trying to set one up and am not sure what goes where.

Greg


Did you ever get the RC ESC to work? Can you post your final config?

Please Log in or Create an account to join the conversation.

More
26 Apr 2012 15:16 #19557 by dieselpilot
I'm still running the settings I posted last. EMC is set up for running industrial PWM signals using the entire duty cycle, not such a small range that RC gear uses. I'm still looking for a cheap industrial control to replace my RC ESC with. In the mean time I run the RC controller basically as an on-off switch.

Greg

Please Log in or Create an account to join the conversation.

Time to create page: 0.176 seconds
Powered by Kunena Forum