Introduction AT90S1200

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

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

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

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

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

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

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

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

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

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

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

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

General Porting Considerations. Memory EEPROM XRAM

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

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

2-wire Serial EEPROM AT24C512

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

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

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

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

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

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

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

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

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

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

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

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

AT89C5131A Starter Kit... Software User Guide

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

USB Test Environment ATUSBTEST- SS7400. Summary

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

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

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)

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

AVR1324: XMEGA ADC Selection Guide. 8-bit Atmel Microcontrollers. Application Note. Features. 1 Introduction

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

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

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

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

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

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

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

HANDLING SUSPEND MODE ON A USB MOUSE

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

2-wire Serial EEPROM AT24C1024. Advance Information

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

STK 500, AVRISP, AVRISP

AVR127: Understanding ADC Parameters. Introduction. Features. Atmel 8-bit and 32-bit Microcontrollers APPLICATION NOTE

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

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

APPLICATION NOTE. Atmel AVR443: Sensor-based Control of Three Phase Brushless DC Motor. Atmel AVR 8-bit Microcontrollers. Features.

How To Use A Watt Saver On A Microcontroller (Watt Saver) On A Cell Phone Or Mp3 Player

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

AN3265 Application note

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

AN2680 Application note

Poor Man s A/D Converter By Dave Wissel at Wave Technology

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

AN3252 Application note

Flexible Active Shutter Control Interface using the MC1323x

AVR223: Digital Filters with AVR. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AN974 APPLICATION NOTE

Software Real Time Clock Implementation on MC9S08LG32

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.

Atmel AVR4920: ASF - USB Device Stack - Compliance and Performance Figures. Atmel Microcontrollers. Application Note. Features.

Application Note. 8-bit Microcontrollers. AVR272: USB CDC Demonstration UART to USB Bridge

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

SEMICONDUCTOR TECHNICAL DATA

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

AN2604 Application note

Two-wire Serial EEPROM AT24C1024 (1)

Digital to Analog and Analog to Digital Conversion

Transcription:

AVR401: 8-bit Precision A/D Converter Features Very Low Cost High Precision Auto-calibration Eliminates Component Inaccuracy Measures Voltages for 0 to V CC Maximum Conversion Time: 1.1 ms Figure 1. A/D Converter Introduction This application note describes how to perform a kind of dual slope A/D conversion with an AVR microcontroller. The converter is very low cost, requiring only six discrete components in addition to the AVR. Five of the controller pins are used (see Figure 1). This example is based on the AT90S1200 device, but any AVR device with a comparator can be used. 8-bit Microcontroller Application Note AVR401 V CC T R B PB7 (AIN0) PB0 AT90S1200 C (AIN1) PB1 PB2 R ref 1 V in (V ) ref R in R ref 2 PB3 Theory of Operation The capacitor is charged with a constant current supplied by the transistor. The capacitor voltage will rise linearly. To discharge the capacitor, the AIN0-pin is set to output with a 0 applied. A reference voltage at V CC /2 is supplied by the resistor network R ref1 and R ref2. When the PB1 and PB2-pins are configured as inputs, the reference is turned off, and the voltage level at the AIN1-pin will be the input voltage V in. By setting the pins as outputs and applying a 0 and a 1, the level at the AIN1-pin will be V CC /2 (if the resistors are of equal size). The input resistor R in have to be at least 100 times higher than the reference resistors R ref1 and R ref2 to avoid measurement errors. Rev. 0953B-08/00 1

