Help with simultaneous control of 2 stepper motors using Propeller
kotsos
Posts: 12
Hi,
What I basically aim to do is to control many (4 in total) stepper motors SIMULTANEOUSLY using the propeller. I wrote an object that successfully controls 1 stepper motor, but when I try to launch the object multiple times, it doesn't work!
This is the code of the object:
Right now all it excecutes is what "stepper.Start(19,22, 200, 0)" does. I suspect that for some reason when I try to launch a second cog, I stop the previous one.
Thanks in advance!
-kotsos
What I basically aim to do is to control many (4 in total) stepper motors SIMULTANEOUSLY using the propeller. I wrote an object that successfully controls 1 stepper motor, but when I try to launch the object multiple times, it doesn't work!
This is the code of the object:
_xinfreq = 5_000_000 _clkmode = xtal1 + pll1x DAT Steps byte %1100, %0110, %0011, %1001 VAR long cntr, stpIdx long stack[200] byte cog PUB Start(P1, P4, nxt, prev) : success Stop success := (cog := cognew(gostep(P1, P4, nxt, prev), @stack)+1) PUB Stop if cog cogstop(cog~ -1) PUB gostep(P1, P4, nxt, prev) dira[19..22]~~ outa[19..22]~~ dira[28..31]~~ outa[28..31]~~ if prev < nxt stepFwd(P1,P4,(nxt-prev)) elseif prev > nxt stepBwd(P1,P4,(prev-nxt)) PUB stepFwd(P1,P4,stps) repeat cntr from 1 to stps stpIdx := ++stpIdx // 4 outa[P1..P4] := Steps[stpIdx] waitcnt(clkfreq/200 + cnt) PUB stepBwd(P1,P4,stps) repeat cntr from 1 to stps stpIdx := (stpIdx + 3) // 4 outa[P1..P4] := Steps[stpIdx] waitcnt(clkfreq/200 + cnt)This is the script that calls the object:
_xinfreq = 5_000_000 _clkmode = xtal1 + pll1x VAR long cntr, stpIdx OBJ stepper : "Stepper_motor_trials" PUB launchStepper stepper.Start(28,31, 200, 0) stepper.Start(19,22, 200, 0)Any suggestions on how to launch the object "stepper" on multiple cogs?
Right now all it excecutes is what "stepper.Start(19,22, 200, 0)" does. I suspect that for some reason when I try to launch a second cog, I stop the previous one.
Thanks in advance!
-kotsos
Comments
Still nothing moves.
How do I clean the gostep method, as you mentioned?
Thanks!
I got it!!!
I re-corrected the dira/outa thing. Here is the code:
And
Thanks A lot! You solved my problem!!!!!