32F417 ADC conversion time - figures don't make sense
Hi All,
I am using the simplest mode, single conv, software start, etc. 21MHz clock (/2 divisor).
I have been measuring the conversion times both in a loop and with a scope on a waggled GPIO pin.
With a sampling interval of 3,56,480 I see conversion times of 2,4,24 us.
Reading the RM, the data sheet, and whatever appnote I can find, I can't see why this should be.
This is the ADC read function
// Starts a conversion on the internal ST ADC, and optionally reads it
// Returns 12 bit result in 'value'.
// Mutex protected.
// This function is BLOCKING unless start_only=true in which case it just starts the ADC.
// Assumes ADC is already enabled.
void KDE_ADC_ST_read(uint8_t channel, uint16_t *value, bool start_only)
{
if (channel==1) {
ADC1_ST_Lock();
ADC1->SR = ~(ADC_FLAG_EOC | ADC_FLAG_OVR);
ADC1->CR2 |= (uint32_t)ADC_CR2_SWSTART;
}
else {
ADC2_ST_Lock();
ADC2->SR = ~(ADC_FLAG_EOC | ADC_FLAG_OVR);
ADC2->CR2 |= (uint32_t)ADC_CR2_SWSTART;
}
if (!start_only)
{
if (channel==1)
{
#ifdef TIMING_DEBUG
TopLED(true);
#endif
// Wait for End of conversion flag (bit 1 in SR)
// This could HANG but only if the silicon is defective or perhaps if the ADC was not enabled
while (((ADC1->SR) & ADC_FLAG_EOC)==0) {}
#ifdef TIMING_DEBUG
TopLED(false);
#endif
// Clear flags for 'conv started' and 'EOC' - clearing EOC is dumb since it is already checked above :)
ADC1->SR = ~(ADC_FLAG_STRT | ADC_FLAG_EOC);
*value = (uint16_t) ADC1->DR;
ADC1_ST_Unlock();
}
else
{
while (((ADC2->SR) & ADC_FLAG_EOC)==0) {}
ADC2->SR = ~(ADC_FLAG_STRT | ADC_FLAG_EOC);
//__HAL_ADC_CLEAR_FLAG(ADC2, ADC_FLAG_STRT | ADC_FLAG_EOC);
*value = (uint16_t) ADC2->DR;
ADC2_ST_Unlock();
}
}
}The other thing I have not found is a way of estimating the accuracy loss across the variable sampling interval. There must be some loss between 3 and 480 otherwise nobody would use anything but 3 : - )