just not getting it with cogs
vettezr1
Posts: 77
Hi guys I am having a little trouble understanding how I can use cogs I can use them to blink LEDs but I want to do more..
In this example can someone show me how to code to say run PST 3 times in differant cogs and also the TV demo in another??
'how to use a few cogs at the same time'
CON
_xinfreq = 5_000_000
_clkmode = xtal1 + pll16x
VAR
long stack[30]
Pub multicogs
cognew(PST@, stack[0])
cognew(PST, @stack[10])
cognewTV_Text_Demo.spin, @stack[20])
Is this anywhere close to what I need to do?
thanks guys
In this example can someone show me how to code to say run PST 3 times in differant cogs and also the TV demo in another??
'how to use a few cogs at the same time'
CON
_xinfreq = 5_000_000
_clkmode = xtal1 + pll16x
VAR
long stack[30]
Pub multicogs
cognew(PST@, stack[0])
cognew(PST, @stack[10])
cognewTV_Text_Demo.spin, @stack[20])
Is this anywhere close to what I need to do?
thanks guys
Comments
http://forums.parallax.com/showthread.php?t=111166
These labs will help you learn, step by step, how to deal with methods, objects, and cogs, etc.
hope that helps you get started,
Mark
Remember that all cogs have access to all pins. Your code doesn't show how you're configuring the PST objects, but it would be a mistake, for example, to configure multiple ones to use the same pins. It's not a matter of just forking off multiple cogs -- one usually needs to put some thought into how the cogs are going to work together to form a cohesive system.
I really like the book "Programming and Customizing the Multicore Propeller Microcontroller: The Official Guide", available from Amazon and other sources. It'll show you lots of real-world examples of how and why you'd want to use multiple cogs.
As others have suggested, post your real code when asking a question, it'll be easier for people to see what's wrong, than trying to guess from pseudocode.
VAR
long GoStack[120]
long StackSpaceSendBits[6]
PUB
cognew(go, @GoStack )
cognew(@SendBits, @StackSpaceSendBits)
VAR
long StackSpaceSonyBits[6] 'Stack space for SonyBits cog
byte Cog 'To store cog number of SonyBits cog
PUB
Cog := (cognew (@SonyBits, @StackSpaceSonyBits))
example this blinks leds using multiple cogs, But what if I Wanted to run a whole new program in another cog? so can anyone show me using this code
how would I run PST and or TVdemo from another cog while this program is running my goal is to be able to run a program to read I/O from one Cog,, have it output data to TV from another cog have yet another cog running the PST program I dont get how to run multiple programs at the same time?
thanks for refering me to manuals I have already read but do not understand hence my posting my question but I am really trying to get help understading what I am asking maybe I am misunderstanding the whole multiple cog concept but I thought we could treat the cogs almost as seperate MCU's? OH Raven thanks I hope this is clear I can not find any examples of running multiple"whole programs from differant cogs
'' From Parallax Inc. Propeller Education Kit - 5: Methods and Cogs Lab
'' BlinkWithCogs.spin
VAR
long stack[30]
PUB LaunchBlinkCogs
cognew(Blink(4, clkfreq/3, 9), @stack[0])
cognew(Blink(5, clkfreq/7, 21), @stack[10])
cognew(Blink(6, clkfreq/11, 39), @stack[20])
PUB Blink( pin, rate, reps)
dira[pin]~~
outa[pin]~
repeat reps * 2
waitcnt(rate/2 + cnt)
!outa[pin]
You have to actually modify the program like PST to run in its own cog. Due to the way Spin works, you can't start a method in a one object using a COGNEW in another object. In other words, you can't have a COGNEW in a "main" object refer to a method in another object. A COGNEW can start up a method in the same object as the COGNEW.
ElectricAye posted a link to a good tutorial. Have a look at it.
You can probably do what you want to do, but you don't run "whole programs" in a cog. Instead, you make Methods, and cogs can call up those Methods when needed. Any variables that you declare in the VAR block will be accessible to all the cogs.