Shop OBEX P1 Docs P2 Docs Learn Events
How is data passed from one cog to another? — Parallax Forums

How is data passed from one cog to another?

jaschandlerjaschandler Posts: 23
edited 2015-06-22 16:18 in Propeller 1
I've been jumping all over but the simple things trip me up. I have to see it before I truly understand the concept.

This module is a test module showing me that this module can read data placed on the common wall by another cog.

While editing this was inadvertently posted to the board. I'm trying to remember how to do the tags I hit enter and it was posted...
{
  This is just a test module that lets me know the data from ADS1131 has been read from this cog.  My current problem is I can't
  figute the obvious.  How does this cog read the data placed by the other cog.

}
CON

        _clkmode        = xtal1 + pll16x
        _xinfreq        = 5_000_000

VAR
                                             
  long  data                                              ' This is in hub ram
  
OBJ       

  LED   :       "LED17v2"              ' Starts another cog running the LED driver
  read  :       "ADS1131_readerObj"    ' Starts another cog that turns on the ADS1131 then reads it storing the value

PUB DisplayText | i


read.start  '(@data)    
LED.Display(@textBuffer)

repeat
 waitcnt($8F0000+cnt)
 bytemove(@textBuffer,@data,8)         ' <== I want it to print the data placed 
 waitcnt($8F00000+cnt)
 bytemove(@textBuffer,@text1,8)
   
DAT
textBuffer    byte "_-_-_-",0,0 '8 byte buffer.
text1         byte "******",0   'This is just here temp so I know something is working


This I believe works and the data is on the board
{{&#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
  &#9474; Object Code used for ADS1131 18-Bit ADC     &#9474;
  &#9474; using a standard wheatstone Bridge Sensors  &#9474;
  &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;
                                                                                             
 
    The DATA READY/DATA (DRDY/DOUT) output pin serves two purposes:
      1.  It indicates when NEW Data is ready to be read by dropping from its normally high
          state to low.
      2.  Afterwards on the first rising edge of SCLK, the DRDY/DOUT pin changes its func-
          tion and it then starts
          outputting the ADC converted data w/ the (MSB) most significant bit first i.e.
          bit 17, bit 16, bit 15,...bit 2, bit 1,and the last bit 0.
          Data are shifted out on each subsequent SCLK rising edge.  After all 18 bits have
          been passed, the DRDY/DOUT
          pin is then forced high on the next SCLK rising edge where it remains high until
          the next data cycle is about to start.

    This program waits while monitoring the DRDY/DOUT pin.  As soon as this pin drives
    negative this alogrithim activates.
    It then looks for the first rising edge off the SCLK pin.  The algorithm then measures
    DRDY/DOUT for a high or a low state.
    A 1 (logic high) or 0 (logic low) is then pushed onto the stack.  Once the 18th data
    bit has been read and placed on the stack
    the algorithm pulls data off the stack in (LSB) least significant bit first.  The data
     is then returned in 5 digit Hex format
    "The positive full-scale input produces an output code of 1FFFFh and the negative full-
    scale input produces an output code of 20000h."
    IN BINARY TWO COMPLEMENT format.

                                                             
          5.0V    ADS1131     3.3V                                                                                                                                                                                                                     
           &#61463;  &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488; &#61463;             P8X32A                                                                                                                                                              
           &#9492;&#9472;&#9472;&#9508;AVDD     DVDD&#9500;&#9472;&#9496;  150&#937;   &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;                                                                                                                                                                     
              &#9474;    DRDY/DOUT&#9500;&#9472;&#9472;&#9472;&#9472;&#9472;&#61629;&#61630;&#9472;&#9472;&#9472;&#9472;&#9508; P25         &#9474;   P24 = SCLK for syncronizing &                                                                                                                                              
              &#9474;         SCLK&#9500;&#9472;&#9472;&#9472;&#9472;&#9472;&#61629;&#61630;&#9472;&#9472;&#9472;&#9472;&#9508; P24         &#9474;         comms w/ Data ready/Data out
              &#9474;             &#9474;           &#9474;             &#9474;   P25 = Data ready/Data out      
              &#9474;         PDWN&#9500;&#9472;&#9472;&#9472;&#9472;&#9472;&#61629;&#61630;&#9472;&#9472;&#9472;&#9472;&#9508; P26         &#9474;   P26 = Activate on 1 or 0 place A
              &#9474;             &#9474;           &#9474;             &#9474;         DC in sleep mode                                                         
            &#9484;&#9472;&#9508;        SPEED&#9500;&#9472;&#9472;&#9472;&#9472;&#9472;&#61629;&#61630;&#9472;&#9472;&#9472;&#9472;&#9508; P27         &#9474;   P27 = Speed select for the ADC:                                                                                                                            
            &#61464; &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;           &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;           1. A logic zero 0 sets
                                                                     the chip to 10 samples
                                                                     per second (SPS) or
                                                                  2. A logic one (high)
                                                                  sets the chip to 80SPS

}}                                                                                                                                                
CON
  _clkmode = xtal1 + pll16x                                                    
  _xinfreq = 5_000_000                             

