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



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

AVR151: Setup and Use of the SPI. Introduction. Features. Atmel AVR 8-bit Microcontroller APPLICATION NOTE

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

AVR126: ADC of megaavr in Single Ended Mode. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

AVR106: C Functions for Reading and Writing to Flash Memory. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

APPLICATION NOTE. AT07175: SAM-BA Bootloader for SAM D21. Atmel SAM D21. Introduction. Features

SMARTCARD XPRO. Preface. SMART ARM-based Microcontrollers USER GUIDE

AT88CK490 Evaluation Kit

APPLICATION NOTE. Secure Personalization with Transport Key Authentication. ATSHA204A, ATECC108A, and ATECC508A. Introduction.

AT15007: Differences between ATmega328/P and ATmega328PB. Introduction. Features. Atmel AVR 8-bit Microcontrollers APPLICATION NOTE

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

AVR311: Using the TWI Module as I2C Slave. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

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

AT11805: Capacitive Touch Long Slider Design with PTC. Introduction. Features. Touch Solutions APPLICATION NOTE

AVR315: Using the TWI Module as I2C Master. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

APPLICATION NOTE. Authentication Counting. Atmel CryptoAuthentication. Features. Introduction

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

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

USER GUIDE EDBG. Description

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

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

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

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

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

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

AN3252 Application note

APPLICATION NOTE. AT16268: JD Smart Cloud Based Smart Plug Getting. Started Guide ATSAMW25. Introduction. Features

APPLICATION NOTE. RF System Architecture Considerations ATAN0014. Description

General Porting Considerations. Memory EEPROM XRAM

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

AN1991. Audio decibel level detector with meter driver

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

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

APPLICATION NOTE. AT12405: Low Power Sensor Design with PTC. Atmel MCU Integrated Touch. Introduction

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

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

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

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

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

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

SAMA5D2. Scope. Reference Documents. Atmel SMART ARM-based MPU ERRATA

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

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

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

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

AN3332 Application note

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

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

How To Use An Atmel Atmel Avr32848 Demo For Android (32Bit) With A Microcontroller (32B) And An Android Accessory (32D) On A Microcontroller (32Gb) On An Android Phone Or

CryptoAuth Xplained Pro

Atmel Norway XMEGA Introduction

Atmel AVR4903: ASF - USB Device HID Mouse Application. Atmel Microcontrollers. Application Note. Features. 1 Introduction

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

AT09333: USB Host Interface (UHI) for Communication Class Device (CDC) Introduction. Atmel Microcontrollers APPLICATION NOTE

QT1 Xplained Pro. Preface. Atmel QTouch USER GUIDE

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

Flexible Active Shutter Control Interface using the MC1323x

APPLICATION NOTE. Atmel AT04389: Connecting SAMD20E to the AT86RF233 Transceiver. Atmel SAMD20. Description. Features

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

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

Simplifying System Design Using the CS4350 PLL DAC

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

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

APPLICATION NOTE. Atmel AT01095: Joystick Game Controller Reference Design. 8-/16-bit Atmel Microcontrollers. Features.

APPLICATION NOTE. AVR042: AVR Hardware Design Considerations. AVR 8-bit Microcontrollers. Features. Description

APPLICATION NOTE. AT05558: Wireless Manufacturing Test Kit. Atmel ATmega256RFR2. Description. Features

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

Real-Time Clock. * Real-Time Computing, edited by Duncan A. Mellichamp, Van Nostrand Reinhold

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

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

AN3998 Application note

AN LPC1700 RTC hardware auto calibration. Document information. RTC, Hardware Auto Calibration, LPC1700, Graphic LCD

AN11008 Flash based non-volatile storage

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

AN3265 Application note

APPLICATION NOTE. AT03155: Real-Time-Clock Calibration and Compensation. SAM3 / SAM4 Series. Scope

Software Real Time Clock Implementation on MC9S08LG32

AN2604 Application note

AN2680 Application note

AN LPC1700 timer triggered memory to GPIO data transfer. Document information. LPC1700, GPIO, DMA, Timer0, Sleep Mode

APPLICATION NOTE. Atmel LF-RFID Kits Overview. Atmel LF-RFID Kit. LF-RFID Kit Introduction

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

USER GUIDE. ZigBit USB Stick User Guide. Introduction

