2011-05-13 12:41 PM
Detection of different ADC channel from same ADC1?
2011-05-17 05:34 AM
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.2011-05-17 05:34 AM
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, Hal2011-05-17 05:34 AM
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) RM0033216/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.2011-05-17 05:34 AM
2011-05-17 05:35 AM
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, Hal2011-05-17 05:35 AM
Thanks baird
Could you please tell how to point a mem. address to adcbuffer i am getting an error?2011-05-17 05:35 AM
Ohh thanks baird, I got it.
Thanks once again all of you.2011-10-10 01:04 PM
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 :)