How is data passed from one cog to another?
jaschandler
Posts: 23
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 I believe works and the data is on the board
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
{{┌─────────────────────────────────────────────┐ │ Object Code used for ADS1131 18-Bit ADC │ │ using a standard wheatstone Bridge Sensors │ └─────────────────────────────────────────────┘ 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  ┌─────────────┐  P8X32A └──┤AVDD DVDD├─┘ 150Ω ┌─────────────┐ │ DRDY/DOUT├─────────┤ P25 │ P24 = SCLK for syncronizing & │ SCLK├─────────┤ P24 │ comms w/ Data ready/Data out │ │ │ │ P25 = Data ready/Data out │ PDWN├─────────┤ P26 │ P26 = Activate on 1 or 0 place A │ │ │ │ DC in sleep mode ┌─┤ SPEED├─────────┤ P27 │ P27 = Speed select for the ADC:  └─────────────┘ └─────────────┘ 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
If the program is running Spin then global variables are shared among all cogs within the same object.
To post code use:
Use the "Reply With Quote" button to see how the code was entered.
The "CODE" tags seemed to take.
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:
As you can see I just removed the comment marker.
In the child object you need:
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.
Thanks Duane. I thought that was the case.