Author Topic: STM32 ADC self-calibration  (Read 5841 times)

0 Members and 1 Guest are viewing this topic.

Offline Red_MicroTopic starter

  • Regular Contributor
  • *
  • Posts: 121
  • Country: ca
STM32 ADC self-calibration
« on: January 22, 2022, 01:32:22 am »
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.
 

Offline peter-h

  • Super Contributor
  • ***
  • Posts: 3694
  • Country: gb
  • Doing electronics since the 1960s...
Re: STM32 ADC self-calibration
« Reply #1 on: January 22, 2022, 03:18:30 pm »
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.

Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 
The following users thanked this post: Red_Micro

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4227
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: STM32 ADC self-calibration
« Reply #2 on: January 22, 2022, 05:06:46 pm »
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_STUP and insert a delay into your code as necessary.

The ADC in STM32F417 doesn't have the same kind of built-in calibration.
 
The following users thanked this post: Red_Micro

Offline peter-h

  • Super Contributor
  • ***
  • Posts: 3694
  • Country: gb
  • Doing electronics since the 1960s...
Re: STM32 ADC self-calibration
« Reply #3 on: January 23, 2022, 09:28:06 am »
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.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Online Jeroen3

  • Super Contributor
  • ***
  • Posts: 4078
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: STM32 ADC self-calibration
« Reply #4 on: January 23, 2022, 02:42:47 pm »
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 appnote AN7073. 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-h
The 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.
« Last Edit: January 23, 2022, 02:46:53 pm by Jeroen3 »
 
The following users thanked this post: Red_Micro

Offline Red_MicroTopic starter

  • Regular Contributor
  • *
  • Posts: 121
  • Country: ca
Re: STM32 ADC self-calibration
« Reply #5 on: January 23, 2022, 03:42:01 pm »
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.

What reference are you using? I have the TL431 but I'm pretty sure it may no be good enough.

Have you taken into account the ADC voltage regulator start-up time?

Yes, I took that time into account. It does not look like it is the problem. I'll rethink it anyways.

ADC's are tricky to get right. When running the self-calibration you probably don't want anything else running.

I think this is worth checking out. I'll see what's running during self-calibration.

 

Online Jeroen3

  • Super Contributor
  • ***
  • Posts: 4078
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: STM32 ADC self-calibration
« Reply #6 on: January 23, 2022, 04:48:08 pm »
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).
 

Offline peter-h

  • Super Contributor
  • ***
  • Posts: 3694
  • Country: gb
  • Doing electronics since the 1960s...
Re: STM32 ADC self-calibration
« Reply #7 on: January 23, 2022, 04:57:39 pm »
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% reference :) The 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.
« Last Edit: January 23, 2022, 06:01:31 pm by peter-h »
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 
The following users thanked this post: mycroft


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf