cancel
Showing results for 
Search instead for 
Did you mean: 

Sampling multiple A/D inputs-Quick Question

rj
Associate II
Posted on February 02, 2013 at 09:18

Quick background: I'm using the STM32VL which has 1 ADC peripheral with a possible 18 channels inputs that are multiplexed to the actual ADC. I believe I have the configuration set up correctly for 2 analog inputs. My question lies in the sampling technique... The way I understand the ADC to work on this board is that it has a single data register, so when I scan multiple analog inputs, I have to read the data in between samples using either flags, interrupts or DMA. I chose to use the EOC flag. What I want to do is after the first sample is finished, store the data in ADCResult_1 and when the second sample is complete, store that into ADCResult_2. This is my code but I dont think is correct since this would store the same value in both ADCResult_1and ADCResult_2:

  while(ADC_GetFlagStatus  (ADC1, ADC_FLAG_EOC) == RESET);     

    ADCResult_1 = ADC_GetConversionValue(ADC1);    // sample 1               

    while(ADC_GetFlagStatus  (ADC1, ADC_FLAG_EOC) == RESET); 

    ADCResult_2 = ADC_GetConversionValue(ADC1);  // sample 2

Any suggestions on how to capture each successive sample repeatedly?
5 REPLIES 5
Posted on February 02, 2013 at 11:27

Any suggestions on how to capture each successive sample repeatedly?

 

Make sure the sample/conversion rate is slower than your ability to read out values. This will include whatever time is needed to service other interrupts, etc.

DMA is used so you don't have to grind the processor in this fashion.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
rj
Associate II
Posted on February 02, 2013 at 16:24

Supposing that my sample rate is adequate, would my code work using the EOC flag?

Posted on February 02, 2013 at 17:05

Supposing that my sample rate is adequate, would my code work using the EOC flag?

I don't know, it appears the most inefficient way to do it, I have not investigated. What's the driver for doing it this way instead of reading them into an array in a paced/controlled way?

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
rj
Associate II
Posted on February 02, 2013 at 17:39

rj
Associate II
Posted on February 02, 2013 at 17:40

The only driver for doing it this way is my lack of experience...I agree this way seems to be very inefficient. I suppose a better way is to create an interrupt service routine that stores the value after each sample conversion. Don't know how to really do that just yet though, which means I need to do some research.