Shop OBEX P1 Docs P2 Docs Learn Events
Quick coginit question — Parallax Forums

Quick coginit question

mikedivmikediv Posts: 825
edited 2009-01-06 23:01 in Propeller 1
I was using one of the sample code examples in methods and cogs it goes somehting like this
VAR
··· long stack[noparse][[/noparse]30]
PUB LaunchBlinkCogs
··· coginit( 1, Blink(4, clkfreq/3, 9), @stack[noparse][[/noparse]0])··· ' Ijust initialized a cog number1
··· coginit(22, Blink(5, clkfreq/7, 21), @stack[noparse][[/noparse]10])· ' I turned on cog 22 how can that be!!!!
··· coginit(3, Blink(6, clkfreq/11, 39), @stack[noparse][[/noparse]20])

PUB Blink( pin, rate, reps)
··· dira[noparse][[/noparse]pin]~~
··· outa[noparse][[/noparse]pin]~
···
··· repeat reps * 2
······ waitcnt(rate/2 + cnt)
······ !outa[noparse][[/noparse]pin]
it blinks some leds I am sure you guys can figure that out by reading code. My question is
when typing I accidently put this in coginit(22, Blink(5, clkfreq/7, 21), @stack[noparse][[/noparse]10])· '·I compiled it
and the program ran just fine I then on purpose when I saw this program seemed to work added 3 more lines with
coginit(12, Blink(5, clkfreq/7, 21), @stack[noparse][[/noparse]10])· '· downloaded it and ran the program the Leds all blinked and the program appears to run just fine
but if there are only 8 cogs how can this be?? is spin just defaulting to a know cog state,, and since my program appears to work
is there anyway to actualy see the cogs running in real time? how can I tell which cogs were actualy started if any?

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-01-06 21:50
    First of all, you should get out of the habit of using COGINIT. There's almost never a good reason to have it in your programs. Use COGNEW instead. That said, the cogid argument to COGINIT is ANDed with %0111, so 22 actually becomes 6.

    -Phil
  • mikedivmikediv Posts: 825
    edited 2009-01-06 21:54
    Phil why not use coginit ??? Then I know exactly what Cog I have turned on right? Correct me if I am wrong but cognew just turns on a cog randomly? so say I was running an program and needed to shut down a cog that I had a known section of code running in with coginit, I just shutdown the cog number how could I do that with cognew is there a way to know which cogs are doing what?
    Oh thanks that makes sense about the 22 being ANDed
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-01-06 22:30
    COGNEW returns the cog number it has assigned, so you can shut it down when necessary. All cogs are identical. There is absolutely no reason to favor one over another when starting them up. In fact, you could easily run afoul of an already running cog started by another object if you use COGINIT. The best rule of thumb is to make your programs cog-number-agnostic. In other words, just say "No" to COGINIT!

    -Phil
  • mikedivmikediv Posts: 825
    edited 2009-01-06 23:01
    thanks Phil I better understand this now I had an article I was using from an online electronics forum I belong to
    and the moderator insisted the proper way was coginit and at the time it kind of made sense to me, but I just got the manual "didnt realize the whole manual was online I thought Parallax charged for the book its very nice of them to make it available I guess thats why I keep ordering stuff from them everyday LOL this is a worse addiction than crack. wife is going to freak when she sees my credit card bill. my office looks like a mad scientist I have wire wrapped circuit boards everwhere I now own at least one of everything Parallax sells ,really! and Boe-Bot keeps pissing off her dog ... Anyway Phil if you see this and get around to it. another problem I could use some help with

    I am trying to add my own objects to code I am writing while I can seem to use others from the object files my sample code is not working here is somehting very simple I tried to do can you see wher eI am going wrong.

    Thank you in advance ..

    Top File: CogObjectExample.spin
    Blinks an LED circuit for 20 repetitions.· The LED
    blink period is determined by how long the P23 pushbutton
    is pressed and held.
    OBJ
    ··· Blinker : "Blinker"
    ··· Button· : "Button"
    ··· mike : "myobject"

    PUB ButtonBlinkTime | time

    ··· repeat
    ······ time := Button.Time(23)
    ······ Blinker.Start(4, time, 20)
    ······ Mike.start
    The object myobject is just another blinker program here """"""""""""""""""""""""""""""""""""""""""""

    PUB Blink | pin, rate, reps
    ··· pin := 6
    ··· rate := clkfreq/3
    ··· reps := 9
    ··· dira[noparse][[/noparse]pin]~~
    ··· outa[noparse][[/noparse]pin]~
    ···
    ··· repeat reps * 2
    ······ waitcnt(rate/2 + cnt)
    ······ !outa[noparse][[/noparse]pin]
    it just blinks pin 6 no big deal but I wanted to call it into the main program just trying to learn to bring in objects/methods but every time I try to compile it I get the error expected a subroutine name? I also tried
    mike.start or object.start., nothing seems to work right I just want to be able to properly incorporate drivers and other program bits into my main program .
Sign In or Register to comment.