Question
How to sample improve ADC speed?
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?
