Shop OBEX P1 Docs P2 Docs Learn Events
Cogs and Objects returning situacion — Parallax Forums

Cogs and Objects returning situacion

HED GROUPHED GROUP Posts: 15
edited 2009-03-07 05:51 in Propeller 1
{{
Hi to everybody can somebody explain us why if we use more than one cog
and call a endless method in the main program the program continue and
cog 2 and 3 blinks led 16 and 23 with led 19 bliking faster.
BUT? if you run the same program using the same method P2 and P3 from a
different object (test1)the first cog (2) run and blink led 16 but the program
stay in that endless method and don't continue with the next instruction.
Is like never return to cog 0 when the cog 2 run it's method from another
object. (Cogs runnig in the same main program have no problem. Cogs runnig
an endless method from another object never return from the first cog - Why ???.
}}

CON
· _clkmode = xtal1+pll16x
· _xinfreq = 5_000_000
VAR
· LONG· cog2ram[noparse][[/noparse]64]
· LONG· cog3ram[noparse][[/noparse]64]
OBJ
· lcd : "TEST1"
PUB Init
COGINIT(2,P2,@COG2ram) ''Blink led 16
COGINIT(3,P3,@COG3ram) ''Blink led 23
DIRa[noparse][[/noparse]19]~~
REPEAT
·!OUTa[noparse][[/noparse]19] ''Blink led 19
·waitcnt(clkfreq / 20 + cnt)
{{===============================================
· COPY ALSO THE FOLLOWING METHODS TO "TEST1" FILE
· Remplace the 2 cogs lines with the following:
· COGINIT(2,lcd.P2,@COG2ram)
· COGINIT(3,lcd.P3,@COG3ram)
· ===============================================
}}
··
PUB P2
DIRa[noparse][[/noparse]16]~~
REPEAT
·!OUTa[noparse][[/noparse]16] ''Blink led 16
·waitcnt(clkfreq + cnt)
···
PUB P3
DIRa[noparse][[/noparse]23]~~
REPEAT
·!OUTa[noparse][[/noparse]23] ''Blink led 23
·waitcnt(clkfreq + cnt)
·

Comments

  • TreeLabTreeLab Posts: 138
    edited 2009-03-07 05:17
    There has been some discussion recently that concluded that you should never pass the address of a spin routine that is in another object to cognew (a relative of coginit. Here is the topic link

    http://forums.parallax.com/forums/default.aspx?f=25&m=331701&g=331706#m331706

    Mike Green's comment is the one to consider carefully.

    Cheers!
    Paul Rowntree
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-03-07 05:51
    HED GROUP,

    Here is a way to accomplish what you want to do...

    MainTest.spin
    CON
      _clkmode = xtal1+pll16x
      _xinfreq = 5_000_000
    OBJ
      lcd : "TEST1"
    
    VAR
    '  LONG  cog2ram[noparse][[/noparse]64]
    '  LONG  cog3ram[noparse][[/noparse]64]  
    
    PUB Init
    'COGINIT(2,P2,@COG2ram) ''Blink led 16
    'COGINIT(3,P3,@COG3ram) ''Blink led 23
    
    'COGINIT(2,lcd.P2,@COG2ram)
    'COGINIT(3,lcd.P3,@COG3ram)
    
    lcd.P2
    lcd.P3
    
    
    DIRa[noparse][[/noparse]19]~~
    REPEAT
     !OUTa[noparse][[/noparse]19] ''Blink led 19
     waitcnt(clkfreq / 20 + cnt)
    {{===============================================
      COPY ALSO THE FOLLOWING METHODS TO "TEST1" FILE
      Remplace the 2 cogs lines with the following:
      COGINIT(2,lcd.P2,@COG2ram)
      COGINIT(3,lcd.P3,@COG3ram)
      ===============================================
    }}
      
    PUB P2
    DIRa[noparse][[/noparse]16]~~
    REPEAT
     !OUTa[noparse][[/noparse]16] ''Blink led 16
     waitcnt(clkfreq + cnt)
       
    PUB P3
    DIRa[noparse][[/noparse]23]~~
    REPEAT
     !OUTa[noparse][[/noparse]23] ''Blink led 23
     waitcnt(clkfreq + cnt)
    
    




    TEST1.spin
    VAR
      LONG  cog2ram[noparse][[/noparse]64]
      LONG  cog3ram[noparse][[/noparse]64]
    
    PUB P2
        COGINIT(2,P2_,@cog2ram)
    
    PUB P3
        COGINIT(3,P3_,@cog3ram)
    
    PUB P2_
        DIRa[noparse][[/noparse]16]~~
        REPEAT
          !OUTa[noparse][[/noparse]16] ''Blink led 16
          waitcnt(clkfreq + cnt)
       
    PUB P3_
        DIRa[noparse][[/noparse]23]~~
        REPEAT
          !OUTa[noparse][[/noparse]23] ''Blink led 23
          waitcnt(clkfreq + cnt)
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 3/7/2009 5:57:14 AM GMT
Sign In or Register to comment.