Shop OBEX P1 Docs P2 Docs Learn Events
PWM Counter questions for stepper drives — Parallax Forums

PWM Counter questions for stepper drives

idbruceidbruce Posts: 6,197
edited 2010-12-14 14:31 in Propeller 1
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.
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?

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

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-12-11 13:54
    Bruce,

    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
  • idbruceidbruce Posts: 6,197
    edited 2010-12-11 21:36
    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:
    Stepper motor speed is proportional to the pulse rate. The pulse width is immaterial.

    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.
    CON
      _clkmode        = xtal1 + pll16x
      _xinfreq        = 5_000_000
     
    VAR
      Long nStepWidth
      Long nStepRate
      Long nStepCount
      Long nClockFrequencyDivisor
      Long nCounterTime
     
    PUB G251StepperDriver(nSteps, nStepPulseRateKHZ)
     
      if nStepPulseRateKHZ > 300 '300kHz maximum step rate
        abort
     
      nClockFrequencyDivisor := clkfreq/nStepPulseRateKHZ
      nClockFrequencyDivisor := nClockFrequencyDivisor/1_000
     
      ctra[30..26] := %00100 ' Configure NCO
      ctra[5..0] := 0
      frqa := 1
      dira[0]~~
     
      nStepCount := nSteps  
      nStepRate := clkfreq/nClockFrequencyDivisor ' Set up cycle and high times
      nStepWidth := clkfreq/10_000 '100 * 1 us minimum count for step duration 
      nCounterTime := cnt ' Mark counter time
     
      repeat nStepCount' Repeat PWM signal
        if nStepCount > 200
     
          'Begin Ramping - Decrease step width until 1 us minimum step duration is reached
     
          if (nStepWidth > clkfreq/1_000_000)  and (nStepCount > 200)
            nStepWidth := nStepWidth - clkfreq/10_000 'Just Guessing :)
     
          'End Ramping - Increase step width until startup speed is reached
     
          if (nStepWidth == clkfreq/1_000_000)  and (nStepCount < (nSteps - 200))
            nStepWidth := nStepWidth + clkfreq/10_000 'Just Guessing Again:)
     
          'If nStepCount is less 200 disregard ramping
     
        phsa := -nStepWidth ' Set up the step pulse width
        nCounterTime += nStepRate ' Calculate next cycle repeat
        nStepCount--
        waitcnt(nCounterTime) ' Wait for next cycle
    
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-12-11 22:51
    I think you misunderstand how a stepper motor driver works. The pulse input pin is edge-triggered. Once the pulse rises and meets the 1usec minimum hold time, it does not matter how much longer it stays up, so long as it gets back down in time to initiate a new rising edge. Each discrete pulse steps the motor one (micro)step. That's all it does. The width of the pulse does not influence the motor current or anything else. The motor current is handled by the G251's internal PWM generator as determined by the Current Set resistor.

    -Phil
  • idbruceidbruce Posts: 6,197
    edited 2010-12-12 09:06
    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
  • idbruceidbruce Posts: 6,197
    edited 2010-12-14 14:31
    Phil

    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
Sign In or Register to comment.