Shop OBEX P1 Docs P2 Docs Learn Events
Stepper Motor driver in Assembler - Has anyone coded that? — Parallax Forums

Stepper Motor driver in Assembler - Has anyone coded that?

Christof Eb.Christof Eb. Posts: 1,162
edited 2008-03-25 12:48 in Propeller 1
Hi,
I tried to find a stepper motor driver in assembler for the prop and did not find one. Did I miss something?

Hardware is in my case to drive L298N via 4 port lines.

Thanks for some input!
C.

Comments

  • LeonLeon Posts: 7,620
    edited 2008-01-07 13:17
    Why do you need it in assembler?

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • simonlsimonl Posts: 866
    edited 2008-01-07 13:22
    @Christof: Not sure if it's PASM, but there's a L298 object in obex (obex.parallax.com/objects/97/).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,

    Simon
    www.norfolkhelicopterclub.co.uk
    You'll always have as many take-offs as landings, the trick is to be sure you can take-off again ;-)
    BTW: I type as I'm thinking, so please don't take any offense at my writing style smile.gif
  • simonlsimonl Posts: 866
    edited 2008-01-07 13:24
    Yup - it uses PASM...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,

    Simon
    www.norfolkhelicopterclub.co.uk
    You'll always have as many take-offs as landings, the trick is to be sure you can take-off again ;-)
    BTW: I type as I'm thinking, so please don't take any offense at my writing style smile.gif
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2008-01-07 13:32
    but it isn't a stepper motor driver.
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-07 20:38
    I love such sequences of postings .....
  • JoergJoerg Posts: 91
    edited 2008-01-08 21:11
    To put some (hopefully) input in this section:

    attachment.php?attachmentid=51338

    For a LM298 connection Input 1 is Bit0 Input2 Bit1 .....



    Saluti Joerg
    517 x 680 - 12K
  • LeonLeon Posts: 7,620
    edited 2008-01-08 21:16
    Someone did post some assembler code a few months ago, I found it when I was looking for something else. I could probably find it again if the search facility worked properly.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • SapiehaSapieha Posts: 2,964
    edited 2008-01-08 21:56
    Hi Christof Eb.

    Look at

    http://forums.parallax.com/forums/default.aspx?f=25&m=170328

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.

    Sapieha
  • Christof Eb.Christof Eb. Posts: 1,162
    edited 2008-01-19 10:27
    Thanks for the inputs!

    Looks like there was not much code. I will decide, if I am going to write my own code which should ramp up and slow down and go for a given number of steps.

    Christof
  • OzStampOzStamp Posts: 377
    edited 2008-01-19 11:07
    Hi Christof

    If very high speed is required you have to use ASM
    But try SPIN before you go that way as we have done some work many months ago
    with a simple step/direction set up and we got pretty good speeds using spin..

    The key to the code is a BARREL SHIFTER type program..
    You load the pattern ( for CW and CCW) and rotate the same BARREL one way or the other way. (ROR and ROL)
    The speed of rotation determines the speed of the motor
    That example program listed (as per Sap's link) shows you that precisely..

    cheers ron
  • BTXBTX Posts: 674
    edited 2008-01-22 00:12
    Hi Christof

    I´m programing an asm driver for steppers and servo motors...I think I will get it finished early...when I get home I will post this.
    Now...it´s only my aditional fun in vacations.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Regards.

    Alberto.
  • m.r.b.m.r.b. Posts: 36
    edited 2008-01-22 12:35
    Yes, I have done I high speed stepper driver in assembler, I needed the speed, for a microsteping driver!!!

    The output of which is clock/direction, to an external microstepping stepper motor driver board.



    The code includes ramp up - steady speed - ramp down trapesiod motion profile, with programmable start speed, terminal speed, home speed·(steps/second), and ramps (steps/second^2)

    It also includes·origin (home) sensor seek routines, + loads more...



    I shall post the code tonight when I get in... Please bear with me 6 hours or so...
  • BTXBTX Posts: 674
    edited 2008-01-22 21:33
    @m.r.b

    That´s exactly what I´m doing..... also with the (home) position sensor.
    I´ll be hopefully waiting for your version ....also then I will post mine (when I get it finished).
    Maybe with both ideas, we could get an improved driver for that !!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Regards.

    Alberto.
  • m.r.b.m.r.b. Posts: 36
    edited 2008-02-01 13:28
    Appologies for the delay... Been very busy with other things.

    Please find the attached Clock-Direction stepper driver Object.

    M.R.B.
  • BTXBTX Posts: 674
    edited 2008-03-25 00:51
    Hi all !!
    Here's what I promess.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Regards.

    Alberto.
  • StefanL38StefanL38 Posts: 2,292
    edited 2008-03-25 09:35
    Hello,

    i took a quick look into the code without analysing it in details.

    i have a question to m.r.b.

    in the sourcecode you wrote "Axis driver object ... THREE instances of this object are created for X,Y and Z axes"

    can two or maybe even all three axis work synchronized to move two or three axis at the same time?
    This would make it possible to move in ANY direction in 3D-Space.

    example:

    looking at only two axis X,Y
    i start at X,Y = 0,0 and wnat to move to X,Y 50,80
    now unsynchronized it would work:
    1.) move from 0,0 to 50,0 (only-X-Axle-move)
    then
    2.) move from 50,0 to 50,80 (only Y-axle-move)

    maybe it is possible to start two axes at the same time.
    But if they are using the same speed the X-axle reaches the target faster than the Y-axle.
    If Y-axle is at position 50 the X-axle has reached its target and stops
    then the Y-axle does the rest from position 50 to 80

    synchronized would be:
    start at X,Y 0,0 and move DIRECTLY to X,Y 50,80 (X-axle AND Y-axle are moving at the SAME TIME - AND if X reaches 50, Y reaches 80

    This means the output between X and Y-Axles has to be synchronized
    the Y-axle has more steps than the X-Axle

    In average every 80/50 = 1.6 steps of the Y-Axle the X-Axle has to go one step

    Now you could try to calculate different speeds for the axis. But how about errors in the calculation of the speeds
    (which has not endlessly digits to calculate superexactly)
    and how about the synchronized starting of the two axis ?

    For one move maybe it doesn't matter. But how about a lot of sequential movements without any stops until reaching the final position ?
    The position-error of each single move will add to a summary-position-error.
    How big will the position error be after 50 or 250 moves ?

    example:
    start at 0,0 move a route to 40,20 to 100,10 to 80,15 etc.

    Move without any stops
    if not synchronized EXACTLY it would work this way
    start at 0,0 to 40,20. Y-axles reaches 20 but X-axle is at 38 and not at 40.
    Y-Axle starts next move towards 100,10 so X-axle does the move from X=38 to X=40 while Y-axle is already running into a different direction (towards Y=10)

    So the REAL route would be 0,0 to 38,20 instead of 0,0 to 40,20


    With synchronized axis the error stays very low

    Therefore it is nescessary that the bitbanging for the steps of BOTH axis is done by ONE loop

    This could be done by an algorithm called "Bresenham-Algorithm".
    The advantage of this algorithm is that it needs only addition and subtraction of integers, regardless of the step-relation of X-axle to Y-axle
    F.e. step-relation X:Y 47:19 or 197 : 5311 or what ever is done correctly by the algorithm.
    This means the algorithm is fast because it doesn't need floating-point maths.

    Did anybody work on implementing the Bresenham-Algorithm for two or maybe even three axis ?


    best regards

    Stefan
  • m.r.b.m.r.b. Posts: 36
    edited 2008-03-25 12:48
    Yes, you can move more than one axis at the same time with my code.... Each axis is driven by it's own cog in the background, so that the rest of the software can do other things... (IE 'talk' to a touchscreen LCD module, for the GUI, ... ·a laboratory analytical balance, ...·a barcode reader etc..)





    In the application I am using it for (robot!!!, helping someone with a college project), in the parent object, I do something like this.... (assuming you have instanciated 3 instances of the axis driver already as "Axis"..) .... Doing the following, will home axes, then move an X,Y axis configuration in a diagonal line!!!



    ·· Axis[noparse][[/noparse]0].Home(True)·· 'Home X, wait for home complete

    ·· Axis[noparse][[/noparse]1].Home(True)··· 'Home Y, wait for home complete

    ·· ......·· previous code

    ·· ......·· blah blah

    ·· Axis[noparse][[/noparse]0].MoveAbs(100,False)·· 'Start X axis move to absolute position, with no wait

    ·· Axis[noparse][[/noparse]1].MoveAbs(100,False)·· 'Start Y axis move to absolute position, with no wait

    ·· Repeat while Axis[noparse][[/noparse]0].GetBusy or Axis[noparse][[/noparse]1].Getbusy· 'Wait for move to complete, before issuing next move command

    ·· ......·· more code

    ·· ......·· blah blah

    The False's relate to "Do you pause program execution until move is complete".

    You can subtitute the 'MoveAbs', for 'MoveInc', to move incrementally, rather than to an absolute logical position!!





    B.T.W.... You can adjust the 'angle' of the line, by adjusting the drive speed settings, before your move....

    IE:-

    Axis[noparse][[/noparse]0].SetTerminalSpeed(nnnn)

    Axis[noparse][[/noparse]1].SetTerminalSpeed(nnnn)

    ...·adjusts the X/Y terminal speeds... thus adjusting the angle of movement..Of course, there will be a small delay between X & Y starting, due to spin program execution timing, for most things it is insignificant, because the motors are ramping up to speed anyway!! (True trapeziod motion profile... Ramp up-Hold-Ramp down!!!)





    But... doing this moves the X, then the Y, after the X is done.......

    ·· Axis[noparse][[/noparse]0].MoveInc(100,True)·· 'Start X axis move, with wait

    ·· Axis[noparse][[/noparse]1].MoveInc(100,True)·· 'Start Y axis move, with wait



    Regards M.R.B.
Sign In or Register to comment.