PWM ESC BLDC Motor Control
- F4br1c4t3D
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 51
- Thank you received: 1
29 Mar 2019 18:50 #129917
by F4br1c4t3D
PWM ESC BLDC Motor Control was created by F4br1c4t3D
Putting the finishing touches on a CNC conversion of a Chinese Mini Lathe and I'm scratching my head over how the pwmgen should be configured to send speed commands to an electronic speed controller to run the brushless DC motor for the spindle.
From the research I've done hobby RC ESCs usually want a 50Hz PWM signal between 1ms and 2ms. 1.5ms being neutral throttle or 0RPM, 2ms being full speed forward and 1ms full speed reverse. my maximum spindle speed after the motor has been geared down should be 2500RPM.I have an encoder set up for spindle speed feedback,which is also most likely not yet configured correctly but I need to get the motor spinning first.
I've set up my configuration files with stepconf. Inputting 50Hz for the frequency, 0 in the speed one box, 1.5 in the PWM1 box, 2500 in the speed two box and 2 in the PWM2 box. I'm assuming the units are in milliseconds here as none are expressed.
In my hal this gives me:
setp pwmgen.0.offset 1.5
setp pwmgen.0.scale 5000.0
setp pwmgen.0.pwm-freq 50.0
^These are the only values I see changing when I adjust the figures in stepconf, are there any other parameters altered by the aforementioned options in stepconf? I ask as I'm using a dummy hal file to generate the values in stepconf then transplant them to my real hal file to avoid destroying other parts of the hal that I've modified since my initial setup.
When I attempt to run the motor from gmocappy if I hit the spindle forward button the esc will beep (it appears to be wanting the throttle to be returned to neutral - a safety feature when it's being used on model aircraft so propellers don't accidentally shred you to pieces if you power up the craft with the throttle up on the transmitter by mistake.) However, stopping the spindle doesn't cause the esc to resume it's normal boot up sequence and the subsequent issuing of spindle speed commands doesn't run the spindle. It's clearly receiving PWM from the BoB though so that's something. I've had the ESC running the motor from a servo tester and it worked just fine with that so I'm guessing the problem here is with my PWM configuration in hal. Does anyone have experience using controling these RC parts with LCNC? Any help would be greatly appreciated.
From the research I've done hobby RC ESCs usually want a 50Hz PWM signal between 1ms and 2ms. 1.5ms being neutral throttle or 0RPM, 2ms being full speed forward and 1ms full speed reverse. my maximum spindle speed after the motor has been geared down should be 2500RPM.I have an encoder set up for spindle speed feedback,which is also most likely not yet configured correctly but I need to get the motor spinning first.
I've set up my configuration files with stepconf. Inputting 50Hz for the frequency, 0 in the speed one box, 1.5 in the PWM1 box, 2500 in the speed two box and 2 in the PWM2 box. I'm assuming the units are in milliseconds here as none are expressed.
In my hal this gives me:
setp pwmgen.0.offset 1.5
setp pwmgen.0.scale 5000.0
setp pwmgen.0.pwm-freq 50.0
^These are the only values I see changing when I adjust the figures in stepconf, are there any other parameters altered by the aforementioned options in stepconf? I ask as I'm using a dummy hal file to generate the values in stepconf then transplant them to my real hal file to avoid destroying other parts of the hal that I've modified since my initial setup.
When I attempt to run the motor from gmocappy if I hit the spindle forward button the esc will beep (it appears to be wanting the throttle to be returned to neutral - a safety feature when it's being used on model aircraft so propellers don't accidentally shred you to pieces if you power up the craft with the throttle up on the transmitter by mistake.) However, stopping the spindle doesn't cause the esc to resume it's normal boot up sequence and the subsequent issuing of spindle speed commands doesn't run the spindle. It's clearly receiving PWM from the BoB though so that's something. I've had the ESC running the motor from a servo tester and it worked just fine with that so I'm guessing the problem here is with my PWM configuration in hal. Does anyone have experience using controling these RC parts with LCNC? Any help would be greatly appreciated.
Please Log in or Create an account to join the conversation.
29 Mar 2019 19:02 - 29 Mar 2019 19:10 #129918
by PCW
Replied by PCW on topic PWM ESC BLDC Motor Control
As I read the PWMGen manual page, the offset is specified in duty cycle, so should be 0.075 (1.5 ms out of 20 ms)
(an offset of 1.5 would make the PWM stuck high)
(an offset of 1.5 would make the PWM stuck high)
Last edit: 29 Mar 2019 19:10 by PCW.
The following user(s) said Thank You: F4br1c4t3D
Please Log in or Create an account to join the conversation.
- F4br1c4t3D
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 51
- Thank you received: 1
29 Mar 2019 19:26 #129920
by F4br1c4t3D
Replied by F4br1c4t3D on topic PWM ESC BLDC Motor Control
OK I think this is making sense to me now. So at 50Hz the time between pulses is 20ms the duty cycle (the "on time" of each pulse?) is a value between 0 and 1. 0 being a "0ms" pulse and 1 being a 20ms pulse. So 1.5ms would be 1.5 / 20 =0.075 or 7.5% duty cycle. I'll try adjusting the offset value and see if that helps.
How does the scale factor in to all this? it's coming out of stepconf at 5000 my max speed is specified as 2500 is the scale related to the frequency somehow? the stepconf manual stated that altering the frequency from 100Hz would change other parameters but it doesn't go into detail about what changes.
How does the scale factor in to all this? it's coming out of stepconf at 5000 my max speed is specified as 2500 is the scale related to the frequency somehow? the stepconf manual stated that altering the frequency from 100Hz would change other parameters but it doesn't go into detail about what changes.
Please Log in or Create an account to join the conversation.
29 Mar 2019 19:35 - 29 Mar 2019 19:39 #129922
by PCW
Replied by PCW on topic PWM ESC BLDC Motor Control
The scale factor needs to take into account that the PWM value is only
changed +-2.5% ( 7.5% +- 2.5 % = 5% to 10%),
So if your full speed is 5000 RPM the PWM scale factor would be 200000!
EDIT
I also dont think stepconf is going to be much help with this.
Its usually much better to create a working hal/ini file set with stepconf and then
toss stepconf and use an editor for fine adjustments
changed +-2.5% ( 7.5% +- 2.5 % = 5% to 10%),
So if your full speed is 5000 RPM the PWM scale factor would be 200000!
EDIT
I also dont think stepconf is going to be much help with this.
Its usually much better to create a working hal/ini file set with stepconf and then
toss stepconf and use an editor for fine adjustments
Last edit: 29 Mar 2019 19:39 by PCW.
The following user(s) said Thank You: F4br1c4t3D
Please Log in or Create an account to join the conversation.
- F4br1c4t3D
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 51
- Thank you received: 1
29 Mar 2019 20:37 #129924
by F4br1c4t3D
Yeah, I was beginning to get that impression.
I have been doing just as you suggest since I initially set up the machine, I've made most of my edits in the Custom.hal file but one or two such as increasing the number of encoders and filters have been made in my main .hal so I've been avoiding using stepconf refine my config.
I thought playing with the values in stepconf and seeing what it output might help me understand how the configuration should work but your responses and the pwmgen manual have been a bit more useful in that regard. Many thanks for that.
My full speed is 2500 rpm so by that logic my scale should be set to 100000?
If I'm following here, it's the max speed (2500) divided by the duty cycle range between min and max speed expressed as a value between 0 and 1 (0.025)
2500 / 0.025 = 100000
I'll go and plug these values in and see what we get. Once again, thanks for the assistance.
Replied by F4br1c4t3D on topic PWM ESC BLDC Motor Control
I also dont think stepconf is going to be much help with this.
Yeah, I was beginning to get that impression.
I have been doing just as you suggest since I initially set up the machine, I've made most of my edits in the Custom.hal file but one or two such as increasing the number of encoders and filters have been made in my main .hal so I've been avoiding using stepconf refine my config.
I thought playing with the values in stepconf and seeing what it output might help me understand how the configuration should work but your responses and the pwmgen manual have been a bit more useful in that regard. Many thanks for that.
My full speed is 2500 rpm so by that logic my scale should be set to 100000?
If I'm following here, it's the max speed (2500) divided by the duty cycle range between min and max speed expressed as a value between 0 and 1 (0.025)
2500 / 0.025 = 100000
I'll go and plug these values in and see what we get. Once again, thanks for the assistance.
Please Log in or Create an account to join the conversation.
- F4br1c4t3D
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 51
- Thank you received: 1
30 Mar 2019 01:13 #129947
by F4br1c4t3D
Replied by F4br1c4t3D on topic PWM ESC BLDC Motor Control
OK I'm getting somewhere. Now when I start LinuxCNC and run the spindle forward the esc beeps, I put it in full reverse speed and it arms then when I put it in full speed forward again it spools up (albeit very slowly and in a stepped fashion - but at least I have it moving now.)
I think the ESC I have behaves differently to what I described in my OP. Since full reverse now seems to be stop and the motor still runs when 0 RPM is commanded. I'm thinking that 1ms is stop 1.5 is 1/2 throttle and 2ms is full throttle. So I need to recalculate my offset and scale?
so if 0RPM is now 1ms 1 / 20 = 0.05 for the offset
my pwm range will now be +5% dc from 1ms to 2ms
So 2500 / 0.05 = 50,000 for the scale.
I'm hoping the slow spool up is because of the soft start setting on the esc I'll have to program it again and see if I can change that. Any other reasons I could be seeing a stepped start to the motor on the LCNC side? It accelerates to a speed and holds for a second, then increases a little and holds again this repeats for a few cycles before the motor speed starts to increase smoothly. Odd.
Going to test these new settings and see how it goes.
I think the ESC I have behaves differently to what I described in my OP. Since full reverse now seems to be stop and the motor still runs when 0 RPM is commanded. I'm thinking that 1ms is stop 1.5 is 1/2 throttle and 2ms is full throttle. So I need to recalculate my offset and scale?
so if 0RPM is now 1ms 1 / 20 = 0.05 for the offset
my pwm range will now be +5% dc from 1ms to 2ms
So 2500 / 0.05 = 50,000 for the scale.
I'm hoping the slow spool up is because of the soft start setting on the esc I'll have to program it again and see if I can change that. Any other reasons I could be seeing a stepped start to the motor on the LCNC side? It accelerates to a speed and holds for a second, then increases a little and holds again this repeats for a few cycles before the motor speed starts to increase smoothly. Odd.
Going to test these new settings and see how it goes.
Please Log in or Create an account to join the conversation.
- F4br1c4t3D
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 51
- Thank you received: 1
30 Mar 2019 21:04 #129992
by F4br1c4t3D
Replied by F4br1c4t3D on topic PWM ESC BLDC Motor Control
No Joy there either the esc doesn't arm at all with those settings.
Curiously, now with the original settings that got the motor running, it now stops when I stop the spindle in gmocappy. I think I may have accidentally re-calibrated the throttle range on the esc itself. If the esc is powered up with the throttle up it enters calibration mode which I may have inadvertently done with PWM sent from LCNC. This is no doubt adding to the confusion!
I might have to hook up the servo tester again and see how that behaves. As it stands the motor will run forward but I have a very narrow range of speed M3 S1 is giving me what appears to be around ~800-1000RPM Since the scale should be linear I'm guessing this is beacuse my offset isn't right.
Does M5 stop the PWM pulse completely or should I still be getting a 1.5ms pulse for 0RPM?
Curiously, now with the original settings that got the motor running, it now stops when I stop the spindle in gmocappy. I think I may have accidentally re-calibrated the throttle range on the esc itself. If the esc is powered up with the throttle up it enters calibration mode which I may have inadvertently done with PWM sent from LCNC. This is no doubt adding to the confusion!
I might have to hook up the servo tester again and see how that behaves. As it stands the motor will run forward but I have a very narrow range of speed M3 S1 is giving me what appears to be around ~800-1000RPM Since the scale should be linear I'm guessing this is beacuse my offset isn't right.
Does M5 stop the PWM pulse completely or should I still be getting a 1.5ms pulse for 0RPM?
Please Log in or Create an account to join the conversation.
Time to create page: 0.072 seconds