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



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

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

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

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

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

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

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

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

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

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

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

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

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

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

AT89C5131A Starter Kit... Software User Guide

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

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

General Porting Considerations. Memory EEPROM XRAM

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

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

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

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

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

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

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

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

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

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 2.0 Full-Speed Host/Function Processor AT43USB370. Summary. Features. Overview

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

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

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

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

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

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

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

2-wire Serial EEPROM AT24C1024. Advance Information

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

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

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)

USB Test Environment ATUSBTEST- SS7400. Summary

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

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

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

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

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

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

Two-wire Serial EEPROM AT24C1024 (1)

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

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

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

Application Note. 8-bit Microcontrollers. AVR280: USB Host CDC Demonstration. 1. 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

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

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

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

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

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

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

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

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

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

STK 500, AVRISP, AVRISP

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

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

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

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

2-wire Serial EEPROM AT24C512

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

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

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

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

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

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

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

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

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

8-bit Microcontroller. Application Note. AVR313: Interfacing the PC AT Keyboard

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

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

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

JTAG ICE.... User Guide

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

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

STK User Guide

8-bit. Application Note. Microcontrollers. AVR273: USB Mass Storage Implementation. Features. 1. Introduction

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

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

Application Note. AVR Microcontrollers. AVR493: Sensorless Commutation of Brushless DC Motor (BLDC) using AT90PWM3 and ATAVRMC

80C51 MCU s. Application Note. Analyzing the Behavior of an Oscillator and Ensuring Good Start-up. Oscillator Fundamentals

AN974 APPLICATION NOTE

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

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

ATEVK525 Mass Storage Board for AVR... Hardware User Guide

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

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

AVR Butterfly Training. Atmel Norway, AVR Applications Group

Transcription:

AVR314: DTMF Generator Features Generation of Sine Waves Using PWM (Pulse-Width Modulation) Combine Different Sine Waves to DTMF Signal Assembler and C High-level Language Code STK500 Top-Module Design 260 Bytes Code Size/128 Bytes Constants Table Size Use of Lookup Tables Introduction This application note describes how DTMF (Dual-Tone Multiple Frequencies) signaling can be implemented using any AVR microcontroller with PWM and SRAM. Applications such as phones are using DTMF signals for transmitting dialing information. There are two frequencies added together to generate a valid DTMF signal, a low frequency (f b ) and a high frequency (f a ). Table 1 shows how the different frequencies are mixed to form DTMF tones. 8-bit Microcontroller Application Note Figure 1. DTMF Generator V CC V CC PD5 AVR AT90S4414 PB7 PB0 1 2 3 A 4 5 6 B 7 8 9 C * 0 # D PB4 PB5 PB6 PB7 XTAL1 XTAL2 PB0 PB1 PB2 PB3 22 pf 8 MHz 22 pf Rev. 1

Table 1. DTMF Tone Matrix fb/fa 1209 Hz 1336 Hz 1477 Hz 1633 Hz 697 Hz 1 2 3 A 770 Hz 4 5 6 B 852 Hz 7 8 9 C 941 Hz * 0 # D The rows of the matrix shown in Table 1 represent the low frequencies while the columns represent the high frequency values. For example, this matrix shows that digit 5 is represented by a low frequency of f b = 770 Hz and a high frequency of f a = 1336 Hz. The two frequencies are transformed to a DTMF signal using equation 1: f () t = A a sin( 2π f a t ) + A b sin( 2π f b t) ) ( 1) where the ratio between the two amplitudes should be: A b A a = K 07, < K < 09, ( 2) Theory of Operation Generating Sine Waves Starting from a general overview about the usage of the PWM, it will be shown how the PWM allows to generate Sine Waves. In the next step, an introduction is given in how frequencies that are different from the ground frequency of the PWM can be generated. After closing the theoretical introduction with the DTMF signal itself, the implementation will be described. According to the relation between high level and low level at the output pin of the PWM, the average voltage at this pin varies. Keeping the relation between both levels constant generates a constant voltage level. Figure 2 shows the PWM output signal. Figure 2. Generation of a Constant Voltage Level V V H V AV V L x y t 2 AVR314

