Shop OBEX P1 Docs P2 Docs Learn Events
Using several cogs — Parallax Forums

Using several cogs

eduardomoraiseduardomorais Posts: 11
edited 2011-02-22 19:26 in Propeller 1
Could anyone give me a program where one makes use of several cogs. I'd like to better understand the use thereof.
I'm using the card propeller parallax. It is has a eight cogs.

Thanks already.

Comments

  • Cluso99Cluso99 Posts: 18,069
    edited 2011-02-22 13:36
    eduardomorais: Firstly welcome to the prop.
    Everywhere you look on the forum there is use of multiple cogs. Firstly, the most basic is to use a cog to send/receive to the pc. Next, you can add a VGA monitor (uses a couple of cogs depending on which VGA driver. TV can use 1 or more cogs. A keyboard will use 1 cog. Interfacing to an SD card will use 2 cogs - one for the low level SPI interface and 1 for the FAT implementation. Remember, our drivers take care of a lot of other things normally done in main code is other micros.
    So, our FullDuplexSerial object that does serial does more than just perform a UART function, it actually takes care of everything so all you do is place characters into a buffer and take the received characters out of a buffer.

    The of course, there is ZiCog which performs a whole Z80 & CPM emulation.
  • prof_brainoprof_braino Posts: 4,313
    edited 2011-02-22 19:20
    Hi eduardoramos

    if you are refering to the prop demoboard (or other board with VGA connector) and find propforth on google code, an example that might be interesting is LowResVGA.f
    The propforth kernel runs a user prompt on cog6, which communicates to the PC serial port via cog7. User input entered in the PC terminal propgram is processed interactively.
    Cog3 and cog4 are have user prompts which are displayed on the VGA terminal connected directly to the propboard, and the user input is entered from the keyboard connected directly to the propboard.

    The user can interact with the cogs at the same time, type input into one cog which and change stuff on the other cogs.
  • doggiedocdoggiedoc Posts: 2,245
    edited 2011-02-22 19:26
    eduardomorais - here is a short program I put together as a learning exercise for PASM - it uses all 8 cogs to flash 8 LEDS in an endless loop - it ended up looking pretty cool. My version is based on the Assembly example in the Propeller manual.

    connect LEDs through resisters to pins 16-23
    {{ AssemblyToggle.spin
    toggle leds on pins 8 pins 
    using all 8 cogs }}
    
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    VAR
      long thePin 
    
      
    PUB Main  (loop)
      {Launch cog to toggle LED endlessly}
    
      repeat loop from 16 to 22
        thePin :=  loop
        cognew(@Toggle, @thePin) 'Launch new cog
        waitcnt(clkfreq/2 + cnt) ' Pause
      thePin := 23                'set Pin for cog 0
      coginit (0,@Toggle, @thePin)   'launch Toggle in cog 0
      
    DAT
            {Toggle Pins on cogs}
    
                  org 0                             'Begin at Cog RAM addr 0
    Toggle        rdlong  ScratchMem, par
                  shl     Pin, ScratchMem
                  mov dira, Pin                     'Set Pin to output                              
                  mov ScratchMem, cnt                     'Calculate delay time
                  add ScratchMem, #9                      'Set minimum delay here
                 
                  
    Increment    waitcnt ScratchMem, Delay               'Wait
                  add Delay, IncValue               'Increment Delay value
                  max Delay, MaxDelay wc            'Set Maximum Delay 
                  xor outa, Pin                     'Toggle Pin
            if_nc jmp #Decrement                    'jump to Decrement loop
                  jmp #Increment                       
    
    Decrement    waitcnt ScratchMem, Delay               'Wait
                  sub Delay, IncValue               'Increment Delay value
                  min Delay, IncValue wc            'Set minimum Delay 
                  xor outa, Pin                     'Toggle Pin
            if_c  jmp #Increment                    'jump to increment loop
                  jmp #Decrement
    
                                 
    Pin           long      1                       'Pin variable
    Delay         long       1_000_000               'Clock cycles to delay
    IncValue      long          50_000               'increment value
    MaxDelay      long      20_000_000               'maximum delay
    ScratchMem          res       1                        'System Counter Workspace
    
Sign In or Register to comment.