DACC (Digital-to-Analog Converter Controller) The outline of this documentation is as follows: Module Overview. Special Considerations

AN4646 Application note

Timer A (0 and 1) and PWM EE3376

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

Single Phase Two-Channel Interleaved PFC Operating in CrM

Application Note. Atmel ATSHA204 Authentication Modes. Prerequisites. Overview. Introduction

PAC52XX Clock Control Firmware Design

AVR130: Setup and Use of AVR Timers. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

Hello and welcome to this training module for the STM32L4 Liquid Crystal Display (LCD) controller. This controller can be used in a wide range of

USER GUIDE. ATWINC1500B Hardware Design Guidelines - IEEE b/g/n IoT Module. Atmel SmartConnect. Introduction

AN2658 Application note

ETEC Digital Controls PIC Lab 10 Pulse Width Modulation

How To Design An Ism Band Antenna For 915Mhz/2.4Ghz Ism Bands On A Pbbb (Bcm) Board

Optimizing VCO PLL Evaluations & PLL Synthesizer Designs

Atmel AVR4027: Tips and Tricks to Optimize Your C Code for 8-bit AVR Microcontrollers. 8-bit Atmel Microcontrollers. Application Note.

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

AN974 APPLICATION NOTE

Transcription:

AVR 8-bit Microcontrollers AVR131: Using the AVR s High-speed PWM APPLICATION NOTE Introduction This application note is an introduction to the use of the high-speed Pulse Width Modulator (PWM) available in some Atmel tinyavr microcontrollers such as Atmel ATtiny26, Atmel ATtiny15, etc. The advantage of high-speed PWM is the increased bandwidth of the analog output signal. The high frequency further allows for smaller and less expensive filter components to be used in shaping the signal. The fast PWM is used to generate a pulse train with varying duty-cycle The PWM output is generated 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 Assembly and C code examples are provided to show the usage of high-speed PWM in the ATtiny26 Features Analog waveform generation using high-speed PWM Example application to generate sine wave High-speed pre-scalable PWM clock

Table of Contents Introduction...1 Features... 1 1. Glossary...3 2. Description...4 2.1. High-speed PWM... 4 2.2. Analog Waveform Generation from PWM Signal... 6 2.3. Sine Wave Generation... 7 3. Application Example... 9 3.1. Firmware - Assembly Code... 9 3.1.1. Initialization... 9 3.1.2. Interrupt Service Routine... 10 3.1.3. Sleep Mode...11 3.2. Firmware - C Code... 11 3.2.1. Sleep Mode - C Code...11 3.3. Application Considerations... 11 4. Results and Conclusion...13 5. References... 14 6. Revision History...15 2

1. Glossary DAC ISR khz MHz PLL PWM RC-filter Digital to Analog Converter Interrupt Service Routine KiloHertz MegaHertz Phase-Locked Loop Pulse Width Modulation Resistor-Capacitor filter 3

2. Description This chapter provides an insight to the theory on high-speed PWM and its usage in generating analog waveform. The high-speed PWM output, 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 to generate an analog signal. Different analog levels can be generated by varying the duty cycle (and thereby the pulse width) of the digital signal. If a high analog level is needed, the duty cycle is increased and vice versa. The analog waveform considered in this application note is Sine Wave. 2.1. High-speed PWM In the AVR, the timer/counters can be used to generate PWM signals. PWM base frequency is determined by timer clock frequency and top counter value. Faster clock frequency will increase the PWM base frequency and vice versa. Lower top value will reduce the time for overflow, which thereby increases the PWM frequency. The PWM base frequency can be calculated as follows: PWM Frequency = Timer clock speed / Timer resolution ATtiny26 devices features the high-speed PWM, which allows the user to run the timer at a higher speed than the CPU clock. Timer/Counter1 supports two accurate, high speed, 8-bit Pulse Width Modulators using clock speeds up to 64MHz. It has two clocking modes; synchronous mode and asynchronous mode. The synchronous mode uses the system clock (CK) as the clock timebase and asynchronous mode uses the fast peripheral clock (PCK) as the clock time base. Asynchronous mode can be enabled by setting the PCKE bit from the PLLCSR Register (PLLCSR > PCKE = 1). Timer/Counter1 features a prescaler setting, which provides clock selections between PCK to PCK/16384 in asynchronous mode. Setting the PSR1 bit in TCCR1B Register resets the prescaler. The block diagram of Timer/Counter1 Prescaler is shown in the following diagram: Figure 2-1. Timer/Counter1 Prescaler Note: Refer the device datasheet for more details on configuration and usage of internal RC Oscillator and PLL. The PLL of Timer/Counter1 needs a 1MHz reference clock. We can use the internal RC oscillator to generate 1MHz by configuring the OSCCAL register. This clock output will be used as reference to PLL which can generate a recommended maximum frequency of 64MHz. Hence, the maximum PWM frequency that could be generated with best resolution is given as follows: PWM Frequency = 64MHz / 256 = 250kHz 4

