Another Cognew Question
hover1
Posts: 1,929
Seems to be the day for a cognew questions.
I am new to cognew, but I completely understand the concept of
But I am trying to use the PWM_32_v2.spin object and I'm not sure I'm using cognew and passing parameters correctly.
I and trying to use different different parameters for each cog, but the attached spin program has them all set the same for testing.
Cog1 starts OK but goes unstable after a while.
Cog2 and 3 never start at a stable state.
Output is based on the 3 LED's I have connected to P0, P1, P2.
Code in question posted below.
My first post for help, I held out as long as I could.
TIA,
Jim
I am new to cognew, but I completely understand the concept of
' FEWER COMMENTS (EASIER TO READ) ' ' EXAMPLE03 ' ' USING TWO COGS (TWO PROCESSORS) '***************************************************************************** 'IMPORTANT: This example requires an understanding of examples 01 and 02. '***************************************************************************** 'DIFFICULTY LEVEL: Easy '***************************************************************************** 'CORRECT OUTPUT: The LEDs at A16 and A17 should blink on and off every second. ' Both should blink on and off at the same time. 'Submitted by Dave Scanlan, March 15, 2006 'File: Example03_FewerComments.spin '***************************************************************************** CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 High = 1 Low = 0 ' VAR long stack0[noparse][[/noparse]20] long stack1[noparse][[/noparse]20] ' PUB Start cognew(BlinkingLED_A16, @stack0) cognew(BlinkingLED_A17, @stack1) ' PRI BlinkingLED_A16 | Pin Pin := 16 DirA[noparse][[/noparse]Pin] := %1 Repeat 5 OutA[noparse][[/noparse]Pin] := High WaitCnt(40_000_000 + Cnt) OutA[noparse][[/noparse]Pin] := Low WaitCnt(40_000_000 + Cnt) ' PRI BlinkingLED_A17 | Pin Pin := 17 DirA[noparse][[/noparse]Pin] := %1 Repeat 5 OutA[noparse][[/noparse]Pin] := High WaitCnt(40_000_000 + Cnt) OutA[noparse][[/noparse]Pin] := Low WaitCnt(40_000_000 + Cnt)
But I am trying to use the PWM_32_v2.spin object and I'm not sure I'm using cognew and passing parameters correctly.
I and trying to use different different parameters for each cog, but the attached spin program has them all set the same for testing.
Cog1 starts OK but goes unstable after a while.
Cog2 and 3 never start at a stable state.
Output is based on the 3 LED's I have connected to P0, P1, P2.
Code in question posted below.
My first post for help, I held out as long as I could.
TIA,
Jim
Comments
The 2nd is the pin in the duty call on rampdown is 0 in all cogs - I dont think that is what you want.
A more general question is since pwm runs a cog and does the work why you need 3 cogs for ramp up/down, there is nothing to stop you doing ramp up/down on multiple pins in 1 cog.
First think I did was to push stack space to 1000 just to make sure.
Doh!! Rampdown pin was right before, must have done some cut/paste this morning.
Why newcog? The first routine never ends. I wold like to run 16 of these routines at different speeds. I looked at Phil's past post but did not catch the jist of it right of the·bat
>"Tim,
>You can start several instances of pwmx8, thus:
>You can then define your own Duty method, thus:
>-Phil
Did you have any success with that?
Thanks,
Jim
·
Going to·change resistors tonight to see if I'm not overloading the Prop·im some way.
Thanks for the input, I was just trying to see if my syntax was correct. I guess I was on the right track for now.
Jim
I did something a while ago, it was a table driven system - it had a list of outputs and delays. Each output had a list of delays, output value
e.g.
output 1, 1 { start value}, 10 {no of changes}, 1000 {ms to next change}, 100, 50, 2000, 50, ...
output 2, 0, ...
...
what this meant was output 1 would start on, it had 10 changes before it looped, in 1000ms change to 0, 100ms after change to 1, 50ms change to 0, etc.
In your case make it delay/duty value pairs. Then 1 cog can just read all the tables looking for hte next change, and loop doing that.
I'll check out that method.
Thanks again!
Jim