8-bit Microcontroller. Application Note. AVR400: Low Cost A/D Converter



Similar documents
8-bit Microcontroller. Application Note. AVR222: 8-point Moving Average Filter

AVR305: Half Duplex Compact Software UART. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

8-bit RISC Microcontroller. Application Note. AVR182: Zero Cross Detector

AVR134: Real Time Clock (RTC) using the Asynchronous Timer. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

General Porting Considerations. Memory EEPROM XRAM

8-bit RISC Microcontroller. Application Note. AVR236: CRC Check of Program Memory

AVR319: Using the USI module for SPI communication. 8-bit Microcontrollers. Application Note. Features. Introduction

AVR317: Using the Master SPI Mode of the USART module. 8-bit Microcontrollers. Application Note. Features. Introduction

8-bit Microcontroller. Application Note. AVR415: RC5 IR Remote Control Transmitter. Features. Introduction. Figure 1.

8-bit Microcontroller. Application Note. AVR314: DTMF Generator

AVR106: C functions for reading and writing to Flash memory. 8-bit Microcontrollers. Application Note. Features. Introduction

AT89C5131A Starter Kit... Software User Guide

How to Calculate the Capacitor of the Reset Input of a C51 Microcontroller 80C51. Application Note. Microcontrollers. Introduction

Tag Tuning/RFID. Application Note. Tag Tuning. Introduction. Antenna Equivalent Circuit

8-bit Microcontroller. Application Note. AVR105: Power Efficient High Endurance Parameter Storage in Flash Memory

Quick Start Guide. CAN Microcontrollers. ATADAPCAN01 - STK501 CAN Extension. Requirements

8-bit Microcontroller. Application. Note. AVR204: BCD Arithmetics. Features. Introduction. 16-bit Binary to 5-digit BCD Conversion bin2bcd16

AT91 ARM Thumb Microcontrollers. Application Note. Interfacing a PC Card to an AT91RM9200-DK. Introduction. Hardware Interface

8-bit Microcontroller. Application Note. AVR201: Using the AVR Hardware Multiplier

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

AVR241: Direct driving of LCD display using general IO. 8-bit Microcontrollers. Application Note. Features. Introduction AVR

Application Note. C51 Bootloaders. C51 General Information about Bootloader and In System Programming. Overview. Abreviations

AVR034: Mixing C and Assembly Code with IAR Embedded Workbench for AVR. 8-bit Microcontroller. Application Note. Features.

AVR245: Code Lock with 4x4 Keypad and I2C LCD. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR442: PC Fan Control using ATtiny13. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR030: Getting Started with IAR Embedded Workbench for Atmel AVR. 8-bit Microcontrollers. Application Note. Features.

AVR120: Characterization and Calibration of the ADC on an AVR. 8-bit Microcontrollers. Application Note. Features. Introduction

How To Prevent Power Supply Corruption On An 8Bit Microcontroller From Overheating

8-bit Microcontroller. Application Note. AVR461: Quick Start Guide for the Embedded Internet Toolkit. Introduction. System Requirements

3-output Laser Driver for HD-DVD/ Blu-ray/DVD/ CD-ROM ATR0885. Preliminary. Summary

AVR32110: Using the AVR32 Timer/Counter. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

USB Test Environment ATUSBTEST- SS7400. Summary

Application Note. USB Mass Storage Device Implementation. USB Microcontrollers. References. Abbreviations. Supported Controllers

8-bit Microcontroller. Application Note. AVR410: RC5 IR Remote Control Receiver

USB 2.0 Full-Speed Host/Function Processor AT43USB370. Summary. Features. Overview

AT91 ARM Thumb Microcontrollers. AT91SAM CAN Bootloader. AT91SAM CAN Bootloader User Notes. 1. Description. 2. Key Features

AVR32100: Using the AVR32 USART. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

Application Note. 8-bit Microcontrollers. AVR091: Replacing AT90S2313 by ATtiny2313. Features. Introduction

