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



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

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

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

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

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. AVR314: DTMF Generator

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

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

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

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.

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

AT89C5131A Starter Kit... Software User Guide

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

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

General Porting Considerations. Memory EEPROM XRAM

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

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.

AVR134: Real Time Clock (RTC) using the Asynchronous Timer. 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

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

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

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

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

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

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

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

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

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

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

USB Test Environment ATUSBTEST- SS7400. Summary

2-wire Serial EEPROM AT24C1024. Advance Information

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

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

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

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

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)

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

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

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

Two-wire Serial EEPROM AT24C1024 (1)

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

AVR32701: AVR32AP7 USB Performance. 32-bit Microcontrollers. Application Note. Features. 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

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

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

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

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

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

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

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

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

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

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

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

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

2-wire Serial EEPROM AT24C512

STK 500, AVRISP, AVRISP

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

AVR287: USB Host HID and Mass Storage Demonstration. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Application Note. Microcontrollers. AVR480: Anti-Pinch System for Electrical Window

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

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

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

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

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

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

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

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

Atmel AVR4903: ASF - USB Device HID Mouse Application. Atmel 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.

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

JTAG ICE.... User Guide

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

Application Note. 8-bit Microcontrollers. AVR293: USB Composite Device

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

8-bit Microcontroller. Application Note. AVR230: DES Bootloader

Transcription:

AVR222: 8-point Moving Average Filter Features 31-word Subroutine Filters Data Arrays up to 256 Bytes Runable Demo Program Introduction The moving average filter is a simple Low Pass FIR (Finite Impulse Response) filter commonly used for smoothening an array of sampled data. This application implements an 8-point filter to simplify the average calculation. The application note gives an excellent demonstration of how the powerful addressing modes in the AVR architecture can be utilized. 8-bit Microcontroller Application Note Theory The moving average filter can be imagined as a window of a certain size (in this case eight) moving along the array, one element at a time. The middle element of the window (in this case element #4) is replaced with the average of all elements in the window. See Figure 1. However, it is important to remember the value of new elements and not make the replacement until the window has passed. This must be done since all averages shall be based on the original data in the array. Figure 1. The 8-point Averaging Window CURRENT WINDOW 12 30 28 25 22 13 17 26 25 23 14 20 16 16 18 14 NEW VALUE = (22+13+17+26+25+23+14+20) / 8 = 20 When the ends of the array is filtered and parts of the window is outside the array, the averaging must be done on less elements than when the entire window is inside the array. This implementation leaves the ends of the array unfiltered to save code. For an 8-point filter, this means that when n elements are filtered, elements 1, 2, 3, and n-3, n-2, n-1, n remain unchanged when filtering is complete. For many applications, this is no problem. Rev. 1

Implementation Usage Algorithm Description The application defines an 8-byte ring buffer (R0 - R7) which always holds the data in the current averaging window. The filter routine calculates the sum of the window and computes the average, which is stored back in the array. The AVR s three pointers are assigned the following functions: Z points to the array element to be replaced. Y points inside the ring buffer when the sum of the buffer contents is calculated in a program loop. X is the ring pointer which holds the position of new values to the buffer. To filter an array in SRAM, use the following procedure: 1. Load ZH with the high address of the first element in the array. 2. Load ZL with the low address of the first element in the array. 3. Load the register variable t_size with the number of elements in the table. 4. Call mav8. The following procedure describes how the sorter is implemented on the AVR: Initialization 1. Clear the X and Y pointers (point to R0). Fill Ring Buffer Initially: 1. Get the SRAM contents at Z and increment Z. 2. Store in register at Y and increment Y. 3. If Y not eight, goto Step 2. Find Average 1. Clear the 16-bit register variable AH:AL (Average Value). 2. Clear YL (point to R0). 3. Get the register contents at Y. 4. Add to AH:AL. 5. If Y not eight, goto Step 8. 6. Divide AH:AL by 8. Write Back Average and Get Next Value to Buffer 1. Get SRAM contents at Z+5 (Next value to buffer). 2. Store to register at X and increment X. 3. Clear the highest five bits of XL to make it point to the start of the buffer if the end is passed. 4. Store AL at Z and increment Z. 5. Decrement t_size. 6. If t_size is not zero (end of array is reached) goto Step 5. 2 AVR222

AVR222 Figure 2. mav8 Flow Chart MAV8 CLEAR X AND Y MAV_TMP @Z Z Z + 1 CALCULATE AVERAGE FILL RING BUFFER @Y MAV_TMP Y Y + 1 YL = 8? Y CLEAR AH:AL, YL MAV_TMP @Y Y Y + 1 AH:AL AH:AL +MAV_TMP YL = 8? N Y AH:AL AH:AL / 8 WRITE BACK AVERAGE AND GET NEXT VALUE TO RING BUFFER MAV_TMP @X MAV_TMP, X X + 1 @Z AL, Z Z + 1 T_SIZE = 0 @(Z+5) CLEAR X BITS 7,6,5,4,3 T_SIZE T_SIZE - 1 Y Return 3

Performance Table 1. mav8 Register Usage Register Input Internal Output R0-R7 Ring Buffer R8 mav_tmp Temporary Storage R9 AL Average Low Byte R10 AH Average High Byte R16 t_size Number of Elements t_size Loop Counter R26 XL R27 XH R28 YL R29 YH R30 Z Address of First Element ZL R31 Z Address of First Element ZH Table 2. mav8 Performance Figures (1) Parameter Code Size (Words) Execution Time (Cycles) Value 30 + return 59 + 75 x (SIZE - 7) + return Register Usage Low Registers High Registers Pointers Interrupts Usage Peripherals Usage None None :11 :1 :X, Y, Z Note: 1. SIZE = Number of bytes to filter Test/Example Program avr222.asm contains a test program which copies 60 bytes of random data from the Program memory to SRAM and calls mav8 to filter the data. The test program is well suited for running under the AVR Studio. 4 AVR222

AVR222 5

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