Bits

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

__________________________________________________ __

}}

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

}

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

}