Help with New Cogs
GeofPrice
Posts: 16
I have a beginner's problem with opening a new cog. I have beat my head against the wall trying to figure why my bigger chunk of code won't work, and I boiled down to this. I am working with the QuickStart Board that has the built in set of LED's on P16 - P23. So this code turns on P16:
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
RunProgSwitchFollower = 16
VAR
long stack[1024]
PUB Main
dira[RunProgSwitchFollower]~~
repeat
outa[RunProgSwitchFollower] := 1
I compile and run this and the LED on P16 comes on. Simple. Now, I try this in a new cog:
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
RunProgSwitchFollower = 16
VAR
long stack[1024]
PUB Main
dira[RunProgSwitchFollower]~~
cognew(SwitchFollower, @stack[0])
PUB SwitchFollower
repeat
outa[RunProgSwitchFollower] := 1
This code does not work. All I've done is move the ouput command to the subroutine and used a new cog to run that. Nothing happens to the LED. So I have added code to interface to the serial terminal, and sent the return value from the COGNEW command to the serial terminal, and the new cog does open. I also added a similar serial terminal output in the repeat loop of the SwitchFollower subroutine, and I get a continuously looping output from the cog. Yet the LED does not come on and P16 doesn't go high with a voltmeter. What gives? The spin manual says that all cogs have access to P0-P31.
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
RunProgSwitchFollower = 16
VAR
long stack[1024]
PUB Main
dira[RunProgSwitchFollower]~~
repeat
outa[RunProgSwitchFollower] := 1
I compile and run this and the LED on P16 comes on. Simple. Now, I try this in a new cog:
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
RunProgSwitchFollower = 16
VAR
long stack[1024]
PUB Main
dira[RunProgSwitchFollower]~~
cognew(SwitchFollower, @stack[0])
PUB SwitchFollower
repeat
outa[RunProgSwitchFollower] := 1
This code does not work. All I've done is move the ouput command to the subroutine and used a new cog to run that. Nothing happens to the LED. So I have added code to interface to the serial terminal, and sent the return value from the COGNEW command to the serial terminal, and the new cog does open. I also added a similar serial terminal output in the repeat loop of the SwitchFollower subroutine, and I get a continuously looping output from the cog. Yet the LED does not come on and P16 doesn't go high with a voltmeter. What gives? The spin manual says that all cogs have access to P0-P31.
Comments
That means if you want the code that runs in a new COG to do some output you have to set DIRA appropriately in that code.
I suggest moving your "dira[RunProgSwitchFollower]~~ " statement into the "SwitchFollower" method.
Do have a look at how the I/O pins work, there are nice descriptions and diagrams in the Propeller manual.
Your SPIN program starts in COG 0, which has output defined, then starts the other COG, which does not. Those definitions are not global.
Edit: slow phone. Heater beat me to it.
Forgot to bid you welcome to the forum. What a great day fro a first posting here.
Slow phone, I dream of a slow phone. Where I am now for the xmas break, I only manage to get a connection at all for a few minutes in an hour or two and then it chops out every half a minute.
@OP: Yes! Welcome. Have fun.
This has the advantage that it keeps your posts short and to the point:)
Glad to see folks getting on with their Christmas projects. It's something of a tradition since getting Lego, Mecano and such thins as presents as a kid.