Starting an infinite loop from another cog
RS_Jim
Posts: 1,764
in Propeller 1
I want to send a command from one cog to another that will start an infinite loop in the second cog. example< I am reading an mcp3208 adc in a cog(2 actually as 1 is running a PASM routine to actually read the adc) I want to send a command from COG 0 to the mcp cog with the address of a buffer where to put the results of continuous reads of the adc. I will use the contents of the buffer in my main cog. IF the mcp cog has something like this:
Jim
PUB main(@ibuff) Repeat ibuff[1] == average(1) ibuff[2] == average(2) ... ibuf[8] == average(8)when I call mcp.main will my cog 0 continue to run serving up the contents of ibuff or will it go off and loop forever in the mcp cog?
Jim
Comments
I got my program to compile and all looks ok. I need to finish up analog connections on the hardware and ring out the adc cs,clock, and data pin connections and it is ready for its first test of the adc.
Jim
You can create a background ADC read process that can read the ADC values and store in a hub location and access the values from another routine or cog as long as said cog knows the address. Also maybe use a semaphore to let the cog looking for the ACD data know that the read cycle is completed.
Your cog0 can start all your background cogs up, and if they are set to continuously repeat i.e. keep reading the ADC, the background cogs will keep running in their loops until the prop is reset or a cogstop is issued to stop them. Pretty sure the FullDuplex serial object runs continuously in a dedicated cog.
Here's a tiddier version.
I'm not sure what your question is. Is the "main" method in your example code in a separate object (file)?
If you want a running average of some set number of samples, I'm sure we could help you with that.