| AVR1600 Using the XMEGA Quadrature Decoder

AVR1600 Using the XMEGA Quadrature Decoder Documentation

# Introduction

This documents the firmware for the application note. The firmware includes the three following main components:

- A quadrature decoder driver that can be used as a starting point for decoding signals from a quadrature encoder.
- An application example that illustrates how the driver can be utilized.
- A quadrature signal generator that can be used to verify the functionality of the application and the driver without a physical quadrature encoder connected.

The application example sets up the device for decoding of quadrature signals received on pins PD0 and PD1, no index pulse. The calculated frequency of the signal is written to the PORTC I/O pins, which can be connected to LEDs etc for visualization.

Note that the ticks in a quadrature signal is represented by a repeating pattern of alternating edges on the PD0 and PD1 lines, such that every fourth tick corresponds to a rising edge on PD0. Since the signal on PD0 initiates the timer capture used for calculating the frequency, the actual tick frequency of a quadrature signal will be four times the frequency calulated by this example application.

The included signal generator can be used to verify the firmware functionality by uncommenting the GENERATE_TEST_SIGNAL definition in qdec_example.c. The signal generator will then output a quadrature signal on PE0 and PE1 (index pulse on PE2) with frequency and direction given by the variables freq and dir also defined in qdec_example.c. The defines CW_DIR and CCW_DIR in qdec_driver.h should be used for setting the direction. By connecting PD0 to PE0 and PD1 to PE1 and starting the application, the calculated frequency should be close to the configured signal generator frequency.

# Compilation Info

This firmware was compiled with IAR Embedded Workbench for AVR 7.10.1 and Atmel Studio 7.0.

To open the application in Studio, open the Studio solution file AVR1600_XMEGA_Quad_Encoder.sln in the AVR1600_XMEGA_Quad_Encoder folder.

To open the application in IAR EWAVR, open the qdec_example.eww workspace file, or:

- Create a new project in IAR EWAVR.
- Add the .c files (and .S90 files where applicable) for the given example to your project.
- Select device ATxmega128A1 (Project Options->General Options->Target).
- Enable bit definitions in I/O include files (Project Options->General Options->System).
- Select optimization low for debug target and high for release (Project Options->C/C++ Compiler->Optimizations).
- Select output format Debug information for C-SPY for the Debug configuration and intel extended for the Release configuration (Project Options->Linker->Output).
- Select Normal DLIB as library (Project Options->General Options->Library Configuration).
- Before debugging, select the correct debugger driver (Project Options->Debugger->Setup).

# Device Info

All XMEGA devices with the targeted module can be used. The example is written for ATxmega128A1.

# Contact Info

For more info about Microchip AVR visit http://www.microchip.com/design-centers/8-bit/microchip-avr-mcus/avr-mcus
Support: http://www.microchip.com/support/

Revision
  7629

Date
  2017-10-05 16:26:05 +0200 (to, 05 okt 2017)

# License

Copyright (c) 2009 Atmel Corporation. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. The name of Atmel may not be used to endorse or promote products derived from this software without specific prior written permission.
4. This software may only be redistributed and used in connection with an Atmel AVR product.

THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

@DOC_TITLE@