Shop OBEX P1 Docs P2 Docs Learn Events
Can't start Cog's — Parallax Forums

Can't start Cog's

BTXBTX Posts: 674
edited 2006-12-04 15:23 in Propeller 1
Hi all !!
I'll trying to get an object with 3 Cogs running, I've a problem like this.

BTX said...
{{ Blinker2.spin }}
CON
· _CLKMODE = XTAL1 + PLL4X···· 'Set to ext low-speed crystal, 4x PLL
· _XINFREQ = 5_000_000········ 'Frequency on XIN pin is 5 MHz
· MAXLEDS = 6················· 'Number of LED objects to use
OBJ
· LED[noparse][[/noparse]6] : "(Ch3-Ex10)-Output"
· tv···· : "tv_text"
PUB Main
{Toggle pins at different rates, simultaneously}
·· tv.start(12)·······························································confused.gif· PROBLEM
·· tv.str(string($A,1,$B,2))···········································confused.gif· PROBLEM
·· tv.str(string("Hello Propeller...... "))························confused.gif· PROBLEM
·· waitcnt(clkfreq * 10 + cnt)······· ' delay.····················
· dira[noparse][[/noparse]16..23]~~································ 'Set pins to outputs
· LED[noparse][[/noparse]NextObject].Start(16, 250,·· 0)··········· 'Blink LEDs
· LED[noparse][[/noparse]NextObject].Start(17, 500,·· 0)
· LED[noparse][[/noparse]NextObject].Start(18,· 50, 300)
· LED[noparse][[/noparse]NextObject].Start(19, 500,· 40)
· LED[noparse][[/noparse]NextObject].Start(20,· 29, 300)
· LED[noparse][[/noparse]NextObject].Start(21, 104, 250)
· LED[noparse][[/noparse]NextObject].Start(22,· 63, 200)··········· '<-Postponed
· LED[noparse][[/noparse]NextObject].Start(23,· 33, 160)··········· '<-Postponed
· LED[noparse][[/noparse]0].Start(20, 1000, 0)····················· 'Restart object 0
· repeat········································ 'Loop endlessly
PUB NextObject : Index
{Scan LED objects and return index of next available LED object.
·Scanning continues until one is available.}
· repeat
··· repeat Index from 0 to MAXLEDS-1
····· if not LED[noparse][[/noparse]Index].Active
······· quit
· while Index == MAXLEDS
With this Object
BTX said...

{{ Output.spin }}
VAR
· long· Stack[noparse][[/noparse]9]······················ 'Stack space for new cog
· byte· Cog··························· 'Hold ID of cog in use, if any

PUB Start(Pin, DelayMS, Count): Success
{{Start new blinking process in new cog; return True if successful.}}
· Stop
· Success := (Cog := cognew(Toggle(Pin, DelayMS, Count), @Stack) + 1)

PUB Stop
{{Stop toggling process, if any.}}
· if Cog
··· cogstop(Cog~ - 1)

PUB Active: YesNo
{{Return TRUE if process is active, FALSE otherwise.}}
· YesNo := Cog > 0

PUB Toggle(Pin, DelayMS, Count)
{{Toggle Pin, Count times with DelayMS milliseconds
· in between.· If Count = 0, toggle Pin forever.}}
· dira[noparse][[/noparse]Pin]~~······························· 'Set I/O pin to output direction
· repeat···································· 'Repeat the following
··· !outa[noparse][[/noparse]Pin]······························ '· Toggle I/O Pin
··· waitcnt(clkfreq / 1000 * DelayMS + cnt)· '· Wait for DelayMS cycles···
· while Count := --Count #> -1·············· 'While not 0 (make min -1)…
· Cog~······································ 'Clear Cog ID variable
The tv_text is correctly called, and I've no signal on TV, how can I solve that, in this example ??
What are happening with the cogs ?
In fact, I can't finish·to understand the·"Stop" method in Output.spin.
Thanks and regards.
Alberto.
·

