Can't start Cog's
BTX
Posts: 674
Hi all !!
I'll trying to get an object with 3 Cogs running, I've a problem like this.
BTX said...
What are happening with the cogs ?
In fact, I can't finish·to understand the·"Stop" method in Output.spin.
Thanks and regards.
Alberto.
·
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)································································ PROBLEM
·· tv.str(string($A,1,$B,2))············································ PROBLEM
·· tv.str(string("Hello Propeller...... "))························· 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.}
With this Object· repeat
··· repeat Index from 0 to MAXLEDS-1
····· if not LED[noparse][[/noparse]Index].Active
······· quit
· while Index == MAXLEDS
The tv_text is correctly called, and I've no signal on TV, how can I solve that, in this example ??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
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
· I changed your clock speed
Brian
Post Edited (truckwiz) : 12/4/2006 2:06:42 AM GMT
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.
How could I avoid that ??
My Blinker.spin is the following:
Seems that a Cog is overrited by the serial driver.
Thanks and Regards.
Alberto.
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
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.
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.
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
Regards.
Alberto.