Increasing the base frequency beyond this will be at the expense of reduced resolution, since fewer steps are available from 0% to 100% duty cycle. Altering the value of the Output Compare Registers (OCR) changes the duty cycle. Increasing the OCR value increases the duty cycle. The PWM output is high until the OCR value is reached, and low until the timer reaches the top value and wraps back to 0. This is shown in following figure. Figure 2-2. Counter Values and PWM Output Counter value OCR value PWM output With 64MHz timer clock and a top value 3, PWM base frequency of 16MHz can be achieved. However, the OCR value is now limited to 0, 1 (25% duty cycle), 2 (50% duty cycle), or 3 (100% duty cycle). This shows that lowering the top value can increase the PWM base frequency, but reduces the resolution. To achieve the maximum output frequency from the timer, it must be run in non-pwm mode. Both the OCR 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 32MHz signal, as shown in following figures. Figure 2-3. High Frequency Digital Output 64 MHz timer clock cycle OCR Counter values TOP 16 MHz 50% PWM (A) TOP OCR TOP OCR TOP OCR TOP OCR 32 MHz non-pwm mode (B) 5

2.2. Analog Waveform Generation from PWM Signal Analog waveforms can be generated by averaging the PWM signals over one period using simple lowpass filters. In this application note, implementation of sine wave generation from high-speed PWM output is explained. If high-speed PWM is used to generate analog signals, the step-size between the analog levels depends on the resolution of the PWM signal. Duty cycle of the PWM signal determines the amplitude of the analog waveform. 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. A real-time example of PWM waveform with varying duty cycle is shown in the following figure. Figure 2-4. PWM Output with Varying Duty Cycle 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. The higher the base frequency is, the easier it is 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. Figure 2-5. 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. 6

2.3. Sine Wave Generation As seen in the previous section, amplitude of the analog waveform is directly proportional to duty cycle of PWM signal. So, if a sine wave is to be generated, the duty cycle of the PWM signal has to be varied accordingly. In ATtiny26, the OCR value determines the duty cycle of the PWM signal. In order to control the variation in amplitude, the duty cycle has to be varied, thereby generating a sine wave. The application uses a sine table that has the sample values (duty cycle of PWM), which will be loaded at every Timer overflow. To generate a sine table, the following parameters must be considered: Table 2-1. Configuration Parameters Parameter CPUFreq TimerFreq Value used in the application 8MHZ 16MHZ TimerTop 255 PWMFreq SineFreq 62.5kHz ~244Hz 1. CPUFreq: This is the frequency at which the system is operated. In the application demonstrated, the CPU runs at 8MHz using Internal RC Oscillator. 2. TimerFreq: This is the frequency at which the Timer/Counter1 is operated. In the application demonstrated, 1MHz output of Internal RC Oscillator acts as Timer1 PLL reference to generate a 64MHz clock. This clock is then prescaled down to 16MHz to demonstrate the prescaling capability of Timer/Counter1. 3. TimerTop: This is the Timer/Counter1 top value that is one of the deciding parameters of PWM frequency. In the application demonstrated 255 is loaded to 8-bit register OCR1C. 4. PWMFreq: This is the frequency of the PWM output. It can be calculated by PWMFreq = TimerFreq / TimerTop. 5. SineFreq: This is the frequency of Sine Wave generated after passing the PWM signal to a Low- Pass filter. This can be calculated by the formula, PWMFreq / TimerTop. 6. SampleValue: This is the instantaneous sample of Sine Wave that will be loaded to OCR1A on every Timer overflow. The sample value decides the duty cycle of PWM which in turn controls the amplitude of the analog waveform (sine wave) generated. The formula to generate SampleValue is shown as follows: Note: 1. Here, n is the number of samples in one cycle of sine wave. It ranges from 0 to TimerTop. 2. It has to be noted that the CPU should be running fast enough to load the duty cycle values to the OCR1A register after every Timer1 overflow. Configurations to generate different frequencies of sine wave are listed in the following table: 7

