Shop OBEX P1 Docs P2 Docs Learn Events
Counting Cogs — Parallax Forums

Counting Cogs

doggiedocdoggiedoc Posts: 2,245
edited 2011-12-26 17:33 in Propeller 1
Anybody know if there is a way to find out how many cogs are in use at any given time in a program? Besides counting manually, that is.

Thanks,
Doc

Comments

  • sidecar-racersidecar-racer Posts: 82
    edited 2011-12-26 16:52
    Look for sparecogs.spin by Alex. Works great
    Rick
  • doggiedocdoggiedoc Posts: 2,245
    edited 2011-12-26 17:04
    Thanks! I'll check it out.

    I've attached the project I'm fiddling with. It's Chip's SpatialSoundDemo that I've modified to use a 2-axis joystick instead of a mouse. I think I may be running out of cogs or possible I am doing something else wrong.

    if I use cognew like I have here it works, but if I try to check for cogs it doesn't - I've commented out the line the doesn't work.
    CON
    _xinfreq = 5_000_000 ' External Crystal Frequency
    _clkmode = xtal1 + pll16x ' Enabled External Crystal and PLL X16
    
    
    OBJ
      rc         : "RCTime"
    
    VAR
    long joyStickStack[2]
    long UDx, LRy
    long  cog
    
    PUB start : okay 
    
    '  stop  
      cognew(RawUDLR,@joyStickStack)
    '  return cog := cognew(RawUDLR,@joyStickStack) + 1
              
    PUB stop
    
    '' Stop joystick driver - frees a cog
    
      if cog                                                                                                                                    
        cogstop(cog~ -  1)
    
    
    PUB RawUDLR  | UD, LR
    
       repeat
        rc.rctime(4, 1, @LR)
        rc.rctime(2, 1, @UD)
        UDx := UD
        LRy := LR
    
        
    PUB _UD : x    
        x :=  UDx
    
    PUB _LR : y
        y := LRy 
        
    
    
  • Mike GMike G Posts: 2,702
    edited 2011-12-26 17:16
    Since cognew returns the newly started COG ID. How about encoding ( |< ) the COG ID in a byte. Then you can use logic operator to keep track of the COGs in use. You could just keep track of the COGs in an array.
  • kuronekokuroneko Posts: 3,623
    edited 2011-12-26 17:21
    @doggiedoc: Be generous and give your joystick stack a few more longs (I stick with 32 during development). Two is definitely too small.

    Also, the way you use the RCTime object looks wrong. You're supposed to start it and simply read variables which are updated by its background task. Just realised it's in foreground mode. Apologies.
  • doggiedocdoggiedoc Posts: 2,245
    edited 2011-12-26 17:29
    I think I got it. I didn't need cognew there at all. I should be calling the "start" method in RCTIME instead of the rctime method directly. This fixes the cog assignment problem posted above. I figured it out when I was bring to count manually how many cogs I was using.
    {---->replaces mouse.spin for SteroSpatializerDemo
    RC time uses 2axis joystick on pins 4 and 2
    
     }
    CON
    _xinfreq = 5_000_000 ' External Crystal Frequency
    _clkmode = xtal1 + pll16x ' Enabled External Crystal and PLL X16
    
    
    OBJ
      UD         : "RCTime"
      LR         : "RCTime"  
    
    VAR
    
    long UDx, LRy
    
    PUB start
    
        UD.start(4, 1, @UDx)
        LR.start(2, 1, @LRy)
    
        
    PUB _UD : x    
        x :=  UDx
    
    PUB _LR : y
        y := LRy 
        
    
  • doggiedocdoggiedoc Posts: 2,245
    edited 2011-12-26 17:33
    Thank you all for the responses - @kuroneko - I see you had the answer for me right there! Thank you all again.

    Paul
Sign In or Register to comment.