ATF15xx Product Family Conversion. Application Note. ATF15xx Product Family Conversion. Introduction

8-bit RISC Microcontroller. Application Note. AVR155: Accessing an I 2 C LCD Display using the AVR 2-wire Serial Interface

AVR444: Sensorless control of 3-phase brushless DC motors. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Table of Contents. Section 1 Introduction Section 2 Getting Started Section 3 Hardware Description

Step Motor Controller. Application Note. AVR360: Step Motor Controller. Theory of Operation. Features. Introduction

APPLICATION NOTE. Atmel AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Atmel AVR 8-bit Microcontroller. Introduction.

DIP Top View VCC A16 A15 A12 A7 A6 A5 A4 A3 A2 A1 A0 I/O0 I/O1 I/O2 GND A17 A14 A13 A8 A9 A11 A10 I/O7 I/O6 I/O5 I/O4 I/O3. PLCC Top View VCC A17

Application Note. Migrating from RS-232 to USB Bridge Specification USB Microcontrollers. Doc Control. References. Abbreviations

Application Note. 8-bit Microcontrollers. AVR280: USB Host CDC Demonstration. 1. Introduction

AVR32138: How to optimize the ADC usage on AT32UC3A0/1, AT32UC3A3 and AT32UC3B0/1 series. 32-bit Microcontrollers. Application Note.

AVR353: Voltage Reference Calibration and Voltage ADC Usage. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1301: Using the XMEGA DAC. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Two-wire Automotive Serial EEPROM AT24C01A AT24C02 AT24C04 AT24C08 (1) AT24C16 (2)

8-bit RISC Microcontroller. Application Note. AVR335: Digital Sound Recorder with AVR and DataFlash

2-wire Serial EEPROM AT24C1024. Advance Information

AVR033: Getting Started with the CodeVisionAVR C Compiler. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

tinyavr Microcontrollers White Paper is the registered trademark of Atmel Corporation, 2325 Orchard Parkway, San Jose, CA Rev.

2-Wire Serial EEPROM AT24C32 AT24C64. 2-Wire, 32K Serial E 2 PROM. Features. Description. Pin Configurations. 32K (4096 x 8) 64K (8192 x 8)

Application Note. 8-bit Microcontrollers. AVR307: Half Duplex UART Using the USI Module

256K (32K x 8) OTP EPROM AT27C256R 256K EPROM. Features. Description. Pin Configurations

AVR055: Using a 32kHz XTAL for run-time calibration of the internal RC. 8-bit Microcontrollers. Application Note. Features.

AVR1600: Using the XMEGA Quadrature Decoder. 8-bit Microcontrollers. Application Note. Features. 1 Introduction. Sensors

AVR32701: AVR32AP7 USB Performance. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

8-bit RISC Microcontroller. Application Note. AVR910: In-System Programming

AT86RF230 (2450 MHz band) Radio Transceiver... User Guide

AVR318: Dallas 1-Wire master. 8-bit Microcontrollers. Application Note. Features. Introduction

AVR1309: Using the XMEGA SPI. 8-bit Microcontrollers. Application Note. Features. 1 Introduction SCK MOSI MISO SS

Two-wire Serial EEPROM AT24C1024 (1)

AVR040: EMC Design Considerations. 8-bit Microcontrollers. Application Note PRELIMINARY. Scope. 1 Introduction

AVR1318: Using the XMEGA built-in AES accelerator. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Using CryptoMemory in Full I 2 C Compliant Mode. Using CryptoMemory in Full I 2 C Compliant Mode AT88SC0104CA AT88SC0204CA AT88SC0404CA AT88SC0808CA

Application Note. 8-bit Microcontrollers. AVR270: USB Mouse Demonstration

STK 500, AVRISP, AVRISP

AVR1900: Getting started with ATxmega128A1 on STK bit Microcontrollers. Application Note. 1 Introduction

AT91 ARM Thumb Microcontrollers. Application Note. GNU-Based Software Development on AT91SAM Microcontrollers. 1. Introduction. 2.

