Skip to content

Commit e20d552

Browse files
BabashreeMchpSachin Shewale
authored and
Sachin Shewale
committed
MPAE-15475:Updated example to use melody with CMT
1 parent 98cd221 commit e20d552

24 files changed

+1447
-2555
lines changed

.main-meta/main.json

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@
22
"metaDataVersion": "1.0.0",
33
"category": "com.microchip.ide.project",
44
"content": {
5-
"metaDataVersion": "1.1.0",
5+
"metaDataVersion": "1.3.0",
66
"name": "com.microchip.mcu8.mplabx.project.pic18f47q10-dac-waveform-generation",
7-
"version": "2.0.3",
8-
"displayName": "Waveform generation using DAC",
7+
"version": "2.0.4",
8+
"displayName": "Waveform generation using DAC of PIC18F47Q10 microcontroller",
99
"projectName": "pic18f47q10-dac-waveform-generation",
10-
"shortDescription": "This example demonstrates how DAC peripherals from PIC18F Q10, can be used to generate reference voltage and different signals",
10+
"shortDescription": "This example demonstrates how DAC peripheral of PIC18F47Q10 can be used to generate reference voltage and different signals. Some compatible PIC18-Q10 family of MCUs are: PIC18F24Q10, PIC18F45Q10, PIC18F26Q10",
1111
"ide": {
1212
"name": "MPLAB X",
13-
"semverRange": ">=5.50.0"
13+
"semverRange": ">=6.5.0"
1414
},
1515
"compiler": [
1616
{
1717
"name": "XC8",
18-
"semverRange": "^2.32.0"
18+
"semverRange": "^2.41.0"
1919
}
2020
],
2121
"dfp": {
2222
"name": "PIC18F-Q_DFP",
23-
"semverRange": "^1.11.185"
23+
"semverRange": "^1.15.360"
2424
},
2525
"configurator": {
2626
"name": "MCC",
27-
"semverRange": ">=4.2.1"
27+
"semverRange": ">=5.2.2"
2828
},
2929
"device": {
3030
"metaDataVersion": "1.0.0",
@@ -36,19 +36,14 @@
3636
"versionRange": "*"
3737
}
3838
},
39-
"author": "Microchip",
40-
"subcategories": [
41-
[
42-
"Peripherals", "DAC"
43-
]
44-
],
39+
"author": "Babashree Ingale",
4540
"peripherals": [
46-
"DAC"
41+
"DAC"
4742
],
4843
"keywords": [
4944
"Signal Generation",
50-
"Voltage Reference",
51-
"Melody"
45+
"Voltage Reference",
46+
"Melody"
5247
],
5348
"additionalData": {
5449
"longDescription": {

README.md

Lines changed: 95 additions & 96 deletions
Large diffs are not rendered by default.

pic18f47q10-dac-waveform-generation.X/dac_application.c

Lines changed: 91 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
11
/**
2-
application.c for application functionalities
2+
dac_application.c for application functionalities.
33
44
@Company
55
Microchip Technology Inc.
66
77
@File Name
8-
application.c
8+
dac_application.c
99
1010
@Summary
11-
This source file contains functions to generate four different waves
11+
This source file contains functions to generate four different waves.
1212
1313
@Description
14-
This source file provides implementations for wave generation APIs.
15-
Generation Information :
16-
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.7
17-
Device : PIC18F47Q10
18-
19-
The API's are tested against the following:
20-
Compiler : XC8 2.31 or later
21-
MPLAB : MPLAB X 5.45
14+
This source file provides implementations for wave generation APIs.
2215
*/
23-
#include <pic18.h>
16+
/*
17+
© [2023] Microchip Technology Inc. and its subsidiaries.
18+
19+
Subject to your compliance with these terms, you may use Microchip
20+
software and any derivatives exclusively with Microchip products.
21+
You are responsible for complying with 3rd party license terms
22+
applicable to your use of 3rd party software (including open source
23+
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
24+
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
25+
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
26+
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
27+
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
28+
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
29+
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
30+
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
31+
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
32+
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
33+
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
34+
THIS SOFTWARE.
35+
*/
2436
#include "mcc_generated_files/system/system.h"
2537
#include "dac_application.h"
2638

@@ -32,14 +44,14 @@
3244
#define MAX_WAVE_COUNT (5) //Number of functionality 3 signals + 2 reference voltage
3345

3446

35-
uint8_t dacUpdateFlag = CLEAR;
36-
uint8_t changeWaveformFlag = CLEAR;
47+
volatile uint8_t dacUpdateFlag = CLEAR;
48+
volatile uint8_t changeWaveformFlag = CLEAR;
3749
uint8_t index = POINTS;
38-
volatile unsigned int swcnt; //variable to handle the interrupt counts for update the signal switch
39-
uint16_t *LUT_ptr; //Pointer to feed the input to DAC1
50+
uint8_t swcnt; //variable to handle the interrupt counts for update the signal switch
51+
uint8_t *LUT_ptr; //Pointer to feed the input to DAC1
4052

4153
// array to generate the sine wave signal of 250 HZ, 3.3V peak to peak
42-
const uint16_t sineLUT[] = {
54+
const uint8_t sineLUT[] = {
4355
0x10, 0x10, 0x11, 0x12, 0x13, 0x13, 0x14, 0x15,
4456
0x15, 0x16, 0x17, 0x17, 0x18, 0x19, 0x19, 0x1a,
4557
0x1a, 0x1b, 0x1b, 0x1c, 0x1c, 0x1d, 0x1d, 0x1e,
@@ -59,7 +71,7 @@ const uint16_t sineLUT[] = {
5971
};
6072

6173
// array to generate the square wave signal of 250 HZ, 3.3V peak to peak
62-
const uint16_t squareLUT[] = {
74+
const uint8_t squareLUT[] = {
6375
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6476
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6577
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -79,7 +91,7 @@ const uint16_t squareLUT[] = {
7991
};
8092

8193
//array to generate the triangle wave of 250 HZ, 3.3V peak to peak
82-
const uint16_t triangleLUT[] = {
94+
const uint8_t triangleLUT[] = {
8395
0x0, 0x1, 0x1, 0x2, 0x2, 0x3, 0x3, 0x4,
8496
0x4, 0x5, 0x5, 0x6, 0x6, 0x7, 0x7, 0x8,
8597
0x8, 0x9, 0x9, 0xa, 0xa, 0xb, 0xb, 0xc,
@@ -99,7 +111,7 @@ const uint16_t triangleLUT[] = {
99111
};
100112

101113
//array to generate the sawtooth wave of 250 HZ, 3.3V peak to peak
102-
const uint16_t sawtoothLUT[] = {
114+
const uint8_t sawtoothLUT[] = {
103115
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01,
104116
0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03,
105117
0x04, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05,
@@ -118,12 +130,12 @@ const uint16_t sawtoothLUT[] = {
118130
0x1e, 0x1e, 0x1e, 0x1e, 0x1f, 0x1f, 0x1f, 0x1f
119131
};
120132

121-
const uint16_t setRefVol1[] = {REFERENCE_VOL1};
122-
const uint16_t setRefVol2[] = {REFERENCE_VOL2};
133+
const uint8_t setRefVol1[] = {REFERENCE_VOL1};
134+
const uint8_t setRefVol2[] = {REFERENCE_VOL2};
123135

124-
const uint16_t defaultLUT[] = {0x1f};
136+
const uint8_t defaultLUT[] = {0x1f};
125137

126-
const uint16_t *signals[] = {
138+
const uint8_t *signals[] = {
127139
setRefVol1,
128140
setRefVol2,
129141
sineLUT,
@@ -143,10 +155,28 @@ typedef enum {
143155
SAWTOOTH_WAVE
144156
}e_signal;
145157

146-
147158
void ChangeWave(void);
148159
void UpdateDac(void);
149160

161+
/**
162+
@Summary
163+
Generate signal using DAC1.
164+
165+
@Description
166+
This routine call the signal switching routine
167+
and this routine feed the input digital data in to DAC1 for generate the switched signal
168+
169+
@Preconditions
170+
The WaveGenerator() routine should be called
171+
prior to use this routine.
172+
173+
@Param
174+
inputData - void.
175+
176+
@Returns
177+
None
178+
179+
*/
150180
void WaveGenerator(void)
151181
{
152182
if (changeWaveformFlag == SET)
@@ -183,9 +213,9 @@ void WaveGenerator(void)
183213

184214
/*
185215
@Description
186-
Check if its time to change the DAC output for number of points to generate different waveforms and increment the LUT pointer
216+
Check if its time to change the DAC output for number of points to generate different waveforms and increment the LUT pointer
187217
@Preconditions
188-
None
218+
None
189219
@Param
190220
None
191221
@Returns
@@ -203,15 +233,15 @@ void UpdateDac(void)
203233
if (index <= 0 )
204234
{
205235
index = POINTS;
206-
LUT_ptr = (uint16_t*) signals[swcnt];
236+
LUT_ptr = (uint8_t *)signals[swcnt];
207237
}
208238
dacUpdateFlag = CLEAR;
209239
}
210240
}
211241

212242
/**
213243
@Description
214-
switch the signals from one signal to another after switch press event
244+
Switch the signals from one signal to another after switch press event
215245
@Preconditions
216246
The changeWaveformFlag should be set prior to use this routine.
217247
@Param
@@ -230,20 +260,50 @@ void ChangeWave(void)
230260
{
231261
swcnt = 0;// point to the first waveform to be generated
232262
}
233-
LUT_ptr = (uint16_t*) signals[swcnt]; // LUT pointer = first point in the LUT of corresponding signal
263+
LUT_ptr = (uint8_t *)signals[swcnt]; // LUT pointer = first point in the LUT of corresponding signal
234264
index = POINTS; // initialize to number of points in the waveform
235265
}
236266

267+
/*
268+
@Description
269+
Initialize LUT pointer for generating first waveform at power up
270+
@Preconditions
271+
None
272+
@Param
273+
None
274+
@Returns
275+
None
276+
*/
237277
void InitWaveform(void)
238278
{
239-
LUT_ptr = (uint16_t*) signals[0];
279+
LUT_ptr = (uint8_t *)signals[0];
240280
}
241281

282+
/*
283+
@Description
284+
Custom user interrupt handler routine for IOC on switch press
285+
@Preconditions
286+
None
287+
@Param
288+
None
289+
@Returns
290+
None
291+
*/
242292
void UserInterruptHandler(void)
243293
{
244294
changeWaveformFlag = SET;
245295
}
246296

297+
/*
298+
@Description
299+
Interrupt handler routine for timer overflow
300+
@Preconditions
301+
None
302+
@Param
303+
None
304+
@Returns
305+
None
306+
*/
247307
void TmrUserInterruptHandler(void)
248308
{
249309
//the period of the timer and number of points in the waveform will determine the frequency of the generated waveform

0 commit comments

Comments
 (0)