AVR314 While equation 3 shows how to calculate the voltage level: xv H + yv L V AV = ------------------------- ( 3) x+ y A sine wave can be generated if the average voltage generated by the PWM is changed every PWM cycle. The relation between high and low level has to be adjusted according to the voltage level of the sine wave at the respective time. Figure 3 visualizes this scheme. The values for adjusting the PWM can be calculated every PWM cycle or stored in a lookup table (LUT). Figure 3 also shows the dependency between frequency of the ground sine wave and the amount of samples. The more samples (Nc) are used, the more accurate the output signal gets. At the same time the frequency sinks. Equation 4 shows this correlation: f f l f CK 510 = ------ = --------------------- ( 4) Nc Nc f: Sine wave frequency (1/T) f L PWM frequency (f CK / 510) T: Period of ground sine wave f CK : Timer Clock Nc: Number of samples (12 in Figure 3) The PWM frequency is dependent on the PWM resolution. For an 8-bit resolution, the Timer TOP value is 0xFF (255). Because the timer counts up and down this value has to be doubled. In dividing the Timer Clock f CK by 510 the PWM frequency can be calculated. According to this coherence a Timer Clock of 8 MHz generates a PWM frequency of 15.6 khz. Modifying the Frequency of the Sine Wave Figure 3. Generating a Sine Wave with PWM V 1 2 3 4 5 6 7 8 9 10 11 12 t 1/fl T 3

