Skip to content

Commit ef574c7

Browse files
author
srinivasa K R
committed
MPAE-7470 : json, readme is updated
1 parent a488a35 commit ef574c7

File tree

26 files changed

+431
-447
lines changed

26 files changed

+431
-447
lines changed

.main-meta/main.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"metaDataVersion": "1.1.0",
66
"name": "com.microchip.mcu8.mplabx.project.pic18f47q10-adc-computation-modes-mplab",
77
"version": "1.0.0",
8-
"displayName": "ADC With Computational Modes",
8+
"displayName": "Usage of PIC18-Q10 family 10-bit ADCC Computation modes for real-time sensing applications",
99
"projectName": "pic18f47q10-adc-computation-modes-mplab",
10-
"shortDescription": "Microchip offers a 10-bit ADCC module in PIC18 Q10 family microcontrollers. This example highlights the basic, average, burst average and low-pass filter computation modes of ADC using PIC18F47Q10 MCU and Curiosity High Pin Count development board.",
10+
"shortDescription": "Microchip offers a 10-bit ADCC module in PIC18-Q10 family microcontrollers. This example highlights the basic, average, burst average and low-pass filter computation modes of ADC using PIC18F47Q10 MCU and Curiosity High Pin Count development board.",
1111
"ide": {
1212
"name": "MPLAB X IDE",
1313
"semverRange": ">=5.40"

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<!-- Please do not change this logo with link -->
22
[![MCHP](images/microchip.png)](https://www.microchip.com)
33

4-
# ADC with Computational Modes
4+
# Usage of PIC18-Q10 family 10-bit ADCC Computation modes for real-time sensing applications
55

6-
The PIC18FxxQ10 family of devices are equipped with a 10-bit ADC with Computation (ADCC) automating Capacitive Voltage Divider (CVD) techniques for advanced touch sensing, averaging, filtering, oversampling and performing automatic threshold comparisons.
6+
The PIC18-Q10 family of devices are equipped with a 10-bit ADC with Computation (ADCC) automating Capacitive Voltage Divider (CVD) techniques for advanced touch sensing, averaging, filtering, oversampling and performing automatic threshold comparisons.
77

88
### Demonstration Video
99

@@ -27,7 +27,7 @@ The PIC18F47Q10 MCU is used in this demo along with curiosity HPC board and USB-
2727

2828
This demo demonstrates the usage of ADCC module with different computation modes such as basic, average, burst average and low pass filter mode for sensing applications.
2929

30-
The basic mode is considered as ‘legacy mode since it does not use the computation features, like a typical ADC module available in many PIC16 and PIC18 devices.
30+
The basic mode is considered as ‘legacy' mode since it does not use the computation features, like a typical ADC module available in many PIC16 and PIC18 devices.
3131

3232
In average mode, the ADCC module accumulates one sample for each auto conversion trigger. The ADCC module accumulates a certain number of samples (depending upon ADRPT value) and computes average of the accumulated value.
3333

@@ -441,5 +441,5 @@ In the above diagrams, the waveform in yellow is the raw ADRES value and wavefor
441441

442442
## Conclusion
443443

444-
The demo provides a code example, which demonstrates the usage of PIC18FxxQ10 MCUs ADCC module and its advanced computation modes. The advanced ADCC module replaces common firmware tasks for average and filtering implementation with the hardware solution and completely avoids the firmware overhead. It performs advanced computations and filtering of data in hardware without any intervention of CPU, therefore reduces design efforts and improves system response.
444+
The demo provides a code example, which demonstrates the usage of PIC18-Q10 MCUs ADCC module and its advanced computation modes. The advanced ADCC module replaces common firmware tasks for average and filtering implementation with the hardware solution and completely avoids the firmware overhead. It performs advanced computations and filtering of data in hardware without any intervention of CPU, therefore reduces design efforts and improves system response.
445445

images/BlockDiagram.png

26 KB
Loading

images/HardwareSetup.jpg

-122 KB
Loading
Lines changed: 129 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,98 @@
11
#include "application.h"
2+
#include "mcc_generated_files/pin_manager.h"
3+
4+
void ADCC_Initialize_BasicMode(void) {
5+
// ADCRS 0; ADMD Basic_mode; ADACLR disabled; ADPSIS ADRES;
6+
ADCON2 = 0x00;
7+
// ADCALC First derivative of Single measurement; ADTMD enabled; ADSOI ADGO not cleared;
8+
ADCON3 = 0x07;
9+
// ADACT TMR0;
10+
ADACT = 0x02;
11+
// ADCS FOSC/64;
12+
ADCLK = 0x1F;
13+
// ADGO stop; ADFM right; ADON enabled; ADCONT disabled; ADCS FOSC/ADCLK;
14+
ADCON0 = 0x84;
15+
}
16+
17+
void ADCC_Initialize_AverageMode(void) {
18+
// ADLTHL 56;
19+
ADLTHL = 0x38;
20+
// ADLTHH 255; // Lower threshold set to -200 diff from setpoint
21+
ADLTHH = 0xFF;
22+
// ADUTHL 200;
23+
ADUTHL = 0xC8;
24+
// ADUTHH 0; // Upper threshold set to +200 diff from setpoint
25+
ADUTHH = 0x00;
26+
// ADSTPTL 255;
27+
ADSTPTL = 0xFF;
28+
// ADSTPTH 1; // Setpoint set to 511
29+
ADSTPTH = 0x01;
30+
// ADRPT 16;
31+
ADRPT = 0x10;
32+
// ADCRS 4; ADMD Average_mode; ADACLR disabled; ADPSIS ADRES;
33+
ADCON2 = 0x42;
34+
// ADCALC Actual result vs setpoint; ADTMD ADERR > ADLTH and ADERR < ADUTH; ADSOI ADGO not cleared;
35+
ADCON3 = 0x13;
36+
// ADACT TMR0;
37+
ADACT = 0x02;
38+
// ADCS FOSC/64;
39+
ADCLK = 0x1F;
40+
// ADGO stop; ADFM right; ADON enabled; ADCONT disabled; ADCS FOSC/ADCLK;
41+
ADCON0 = 0x84;
42+
}
43+
44+
void ADCC_Initialize_BurstAverageMode(void) {
45+
// ADLTHL 56;
46+
ADLTHL = 0x38;
47+
// ADLTHH 255; // Lower threshold set to -200 diff from setpoint
48+
ADLTHH = 0xFF;
49+
// ADUTHL 200;
50+
ADUTHL = 0xC8;
51+
// ADUTHH 0; // Upper threshold set to +200 diff from setpoint
52+
ADUTHH = 0x00;
53+
// ADSTPTL 255;
54+
ADSTPTL = 0xFF;
55+
// ADSTPTH 1; // Setpoint set to 511
56+
ADSTPTH = 0x01;
57+
// ADRPT 16;
58+
ADRPT = 0x10;
59+
// ADCRS 4; ADMD Burst_average_mode; ADACLR disabled; ADPSIS ADRES;
60+
ADCON2 = 0x43;
61+
// ADCALC Actual result vs setpoint; ADTMD ADERR > ADLTH and ADERR < ADUTH; ADSOI ADGO not cleared;
62+
ADCON3 = 0x13;
63+
// ADACT TMR0;
64+
ADACT = 0x02;
65+
// ADCS FOSC/64;
66+
ADCLK = 0x1F;
67+
// ADGO stop; ADFM right; ADON enabled; ADCONT disabled; ADCS FOSC/ADCLK;
68+
ADCON0 = 0x84;
69+
}
70+
71+
void ADCC_Initialize_LowPassFilterMode(void) {
72+
// ADRPT 16;
73+
ADRPT = 0x10;
74+
// ADCRS 3; ADMD Low_pass_filter_mode; ADACLR disabled; ADPSIS ADRES;
75+
ADCON2 = 0x34;
76+
// ADCALC Filtered value vs setpoint; ADTMD enabled; ADSOI ADGO not cleared;
77+
ADCON3 = 0x57;
78+
// ADACT TMR0;
79+
ADACT = 0x02;
80+
// ADCS FOSC/64;
81+
ADCLK = 0x1F;
82+
// ADGO stop; ADFM right; ADON enabled; ADCONT disabled; ADCS FOSC/ADCLK;
83+
ADCON0 = 0x84;
84+
}
285

386
void ADCC_SetChannel(adcc_channel_t channel) {
487
// select the A/D channel
588
ADPCH = channel;
689
}
790

8-
void ApplicationTask (void) {
91+
void ApplicationTask(void) {
992
// change the ADCC modes based on button press
10-
switch(count) {
93+
switch (count) {
1194
case BASIC_MODE:
12-
if(!basicModeInit) {
95+
if (!basicModeInit) {
1396
// stop the timer and configure it to 10ms for ADC auto conversion
1497
TMR0_StopTimer();
1598
TMR0_Reload(TIMER0_10ms);
@@ -24,14 +107,14 @@ void ApplicationTask (void) {
24107
basicModeInit = true;
25108
} else {
26109
// if ADC conversion is ready, print the data on serial port
27-
if(adcReadyFlag) {
110+
if (adcReadyFlag) {
28111
adcReadyFlag = false;
29-
printf ("Basic Mode - ADRES=%d \r\n", ADRES);
112+
printf("Basic Mode - ADRES=%d \r\n", ADRES);
30113
}
31114
}
32115
break;
33116
case AVG_MODE:
34-
if(!avgModeInit) {
117+
if (!avgModeInit) {
35118
// stop the timer
36119
TMR0_StopTimer();
37120
// turn on LED 1
@@ -46,21 +129,21 @@ void ApplicationTask (void) {
46129
basicModeInit = false;
47130
} else {
48131
// if ADC value is within threshold limits, print the actual value
49-
if(adcReadyFlag) {
132+
if (adcReadyFlag) {
50133
adcReadyFlag = false;
51-
printf ("AVG Mode - ADFLT=%d \r\n", ADFLTR);
134+
printf("AVG Mode - ADFLT=%d \r\n", ADFLTR);
52135
}
53136
// check if upper threshold is crossed
54-
if(ADCC_HasErrorCrossedUpperThreshold()) {
55-
printf ("AVG Mode - ADFLT=%d - SP=%d - UT=%d - UT Crossed\r\n", ADFLTR,ADSTPT,ADUTH);
56-
// check if lower threshold is crossed
57-
} else if(ADCC_HasErrorCrossedLowerThreshold()) {
58-
printf ("AVG Mode - ADFLT=%d - SP=%d - LT=%d - LT Crossed\r\n", ADFLTR,ADSTPT,ADLTH);
59-
}
137+
if (ADCC_HasErrorCrossedUpperThreshold()) {
138+
printf("AVG Mode - ADFLT=%d - SP=%d - UT=%d - UT Crossed\r\n", ADFLTR, ADSTPT, ADUTH);
139+
// check if lower threshold is crossed
140+
} else if (ADCC_HasErrorCrossedLowerThreshold()) {
141+
printf("AVG Mode - ADFLT=%d - SP=%d - LT=%d - LT Crossed\r\n", ADFLTR, ADSTPT, ADLTH);
142+
}
60143
}
61144
break;
62145
case BURST_AVG_MODE:
63-
if(!burstAvgModeInit) {
146+
if (!burstAvgModeInit) {
64147
// stop the timer
65148
TMR0_StopTimer();
66149
// turn on LED 2
@@ -75,21 +158,21 @@ void ApplicationTask (void) {
75158
avgModeInit = false;
76159
} else {
77160
// if ADC value is within threshold limits, print the actual value
78-
if(adcReadyFlag) {
161+
if (adcReadyFlag) {
79162
adcReadyFlag = false;
80-
printf ("Burst AVG Mode - ADFLT=%d \r\n", ADFLTR);
163+
printf("Burst AVG Mode - ADFLT=%d \r\n", ADFLTR);
81164
}
82165
// check if upper threshold is crossed
83-
if(ADCC_HasErrorCrossedUpperThreshold()) {
84-
printf ("Burst AVG Mode - ADFLT=%d - SP=%d - UT=%d - UT Crossed\r\n", ADFLTR,ADSTPT,ADUTH);
85-
// check if lower threshold is crossed
86-
} else if(ADCC_HasErrorCrossedLowerThreshold()) {
87-
printf ("Burst AVG Mode - ADFLT=%d - SP=%d - LT=%d - LT Crossed\r\n", ADFLTR,ADSTPT,ADLTH);
88-
}
166+
if (ADCC_HasErrorCrossedUpperThreshold()) {
167+
printf("Burst AVG Mode - ADFLT=%d - SP=%d - UT=%d - UT Crossed\r\n", ADFLTR, ADSTPT, ADUTH);
168+
// check if lower threshold is crossed
169+
} else if (ADCC_HasErrorCrossedLowerThreshold()) {
170+
printf("Burst AVG Mode - ADFLT=%d - SP=%d - LT=%d - LT Crossed\r\n", ADFLTR, ADSTPT, ADLTH);
171+
}
89172
}
90173
break;
91174
case LPF_MODE:
92-
if(!lpfModeInit) {
175+
if (!lpfModeInit) {
93176
// stop the timer and configure it to 1ms for ADC auto conversion
94177
TMR0_StopTimer();
95178
TMR0_Reload(TIMER0_1ms);
@@ -105,20 +188,34 @@ void ApplicationTask (void) {
105188
burstAvgModeInit = false;
106189
} else {
107190
// send the low pass filter value to the data visualizer
108-
if(adcReadyFlag) {
191+
if (adcReadyFlag) {
109192
adcReadyFlag = false;
110-
EUSART1_Write(0x03);
111-
EUSART1_Write(ADRESL); // Visualizer reads low byte first
112-
EUSART1_Write(ADRESH); // Then reads the high byte// These are commands sent to the Data Visualizer, 0x03 = Start
113-
EUSART1_Write(ADFLTRL); // Visualizer reads low byte first
114-
EUSART1_Write(ADFLTRH); // Then reads the high byte
115-
EUSART1_Write(0xFC); // Stop command
193+
EUSART1_Write(0x03);
194+
EUSART1_Write(ADRESL); // Visualizer reads low byte first
195+
EUSART1_Write(ADRESH); // Then reads the high byte// These are commands sent to the Data Visualizer, 0x03 = Start
196+
EUSART1_Write(ADFLTRL); // Visualizer reads low byte first
197+
EUSART1_Write(ADFLTRH); // Then reads the high byte
198+
EUSART1_Write(0xFC); // Stop command
116199
}
117200
}
118-
break;
201+
break;
119202
default:
120203
count = BASIC_MODE;
121204
lpfModeInit = false;
122205
break;
123206
}
124207
}
208+
209+
void ADCUserInterrupt(void) {
210+
unsigned int ch;
211+
ch++;
212+
213+
adcReadyFlag = true;
214+
215+
}
216+
217+
void TMR4UserInterrupt(void) {
218+
if (RC5_GetValue()) {
219+
count++;
220+
}
221+
}

pic18f47q10-adc-computation-modes-mplab.X/application.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,15 @@ volatile bool lpfModeInit = false;
3737

3838
// set the analog channel for ADCC
3939
void ADCC_SetChannel(adcc_channel_t channel);
40-
40+
void ADCC_Initialize_BasicMode(void);
41+
void ADCC_Initialize_AverageMode(void);
42+
void ADCC_Initialize_BurstAverageMode(void);
43+
void ADCC_Initialize_LowPassFilterMode(void);
4144
// application task
4245
void ApplicationTask(void);
4346

44-
47+
void ADCUserInterrupt(void);
48+
void TMR4UserInterrupt(void);
4549
#ifdef __cplusplus
4650
}
4751
#endif

0 commit comments

Comments
 (0)