Shop OBEX P1 Docs P2 Docs Learn Events
Code Help — Parallax Forums

Code Help

OwenOwen Posts: 100
edited 2007-01-16 19:45 in Propeller 1
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)

Comments

  • GadgetmanGadgetman Posts: 2,436
    edited 2007-01-16 13:50
    You posted...
    cognew(Steping(stepPinX, dirPinX, enablePinX, stepsx, dirx, speedx), @stack[noparse][[/noparse]0])
    cognew(Steping(stepPinY, dirPinY, enablePinY, stepsy, diry, speedy), @stack[noparse][[/noparse]20])

    Is there any reason that one of them doesn't have a stack?
    (Maybe it's overwriting the other's stack?)


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't visit my new website...
  • OwenOwen Posts: 100
    edited 2007-01-16 17:03
    Maybe i'm just confused but they share the same sack but use different parts of it. I tried using different stacks but still have the same result. Any other ideas?

    thanks,
    Owen
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-01-16 17:19
    Does one instantiation work? reserving 20 for your stack space may not be enough. Using two different stacks would produce the same problem again if the allocated space was not large enough *and* the stack variables were defined consecutively of one another.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • CJCJ Posts: 470
    edited 2007-01-16 17:35
    if the stack was the issue, couldn't you figure that out by switching the stack assignments, if the working one changed when you swap the stacks, wouldn't that be a good indication of too small stack sizes?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who says you have to have knowledge to use it?

    I've killed a fly with my bare mind.
  • inserviinservi Posts: 113
    edited 2007-01-16 18:13
    Hello,

    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
  • OwenOwen Posts: 100
    edited 2007-01-16 19:32
    I tried reversing the stack space and nothing changes. I have tried using oversized very generous stack sizes also with no change. as for the clock speed i'm using a DLP-Prop which uses a 6khz crystal so that shouldn't be a problem. I'm still stumped...
  • rokickirokicki Posts: 1,000
    edited 2007-01-16 19:32
    I believe the problem is here:

    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.
  • OwenOwen Posts: 100
    edited 2007-01-16 19:40
    ok so I tried commenting out the Y cog:

    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...
  • OwenOwen Posts: 100
    edited 2007-01-16 19:45
    thank you thank you they do need to be local variables.
    thanks for the help,
    Owen
Sign In or Register to comment.