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



Similar documents
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

General Porting Considerations. Memory EEPROM XRAM

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

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

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

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

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

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

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

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

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

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

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

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

AT91SAM ARM-based Flash MCU. Application Note

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

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

AVR1306: Using the XMEGA Timer/Counter. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

8051 Flash Microcontroller. Application Note. A Digital Thermometer Using the Atmel AT89LP2052 Microcontroller

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

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

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

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

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

AVR ONE!... Quick-start Guide. EVK Windows 32104B AVR ONE! 02/10

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

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

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

USER GUIDE EDBG. Description

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

AT89C5131A Starter Kit... Software User Guide

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

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

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

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

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

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

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

256K (32K x 8) Battery-Voltage Parallel EEPROMs AT28BV256

USER GUIDE. ZigBit USB Stick User Guide. Introduction

Introducing a platform to facilitate reliable and highly productive embedded developments

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

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

Application Note. USB Microcontrollers. USB PC Drivers Based on Generic HID Class. 1. Introduction

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

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

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

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

AT88CK490 Evaluation Kit

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

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

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

Application Note. Atmel CryptoAuthentication Product Uses. Atmel ATSHA204. Abstract. Overview

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

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

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

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

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

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

AVR449: Sinusoidal driving of 3-phase permanent magnet motor using ATtiny261/461/ bit Microcontrollers. Application Note.

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

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

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

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

Designing Feature-Rich User Interfaces for Home and Industrial Controllers

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

Capacitive Touch Technology Opens the Door to a New Generation of Automotive User Interfaces

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

APPLICATION NOTE. Atmel AT02985: User s Guide for USB-CAN Demo on SAM4E-EK. Atmel AVR 32-bit Microcontroller. Features. Description.

64K (8K x 8) Parallel EEPROM with Page Write and Software Data Protection AT28C64B

AN3332 Application note

8-bit Microcontroller. Application Note. AVR286: LIN Firmware Base for LIN/UART Controller. LIN Features. 1. Atmel LIN/UART Controller

Dell Spotlight on Active Directory Server Health Wizard Configuration Guide

Transcription:

AVR1600: Using the XMEGA Quadrature Decoder Features Quadrature Decoders 16-bit angular resolution Rotation speed and acceleration 1 Introduction Quadrature encoders are used to determine the position and speed of a rotary device, such as servo-motors, volume control wheels, PC mice etc. The decoded quadrature signals are used as a sensory input to a system to determine the absolute or relative position of the rotary device, which again can be used e.g. in a control loop (for e.g. the servo-motor). The AVR XMEGA TM includes hardware support for reading position from Quadrature Encoders. A combination of peripheral modules is used to decode the Quadrature Encoder signals: IO pins are used as input to the Event System s Quadrature Decoder (QDEC), which connects to a Timer/Counter. The XMEGA hardware supports incremental encoders (Quadrature Encoders). The Quadrature Encoder also supports encoders with index signal for absolute positioning. This application note describes the basic functionality of the XMEGA QDECs with code example. 8-bit Microcontrollers Application Note Figure 1-1. Example system. (QDPH0) PINx+0 (QDPH90) PINx+1 (QDINDX) PINx+2 Sensors LED Rotation Rev.

2 Quadrature Encoders A quadrature encoder uses two signals to encode rotation and direction. The two quadrature encoder signal (QDPH0 and QDPH90) are characterized by having two square waves phase shifted 90 degrees relative to each other. This can be implemented using a quadrature encoder disk shown in 1Figure 2-1 or with a rate encoder disk (shown in 2Figure 2-2) with the sensors logical 90 degrees out of phase. Figure 2-1. Quadrature Encoder disk. Figure 2-2. 30 Degree Rate Encoder disk. Rotational movement can be measured by counting the edges of the two waveforms. The phase relationship between the two square waves determines the direction of rotation. 3Figure 2-3 shows typical quadrature signals from a rotary encoder. The signals named QDPH0 and QDPH90 are the two quadrature signals. The figure shows how the phase relationship determines the direction of rotation. When QDPH0 leads QDPH90, the rotation is defined as positive or forward. When QDPH90 leads QDPH0, the rotation is defined as negative or reverse. The concatenation of the two phase signals is called the quadrature state or the phase state. 2 AVR1600