AVR068: STK500 Communication Protocol. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

3-output Laser Driver for HD-DVD/ Blu-ray/DVD/ CD-ROM ATR0885. Preliminary. Summary. Features. Applications. 1. Description

AVR1321: Using the Atmel AVR XMEGA 32-bit Real Time Counter and Battery Backup System. 8-bit Microcontrollers. Application Note.

AVR064: A Temperature Monitoring System with LCD Output. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

8-bit. Application Note. Microcontrollers. AVR282: USB Firmware Upgrade for AT90USB

All-band AM/FM Receiver and Audio Amplifier IC U2510B

AVR1922: Xplain Board Controller Firmware. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR2006: Design and characterization of the Radio Controller Board's 2.4GHz PCB Antenna. Application Note. Features.

AVR115: Data Logging with Atmel File System on ATmega32U4. Microcontrollers. Application Note. 1 Introduction. Atmel

ATF1500AS Device Family. Application Note. In-System Programming of Atmel ATF1500AS Devices on the HP3070. Introduction.

32-bit AVR UC3 Microcontrollers. 32-bit AtmelAVR Application Note. AVR32769: How to Compile the standalone AVR32 Software Framework in AVR32 Studio V2

AVR32788: AVR 32 How to use the SSC in I2S mode. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1510: Xplain training - XMEGA USART. 8-bit Microcontrollers. Application Note. Prerequisites. 1 Introduction

AVR441: Intelligent BLDC Fan Controller with Temperature Sensor and Serial Interface. 8-bit Microcontrollers. Application Note.

AVR125: ADC of tinyavr in Single Ended Mode. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR447: Sinusoidal driving of three-phase permanent magnet motor using ATmega48/88/ bit Microcontrollers. Application Note.

2-wire Serial EEPROM AT24C512

JTAG ICE.... User Guide

Application Note Microcontrollers. Guidelines to Keep ADC Resolution within Specification. Introduction. ADC Resolution

AVR131: Using the AVR s High-speed PWM. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

AVR2004: LC-Balun for AT86RF230. Application Note. Features. 1 Introduction

AN974 APPLICATION NOTE

Application Note. 8-bit Microcontrollers. AVR435: BLDC/BLAC Motor Control Using a Sinus Modulated PWM Algorithm. 1. Features. 2.

Atmel AVR4921: ASF - USB Device Stack Differences between ASF V1 and V2. 8-bit Atmel Microcontrollers. Application Note. Features.

APPLICATION NOTE Atmel AT02509: In House Unit with Bluetooth Low Energy Module Hardware User Guide 8-bit Atmel Microcontroller Features Description

AVR1003: Using the XMEGA Clock System. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Atmel AVR1017: XMEGA - USB Hardware Design Recommendations. 8-bit Atmel Microcontrollers. Application Note. Features.

Transcription:

AVR400: Low Cost A/D Converter Features Interrupt Driven : 23 Words Low Use of External Components Resolution: 6 Bits Measurement Range: 0-2 V Runs on Any AVR Device with 8-bit Timer/Counter and Analog Comparator Introduction This application note targets cost and space critical applications that need an ADC. It describes how to make a simple ADC with only two external components, a resistor and a capacitor. The design enables a very compact and inexpensive application. 8-bit Microcontroller Application Note Theory of Operation Nearly all AVR microcontrollers feature an Analog Comparator which makes it easy to implement an ADC. The signal to be measured is connected to the inverted input, and a reference signal is connected to the non-inverting input. The reference signal is generated by charging a capacitor through a resistor. When the capacitor is being charged, the voltage across it will follow an exponential curve. If the voltage range to be measured is limited to 2/5*V CC, the exponential curve is a good approximation to a straight line. The voltage of the applied signal, UIN is found by measuring the time it takes for the voltage across the capacitor to rise above the applied voltage. By using one pin on port B to control the charging and discharging of the capacitor, only three port pins are used. A schematic diagram is found in Figure 1. Figure 1. Circuit Diagram 5V RESET PD0 PD1 XTAL2 XTAL1 PD2(INT0) PD3 PD4(T0) PD5 GND VCC PB7(SCK) PB6(MISOI) PB5(MOSI) PB4 PB3 PB2 PB1(AIN1) PB0(AIN0) PD6 R UIN AT90S1200 C Rev. 1

