Skip to content

Commit 7c8d817

Browse files
committed
MPAE-18220 added readme.md
1 parent 6b1103d commit 7c8d817

35 files changed

+5500
-2
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
</picture>
77
</a>
88

9-
# MCC Melody ADC Data Streamer Printf Example - Callbacks Implementation (PIC18F57Q43)
9+
# MCC Melody ADC Data Streamer PWM Example - Callbacks Implementation (PIC18F57Q43)
1010

11-
The [ADC Data Streamer example](https://onlinedocs.microchip.com/v2/keyword-lookup?keyword=MCC.MELODY.EXAMPLES.RUNNING.ADCC.DATA.STREAMER&version=latest&redirect=true "Analog-to-Digital Conversion (ADC) Data Streamer example"), of the MCC Melody ADCC Example Component, is used in the Callbacks Implementation. Displays ADCC samples visualized with the Data Streamer. An ADC conversion is taken every 100 ms on the selected analog channel, also toggling a LED and Debug GPIO.
11+
This example builds on the [ADC Data Streamer PWM example](https://onlinedocs.microchip.com/v2/keyword-lookup?keyword=MCC.MELODY.EXAMPLES.RUNNING.ADCC.DATA.STREAMER&version=latest&redirect=true "Analog-to-Digital Conversion (ADC) Data Streamer example"), of the MCC Melody ADCC Example Component (Callback Implementation). Displays ADCC samples visualized with the Data Streamer. An ADC conversion is taken every 100 ms on the selected analog channel, also toggling a LED and Debug GPIO.
12+
13+
A PWM use-case from the [How to Use the PWMx_16BIT PLIB Driver](https://onlinedocs.microchip.com/v2/keyword-lookup?keyword=SCF-PIC8-PWM-V1&version=latest&redirect=true) section, from the MCC Melody API reference for PIC16F/18F. Specifically the **PIC PWM Use Case: Gradually Brightening LED**.
14+
15+
So, as the pot meter is adjusted, the brightness of the PWM is adjusted, mapped to a % of the range of the ADC value.
1216

1317
## MCC Melody Example Components
1418
Example Components are a tight integration of learning material directly into MCC. This allows users to conveniently place configuration instructions side-by-side to the components they are configuring. For more information, refer to the [MCC Melody Example Components Introduction](https://onlinedocs.microchip.com/v2/keyword-lookup?keyword=MCC.MELODY.EXAMPLES&version=latest&redirect=true).
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+
* MAIN Generated Driver File
3+
*
4+
* @file main.c
5+
*
6+
* @defgroup main MAIN
7+
*
8+
* @brief This is the generated driver implementation file for the MAIN driver.
9+
*
10+
* @version MAIN Driver Version 1.0.2
11+
*
12+
* @version Package Version: 3.1.2
13+
*/
14+
15+
/*
16+
© [2024] Microchip Technology Inc. and its subsidiaries.
17+
18+
Subject to your compliance with these terms, you may use Microchip
19+
software and any derivatives exclusively with Microchip products.
20+
You are responsible for complying with 3rd party license terms
21+
applicable to your use of 3rd party software (including open source
22+
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
23+
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
24+
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
25+
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
26+
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
27+
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
28+
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
29+
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
30+
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
31+
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
32+
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
33+
THIS SOFTWARE.
34+
*/
35+
#include "mcc_generated_files/system/system.h"
36+
37+
static void ADCC_ConversionDone_Callback(void);
38+
static void PWM_DutyCycleSetPercentage_Slice1(uint16_t, uint16_t, uint16_t);
39+
static void Timer_Callback_20ms(void);
40+
41+
#define MAXIMUM_INPUT_VALUE 4100 // TODO: Replace with the desired maximum value, e.g. a 16 bit ADC connected to a potentiometer could be 4100)
42+
static uint16_t Count = 0;
43+
static uint16_t periodCountTop = 100;
44+
45+
static const struct TMR_INTERFACE *Timer = &Timer2; // TODO: Replace TimerX with name of const struct TMR_INTERFACE, from MCC Generated Files > timer > tmrx.c
46+
static volatile bool sendFrame = false;
47+
48+
void PWM_DutyCycleSetPercentage_Slice1(uint16_t current, uint16_t max, uint16_t periodCountTop)
49+
{
50+
uint16_t PWM_DytyCyclePercentage = (1.0f - ((double) current / (double) max)) * periodCountTop;
51+
PWM_SetSlice1Output1DutyCycleRegister(PWM_DytyCyclePercentage);
52+
PWM_LoadBufferRegisters();
53+
}
54+
55+
void ADCC_ConversionDone_Callback(void)
56+
{
57+
DataStreamer.adcResult = ADCC_GetConversionResult();
58+
DataStreamer.adcSampleCount++;
59+
PWM_DutyCycleSetPercentage_Slice1(DataStreamer.adcResult, MAXIMUM_INPUT_VALUE, periodCountTop);
60+
IO_Debug_Toggle();
61+
sendFrame = true;
62+
}
63+
64+
void Timer_Callback_20ms(void)
65+
{
66+
ADCC_DischargeSampleCapacitor();
67+
ADCC_StartConversion(channel_ANA7); // TODO: Replace x with the ADCC Channel you selected in Pin Grid View
68+
}
69+
70+
int main(void)
71+
{
72+
SYSTEM_Initialize();
73+
74+
DataStreamer.adcSampleCount = 0;
75+
DataStreamer.adcResult = 0;
76+
ADCC_SetADIInterruptHandler(ADCC_ConversionDone_Callback);
77+
Timer->TimeoutCallbackRegister(Timer_Callback_20ms);
78+
PWM_WritePeriodRegister(periodCountTop);
79+
80+
INTERRUPT_GlobalInterruptEnable();
81+
82+
while (1)
83+
{
84+
if (sendFrame)
85+
{
86+
WriteFrame();
87+
sendFrame = false;
88+
}
89+
}
90+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This file has been autogenerated by MPLAB Code Configurator. Please do not edit this file.
2+
3+
manifest_file_version: 1.0.0
4+
project: pic18f57q43-adcc-data-streamer-pwm-callbacks-mcc
5+
creation_date: 2024-08-08T08:05:43.089+02:00[Europe/Paris]
6+
operating_system: Windows 10
7+
mcc_mode: IDE
8+
mcc_mode_version: v6.20
9+
device_name: PIC18F57Q43
10+
compiler: XC8 2.46
11+
mcc_version: 5.5.1
12+
mcc_core_version: 5.7.1
13+
content_manager_version: 5.0.1-e
14+
is_mcc_offline: false
15+
is_using_prerelease_versions: false
16+
mcc_content_registries: https://registry.npmjs.org/
17+
device_library: {library_class: com.microchip.mcc.melody.Library, name: Melody, version: 2.7.1}
18+
packs: {name: PIC18F-Q_DFP, version: 1.25.433}
19+
modules:
20+
- {name: '@mchp-mcc/data-streamer-driver', type: MELODY, version: 2.0.2-dev.1}
21+
- {name: '@mchp-mcc/example-pic-adcc', type: MELODY, version: 1.0.0}
22+
- {name: '@mchp-mcc/main-manager', type: MELODY, version: 3.1.2}
23+
- {name: '@mchp-mcc/pic-8bit', type: MELODY, version: 5.28.2}
24+
- {name: '@mchp-mcc/pic18-configuration-bits-v1', type: MELODY, version: 5.3.5}
25+
- {name: '@mchp-mcc/pic18-pin-manager', type: MELODY, version: 3.7.1}
26+
- {name: '@mchp-mcc/pin-content-processor', type: MELODY, version: 3.8.0}
27+
- {name: '@mchp-mcc/scf-pic8-adcc-v1', type: MELODY, version: 4.0.13}
28+
- {name: '@mchp-mcc/scf-pic8-interrupt-v1', type: MELODY, version: 5.2.10}
29+
- {name: '@mchp-mcc/scf-pic8-osc-v1', type: MELODY, version: 4.3.6}
30+
- {name: '@mchp-mcc/scf-pic8-pwm-v1', type: MELODY, version: 4.1.10}
31+
- {name: '@mchp-mcc/scf-pic8-tmr2-v1', type: MELODY, version: 4.0.18}
32+
- {name: '@mchp-mcc/scf-pic8-uart-v1', type: MELODY, version: 7.1.2}
33+
- {name: '@mchp-mcc/uart-driver', type: MELODY, version: 1.10.2}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This file has been autogenerated by MPLAB Code Configurator. Please do not edit this file.
2+
3+
manifest_file_version: 1.0.0
4+
project: pic18f57q43-adcc-data-streamer-pwm-callbacks-mcc
5+
creation_date: 2024-08-08T08:05:43.059+02:00[Europe/Paris]
6+
operating_system: Windows 10
7+
mcc_mode: IDE
8+
mcc_mode_version: v6.20
9+
device_name: PIC18F57Q43
10+
compiler: XC8 2.46
11+
mcc_version: 5.5.1
12+
mcc_core_version: 5.7.1
13+
content_manager_version: 5.0.1-e
14+
is_mcc_offline: false
15+
is_using_prerelease_versions: false
16+
mcc_content_registries: https://registry.npmjs.org/
17+
device_library: {library_class: com.microchip.mcc.melody.Library, name: Melody, version: 2.7.1}
18+
packs: {name: PIC18F-Q_DFP, version: 1.25.433}
19+
modules:
20+
- {name: '@mchp-mcc/data-streamer-driver', type: MELODY, version: 2.0.2-dev.1}
21+
- {name: '@mchp-mcc/example-pic-adcc', type: MELODY, version: 1.0.0}
22+
- {name: '@mchp-mcc/main-manager', type: MELODY, version: 3.1.2}
23+
- {name: '@mchp-mcc/pic-8bit', type: MELODY, version: 5.28.2}
24+
- {name: '@mchp-mcc/pic18-configuration-bits-v1', type: MELODY, version: 5.3.5}
25+
- {name: '@mchp-mcc/pic18-pin-manager', type: MELODY, version: 3.7.1}
26+
- {name: '@mchp-mcc/pin-content-processor', type: MELODY, version: 3.8.0}
27+
- {name: '@mchp-mcc/scf-pic8-adcc-v1', type: MELODY, version: 4.0.13}
28+
- {name: '@mchp-mcc/scf-pic8-interrupt-v1', type: MELODY, version: 5.2.10}
29+
- {name: '@mchp-mcc/scf-pic8-osc-v1', type: MELODY, version: 4.3.6}
30+
- {name: '@mchp-mcc/scf-pic8-pwm-v1', type: MELODY, version: 4.1.10}
31+
- {name: '@mchp-mcc/scf-pic8-tmr2-v1', type: MELODY, version: 4.0.18}
32+
- {name: '@mchp-mcc/scf-pic8-uart-v1', type: MELODY, version: 7.1.2}
33+
- {name: '@mchp-mcc/uart-driver', type: MELODY, version: 1.10.2}

0 commit comments

Comments
 (0)