multiple cognew command problem
fireman508
Posts: 19
Hello,
I'm having a problem with the cognew command. Every time I run my code below, only the first cog (temp.main) initializes and none of the code following it is run. The code is supposed to start a new cog and then display a number to confirm that it started. I'm not sure if this is simply how the cognew function works or if my coding is wrong, but I ran it once in the past and all 5 cogs started no problem. Any help or advice would be greatly appreciated. Thanks!
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
pin = 9
baud = 19_200
lines = 2
VAR
LONG TEMP0[9]
LONG PRESS0[9]
LONG CLOCK0[9]
LONG USB0[9]
LONG CAM0[9]
LONG JAR0[9]
BYTE START0
BYTE START1
BYTE START2
BYTE START3
BYTE START4
BYTE START5
OBJ
LCD : "Serial_Lcd.spin"
TEMP : "TEMP.spin"
PRESS : "PRESS.spin"
USB : "USB.spin"
CAM : "CAM.spin"
JAR : "JAR.spin"
CLOCK : "CLOCK.spin"
PUB MAIN
LCD.start(pin, baud, lines)
waitcnt(clkfreq / 100 + cnt)
LCD.backlight(1)
LCD.cursor(3)
LCD.cls
LCD.STR(STRING("STARTING COGS..."))
LCD.NEWLINE
START0 := COGNEW(TEMP.MAIN(1), @TEMP0)
IF START0
LCD.PUTC(9)
LCD.DEC(0)
START1 := COGNEW(PRESS.MAIN, @PRESS0)
IF START1
LCD.PUTC(9)
LCD.DEC(1)
START2 := COGNEW(CLOCK.MAIN(1), @CLOCK0)
IF START2
LCD.PUTC(9)
LCD.DEC(2)
START3 := COGNEW(USB.MAIN(1), @USB0)
IF START3
LCD.PUTC(9)
LCD.DEC(3)
START4 := COGNEW(CAM.MAIN, @CAM0)
IF START4
LCD.PUTC(9)
LCD.DEC(4)
START5 := COGNEW(JAR.MAIN, @JAR0)
IF START5
LCD.PUTC(9)
LCD.DEC(5)
LCD.STOP
I'm having a problem with the cognew command. Every time I run my code below, only the first cog (temp.main) initializes and none of the code following it is run. The code is supposed to start a new cog and then display a number to confirm that it started. I'm not sure if this is simply how the cognew function works or if my coding is wrong, but I ran it once in the past and all 5 cogs started no problem. Any help or advice would be greatly appreciated. Thanks!
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
pin = 9
baud = 19_200
lines = 2
VAR
LONG TEMP0[9]
LONG PRESS0[9]
LONG CLOCK0[9]
LONG USB0[9]
LONG CAM0[9]
LONG JAR0[9]
BYTE START0
BYTE START1
BYTE START2
BYTE START3
BYTE START4
BYTE START5
OBJ
LCD : "Serial_Lcd.spin"
TEMP : "TEMP.spin"
PRESS : "PRESS.spin"
USB : "USB.spin"
CAM : "CAM.spin"
JAR : "JAR.spin"
CLOCK : "CLOCK.spin"
PUB MAIN
LCD.start(pin, baud, lines)
waitcnt(clkfreq / 100 + cnt)
LCD.backlight(1)
LCD.cursor(3)
LCD.cls
LCD.STR(STRING("STARTING COGS..."))
LCD.NEWLINE
START0 := COGNEW(TEMP.MAIN(1), @TEMP0)
IF START0
LCD.PUTC(9)
LCD.DEC(0)
START1 := COGNEW(PRESS.MAIN, @PRESS0)
IF START1
LCD.PUTC(9)
LCD.DEC(1)
START2 := COGNEW(CLOCK.MAIN(1), @CLOCK0)
IF START2
LCD.PUTC(9)
LCD.DEC(2)
START3 := COGNEW(USB.MAIN(1), @USB0)
IF START3
LCD.PUTC(9)
LCD.DEC(3)
START4 := COGNEW(CAM.MAIN, @CAM0)
IF START4
LCD.PUTC(9)
LCD.DEC(4)
START5 := COGNEW(JAR.MAIN, @JAR0)
IF START5
LCD.PUTC(9)
LCD.DEC(5)
LCD.STOP
Comments
So you're better off embedding the cognew inside the relevant main methods.
Also, readability is improved by embedding your code sample in [noparse] [/noparse] tags.
All your objects should have a start method which contains the COGNEW.
The main you posted here would simply call these start methods instead of doing the COGNEW.
I'd also shift the stack to the object as you can then maintain it's size in case you do changes in the object (for example calling additional PRI functions)