Table 2-2. Various Combinations to Generate Desired Frequency of Sine Wave CPUFreq [MH] TimerFreq [MH] PWMFreq [kh] SineFreq [Hz] TimerTop Number of CPU cycles before overflow 8 16 62.5 250 249 125 8 16 62.5 500 124 62.5 8 16 62.5 800 77 39 16 16 62.5 800 77 78 16 16 62.5 1000 62 63 16 16 62.5 1500 41 42 Note: The values shown in the table has some restrictions on CPU speed and PWM speed. For more details, refer Interrupt Service Routine on page 10. 8

3. Application Example This application note comes with an example code in both C & Assembly language to generate sine wave from High-Speed PWM of Atmel ATtiny26. This section discusses more about the firmware, limitations, and design parameters that user shall consider before using the code in their application. 3.1. Firmware - Assembly Code The implementation is such that CPU runs at 8MHz and Timer1 is clocked by 16MHz clock. Necessary fuses are to be programmed accordingly. The code consists of three parts: Initialization, Timer1 overflow interrupt service routine, and a sleep loop. Figure 3-1. Flowchart of main() - Sine Wave Generator Code Main( ) init( ) Timer1 OVF interrupt Sleep 3.1.1. Initialization To generate an output from the PWM the Output Compare Pin of Timer1 (OC1A) is set up as output. 1. The clock source for the timer is prepared by starting the PLL and locked to the system clock (required). 2. The PLL takes approximately 100ms to lock onto the system clock and it is therefore necessary to wait for the PLL lock flag before proceeding. 3. When the PLL is locked it is selected as clock source for the timer. 4. The PWM mode is selected so that the OC1A pin toggles on compare match. 5. 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. 6. The prescaler is set, which also starts the timer. 7. The Overflow interrupt is enabled. 9

Figure 3-2. Flowchart of init() - Initialize Timer1 and I/O Pin for Fast PWM Mode Init() Set PB1 as output Enable and lock PLL Wait for PLL to lock (Approx.100ms) Set PWM mode: toggle OC1A on compare Set PWM Top Value: OCR1C=0xFF Set PLL as PWM clock sources Enable Timer/ Set PWM clock prescaler to PCK/4 (16MHz PWM clock) Enable Timer1 OVF interrupt Return 3.1.2. Interrupt Service Routine When the Timer1 value reaches the OCR1C value (0xFF), the Timer Overflow interrupt service routine (ISR) is executed. This happens at a constant interval, since OCR1C is constant. This interval is the base frequency of the fast PWM output signal. The sine table generated as explained in Sine Wave Generation on page 7 is stored in the Flash memory as a Look-Up Table. When the ISR is executed, the value from sine table is loaded to OCR1A register. On each look-up the index to the look-up table is incremented so that consecutive values can be loaded. In this way the pulse width is modulated to the sine wave. Note: The OCR1A register is buffered and that the latching of the buffer into the actual OCR1A register takes place on the timer overflow. The interrupt routine in assembly language takes 13 clock cycles to execute. The call to and return from the interrupt comes in addition in total 21 system clock cycles. Since Timer1 is an 8-bit timer with top value as 255, the interrupt occurs every TimerTop / (TimerFreq / CPUFreq) > 256 / 2 = 128 cycles. If the Timer1 clock is configured to 64MHz and CPU is operated at 8MHz, timer overflow interrupt occurs every 32 cycles of system clock (which is within the limits of the application). Though it is possible to clock the Timer1 with the maximum frequency of 64MHz, the PLL output is prescaled by 4 to 16MHz, to illustrate the use of the prescaler. 10

