AVR131: Using the AVR s High-speed PWM. 8-bit Microcontroller. Application Note. Features. Introduction. Theory of Operation

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

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

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.

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

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

How to Calculate the Capacitor of the Reset Input of a C51 Microcontroller 80C51. Application Note. Microcontrollers. 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

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

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

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

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

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

AT89C5131A Starter Kit... Software User Guide

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

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

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

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

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

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.

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

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

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

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

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

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

AVR32100: Using the AVR32 USART. 32-bit 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

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

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

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

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

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

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

USB Test Environment ATUSBTEST- SS7400. Summary

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.

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

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

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

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

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

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

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

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

AVR1301: Using the XMEGA DAC. 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.

AVR033: Getting Started with the CodeVisionAVR C Compiler. 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

STK 500, AVRISP, AVRISP

2-wire Serial EEPROM AT24C1024. Advance Information

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

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)

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

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

Two-wire Serial EEPROM AT24C1024 (1)

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

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

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

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

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

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

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

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

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

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

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

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

AVR Timer/Counter. Prof Prabhat Ranjan DA-IICT, Gandhinagar

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

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

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

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

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

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

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.

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

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

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

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

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

2-wire Serial EEPROM AT24C512

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

Flexible Active Shutter Control Interface using the MC1323x

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

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

AN3252 Application note

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

Transcription:

AVR131: Using the AVR s High-speed PWM Features Analog Waveform Generation using PWM High-speed Prescalable PWM Clock 8-bit Microcontroller Introduction This application note is an introduction to the use of the high-speed Pulse Width Modulator (PWM) available in some AVR microcontrollers. The assembly code example provided shows how to use the fast PWM in the ATtiny26. The ATtiny15 also features a high-speed PWM timer. The fast PWM is used to generate a pulse train with varying duty-cycle on the OC1A output pin (PB1). An analog filter can be used to shape the digital PWM output to obtain an analog signal such as a sine wave. The advantage of high-speed PWM is the increased bandwidth of the analog output signal and that the high frequency allows for smaller and less expensive filter components used to shape the signal. Application Note Theory of Operation PWM combined with an analog filter can be used to generate analog output signals, i.e. a digital to analog converter (DAC). A digital pulse train with a constant period (fixed base frequency) is used as a basis. To generate different analog levels, the duty cycle and thereby the pulse width of the digital signal is changed. If a high analog level is needed, the pulse width is increased and vice versa. Averaging the digital signal over one period (using an analog low-pass filter) generates the analog signal. A duty cycle of 50% gives an analog signal with half the supply voltage, while 75% duty cycle gives an analog signal with 75% supply voltage. Examples on filtered output signals are shown at the end of this document. The analog low-pass filter could be a simple passive RC-filter for instance. The filter removes the high PWM base frequency and lets through the analog signal. The filter crossover frequency must be chosen high enough to not alter the analog signal of interest. At the same time it must be as low as possible to minimize the ripple from the PWM base frequency. Rev.

Figure 1. Low-pass RC-filter PWM in R C Analog out If the analog signal is fed to a low-impedance input, a buffer amplifier should be connected between the filter output and the load. This will prevent the load from discharging the capacitor and creating ripple voltages. A real-life example of varying duty cycle Pulse Width Modulation is shown in figure 2. Figure 2. PWM Output with Varying Duty Cycle In the AVR, the timer/counters are used to generate PWM signals. To change the PWM base frequency, the timer clock frequency and top counter value is changed. Faster clock and/or lower top value will increase the PWM base frequency, or timer overflow frequency. With full resolution (top value 255) the maximum PWM base frequency is 250 khz. Increasing the base frequency beyond this frequency will be at the expense of reduced resolution, since fewer step are then available from 0% to 100% duty cycle. Altering the value of the Output Compare Registers () changes the duty cycle. Increasing the value increases the duty cycle. The PWM output is high until the value is reached, and low until the timer reaches the top value and wraps back to 0. This is called Fast-PWM mode. 2 AVR131 App Note

AVR131 App Note Figure 3. Counter Values and PWM Output Counter value value PWM output If using the high-speed PWM to generate analog signals, the step-size between the analog levels is depending on the resolution of the PWM. The higher base frequency the more easily is it to attenuate the base frequency and thereby minimize the signal ripple. The selection of resolution versus base frequency is thus an application dependent trade-off. Alternative Usage The high-speed timer can also be used to generate high frequency digital signals, which can be used to clock other digital parts in the application. Setting the counter top value to a small value, very high base frequencies are available. The highest possible timer clock frequency for the ATtiny26 high-speed timer is 64 MHz (no prescaling). At 16 MHz PWM base frequency (top value 3) the value can be set to 0, 1 (25% duty cycle), 2 (50% duty cycle, A in Figure 4) or 3 (100% duty cycle). This shows that lowering the top value to increase the PWM base frequency reduces the resolution. To achieve the maximum output frequency from the timer, it must be run in non-pwm mode. Both the value and the top value must be set to 0. The counter is then stuck at 0. Setting the Output Compare Match action to toggle output makes the timer toggle the output on every timer clock tick. The result is a 32 MHz signal (B in Figure 4). 3

