cancel
Showing results for 
Search instead for 
Did you mean: 

need help understanding Vref / Vdda

deep_rune
Associate III

I'm trying to find what voltage reference my ADC is using, as it is not going up to 0xFFF. Along the line, I have become quite confused about the Vref - I used to use other chips where the Vref is just a reference voltage for the ADC, but with STM32 it seems it's more complicated.

I'm confused by the function of the Vref / Vdda pin on the STM32L412 - is this a power pin, or a voltage reference pin? I looked through the reference manual but the information was ambiguous. If it's a power pin, how much current does it need? And how does the Vref work?

15 REPLIES 15
By VREF do you mean VREFINT? I don't think that's specified to within a few millivolts. Presumably your VREF+ is also only good to within a limited range.
Perhaps it is neither a software nor a hardware issue, but an issue of expectations. You would need to provide more precise details.
In my experience, the (SAR) ADC in the STM32 families is accurate to within an LSB for static voltages.
Take a look at AN2834.
If you feel a post has answered your question, please click "Accept as Solution".
S.Ma
Principal

It should be the bandgap voltage, works like an internal regulator. By measuring it, vdda can be deducted.

There's a load more detail in the principle question here : https://community.st.com/s/question/0D53W00001iGvOGSA0/stm32l496rgt6-adc (including all sorts of generated source files) but the long and the short of it is that I'm using an external 2.5V voltage source to power with VSSA and have the ADC set to 12 bits which I was assuming would give me an LSB of around 2500/4096 = 0.6mV but in practice I'm getting an error of around 30mV when reading a 1393mV source.

I've tried pretty much everything I can think of and nothing seems to make any real difference.

> in practice I'm getting an error of around 30mV when reading a 1393mV source.

Did you perform ADC calibration before measurement, as outlined in the ADC chapter in RM?

Also, next time, don't hijack an old thread, start your own.

JW

I believe so, although I could be doing it wrong:

main.c

int main(void) {
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_ADC1_Init();
 
  if (HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED) != HAL_OK) {
	  Error_Handler();
  }
 
  while (1) {
		if (HAL_ADC_Start(&hadc1) != HAL_OK) {
		  Error_Handler();
		}
 
		if (HAL_ADC_PollForConversion(&hadc1, 100) != HAL_OK) {
			Error_Handler();
		}
 
	    float adc = (float)HAL_ADC_GetValue(&hadc1);
 
	    float vref = 2500.0f;
	    float vadc = (adc * vref) / 4096.0f;
 
	    float R14 = 47000;
	    float R15 = 100000;
	    float vbat = vadc * (R14 + R15) / R15;
 
	    __NOP();
  }