Comments

  • [Deleted User][Deleted User] Posts: 0
    edited 2006-12-04 01:53
    Try This ,

    · I changed your clock speed

    Brian


    Post Edited (truckwiz) : 12/4/2006 2:06:42 AM GMT
  • BTXBTX Posts: 674
    edited 2006-12-04 02:08
    Such a stupid thing....PLL16X !!!
    Sorry Brian.
    And thanks so much. !!

    I'll continue tomorrow....just I'm seeing, it's so late to propelling for me, this night..

    Regards
    Alberto.
  • BTXBTX Posts: 674
    edited 2006-12-04 03:19
    Sorry, now I like to add FullDuplexSerial driver to the code, and I have 3 LED non working ??
    How could I avoid that ??

    My Blinker.spin is the following:
    BTX said...
    CON
    · _CLKMODE = XTAL1 + PLL16X···· 'Set to ext low-speed crystal, 4x PLL
    · _XINFREQ = 5_000_000········ 'Frequency on XIN pin is 5 MHz
    · MAXLEDS = 6················· 'Number of LED objects to use

    OBJ
    · LED[noparse][[/noparse]6] : "(Ch3-Ex10)-Output"
    · tv···· : "tv_text"
    · serial : "FullDuplexSerial"

    VAR
    byte pulx

    PUB Main
    {Toggle pins at different rates, simultaneously}···········
    ·· tv.start(12)··················································· '
    ·· serial.start(31,30,%0000,57600)
    ·· tv.str(string($A,1,$B,2))
    ·· tv.str(string("Hello Propeller-1...... "))


    ·· serial.str(string(13,10,"Prueba de envio por serial",13,10))

    ·· pulx := serial.rx
    ·· tv.str(string($A,1,$B,5))
    ·· tv.str(string("Pulx: "))
    ·· tv.dec(pulx)·······

    ·· waitcnt(clkfreq * 2 + cnt)······· ' delay.···················
    · dira[noparse][[/noparse]16..23]~~································ 'Set pins to outputs
    · LED[noparse][[/noparse]NextObject].Start(16, 250,·· 0)··········· 'Blink LEDs
    · LED[noparse][[/noparse]NextObject].Start(17, 500,·· 0)
    · LED[noparse][[/noparse]NextObject].Start(18,· 50, 300)
    · LED[noparse][[/noparse]NextObject].Start(19, 500,· 40)
    · LED[noparse][[/noparse]NextObject].Start(20,· 29, 300)
    · LED[noparse][[/noparse]NextObject].Start(21, 104, 250)
    · LED[noparse][[/noparse]NextObject].Start(22,· 63, 200)··········· '<-Postponed
    · LED[noparse][[/noparse]NextObject].Start(23,· 33, 160)··········· '<-Postponed
    · LED[noparse][[/noparse]0].Start(20, 1000, 0)····················· 'Restart object 0
    · repeat········································ 'Loop endlessly
    PUB NextObject : Index
    {Scan LED objects and return index of next available LED object.
    ·Scanning continues until one is available.}
    · repeat
    ··· repeat Index from 0 to MAXLEDS-1
    ····· if not LED[noparse][[/noparse]Index].Active
    ······· quit
    · while Index == MAXLEDS
    Seems that a Cog is overrited by the serial driver.

    Thanks and Regards.
    Alberto.
  • [Deleted User][Deleted User] Posts: 0
    edited 2006-12-04 04:12
    BTX,
    I'm not the best guy to answer this, but I don't see where you are starting another cog. You should have a COGNEW somewhere in your code


    Brian
  • Mike GreenMike Green Posts: 23,101
    edited 2006-12-04 05:14
    The serial.start call does the COGNEW.

    What are you observing? I don't see an obvious problem except that using the same serial pins that are used for bootstrapping can be a problem. In particular, a change in DTR can cause a reset when you don't expect it.
  • BTXBTX Posts: 674
    edited 2006-12-04 13:06
    Brian and Mike

    The code I'm trying is Blinker2.spin plus Output.spin..

    Output.spin start many cogs to launch LED blinking individually (In the original form of the code).

    But, when I use the "tv_text" and the "FullDuplexSerial" objects, added to Blinker2.spin code, the result is different than when I not use them.

    I fact two LED never blink anymore, so I assume that I have no more cogs for that LED, how can I follow ?? which cogs are using tv_text and Serial driver, to avoid overwrite them in the case I want to add more code and get all LED blinking ?

    My real problem is not this example, ( but the behavior is similar ). I would like to solve this, to put my final code at forum !

    My real code call "tv_text" and the "FullDuplexSerial" objects, then gets data by serial port and show in the TV, then must start 3 new cogs to run steppers (I use the same method like in this 2 examples), the result is the same, cogs were overwrite and no steppers get turn.

    Hope you understand my questions.

    Thanks in advance.

    Alberto.
  • Mike GreenMike Green Posts: 23,101
    edited 2006-12-04 14:51
    tv_text and FullDuplexSerial each start a cog. If you need 3 steppers, that's 3 more cogs. Your original cog makes a total of 6 which still leaves 2 idle cogs. Generally, each object keeps track of which cog it uses and only returns (from the start method) whether it was successful at starting up. Each library object does have a stop method that will stop its cog and possibly do other cleanup. The hardware does keep track of which cogs are available and you should use that model. Create an object for driving a stepper. Use either FullDuplexSerial.spin or tv.spin for a model for a start and stop method. In your main program, set up an array of objects for the stepper driver ("OBJ step : "StepperDriver"), and experiment with starting and stopping them. For test purposes, they just start a cog in SPIN to blink an LED as you're trying to do now.

    Your existing code could be used, but I'd suggest leaving out the more complex parts that look for active LEDs and only have 3 or 4 instances rather than 8 or 9. You know already that there are only 8 cogs and you don't intend to use all of them.

    Post Edited (Mike Green) : 12/4/2006 2:57:52 PM GMT

  • BTXBTX Posts: 674
    edited 2006-12-04 15:23
    Thanks Mike I'll try your sggests

    Regards.
    Alberto.
Sign In or Register to comment.