PDA

View Full Version : Need code for analog to digital !



alex2
10-26-2006, 01:16 AM
I have four 12-bit analog to digital parallel converters connected to propeller.
I am using one dedicated cog to monitor/poll end-of -conversion (EOC) outputs of those four
ADCs via four i/o pins, one for each EOC.

I need one separate cog for each ADC.
The ADCs are not necessarilly synchronized, so the EOC signals are not changing at the same time.

My generic idea behind the code :

1)Poll the EOCs i/o pins -cog0
2)If any EOC active, determine which one it is and
which cog should be started to get the sample -cog0
3)Poll again -cog0 and at the same time read sample from ADC-cog1,2,3 or 4

How do I start and assign new cogs to process samples coming from each of the four ADCs ?
How will I let the other cogs (1,2,3,4) know that it is time to read sample from ADC latch ?

Please help, getting desperate.

Thanks.

Mike Green
10-26-2006, 09:54 AM
Rather than polling the EOC for each ADC in one cog, how about having a cog do the whole thing? By that I mean that a cog would wait for the EOC output for its ADC to be active, then read the sample from the ADC, store it in a particular memory location for the ADC, then go wait again. The same routine could be used for all four cogs with the pin numbers for the ADCs passed as parameters to the routine and the location to store the result also passed. I don't know how you're interfacing to the ADCs, but suppose each ADC has an EOC pin starting at eocBase, then a block of pins (adcPinCount) for each ADC starting at adcBase. Some "pseudo-code" might look like:



VAR
long ADCvalues[ 4], ADCflags[ 4], stack[64]
PUB initialization | j
repeat i from 0 to 3
ADCflags[j] := false
COGNEW(ADCprocess(eocBase + j, adcBase * adcPinCount + j, j),@stack+j*64)
' Now all ADCs are running and each will set its ADCflags value to true when its ADCvalues is updated.
' After you look at each updated ADCvalue you're interested in, set its ADCflags value to false showing
' that you've used it. The false will get changed to true the next time the ADC finishes its conversion.
PUB ADCprocess(eocPin, adcPin, valueIndex) | x
' Initialize the ADC on eocPin and adcPin
repeat
repeat until ina[eocPin] == 1 ' Wait until eocPin is high
' read adc value into local variable x
ADCvalues[valueIndex] := x ' Makes value globally available
ADCflags[valueIndex] := true ' Indicates that value is available


Post Edited (Mike Green) : 10/26/2006 1:58:46 AM GMT

alex2
10-27-2006, 05:34 AM
Thanks Mike,
that looks like a good way to go about it, I should have thought of that.

I hope I will have some schematics and code later on to share, though
it may take a while.