Shop OBEX P1 Docs P2 Docs Learn Events
Help with New Cogs — Parallax Forums

Help with New Cogs

GeofPriceGeofPrice Posts: 16
edited 2012-12-24 10:43 in Propeller 1
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.

Comments

  • Heater.Heater. Posts: 21,230
    edited 2012-12-24 08:37
    Every COG has it's own control of pin direction with it's own DIRA register.

    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.
  • potatoheadpotatohead Posts: 10,261
    edited 2012-12-24 08:38
    Make sure you are setting pin directions in the new COG too. By default they are inputs.

    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.
  • Heater.Heater. Posts: 21,230
    edited 2012-12-24 08:41
    GeofPrice,

    Forgot to bid you welcome to the forum. What a great day fro a first posting here.
  • Heater.Heater. Posts: 21,230
    edited 2012-12-24 08:44
    potatohead,

    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.
  • potatoheadpotatohead Posts: 10,261
    edited 2012-12-24 08:46
    Funny. I am out in the sticks myself. Connection is good for an idle check in, but not much more.

    @OP: Yes! Welcome. Have fun.
  • Heater.Heater. Posts: 21,230
    edited 2012-12-24 09:22
    Potatohead,
    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.
  • GeofPriceGeofPrice Posts: 16
    edited 2012-12-24 10:43
    Thanks! I knew it was something simple.
Sign In or Register to comment.