Shop OBEX P1 Docs P2 Docs Learn Events
Program Stalls Problem? — Parallax Forums

Program Stalls Problem?

GeeksGoneBadGeeksGoneBad Posts: 100
edited 2011-05-25 04:30 in Propeller 1
Hey Everybody - I am working on an application that interfaces the Prop Proto board with an Easydriver stepper board - I had posted before about power requirements for powering the Proto board but this problem is with my actual spin program so I figured it deserved a new post?

I'm new to all this and trying to get things going and having some good success - except for one problem

I wanted a way to stop the stepper motor so what I did was say if the value I am gettin gfrom the RCMeasure is less than 350 (which is a bit more than what I get when the pot is all the way down) so when I turn the knob all the way down it stops - simple enough and it works

but sometimes it does not start back up - sometimes it does - it's weird...

It's probably something with my program so I wanted to post it here for advice :)
VAR

  long time
  long Stack[20]

CON

  _xinfreq = 5_000_000                      
  _clkmode = xtal1 + pll16x

  MS1Pin = 23
  MS2Pin = 19
  SleepPin = 24
  ResetPin = 21
  PFD = 22
  EnablePin = 20
  DirectionPin = 17
  DirectionSwitch = 7
  StepPin = 18

  Forward = 0
  Reverse = 1
  
  
PUB Main

    Cognew(StepMotor,@stack[0])
    Cognew(RCMeasure,@stack[10])
                                
PUB StepMotor

    dira[StepPin] := 1
    dira[DirectionPin] := 1
    dira[MS1Pin] := 1
    dira[MS2Pin] := 1
    dira[SleepPin] := 1

    outa[MS1Pin] := 0
    outa[MS2Pin] := 1

    repeat
      if time > 350
        outa[SleepPin] := 1
        outa[DirectionPin] := ina[DirectionSwitch]
        outa[StepPin] := 1
        waitcnt(clkfreq/time + cnt)
        outa[StepPin] := 0
        waitcnt(clkfreq/time + cnt)
      else
        outa[SleepPin] := 0
        
PUB RCMeasure      

  ctra[30..26] := %01000                     ' Set mode to "POS detector"
  ctra[5..0] := 16                           ' Set APIN to 16 (P16)
  frqa := 1                                  ' Increment phsa by 1 for each clock tick

  repeat
     dira[16] := outa[16] := 1               ' Set pin to output-high
     waitcnt(clkfreq/100_000 + cnt)          ' Wait for circuit to charge
      
     phsa~                                   ' Clear the phsa register
     dira[16]~                               ' Pin to input stops charging circuit

     repeat 22
       waitcnt(clkfreq/60 + cnt)        

     time := (phsa - 624) #> 0
     waitcnt(clkfreq/2 + cnt)
     

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2011-05-25 01:03
    Is there a way for you to figure out how big time is when it stalls? Just wondering whether time becomes too big (~210k) to push clkfreq/time below 381 which is the minimum required offsetA for a SPIN waitcnt. As a quick check you could change the call to something like waitcnt((clkfreq/time #> 381) + cnt).

    Another issue I can see is that both methods run concurrently without any obvious synchronisation. Which means that time may pass the > 350 test but is then reset to 0 (limit minimum) before the waitcnt. This means - SPIN enforcing n/0 == 0 - that you end up with what is basically a waitcnt(cnt), i.e. a stall. To test this scenario just lock the time value like this:
    repeat
        if [COLOR="red"](temp := time) > 350[/COLOR]
          outa[SleepPin] := 1
          outa[DirectionPin] := ina[DirectionSwitch]
          outa[StepPin] := 1
          waitcnt(clkfreq/[COLOR="red"]temp[/COLOR] + cnt)
          outa[StepPin] := 0
          waitcnt(clkfreq/[COLOR="red"]temp[/COLOR] + cnt)
        else
          outa[SleepPin] := 0
    
    A to avoid a stall due to wrap-around
  • GeeksGoneBadGeeksGoneBad Posts: 100
    edited 2011-05-25 04:30
    Hi kuroneko, Thank you very much - your code example works (at least in the dozen tests I just did)
Sign In or Register to comment.