2024-11-06 10:26 PM - last edited on 2024-11-07 12:15 AM by Peter BENSCH
Hello, I am using ADC and DAC for sensing in my device, and I am using the STM32F405RGT6. I want to perform calibration, but I cannot use
"HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);"
. I tried using this code:
SET_BIT(ADC1->CR2, ADC_CR2_CAL);
(READ_BIT(ADC1->CR2, ADC_CR2_CAL) != 0);
But it resulted in an error because I don't fully understand it. Is there a solution for this? I just want to perform calibration. If I'm using a potentiometer, do I need to use a jumper?
I also want to ask why calibration is important, and what happens if calibration is not performed? Please help me.
2024-11-07 12:11 AM - last edited on 2024-11-07 01:13 AM by Andrew Neil
Originally posted as a separate thread - merged.
I am using STM32F4 to perform sensing on my circuit. Before doing so, I would like to calibrate it first. I am doing this because I read that calibration is 'important,' but I don't understand why calibration 'must' be done. I say this because I previously used the ADC and DAC directly without calibration, and it worked fine. Therefore, I want to clarify why calibration must be done. Is it possible to proceed without it? I am using STM32F4, and when I use "
HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);
" it doesn't work and throws an error. I have run out of ideas for calibration besides the above method. Is it true that STM32F4 does not have calibration, or is there information that I missed? Please help.
2024-11-07 12:25 AM
Quoting from the reference manual for a F3 (I don't have one for your F405 at hand) :
Calibration is preliminary to any ADC operation. It removes the offset error which may vary from chip to chip due to process or bandgap variation.
It is not strictly necessary, but recommended.
If not calibrated, variations (measurement errors) between different runs and/or different MCUs significantly increase. The datasheet usually only lists accuracy values after internal calibration.
And here a quote from the same F3 manual regarding the calibration sequence :
Software procedure to calibrate the ADC
1. Ensure ADVREGEN[1:0]=01 and that ADC voltage regulator startup time has elapsed.
2. Ensure that ADEN=0.
3. Select the input mode for this calibration by setting ADCALDIF=0 (Single-ended input)
or ADCALDIF=1 (Differential input).
4. Set ADCAL=1.
5. Wait until ADCAL=0.
6. The calibration factor can be read from ADCx_CALFACT register.
I suggest to consult the RM of your MCU, and check/debug with the code.
I neither like nor use Cube/HAL code for my boards.
2024-11-07 12:52 AM - edited 2024-11-07 01:10 AM
The ADCs are SAR-type and so have a bunch of little caps to switch for getting a result.
info see -> https://www.digikey.de/en/articles/analog-basics-part-1-sar-analog-to-digital-converters
or de : https://www.digikey.de/de/articles/analog-basics-part-1-sar-analog-to-digital-converters
So any ADC needs a "calibration cycle" after power up, to adjust the caps/switches , until desired precision is reached.
Thats why you need calibration always at first.
But because you have to do it anyway - some ADC series have built in automatic: after power up or at first use, they do the calib-cycle at first and then run "as usual" , no need to call any calibration by the user.
So just look in ds of your chip -> ADC : if data is like "resolution 10.5 bit " and no remark for "calibrated or after calibration" , then its auto-cal.
...for F401 see ds :
guess , what its doing in this 2..3us after power-up ...!
and:
-> nothing about calibration -> just characterization . start ...ready ...use it.
Otherwise you will find ..remarks (H743 here).:
and also about calibration details :
-> So no need for user calibration, if ADC has built in automatic to do it.
2024-11-07 12:53 AM
Unfortunately, STM32F4 series ADCs, including the one in your STM32F405RGT6, do not have a built-in calibration function, which is why HAL_ADCEx_Calibration_Start() is unavailable for this series.
Calibration is important for any ADC to minimize offset and gain errors.
2024-11-07 01:18 AM
@macam1 wrote:it doesn't work and throws an error.
So what error, exactly, does it throw?
Copy the error message from your IDE, and paste it here.
If you're using STM32CubeIDE, the best way to do that is from the 'Console' view: