How to use expansion board based on the stsafe-a110 secure element (14 pages)
Summary of Contents for ST STM32
Page 1
How to get the best ADC accuracy in STM32 microcontrollers Introduction STM32 microcontrollers embed up to four advanced 12-bit ADCs (depending on the device). A self-calibration feature is provided to enhance ADC accuracy versus environmental condition changes. In applications involving analog-to-digital conversion, ADC accuracy has an impact on the overall system quality and efficiency.
Page 4
List of tables AN2834 List of tables Table 1. Document revision history ..........48 4/49 DocID15067 Rev 3...
Page 5
AN2834 List of figures List of figures Figure 1. Basic schematic of SAR switched-capacitor ADC (example of 10-bit ADC)... . . 6 Figure 2. Sample state ............. 7 Figure 3.
ADC internal principle SAR ADC internal structure The ADC embedded in STM32 microcontrollers uses the SAR (successive approximation register) principle, by which the conversion is performed in several steps. The number of conversion steps is equal to the number of bits in the ADC converter. Each step is driven by the ADC clock.
AN2834 ADC internal principle Figure 2. Sample state 1. Sample state: capacitors are charging to V voltage. Sa switched to V , Sb switch closed during sampling time. Figure 3. Hold state 1. Hold state: the input is disconnected, capacitors hold input voltage. Sb switch is open, then S1-S11 switched to ground and Sa switched to V DocID15067 Rev 3 7/49...
ADC internal principle AN2834 Figure 4. Step 1: Compare with V 1. First approximation step. S1 switched to V Figure 5. Step 2: If MSB = 0, then compare with ¼V 1. Compare with ¼V ; if MSB =1. S1 switched back to ground. S2 switched to V 8/49 DocID15067 Rev 3...
AN2834 ADC internal principle Figure 6. Step 2: If MSB = 1, then compare with ¾V 1. Compare with ¾V ; if MSB =0. S1 remained switched to ground. S2 switched to V DocID15067 Rev 3 9/49...
1. Still ideally, the first transition occurs at 0.5 LSB. The offset error is denoted by . The offset error can easily be calibrated by the application firmware. Example For the STM32 ADC, the smallest detectable incremental change in voltage is expressed in terms of LSBs: 1 LSB = V...
AN2834 ADC errors Figure 7. Positive offset error representation 1. The error offset, E , is shown in magenta. When an analog input voltage of less than 0.5 LSB generates the first transition, the offset error is negative (refer to Figure 8 for an example of negative offset error).
ADC errors AN2834 2.1.2 Gain error The gain error is the deviation between the last actual transition and the last ideal transition. It is denoted by E The last actual transition is the transition from 0xFFE to 0xFFF. Ideally, there should be a transition from 0xFFE to 0xFFF when the analog input is equal to V –...
AN2834 ADC errors Figure 10. Negative gain error representation 1. The gain error, E , is shown in magenta. 2.1.3 Differential linearity error The differential linearity error (DLE) is the maximum deviation between the actual and ideal steps. Here ‘ideal’ does not refer to the ideal transfer curve but to the ADC resolution. The DLE is denoted by E .
ADC errors AN2834 Figure 11. Differential linearity error representation 1. The differential linearity error, E , is shown in magenta. If V = 3.3 V, an analog input of 1.9998 V (0x9B1) can provide results varying between REF+ 0x9B0 and 0x9B2. Similarly, for an input of 2.0014 V (0x9B3), the results may vary between 0x9B2 and 0x9B4.
AN2834 ADC errors Figure 12. Integral linearity error representation 1. The integral linearity error, E , is shown in magenta. Example If the first transition from 0 to 1 occurs at 550 µV and the last transition (0xFFE to 0xFFF) occurs at 3.298435 V (gain error), then the line on the transfer curve that connects the actual digital codes 0x1 and 0xFFF is the endpoint correlation line.
ADC errors AN2834 2.1.5 Total unadjusted error The total unadjusted error (TUE) is the maximum deviation between the actual and the ideal transfer curves. This parameter specifies the total errors that may occur, thus causing the maximum deviation between the ideal digital output and the actual digital output. TUE is the maximum deviation recorded between the ideal expected value and the actual value obtained from the ADC for any input voltage.
AN2834 ADC errors Errors due to the ADC environment 2.2.1 Reference voltage noise As the ADC output is the ratio between the analog signal voltage and the reference voltage, any noise on the analog reference causes a change in the converted digital value. V analog power supply is used on some packages as the reference voltage (V ), so the REF+...
ADC errors AN2834 2.2.3 External reference voltage parameters In case of usage external source for reference voltage (on V pin) there are important REF+ parameters of this external reference source. Three reference voltage specifications must be considered: temperature drift, voltage noise, long term stability. 2.2.4 Analog input signal noise Small but high-frequency signal variation can result in big conversion errors during sampling...
AN2834 ADC errors The effective charging of C is governed by R , so the charging time constant becomes t = (R ) × C . If the sampling time is less than the time required to fully charge the C through R <...
ADC errors AN2834 Figure 16. Analog input with R and C 2.2.8 Injection current effect A negative injection current on any analog pin (or a closely positioned digital input pin) may introduce leakage current into the ADC input. The worst case is the adjacent analog channel.
AN2834 ADC errors 2.2.10 I/O pin crosstalk Switching the I/Os may induce some noise in the analog input of the ADC due to capacitive coupling between I/Os. Crosstalk may be introduced by PCB tracks that run close to each other or that cross each other. Internally switching digital signals and I/Os introduces high-frequency noise.
ADC curve stored in the microcontroller memory but this needs calibration of each individual device in final application. Offset and gain errors can be easily compensated using the STM32 ADC self-calibration feature or by microcontroller firmware.
1 µF Tantalum or Ceramic). Refer to Figure 20 Figure 21 for decoupling examples. For STM32 microcontrollers delivered in 100/144-pin packages, it is possible to improve the accuracy on low-voltage inputs by connecting a separate external ADC reference voltage input on V (refer to Section 3.2.5).
How to get the best ADC accuracy AN2834 3.2.2 Reference voltage / Power-supply regulation The power supply should have good line and load regulation since the ADC uses V REF+ as the analog reference and the digital value is the ratio of the analog input signal to this voltage reference.
(so, capacitive coupling must be used). A very simple implementation of the quasi-triangular source which is generated directly by the STM32 microcontroller is on Figure Figure 22. Simple quasi-triangular source using a microcontroller output...
If the measured signal is too small (in comparison with the ADC range), then an external preamplifier can be useful. This method can be implemented whatever the STM32 package, and more specifically in packages that do not have a V input.
AN2834 How to get the best ADC accuracy This amplifier can adapt the input signal range to the ADC range. It can also insert offsets between the input signal and the ADC input. When designing the preamplifier, care must be taken not to generate additional errors (such as additional offset, amplifier gain stability or linearity, frequency response).
How to get the best ADC accuracy AN2834 3.2.6 Analog source resistance calculation Let us assume that the maximum error allowed is equal to 1/2 LSB. We will calculate the maximum source resistance allowed. is the voltage across the internal C capacitor (refer to Figure 15).
Page 29
AN2834 How to get the best ADC accuracy By combining equations (1), (2) and (3), we obtain final formula: ------------------------------------------------------------------------ - R – AINmax ADCmax ⋅ ⋅ Example for STM32F1 parameters = 14 MHz, C = 8 pF, R max = 1 kΩ and for T = 7.5, the maximum source resistance allowed for an error equal to 1/2 LSB is: ----------------------------------------------------------------------------------------------- - 1kΩ...
How to get the best ADC accuracy AN2834 3.2.7 Source frequency condition vs. source and parasitic capacitors The external capacitance will not allow the analog input voltage to be exactly the same as if the capacitor is not fully charged by the analog source. If the analog input signal changes, then the analog signal frequency (F ) should be such that the time period of this analog signal is at least: 10 ×...
I/O pin that can give birth to the negative injection current. The ADC accuracy will not be affected by positive injection currents within the limits specified for I and ΣI (refer to the appropriate STM32 datasheet, I/O port INJ(PIN) INJ(PIN) characteristics section). 3.2.10...
How to get the best ADC accuracy AN2834 3.2.11 EMI-induced noise reduction You can reduce EMI noise using proper shielding and layout techniques. The possible sources of emission must be physically separated from the receptors. They can be separated electrically by proper grounding and shielding. Shielding technique Placing ground tracks alongside sensitive analog signals provides shielding on the PCB.
(see Figure 30). Depending on the STM32 package, different analog and digital power supply and ground pins are available. The V and V pins can be powered from separate power supplies.
How to get the best ADC accuracy AN2834 Separating the analog and digital supplies Figure 30. It is also recommended to connect the analog and digital grounds in a star network. This means that you must connect the analog and digital grounds at only one point. This prevents the introduction of noise in the analog power supply circuit due to digital signal switching.
AN2834 How to get the best ADC accuracy 3.2.13 Component placement and routing Place the components and route the signal traces on the PCB so as to shield analog inputs. Components like resistors and capacitors must be connected with very short leads. You can use surface-mounted device (SMD) resistors and capacitors.
How to get the best ADC accuracy AN2834 In STM32L0 and STM32L4 microcontrollers, averaging can be performed by using the hardware oversampling feature: the ADC performs built-in hardware averaging according to configurable parameters (number of samples to average and final right bit shift of result). The advantage of averaging is to improve ADC precision without any hardware changes.
AN2834 How to get the best ADC accuracy 3.3.3 FFT for AC measurement In some specific cases the application needs to know the amplitude of an AC signal with a given frequency. In this case the effective value of an AC signal can also be obtained by using a relatively slow sampling speed (in comparison to the measured signal frequency).
How to get the best ADC accuracy AN2834 3.3.4 ADC calibration This method requires knowledge of the internal ADC structure and of how the ADC converter is implemented inside the microcontroller. This is necessary to design a physical/mathematical model of the ADC implementation. A proper physical model (which is usually a schematic diagram) is used as a basis for describing it mathematically.
How to get the best ADC accuracy High impedance source measurement This section describes the ADC measurement behavior of STM32 ADC when a signal source with high internal impedance is used. It explains how to design an application to reach the requested precision and provides workarounds.
How to get the best ADC accuracy AN2834 3.4.2 Explanation of the behavior The explanation of this additional pin noise and additional measurement error (in case a signal source with high internal impedance is used) comes from the internal ADC structure: its input sampling circuit.
AN2834 How to get the best ADC accuracy 3.4.3 Minimizing additional errors Workaround for high impedance sources To solve the additional error problem, the sampling time (T ) can be increased by configuring ADC settings in MCU firmware, so that the C charge is discharged through the source impedance R .
How to get the best ADC accuracy AN2834 Workaround for extra high impedance sources This workaround combines both hardware and software changes. Hardware change The hardware change consists in adding a large external capacitor (C ) to the input pin. The capacity size connected to the input pin must reach the value that causes the discharging of the internal sampling capacity C to the external capacitor C...
Page 43
AN2834 How to get the best ADC accuracy Software change The side effect mentioned above can be solved by software. The objective is to create a delay in order to let C discharge through R (not measure so often) giving enough “discharge time”...
Page 44
How to get the best ADC accuracy AN2834 An extra large C >> ) enables sampling more often. ⋅ ------------- - However, increasing C limits the frequency bandwidth of measurement signal (increasing the “external” timing constant R The formulas below show how to choose the optimal C value: signal bandwidth in correlation with sample time.
How to get the best ADC accuracy AN2834 Figure 38. Parasitic capacitances of sampling switch This charging and discharging currents (PMOS and NMOS asymmetric capacitances) can cause charge transfer to sampling capacitor C Internal charging of sampling capacitor It is possible that after the conversion process (successive approximation process in SAR type of ADC) the sample and hold capacitor C is charged to some voltage.
Conclusion This application notes describes the main ADC errors and then methods and application design rules to minimize STM32 ADC errors and obtain the best ADC accuracy. The choice of method depends on the application requirements and is always a compromise between speed, precision, enough computation power and design topology.
Text improvements and additions. Changed the Disclaimer on the final page. Document scope extended to all STM32 microcontrollers. Updated Figure 5: Step 2: If MSB = 0, then compare with ¼VREF Figure 6: Step 2: If MSB = 1, then compare with ¾VREF.
Page 49
ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on ST products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order acknowledgement.
Need help?
Do you have a question about the STM32 and is the answer not in the manual?
Questions and answers