Shop OBEX P1 Docs P2 Docs Learn Events
Second attempt at stepper motor driver — Parallax Forums

Second attempt at stepper motor driver

BtussBtuss Posts: 20
edited 2021-02-11 00:42 in Propeller 2

It occurred to me that the desired s- curve motion profile resembles a sine wave. This driver attempts to utilize that fact. I am mapping the number of steps (say 0- 5000) to degrees (0-360), calculating the cosine and scaling it by the desired velocity. (qrotate in the cordic solver)
The time delay between steps = Clock frequency / velocity at step
Please see the attached pdf.

on a side note.
On January 25, 2021 I submitted my first version stepper driver following the link on the Github site.
Method 3 - Non-Git User
Email your suggestions or contributions (archived/zipped up if necessary) to Parallax Developer with a clear explanation of what is included.
I have never submitted an object before.
After I emailed my project I heard nothing. No confirmation. No thanks but no thanks. nothing
I realize you are all busy releasing a major new product but it was kind of disheartening.

edit - I just posted an updated version. I realized short moves could have very high acceleration values. This fixes that.

Comments

  • interpolate - yes it will output a single step, and it works out that at very low speeds there is little to no ramp up or down.
    Try it and let me know what you think.

  • @interpolate said:
    steppers are in there prime at low speeds...they give max torque at that range. how fast can u get? its gonna count!

    im sorry for picking ur stuff apart but now i need to know whats ur output from ur prop...2 wire(step and direction) or four wire (four switch mode)?

    Please take a look at the enclosed PDF. I have two drivers. One with step and direction outputs and one with cw, ccw clock outputs. I realize steppers can supply the most torque at low speed and that torque falls off rapidly at higher speeds. That said using the circuit I show in the PDF and running in half step mode with no load i can achieve 50,000 steps/sec with no loss of steps.

  • Ken GraceyKen Gracey Posts: 7,386
    edited 2021-02-10 05:03

    Hello @Btuss -
    Sorry to hear that the object was submitted to developer@parallax.com and you received no response. This must've been an oversight on our part; I don't receive that e-mail address but it goes to @"Jeff Martin", who has been busy with Propeller Tool improvements since December. So, we need to get this posted!
    We have two places for it: (a) on our OBEX, and (b) as a Quick Byte. @"Jeff Martin" takes care of OBEX and I've been handling Quick Bytes. Many objects are in both places.

    I'll get with Jeff and we'll see the zip is put on OBEX. I'll also wire up my stepper and driver to try the object out for appearance as a Quick Byte.

    Thank you for your work here, and sorry that you got caught in our e-mail blender.

    Sincerely,

    Ken Gracey

  • @"Ken Gracey" said:
    Hello @Btuss -
    Sorry to hear that the object was submitted to developer@parallax.com and you received no response. This must've been an oversight on our part; I don't receive that e-mail address but it goes to @"Jeff Martin", who has been busy with Propeller Tool improvements since December. So, we need to get this posted!
    We have two places for it: (a) on our OBEX, and (b) as a Quick Byte. @"Jeff Martin" takes care of OBEX and I've been handling Quick Bytes. Many objects are in both places.

    I'll get with Jeff and we'll see the zip is put on OBEX. I'll also wire up my stepper and driver to try the object out for appearance as a Quick Byte.

    Thank you for your work here, and sorry that you got caught in our e-mail blender.

    Sincerely,

    Ken Gracey

    Thanks Ken
    I know this is a busy time for all of you.
    Maybe even an automated reply just to let the person know the email was received.

  • @interpolate said:
    a typical stepper is 1.8 or something deg per step...ur saying ur running 15000 rpm in full step 1/2 that for half step? ok

    My stepper is .72 degrees/step or 1000 steps/rev in half step mode = 3000 RPM

  • Please excuse me for my ignorance but I don't understand at all what your're doing. You are talking about "stepper driver", "sine wave" and "motion profile". In the termiology I'm used to a "stepper motor driver" is a piece of hardware that takes step and direction inputs and outputs current to the motor windings. But here the word "driver" stands for the piece of software that is between the API and the hardware, correct? You are using an external driver hardware and are generating step and direction signals with the P2, right? So what is the API, what input does you driver software accept? It would be nice if you would include some comments in you code about what the arguments to the functions mean. I see a lot of comments about the calculations but I can figure out what it's actually doing.

    I read that the sine wave is used for the acceleration/decelleration profile. The the graphs should start at zero, ramp up to the max. velocity and ramp back down to zero. But the graph in the PDF shows a periodical sine wave. Or do you use the sine wave as nominal value for the winding currents dependant on the rotor angle?

    Sorry, I don't want to critizise, I just want to understand how this works.

  • @ManAtWork said:
    Please excuse me for my ignorance but I don't understand at all what your're doing. You are talking about "stepper driver", "sine wave" and "motion profile". In the termiology I'm used to a "stepper motor driver" is a piece of hardware that takes step and direction inputs and outputs current to the motor windings. But here the word "driver" stands for the piece of software that is between the API and the hardware, correct? You are using an external driver hardware and are generating step and direction signals with the P2, right? So what is the API, what input does you driver software accept? It would be nice if you would include some comments in you code about what the arguments to the functions mean. I see a lot of comments about the calculations but I can figure out what it's actually doing.

    I read that the sine wave is used for the acceleration/decelleration profile. The the graphs should start at zero, ramp up to the max. velocity and ramp back down to zero. But the graph in the PDF shows a periodical sine wave. Or do you use the sine wave as nominal value for the winding currents dependant on the rotor angle?

    Sorry, I don't want to critizise, I just want to understand how this works.

    But here the word "driver" stands for the piece of software that is between the API and the hardware, correct?

    • YES

    You are using an external driver hardware and are generating step and direction signals with the P2, right?

    • Yes again

    I'm sorry that my language is not as precise as it could be. In the graph above the blue curve described by the function y = 5-5(cos(x)) could be rewritten as Velocity(at step n) = MaxVelocity/2 - MaxVelocity/2 * cos(step n mapped to degrees in the range 0 -360). That blue curve is the motion profile. It starts at zero velocity (at zero degrees), accelerates to MaxVelocity (at the 180 degree point of the curve) and then decelerates to zero velocity (at 360 degrees)


    The curve above was generated from step numbers 0 -500 mapped to 0-360 degrees with a MaxVelocity of 10,000 steps/sec. The number of steps is related to the MaxAcceleration which occurs around the 90 and 270 degree points. More steps = lower acceleration, fewer steps = greater acceleration.
    In practice I pick the number of steps to map to produce an acceptable acceleration (for a given MaxVelocity) and then add additional steps at the 180 degree point of the curve where the acceleration is zero to fit the requirements of the move. For example if i needed to move 750 steps at a max velocity of 10,000 steps/sec. I could map 500 steps to (0-360 degrees) and then add (750-500 = 250) steps in the middle and my curve would look like this.

    Once I know the velocity at any step I can calculate the delay between that step and the next by the formula. Delay = clock frequency / velocity

    So what is the API, what input does you driver software accept?

    obj
    stepper : "step_driver2_sd" ' pasm stepper routine for step and direction type
    Pub
    stepper.start(sspin, cpin, dpin) 'start/stop pin, (step pin, dir pin to driver) ......Where sspin - specifies a pin that must be held high to run, pulled low causes a controlled deceleration to stop.

    stepper.move(speed,steps) ...... This is the call to the stepper routine, where speed is steps/sec and steps = number of steps to move (+/-)

    The driver updates a position variable as the move is in progress
    A mode variable that informs if a move is in progress, direction and current phase (acceleration, at_speed or deceleration)
    and a steps to move variable(STM) that is set to zero to indicate that the routine is ready for another move.

    I hope that answers your questions if not please let me know. I'm not saying this is the best way just a novel way to generate a motion profile with minimum jerk. I use it to control a motor connected to the rotary table on my milling machine.

  • I am thinking of a stationary motor that is not moving and I want to move it X number of steps in one direction.

    Your code looks like a motor that is spinning and you want to change its rotation by X amount using Y number of steps to get there.

    Mike

  • @iseries said:
    I am thinking of a stationary motor that is not moving and I want to move it X number of steps in one direction.

    Your code looks like a motor that is spinning and you want to change its rotation by X amount using Y number of steps to get there.

    Mike

    You can use it two ways.
    1. Motor is stationary. Command it to move a number of steps at a certain speed then stop.
    2. Motor is moving. Send it additional commands to extend the motion provided the additional commands are at the same speed in the same direction. Then stop.

  • @interpolate said:
    ur csd5814 takes for/rev signals
    why use step/dir?

    There are two versions. I realize most people will have step / direction type

  • PUB stepper.start(sspin, cpin, dpin) 'start/stop pin, (step pin, dir pin to driver) ......
    Where sspin - specifies a pin that must be held high to run, pulled low causes a controlled deceleration to stop.
    stepper.move(speed,steps) ......
    This is the call to the stepper routine, where speed is steps/sec and steps = number of steps to move (+/-)

    Ah thanks, this is what I was looking for.

Sign In or Register to comment.