How many analog reads can occur simultaneously?

If I set up several threads to read analog signals from several pins at the same time, is the G120 (cobra II) going to get angry with me?

Simply put, are there any problems with assigning ONE pin to ONE thread and have it run? (no shared resources) IE The ADC isn’t multiplexed all pins / etc?

To my opinion, this should not be a problem.

in most devices the ADC is multiplexed. you will have to check the chip manual for the exact configuration. only one read at a time.

I’m pretty convinced the device can NOT read from multiple analogs ADCs at the same time.

When running tightly parallelized; I get strange unexpected readings from the pins. But when I run sequentially, the readings are what I expect. The results feels the same as when reading/writing from unlocked doubles on two threads… 1/2 of the value is new, 1/2 is old.

@ JustinKScott - For software compatibility with all the FEZ boards, I would assume use of a multiplexor. The only question I would have is whether some of the newer/larger boards/chips might have two multiplexors. That is why I said the chip manual would have to be checked.

The thing that I do not understant is that even if ADC are multiplexed and that you are in multi thread application, you still have at fine grain only one thread accessing your ADC. Our devices are not multicores (as far as I know) and therefore even if you have two threads in parallel and if analog read is an atomic operation (I suppose that this is the case) this shouldn’t be a problem.

@ leforban - there is internal wait time for the multiplexor to settle after switching the channel. during this wait time, the dispatcher could switch tasks, and the other thread could then switch the channel. when the first thread wakes up, it would read the wrong channel.

If this is the case this would indicate that analog read is not an atomic operation and is not thread safe leading in problem such as the one that have JustinKScott.

correct.

You can’t read the wrong channel as they are stored in different hardware registers. The max scan rate for the G120 is 400KHz but the only way you will be able to read at anyway near this rate is via a custom RLP routine. This is not as daunting as it sounds.

Is your problem that you need to read multiple ADC channels at a very high rate or do you need the reads to be as close to simultaneous as possible? If the latter there is a hardware pin triggered conversion mechanism that you could run using REGISTER without going into RLP.

Really? So your saying the output of the ADC , is sent to separate hardware registers? Which chip are you referring to?

Yes, It’s an NXP178x. http://www.nxp.com/documents/user_manual/UM10470.pdf page 824. It even has a conversion done and overrun flag.

You can read it directly

      private static Register AD0DR0 = new Register(0x4003010);//channel 1 ADC result register
        private static Register AD0DR1 = new Register(0x40034014);//etc etc
        uint val = (AD0DR0 .Read() >> 4) & 0xFFF;

Look at the ADC diagram on page 819. One ADC with Mux.

From page 827:

Once an ADC conversion is started, it cannot be interrupted. A new software write to 
launch a new conversion or a new edge-trigger event will be ignored while the previous 
conversion is in progress.

Answer to original question, one read at a time.