Figure 4. High Frequency Digital Output 64 MHz timer clock ticks Counter values 16 MHz 50% PWM (A) 32 MHz non-pwm mode (B) Application Example Figure 5 illustrates how to generate a sine wave from the high-speed PWM output. The code consists of 3 parts: Initialization, Timer1 overflow interrupt service routine and a sleep loop. The implementation assumes that the device system clock is 8 MHz. Figure 5. Main Loop of Sine Wave Generator Example Code Main( ) Init() Timer1 OVF interrupt Sleep 4 AVR131 App Note

AVR131 App Note Initialization To be able to generate an output from the PWM, the Output Compare Pin of Timer1 (OC1A) is set up as output. Next the Timer1 is set up: The clock source for the timer is prepared the PLL is started and locked to the system clock (required). The PLL takes approximately 100 ms to lock onto the system clock and it is therefore necessary to wait for the PLL lock flag before proceeding. Once the PLL is locked it is selected as clock source for the timer. The PWM mode is then selected so that the OC1A pin toggles on compare match and the Top value of the timer is set to 0xFF. The Top value affects the resolution and the base frequency of the PWM the higher the Top value is the higher resolution and the lower base frequency. The Timer is now ready to be started: The prescaler is set, which also starts the timer. Finally, the Overflow interrupt is enabled. Figure 6. Init Routine, Initializes Pin and Timer1 to Operate in Fast PWM Mode Init() Set PB1 as output Set PWM mode: toggle OC1A on compare Enable and lock PLL Set PWM Top value: 1C = 0xFF Wait for PLL to lock (app. 100 ms) Enable Timer/ Set PWM clock prescaler to PCK/2 (32 MHz PWM clock) Set PLL as PWM clock source Enable Timer1 OVF interrupt Return Interrupt Service Routine When the Timer1 value reaches the 1C value (0xFF), the Timer Overflow interrupt service routine (ISR) is executed. This happens at a constant interval, since 1C is constant. This interval is the base frequency of the fast PWM output signal. In the Timer1 Overflow ISR, a look up in a sine table is made. On each look-up the index to the look-up table is incremented so that new values can be loaded. The value from the sine table is written to 1A. In this way the pulse width is modulated to the sine 5

wave. Note that the 1A register is buffered and that the latching of the buffer into the actual 1A register takes place on the timer overflow. The interrupt routine takes 13 clock cycles to execute. The call and return to and from the interrupt comes in addition in total 21 system clock cycles. Since Timer1 is an 8-bit timer the interrupt occurs every 256/(PWM_clock/system_clock) cycle. The example is based on that the device is clocked from the internal RC oscillator, which is 8 MHz. If the maximum PWM clock, 64 MHz, is used this would mean a Timer1 Overflow interrupt every 32 cycles. Though it is possible to clock the PWM with the maximum frequency of 64 MHz, the PWM clock is in this application note prescaled by 4 to 16 MHz to illustrate the use of the prescaler. Figure 7. Timer1 Overflow Interrupt Service Routine Timer1 OVF ISR Look-up new pulse width in sine table Increment sine table pointer Copy sine value (pulse width) to 1A Return from interrupt Idle Scope Pictures The sleep mode Idle is used to put the device into power reduction state while waiting for the Interrupt to occur. When the interrupt is serviced, it goes back to sleep. The following scope pictures are examples of sine wave signals generated by the ATtiny26 PWM. The scope snap-shots show the output on the OC1A pin, which is the digital pulse modulated signal, and the filtered/shaped PWM signal. A simple RC filter is used to shape the PWM signal to a sine wave an analog signal where the amplitude is given by the duty cycle of the PWM output. The RC filter used has an R = 10 kω and a C = 100 nf, resulting in a filter crossover frequency of 1 khz, which will let the low frequency sine wave pass while filtering out the high frequency PWM base. 6 AVR131 App Note

AVR131 App Note Figure 8. OC1A Output Filtered and Not Filtered Figure 9. OC1A Output Filtered and Not Filtered, Details 7

Atmel Corporation 2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Regional Headquarters 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 Tsimshatsui 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, USA Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 Microcontrollers 2325 Orchard Parkway San Jose, CA 95131, USA 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, USA 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, USA 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 Literature Requests www.atmel.com/literature Disclaimer: 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 Corporation 2003. All rights reserved. Atmel and combinations thereof, and AVR are the registered trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be the trademarks of others. Printed on recycled paper.