Shop OBEX P1 Docs P2 Docs Learn Events
just not getting it with cogs — Parallax Forums

just not getting it with cogs

vettezr1vettezr1 Posts: 77
edited 2010-10-05 12:10 in Propeller 1
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

Comments

  • RavenkallenRavenkallen Posts: 1,057
    edited 2010-10-01 18:19
    I don't really get what you are saying....Could you explain a little what you want to do?
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-10-01 19:26
    I hate to sound critical but, based upon the many mistakes in your code, it appears to me that you need to start at the beginning and work your way through the excellent educational labs that Parallax provides at the following link:

    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
  • smbakersmbaker Posts: 164
    edited 2010-10-01 21:32
    vettezr1 wrote: »
    Is this anywhere close to what I need to do?
    thanks guys

    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.
  • bill190bill190 Posts: 769
    edited 2010-10-01 23:05
    As to using cognew and the stack space. Following are two cognews I use in one file. There is a *lot* of other stuff before and between the two cognew's in my file, but I have just plucked these so you can see an example of the VAR listing as they relate to the cognew commands. And two cognew's which work.


    VAR
    long GoStack[120]
    long StackSpaceSendBits[6]

    PUB
    cognew(go, @GoStack )
    cognew(@SendBits, @StackSpaceSendBits)
  • bill190bill190 Posts: 769
    edited 2010-10-01 23:14
    Here is a little more complicated example...


    VAR

    long StackSpaceSonyBits[6] 'Stack space for SonyBits cog
    byte Cog 'To store cog number of SonyBits cog

    PUB

    Cog := (cognew (@SonyBits, @StackSpaceSonyBits))
  • vettezr1vettezr1 Posts: 77
    edited 2010-10-05 11:51
    Thanks Bill I guess I am not being clear I somewhat understand how to use multiple cogs to blink leds.. I do not understand how to use cogs to run "whole programs"..
    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]
  • Mike GreenMike Green Posts: 23,101
    edited 2010-10-05 12:06
    You don't run things like PST or TVdemo "from another cog". It just doesn't work that way. That's why there are no examples of it.

    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.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-10-05 12:10
    vettezr1 wrote: »
    .... I do not understand how to use cogs to run "whole programs"..

    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.
Sign In or Register to comment.