cancel
Showing results for 
Search instead for 
Did you mean: 

How to sample improve ADC speed?

STM32L09
Associate II

My application senario: sample the sensor signal every second, and transmit through UART. 

to save power supply, I select ADC single mode, and used average as filter.

void ConfigureADC(void)
{
ADC1->CFGR1 |= ADC_CFGR1_AUTOFF;
ADC1->CFGR2 = (ADC1->CFGR2 & (~ADC_CFGR2_CKMODE))
| (ADC_CFGR2_OVSE | ADC_CFGR2_OVSR_2 | ADC_CFGR2_OVSR_1 | ADC_CFGR2_OVSR_0| ADC_CFGR2_OVSS_2); 
ADC1->SMPR |= ADC_SMPR_SMP_0 | ADC_SMPR_SMP_1 | ADC_SMPR_SMP_2; 
ADC1->CR |= ADC_CR_ADEN; 
ADC->CCR |= ADC_CCR_VREFEN|ADC_CCR_TSEN; 
}


unsigned int SignleADC(unsigned long int channel)
{
ADC1->CHSELR = channel; 
ADC1->CR |= ADC_CR_ADSTART;
while ((ADC1->ISR & ADC_ISR_EOC) == 0) 
{
}
ADC1->CR |= ADC_CR_ADSTP;
return ADC1->DR;
}

unsigned int Sensor_Read(void)
{
unsigned int gas[128];
unsigned long int read=0;
for(unsigned char i=0;i<128;i++)
gas[i] = SignleADC(ADC_CHSELR_CHSEL5);
for(unsigned char i=0;i<128;i++)
read += gas[i];

read = read>>7;
return((unsigned int)read);
}

Now the run time for Sensor_Read is about 700ms, it's too long, how can I improve the speed?

 

4 REPLIES 4

The most obvious would be to sum/average over fewer samples, or use the longer sample/hold to negate the need.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

thanks, but 128 is minimum, otherwise the noise too high

Convert with DMA in background. Perform averaging on demand when you send out sample.

If you feel a post has answered your question, please click "Accept as Solution".
mƎALLEm
ST Employee

Hello @STM32L09 ,

In next time please use </> button to paste your code. See this post. I've edited your post.

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.