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
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 ;
3749uint8_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-
147158void ChangeWave (void );
148159void 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+ */
150180void 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+ */
237277void 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+ */
242292void 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+ */
247307void 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