Shop OBEX P1 Docs P2 Docs Learn Events
Help converting to spin stepper motor ramping — Parallax Forums

Help converting to spin stepper motor ramping

BitsBits Posts: 414
edited 2011-10-25 05:10 in Propeller 1
I have found a document that appears to be an elegant solution for a stepper motor ramp. In my attempt to program this document into spin I have discovered a problem. The link to said document is here.

I identify that there has to be a clock (be an object or cog) that should engender a pulse on a selected output pin. That clock needs to be updated from one of these equations. This has yet been programmed.

I think I understand the equations and have posted them below in a very basic manor using floating point computations.

But if someone could explain an order or provide a crude flow chart for what equations have to be executed and when, I would be appreciative.
{{


 Real time stepper motor linear ramping
 ____________________________________________________
 
 First attempt by : Bits 
 Documentaion bt  : Aryeh Eiderman
 PDF located at   : http://www.hwml.com/LeibRamp.pdf 
 HTML located at  : http://www.hwml.com/LeibRamp.htm
 ____________________________________________________
                    
}}


Con


  _clkmode        = xtal1 + pll16x
  _xinfreq        = 5_000_000


Var


  Long  Base_Speed, Slew_Speed
  Long  acceleration,Timer_freq
  Long  Base_Speed_Squared, Slew_Speed_Squared 


  Long  S, P1, Ps, R, P, M
  
Obj


   ser :"fullduplexserial"
   math :"float32"
   
pub Start


  math.start
  init
  main


  
Pub Main


Pub init


  ser.start(31,30,0,19200)  
  acceleration := 1.0            'steps / second
  Base_Speed := 2.0              'steps / second
  Slew_Speed := 5.0              'steps / second                         
  Timer_freq := 1.0              'ticks / second Hz
  S := P1 := Ps := R := P := M := 0.0
  Base_Speed_Squared := math.Fmul(Base_Speed,Base_Speed)
  Slew_Speed_Squared := math.Fmul(Slew_Speed,Slew_Speed)
    
Pub accel_deceleration_distance | Temp


  Temp :=  Math.Fmul(2.0,acceleration)                   
  S := Math.Fsub(Slew_Speed_Squared, Base_Speed_Squared)
  S := Math.Fdiv(S,temp)


Pub delay_period_4_inital_step | Temp                    


  Temp := Math.Fmul(2.0,acceleration)
  P1 := Math.Fadd(Base_Speed_Squared,Temp)
  P1 := Math.FSqr(P1)
  P1 := Math.Fdiv(Timer_Freq,P1)  
  
Pub delay_period_4_slew_speed                       


  Ps := Math.Fdiv(Timer_Freq,Slew_speed)
  
Pub constant_multipler | Temp


  Temp := Math.Fmul(Timer_freq,Timer_freq)   
  R := Math.Fdiv(acceleration,Temp)   


Pub variable_delay_period | Temp


  Temp := Math.Fmul(P,P)
  Temp := Math.Fmul(Temp,m)
  Temp := Math.Fadd(1.0,Temp)
  Temp := Math.Fmul(p,Temp)
  P := Temp


Pub variable_multiplier


  M := 0
  
  { floating point
    logic needed below
     
  if (R < 0)
    M := -R
      
  if (R > 0)
    M := R
             }

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-23 15:16
    A couple of comments:

    1) Floating point is a lot slower than integer arithmetic. Still, floating point speeds with the Propeller are not too shabby. Make sure to use the new floating point object "F32". It's faster and has some minor numeric corrections.

    2) You have to use FNeg for negation and FCmp for comparisons like: if Math.FCmp(R,0.0) < 0
  • BitsBits Posts: 414
    edited 2011-10-23 17:12
    Thanks Mike Green for the advice.

    Trying to come up with some way to even start the process is a testing to my fortitude. I have read the document a few dozen times and still the light is off.

    Hum, anyone even have a slight idea on how I can proceed?
  • ElectricAyeElectricAye Posts: 4,561
    edited 2011-10-23 19:26
    Bits wrote: »
    ...

    Hum, anyone even have a slight idea on how I can proceed?

    Have you had a look at this attachment? Maybe this can help.
    But I agree with Mike about using integers vs. floats.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2011-10-23 19:42
    The original algorithm was designed back in 1994 to work on a PC through it's parallel port and the author asserted that it worked faster in floating point than in integer form. While this may be true for a PC the Prop however is a microcontroller and is not equipped with an FPU.

    What are you trying to do, is it to build a stepper controller with ramping or is this your part of a team assignment where you have been given the task of implementing this on the Prop?

    If you have total control and want to build a stepper I would suggest using a chip with all this built in and more. Have a look at the L6470 which allows you specify acceleration & deceleration parameters amongst many other housekeeping functions.
  • BitsBits Posts: 414
    edited 2011-10-23 21:30
    Peter you are sweet, by the way I was not given a task, in fact It is I who delivers the task to my employees. Otherwise that IC you mentioned looks promising. Thanks for the bash and save. :):lol:
  • MicksterMickster Posts: 2,723
    edited 2011-10-24 13:28
    At first glance this is not much different to trapezoidal velocity profile generation for servo motor control. It should be possible to pre-process the entire profile and not have to worry about real-time math performance...or am I missing something?

    Regards,

    Mickster
  • BitsBits Posts: 414
    edited 2011-10-24 14:19
    Mickster,

    I was thinking similar to your post, in that all the calculations could be completed first then at run time only one recursive equation is used. I am still trying to decipher the order of things.
  • lardomlardom Posts: 1,659
    edited 2011-10-24 21:07
    This object demos ramping. I hope it helps.
    http://obex.parallax.com/objects/617/
  • BitsBits Posts: 414
    edited 2011-10-25 05:10
    Mickster, Thank you so much, that is exactly what I needed to gain some understanding.
    Lardom, Ill have a peek at that code.
Sign In or Register to comment.