Reading All Analog channels

Thread Starter

electronicsLearner77

Joined May 26, 2012
127
There is a requirement where i have to around 20 different analog channels some crossing AN32 like AN55 etc in dspic33ev256gm106. There does not seem to be a single ADC initialization method where i can read all the channels at one time in interrupt. What is the best optimized initialization method i can do to read all the channels. Please advise.
 

GopherT

Joined Nov 23, 2012
8,009
There is a requirement where i have to around 20 different analog channels some crossing AN32 like AN55 etc in dspic33ev256gm106. There does not seem to be a single ADC initialization method where i can read all the channels at one time in interrupt. What is the best optimized initialization method i can do to read all the channels. Please advise.
First you need to realize that a PIC has a limited. Number of actual ADCs, the pins labeled AN1-ANx, are "ADC Channels" with can be selected to connect to the actual ADC through internal switching. This internal switching to connecting of many pins to one peripheral (ADC in this case) is known as multiplexing.
 

atferrari

Joined Jan 6, 2004
5,011
There is a requirement where i have to around 20 different analog channels some crossing AN32 like AN55 etc in dspic33ev256gm106. There does not seem to be a single ADC initialization method where i can read all the channels at one time in interrupt. What is the best optimized initialization method i can do to read all the channels. Please advise.
Maybe you could go away by reading all channels "at one time" in the same ISR accepting they have to be read one after the other with a certain delay in between. There are even some micros that could do two at a time but those values you have to process them one after the other.

Could you say what is the use and why do you need all them read at once?
 

nsaspook

Joined Aug 27, 2009
16,321
Take a look at the dsPIC33/PIC24 ADC manual: http://ww1.microchip.com/downloads/en/DeviceDoc/70621c.pdf

It's possible to use one S/H Channel to auto scan inputs.
16.6.3 Channel Scanning

The ADC module supports the Channel Scanning mode using CH0 (S&H Channel 0). The number of inputs scanned is software-selectable. Any subset of the analog inputs, from AN0 to AN31 (depending on the number of analog inputs present on a specific device), can be selected for conversion. The selected inputs are converted in ascending order. For example, if the input selection includes AN4, AN1 and AN3, the conversion sequence is AN1, AN3 and AN4. The conversion sequence selection is made by programming the ADCx Channel Select register (ADxCSSL). A logic ‘1’ in the ADCx Channel Select register marks the associated analog input channel for inclusion in the conversion sequence. The Channel Scanning mode is enabled by setting the Channel Scan bit (CSCNA) in ADCx Control Register 2 (ADxCON2<10>). In Channel Scanning mode, MUXA software control is ignored and the ADC module sequences through the enabled channels. In devices without DMA or with the ADC DMA Enable bit (ADDMAEN) clear, for every sample/convert sequence, one analog input is scanned. The ADC interrupt must be generated after all selected channels are scanned. If “N” inputs are enabled for channel scan, an interrupt must be generated after the “N” sample/convert sequence. Table 16-12 lists the SMPIx values to scan “N” analog inputs using CH0 in different ADC configurations.
 

crutschow

Joined Mar 14, 2008
38,503
If you need to read all channels at exactly the same time then you either need a separate A/D for each channel, or a sample-and-hold circuit for each channel.

How often do you need to read each channel?
 

Thread Starter

electronicsLearner77

Joined May 26, 2012
127
Ok i understand. Can you confirm if the following initialization is ok. On power ON i initialiaze say AN1 to channel 0 and generate an interrupt after single sample and convert. In the interrupt i read the ADC buffer value then i again reinitialize in the interrupt to connect AN2 to channel 0 and so on. Is it correct method? My only fear is it keeps generating the interrupt. Any better method you can suggest?
 

nsaspook

Joined Aug 27, 2009
16,321
Ok i understand. Can you confirm if the following initialization is ok. On power ON i initialiaze say AN1 to channel 0 and generate an interrupt after single sample and convert. In the interrupt i read the ADC buffer value then i again reinitialize in the interrupt to connect AN2 to channel 0 and so on. Is it correct method? My only fear is it keeps generating the interrupt. Any better method you can suggest?
Your interrupt code can enable or disable adc interrupts, conversions while channel switching if that's the way you want to design the software.

Sure there are better methods, that chip can automatically scan selected channels, sample/hold/convert each channel and then transfer all the results via DMA to the buffer of your choice with a single interrupt when all selected channels are done.
 

Thread Starter

electronicsLearner77

Joined May 26, 2012
127
I thought of enabling channel scan, but the limitation is it can scan only channels from 0 to 31. Some of my channels fall beyond 31, so did not know how to initialize those channels.
 
Top