Cognew Compiles but the program wont run
Snyggis
Posts: 14
I am still very new to the propeller, and this is probably a basic question. I am trying to launch 4 cogs to perform multiple tasks. I have the code working just fine with three cognew commands, but when I add a 4th everything stops working. If anyone had an idea where to look I would really appreciate it!
Code Below:
[CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
Debug: "FullDuplexSerialPlus"
Var long stack[50], RPM
PUB Main
Debug.start(31, 30, 0, 57600)
Dira[16]:=0
Dira[11]~~
cognew(PulseOut(21, 50, 148), @stack[10])
cognew(LEdge(16), @stack[20])
cognew(Output(15), @stack[30])
cognew(Pulsetest(11), @stack[40])
repeat
waitcnt(clkfreq + cnt)
debug.str(String("RPM = "))
debug.dec(RPM)
debug.str(string(13))
Pub PulseOut(pin, hz, ms)
repeat
Outa[Pin]:=1
waitcnt(clkfreq/100000*ms + cnt)
outa[21] := 0
waitcnt(clkfreq/hz + cnt)
Pub LEdge(inpin)| Edge
ctra[30..26]:= %01010
ctra[5..0]:= 16
frqa:=1
Edge~
Repeat
phsa~
waitcnt(clkfreq/1000+cnt)
if phsa> 1
edge++
RPM := edge
Pub Output(LEDPin)
Dira[ledpin]~~
repeat
outa[ledpin] := ina[16]
Pub Pulsetest(pin)
Repeat
outa[pin]:=0
waitcnt(clkfreq/2+cnt)
outa[pin]:=1
waitcnt(clkfreq/2+cnt)]
Code Below:
[CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
Debug: "FullDuplexSerialPlus"
Var long stack[50], RPM
PUB Main
Debug.start(31, 30, 0, 57600)
Dira[16]:=0
Dira[11]~~
cognew(PulseOut(21, 50, 148), @stack[10])
cognew(LEdge(16), @stack[20])
cognew(Output(15), @stack[30])
cognew(Pulsetest(11), @stack[40])
repeat
waitcnt(clkfreq + cnt)
debug.str(String("RPM = "))
debug.dec(RPM)
debug.str(string(13))
Pub PulseOut(pin, hz, ms)
repeat
Outa[Pin]:=1
waitcnt(clkfreq/100000*ms + cnt)
outa[21] := 0
waitcnt(clkfreq/hz + cnt)
Pub LEdge(inpin)| Edge
ctra[30..26]:= %01010
ctra[5..0]:= 16
frqa:=1
Edge~
Repeat
phsa~
waitcnt(clkfreq/1000+cnt)
if phsa> 1
edge++
RPM := edge
Pub Output(LEDPin)
Dira[ledpin]~~
repeat
outa[ledpin] := ina[16]
Pub Pulsetest(pin)
Repeat
outa[pin]:=0
waitcnt(clkfreq/2+cnt)
outa[pin]:=1
waitcnt(clkfreq/2+cnt)]
Comments
Also, please use [ code ] tags in the future to maintain the formatting of your code.
My guess is that your indentation is off somewhere, but I can't tell from what you posted.
You also start Debug twice, which may be (depending on your driver) an extra cog.
Thanks for looking at this!
re: tags, you put [noparse] [/noparse] at the end.
LEDedge - This is to debounce a optical switch and output a single edge - Works fine with only 3 cogs
Output - All this does is turn on a a LED whenever the optical switch comes on - Also works fine
Everything seems to function okay until I try to add another cog with Pulsetest - This is just pulsing a pin on and off. As soon as I add this method none of the other three methods function at all (RC pulses stop, LED edge stops, and the LED ouput also stops. The funny thing is if I delete one of the other cogs and method then the remaining ones work. It seems like it only wants to have 3 functioning at once.
Again, no pin is set as an output so no pulsing takes place.
FWIW, I generated fake input for pin 16 and relocated some pin locations to indicator LEDs (demoboard). With those changes all 4 cogs work just fine.