STM32 ADC self-calibration - Page 1
Forum section: electronics / general

author: Red_Micro
author_rank: Regular Contributor
timestamp: January 22, 2022, 01:32:22 am
content: Has anyone had a closer experience with the ADC self calibration step in the STM32L4 family? The reference manual says it is to remove the offset due to chip variation and it also provides a way to adjust the calibration factor. I'm playing with the ADC_CALFACT register (where the ADC self-calibration stores the resulting cal factor) and writing other values gives me better accuracy than the one resulting from the self-calibration. I'm wondering now if the self-calibration routine is not calculating optimal values.

author: peter-h
author_rank: Super Contributor
timestamp: January 22, 2022, 03:18:30 pm
content: How far out is it?I am doing a 32F417 design right now which has various ADCs, internal and external, and it involves factory cal, but I am using an external 0.01% reference. It's very easy.The internal DACs are always noisy - last 2 bits or so are noise. You have to take say 100 readings, add them up and divide by 100, to get any sort of stable value. They probably don't do that in the factory cal.

author: AndyC_772
author_rank: Super Contributor
timestamp: January 22, 2022, 05:06:46 pm
content: Have you taken into account the ADC voltage regulator start-up time?If you just enable the regulator then immediately start the calibration sequence, then it doesn't return accurate results. Check the data sheet for TADCVREG_STUPand insert a delay into your code as necessary.The ADC in STM32F417 doesn't have the same kind of built-in calibration.

author: peter-h
author_rank: Super Contributor
timestamp: January 23, 2022, 09:28:06 am
content: The 417 does have such a thing for some features; from memory, the internal reference, and the temperature sensor. The factory test writes some calibration values into FLASH somewhere. I have never used these; the documentation is really obscure.

author: Jeroen3
author_rank: Super Contributor
timestamp: January 23, 2022, 02:42:47 pm
content: Some parts of the chip are intentionally not explained I think. It would expose too much.For example, in the F4 series there are the ADCxDC1 bits you can turn on in the SYSCFG module that obviously do something to improve ADC accuracy, but they are not described in the reference manual. That just points you to appnoteAN7073. Which is basically a big warning to not use those bits, except in very specific cases...The F4 is a particularly noisy chip, if you need the ADC you're going to need an HSE and disable the flash prefetcher, so there goes your performance.The L4 is newer, I hope they learned from the F4 and made it better.ADC's are tricky to get right. When running the self-calibration you probably don't want anything else running.With an good enough scope you can probably tell when you're running the FPU on the power rails. This will be amplified with poor power distribution (eg: 2 layer).Check also this application note listing all possible improvements and mitigations for using the ADC,AN2834.@peter-hThe calibration values written to ROM in the factory for the temperature sensor are to provide the accurate gradient for you. You get two temperature with a known Vdda to interpolate around.The internal reference calibration value is one known point at known Vdda you can then use with the temperature calibrations to put the 50ppm to work.Using those you can also calculate the Vdda, but not better than the internal reference.The absolute value of the internal reference still needs external information. When that is given it is actually pretty good.

author: Red_Micro
author_rank: Regular Contributor
timestamp: January 23, 2022, 03:42:01 pm
content: Quote from: peter-h on January 22, 2022, 03:18:30 pmWhat reference are you using? I have the TL431 but I'm pretty sure it may no be good enough.Quote from: AndyC_772 on January 22, 2022, 05:06:46 pmYes, I took that time into account. It does not look like it is the problem. I'll rethink it anyways.Quote from: Jeroen3 on January 23, 2022, 02:42:47 pmI think this is worth checking out. I'll see what's running during self-calibration.

author: Jeroen3
author_rank: Super Contributor
timestamp: January 23, 2022, 04:48:08 pm
content: Any reference is already an improvement over just using Vdd wired to Vref since Vdd will have plenty of noise and will dip depending on load (computation, io, led's).

author: peter-h
author_rank: Super Contributor
timestamp: January 23, 2022, 04:57:39 pm
content: A TL431 is actually very good, and costs practically nothing. I am using it as a reference for the ADCs and DACs. The initial tolerance is around 1% so I am doing external cal on that and storing a cal value for span. There is no need to calibrate the zero because that seems to be inherently very close. A TL431, calibrated, will easily give you 12 bit level accuracy long-term.I've been using these on-chip ADCs and DACs and one never gets anywhere near their spec in a practical application, with other stuff running. They can be pretty good if you take say 100-1000 readings and average them, because the noise is pretty random. But that doesn't matter; the ADCs are very fast and easily fast enough for advanced brushless motor control and such like and you don't need 12 bits there.If you need accuracy and low noise, 12 bits or better, you need a dedicated chip, and locate it near the analog front end. There are some amazing chips; I am using an MCP3550 (which also never achieves its 22 bit spec but is very good) and an ADS1118. Both via SPI. And galvanically isolated. The MCP3550 is good enough for 0.01% sort of accuracy, which is hard to achieve in production anyway; try setting up a 0.005% referenceThe best resistors you can buy are 0.005%. I've been doing precision analog since the 1970s and it has never been easier than now, but you still need careful construction and layout.