Shop OBEX P1 Docs P2 Docs Learn Events
Another Cognew Question — Parallax Forums

Another Cognew Question

hover1hover1 Posts: 1,929
edited 2009-09-09 01:06 in Propeller 1
Seems to be the day for a cognew questions.


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. smile.gif

TIA,
Jim

Comments

  • TimmooreTimmoore Posts: 1,031
    edited 2009-09-08 23:34
    The first thing I would do is increase the stack size from 10 to 100.
    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.
  • hover1hover1 Posts: 1,929
    edited 2009-09-09 00:08
    Timmoore said...
    The first thing I would do is increase the stack size from 10 to 100.

    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.
    Thanks Tim -- all knowing of LED'ssmilewinkgrin.gif

    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:

    [b]OBJ[/b]
    
      pwm[noparse][[/noparse]3] : "pwm_x8"
    
    [b]PUB[/b] Start | j
    
      [b]repeat[/b] j [b]from[/b] 0 to 2
        pwm[noparse][[/noparse]j].Start(j << 3, $ff, 5000)
    
    
    


    >You can then define your own Duty method, thus:

    [b]PUB[/b] Duty(pin, amt)
    
      pwm[noparse][[/noparse]pin >> 3].Duty(pin, amt)
    
    
    


    >-Phil

    Did you have any success with that?

    Thanks,

    Jim

    ·
  • hover1hover1 Posts: 1,929
    edited 2009-09-09 00:36
    Seems to be running better since I (you) fixed the the rampdown problem. I'm still having speratic glitches on all pins, (flickers).

    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


    Timmoore said...
    The first thing I would do is increase the stack size from 10 to 100.
    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.
  • TimmooreTimmoore Posts: 1,031
    edited 2009-09-09 00:51
    I have used both pwm_32_v2 and pwm_x8. I currently use the pwm_32_v2 because I have both pwm and servo outputs and pwm_32_v2 does both and saved a cog.
    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.
  • hover1hover1 Posts: 1,929
    edited 2009-09-09 01:06
    Timmoore said...
    I have used both pwm_32_v2 and pwm_x8. I currently use the pwm_32_v2 because I have both pwm and servo outputs and pwm_32_v2 does both and saved a cog.
    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
Sign In or Register to comment.