Stepper Pub Not OutA_ing
CannibalRobotics
Posts: 535
I have these peices of code to drive 2 stepper motors.
When I run Init and top of Main, the motors move through the routine, find their limits and position the platform with the offsets - no problem.
If I call StepX (same as StepY) from another cog, the count increments but there is no output to the motors. Since the count is moving, I know the routine is getting cycled as that's the only place the count gets incremented anywhere.
Is this because of a confilct of output port ownership?
How do I resolve it?
Thanks in advance!
When I run Init and top of Main, the motors move through the routine, find their limits and position the platform with the offsets - no problem.
If I call StepX (same as StepY) from another cog, the count increments but there is no output to the motors. Since the count is moving, I know the routine is getting cycled as that's the only place the count gets incremented anywhere.
Is this because of a confilct of output port ownership?
How do I resolve it?
Thanks in advance!
Pub Init(StepLock) cognew(Main(StepLock), @Stack) return @Xcount Pub Main(StepLock) Lock := StepLock SetUp Xdelay := 35_000 Ydelay := 30_000 Zdelay := 20_000 Repeat 3 FindXMarker MoveDegreesX(18) Xcount := 0 Xtarget := 0 Repeat 4 FindYMarker MoveDegreesY(-170) Ycount := 0 Ytarget := 0 Repeat Pub FindXMarker Repeat while ina[Xmarker] == 0 stepX(1) Repeat while ina[Xmarker] == 1 stepX(1) Xrev := Xcount Xcount := 0 Pub FindYMarker Repeat while ina[Ymarker] == 0 stepY(1) Repeat while ina[Ymarker] == 1 stepY(1) Yrev := Ycount Ycount := 0 Pub StepX(d) | i ' Steps Motor X d times (- == reverse) if d < 0 ' Test for direction and set output OutA[Xdir] := 1 i := -1 ' Set step count increment - else OutA[Xdir] := 0 i := 1 ' Set step count increment + OutA[Enable] := 0 ' Enable the stepper controller Repeat ||d ' Repeat d steps ( || means absolute value for negitive directions) OutA[Xstep] := 1 ' High on stepper controller Waitcnt(cnt + Xdelay) ' Wait Xdelay OutA[Xstep] := 0 ' Low on stepper controller Waitcnt(cnt + Xdelay) ' Wait Xdelay again lockset(Lock) ' Lock set to prevent external read conflict XCount := Xcount + i ' Bump the step count by increment LockClr(Lock) ' clear the lock for reads OutA[Enable] := 1 ' disable the controller Return Xcount ' Send Xcount back
Comments
You don't have to for this problem (supposing dira is the only problem), but in the future, can you please go to File -> Archive "name" -> Project... in Propeller Tool or File -> Create Propeller Archive in BST and make an archive of your entire project and upload that to the forums? That way, we can see all of your code, including variable definitions, object definitions, and object source. The first thing I looked for when I saw your code was the possibility of a stack overflow, but then I couldn't find the definition of Stack!
Before posting this I had tried putting dira(x) :=1 for all ports inside the StepX routine so they were set to output each time. No joy.
Something else is going on.
There's no way in the code you've posted that you would get any output at all because you never set dira[x] := 1. This means that the problem is probably in some code that you haven't posted. Is every cog that uses a pin making that pin an output? dira is per cog, not global. Every cog that wants to output on a pin has to set the pin to an output, not just the first cog that changes the pin's state, even though only one cog has to make a pin an output for it to be an output.
effective_dira := dira0 | dira1 | dira2 | ...
effective_outa := (outa0 & dira0) | (outa1 & dira1) | (outa2 & dira2) | ...
+1 for code attachment
@kuroneko: The LockSet and LockClr commands are primarilly to protect the Xcount and Ycount. It was my intent to put the repeat on the stepper side as well but then I've got to set up counters in place of the delays to compensate for extra repeat rolls. I also don't want the stepper motors getting interupted. In light of the most basic function not working, I thought I'd concentrate my efforts there. I've run the code with those remarked out and it's still a non player.
@Electrodude I've put the DIRA[x...] commands into all sections of the code that attempt to hit those ports (whick seems counter intuitive) but, it has not changed anything. I've also pushed the stack allocation up and down and it seems to have no effect.
What's totally bazarre is that SetpX and StepY work fine when called by 'StepperDriver/Main'
Again, thanks in advance...