2020-12-23 10:37 AM
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?
2022-08-05 08:21 AM
2022-08-05 07:21 PM
It should be the bandgap voltage, works like an internal regulator. By measuring it, vdda can be deducted.
2022-08-09 12:59 AM
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.
2022-08-09 01:16 AM
> 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
2022-08-09 01:19 AM
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();
}
2022-08-09 02:58 AM
my original question is here : https://community.st.com/s/question/0D53W00001iGvOGSA0/stm32l496rgt6-adc