The time constant of the R/C network must be tuned so that the following equation is satisfied: Component values for some typical Oscillator frequencies are shown in Table 1. If the time constant varies from this, it will cause errors in the result. This makes it necessary to use components with high accuracy in the RC-network. The voltage curve for the capacitor is shown together with a straight line in Figure 2. As the supply voltage is used as a reference, it must be stable during the conversion. Figure 2. A/D Converter Linearity 512 --------- = f RCln 1 2 5 -- RC = 1002 ------------ f Table 1. R/C Network Coomponent s XTAL (MHz) 1 2 4 6 8 10 12 14 16 R (kω) 100 33 30 30 27 100 56 47 160 C (nf) 10 15 8.2 5.6 4.7 1 1.5 1.5 0.39 To ensure proper operation, the capacitor must be discharged for at least 200 µs between conversions. If the capacitor is not properly discharged, it will not be possible to measure low values. If the voltage input is larger than 2/5 V CC, the converter will return the maximum value. This is accomplished by loading an offset value into the Timer/Counter0 Register before conversion starts. The timer will give an Overflow Interrupt after 512 cycles (64*8). This is the time it takes for the voltage across the capacitor to reach 2/5 V CC. If the voltage is within the operating range, an Analog Comparator interrupt will occur. Offset is subtracted from the measured value. Implementation The ADC uses Timer/Counter0 and the Analog Comparator interrupts. This frees the MCU resources during conversion. 2 AVR400

AVR400 Subroutine convert_init ADC Initialization This subroutine is called to initialize the ADC. This must be done before the ADC is used. By calling this subroutine, the Comparator and Timer interrupts are enabled, and the control pin is set as output. Then the SEI instruction, which enables global interrupts, should be called to enable the A/D converter. By calling CLI, the A/D converter is disabled. Table 2. convert_init Subroutine Performance Figures Execution Cycles 6 words 10, including the RET instruction Table 3. convert_init Register Usage Register Input Internal Output R16 "result" Scratch Register Figure 3. convert_init Flow Chart SET COMPARATOR AND INTERRUPT ENABLE TIMER INTERRUPT SET CONTROL PIN OUTPUT FINISHED - A/D INITIALIZED AD_convert Subroutine Start an A/D Conversion This routine is used to start an A/D conversion. It pre-loads the Counter with 256-64 and starts counting up at the frequency XTAL/8. The Conversion Complete Flag (the T- flag in the Status Register) is cleared, and the charging of the capacitor is started. Table 4. AD_convert Subroutine Performance Figures Execution Cycle 7 words 10 (including RET) Status Flags 3

Table 5. AD_convert Register usage Register Input Internal Output R16 SREG "result" Scratch Register Figure 4. ADC Conversion Flow Chart LOAD OFFSET INTO COUNTER T-flag This flag is used to indicate that a conversion is in progress. CLEAR CONVERSION COMPLETE FLAG START COUNTER, CLOCK/8 START CHARGING FINISHED - CONVERSION STARTED ANA_COMP Interrupt Handling Routine This routine is executed when a conversion is complete. It loads the Timer/Counter0 value, stops the timer and sets the Conversion Complete Flag (T-flag in SREG). The offset is then subtracted from the timer value. It is necessary to subtract one more than the offset, because the interrupt handling takes a minimum of seven cycles. Table 6. ANA_COMP Subroutine Performance Figures Execution Cycle 7 words 11 (including RETI) Status Flags Interrupt Usage Timer/Counter0 and Analog Comparator Interrupt :2 Table 7. ANA_COMP Register usage Register Input Internal Output R16 "result" Stores the Timer value "result" Contains the result from the A/D conversion R17 SREG "temp" Scratch Register T-Flag This flag is used to indicate that the conversion is finished 4 AVR400