The algorithm used for the conversion is as follows: 1. Turn on the reference 2. Charge the capacitor until the reference voltage is reached. Measure the time needed for this, T ref 3. Turn off the reference and discharge the capacitor 4. Charge the capacitor until the input voltage is reached. Measure the time needed for this, T in The conversion cycle is shown in Figure 2. The time measurement is performed by the Timer/Counter, which is expanded to nine bits by using the Timer/Counter Overflow interrupt. Figure 2. Conversion Cycle Calculation Suppose that V CC is 5 volts. The relationship between the input voltage and the reference voltage is given by: V Equation 1 V ref T in = -------------------------- in T ref The ideal output from the conversion is an 8-bit number, where 0 volts corresponds to zero and 5 volts is 255. The reference voltage V CC /2 thus corresponds to 128. The equation can be re-written as: T Equation 2 in 128 V in = ------------------------ T ref However, with inaccuracy in the reference resistors, the reference voltage may vary slightly. To compensate for this, a calibration can be performed by applying a known voltage at the input, and compare this to the reference. If the applied calibration voltage is exactly 2.5 volts, the reference voltage can be found by the equation: Equation 3 T ref V cal T ref 128 V ref = ----------------------------- = --------------------------- T cal T cal The calibration cycle is executed by holding the PB7-pin high during power-up. The calibration voltage is then applied, and the PB7-pin is set low. This starts calibration, and once performed, the value of the reference voltage is stored in EEPROM. During normal operation, the reference value is read from EEPROM, and the input voltage is calculated using Equation 1. Configuration Example As the resulting output is to be 8 bits, the timer should be of at least 9 bits to maintain the resolution. The components should be chosen so that the nominal time charging the capacitor up to V CC is about 256 timer steps. In that way, inaccuracy in the component values and temperature changes are allowed, without causing the charging time to be longer than the maximum timer period, or too short, giving lower resolution. To achieve sufficient accuracy, a prescaler factor of 8 or higher should be used. The AT90S1200 Timer/Counter0 is of only 8 bits, so the 9th bit must be handled in software. The following example illustrates how the component values can be found. First, decide which crystal frequency to operate at. With a 4 MHz crystal, the clock period is 250 ns. By setting the prescaler to CK/8, the timer is incremented every 2 ms. The maximum timer period with 9 bits is 512 =2 ms = 1,024 ms. From this, we set 2 =T ref to 512 ms. The charging of a capacitor whit a constant current is described by the equation: I Equation 4 V = --- t C We can find the required current when the capacitor size, the time and the voltage difference is known: Equation 5 I = V ----------------- C t The capacitor will be charged up to V CC = 5V, and with a 0.22 mf capacitor, the transistor must supply a current of 2.15 ma. The R B value is dependent upon the transistor s h FE. For a BC558A pnp transistor, h FE is in the range 125 to 250. This makes this transistor ideal for use, since any h FE value in the specified range can be used. To make sure the full range in h FE can be used, the average value, 188, is used in the calculations. The resulting base current is 11.4 µa. The transistor is turned on by applying a 0 on the corresponding pin. At this current values, the transistor baseemitter voltage is about 0.1 V. The base resistor is found to be: Equation 6 V CC + V BE 4.9V R B = ------------------------------- = ------------------- = 430kΩ I B 11.4µA 2 AVR401

AVR401 The reference voltage is generated by the divider network R ref1 and R ref2. The R in has to be much larger than these two, so that the input voltage will not influence with the reference voltage. 100 kω for R in and 1 kω for each of R ref1 and R ref2 is suitable. The transistor should be connected to a pin as long away from the comparator inputs as possible. When a pin is switched, a noise spike appear at the adjacent pins. This will cause problems when measuring low voltages, as the noise spike might trigger the comparator before the capacitor voltage has reached the measured voltage. Figure 3 shows measured linearity for a 4 MHz clocked application using the component values calculated in the above example. Figure 3. Measured Linearity LINEARITY O U T P U T V A L U E 250 200 150 100 50 0 0 1 2 3 4 5 INPUT VOLTAGE Implementation The software consist of several subroutines. The routines reference and convert handles the charging and timing. After they complete execution, the main program must perform the calculation needed. This is done using two subroutines that performs division and multiplication, div17u and mul9. There are also two delays used by the other routines and the main program. They are used to discharge the capacitor completely and to generate a delay between each conversion. reference Subroutine - Measures the Reference Voltage The routine discharges the capacitor, turns on the transistor and charges the capacitor until the capacitor voltage is equal to the reference voltage. The time from the beginning of the charging and until the voltages are equal is measured. The capacitor is then discharged again. The charging time is used together with the charging time from the convert routine to calculate the input voltage. This routine does not have to be called every time a conversion is performed, depending on variations in ambient temperature. Especially the parameter h FE in the transistor is quite temperature dependent, so if the ambient temperature is varying, the subroutine will have to be executed frequently. In the example program, the reference routine is called each time a conversion is performed. Table 1. reference Subroutine Performance Figures Execution cycles 24 words Depends on the reference voltage. ` Low registers ` Global :2 :1 Table 2. reference Register Input Internal Output R17 Tref - Holds the time to reach the reference voltage. R18 R20 TH - High part of timer. temp 3

Figure 4. Flow Chart for reference reference AIN0 as output (discharge capacitor) PB2 and PB3 as outputs (Turn on V ) ref delay Clear timer variables AIN0 as input (capacitor ready for charging) Turn on transistor (charge capacitor) Yes ACO = 1? (V cap > V ref?) No Timer > 0x1FF? No Yes Store T ref Stop timer Turn off transistor AIN0 as output (discharge capacitor) PB2 and PB3 as inputs (Turn off V ) ref return 4 AVR401

AVR401 input Subroutine - Measures the Input Voltage The routine turns on the transistor and charges the capacitor until the capacitor voltage is equal to the input voltage. Then capacitor is then discharged. The time needed to do this is measured and stored in T in. There should be a few microseconds delay between two conversion cycles, to ensure that the capacitor is completely discharged. In the example program, this is done by calling a delay routine. Table 3. input Subroutine Performance Figures Execution Cycles 19 words Depends on the input voltage ` Low registers ` Global :2 :1 Table 4. input Register Input Internal Output R14 R15 R20 temp TinH - High part of the input voltage charge time. TinL - Low part of the input voltage charge time. 5

