Code review with multiple cogs and cognew
Brian218
Posts: 92
I am really stuck when it comes to using multiple cogs. I wrote the following code in-order to understand multiple cogs, and can't get it to run correctly. Could someone review my code and let me know what I'm doing wrong? As it is I'm not getting the leds to illuminate at all.
Thanks
Addendum....I uploaded the actual file, the 'cut and paste' in the original post did not show the correct spacing.
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
VAR
LONG STACK[noparse][[/noparse]20]' STACK SPACE FOR NEW COG
LONG STACK1[noparse][[/noparse]20]
LONG STACK2[noparse][[/noparse]20]
PUB MAIN
DIRA[noparse][[/noparse]0..7]~~ 'SET PINS TO OUTPUT
DIRA[noparse][[/noparse]24..26]~~
COGNEW(SLOW, @STACK)
COGNEW(MEDIUM, @STACK1)
COGNEW(FAST, @STACK2)
PUB SLOW
REPEAT
!OUTA[noparse][[/noparse]0..2] ' TOGGLES 3 GREEN LEDs
WAITCNT(80_000_000 + CNT)
PUB MEDIUM
REPEAT
!OUTA[noparse][[/noparse]3..6] ' TOGGLES 3 YELLOW LEDs
WAITCNT(40_000_000 + CNT)
PUB FAST
REPEAT
!OUTA[noparse][[/noparse]24..26] ' TOGGLES 3 RED LEDs
WAITCNT(10_000_000 + CNT)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
This post is a work of art. Variations in spelling and grammar are intentional, artistic endeavors that add value to all of mankind.
Post Edited (Brian218) : 10/1/2008 11:47:03 AM GMT
Thanks
Addendum....I uploaded the actual file, the 'cut and paste' in the original post did not show the correct spacing.
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
VAR
LONG STACK[noparse][[/noparse]20]' STACK SPACE FOR NEW COG
LONG STACK1[noparse][[/noparse]20]
LONG STACK2[noparse][[/noparse]20]
PUB MAIN
DIRA[noparse][[/noparse]0..7]~~ 'SET PINS TO OUTPUT
DIRA[noparse][[/noparse]24..26]~~
COGNEW(SLOW, @STACK)
COGNEW(MEDIUM, @STACK1)
COGNEW(FAST, @STACK2)
PUB SLOW
REPEAT
!OUTA[noparse][[/noparse]0..2] ' TOGGLES 3 GREEN LEDs
WAITCNT(80_000_000 + CNT)
PUB MEDIUM
REPEAT
!OUTA[noparse][[/noparse]3..6] ' TOGGLES 3 YELLOW LEDs
WAITCNT(40_000_000 + CNT)
PUB FAST
REPEAT
!OUTA[noparse][[/noparse]24..26] ' TOGGLES 3 RED LEDs
WAITCNT(10_000_000 + CNT)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
This post is a work of art. Variations in spelling and grammar are intentional, artistic endeavors that add value to all of mankind.
Post Edited (Brian218) : 10/1/2008 11:47:03 AM GMT
spin
975B
Comments
You have
which will not work. A more correct version would be
**I just went back and uploaded the actual file; sorry for any confusion.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
This post is a work of art. Variations in spelling and grammar are intentional, artistic endeavors that add value to all of mankind.
Post Edited (Brian218) : 10/1/2008 11:08:28 AM GMT
example:
PUB SLOW
DIRA[noparse][[/noparse]0..2]~~
REPEAT
··· !OUTA[noparse][[/noparse]0..2] ' TOGGLES 3 GREEN LEDs
··· WAITCNT(80_000_000 + CNT)
Post Edited (agfa) : 10/1/2008 12:10:00 PM GMT
When you use DIRA in the method which executes the CogNew it is setting DIRA for its Cog only, not for the Cogs which will started by CogNew.
If you make your launched Cog code more complicated you may need to increase the size of your stack. If you hit any peculiar behaviour try that as a first resort.
Thanks again
B-218
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
This post is a work of art. Variations in spelling and grammar are intentional, artistic endeavors that add value to all of mankind.