cancel
Showing results for 
Search instead for 
Did you mean: 

ADC Scan Mode - Help please

matic
Associate III
Posted on July 21, 2015 at 20:56

Hi.

I have to make 8 AD conversions (Channel 0 - Channel 7) and I would like to put converted values in a predetermined array via DMA. I am trying to achieve  that with a SCAN mode (but NOT continuous). Now my questions are:

Do all of the 8 converted values appear simultaneously in my predetermined array or one by one? If the second is true, than I have to worry about that, I'm not reading some of the new and some of the old conversions. Do I have to wait for a TCIF (Transfer Complete Flag) and only than read values from an array?

Also, if I have to wait for that flag,  can I wait for it in a ''while'' loop and make some other computations in that time?

Thank you very much for your help

#stm32f1 #dma #adc
9 REPLIES 9
Mark Edwards
Associate II
Posted on July 21, 2015 at 21:13

They appear sequentially. You could use the DMA’s transfer complete interrupt to set a flag to let you know when they are all done, leaving you free to do something else, or monitor the NDTR register which will let you know which was the last transfer that took place (note: it counts backwards so NDTR – 1 would be the first value in the array).

Posted on July 21, 2015 at 21:57

You can architect your loop in anyway you wish. The DMA TC acts as an EOC for your set on samples. The DMA occurs in the background, and can be quite rapidly depending on you chosen sample rates.

If you have other things to do you can process the new measurements in the TC interrupt. 

If you have some special ordering (rank) you could get the 4 measurements you want in the front of the buffer, and just wait for HT (Half Transfer) for those.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
matic
Associate III
Posted on July 22, 2015 at 16:28

Thanks. One more question.

If I want to do some computations while waiting for a TC flag, do I have to do that in ISR or anywhere else? Let say, is it possible to start ADC and after that went into a ''while'' loop where just waiting for a TC and during that time do some other stuff inside of a ''while''. In that case, I suppose, there is no need for ISR at all.

Am I wrong? Thanks

Posted on July 22, 2015 at 16:53

The hardware is going to do it's thing regardless of how you construct your software loops or interrupts. You can spin in a loop if you wish, the sampling occurs relatively quickly, I have no idea how complex/involved your computations are.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
matic
Associate III
Posted on July 22, 2015 at 17:19

It's not a complex mathematics. I have to do some basics operations, but with 2 pairs (of four) converted values. I would also like to do that as fast as possible.

Thus, I also have an idea to use 2 ADC moduls - one for the first pair of four signals and another ADC for second four signals. That way, I could get both pairs simultaneously. If I do that, can I use the same DMA modul with 2 different channels or do I have to use two completely separate DMA moduls? 

Posted on July 22, 2015 at 17:31

Your post makes no reference to a specific STM32, at this point they make hundreds.

Most STM32 part's I'm familiar with can bind two ADC together so that a pair of channels can be sampled together (same instant in time), and both those can be read by a single DMA module via a common ADC register.

The reference manuals should provide a functional overview of what a specific part is capable of.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
matic
Associate III
Posted on July 22, 2015 at 17:53

I'm using STM32F103C8.

I'm just looking at the reference manual and as I see (if I am correct), it is possible to configure one ADC in DUAL  mode. Than, the upper (31:16) bits of a DR register contains regular data of ADC2 and lower (15:0) bits contains data of ADC1. I am not sure, if I understand right.

If that is correct, than I think I could transfer 2x 16 bits via DMA at once.

Posted on July 22, 2015 at 18:12

Mechanically it needs to be singular/atomic 32-bit read, the net effect is two 16-bit half-words get transferred in one operation.

STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\ADC\RegSimul_DualMode\readme.txt

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
matic
Associate III
Posted on July 22, 2015 at 19:59

Thank you clive1. I will definitely try that.