Figure 5. Flow Chart for input input AIN0 as input (capacitor ready for charging) Clear error flag Clear timer variables Turn on transistor (charge capacitor) Yes ACO = 1? (V cap > V in?) No Timer > 0x1FF? No Yes Set error flag Store T in Stop timer Turn off transistor AIN0 as output (discharge capacitor) return 6 AVR401

AVR401 T0_int Interrupt Service Routine The only function for this routine is to increment the TH variable, so a 16-bit timer is created. Only 9 bits are used. Table 5. T0_int interrupt Performance Figures Execution Cycles 2 words 9 - including the reti instruction ` Low registers ` Global :1 mpy9u 9 8 Bit Multiplication This routine performs a 9 8 bit multiplication. The 9-bit multiplier must be stored in the carry-flag (MSB) and the mp9u register. The multiplicand is stored in the mc9u register. The answer is placed in C:m9uH:m9uL. The registers used for the result are the same as those used for the input to the division routine. The routine is based on the mpy8u multiplication routine described in application note AVR 200. Table 6. mpy9u Subroutine Performance Figures Execution cycles 83 11 words ` Low registers ` Global ` Flags :3 :1 :C Table 7. mpy9u Register Input Internal Output R0 mc9u - Multiplicand R1 mp9u - Multiplier m9ul - Result low byte R2 m9uh - Result high byte C-flag Multiplier, 9th bit Result, 17th bit R20 temp - Used as loop counter div17u 17/16 Bit Division This routine performs a 17/16 bit division. The 17-bit dividend must be stored in the (C:didH:didL) variable, where the carry-flag is most significant. The divisor is stored in the (divh:divl) variable. The result is placed in (resh:resl) and the reminder in (remh:reml). The routine is based on the div16u multiplication routine described in application note AVR 200. 7

Table 8. div17u Subroutine Performance Figures Execution Cycles 18 words 209 min, 292 max. `Low registers ` Global ` Flags :6 :1 :C Table 9. div17u Register Input Internal Output R1 didl - Low part dividend dresl - Low part result R2 didh - High part dividend dresh - High part result C-flag R3 R4 R5 R6 17th bit of dividend divl - Low part divisor divh - High part divisor reml - Low part reminder remh - High part reminder Example Program The included example program performs repeated conversions. First, the charging time for the reference is measured, then for the input voltage. The result is output to Port D and Port B pin 4 (MSB). The result is inverted before it is output, so active low LEDs can be connected to show the result. This conversion cycle is repeated in an endless loop. To perform a calibration the PB7-pin must be initially in high state and the capacitor has to be discharged. Afterwards the user should apply 2.5 volts at the input before setting the PB7-pin low. The calibrated V ref is stored in EEPROM, where it is fetched at every normal power-up. 8 AVR401

AVR401 Performance Figures Table 10. Overall Performance Figures Interrupt Usage Peripheral Usage 43 words - Conversion routines only (not mpy9u and div17u) 147 words - Complete application note ` Low Registers ` Pointers Timer/Counter 0 Interrupt :9 :5 Timer/Counter0 Analog Comparator Port B, pin 0 to 3 and pin 7 Port D, all pins (example program only) Port B, pin 4 (example program only) The calibration routine can be skipped if only relative values are measured. The reference voltage is then assumed to be 128, which will also make the calculations easier. The reference network can be substituted with a voltage reference to achieve even better accuracy. It is then possible to measure variations in V CC by connecting it via a voltage divider network to the input. 9

Atmel Headquarters Corporate Headquarters 2325 Orchard Parkway San Jose, CA 95131 TEL (408) 441-0311 FAX (408) 487-2600 Europe Atmel U.K., Ltd. Coliseum Business Centre Riverside Way Camberley, Surrey GU15 3YL England TEL (44) 1276-686-677 FAX (44) 1276-686-697 Asia Atmel Asia, Ltd. Room 1219 Chinachem Golden Plaza 77 Mody Road Tsimhatsui East Kowloon Hong Kong TEL (852) 2721-9778 FAX (852) 2722-1369 Japan Atmel Japan K.K. 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 Atmel Colorado Springs 1150 E. Cheyenne Mtn. Blvd. Colorado Springs, CO 80906 TEL (719) 576-3300 FAX (719) 540-1759 Atmel Rousset Zone Industrielle 13106 Rousset Cedex France TEL (33) 4-4253-6000 FAX (33) 4-4253-6001 Fax-on-Demand North America: 1-(800) 292-8635 International: 1-(408) 441-0732 e-mail literature@atmel.com Web Site http://www.atmel.com BBS 1-(408) 436-4309 Atmel Corporation 2000. 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. Marks bearing and/or are registered trademarks and trademarks of Atmel Corporation. Terms and product names in this document may be trademarks of others. Printed on recycled paper. 0953B08/00/xM