AVR1600 The index signal shown in the figure as QDINDX, used for absolute positioning, can be high for a maximum of four states. If the index is high for four states as shown in 4Figure 2-3, any of the states can be chosen to be the index recognition state. Quadrature encoders are commonly used as position sensors in motor applications, but are also found in other rotary sensors, such as the ball tracker in computer mice. Figure 2-3. Quadrature signals from a rotary encoder. 1 cycle / 4 states Forward Direction QDPH0 QDPH90 QDINDX 00 10 11 01 Backward Direction QDPH0 QDPH90 QDINDX 01 11 10 00 2.1 Quadrature encoder output signals Quadrature encoders have two or three output lines: Two-output encoders can provide information about the relative position for a rotary device. These two outputs have four (quad) states from which it has its name. Unless the initial rotary displacement is known, a two-output encoder can only be used to calculate relative movement, speed and position. The absolute rotary displacement will not be known. Having a third signal, referred to as an index signal, generating a pulse once per revolution, can resolve this. 3 Quadrature decoding The event system has extensions that make it possible to decode a quadrature signal and use this as a source for a Timer/Counter. The rotary displacement using a two-output encoder is shown in 5Figure 3-2. Using a three-output encoder the absolute position will be known, as shown in 6Figure 3-1. When the QDINDX signal occurs the Timer/Counter value will be reset if not equal to BOTTOM, and an error bit will be set (ERRIF in INTFLAGS-interrupt flag register to the Timer/Counter). This enables the system to detect skip/error in the system or reset the counter for first pass. The speed and acceleration can be calculated by timing the rate of change in the Timer/Counter register (shown in 7Figure 3-3). 3

Figure 3-1. Timer/Counter value with index/reset signal. TOP Index error Index ok BOTTOM QDPH0 QDPH90 QDINDX Figure 3-2. Timer/Counter value without index/reset signal. Figure 3-3. Timer/Counter value with decreasing speed (backwards rotation) 4 AVR1600

AVR1600 3.1 The XMEGA quadrature decoder The XMEGA quadrature decoder supports automatic decoding of a quadrature signal, with optional reset by an index signal. To utilize the quadrature decoder, three modules are used: I/O port pins quadrature signal input The Event System quadrature decoding A Timer/Counter keeping track of the current position 3.1.1 Index signal and error states The XMEGA Timer/Counter modules are able to use the quadrature events to count up/down when the event action is set to quadrature encoding. As a result, the current position of the rotary device is tracked by the Timer/Counter, and can be directly read from the Timer/Counter CNT[H:L] register. The Timer/Counter works normally and interrupts/events can be used. E.g. an event can be sent to another Timer/Counter counting revolution. Interrupts can be given at relative/absolute positions. An extra Timer/Counter can be used to calculate rotation speed and acceleration. The index signal can be used to reset the Timer/Counter: When the index signal is high and the quadrature state match that selected by the QDIRM bits (shown in 8Table 3-1) the Timer/Counter is reset. The QDIRM[1:0] bits are located in the event channel control register - CHnCTRL. When using an encoder with index output, the Timer/Counter period (PER[H:L]) register should be set to match the number of pulses per revolution from the encoder wheel: When the period register corresponds to the number of quadrature pulses per revolution, the index should occur and the position counter should be equal to BOTTOM. If the position counter is different from BOTTOM when the index is recognized, the Timer/Counter ERRIF bit is set in the INTFLAGS Interrupt Flag Register. Similarly the ERRIF is set if the position counter passes BOTTOM without recognition of the index. The index signal can be implemented differently from different manufacturers. The index can be high one state and the corresponding state must be chosen in the QDIRM bit settings for the index recognition state (shown in 9Table 3-1). The index can be high for a maximum of 4 states and then any one of the index recognition states can be chosen. A detailed example of how to use the XMEGA quadrature decoder can be found in section 13.2. Table 3-1. QDIRM Bit Settings. QDIRM[1:0] Index Recognition State 0 0 {QDPH0, QDPH90} = 0b00 0 1 {QDPH0, QDPH90} = 0b01 1 0 {QDPH0, QDPH90} = 0b10 1 1 {QDPH0, QDPH90} = 0b11 5

