View Full Version : Unsolved Help converting to spin stepper motor ramping

10-23-2011, 09:32 PM
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 (http://www.hwml.com/LeibRamp.htm).

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
__________________________________________________ __



_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000


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

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


ser :"fullduplexserial"
math :"float32"

pub Start


Pub Main

Pub init

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

Mike Green
10-23-2011, 10:16 PM
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 (http://obex.parallax.com/objects/689/)". 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

10-24-2011, 12:12 AM
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?

10-24-2011, 02:26 AM

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 Jakacki
10-24-2011, 02:42 AM
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 (http://www.st.com/internet/analog/product/248592.jsp)which allows you specify acceleration & deceleration parameters amongst many other housekeeping functions.

10-24-2011, 04:30 AM
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:

10-24-2011, 08:28 PM
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?



10-24-2011, 09:19 PM

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.

10-25-2011, 04:07 AM
This object demos ramping. I hope it helps.

10-25-2011, 08:59 AM
This link and the attached PDFs might also be of help.

http://www.pmdcorp.com/news/articles/html/Mathematics_of_Motion_Control_Profiles.cfm (http://www.pmdcorp.com/news/articles/html/Mathematics_of_Motion_Control_Profiles.cfm)

10-25-2011, 12:10 PM
Mickster, Thank you so much, that is exactly what I needed to gain some understanding.
Lardom, Ill have a peek at that code.