Skip to content

Commit 1819c80

Browse files
committed
MPAE-11969: Added initial example
1 parent 798d545 commit 1819c80

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+6108
-31
lines changed

.main-meta/main.json

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,74 @@
44
"content": {
55
"metaDataVersion": "1.1.0",
66
"name": "com.microchip.mcu8.mplabx.project.avr128db48-timer-triggered-adc-sampling-mplab-mcc",
7-
"version": "",
8-
"displayName": "",
7+
"version": "1.0.0",
8+
"displayName": "Timer Triggered ADC Sampling",
99
"projectName": "avr128db48-timer-triggered-adc-sampling-mplab-mcc",
10-
"shortDescription": "",
10+
"shortDescription": "This example shows how to configure the Analog-to-Digital Converter (ADC) to trigger a conversion on a specific event. The Timer/Counter type A (TCA) overflow is used to trigger the ADC sample accumulation and ADC result is transmitted through USART",
1111
"ide": {
1212
"name": "MPLAB X",
13-
"semverRange": ""
13+
"semverRange": ">=5.45.0"
1414
},
1515
"compiler": [
1616
{
1717
"name": "XC8",
18-
"semverRange": ""
18+
"semverRange": "^2.31.0"
1919
}
2020
],
2121
"dfp": {
22-
"name": "",
23-
"semverRange": ""
22+
"name": "AVR-Dx_DFP",
23+
"semverRange": "^1.7.88"
2424
},
2525
"configurator": {
26-
"name": "",
27-
"semverRange": ""
26+
"name": "MCC",
27+
"semverRange": ">=4.1.0"
2828
},
2929
"device": {
3030
"metaDataVersion": "1.0.0",
3131
"category": "com.microchip.portal.contentRef",
3232
"content": {
3333
"metaDataVersion": "1.0.0",
3434
"category": "com.microchip.device",
35-
"name": "",
35+
"name": "AVR128DB48",
3636
"versionRange": "*"
3737
}
3838
},
39-
"author": "",
39+
"author": "Rupali Honrao",
4040
"subcategories": [
41+
[
42+
"Peripherals", "ADC"
43+
],
44+
[
45+
"Peripherals", "USART"
46+
],
47+
[
48+
"Peripherals", "PORT"
49+
],
50+
[
51+
"Peripherals", "CLKCTRL"
52+
],
53+
[
54+
"Peripherals", "TCA"
55+
],
56+
[
57+
"Peripherals", "EVSYS"
58+
]
4159
],
4260
"peripherals": [
61+
"ADC","USART","PORT","CLKCTRL","TCA","EVSYS"
4362
],
4463
"keywords": [
64+
"8/16 bit timer",
65+
"Curiosity Nano",
66+
"Melody",
67+
"12-bit ADC",
68+
"Oversampling",
69+
"Sample-accumulation",
70+
"CDC",
71+
"Virtual COM Port",
72+
"Data Visualizer",
73+
"Event System"
74+
4575
],
4676
"additionalData": {
4777
"longDescription": {

128db48-timer-triggered-adc-sampling-mplab-mcc.X/128db48-timer-triggered-adc-sampling-mplab-mcc.mc3

Lines changed: 243 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#
2+
# There exist several targets which are by default empty and which can be
3+
# used for execution of your targets. These targets are usually executed
4+
# before and after some main targets. They are:
5+
#
6+
# .build-pre: called before 'build' target
7+
# .build-post: called after 'build' target
8+
# .clean-pre: called before 'clean' target
9+
# .clean-post: called after 'clean' target
10+
# .clobber-pre: called before 'clobber' target
11+
# .clobber-post: called after 'clobber' target
12+
# .all-pre: called before 'all' target
13+
# .all-post: called after 'all' target
14+
# .help-pre: called before 'help' target
15+
# .help-post: called after 'help' target
16+
#
17+
# Targets beginning with '.' are not intended to be called on their own.
18+
#
19+
# Main targets can be executed directly, and they are:
20+
#
21+
# build build a specific configuration
22+
# clean remove built files from a configuration
23+
# clobber remove all built files
24+
# all build all configurations
25+
# help print help mesage
26+
#
27+
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
28+
# .help-impl are implemented in nbproject/makefile-impl.mk.
29+
#
30+
# Available make variables:
31+
#
32+
# CND_BASEDIR base directory for relative paths
33+
# CND_DISTDIR default top distribution directory (build artifacts)
34+
# CND_BUILDDIR default top build directory (object files, ...)
35+
# CONF name of current configuration
36+
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
37+
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
38+
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
39+
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
40+
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
41+
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
42+
#
43+
# NOCDDL
44+
45+
46+
# Environment
47+
MKDIR=mkdir
48+
CP=cp
49+
CCADMIN=CCadmin
50+
RANLIB=ranlib
51+
52+
53+
# build
54+
build: .build-post
55+
56+
.build-pre:
57+
# Add your pre 'build' code here...
58+
59+
.build-post: .build-impl
60+
# Add your post 'build' code here...
61+
62+
63+
# clean
64+
clean: .clean-post
65+
66+
.clean-pre:
67+
# Add your pre 'clean' code here...
68+
# WARNING: the IDE does not call this target since it takes a long time to
69+
# simply run make. Instead, the IDE removes the configuration directories
70+
# under build and dist directly without calling make.
71+
# This target is left here so people can do a clean when running a clean
72+
# outside the IDE.
73+
74+
.clean-post: .clean-impl
75+
# Add your post 'clean' code here...
76+
77+
78+
# clobber
79+
clobber: .clobber-post
80+
81+
.clobber-pre:
82+
# Add your pre 'clobber' code here...
83+
84+
.clobber-post: .clobber-impl
85+
# Add your post 'clobber' code here...
86+
87+
88+
# all
89+
all: .all-post
90+
91+
.all-pre:
92+
# Add your pre 'all' code here...
93+
94+
.all-post: .all-impl
95+
# Add your post 'all' code here...
96+
97+
98+
# help
99+
help: .help-post
100+
101+
.help-pre:
102+
# Add your pre 'help' code here...
103+
104+
.help-post: .help-impl
105+
# Add your post 'help' code here...
106+
107+
108+
109+
# include project implementation makefile
110+
include nbproject/Makefile-impl.mk
111+
112+
# include project make variables
113+
include nbproject/Makefile-variables.mk
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
Copyright (c) [2012-2020] Microchip Technology Inc.
3+
4+
All rights reserved.
5+
6+
You are permitted to use the accompanying software and its derivatives
7+
with Microchip products. See the Microchip license agreement accompanying
8+
this software, if any, for additional info regarding your rights and
9+
obligations.
10+
11+
MICROCHIP SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
12+
WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
13+
LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT
14+
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP OR ITS
15+
LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT
16+
LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE
17+
THEORY FOR ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT
18+
LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES,
19+
OR OTHER SIMILAR COSTS.
20+
21+
To the fullest extend allowed by law, Microchip and its licensors
22+
liability will not exceed the amount of fees, if any, that you paid
23+
directly to Microchip to use this software.
24+
25+
THIRD PARTY SOFTWARE: Notwithstanding anything to the contrary, any
26+
third party software accompanying this software is subject to the terms
27+
and conditions of the third party's license agreement. To the extent
28+
required by third party licenses covering such third party software,
29+
the terms of such license will apply in lieu of the terms provided in
30+
this notice or applicable license. To the extent the terms of such
31+
third party licenses prohibit any of the restrictions described here,
32+
such restrictions will not apply to such third party software.
33+
*/
34+
#include "mcc_generated_files/system/system.h"
35+
36+
struct
37+
{
38+
uint32_t result;
39+
uint16_t sample;
40+
uint16_t average_result;
41+
} adc_data;
42+
43+
#define TRUNCATED_SHIFT 4 /* Total number of SAMPLES accumulated are 128. Since this is truncated down to 16 bits, dividing ADC result by 16 or right shifting by 4 will give the average 12-bit ADC result */
44+
#define MAX_VOLTAGE 3.3
45+
46+
#define ADC_RESOLUTION 0x0FFF /* In the test setup, VDD = 3.3V, ADC ref is VDD. 12 bit ADC count is 4095 at 3.3V */
47+
48+
float voltage;
49+
50+
51+
52+
/***************************************transmit_to_terminal********************************************
53+
Convert float number (calculated voltage) to string and send to USART3, (PC serial terminal)
54+
**************************************************************************************************/
55+
void transmit_to_terminal(float number)
56+
{
57+
char string[8];
58+
59+
dtostrf(number, 4, 2, string);
60+
printf("\nVoltage:");
61+
printf(string);
62+
printf("V");
63+
64+
}
65+
/***************************************MAIN*******************************************************
66+
* Initialize peripherals.
67+
* Enable ADC Auto trigger.
68+
* When ADC result is ready(after accumulating 128 samples), read accumulated result.
69+
* Calculate average result and voltage at analog pin.
70+
* Send calculated voltage to serial terminal through USART3.
71+
**************************************************************************************************/
72+
int main(void)
73+
{
74+
SYSTEM_Initialize();
75+
ADC0_EnableAutoTrigger();
76+
77+
78+
while(1)
79+
{
80+
if(ADC0_IsConversionDone())
81+
{
82+
adc_data.result = ADC0_GetConversionResult();
83+
adc_data.average_result = (uint16_t)(adc_data.result >> (TRUNCATED_SHIFT));
84+
voltage = (float)(adc_data.average_result * MAX_VOLTAGE) / (ADC_RESOLUTION);
85+
transmit_to_terminal(voltage);
86+
87+
}
88+
89+
}
90+
}

0 commit comments

Comments
 (0)