Skip to content

Commit 2674ad7

Browse files
MPAE-14802: modified readme file,images and code.
1 parent aa51f4d commit 2674ad7

File tree

27 files changed

+812
-448
lines changed

27 files changed

+812
-448
lines changed

.main-meta/main.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"content": {
55
"metaDataVersion": "1.3.0",
66
"name": "com.microchip.mcu8.mplabx.project.avr64dd32-quadrature-decoder-mplab-mcc",
7-
"version": "1.0.0",
7+
"version": "1.0.1",
88
"displayName": "Core Independent Quadrature Decoder using the AVR64DD32 Microcontroller with MCC Melody",
99
"projectName": "avr64dd32-quadrature-decoder-mplab-mcc",
1010
"shortDescription": "Guide for using Core Independent Quadrature Decoder with AVR64DD32 Microcontroller using MCC Melody",

README.md

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,7 @@ More details and code examples on the AVR64DD32 can be found at the following li
3737
- [AVR-Dx Series Device Pack v2.1.152 or newer](https://packs.download.microchip.com)
3838
- [MPLAB® Code Configurator Melody core 2.1.13 or newer](https://www.microchip.com/en-us/tools-resources/configure/mplab-code-configurator/melody)
3939
- [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
40+
- Logic Analyzer Software
4841
- Terminal software – Tera term, Real term, PuTTY, etc vXXX
4942

5043

@@ -53,12 +46,16 @@ CCL: 3.1.2
5346
- The AVR64DD32 Curiosity Nano Development Board is used as a test platform.
5447
<br><img src="images/AVR64DD32.PNG" width="640"><br>
5548
- Oscilloscope/Logic Analyzer
56-
- Motor with encoder
57-
58-
<img src="images/motor.jpg" width="300"><br>
5949
- Rotary encoder <br>
6050
<img src="images/rotor.jpg" width="300"><br>
6151

52+
*Note*: The setup can be made using **Rotary encoder** or **Motor with encoder**. In this example we use the **Rotary encoder**.
53+
54+
- Motor with encoder
55+
56+
<img src="images/motor.jpg" width="300"><br>
57+
58+
6259

6360

6461
## Operation
@@ -70,32 +67,64 @@ To program the Curiosity Nano board with this MPLAB® X project, follow the step
7067

7168
The AVR64DD32 Curiosity Nano Development Board is used as test platform.
7269

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">
70+
- System Clock - 4 MHz (default)
71+
- TCA0:
72+
- System Clock/64
73+
- Timer Mode 16 bit
74+
- Count Direction - UP
75+
- Overflow Interrupt Enable - every 1 second
76+
- Waveform Generation Mode - Normal Mode
77+
- TCB0:
78+
- Clock Select - Event
79+
- Timer Mode: INT
80+
- Enable Asynchronous
81+
- Overflow Interrupt Enable
82+
- TCB1:
83+
- Clock Select - Event
84+
- Timer Mode: INT
85+
- Enable Asynchronous
86+
- Overflow Interrupt Enable
87+
- UART0:
88+
- Baudrate: 115200
89+
- Parity: None
90+
- Enable USART Transmit and Receive
91+
- Printf Support Enable
7892

7993
The following configurations must be made for this project:
8094

8195

8296
| Pin | Configuration | Semnification |
8397
| :---: | :-----------------: | :-----------------: |
84-
| PA0 | Input | Phase A |
85-
| PA1 | Input | Phase B |
98+
| PA4 | Input | Phase A |
99+
| PA5 | Input | Phase B |
86100
| PC0 | Output | USART TX |
87101
| PC1 | Input | USART RX |
88102
| PA6 | Output | CW detection |
89103
| PD3 | Output | CCW detection |
90104

91-
<br><img src="images/portconn.jpg" width="500">
105+
106+
The internal connections and signals are presented in the following pictures:
107+
108+
<br><img src="images/quad_internal_connections.png" width="1200">
109+
110+
<br><img src="images/cases.png" width="1200">
111+
92112
<br><br>
93113

94114
## 2. Demo
95115

96-
In this demo, the function `QEI_GetVelocity` is called every second and the return is printed on serial communication.
116+
In this demo, the function `QEI_GetVelocity` is called every second and the return is printed on serial communication. The setup connections are presented in the following picture:
117+
118+
<br><img src="images/portconn.jpg" width="960">
119+
<br>
120+
121+
Every one second, the device sends a message through USART interface together with the counter value:
122+
<br><img src="images/serial-terminal.jpg">
123+
124+
The signals are presented in the following picture. The values of counter are **8** and **-8**.
125+
<br><img src="images/Signals_Capture.jpg">
126+
97127

98-
<br><img src="images/demo.png">
99128
<br><br>
100129

101130
## 3. Summary

avr64dd32-quadrature-decoder-mplab-mcc.X/avr64dd32_quad.mc3

Lines changed: 89 additions & 70 deletions
Large diffs are not rendered by default.

avr64dd32-quadrature-decoder-mplab-mcc.X/main.c

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,40 +35,65 @@
3535
#include "qei.h"
3636
#include <stdio.h>
3737

38-
void onCW()
38+
volatile static bool flag_OVF_CW = false;
39+
volatile static bool flag_OVF_CCW = false;
40+
volatile static bool flag_1_sec = false;
41+
42+
void onCW(void)
3943
{
4044
LED_SetHigh();
4145
}
4246

43-
void onCCW()
47+
void onCCW(void)
4448
{
4549
LED_SetLow();
4650
}
4751

48-
void onCW_OVF()
52+
void onCW_OVF(void)
4953
{
50-
printf("CW OVF");
54+
flag_OVF_CW = true;
5155
}
5256

53-
void onCCW_OVF()
57+
void onCCW_OVF(void)
5458
{
55-
printf("CCW OVF");
59+
flag_OVF_CCW = true;
5660
}
5761

58-
int main(void)
62+
void onOneSecond(void)
63+
{
64+
flag_1_sec = true;
65+
}
66+
67+
void main(void)
5968
{
6069
SYSTEM_Initialize();
61-
70+
6271
QEI_Initialize();
6372
QEI_SetHandlerCW(onCW);
6473
QEI_SetHandlerCCW(onCCW);
6574
QEI_SetHandlerCW_OVF(onCW_OVF);
6675
QEI_SetHandlerCCW_OVF(onCCW_OVF);
76+
TCA0_OverflowCallbackRegister(onOneSecond);
6777

6878
while (1)
6979
{
70-
/* QEI_CallbackHandler(); */
71-
printf("Counter value is: %ld\n\r", QEI_GetVelocity());
72-
_delay_ms(1000);
80+
81+
if(flag_OVF_CW == true)
82+
{
83+
flag_OVF_CW = false;
84+
printf("CW OVF\n\r");
85+
}
86+
87+
if(flag_OVF_CCW == true)
88+
{
89+
flag_OVF_CCW = false;
90+
printf("CCW OVF\n\r");
91+
}
92+
93+
if(flag_1_sec == true)
94+
{
95+
flag_1_sec = false;
96+
printf("Counter value is: %ld\n\r", QEI_GetVelocity());
97+
}
7398
}
74-
}
99+
}

avr64dd32-quadrature-decoder-mplab-mcc.X/mcc_generated_files/peripheral/src/evsys.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
// Set the EVSYS module to the options selected in the user interface.
2525

2626
int8_t EVSYS_Initialize(void) {
27-
// CHANNEL0 PORTA_PIN0;
28-
EVSYS.CHANNEL0 = 0x40;
29-
// CHANNEL1 PORTA_PIN1;
30-
EVSYS.CHANNEL1 = 0x41;
27+
// CHANNEL0 PORTA_PIN4;
28+
EVSYS.CHANNEL0 = 0x44;
29+
// CHANNEL1 PORTA_PIN5;
30+
EVSYS.CHANNEL1 = 0x45;
3131
// CHANNEL2 CCL_LUT1;
3232
EVSYS.CHANNEL2 = 0x11;
3333
// CHANNEL3 CCL_LUT3;

avr64dd32-quadrature-decoder-mplab-mcc.X/mcc_generated_files/system/clock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#define CLOCK_H
3636

3737
#ifndef F_CPU
38-
#define F_CPU 24000000UL
38+
#define F_CPU 4000000UL
3939
#endif
4040

4141
#include "ccp.h"

0 commit comments

Comments
 (0)