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:
2024-11-07 05:46 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.
I downloaded the datasheet, and this MCU family has indeed no ADC calibration feature.
Of course then there is no point in trying. Remove the HAL call.
> Calibration is important for any ADC to minimize offset and gain errors.
You can either go without, not sure what difference it makes with your application.
Another option would be to use a MCU which allows for ADC calibration, like the F3xx.
And a third option would be an external calibration. Measure a reference source with your F405 board and a reference meter, preferably at several temperatures. You can implement a correction factor / offset into the code from your measurement.
Depending on required precision, this might be necessary for every individual device.
2024-11-07 06:24 PM
If I use 'thresholds' in determining my ADC results, does that count as calibration? Because I cannot find a way to perform calibration, I am a beginner and I am trying to understand it. Would you be willing to provide an example? I want to perform voltage sensing with a voltage divider where R1 = 15k and R2 = 4700, and I will measure/sense at R2 with an input voltage of 12V.
2024-11-07 06:26 PM
forget the error because i don't used the "HAL_ADCEx_Calibration_Start() ".
now i want to ask you about "other way for calibration" If I use 'thresholds' in determining my ADC results, does that count as calibration? Because I cannot find a way to perform calibration, I am a beginner and I am trying to understand it. Would you be willing to provide an example? I want to perform voltage sensing with a voltage divider where R1 = 15k and R2 = 4700, and I will measure/sense at R2 with an input voltage of 12V
2024-11-07 06:26 PM
If I use 'thresholds' in determining my ADC results, does that count as calibration? Because I cannot find a way to perform calibration, I am a beginner and I am trying to understand it. Would you be willing to provide an example? I want to perform voltage sensing with a voltage divider where R1 = 15k and R2 = 4700, and I will measure/sense at R2 with an input voltage of 12V