Cogstop
MD2010
Posts: 11
Hi,
I wrote two programs that launch a Blink method. One works as expected and the other one is not. In both programs I have a loop that is waiting for two conditions, if condition one is meet LED (x) will turn on. If the second condition is met a cog[2] will launch a Blink method. If condition one is met again cog[2] should stop and LED(X) will turn on again. This works in program A but not in program B. I was wondering if anyone could help me with that?
program A
PUB LedOn | Hr , GUTS, s1, s2, count, cog[2] ' Method declaration
Debug.Start(31, 30, 0, 115200)
Debug.tx(CLS)
dira[10] := 1
dira[11] := 1
dira[1] := 1
dira[5] := 1
dira[16] := 0
dira[17] := 0
repeat
menu := debug.getstr(menu)
Debug.Str(String("wating for String:"))
Debug.tx(Debug#CR)
if STRCOMP (menu, @Str1) 'B1 "Red LED will flash"
cogstop(2)
cogstop(3)
outa[11]~~
outa[1]~~
elseif STRCOMP (menu, @Str3) 'B2 "Green LED will flash"
cog[2] := cognew(Blink(10), @stack[30])
cog[3] := cognew(Blink(5), @stack[50])
outa[11]~
outa[1]~
program B
PUB LedOnOff | counter, cog[2]
dira[10] := 1
dira[11] := 1
dira[1] := 1
dira[5] := 1
dira[16] := 0
dira[17] := 0
counter := 0
repeat
waitcnt(clkfreq/2 + cnt)
if ina[16]
cogstop(2)
cogstop(3)
outa[11]~~
outa[1]~~
elseif ina[17]
waitcnt(clkfreq*5 + cnt)
cog[2] := cognew(Blink(10), @stack[30])
cog[3] := cognew(Blink(5), @stack[50])
outa[11]~
outa[1]~
I wrote two programs that launch a Blink method. One works as expected and the other one is not. In both programs I have a loop that is waiting for two conditions, if condition one is meet LED (x) will turn on. If the second condition is met a cog[2] will launch a Blink method. If condition one is met again cog[2] should stop and LED(X) will turn on again. This works in program A but not in program B. I was wondering if anyone could help me with that?
program A
PUB LedOn | Hr , GUTS, s1, s2, count, cog[2] ' Method declaration
Debug.Start(31, 30, 0, 115200)
Debug.tx(CLS)
dira[10] := 1
dira[11] := 1
dira[1] := 1
dira[5] := 1
dira[16] := 0
dira[17] := 0
repeat
menu := debug.getstr(menu)
Debug.Str(String("wating for String:"))
Debug.tx(Debug#CR)
if STRCOMP (menu, @Str1) 'B1 "Red LED will flash"
cogstop(2)
cogstop(3)
outa[11]~~
outa[1]~~
elseif STRCOMP (menu, @Str3) 'B2 "Green LED will flash"
cog[2] := cognew(Blink(10), @stack[30])
cog[3] := cognew(Blink(5), @stack[50])
outa[11]~
outa[1]~
program B
PUB LedOnOff | counter, cog[2]
dira[10] := 1
dira[11] := 1
dira[1] := 1
dira[5] := 1
dira[16] := 0
dira[17] := 0
counter := 0
repeat
waitcnt(clkfreq/2 + cnt)
if ina[16]
cogstop(2)
cogstop(3)
outa[11]~~
outa[1]~~
elseif ina[17]
waitcnt(clkfreq*5 + cnt)
cog[2] := cognew(Blink(10), @stack[30])
cog[3] := cognew(Blink(5), @stack[50])
outa[11]~
outa[1]~
Comments
It would help us see you code properly if you used the code blocks. You can find them as the # icon if you "Go Advanced" or you can use:
[C0DE] your code goes here and end with [\C0DE]
I used a zero instead of "O" so you can see them. Make sure and use an oh not a zero.
Welcome to the forum.
Duane
Program A.
CON
_clkmode = xtal1 + pll16x ' use crystal x 16
_xinfreq = 5_000_000
''Parallax Serial Terminal Control Character Constants
''────────────────────────────────────────────────────
HOME = 1 ''HOME = 1
CRSRXY = 2 ''CRSRXY = 2
CRSRLF = 3 ''CRSRLF = 3
CRSRRT = 4 ''CRSRRT = 4
CRSRUP = 5 ''CRSRUP = 5
CRSRDN = 6 ''CRSRDN = 6
BELL = 7 ''BELL = 7
BKSP = 8 ''BKSP = 8
TAB = 9 ''TAB = 9
LF = 10 ''LF = 10
CLREOL = 11 ''CLREOL = 11
CLRDN = 12 ''CLRDN = 12
CR = 13 ''CR = 13
CRSRX = 14 ''CRSRX = 14
CRSRY = 15 ''CRSRY = 15
CLS = 16 ''CLS = 16
term = $0D
VAR
byte menu
long stack[60]
OBJ
debug : "FullDuplexSerialPlus"
delay : "timing"
PUB LedOn | Hr , GUTS, s1, s2, count, cog[2] ' Method declaration
Debug.Start(31, 30, 0, 115200)
Debug.tx(CLS)
dira[10] := 1
dira[11] := 1
dira[1] := 1
dira[5] := 1
dira[16] := 0
dira[17] := 0
repeat
menu := debug.getstr(menu)
Debug.Str(String("wating for String:"))
Debug.tx(Debug#CR)
if STRCOMP (menu, @Str1) 'B1 "Red LED will flash"
cogstop(2)
cogstop(3)
outa[11]~~
outa[1]~~
elseif STRCOMP (menu, @Str3) 'B2 "Green LED will flash"
cog[2] := cognew(Blink(10), @stack[30])
cog[3] := cognew(Blink(5), @stack[50])
outa[11]~
outa[1]~
PUB Blink( pin)
dira[pin]~~
outa[pin]~
repeat
waitcnt(clkfreq/2 + cnt)
!outa[pin]
DAT
Str1 byte "B1", 0
Str3 byte "B2", 0
program B
CON
_clkmode = xtal1 + pll16x ' use crystal x 16
_xinfreq = 5_000_000
VAR
byte menu
long stack[60]
OBJ
debug : "FullDuplexSerialPlus"
PUB LedOnOff | counter, cog[2]
dira[10] := 1
dira[11] := 1
dira[1] := 1
dira[5] := 1
dira[16] := 0
dira[17] := 0
counter := 0
repeat
waitcnt(clkfreq/2 + cnt)
if ina[16]
cogstop(cog[0])
cogstop(cog[1])
outa[11]~~
outa[1]~~
elseif ina[17]
waitcnt(clkfreq*5 + cnt)
cog[0] := cognew(Blink(10), @stack[30])
cog[1] := cognew(Blink(5), @stack[50])
outa[11]~
outa[1]~
PUB Blink( pin)
dira[pin]~~
outa[pin]~
repeat
waitcnt(clkfreq/2 + cnt)
!outa[pin]
-Phil