GithubHelp home page GithubHelp logo

microchip-pic-avr-examples / avr64dd32-quadrature-decoder-mplab-mcc Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 4.09 MB

Guide for using Core Independent Quadrature Decoder with AVR64DD32 Microcontroller using MCC Melody

License: Other

Makefile 2.09% C 95.92% Assembly 1.99%
ccl getting-started quadrature-encoder tcb uart evsys

avr64dd32-quadrature-decoder-mplab-mcc's Introduction

MCHP

Core Independent Quadrature Decoder using the AVR64DD32 Microcontroller with MCC Melody

Quadrature signals are the standard output waveforms of incremental encoders that come with motors. They provide information about motor direction and shaft position. There are two types of encoders - linear and rotary - and each can have two types of measurement: Absolute and incremental. There are also different technologies used for encoders: Magnetic, optical, inductive, capacitive, and laser.

The main categories of encoders are absolute and incremental. A rotary absolute encoder outputs a unique code for each position of the motor's shaft. If the power of this encoder is lost and the shaft is rotated, the encoder can return the correct position of the shaft. The rotary incremental encoder generates pulses while the shaft is rotated. If any pulse is missed, then the shaft position cannot be determined correctly anymore. This application will use a rotary incremental encoder to show how to decode quadrature signals.

The following image highlights the Clockwise (CW) and Counterclockwise (CCW) conditions on the quadrature signals A and B. When signal A leads signal B (on rising or falling edge), it will be a clockwise detection, otherwise, when signal B leads signal A (on rising or falling edge), it will be a counterclockwise detection.


The quadrature decoder uses the Configurable Custom Logic (CCL) on the AVR64DD32 to detect CW and CCW pulses. The following picture shows the output signals of the CCL implementation, CW and CCW, based on the quadrature signals A and B.


Using the Event System (EVSYS) peripheral, the CW and CCW signals are linked to two TCB instances: One counts the CW pulses, the other one counts the CCW pulses.

Related Documentation

More details and code examples on the AVR64DD32 can be found at the following links:

Software Used

Hardware Used

  • AVR64DD32 Curiosity Nano Development Board is used as a test platform.




  • Oscilloscope/Logic Analyzer

  • Rotary encoder

Note: The setup can be made using rotary encoder or motor with encoder. In this example we use the rotary encoder.

  • Motor with encoder


Operation

To program the Curiosity Nano board with this MPLAB® X project, follow the steps provided in the How to Program the Curiosity Nano Board chapter.

1. Setup

The following peripheral and clock configurations are set up using MCC Melody for the AVR64DD32:

  • System Clock - 4 MHz (default)
  • TCA0:
    • System Clock/64
    • Timer Mode 16 bit
    • Count Direction - UP
    • Overflow Interrupt Enable - every 1 second
    • Waveform Generation Mode - Normal Mode
  • TCB0:
    • Clock Select - Event
    • Timer Mode: INT
    • Enable Asynchronous
    • Overflow Interrupt Enable
  • TCB1:
    • Clock Select - Event
    • Timer Mode: INT
    • Enable Asynchronous
    • Overflow Interrupt Enable
  • UART0:
    • Baudrate: 115200
    • Parity: None
    • Enable USART Transmit and Receive
    • Printf Support Enable
  • EVSYS:
    • Configuration described in the below schematic
  • CCL:
    • Configuration described in the below schematic

The following pin configurations must be made for this project:

Pin Configuration Function
PA4 Input Phase A
PA5 Input Phase B
PC0 Output USART TX
PC1 Input USART RX
PA6 Output CW detection
PD3 Output CCW detection

The internal connections and signals are presented in the following pictures:



2. Demo

In this demo, the function QEI_GetVelocity is called every second and the returned value is printed on the serial terminal. The hardware setup is presented in the image below:



Every second, the device prints a message with the counter value through the USART interface:

Note: Follow the steps in the How to use MPLAB® Data Visualizer section to set up the Data Visualizer so that it can correctly show the text messages through USART0.

A snapshot of the different signals from the logic analyzer can be seen below. The CW and CCW pulses correspond to the counter values 8 and -8.

3. Summary

The quadrature decoder can detect and count clockwise and counterclockwise pulses on rising and falling edges of the quadrature signals. Read more about the implementation at https://www.microchip.com/en-us/about/blog/design-corner/quadrature-decoder.

How to use MPLAB® Data Visualizer

This section illustrates how to use the MPLAB® X Data Visualizer to send commands and receive information, but prior to programming the AVR64DD32 Curiosity Nano Board. This can be applied to any other projects.

Operation

  1. Open the software terminal in MPLAB® X IDE. Left click on the Data Visualizer button.

  2. Select the Input Source corresponding to the AVR64DD32 in the right side.

  3. Identify the coresponding COMx that is represented by the AVR64DD32 Curiosity Nano Board and select it in the Connections tab in the left side.

  4. Set the specific Baud Rate, in this case 115200.

  5. Press Start streaming COMx button. The text messages will appear in the Terminal tab.

How to Program the Curiosity Nano board

This chapter shows how to use the MPLAB® X IDE to program an AVR® device with an Example_Project.X. This can be applied for any other projects.

  • Connect the board to the PC.

  • Open the Example_Project.X project in MPLAB X IDE.

  • Set the Example_Project.X project as main project.

    • Right click on the project in the Projects tab and click Set as Main Project.
  • Clean and build the Example_Project.X project.

    • Right click on the Example_Project.X project and select Clean and Build.
  • Select the AVRxxxxx Curiosity Nano in the Connected Hardware Tool section of the project settings:

    • Right click on the project and click Properties
    • Click on the arrow under the Connected Hardware Tool
    • Select the AVRxxxxx Curiosity Nano (click on the SN), click Apply and then click OK:
  • Program the project to the board.

    • Right click on the project and click Make and Program Device.

avr64dd32-quadrature-decoder-mplab-mcc's People

Contributors

aku-work avatar stanciu-cosmin avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.