AVR400 Figure 5. "ANA_COMP" Flowchart LOAD TIMER VALUE STOP TIMER REMOVE OFFSET FROM RESULT SET CONVERSION COMPLETE FLAG FINISHED - CONVERSION COMPLETE Example Program The example program that is included in this application note performs successive conversions, and presents the data as binary values on port B. Table 8. Overall Performance Figures Status Flags Interrupt Usage Peripheral Usage 23 words A/D converter routines only 37 words Complete with test program Timer/Counter0 Overflow Interrupt Analog Comparator Interrupt Timer/Counter0 Analog Comparator (port B pin0 and pin1) Port B pin2 Port D (example program only) :2 5

Atmel Headquarters Corporate Headquarters 2325 Orchard Parkway San Jose, CA 95131 TEL 1(408) 441-0311 FAX 1(408) 487-2600 Europe Atmel Sarl Route des Arsenaux 41 Case Postale 80 CH-1705 Fribourg Switzerland TEL (41) 26-426-5555 FAX (41) 26-426-5500 Asia Room 1219 Chinachem Golden Plaza 77 Mody Road Tsimhatsui East Kowloon Hong Kong TEL (852) 2721-9778 FAX (852) 2722-1369 Japan 9F, Tonetsu Shinkawa Bldg. 1-24-8 Shinkawa Chuo-ku, Tokyo 104-0033 Japan TEL (81) 3-3523-3551 FAX (81) 3-3523-7581 Atmel Operations Memory 2325 Orchard Parkway San Jose, CA 95131 TEL 1(408) 441-0311 FAX 1(408) 436-4314 Microcontrollers 2325 Orchard Parkway San Jose, CA 95131 TEL 1(408) 441-0311 FAX 1(408) 436-4314 La Chantrerie BP 70602 44306 Nantes Cedex 3, France TEL (33) 2-40-18-18-18 FAX (33) 2-40-18-19-60 ASIC/ASSP/Smart Cards Zone Industrielle 13106 Rousset Cedex, France TEL (33) 4-42-53-60-00 FAX (33) 4-42-53-60-01 1150 East Cheyenne Mtn. Blvd. Colorado Springs, CO 80906 TEL 1(719) 576-3300 FAX 1(719) 540-1759 Scottish Enterprise Technology Park Maxwell Building East Kilbride G75 0QR, Scotland TEL (44) 1355-803-000 FAX (44) 1355-242-743 RF/Automotive Theresienstrasse 2 Postfach 3535 74025 Heilbronn, Germany TEL (49) 71-31-67-0 FAX (49) 71-31-67-2340 1150 East Cheyenne Mtn. Blvd. Colorado Springs, CO 80906 TEL 1(719) 576-3300 FAX 1(719) 540-1759 Biometrics/Imaging/Hi-Rel MPU/ High Speed Converters/RF Datacom Avenue de Rochepleine BP 123 38521 Saint-Egreve Cedex, France TEL (33) 4-76-58-30-00 FAX (33) 4-76-58-34-80 e-mail literature@atmel.com Web Site http://www.atmel.com Atmel Corporation 2002. Atmel Corporation makes no warranty for the use of its products, other than those expressly contained in the Company s standard warranty which is detailed in Atmel s Terms and Conditions located on the Company s web site. The Company assumes no responsibility for any errors which may appear in this document, reserves the right to change devices or specifications detailed herein at any time without notice, and does not make any commitment to update the information contained herein. No licenses to patents or other intellectual property of Atmel are granted by the Company in connection with the sale of Atmel products, expressly or by implication. Atmel s products are not authorized for use as critical components in life support devices or systems. ATMEL and AVR are the registered trademarks of Atmel. Other terms and product names may be the trademarks of others. Printed on recycled paper. 0M