没有合适的资源?快使用搜索试试~ 我知道了~
首页STM32 ADC采样精度提高办法
资源详情
资源评论
资源推荐

August 2012 Doc ID 022945 Rev 3 1/19
AN4073
Application note
How to improve ADC accuracy when using STM32F2xx,
STM32F40x and STM32F41x microcontrollers
Introduction
The purpose of this application note is to show how to improve the accuracy of A/D
conversions for applications using the STM32F20x / STM32F21x (revZ, revY, revX) and
STM32F40x/STM32F41x (revZ) microcontrollers.
It also explains the firmware methodology, which can be applied to reduce the ADC error. A
reference application is shown with implementation of firmware filtering techniques (using
averaging algorithms) to minimize the ADC errors.
The document also gives some general tips on writing firmware for better ADC accuracy.
Please note that the data provided with this application note is for reference only, measured
in a lab under typical conditions (unless specified otherwise) and not tested in production.
Table 1 lists the microcontrollers concerned by this application note.
Table 1. Applicable products
Type Applicable products
Microcontrollers
STM32F20x / STM32F21x (revZ, revY, revX) and
STM32F40x/STM32F41x (revZ) microcontrollers
www.st.com

Contents AN4073
2/19 Doc ID 022945 Rev 3
Contents
1 Overview of parameters impacting the ADC accuracy . . . . . . . . . . . . . 3
2 Firmware techniques for improving the conversion accuracy . . . . . . . 4
2.1 Averaging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.1.1 Averaging of N ADC samples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.1.2 Averaging of N-X ADC samples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2 Additional recommendation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3 Practical measurements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.1 Measurement conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.1.1 Hardware setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.1.2 Firmware setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2.1 ADC measurements when ART is ON . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.2.2 ADC measurements when ART is OFF . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.2.3 ADC measurements when (Data+Instruction) cache ON + prefetch OFF
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.3 Timing considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Appendix A Averaging of N ADC samples: source code . . . . . . . . . . . . . . . . . . 15
Appendix B Averaging of N-X ADC samples: source code . . . . . . . . . . . . . . . . 16
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

AN4073 Overview of parameters impacting the ADC accuracy
Doc ID 022945 Rev 3 3/19
1 Overview of parameters impacting the ADC accuracy
The accuracy of an analog to digital conversion has an impact on the overall system quality
and efficiency. To improve the accuracy, you need to understand the errors associated with
the ADC and the parameters affecting them.
The ADC, itself, cannot ensure the accuracy of results. It depends on your overall system
design. For this reason, you need to do some careful preparation before starting your
development.
Many parameters impact the ADC accuracy, depending on the application. Some of these
factors are: PCB layout, voltage source, I/O switching and analog source impedance.
For more details about ADC errors, please refer to AN2834: How to get the best ADC accu-
racy in STM32F10xxx devices and to AN3137: A/D converter on STM8L devices application
notes.

Firmware techniques for improving the conversion accuracy AN4073
4/19 Doc ID 022945 Rev 3
2 Firmware techniques for improving the conversion
accuracy
2.1 Averaging
Averaging is a simple technique where you sample an analog input several times and take
the average of the results. This technique is helpful to eliminate the effect of noise on the
analog input or a wrong conversion.
2.1.1 Averaging of N ADC samples
When this method is used, it is better to collect the samples in multiples of 2 (N should be a
multiple of 2). This makes it more efficient to compute the average because you can do the
division by right-shifting the sum of the converted values. This saves CPU time and code
memory needed to execute a division algorithm (in Cortex-Mx, this takes 1 CPU cycle).
Figure 1. Graphical representation of averaging technique
This averaging technique is used to measure the voltage on one analog input pin. A total of
N conversions is considered and the average is calculated. This is done in a loop in the
firmware.
069
'LJLWDORXWSXW
$YHUDJHYDOXH
1XPEHURI
FRQYHUVLRQV
平均法是一种简单的技术,你可以把模拟输入采样几次,取结果的平均值。这种技术有
助于消除噪声对模拟输入或错误转换的影响。
当使用这种方法时,最好以2倍的倍数收集样本(n应该是2的倍
数)。这样可以更有效地计算平均值,因为可以通过右移转换值之
和来进行除法运算。这样可以节省执行除法算法所需的CPU时间和
代码内存(在MX中,这需要1个CPU周期)。
这种平均技术是用来测量一个模拟输入引脚上的电压。考虑到总N转换,并计算平均值。这是在固件循环中
完成的。
剩余18页未读,继续阅读



















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0