Figure 3-3. Flowchart of OC1A_isr() - Timer1 ISR to Load Sine Table in OCR1A Timer1 OVF ISR Look-up new pulse width in sine table Increment sine table pointer Copy sine value (pulse width) to OCR1A Return from interrupt 3.1.3. Sleep Mode 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 returns back to sleep. 3.2. Firmware - C Code Implementation of Initialization and Interrupt Service Routine in C language is the same as that of Assembly language. For more details, refer Firmware - Assembly Code on page 9. It is to be noted that ISR implemented in C language takes 46 CPU cycles with Optimization set to Os. 3.2.1. Sleep Mode - C Code The following code snippet is added to enable Sleep mode for the device. sleep_enable(); while(1) { //Enter Sleep mode sleep_mode(); } The functions sleep_enable() & sleep_mode() are predefined directives, defined in sleep.h. 3.3. Application Considerations The following considerations must be taken care of while implementing the application 1. The RC filter used in this application is the simplest component to generate analog signal from PWM output. For analog signal output with lesser ripples, noise components, etc., better signal conditioning must be performed. 2. The output of the RC Filter will be an analog signal with reduced amplitude. Based on the need, a suitable amplifier circuit can be added to solve the purpose. 11

3. The PWM frequency can be increased further by reducing the resolution of the sine-wave. However, reduced resolution results in increased step size of the waveform, which would result in ripples and non-smooth waveform. 4. The design parameters should be configured such that TimerTop / (TimerFreq / CPUFreq) shall be greater than 21 cycles for application in assembly language and greater that 46 cycles for application in C language. Breaching this may result in sine wave generated with undesired frequency. For different configurations, refer Table 2-2 Various Combinations to Generate Desired Frequency of Sine Wave on page 8. 5. Frequency of the output sine wave depends on the CPU frequency and Timer1 Clock frequency. The clock used from Timer1 is a PLL with internal RC oscillator as reference. Hence, it is necessary to calibrate the RC oscillator to generate the desired frequency of sine wave. 12

4. Results and Conclusion The following screen-shots are examples of sine wave signals generated by Atmel ATtiny26 PWM for the configuration mentioned in Table 2-1 Configuration Parameters on page 7. Figure 4-1. PWM Output and Sine Wave Figure 4-2. PWM Output and Sine Wave Zoomed View Note: 1. Waveform in blue color is unfiltered PWM signal. 2. Waveform in Yellow color is filtered Sine signal. The screen-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 controlled by the duty cycle of the PWM output. The RC filter used has R = 10kΩ and C = 100nF, resulting in a filter crossover frequency of 1kHz, which will let the low frequency sine wave pass while filtering out the high frequency PWM base. 13

5. References 1. AVR130: Using the timers on tinyavr and megaavr devices 2. AVR135: Using Timer Capture to Measure PWM Duty Cycle on tinyavr and megaavr devices 3. AVR205: Frequency measurement made easy with Atmel tinyavr and Atmel megaavr 4. AVR504: Migrating from ATtiny26 to ATtiny261/461/861 14

6. Revision History Doc Rev. Date Comments 2542B 03/2016 Updated for Atmel Studio 7 and added C example code 2542A 09/2003 Initial document release 15

Atmel Corporation 1600 Technology Drive, San Jose, CA 95110 USA T: (+1)(408) 441.0311 F: (+1)(408) 436.4200 www.atmel.com 2016 Atmel Corporation. / Rev.: Atmel, Atmel logo and combinations thereof, Enabling Unlimited Possibilities, AVR, tinyavr, and others are registered trademarks or trademarks of Atmel Corporation in U.S. and other countries. Other terms and product names may be trademarks of others. DISCLAIMER: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN THE ATMEL TERMS AND CONDITIONS OF SALES LOCATED ON THE ATMEL WEBSITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS AND PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and products descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. SAFETY-CRITICAL, MILITARY, AND AUTOMOTIVE APPLICATIONS DISCLAIMER: Atmel products are not designed for and will not be used in connection with any applications where the failure of such products would reasonably be expected to result in significant personal injury or death ( Safety-Critical Applications ) without an Atmel officer's specific written consent. Safety-Critical Applications include, without limitation, life support devices and systems, equipment or systems for the operation of nuclear facilities and weapons systems. Atmel products are not designed nor intended for use in military or aerospace applications or environments unless specifically designated by Atmel as military-grade. Atmel products are not designed nor intended for use in automotive applications unless specifically designated by Atmel as automotive-grade.