PWM Counter questions for stepper drives
idbruce
Posts: 6,197
Hello All
Just a few quick questions about PWM counters for stepper drives. I have a total of fifteen G251 stepper drives from Gecko Drive, which I must interface . The datasheet for this specific driver stipulates that the step pulse width must be a minimum of 1us and that the step pulse rate must be between 0 - 300kHz. After reviewing counter documentation in AN001-PropellerCountersv1.1 and PEKitLabs-v1.2, with a few simple modifications, I tested several of the drives using 1Hz25PercentDutyCycle.spin which is part of the PEKitLabs-v1.2 source code. 1Hz25PercentDutyCycle.spin is shown below without my modifications.
MHz, KHz, and clock speeds are all still very new to me, so my questions pertain to these items, as it pertains to the code above. To obtain the specified one microsecond minimum step pulse width, would it be correct to use the following equation?
Not that it is the best setting, but which setting would make the motor run the fastest, the highest kHz or the lowest kHz?
And finally, when controlling stepper motor speed, is it better to alter the step pulse width or rate?
Any information that you may provide to further my understanding of these issues will be greatly appreciated.
Bruce
Just a few quick questions about PWM counters for stepper drives. I have a total of fifteen G251 stepper drives from Gecko Drive, which I must interface . The datasheet for this specific driver stipulates that the step pulse width must be a minimum of 1us and that the step pulse rate must be between 0 - 300kHz. After reviewing counter documentation in AN001-PropellerCountersv1.1 and PEKitLabs-v1.2, with a few simple modifications, I tested several of the drives using 1Hz25PercentDutyCycle.spin which is part of the PEKitLabs-v1.2 source code. 1Hz25PercentDutyCycle.spin is shown below without my modifications.
CON _clkmode = xtal1 + pll16x ' System clock → 80 MHz _xinfreq = 5_000_000 PUB TestPwm | tc, tHa, t ctra[30..26] := %00100 ' Configure Counter A to NCO ctra[5..0] := 4 frqa := 1 dira[4]~~ tC := clkfreq ' Set up cycle and high times tHa := clkfreq/4 t := cnt ' Mark counter time repeat ' Repeat PWM signal phsa := -tHa ' Set up the pulse t += tC ' Calculate next cycle repeat waitcnt(t) ' Wait for next cycle
MHz, KHz, and clock speeds are all still very new to me, so my questions pertain to these items, as it pertains to the code above. To obtain the specified one microsecond minimum step pulse width, would it be correct to use the following equation?
tHa := clkfreq/1_000_000
Additionally, would the following equations be correct in obtaining the 0 - 300kHz step pulse rate?
tC := 0 for 0kHz
tC := clkfreq/266 for 300kHz
tC := clkfreq/400 for 200kHz
tC := clkfreq/800 for 100kHz
It is my understanding that when you divide the clock speed the result is hertz, is this correct?tC := clkfreq/266 for 300kHz
tC := clkfreq/400 for 200kHz
tC := clkfreq/800 for 100kHz
Not that it is the best setting, but which setting would make the motor run the fastest, the highest kHz or the lowest kHz?
And finally, when controlling stepper motor speed, is it better to alter the step pulse width or rate?
Any information that you may provide to further my understanding of these issues will be greatly appreciated.
Bruce
Comments
1. The 1 usec pulse width is a minimum. Therefore, even a 50% duty cycle will be acceptable. So there's no need to use a PWM technique to pulse the driver. Stepper motor speed is proportional to the pulse rate. The pulse width is immaterial.
2. You will not get anywhere near a 300KHz step rate controlling the motor from Spin. OTOH, 300KHz is extremely fast for a stepper motor, unless you're microstepping it.
3. You could get a 300KHz output directly from an NCO clock, but it would be difficult to do ramping or to control the step count that way.
4. Your best bet would be to use/write a PASM driver. There's one in the OBEX that might work for you: http://obex.parallax.com/objects/682/
-Phil
Sorry it took so long to respond.
First off, let me say thank you for responding, I truly appreciate your input. Secondly, let me say that the stepper drives have a resolution of 10 microsteps per full step, Okay, so here were my thoughts to your response. In your response you stated:
I hate to disagree, especially when I solicit for help, however, pulse rate and pulse width must both affect stepper motor speed. Widening the pulse width will definitely increase the length of time before the next step iteration. As I see it, the only downside to widening the pulse width would be that the stepper coils would be energized for a longer period of time, therefore the stepper coils would generate more heat. As for the drivers, according to the datasheet, with the driver at maximum current (coils fully energized) and at @ 50VDC (equivalent to my power supply), power dissipation should be 3.3W. As long as the motors don't get too hot, I should be able to do my ramping by widening and narrowing the pulse width. I would use an existing object, but it appears that the good drivers are written in assembly, which I have never coded. And I certainly like using code that I can fairly understand. Please see the example code below and once again, please provide any additional guidance that you deem necessary. I have also attached the datasheet for the G251 driver. The necessary specs. are on page 4.
-Phil
Let me get back to you on this post within the next day or so. It will be soon. Thanks for your input.
Bruce
You were right. I was wrong. But a new obect became of it.
Check this out my friend http://forums.parallax.com/showthread.php?127919-New-PWM-Stepper-Driver-With-Ramping