cancel
Showing results for 
Search instead for 
Did you mean: 

Detection of different ADC channel from same ADC1?

parag
Associate II
Posted on May 13, 2011 at 21:41

Detection of different ADC channel from same ADC1?

8 REPLIES 8
picguy2
Associate II
Posted on May 17, 2011 at 14:34

RTFM - (Read The Fine Manual) In my copy of RM0008 on page 146 of 681 we read:

10.3.3 Channel selection

There are 16 multiplexed channels. It is possible to organize the conversions in two groups: regular and injected. A group consists of a sequence of conversions which can be done on any channel and in any order. For instance, it is possible to do the conversion in the following order: Ch3, Ch8, Ch2, Ch2, Ch0, Ch2, Ch2, Ch15.

The regular group is composed of up to 16 conversions. The regular channels and their order in the conversion sequence must be selected in the ADC_SQRx registers. The total number of conversions in the regular group must be written in the L[3:0] bits in the ADC_SQR1 register.

[End snip from RM0008]

You will likely want to use DMA.  Using DMA and continuous mode ADC values are dumped into a circular buffer without software intervention.  I used an interrupt at the end of a group to post the address of the latest values.  I believe you can use a 3 half-word receive area where each 16-bit half word is updated.  (I have used 4 channels that way.)  Use a timer to start the next round of conversions.

Or you could use the injected channels.  Each injected channel has its own converted result register.

raptorhal2
Lead
Posted on May 17, 2011 at 14:34

Here is another way of looking at your problem:

Use a DMA channel to convert a group of ADC channels. When you initialize the DMA structure, point the MemoryBaseAddress to a 3 word buffer (e.g., (u32)&MyADCBuffer) and set BufferSize to 3. When you initialize the ADC structure, set NbrOfChannel to 3. Then code 3 ADC_RegularChannelConfig statements to convert ADC Channel__x, y where x are 12, 13 and 14 in any sequence you want and y is the conversion sequence 1, 2, 3.

Your ADC channels conversion results will then be in the 3 word buffer in the x sequence.

Cheers, Hal

marcot
Associate II
Posted on May 17, 2011 at 14:34

Unlike almost everybody else, ST doesn't have a register per channel.  You either read after each conversion or use the DMA.

Extract from the manual:

Analog-to-digital converter (ADC) RM0033

216/1317 Doc ID 15403 Rev 3

10.8 Data management

10.8.1 Using the DMA

Since converted regular channel values are stored into a unique data register, it is useful to

use DMA for conversion of more than one regular channel. This avoids the loss of the data

already stored in the ADC_DR register.

When the DMA mode is enabled (DMA bit set to 1 in the ADC_CR2 register), after each

conversion of a regular channel, a DMA request is generated. This allows the transfer of the

converted data from the ADC_DR register to the destination location selected by the

software.

Despite this, if data are lost (overrun), the OVR bit in the ADC_SR register is set and an

interrupt is generated (if the OVRIE enable bit is set). DMA transfers are then disabled and

DMA requests are no longer accepted. In this case, if a DMA request is made, the regular

conversion in progress is aborted and further regular triggers are ignored. It is then

necessary to clear the OVR flag and the DMAEN bit in the used DMA stream, and to reinitialize

both the DMA and the ADC to have the wanted converted channel data transferred

to the right memory location. Only then can the conversion be resumed and the data

transfer, enabled again. Injected channel conversions are not impacted by overrun errors.

I hope that it helps.

parag
Associate II
Posted on May 17, 2011 at 14:34

Thank you so much guys. It helps me a lot.

One more question, I never work on DMA, just I wanted to know how to read the data once result got stored in memory(using DMA)?

raptorhal2
Lead
Posted on May 17, 2011 at 14:35

The conversion results are in MyADCBuffer[], which is declared in your program, so you can access the results just like accessing the contents of any array.

Cheers, Hal

parag
Associate II
Posted on May 17, 2011 at 14:35

Thanks baird

Could you please tell how to point a mem. address to adcbuffer i am getting an error?

parag
Associate II
Posted on May 17, 2011 at 14:35

Ohh thanks baird, I got it.

Thanks once again all of you.

antoniocorregedor
Associate II
Posted on October 10, 2011 at 22:04

Just wanted to thank you guys for this post, it proved useful in helping me getting my code up and running with the DMA and ADC.  Keep up the good work :)