Under normal circumstances, the ADC successive approximation conversion circuit requires a sampling clock between 50kHz and 200kHz to achieve maximum accuracy. When the conversion accuracy is required to be less than 10 bits, the ADC sampling clock can be higher than 200kHz to obtain a higher sampling rate.
The ADC module contains an ADC clock source with a prescaler, which can divide the system clock greater than 100KHz to obtain a suitable ADC clock for ADC use. The prescaler's division coefficient is set by the ADPS bit in the ADCSRA register. Once the ADEN bit in the ADCSRA register is set to "1" (ADC starts working), the prescaler starts counting. When the ADEN bit is "1", the prescaler will always work; when the ADEN bit is "0", the prescaler is always in reset state.
The time it takes for the AVR ADC to complete a conversion is shown in Table 6.2.5. As can be seen from the table, it usually takes 13-14 ADC clocks to complete an ADC conversion. It takes 25 ADC clocks from the start of the ADC to the completion of the first conversion, because the analog circuit part of the ADC unit needs to be initialized.
When the ADSC bit in the ADCSRA register is set and the ADC conversion is started, the A/D conversion will start at the rising edge of the subsequent ADC clock. When a normal A/D conversion starts, a sampling and holding time of 1.5 ADC clock cycles is required (a sampling and holding time of 13.5 ADC clock cycles is required after the ADC is first started). When an A/D conversion is completed, the conversion result is written to the ADC data register, and ADIF (ADC interrupt flag) will be set. In single conversion mode, ADSC is also cleared at the same time. The user program can set the ADSC bit again, and a new conversion will start at the next rising edge of the ADC clock.
When the ADC is set to automatic trigger mode, the rising edge of the trigger signal will start an ADC conversion. The result of the conversion will be kept until the next rising edge of the trigger signal appears, and then a new ADC conversion will start. This ensures that the ADC performs a conversion at a certain time interval. In this mode, the ADC requires a sampling and holding time of 2 ADC clock cycles.
In free continuous conversion mode, a new conversion starts immediately after one conversion is completed. At this time, the ADSC bit remains at "1".
2. Selection of ADC input channel and reference power supply
The MUXn and REFS1, REFS0 bits in the ADMUX register are actually a buffer that is connected to a temporary register that the MCU can read randomly. This structure ensures that the ADC input channel and reference power supply can only be changed at a safe point in the ADC conversion process. Before the ADC conversion starts, the channel and reference power supply can be continuously updated. Once the conversion starts, the channel and reference power supply will be locked and kept for enough time to ensure the normal ADC conversion. In the last ADC clock cycle before the conversion is completed (when the ADIF position of ADCSRA is "1"), the channel and reference power supply begin to be updated again.
Note: Since A/D conversion starts on the rising edge of the first ADC clock after setting ADSC, do not write a new channel or reference power supply to the ADMUX register within one ADC clock cycle after setting ADSC.
Be careful when changing the differential input channel. Once the differential input channel is determined, the gain amplifier needs 125µs to stabilize. Therefore, do not start the A/D conversion within 125µs after selecting the new differential input channel, or discard the conversion results during this period. After changing the reference power supply by changing REFS1 and REFS0 in ADMUX, the first differential conversion should also follow the above time processing process.
1) When changing the ADC input channel, the following should be followed to ensure that the correct channel is selected:
In continuous conversion mode, always change the channel settings before starting the ADC to start the first conversion. Although the input channel change occurs within 1 ADC clock cycle after the ADSC bit is written to "1", the simplest method is to wait until the first conversion is completed before changing the channel settings. However, since a new conversion has been automatically started at this time, the current conversion result still reflects the conversion value of the previous channel, and the next conversion result will be the value of the newly set channel.
2) ADC voltage reference source
The reference voltage (VREF) of the ADC determines the range of the A/D conversion. If the input voltage of the single-ended channel exceeds VREF, the conversion result will be close to 0x3FF (1023). The reference voltage VREF of the ADC can be selected as AVCC or the internal 2.56V reference source of the chip, or as the reference voltage source externally connected to the AREF pin.
If an external fixed voltage source is connected to the AREF pin, any internal reference power supply cannot be used, otherwise the external voltage source will be short-circuited. The external reference power supply range should be between 2.0V and AVCC-0.2V. The first ADC conversion result after the reference power supply is changed may not be accurate, and it is recommended to discard the conversion result.
[page]
3. ADC conversion results
After the A/D conversion is completed (ADIF = 1), the conversion result can be obtained in the ADC data register (ADCL and ADCH). For the A/D conversion of single-ended input, the conversion result is:
ADC = (VIN × 1024) / VREF
Where VIN represents the voltage on the selected input pin, VREF represents the voltage of the selected reference power supply. 0x000 means the voltage of the input pin is the analog ground, and 0x3FF means the voltage of the input pin is the reference voltage value minus one LSB.
For a differential conversion, this results in:
ADC=(VPOS-VNEG)×GAIN×512/VREF
For example, if the differential input channel is selected as ADC3-ADC2, with a gain of 10, a reference voltage of 2.56V, and left-end alignment (ADMUX=0xED), the voltage on the ADC3 pin is 300mV, and the voltage on the ADC2 pin is 500mV.
Then ADCR=(300-500)×10×512/2560=-400=0x270, ADCL=0x00, ADCH=0x9C.
If the result is right-aligned (ADLAR="0"), ADCL=0x70, ADCH=0x02.
Appendix 2: In-depth discussion of ADC application design
Although the AVR has a 10-bit ADC integrated inside, in actual applications, to truly achieve a 10-bit accurate and relatively stable ADC is not as simple as the example in the previous section. It requires further comprehensive and detailed consideration from the aspects of hardware and software. The following are some key points that should be considered in ADC design and application.
1. Stability of AVcc.
AVcc is the power supply for ADC. If AVcc is unstable, it will affect the conversion accuracy of ADC. In Figure 10-5, the system power supply is connected to AVcc after passing through an LC filter. This can effectively suppress the high-frequency noise in the system power supply and improve the stability of AVcc. In addition, when using ADC in situations with higher requirements, try not to use the ports on the PA port that are not used as ADC input as digital I/O ports. Because the working power supply of the PA port is provided by AVcc, if there is a relatively large current fluctuation on the PA port, it will also affect the stability of AVcc.
2. Selection and determination of reference voltage VREF
In practical applications, the correct reference voltage VREF should be selected according to the range of the input measurement voltage in order to obtain better conversion accuracy. The reference voltage VREF of the ADC also determines the range of A/D conversion. If the input voltage of the single-ended channel exceeds VREF, the conversion results will all be close to 0x3FF. Therefore, the reference voltage of the ADC should be slightly larger than the highest value of the analog input voltage.
The reference voltage VREF of ADC can be selected as AVCC, or the 2.56V reference source inside the chip, or the reference voltage source externally connected to the AREF pin. The external reference voltage should be stable and greater than 2.0V (when the working voltage of the chip is 1.8V, the external reference voltage should be greater than 1.0V). In situations with higher requirements, it is recommended to connect a standard reference voltage source to the AREF pin as the reference power supply for the ADC.
3. ADC channel bandwidth and input impedance
Regardless of whether single-ended input conversion or differential input conversion is used, the input voltage of all analog input ports should be between AVcc and GND.
In single-ended ADC conversion mode, the input frequency bandwidth of the ADC channel depends on the ADC conversion clock frequency. A conventional ADC conversion requires 13 ADC clocks. When the ADC conversion clock is 1MHz, the number of ADC sampling conversions in one second is about 77K. According to the sampling theorem, the bandwidth of the ADC channel is 38.5KHz.
The bandwidth of the differential ADC conversion is determined by the bandwidth of the differential amplifier inside the chip, which is 4KHz.
4. Selection of ADC sampling clock
Under normal conditions, the AVR ADC successive comparison circuit needs a sampling clock of 50K~200KHz to achieve the maximum conversion accuracy. A normal ADC conversion process requires 13 sampling clocks. Assuming that the ADC sampling clock is 200KHz, the highest sampling rate is 200K/13=15.384K. Therefore, according to the sampling theorem, the theoretical maximum frequency of the measured analog signal is 7.7K!
Although the ADC sampling clock can be set to 1M, it does not improve the ADC conversion accuracy, but reduces the conversion accuracy (limited by the successive comparison hardware circuit), so the AVR ADC cannot complete the task of high-speed ADC. If the required conversion accuracy is less than 10 bits, the sampling clock can be higher than 200KHz to achieve a higher sampling frequency.
The ADC sampling clock is selected as follows: given or estimated the highest frequency fs of the analog signal to be measured, the sampling frequency is 4-10 times of fs, and then multiplied by 13 to get the ADC sampling clock frequency, which should be between 50K and 200KHz. If the frequency is greater than 200KHz, the 10-bit accuracy of the ADC cannot be guaranteed. If the frequency is less than 50Khz, a value between 50K and 200KHz can be selected.
5. Suppression of analog noise
The digital circuits outside and inside the device will generate electromagnetic interference and affect the accuracy of analog measurements. If the ADC conversion accuracy is very high, the following techniques can be used to reduce the impact of noise:
(1) Make the analog signal path as short as possible. Analog signal lines should pass through the analog ground wiring board and be kept as far away from high-speed switching digital signal lines as possible.
(2) The AVcc pin of the AVR should be connected to the digital power supply Vcc through an LC network.
(3) Use the ADC noise suppressor function to reduce the noise from inside the MCU.
(4) If some ADC pins are used as general digital output ports, do not change the status of these pins during the ADC conversion process.
6. ADC Calibration
Due to objective reasons such as the nonlinearity of the amplifier in the ADC part of the AVR, the ADC conversion result will have errors. If you want to obtain high-precision ADC conversion, you also need to correct the ADC result. For specific methods, please refer to the AVR application note AVR120 (avr_app_120.pdf). This application design reference introduces the types of errors and correction solutions in detail.
7. Improvement of ADC accuracy
With the above mentioned points guaranteed, the accuracy of ADC can be improved appropriately through software means, such as taking average of multiple measurements, software filtering algorithm, etc. AVR application note AVR121 (avr_app_121.pdf) introduces a software implementation using oversampling algorithm, which can improve the accuracy of ADC to 11 bits or higher, of course, this is achieved on the basis of spending more time.
Previous article:Design of AVR reset circuit
Next article:AVR MCU fuse settings
Recommended ReadingLatest update time:2024-11-16 15:19
- Popular Resources
- Popular amplifiers
- Learning PLC is easy - PLC ladder diagram and statement table with pictures (Li Changjun, Zhou Hua)
- A Complete Illustrated Guide to Operational Amplifier Applications (Written by Wang Zhenhong)
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
- ESP32-S3 source code
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- 【NXP Rapid IoT Review】+ Unboxing Review
- micrpython
- TMS320C665x]02, CCS v6.1 Full License Harmony
- Maintenance method of 18650 lithium battery pack
- Several considerations for DSP hardware design
- How to choose crystal oscillator capacitor for RTC and microcontroller?
- 【TouchGFX Design】Learning about straight lines and toggle buttons
- Summer benefits, download high-quality resources with one click for 0 points, and 30 download points are waiting for you!
- EBAZ4205 mining board based on Z7010, have you tried it?
- STM32 low power library upower