3.2 Quadrature Decoding In this example, TCC0 will be used as a quadrature counter, using Event Channel 0 for quadrature decoding and Event Channel 1 for the index signal. PORTD will be used for input of the three quadrature signals: QDPH0 on PD0, QDPH90 on PD1 and QDIND on PD2. 1. Configure PD0 and PD1 as inputs. 2. Configure PD0 and PD1 input sense control register to level sensing (transparent for events). 3. Select PD0 as multiplexer input for event channel 0. 4. Optional for index: a. Configure PD2 as input. b. Configure PD2 input sense control register to sense both edges. c. Select PD2 as multiplexer input for event channel 1. d. Set the Quadrature Index Enable bit in event channel 0. e. Select the Index Recognition mode for channel 0. 5. Enable quadrature decoding and digital filtering in event channel 0. 6. Set Quadrature decoding as event action for TCC0. 7. Select event channel 0 as event source for TCC0. 8. Set the period register of TCC0 to (n * 4 1), where n is the line count of the quadrature encoder. 9. Enable TCC0 by setting CLKSEL to a CLKSEL_DIV1. The angle of a quadrature encoder attached to QDPH0, QDPH90 (and QINDX) can now be read directly from the Timer/Counter Count register. If the Count register is different from BOTTOM when the index is recognized, the Timer/Counter error flag is set. Similarly the error flag is set if the position counter passes BOTTOM without the recognition of the index. A code example using the Quadrature decoder is included in the source code for this application note. This implementation uses the index signal for absolute position. 4 Driver/Example Implementation The included driver has functions that can be used to configure the Quadrature Decoder. The driver is written in ANSI C, and should compile on all compilers with XMEGA support. Note that this driver is not written with high performance in mind. It is designed as a library to get started with the XMEGA Quadrature Decoder and an easy-to-use framework for rapid prototyping. For time and code space critical application development, consider replacing function calls with macros or direct access to registers. 6 AVR1600

AVR1600 4.1 Files The source code package consists of the following files: qdec_driver.c Quadrature decoder driver source file qdec_driver.h Quadrature decoder driver header file qdec_example.c Example of using the quadrature decoder 4.2 Doxygen Documentation All source code is prepared for automatic documentation generation using Doxygen. Doxygen is a tool for generating documentation from source code by analyzing the source code and using special keywords. For more details about Doxygen please visit 0Uhttp://www.doxygen.orgH. Precompiled Doxygen documentation is also supplied with the source code accompanying this application note, available from the readme.html file in the source code folder. 7

Disclaimer Headquarters International Atmel Corporation 2325 Orchard Parkway San Jose, CA 95131 USA Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Atmel Asia Room 1219 Chinachem Golden Plaza 77 Mody Road Tsimshatsui East Kowloon Hong Kong Tel: (852) 2721-9778 Fax: (852) 2722-1369 Atmel Europe Le Krebs 8, Rue Jean-Pierre Timbaud BP 309 78054 Saint-Quentin-en- Yvelines Cedex France Tel: (33) 1-30-60-70-00 Fax: (33) 1-30-60-71-11 Atmel 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 Product Contact Web Site www.atmel.com Technical Support avr@atmel.com Sales Contact www.atmel.com/contacts Literature Request www.atmel.com/literature 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 ATMEL S TERMS AND CONDITIONS OF SALE LOCATED ON ATMEL S WEB SITE, 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 OF 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 product 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 s products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. 2008 Atmel Corporation. All rights reserved. Atmel, logo and combinations thereof, AVR and others, are the registered trademarks or trademarks, XMEGA TM and others are trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others.