VAR

  long  cog                                               ' This is in hub ram
  long  data                                              '

OBJ
 
PUB start : okay

okay := cog :=          cognew(@entry, @data) + 1         ' NOTE: we send the cog the address to the hub ram variable data

PUB stop

  if cog
    cogstop(cog~ -  1)

DAT

                        org         0
entry                                                     ' When the cog starts par is initialized with the address passed in the coginit command
                                                          ' in this case it was passed @data
                      
                        mov         p,      par           ' load parameter pointer into p (points to global variables)
                                                          ' p is just a copy and keeps par unchanged for later.

StartupADS1131
                        mov         dira,   STARTUP       ' P26 & P27 output low
                        mov         outa,   POWER         ' P26 is shifted high "1" the ADS1131 is now on
                                                          
:loop
                        waitpne     DROUT,  DROUT         ' Wait for data ready (DROUT should drive low)
                        mov         count,  #18
                        mov         _data,  #0
                        
:dataLoop               xor         outa,   SCLK          ' toggle high/low so that DROUT will show data
                        
                                                          ' SCLK should remain low/high for at least 100ns 


                                                          ' capture and store bit(s)
                        test        DROUT,  ina wc        ' sample bit (DROUT) 4 clks = 50ns
                        rcl         _data,   #1           ' store bit (use rcr for opposite order) 50ns + 50ns = 100ns
                        xor         outa,   SCLK
                        djnz        count,  #:dataLoop    ' for all 18 bits 
                        xor         outa,   SCLK          ' toggle DROUT back to high in order to reset DROUT
                        wrlong      _data,  p             ' Write the cog variable _data to the hub variable data
                                                          ' This instruction takes 8..23 clks or 100..287.5ns I want the ADC (ADS1131) to sleep while this is happening
                                                          ' after that I'll remove the nop delays and XOR instruction follows next to take the ADC out of sleep


                                                          ' As long as SCLK remains high the ADS1131 sleeps
                        xor         outa,   SCLK          ' toggle DROUT low to enable ADS1131 to wake up and read the next conversion 
                        jmp         #:loop                '

                                                                                                 
SCLK                    long        |<24                  ' Pin P24                       = $0100_0000
DROUT                   long        |<25                  ' Pin P25                       = $0200_0000        
POWER                   long        |<26                  ' Pin P26                       = $0400_0000
SPEED                   long        |<27                  ' Pin P27                       = $0800_0000
STARTUP                 long        |<26 | |<27 | |<24    ' Pin P26 bitwise OR w/ Pin P27 = $0C00_0000

' And last variables 
p                       res         1
count                   res         1
_data                   res         1


                        fit

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-06-22 07:59
    Which language are you using?

    If the program is running Spin then global variables are shared among all cogs within the same object.

    To post code use:
      Place code here.
    

    Use the "Reply With Quote" button to see how the code was entered.
  • jaschandlerjaschandler Posts: 23
    edited 2015-06-22 08:16
    Thank You Duane. I stumbled all weekend. But now I have to prepare for a party and was hoping someone can push me in the right direction. I'll get back after this party I'm hosting is over.
  • PublisonPublison Posts: 12,366
    edited 2015-06-22 08:27
    What is it you want to change? You can go back to the original post and edit it completely.

    The "CODE" tags seemed to take.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-06-22 09:40
    It looks like you were on the right track.

    The trick isn't sharing variables among cogs, the trick is sharing variables among objects.

    The "start" method of the "read" runs in the same cog as the cog which called it.

    To have the "read" object place the data in the parent object's variable use:
    read.start(@data)  
    

    As you can see I just removed the comment marker.

    In the child object you need:
    PUB start(dataPtr) : okay
    
    okay := cog :=          cognew(@entry, dataPtr) + 1         ' NOTE: we send the cog the address to the hub ram variable data
    

    Now the address points to the parent's hub RAM address. The variable "Data" can be deleted from the child object since it's not used.

    Edit: BTW, I didn't check most of the code. I only looked at how the data address was used.

    @Publison. The first post has been edited and code added. I think he just forgot to remove the part about not knowing how to add code.

    Edit again: I just looked a bit at the rest of the code and I don't think it will work correctly. You want to use use "lcd.dec(data)" to display the value of data. This is assuming the lcd object has a dec method.
  • PublisonPublison Posts: 12,366
    edited 2015-06-22 12:24
    Duane Degn wrote: »

    Thanks Duane. I thought that was the case.
  • jaschandlerjaschandler Posts: 23
    edited 2015-06-22 16:18
    Thank You All...I should be able to figure this puzzle out now...with time I'll be able to help others.
Sign In or Register to comment.