Let s assume that the sinusoid samples for adjusting the PWM are not read in a sequentially manner from the lookup table but just every second value. At the same sample frequency an output signal with twice the frequency is generated (see Figure 4). Figure 4. Doubling the Output Frequency (X SW = 2) V 1 2 3 4 5 6 7 8 9 10 11 12 t 1/fl T/2 T In using not every second sample but every third, fourth, fifth... it is possible to generate Nc different frequencies in the range from [1/T Hz.. 0 Hz]. Note: for high frequencies it will not be a sine wave anymore. The step-width between samples is specified by X SW. Equation 5 describes this relation: X SW f ------ Nc fnc510 = = ---------------------- ( 5) f l F CK How to calculate the actual value with which the PWM has to be adjusted every PWM cycle (Timer overflow) is shown in equation 6. Based on the value of the previous cycle (X' LUT ) the new value (X LUT ) is calculated in adding the step-width (X SW ). X LUT = X LUT + X SW ( 6) X' LUT : X LUT : old position in lookup table new position in lookup table Adding the Two Different Frequencies to a DTMF Signal A DTMF signal has to be generated according to equations (1) and (2). Since this is easy to obtain with simple shift register operations a K-Factor of K = 3/4 has been chosen. By using equation (6) the lookup table position of the next value for adjusting the PWM can be calculated as follows: 3 f ( X LUT ) = f ( X LUTa ) + -- f ( X 4 LUTb ) ( 7) with X LUTa = X LUTa + X SWa X LUTb = X LUTb + X SWb 3 f ( X LUT ) = f ( X LUTa + X SWa ) + -- f ( X 4 LUTb + X SWb ) ( 8) 4 AVR314

AVR314 Implementation of the DTMF Generator In this application a DTMF tone generator is built using one of the 8-bit PWM outputs (OC1A) and a sinusoid table with Nc = 128 samples each with n = 7 bits. The following equations show this dependency and shows how the elements of the LUT are calculated: 2Π x f( x) = 63+ 63 sin ----------- 128 x [ 0 127] ( 9) The advantage in using 7 bits is that the sum of the high and low frequency signals fits in one byte. To support the whole DTMF tone set, we have to calculate eight X SW values, one for each DTMF frequency, and place them in a table. To achieve a higher accuracy, the following solution has been implemented: The X SW values calculated after equation 5 need only five bytes. To use all eight bytes to have a lower rounding error, this value is multiplied by eight. The pointer to the lookup table is saved in the same manner. But here two bytes are needed to store the actual value times eight. This means that three right shifts and a module operation with Nc have to be executed before using them as pointers to the sine values in the lookup table. Equation 10 shows the complete dependencies: X LUTa b, ROUND 1 8 -- X 8 Nc f 510 = LUTa, bext + --------------------------- ( 10) F CK X LUTa,b : Current position of element in LUT (actual format) X LUTa,bExt : Previous position of element in LUT (extended format) Figure 5. Schematics of the STK500 Top-Module AUXI0 CT7 CT5 CT3 CT1 NC RST PE1 VTG PC7 PC5 PC3 PC1 PA7 PA5 PA3 PA1 AUXO0 CT6 CT4 CT2 BSEL2 REF PE2 PE0 VTG PC6 PC4 PC2 PC0 PA6 PA4 PA2 PA0 1 2 3 A 4 5 6 B 7 8 9 C * 0 # D PB3 PB2 PB1 PB0 PB4 PB5 PB6 PB7 AUXI1 DATA7 DATA5 DATA3 DATA1 SI SCK XT1 VTG PB7 PB5 PB3 PB1 PD7 PD5 PD3 PD1 AUXO1 DATA6 DATA4 DATA2 DATA0 SO CS XT2 VTG PB6 PB4 PB2 PB0 PD6 PD4 PD2 PD0 J700 (Expand2) J701 (Expand1) The PWM signal is put out on the OC1A pin (PD5). An additional output filter will help to achieve a good sinusoid. If the PWM frequency is decreased, it can be necessary to implement a steeper filter to obtain a good result. 5

The connection with the keypad is shown in Figure 1. The functionality of the keypad determines how the pressed key has to be evaluated. It has to be done in two steps: 1. Determination of the row of the pressed key - define low nibble of PORTB as output/zero value - define high nibble of PORTB as input/pull up - low bit in high nibble determines row 2. Determination of the column of the pressed key - define high nibble of PORTB as output/zero value - define low nibble of PORTB as input/pull up - low bit in low nibble determines column Note: On the STK200 there are serial resistors between the PORTB header pins and the pins BP5, PB6 and PB7 of the part itself (please see the schematics of the STK200 for more details). This will cause problems if the keypad is connected to the PORTB header. Figure 6 visualizes the functionality of the routine to detect a pressed key. Dependent on which key is pressed it determines the step width value. The interrupt routine uses this values to calculate the PWM settings for the two Sine Waves of the DTMF tone. The interrupt routine is shown in Figure 7 and Figure 8. The interrupt routine calculates the output compare value for the next PWM cycle. The interrupt routine first calculates the position of the next sample value in the LUT and read the value stored there. The position of the sample in the LUT is determined by the step-width. The step-width itself is determined by the frequency which is to be generated. Combining the sample values of the both DTMF frequencies using formula 7 gives the final output compare value of the PWM. Figure 6. Main Function Main Check Keypad Key Pressed? No Step-width a,b = 0 Yes Set Step-width a,b According the Pressed Key 6 AVR314

AVR314 Figure 7. Interrupt Service Routine Timer Overflow ISR Timer1_OVF X LUTaEXT = X LUTaEXT ' + X SW OCR_RelVal a = GetSample (X LUTaEXT ) X LUTbEXT = X LUTbEXT ' + X SW OCR_RelVal b = GetSample (X LUTbEXT ) OCR = OCR_RelVal a + 3/4 OCR_RelVal b Return Figure 8. Function GetSample GetSample X LUTa,b = (X LUTa,bExt + 4) / 8 X LUTa,b < 128 OCR_RelVal = f(x LUTa,b ) Return 7

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