1. Development Language
This example was developed using WinAVR/GCC 20050214 version
2. Example Description
This program simply demonstrates how to use the ADC analog-to-digital converter of ATMEGA16. Common single-ended input, differential input and calibration, reference voltage calibration, query mode, interrupt mode, data format conversion. In order to simplify the program, various data are not output to the outside. It is recommended to use the JTAG ICE hardware emulator when learning.
3. Circuit diagram design:
To simplify the circuit design, the ATmega16 function board from this website was used.
In the example, the internal 2.56V voltage reference is selected as Vref, and the differential channel is magnified 10 times
. The single-ended voltage measurement range is 02.56V, resolution is 2.5mV.
The differential voltage measurement range is +/- 256mV, resolution is 0.5mV.
Current resolution = 50uA@10 ohm current sampling resistor
Current resolution = 500uA@1 ohm current sampling resistor
In the program, the measured reference voltage needs to be substituted into the constant Vref to obtain a more accurate result
The sample I have is measured to be 2.556V@Vcc=5.0V
2.550V@Vcc=3.3V
This circuit is for reference only and does not consider the requirements for anti-interference.
.
4. Code design and description:
/******************************************************** ADC (analog-to-digital conversion) usage example ******* ******* Planning, organization and testing: Armok ***
**** Code design: HJJourAVR ******* Compiler: WINAVR20050214 ******* www.OurAVR.com 2005.8.31 ****************************************************/#include
//Pin definition
#define in_Single 0 //PA0(ADC0)
#define in_Diff_P 3 //PA3(ADC3)
#define in_Diff_N 2 //PA2(ADC2)
//Constant definition
//Single-ended channel, no amplification
#define AD_SE_ADC0 0x00 //ADC0
#define AD_SE_ADC1 0x01 //ADC1
#define AD_SE_ADC2 0x02 //ADC2
#define AD_SE_ADC3 0x03 //ADC3
#define AD_SE_ADC4 0x04 //ADC4
#define AD_SE_ADC5 0x05 //ADC5
#define AD_SE_ADC6 0x06 //ADC6
#define AD_SE_ADC7 0x07 //ADC7
//Differential channel ADC0 as negative terminal, 10/200 times magnification
#define AD_Diff0_0_10x 0x08 //ADC0+ ADC0-, 10 times magnification, for calibration
#define AD_Diff1_0_10x 0x09 //ADC1+ ADC0-, 10 times magnification
#define AD_Diff0_0_200x 0x0A //ADC0+ ADC0-, 200 times magnification, for calibration
#define AD_Diff1_0_200x 0x0B //ADC1+ ADC0-, 200 times magnification
//Differential channel ADC2 as negative terminal, 10/200 times magnification
#define AD_Diff2_2_10x 0x0C //ADC2+ ADC2-, 10 times magnification, for calibration
#define AD_Diff3_2_10x 0x0D //ADC3+ ADC2-, 10 times magnification
#define AD_Diff2_2_200x 0x0E //ADC2+ ADC2-, 200 times magnification, for calibration
#define AD_Diff3_2_200x 0x0F //ADC3+ ADC2-, 200 times magnification
//Differential channel ADC1 is used as the negative terminal and is not amplified
#define AD_Diff0_1_1x 0x10 //ADC0+ ADC1-
#define AD_Diff1_1_1x 0x11 //ADC1+ ADC1-, for calibration
#define AD_Diff2_1_1x 0x12 //ADC2+ ADC1-
#define AD_Diff3_1_1x 0x13 //ADC3+ ADC1-
#define AD_Diff4_1_1x 0x14 //ADC4+ ADC1-
#define AD_Diff5_1_1x 0x15 //ADC5+ ADC1-
#define AD_Diff6_1_1x 0x16 //ADC6+ ADC1-
#define AD_Diff7_1_1x 0x17 //ADC7+ ADC1-
//Differential channel ADC2 is used as the negative terminal and is not amplified
#define AD_Diff0_2_1x 0x18 //ADC0+ ADC2-
#define AD_Diff1_2_1x 0x19 //ADC1+ ADC2-
#define AD_Diff2_2_1x 0x1A //ADC2+ ADC2-, for calibration
#define AD_Diff3_2_1x 0x1B //ADC3+ ADC2-
#define AD_Diff4_2_1x 0x1C //ADC4+ ADC2-
#define AD_Diff5_2_1x 0x1D //ADC5+ ADC2-
//Single-ended channel, no amplification
#define AD_SE_VBG 0x1E //VBG internal bandgap 1.22V voltage reference, for calibration
#define AD_SE_GND 0x1F //Ground calibration
//Note:
//Differential channels, if using 1x or 10x gain, 8-bit resolution is available. If using 200x gain, 7-bit resolution is available.
//Differential input channel devices in PDIP package are not tested. Devices are only guaranteed to work properly in TQFP and MLF packages.
#define Vref 2556 //mV measured Vref pin voltage @5.0V power supply
//#define Vref 2550 //mV measured Vref pin voltage @3.3V power supply
//Global variables
unsigned int ADC_SingleEnded; //ADC value of single-ended input
int ADC_Diff; //ADC value of differential input
volatile unsigned int ADC_INT_SE; //ADC value of single-ended input used in interrupt mode, will be modified in interrupt service routine,
//must be qualified by volatile
volatile unsigned char ADC_OK; //ADC status, will be modified in interrupt service routine, must be qualified by volatile
unsigned int LED_Volt; //Converted voltage mV
int LED_Curr; //Conversion
Previous article:AVR Studio Quick Start
Next article:AVR MCU JTAG Debugging Quick Start
Recommended ReadingLatest update time:2024-11-16 19:35
- Popular Resources
- Popular amplifiers
- Principles and Applications of Single Chip Microcomputers 3rd Edition (Zhang Yigang)
- Metronom Real-Time Operating System RTOS for AVR microcontrollers
- Learn C language for AVR microcontrollers easily (with video tutorial) (Yan Yu, Li Jia, Qin Wenhai)
- ATmega16 MCU C language programming classic example (Chen Zhongping)
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
- 【CH579M-R1】+BH1750 light intensity detection
- Introduction to Several Common Laser Sensor Applications
- Both ends are TYPEC ports
- 5G Overview and Fundamentals
- TI's F28379D controlCARD for C2000 Real-Time Control Development Kit
- Please help, how does the FPGA Ethernet data receiver perform CRC check?
- A Brief Analysis of Wireless Positioning Technology
- [TI recommended course] #C2837x Getting Started Guide#
- EEWORLD University Hall--One minute to understand: SRRC certification
- It turns out that she was the one who scolded Lei Jun for an hour as if he were a primary school student