Quickstart Demo 5 Multiple Cogs
g3cwi
Posts: 262
Hi all
I just downloaded the Quickstart demo from:
http://www.parallaxsemiconductor.com/quickstart5
This is supposed to show multiple cogs doing different stuff - but it does not on my Quickstart board. It flashes 3 LEDs at the rate determined by the last cognew statement. I was expecting to see three LEDs flashing at different rates - but I don't. Have I misunderstood the intention of the program?
Puzzled.
Edit: actually all three Leds flash the same rate but that rate seems to vary with time. Nothing is obviously being done independently.
Regards
Richard
I just downloaded the Quickstart demo from:
http://www.parallaxsemiconductor.com/quickstart5
This is supposed to show multiple cogs doing different stuff - but it does not on my Quickstart board. It flashes 3 LEDs at the rate determined by the last cognew statement. I was expecting to see three LEDs flashing at different rates - but I don't. Have I misunderstood the intention of the program?
{{ QuickStart 5: MulticogTwinkleDemo.spin www.parallaxsemiconductor.com }} CON _clkmode = xtal1 + pll16x 'Establish speed _xinfreq = 5_000_000 '80Mhz OBJ led: "E555_LEDEngine.spin" 'Include LED methods object VAR byte Counter 'Establish Counter Variable long stack[90] 'Establish working space PUB Main cognew(Twinkle(16,clkfreq/50), @stack[0]) 'start Twinkle cog 1 cognew(Twinkle(19,clkfreq/150), @stack[30]) 'start Twinkle cog 2 cognew(Twinkle(22,clkfreq/100), @stack[60]) 'start Twinkle cog 3 PUB Twinkle(PIN,RATE) 'Method declaration repeat 'Initiate a master loop repeat Counter from 0 to 100 'Repeat loop Counter led.LEDBrightness(Counter, PIN) 'Adjust LED brightness waitcnt(RATE + cnt) 'Wait a moment repeat Counter from 100 to 0 'Repeat loop Counter led.LEDBrightness(Counter,PIN) 'Adjust LED brightness waitcnt(RATE + cnt) 'Wait a moment
Puzzled.
Edit: actually all three Leds flash the same rate but that rate seems to vary with time. Nothing is obviously being done independently.
Regards
Richard
Comments
As it is now, the variable Counter is being changed by three different cogs. Not a good way to do this (IMO).
Here's my suggestion.
Comment out the global "Counter" variable.
And make it local.
It should then behave as expected.
With these changes, the each cog uses its own variable "counter" so the other cogs aren't affecting it like the original program.
(I think.)
I fixed the demo code to be multi-cog so nobody shares any variables in the object or in the main program.
Now it's a happy and productive member of the Demo world!
That's much better thanks. It now looks like the LEDs are being independently controlled (which is what was presumably intended). That's a change Parallax might do well to consider!
Rick - thanks too. I like demos that demonstrate what they suggest they will!
Regards
Richard
I haven't tried running this program, but I don't see a need to include multiple instances when run from different cogs. It makes use of the cogs counters which shouldn't interfere with one another (as long as they're be run from different cogs).
I just updated it to use all 8 COGs, so I'lltry it with just one object instance......stay tuned.
I guess you're right. It appears to work with the localized counter variable and a single object instance. The object itself doesn't have any variable space and everything it does is with the passed variable (on the stack?). I need to learn my SPIN better!!
Here's and 8 COG version with a single object instance.....it's running on my desk now and is very relaxing!
Stack is way to big - the object says 11 longs, but for a demo, we have plenty of memory.
Just done that.
Cheers