Program Stalls Problem?
GeeksGoneBad
Posts: 100
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
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
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: A to avoid a stall due to wrap-around