Shop OBEX P1 Docs P2 Docs Learn Events
Stepper Pub Not OutA_ing — Parallax Forums

Stepper Pub Not OutA_ing

CannibalRoboticsCannibalRobotics Posts: 535
edited 2014-10-24 07:51 in Propeller 1
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!
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

  • ElectrodudeElectrodude Posts: 1,658
    edited 2014-10-23 16:52
    You have to set dira[pin] to 1 for every pin you want to be an output, or the pins will just act as inputs.

    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!
  • CannibalRoboticsCannibalRobotics Posts: 535
    edited 2014-10-23 18:26
    That wouldn't explain why it works then stops.
    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.
  • ElectrodudeElectrodude Posts: 1,658
    edited 2014-10-23 18:38
    In that case, can you please post all of your code as a Propeller Archive as explained in my previous post? I have no idea how big your stack is, how big any of your variables are, what's calling this code, etc.

    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) | ...
  • kuronekokuroneko Posts: 3,623
    edited 2014-10-23 22:26
    Another thing is the current use of lockset. What you want is repeat while lockset(lock) instead. The way it is now it's just wasting time but not protecting anything.

    +1 for code attachment
  • CannibalRoboticsCannibalRobotics Posts: 535
    edited 2014-10-24 07:51
    The entire code is attached.
    @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...
Sign In or Register to comment.