1
1
/**
2
- application .c for application functionalities
2
+ dac_application .c for application functionalities.
3
3
4
4
@Company
5
5
Microchip Technology Inc.
6
6
7
7
@File Name
8
- application .c
8
+ dac_application .c
9
9
10
10
@Summary
11
- This source file contains functions to generate four different waves
11
+ This source file contains functions to generate four different waves.
12
12
13
13
@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.
22
15
*/
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
+ */
24
36
#include "mcc_generated_files/system/system.h"
25
37
#include "dac_application.h"
26
38
32
44
#define MAX_WAVE_COUNT (5) //Number of functionality 3 signals + 2 reference voltage
33
45
34
46
35
- uint8_t dacUpdateFlag = CLEAR ;
36
- uint8_t changeWaveformFlag = CLEAR ;
47
+ volatile uint8_t dacUpdateFlag = CLEAR ;
48
+ volatile uint8_t changeWaveformFlag = CLEAR ;
37
49
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
40
52
41
53
// 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 [] = {
43
55
0x10 , 0x10 , 0x11 , 0x12 , 0x13 , 0x13 , 0x14 , 0x15 ,
44
56
0x15 , 0x16 , 0x17 , 0x17 , 0x18 , 0x19 , 0x19 , 0x1a ,
45
57
0x1a , 0x1b , 0x1b , 0x1c , 0x1c , 0x1d , 0x1d , 0x1e ,
@@ -59,7 +71,7 @@ const uint16_t sineLUT[] = {
59
71
};
60
72
61
73
// 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 [] = {
63
75
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
64
76
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
65
77
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
@@ -79,7 +91,7 @@ const uint16_t squareLUT[] = {
79
91
};
80
92
81
93
//array to generate the triangle wave of 250 HZ, 3.3V peak to peak
82
- const uint16_t triangleLUT [] = {
94
+ const uint8_t triangleLUT [] = {
83
95
0x0 , 0x1 , 0x1 , 0x2 , 0x2 , 0x3 , 0x3 , 0x4 ,
84
96
0x4 , 0x5 , 0x5 , 0x6 , 0x6 , 0x7 , 0x7 , 0x8 ,
85
97
0x8 , 0x9 , 0x9 , 0xa , 0xa , 0xb , 0xb , 0xc ,
@@ -99,7 +111,7 @@ const uint16_t triangleLUT[] = {
99
111
};
100
112
101
113
//array to generate the sawtooth wave of 250 HZ, 3.3V peak to peak
102
- const uint16_t sawtoothLUT [] = {
114
+ const uint8_t sawtoothLUT [] = {
103
115
0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x01 , 0x01 , 0x01 ,
104
116
0x02 , 0x02 , 0x02 , 0x02 , 0x03 , 0x03 , 0x03 , 0x03 ,
105
117
0x04 , 0x04 , 0x04 , 0x04 , 0x05 , 0x05 , 0x05 , 0x05 ,
@@ -118,12 +130,12 @@ const uint16_t sawtoothLUT[] = {
118
130
0x1e , 0x1e , 0x1e , 0x1e , 0x1f , 0x1f , 0x1f , 0x1f
119
131
};
120
132
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 };
123
135
124
- const uint16_t defaultLUT [] = {0x1f };
136
+ const uint8_t defaultLUT [] = {0x1f };
125
137
126
- const uint16_t * signals [] = {
138
+ const uint8_t * signals [] = {
127
139
setRefVol1 ,
128
140
setRefVol2 ,
129
141
sineLUT ,
@@ -143,10 +155,28 @@ typedef enum {
143
155
SAWTOOTH_WAVE
144
156
}e_signal ;
145
157
146
-
147
158
void ChangeWave (void );
148
159
void UpdateDac (void );
149
160
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
+ */
150
180
void WaveGenerator (void )
151
181
{
152
182
if (changeWaveformFlag == SET )
@@ -183,9 +213,9 @@ void WaveGenerator(void)
183
213
184
214
/*
185
215
@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
187
217
@Preconditions
188
- None
218
+ None
189
219
@Param
190
220
None
191
221
@Returns
@@ -203,15 +233,15 @@ void UpdateDac(void)
203
233
if (index <= 0 )
204
234
{
205
235
index = POINTS ;
206
- LUT_ptr = (uint16_t * ) signals [swcnt ];
236
+ LUT_ptr = (uint8_t * ) signals [swcnt ];
207
237
}
208
238
dacUpdateFlag = CLEAR ;
209
239
}
210
240
}
211
241
212
242
/**
213
243
@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
215
245
@Preconditions
216
246
The changeWaveformFlag should be set prior to use this routine.
217
247
@Param
@@ -230,20 +260,50 @@ void ChangeWave(void)
230
260
{
231
261
swcnt = 0 ;// point to the first waveform to be generated
232
262
}
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
234
264
index = POINTS ; // initialize to number of points in the waveform
235
265
}
236
266
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
+ */
237
277
void InitWaveform (void )
238
278
{
239
- LUT_ptr = (uint16_t * ) signals [0 ];
279
+ LUT_ptr = (uint8_t * ) signals [0 ];
240
280
}
241
281
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
+ */
242
292
void UserInterruptHandler (void )
243
293
{
244
294
changeWaveformFlag = SET ;
245
295
}
246
296
297
+ /*
298
+ @Description
299
+ Interrupt handler routine for timer overflow
300
+ @Preconditions
301
+ None
302
+ @Param
303
+ None
304
+ @Returns
305
+ None
306
+ */
247
307
void TmrUserInterruptHandler (void )
248
308
{
249
309
//the period of the timer and number of points in the waveform will determine the frequency of the generated waveform
0 commit comments