Shop OBEX P1 Docs P2 Docs Learn Events
PWM stepper motor driver — Parallax Forums

PWM stepper motor driver

micronewbmicronewb Posts: 20
edited 2010-06-17 17:40 in Propeller 1
I am working on running some stepper motors for a walker and I am interfacing with a microstep motor driver. The only problem I am having is I am losing my PWM signal at 28Khz. I am setup on the oscilloscope and the signal drops out higher than that frequency. I have tried writing a spin version using waitcnt and have tried the pwmx8 object. Any ideas why this is happening and how i can increase the frequency, I really need a signal up to at least 35 Khz. Thanks in advance for any help!

Comments

  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-06-01 15:33
    You should probably include some more details of your circuit design. For example, does this dropout occur only when the Propeller is connected to your motor or does it happen even when the motor driver is disconnected from your Prop? What stands between the Prop and motor, what sort of driver? A schematic would be most helpful.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-06-01 15:44
    Ditto. There's no inherent reason why a Propeller can't do PWM above 28KHz. Without further information about your circuitry, driver, and code, it's impossible to guess why it doesn't work.
  • micronewbmicronewb Posts: 20
    edited 2010-06-01 15:45
    Right now I have the motor controller disconnected from the prop and am just viewing the signal on the I/O pin I am going to use. I have connected the motor controller and the signal quits at the same point as when it is not connected. I know you asked for a diagram, but right now I can't even get a frequency higher than 28 kHz without anything connected. Just to answer some of your other questions the motor controller is the US Digital MD1, and I can drive the stepper up to the 28 kHz, and I know the motor controller can go higher because I have pushed a much higher frequency signal with a commercial product that ran fine, so I am pretty confident if I can get the propeller to output the signal with a high enough frequency I can make the motor controller work.
  • micronewbmicronewb Posts: 20
    edited 2010-06-01 16:13
    Another update: I wrote a simple spin code that sets a pin to output and then triggers high and low without a pause. The fastest the chip will run is around 67 kHz. By the time I add a few lines of code to control my output this isn't unreasonable to see the drop in frequency. Is this a hardware limitation?
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-06-01 17:36
    micronewb said...
    Another update: I wrote a simple spin code that sets a pin to output and then triggers high and low without a pause. The fastest the chip will run is around 67 kHz. By the time I add a few lines of code to control my output this isn't unreasonable to see the drop in frequency. Is this a hardware limitation?

    Do you have the external 5 MHz crystal hooked up properly? Is your clock phase-locked loop set properly?

    In your CON section you should have:

    
    _clkmode = xtal1 + pll16x
    _xinfreq   = 5_000_000
    
    
    

    Post Edited (ElectricAye) : 6/1/2010 5:42:24 PM GMT
  • micronewbmicronewb Posts: 20
    edited 2010-06-01 18:00
    i'm actually using the 6.25 crystal but yes this is what the con block looks like:

    CON
    _clkmode = xtal1 + pll16x
    _xinfreq = 6_250_000
  • TimmooreTimmoore Posts: 1,031
    edited 2010-06-01 18:03
    You could use one of the objects in obex that use pasm for pwm generation e.g. pwm_32_v2 from beau, is one I use.
  • micronewbmicronewb Posts: 20
    edited 2010-06-01 18:30
    Does his object only take integer values for the timeon and timeoff? If so I need more control over the frequency than integer values are giving.
  • TimmooreTimmoore Posts: 1,031
    edited 2010-06-01 18:43
    The time is in multiples of the resolution 8.15us, that gives an upper Hz of ~61KHz unless you modify the object, it supports 32 pwm outputs, reducing that no will increase the resolution. though the higher the speed the less effective resolution you have over the pwm signal.
    Another option is phil did an object that used the vga hardware to generate pwm. If I remember correctly it could do ~80KHz with 8bits of resolution, it is also in obex.
  • StefanL38StefanL38 Posts: 2,292
    edited 2010-06-02 19:37
    you are right with a small loop in SPIN

    like this

    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    PUB Main
      dira[noparse][[/noparse]15] := 1
    
      repeat
        !outa[noparse][[/noparse]15]
    
    



    I get around 43 kHz

    not much commands left to stay above 35kHz

    So if you want to do 35kHz the signal has to be generated in PASM

    Is your steppermotor continoius rotation and it is NOT important if you loose some steps?

    Or do you need to control it and calculate with every single microstep ?


    How about attaching your code to a posting as a propellertool archive to make sure that all files needed are included
    and then let forum members take a look at your code and test it on theier propeller-chips?

    It could be some really dumb detail but how should we know without looking into the code?

    best regards

    Stefan

    Post Edited (StefanL38) : 6/2/2010 7:55:58 PM GMT
  • micronewbmicronewb Posts: 20
    edited 2010-06-02 19:53
    I got a response back from Dave and he said my code was trying to execute faster than the spin language can handle, so I am going to rewrite the routine in assembly and if that doesn't do the trick I will definitely post my code back...I might anyway i'm not the best assembly programmer [noparse]:)[/noparse] Thanks for the help everyone.
  • robotdiggrobotdigg Posts: 1
    edited 2010-06-10 02:15
    That depends on stepper motors
    28KZ or 32KZ is a division. At this time the current is highest, as well the Back-EMF. Maybe surpass your motor's rated.
  • micronewbmicronewb Posts: 20
    edited 2010-06-17 12:09
    Hey everybody,

    Turns out assembly solves all the problems. I can get my pwm signal up to 2.8 Mhz now. I lose resolution quickly after 2.0 Mhz as expected, but thanks again for the suggestions.

    Gavin.
  • Zap-oZap-o Posts: 452
    edited 2010-06-17 16:45
    Where is some code I would like to learn from the *** code. I need to run steppers at times and I cant get them to go any faster either..
  • micronewbmicronewb Posts: 20
    edited 2010-06-17 17:40
    Zap-O,

    My only warning is we run through a motor driver currently so this will strictly give you a PWM signal. I don't take care of the stepper phases in this program, but if this is what your looking for have at it.
Sign In or Register to comment.