Code Help
Owen
Posts: 100
Can anyone help me with this code I wrote? it's a program to controll two stepper motors including a quadratic ramp of the speed. The program is given speed, direction, and steps to turn from a serial port. My problem is that the y axis speed (speedy) changes the speed for both motors and the value of speedx changes nothing. Everything else in the program seems to work perfectly. I have looked and looked for a simple syntax error or somthing but can't see any problems, can anyone help?
thanks,
Owen
CON
_clkmode = xtal1 + pll16x
_xinfreq = 6_000_000
stepPinX = 20
enablePinX = 21
dirPinX = 22
stepPinY = 23
enablePinY = 24
dirPinY = 25
K = 180000 ' Constant arbitrary
Var
long stack[noparse][[/noparse]40]
long stepsx
long stepsy
long speedx
long speedy
byte dirx
byte diry
long ramp
long timeR
long a
long b
long c
long Rs
OBJ
serial : "Extended_FDSerial"
PUB Turn
serial.start(1,2,%0000,57600)
repeat
repeat until 1 == serial.rx
stepsx :=serial.rxDec
dirx :=serial.rx
speedx :=serial.rx * 1000
stepsy :=serial.rxDec
diry :=serial.rx
speedy :=serial.rx * 1000
cognew(Steping(stepPinX, dirPinX, enablePinX, stepsx, dirx, speedx), @stack[noparse][[/noparse]0])
cognew(Steping(stepPinY, dirPinY, enablePinY, stepsy, diry, speedy), @stack[noparse][[/noparse]20])
PUB Steping(stepPin, dirPin, enablePin, steps, dir, speed) | pc,R
'ramp:=60
timeR:=2000
dira[noparse][[/noparse]enablePin]~~
outa[noparse][[/noparse]enablePin]~
dira[noparse][[/noparse]stepPin]~~
outa[noparse][[/noparse]stepPin]~
dira[noparse][[/noparse]dirPin]~~
outa[noparse][[/noparse]dirPin] := dir
pc := 0 ' pc = pulses counter
ramp := k/timeR
a := (timeR*timeR)/k ' NEW cuadratic ramp aX2 + bX + c
b := -2 * timeR
c := k + speed
R := ramp * timeR
repeat steps ' Loop turn the motor "Se" steps....
pc := pc + 1
IF ramp*2 =< steps
if pc =< ramp
R := a*(pc*pc) + b*pc + c
if pc => steps - ramp
R := a*(steps-pc)*(steps-pc) + b*(steps-pc) + c
else
if pc =< steps/3
R := a*(pc*pc) + b*pc + c
if pc => steps - (steps/3)
R := a*(steps-pc)*(steps-pc) + b*(steps-pc) + c
outa[noparse][[/noparse]stepPin] := 1 ' Set pin 4 high
waitcnt(R + 1000 + cnt ) ' Wait for pulse high width plus 1000 to adjust the time lost in other processing.)
outa[noparse][[/noparse]stepPin] := 0 ' Pin 4 now low
waitcnt(R + cnt)
thanks,
Owen
CON
_clkmode = xtal1 + pll16x
_xinfreq = 6_000_000
stepPinX = 20
enablePinX = 21
dirPinX = 22
stepPinY = 23
enablePinY = 24
dirPinY = 25
K = 180000 ' Constant arbitrary
Var
long stack[noparse][[/noparse]40]
long stepsx
long stepsy
long speedx
long speedy
byte dirx
byte diry
long ramp
long timeR
long a
long b
long c
long Rs
OBJ
serial : "Extended_FDSerial"
PUB Turn
serial.start(1,2,%0000,57600)
repeat
repeat until 1 == serial.rx
stepsx :=serial.rxDec
dirx :=serial.rx
speedx :=serial.rx * 1000
stepsy :=serial.rxDec
diry :=serial.rx
speedy :=serial.rx * 1000
cognew(Steping(stepPinX, dirPinX, enablePinX, stepsx, dirx, speedx), @stack[noparse][[/noparse]0])
cognew(Steping(stepPinY, dirPinY, enablePinY, stepsy, diry, speedy), @stack[noparse][[/noparse]20])
PUB Steping(stepPin, dirPin, enablePin, steps, dir, speed) | pc,R
'ramp:=60
timeR:=2000
dira[noparse][[/noparse]enablePin]~~
outa[noparse][[/noparse]enablePin]~
dira[noparse][[/noparse]stepPin]~~
outa[noparse][[/noparse]stepPin]~
dira[noparse][[/noparse]dirPin]~~
outa[noparse][[/noparse]dirPin] := dir
pc := 0 ' pc = pulses counter
ramp := k/timeR
a := (timeR*timeR)/k ' NEW cuadratic ramp aX2 + bX + c
b := -2 * timeR
c := k + speed
R := ramp * timeR
repeat steps ' Loop turn the motor "Se" steps....
pc := pc + 1
IF ramp*2 =< steps
if pc =< ramp
R := a*(pc*pc) + b*pc + c
if pc => steps - ramp
R := a*(steps-pc)*(steps-pc) + b*(steps-pc) + c
else
if pc =< steps/3
R := a*(pc*pc) + b*pc + c
if pc => steps - (steps/3)
R := a*(steps-pc)*(steps-pc) + b*(steps-pc) + c
outa[noparse][[/noparse]stepPin] := 1 ' Set pin 4 high
waitcnt(R + 1000 + cnt ) ' Wait for pulse high width plus 1000 to adjust the time lost in other processing.)
outa[noparse][[/noparse]stepPin] := 0 ' Pin 4 now low
waitcnt(R + cnt)
Comments
(Maybe it's overwriting the other's stack?)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't visit my new website...
thanks,
Owen
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Who says you have to have knowledge to use it?
I've killed a fly with my bare mind.
I think that the propeller is supporting until 80 Mhz.
If i'v well understanding the calcul, the _xinfreq = 6_000_000 multuply by pll16x give 96Mhz !
It is maybe to much ?
dro
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
in medio virtus
long ramp
long timeR
long a
long b
long c
long Rs
These are shared variables in shared memory; both cogs will use the same ones, so they will
step all over each other.
Make the stacks larger (use say 100 longs for each) just to be safe, and make these variables
be locals in "Steping" and you should be okay.
cognew(Steping(stepPinX, dirPinX, enablePinX, stepsx, dirx, speedx), @stack[noparse][[/noparse]0])
'cognew(Steping(stepPinY, dirPinY, enablePinY, stepsy, diry, speedy), @stack[noparse][[/noparse]40])
and now I can controll the x axis speed like I want to. this is progress but i still cant controll them both, still confused...
thanks for the help,
Owen