STM32L412KB ADC Oversampling - Question to right bitshift
Hello,
i am using ADC with DMA. In my initialization code i did the ADC calibration procedure like that:
HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED); // ADC calibration
VrefintCalValue = (*VREFINT_CAL_ADDR); // read out the calibration value of VREFINT
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_buffer, 3); // Start ADC for 3 conversions and transfer data over DMA inside the memoryAfter ADC conversion complete, i calculate the battery voltage (vdd) as follows:
adc_value_VREFINT = (double)(3 * VrefintCalValue) / 4095;
vdd = 3000 * ((double)VrefintCalValue / (adc_buffer[2] >> 4)); // why not (adc_buffer[2] >> 3)?The calculation works fine, but i don't understand the 4x bitshift. In my opinion it must be 3x bit-shift.
Here is a part of my ADC init:
hadc1.Init.OversamplingMode = ENABLE;
hadc1.Init.Oversampling.Ratio = ADC_OVERSAMPLING_RATIO_128;
hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_3;
hadc1.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER;
hadc1.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_CONTINUED_MODE;Can someone explain to me why a 3x right bit-shift is wrong in that case?
