|
1 | | -<!-- Please do not change this logo with link --> |
| 1 | +[](https://www.microchip.com) |
2 | 2 |
|
3 | | -[](https://www.microchip.com) |
| 3 | + # Core Independent Quadrature Decoder using the AVR64DD32 Microcontroller with MCC Melody |
4 | 4 |
|
5 | | -# Update the title for avr64dd32-quadrature-decoder-mplab-mcc here |
| 5 | +<br> |
6 | 6 |
|
7 | | -<!-- This is where the introduction to the example goes, including mentioning the peripherals used --> |
| 7 | +Quadrature signals are the standard waveforms used as output for 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. |
8 | 8 |
|
9 | | -## Related Documentation |
| 9 | +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. |
| 10 | +This application will use a rotary incremental encoder to show how to decode quadrature signals. |
10 | 11 |
|
11 | | -<!-- Any information about an application note or tech brief can be linked here. Use unbreakable links! |
12 | | - In addition a link to the device family landing page and relevant peripheral pages as well: |
13 | | - - [AN3381 - Brushless DC Fan Speed Control Using Temperature Input and Tachometer Feedback](https://microchip.com/00003381/) |
14 | | - - [PIC18F-Q10 Family Product Page](https://www.microchip.com/design-centers/8-bit/pic-mcus/device-selection/pic18f-q10-product-family) --> |
| 12 | +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. |
15 | 13 |
|
16 | | -## Software Used |
| 14 | +<br><img src="images/cw_ccw.png"> |
17 | 15 |
|
18 | | -<!-- All software used in this example must be listed here. Use unbreakable links! |
19 | | - - MPLAB® X IDE 5.30 or newer [(microchip.com/mplab/mplab-x-ide)](http://www.microchip.com/mplab/mplab-x-ide) |
20 | | - - MPLAB® XC8 2.10 or a newer compiler [(microchip.com/mplab/compilers)](http://www.microchip.com/mplab/compilers) |
21 | | - - MPLAB® Code Configurator (MCC) 3.95.0 or newer [(microchip.com/mplab/mplab-code-configurator)](https://www.microchip.com/mplab/mplab-code-configurator) |
22 | | - - MPLAB® Code Configurator (MCC) Device Libraries PIC10 / PIC12 / PIC16 / PIC18 MCUs [(microchip.com/mplab/mplab-code-configurator)](https://www.microchip.com/mplab/mplab-code-configurator) |
23 | | - - Microchip PIC18F-Q Series Device Support (1.4.109) or newer [(packs.download.microchip.com/)](https://packs.download.microchip.com/) --> |
| 16 | +The quadrature decoder uses the Configurable Custom Logic (CCL) 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. |
24 | 17 |
|
25 | | -- MPLAB® X IDE 6.0.0 or newer [(MPLAB® X IDE 6.0)](https://www.microchip.com/en-us/development-tools-tools-and-software/mplab-x-ide?utm_source=GitHub&utm_medium=TextLink&utm_campaign=MCU8_MMTCha_MPAE_Examples&utm_content=avr64dd32-quadrature-decoder-mplab-mcc-github) |
26 | | -- MPLAB® XC8 2.36.0 or newer compiler [(MPLAB® XC8 2.36)](https://www.microchip.com/en-us/development-tools-tools-and-software/mplab-xc-compilers?utm_source=GitHub&utm_medium=TextLink&utm_campaign=MCU8_MMTCha_MPAE_Examples&utm_content=avr64dd32-quadrature-decoder-mplab-mcc-github) |
| 18 | +<br><img src="images/wavedrom.png"> |
27 | 19 |
|
28 | | -## Hardware Used |
| 20 | +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. |
29 | 21 |
|
30 | | -<!-- All hardware used in this example must be listed here. Use unbreakable links! |
31 | | - - PIC18F47Q10 Curiosity Nano [(DM182029)](https://www.microchip.com/Developmenttools/ProductDetails/DM182029) |
32 | | - - Curiosity Nano Base for Click boards™ [(AC164162)](https://www.microchip.com/Developmenttools/ProductDetails/AC164162) |
33 | | - - POT Click board™ [(MIKROE-3402)](https://www.mikroe.com/pot-click) --> |
| 22 | +<br> |
| 23 | + |
| 24 | +## Related Documentation |
| 25 | + |
| 26 | +More details and code examples on the AVR64DD32 can be found at the following links: |
| 27 | +- [Interfacing Quadrature Encoder using CCL with TCA and TCB](http://ww1.microchip.com/downloads/en/AppNotes/00002434A.pdf) |
| 28 | +- [Getting Started with CCL](http://ww1.microchip.com/downloads/en/AppNotes/TB3218-Getting-Started-with-CCL-90003218A.pdf) |
| 29 | +- [AVR64DD32 Product Page](https://www.microchip.com/wwwproducts/en/AVR64DD32) |
| 30 | +- [AVR64DD32 Code Examples on GitHub](https://github.com/microchip-pic-avr-examples?q=AVR64DD32) |
| 31 | +- [AVR64DD32 Project Examples in START](https://start.atmel.com/#examples/AVR64DD32CuriosityNano) |
| 32 | + |
| 33 | +## Software Used |
| 34 | + |
| 35 | +- [MPLAB® X IDE 6.00 or newer](http://www.microchip.com/mplab/mplab-x-ide) |
| 36 | +- [MPLAB® XC8 2.36 or a newer compiler](http://www.microchip.com/mplab/compilers) |
| 37 | +- [AVR-Dx Series Device Pack v2.1.152 or newer](https://packs.download.microchip.com) |
| 38 | +- [MPLAB® Code Configurator Melody core 2.1.13 or newer](https://www.microchip.com/en-us/tools-resources/configure/mplab-code-configurator/melody) |
| 39 | +- [MPLAB® Code Configurator Melody Drivers](https://www.microchip.com/en-us/tools-resources/configure/mplab-code-configurator/melody) |
| 40 | +</br> |
| 41 | +TCB: 5.0.5 |
| 42 | +</br> |
| 43 | +UART: 1.6.0 |
| 44 | +</br> |
| 45 | +CCL: 3.1.2 |
| 46 | + |
| 47 | +- Saleae Logic |
| 48 | +- Terminal software – Tera term, Real term, PuTTY, etc vXXX |
| 49 | + |
| 50 | + |
| 51 | +## Hardware Used |
| 52 | + |
| 53 | +- The AVR64DD32 Curiosity Nano Development Board is used as a test platform. |
| 54 | + <br><img src="images/AVR64DD32.PNG" width="640"><br> |
| 55 | +- Oscilloscope/Logic Analyzer |
| 56 | +- Motor with encoder |
| 57 | + |
| 58 | + <img src="images/motor.jpg" width="300"><br> |
| 59 | +- Rotary encoder <br> |
| 60 | + <img src="images/rotor.jpg" width="300"><br> |
34 | 61 |
|
35 | | -## Setup |
36 | 62 |
|
37 | | -<!-- Explain how to connect hardware and set up software. Depending on complexity, step-by-step instructions and/or tables and/or images can be used --> |
38 | 63 |
|
39 | 64 | ## Operation |
40 | 65 |
|
41 | | -<!-- Explain how to operate the example. Depending on complexity, step-by-step instructions and/or tables and/or images can be used --> |
| 66 | +To program the Curiosity Nano board with this MPLAB® X project, follow the steps provided in the [How to Program the Curiosity Nano Board](#how-to-program-the-curiosity-nano-board) chapter.<br><br> |
| 67 | + |
| 68 | + |
| 69 | +## 1. Setup |
| 70 | + |
| 71 | +The AVR64DD32 Curiosity Nano Development Board is used as test platform. |
| 72 | + |
| 73 | +<br><img src="images/AVR64DD32.PNG" width="500"> |
| 74 | + |
| 75 | +**PA0** and **PA1** are not connected by default on the AVR64DD32 board. **The user must connect them through soldering on the back of the board where it is written PA0 and PA1**. |
| 76 | + |
| 77 | +<br><img src="images/weld.png" width="500"> |
| 78 | + |
| 79 | +The following configurations must be made for this project: |
| 80 | + |
| 81 | + |
| 82 | +| Pin | Configuration | Semnification | |
| 83 | +| :---: | :-----------------: | :-----------------: | |
| 84 | +| PA0 | Input | Phase A | |
| 85 | +| PA1 | Input | Phase B | |
| 86 | +| PC0 | Output | USART TX | |
| 87 | +| PC1 | Input | USART RX | |
| 88 | +| PA6 | Output | CW detection | |
| 89 | +| PD3 | Output | CCW detection | |
| 90 | + |
| 91 | +<br><img src="images/portconn.jpg" width="500"> |
| 92 | +<br><br> |
| 93 | + |
| 94 | + ## 2. Demo |
| 95 | + |
| 96 | +In this demo, the function `QEI_GetVelocity` is called every second and the return is printed on serial communication. |
| 97 | + |
| 98 | +<br><img src="images/demo.png"> |
| 99 | +<br><br> |
| 100 | + |
| 101 | + ## 3. Summary |
| 102 | + |
| 103 | +The quadrature decoder can detect and count clockwise and counterclockwise pulses on rising and falling edges of the quadrature signals. |
| 104 | + |
| 105 | +- [Back to Top](#core-independent-quadrature-decoder-using-the-avr64dd32-microcontroller-with-mcc-melody)<br><br> |
| 106 | + |
| 107 | + |
| 108 | +## How to Program the Curiosity Nano board |
| 109 | + |
| 110 | +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. |
| 111 | + |
| 112 | +- Connect the board to the PC. |
| 113 | + |
| 114 | +- Open the Example_Project.X project in MPLAB X IDE. |
| 115 | + |
| 116 | +- Set the Example_Project.X project as main project. |
| 117 | + |
| 118 | + - Right click on the project in the **Projects** tab and click **Set as Main Project**. |
| 119 | + <br><img src="images/Program_Set_as_Main_Project.PNG" width="600"> |
| 120 | + |
| 121 | +- Clean and build the Example_Project.X project. |
| 122 | + |
| 123 | + - Right click on the **Example_Project.X** project and select **Clean and Build**. |
| 124 | + <br><img src="images/Program_Clean_and_Build.PNG" width="600"> |
| 125 | + |
| 126 | +- Select the **AVRxxxxx Curiosity Nano** in the Connected Hardware Tool section of the project settings: |
| 127 | + |
| 128 | + - Right click on the project and click **Properties** |
| 129 | + - Click on the arrow under the Connected Hardware Tool |
| 130 | + - Select the **AVRxxxxx Curiosity Nano** (click on the **SN**), click **Apply** and then click **OK**: |
| 131 | + <br><img src="images/Program_Tool_Selection.PNG" width="600"> |
| 132 | + |
| 133 | +- Program the project to the board. |
| 134 | + - Right click on the project and click **Make and Program Device**. |
| 135 | + <br><img src="images/Program_Make_and_Program_Device.PNG" width="600"> |
| 136 | + |
| 137 | +<br> |
42 | 138 |
|
43 | | -## Summary |
| 139 | +- [Back to Setup](#1-setup) |
| 140 | +- [Back to Demo](#2-demo) |
| 141 | +- [Back to Summary](#3-summary) |
| 142 | +- [Back to Top](#core-independent-quadrature-decoder-using-the-avr64dd32-microcontroller-with-mcc-melody) |
44 | 143 |
|
45 | | -<!-- Summarize what the example has shown --> |
|
0 commit comments