Skip to main content
ScottT
Associate
February 22, 2019
Question

STM32F4 ADC overrun errors

Hi, I have a problem configuring ADC1 on an STM32F429 to do a regular scan of a sequence of 4 channels without using DMA. The fourth channel is the internal temperature sensor. The third channel to be scanned always gives an overrun error (ADC_SR.OVR=1). We are also configuring two other channels as injected channels at the same time (not shown in the code below). The initialization code looks like this (using the CMSIS peripheral access layer) :

	ADC1->CR1 |= ADC_CR1_SCAN;				
				
	ADC1->SQR1 |= 3 << ADC_SQR1_L_Pos;
 
	ADC1->SQR3 |=
		(12U << ADC_SQR3_SQ1_Pos) |
		(3U << ADC_SQR3_SQ2_Pos) |
		(4U << ADC_SQR3_SQ3_Pos) |
		(18U << ADC_SQR3_SQ4_Pos);
 
	ADC123_COMMON->CCR |=
		ADC_CCR_TSVREFE;
	 
	ADC1->CR2 |= ADC_CR2_EOCS;
	
	// Sampling time = 15 cycles for the channels we use
	ADC1->SMPR1 = 00100000101;
	ADC1->SMPR2 = 00000011001;
 
	ADC1->CR2 |= ADC_CR2_ADON;

and the sampling code, called every 220ms, looks like this:

	int i = 0;
	Bool Overrun = FALSE;
 
	ADC1->CR2 |= ADC_CR2_SWSTART;
 
	do
	{ 
		if(Overrun)
			ADC1->CR2 |= ADC_CR2_SWSTART;
 
		while ((ADC1->SR & ADC_SR_EOC) == 0)
		{
			if(ADC1->SR & ADC_SR_OVR)
			{
				ADC1->SR &= ~(ADC_SR_OVR | ADC_SR_EOC);	
				Overrun = TRUE;
				break;
			}	
			else
			{					
				Overrun = FALSE;				
			}
		}
 
		if(!Overrun)
		{						
			ADCValues[i] = ADC1->DR;
		}	
		i++;		
 
	} while (i < 4);
}

So we always read the data register immediately after ADC_SR.EOC is set, but for some reason we are still getting an overrun error for one of the channels. If I only include the first two channels in the sequence there are no errors. If I increase the number of cycles for some of the channels to the max (480 cycles) it seems to make the error go away, but I'd like to understand better what is going on here. Can anyone help?

Thanks,

Scott.

This topic has been closed for replies.

2 replies

SBeno.1
Associate
May 26, 2020

Hi,

Did you solve this issue yet ?

I have come to something similar, the data of the ADC was skipping steps from raw value 1991 to 2047 and we had some overrun error.

Using the ADC1 with DMA triggers in scan mode.

Our workaround for now is to put the APB2 to 42MHz instead of the nominal 84MHz. Thus, I haven't found any errata on this.

waclawek.jan
Super User
May 26, 2020

@Community member​ ,

please start a new thread, stating exactly what's the problem is, on which STM32, posting values of registers read out from ADC and perhaps DMA.

Regarding the original post, I don't know what's the ADC clock setting there, but 15 cycles sounds quite like there's an opportunity that the C code reading out the measurements will be slower, expecially at low optimization settings. I'd also say that 15 cycles won't be enough for the temperature sensor, that would need to be checked with DS.

JW