Shop OBEX P1 Docs P2 Docs Learn Events
Counter, Cogs, Methods and Objects. What runs In what Cog? — Parallax Forums

Counter, Cogs, Methods and Objects. What runs In what Cog?

RonPRonP Posts: 384
edited 2011-08-01 20:06 in Propeller 1
Say for example COG 0's first method launches another COG's Counters using cognew to do something, the counters are counting away and the COG is free to do other stuff this is COG 1. Then COG 0 launches another COG using cognew to do something run a method or object not involving Counters. Will the code be launched in COG 1 or does it get passed to COG 2? If the method or object used the counters what would happen?

Confused Ron

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2011-08-01 19:33
    In order to keep the counters alive you have to keep the cog alive which means cog 1 in your example will (have to) be (kept) busy and is not available for cognew usage. Also, you can't launch another cogs counters as such. You have to launch the cog which in turn starts the counters using a few lines of code.
  • RonPRonP Posts: 384
    edited 2011-08-01 19:51
    Thank you, Kuroneko

    This is what confused me the comments in the SecondProcess Method. So if the counters where running for say a Minute that Cog's processor I guess would be unavailable for that time. The code is from PE Kit Tools. The comments make it sound like the Cog is ready for work.
    VAR
    
      long stack[50]                                ' Stack for SecondProcess
    
    OBJ
    
      sqw : "SquareWave"                            ' Declare Square wave object
    
    PUB go
                                 
      'clkgen.Freq(I/O pin, module=0 or 1, frequency in Hz)
      
      sqw.Freq(4, 0, 10)                            ' P4, channel 0, 10 Hz
      sqw.Freq(5, 1, 25)                            ' P9, channel 1, 25 Hz
    
      'Cog moves on to other jobs and lets counter modules blink the lights.
      waitcnt(clkfreq*3+cnt)                        ' Blink for 10 seconds
    
      cognew(SecondProcess, @stack)                 ' Launch another cog
    
      waitcnt(clkfreq*2+cnt)                        ' 4 square waves, 2 more seconds
    
      sqw.FreqUpdate(0,5)                           ' Channel 0 freq to 5 Hz
    
      waitcnt(clkfreq*2+cnt)                        ' 4 square waves, 2 more seconds
    
      sqw.End(0)                                    ' End Channel 0 transmission
      sqw.End(1)                                    ' End Channel 1 transmission
    
    PUB SecondProcess
    
      ' This second cog uses the same square wave object to configure its counter
      ' modules to create two more square waves.  As with the other cog, this cog's
      ' does not need to do anything to keep the square waves going, so it can move
      ' on to other tasks.
    
      sqw.Freq(6, 0, 11)                            ' P6, channel 0, 17 Hz
      sqw.Freq(7, 1, 23)                            ' P7, channel 1, 25 Hz
    
      waitcnt(clkfreq*5+cnt)                        ' Send for about 5 seconds
    
      sqw.End(0)                                    ' End Channel 0 transmission
      sqw.End(1)                                    ' End Channel 1 transmission
    

    Ron
  • kuronekokuroneko Posts: 3,623
    edited 2011-08-01 20:00
    RonP wrote: »
    So if the counters where running for say a Minute that Cog's processor I guess would be unavailable for that time.
    Unavailable in the sense that it isn't visible in the cognew pool. Because counters run independently of the cogs CPU it can do something else after the counters have been started, e.g. lets say it runs a command/response loop. The first command could either default to start counters or be sent explicitly. Then you send other commands to e.g. copy memory or do some math, after a minute you could tell it to stop the counters and then keep doing other stuff or shut itself down.

    In the example you posted it just waits because it doesn't have anything useful to do. It's your choice in the end.
  • RonPRonP Posts: 384
    edited 2011-08-01 20:06
    Ok now I got it. Not available for cognew.

    Thanks again Ron
Sign In or Register to comment.