Bar Logo 3.8/7.6 kw Totem pole Demonstration Application (Part-No. (not specified))
 
Content
     
Loading...
Searching...
No Matches
adc1.c
Go to the documentation of this file.
1
17/*
18© [2024] Microchip Technology Inc. and its subsidiaries.
19
20 Subject to your compliance with these terms, you may use Microchip
21 software and any derivatives exclusively with Microchip products.
22 You are responsible for complying with 3rd party license terms
23 applicable to your use of 3rd party software (including open source
24 software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
25 NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
26 SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
27 MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
28 WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
29 INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
30 KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
31 MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
32 FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
33 TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
34 EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
35 THIS SOFTWARE.
36*/
37
38// Section: Included Files
39#include <stddef.h>
40#include "../adc1.h"
41
42// Section: File specific functions
43
44static void (*ADC1_CommonHandler)(void) = NULL;
45static void (*ADC1_ChannelHandler)(enum ADC_CHANNEL channel, uint16_t adcVal) = NULL;
46static void (*ADC1_ComparatorHandler)(enum ADC_CMP comparator) = NULL;
47
48// Section: File specific data type definitions
49
50//Defines an object for ADC_MULTICORE.
53 .ComparatorTasks = NULL,
54 .IndividualChannelInterruptEnable = &ADC1_IndividualChannelInterruptEnable,
55 .IndividualChannelInterruptDisable = &ADC1_IndividualChannelInterruptDisable,
56 .IndividualChannelInterruptFlagClear = &ADC1_IndividualChannelInterruptFlagClear,
57 .IndividualChannelInterruptPrioritySet = &ADC1_IndividualChannelInterruptPrioritySet,
58 .ChannelCallbackRegister = &ADC1_ChannelCallbackRegister,
59 .ComparatorCallbackRegister = &ADC1_ComparatorCallbackRegister,
60 .CorePowerEnable = &ADC1_CorePowerEnable,
61 .SharedCorePowerEnable = &ADC1_SharedCorePowerEnable,
62 .PWMTriggerSourceSet = NULL
63};
64
65//Defines an object for ADC_INTERFACE.
66
67const struct ADC_INTERFACE ADC1 = {
69 .Deinitialize = &ADC1_Deinitialize,
70 .Enable = &ADC1_Enable,
71 .Disable = &ADC1_Disable,
72 .SoftwareTriggerEnable = &ADC1_SoftwareTriggerEnable,
73 .SoftwareTriggerDisable = &ADC1_SoftwareTriggerDisable,
74 .ChannelSelect = &ADC1_ChannelSelect,
75 .ConversionResultGet = &ADC1_ConversionResultGet,
76 .IsConversionComplete = &ADC1_IsConversionComplete,
77 .ResolutionSet = &ADC1_ResolutionSet,
78 .InterruptEnable = &ADC1_InterruptEnable,
79 .InterruptDisable = &ADC1_InterruptDisable,
80 .InterruptFlagClear = &ADC1_InterruptFlagClear,
81 .InterruptPrioritySet = &ADC1_InterruptPrioritySet,
82 .CommonCallbackRegister = &ADC1_CommonCallbackRegister,
83 .Tasks = &ADC1_Tasks,
84 .adcMulticoreInterface = &adc1Multicore,
85};
86
87// Section: Driver Interface Function Definitions
88
89void ADC1_Initialize (void)
90{
91 // ADSIDL disabled; ADON enabled;
92 ADCON1L = (uint16_t)0x8000 & (uint16_t)0x7FFF; //Disabling ADON bit
93 // SHRRES 12-bit resolution; FORM Integer;
94 ADCON1H = 0x60;
95 // SHRADCS 2; SHREISEL Early interrupt is generated 1 TADCORE clock prior to data being ready; PTGEN disabled; EIEN disabled; REFERCIE disabled; REFCIE disabled;
96 ADCON2L = 0x0;
97 // SHRSAMC 0;
98 ADCON2H = 0x0;
99 // CNVCHSEL AN0; SWCTRG disabled; SWLCTRG disabled; SHRSAMP disabled; SUSPCIE disabled; SUSPEND disabled; REFSEL disabled;
100 ADCON3L = 0x0;
101 // C0EN enabled; C1EN enabled; SHREN enabled; CLKDIV 1; CLKSEL FOSC/2;
102 ADCON3H = (uint16_t)0x83 & (uint16_t)0xFF00; //Disabling C0EN, C1EN, C2EN, C3EN and SHREN bits
103 // SAMC0EN enabled; SAMC1EN enabled; SYNCTRG0 disabled; SYNCTRG1 disabled;
104 ADCON4L = 0x3;
105 // C0CHS S1AN0; C1CHS S1AN1;
106 ADCON4H = 0x0;
107 // SIGN0 disabled; DIFF0 disabled; SIGN1 disabled; DIFF1 disabled; SIGN2 disabled; SIGN3 disabled; SIGN4 disabled; SIGN5 disabled; SIGN6 disabled; SIGN7 disabled;
108 ADMOD0L = 0x0;
109 // SIGN8 disabled; SIGN9 disabled; SIGN10 disabled; SIGN11 disabled; SIGN12 disabled; SIGN13 disabled; SIGN14 disabled; SIGN15 disabled;
110 ADMOD0H = 0x0;
111 // SIGN16 disabled; SIGN17 disabled; SIGN18 disabled; SIGN19 disabled; SIGN20 disabled;
112 ADMOD1L = 0x0;
113 // IE0 enabled; IE1 enabled; IE2 disabled; IE3 disabled; IE4 disabled; IE5 disabled; IE6 disabled; IE7 disabled; IE8 disabled; IE9 disabled; IE10 disabled; IE11 disabled; IE12 disabled; IE13 disabled; IE14 disabled; IE15 disabled;
114 ADIEL = 0x3;
115 // IE16 disabled; IE17 disabled; IE18 disabled; IE19 disabled; IE20 disabled;
116 ADIEH = 0x0;
117 //
118 ADSTATL = 0x0;
119 //
120 ADSTATH = 0x0;
121 // CMPEN0 disabled; CMPEN1 disabled; CMPEN2 disabled; CMPEN3 disabled; CMPEN4 disabled; CMPEN5 disabled; CMPEN6 disabled; CMPEN7 disabled; CMPEN8 disabled; CMPEN9 disabled; CMPEN10 disabled; CMPEN11 disabled; CMPEN12 disabled; CMPEN13 disabled; CMPEN14 disabled; CMPEN15 disabled;
122 ADCMP0ENL = 0x0;
123 // CMPEN0 disabled; CMPEN1 disabled; CMPEN2 disabled; CMPEN3 disabled; CMPEN4 disabled; CMPEN5 disabled; CMPEN6 disabled; CMPEN7 disabled; CMPEN8 disabled; CMPEN9 disabled; CMPEN10 disabled; CMPEN11 disabled; CMPEN12 disabled; CMPEN13 disabled; CMPEN14 disabled; CMPEN15 disabled;
124 ADCMP1ENL = 0x0;
125 // CMPEN0 disabled; CMPEN1 disabled; CMPEN2 disabled; CMPEN3 disabled; CMPEN4 disabled; CMPEN5 disabled; CMPEN6 disabled; CMPEN7 disabled; CMPEN8 disabled; CMPEN9 disabled; CMPEN10 disabled; CMPEN11 disabled; CMPEN12 disabled; CMPEN13 disabled; CMPEN14 disabled; CMPEN15 disabled;
126 ADCMP2ENL = 0x0;
127 // CMPEN0 disabled; CMPEN1 disabled; CMPEN2 disabled; CMPEN3 disabled; CMPEN4 disabled; CMPEN5 disabled; CMPEN6 disabled; CMPEN7 disabled; CMPEN8 disabled; CMPEN9 disabled; CMPEN10 disabled; CMPEN11 disabled; CMPEN12 disabled; CMPEN13 disabled; CMPEN14 disabled; CMPEN15 disabled;
128 ADCMP3ENL = 0x0;
129 // CMPEN16 disabled; CMPEN17 disabled; CMPEN18 disabled; CMPEN19 disabled; CMPEN20 disabled;
130 ADCMP0ENH = 0x0;
131 // CMPEN16 disabled; CMPEN17 disabled; CMPEN18 disabled; CMPEN19 disabled; CMPEN20 disabled;
132 ADCMP1ENH = 0x0;
133 // CMPEN16 disabled; CMPEN17 disabled; CMPEN18 disabled; CMPEN19 disabled; CMPEN20 disabled;
134 ADCMP2ENH = 0x0;
135 // CMPEN16 disabled; CMPEN17 disabled; CMPEN18 disabled; CMPEN19 disabled; CMPEN20 disabled;
136 ADCMP3ENH = 0x0;
137 // CMPLO 0x0;
138 ADCMP0LO = 0x0;
139 // CMPLO 0x0;
140 ADCMP1LO = 0x0;
141 // CMPLO 0x0;
142 ADCMP2LO = 0x0;
143 // CMPLO 0x0;
144 ADCMP3LO = 0x0;
145 // CMPHI 0x0;
146 ADCMP0HI = 0x0;
147 // CMPHI 0x0;
148 ADCMP1HI = 0x0;
149 // CMPHI 0x0;
150 ADCMP2HI = 0x0;
151 // CMPHI 0x0;
152 ADCMP3HI = 0x0;
153 //
154 ADFL0DAT = 0x0;
155 //
156 ADFL1DAT = 0x0;
157 //
158 ADFL2DAT = 0x0;
159 //
160 ADFL3DAT = 0x0;
161 // FLCHSEL AN0; IE disabled; OVRSAM 4x; MODE Oversampling Mode; FLEN disabled;
162 ADFL0CON = 0x400;
163 // FLCHSEL AN0; IE disabled; OVRSAM 4x; MODE Oversampling Mode; FLEN disabled;
164 ADFL1CON = 0x400;
165 // FLCHSEL AN0; IE disabled; OVRSAM 4x; MODE Oversampling Mode; FLEN disabled;
166 ADFL2CON = 0x400;
167 // FLCHSEL AN0; IE disabled; OVRSAM 4x; MODE Oversampling Mode; FLEN disabled;
168 ADFL3CON = 0x400;
169 // LOLO disabled; LOHI disabled; HILO disabled; HIHI disabled; BTWN disabled; IE disabled; CMPEN disabled;
170 ADCMP0CON = 0x0;
171 // LOLO disabled; LOHI disabled; HILO disabled; HIHI disabled; BTWN disabled; IE disabled; CMPEN disabled;
172 ADCMP1CON = 0x0;
173 // LOLO disabled; LOHI disabled; HILO disabled; HIHI disabled; BTWN disabled; IE disabled; CMPEN disabled;
174 ADCMP2CON = 0x0;
175 // LOLO disabled; LOHI disabled; HILO disabled; HIHI disabled; BTWN disabled; IE disabled; CMPEN disabled;
176 ADCMP3CON = 0x0;
177 // LVLEN0 disabled; LVLEN1 disabled; LVLEN2 disabled; LVLEN3 disabled; LVLEN4 disabled; LVLEN5 disabled; LVLEN6 disabled; LVLEN7 disabled; LVLEN8 disabled; LVLEN9 disabled; LVLEN10 disabled; LVLEN11 disabled; LVLEN12 disabled; LVLEN13 disabled; LVLEN14 disabled; LVLEN15 disabled;
178 ADLVLTRGL = 0x0;
179 // LVLEN16 disabled; LVLEN17 disabled; LVLEN18 disabled; LVLEN19 disabled; LVLEN20 disabled;
180 ADLVLTRGH = 0x0;
181 // SAMC 0;
182 ADCORE0L = 0x0;
183 // SAMC 0;
184 ADCORE1L = 0x0;
185 // ADCS 2; RES 12-bit resolution; EISEL Early interrupt is generated 1 TADCORE clock prior to data being ready;
186 ADCORE0H = 0x300;
187 // ADCS 2; RES 12-bit resolution; EISEL Early interrupt is generated 1 TADCORE clock prior to data being ready;
188 ADCORE1H = 0x300;
189 // EIEN0 disabled; EIEN1 disabled; EIEN2 disabled; EIEN3 disabled; EIEN4 disabled; EIEN5 disabled; EIEN6 disabled; EIEN7 disabled; EIEN8 disabled; EIEN9 disabled; EIEN10 disabled; EIEN11 disabled; EIEN12 disabled; EIEN13 disabled; EIEN14 disabled; EIEN15 disabled;
190 ADEIEL = 0x0;
191 // EIEN16 disabled; EIEN17 disabled; EIEN18 disabled; EIEN19 disabled; EIEN20 disabled;
192 ADEIEH = 0x0;
193 // EISTAT0 disabled; EISTAT1 disabled; EISTAT2 disabled; EISTAT3 disabled; EISTAT4 disabled; EISTAT5 disabled; EISTAT6 disabled; EISTAT7 disabled; EISTAT8 disabled; EISTAT9 disabled; EISTAT10 disabled; EISTAT11 disabled; EISTAT12 disabled; EISTAT13 disabled; EISTAT14 disabled; EISTAT15 disabled;
194 ADEISTATL = 0x0;
195 // EISTAT16 disabled; EISTAT17 disabled; EISTAT18 disabled; EISTAT19 disabled; EISTAT20 disabled;
196 ADEISTATH = 0x0;
197 // C0CIE disabled; C1CIE disabled; SHRCIE disabled; WARMTIME 16 Source Clock Periods;
198 ADCON5H = (uint16_t)0x400 & (uint16_t)0xF0FF; //Disabling WARMTIME bit
199 //
200 ADCBUF0 = 0x0;
201 //
202 ADCBUF1 = 0x0;
203 //
204 ADCBUF2 = 0x0;
205 //
206 ADCBUF3 = 0x0;
207 //
208 ADCBUF4 = 0x0;
209 //
210 ADCBUF5 = 0x0;
211 //
212 ADCBUF6 = 0x0;
213 //
214 ADCBUF7 = 0x0;
215 //
216 ADCBUF8 = 0x0;
217 //
218 ADCBUF9 = 0x0;
219 //
220 ADCBUF10 = 0x0;
221 //
222 ADCBUF11 = 0x0;
223 //
224 ADCBUF12 = 0x0;
225 //
226 ADCBUF13 = 0x0;
227 //
228 ADCBUF14 = 0x0;
229 //
230 ADCBUF15 = 0x0;
231 //
232 ADCBUF16 = 0x0;
233 //
234 ADCBUF17 = 0x0;
235 //
236 ADCBUF18 = 0x0;
237 //
238 ADCBUF19 = 0x0;
239 //
240 ADCBUF20 = 0x0;
241
245
246 // Clearing ADC1 interrupt.
247 IFS5bits.ADCIF = 0;
248 // Enabling ADC1 interrupt.
249 IEC5bits.ADCIE = 1;
250 // Clearing IL1_F interrupt flag.
251 IFS5bits.ADCAN0IF = 0;
252 // Enabling IL1_F interrupt.
253 IEC5bits.ADCAN0IE = 1;
254 // Clearing IL2_F interrupt flag.
255 IFS5bits.ADCAN1IF = 0;
256 // Enabling IL2_F interrupt.
257 IEC5bits.ADCAN1IE = 1;
258
259 // Setting WARMTIME bit
260 ADCON5Hbits.WARMTIME = 0xF;
261 // Enabling ADC Module
262 ADCON1Lbits.ADON = 0x1;
263 // Enabling Power for Core0
265 // Enabling Power for Core1
267 // Enabling Power for the Shared Core
269
270 //TRGSRC0 S1 PWM1 Trigger1; TRGSRC1 S1 PWM2 Trigger1;
271 ADTRIG0L = 0x604;
272 //TRGSRC2 None; TRGSRC3 None;
273 ADTRIG0H = 0x0;
274 //TRGSRC4 None; TRGSRC5 None;
275 ADTRIG1L = 0x0;
276 //TRGSRC6 None; TRGSRC7 None;
277 ADTRIG1H = 0x0;
278 //TRGSRC8 None; TRGSRC9 None;
279 ADTRIG2L = 0x0;
280 //TRGSRC10 S1 PWM1 Trigger1; TRGSRC11 None;
281 ADTRIG2H = 0x4;
282 //TRGSRC12 None; TRGSRC13 None;
283 ADTRIG3L = 0x0;
284 //TRGSRC14 None; TRGSRC15 Common Software Trigger;
285 ADTRIG3H = 0x100;
286 //TRGSRC16 None; TRGSRC17 None;
287 ADTRIG4L = 0x0;
288 //TRGSRC18 None; TRGSRC19 None;
289 ADTRIG4H = 0x0;
290 //TRGSRC20 None;
291 ADTRIG5L = 0x0;
292}
293
295{
296 uint16_t dummy; //buffers has to be read before clearing interrupt flags
297 ADCON1Lbits.ADON = 0;
298
299 dummy = ADCBUF0;
300 IFS5bits.ADCAN0IF = 0;
301 IEC5bits.ADCAN0IE = 0;
302
303 dummy = ADCBUF1;
304 IFS5bits.ADCAN1IF = 0;
305 IEC5bits.ADCAN1IE = 0;
306
307 IFS5bits.ADCIF = 0;
308 IEC5bits.ADCIE = 0;
309
310 ADCON1L = 0x0;
311 ADCON1H = 0x60;
312 ADCON2L = 0x0;
313 ADCON2H = 0x0;
314 ADCON3L = 0x0;
315 ADCON3H = 0x0;
316 ADCON4L = 0x0;
317 ADCON4H = 0x0;
318 ADMOD0L = 0x0;
319 ADMOD0H = 0x0;
320 ADMOD1L = 0x0;
321 ADIEL = 0x0;
322 ADIEH = 0x0;
323 ADSTATL = 0x0;
324 ADSTATH = 0x0;
325 ADCMP0ENL = 0x0;
326 ADCMP1ENL = 0x0;
327 ADCMP2ENL = 0x0;
328 ADCMP3ENL = 0x0;
329 ADCMP0ENH = 0x0;
330 ADCMP1ENH = 0x0;
331 ADCMP2ENH = 0x0;
332 ADCMP3ENH = 0x0;
333 ADCMP0LO = 0x0;
334 ADCMP1LO = 0x0;
335 ADCMP2LO = 0x0;
336 ADCMP3LO = 0x0;
337 ADCMP0HI = 0x0;
338 ADCMP1HI = 0x0;
339 ADCMP2HI = 0x0;
340 ADCMP3HI = 0x0;
341 ADFL0DAT = 0x0;
342 ADFL1DAT = 0x0;
343 ADFL2DAT = 0x0;
344 ADFL3DAT = 0x0;
345 ADFL0CON = 0x0;
346 ADFL1CON = 0x0;
347 ADFL2CON = 0x0;
348 ADFL3CON = 0x0;
349 ADTRIG0L = 0x0;
350 ADTRIG0H = 0x0;
351 ADTRIG1L = 0x0;
352 ADTRIG1H = 0x0;
353 ADTRIG2L = 0x0;
354 ADTRIG2H = 0x0;
355 ADTRIG3L = 0x0;
356 ADTRIG3H = 0x0;
357 ADTRIG4L = 0x0;
358 ADTRIG4H = 0x0;
359 ADTRIG5L = 0x0;
360 ADCMP0CON = 0x0;
361 ADCMP1CON = 0x0;
362 ADCMP2CON = 0x0;
363 ADCMP3CON = 0x0;
364 ADLVLTRGL = 0x0;
365 ADLVLTRGH = 0x0;
366 ADCORE0L = 0x0;
367 ADCORE1L = 0x0;
368 ADCORE0H = 0x300;
369 ADCORE1H = 0x300;
370 ADEIEL = 0x0;
371 ADEIEH = 0x0;
372 ADEISTATL = 0x0;
373 ADEISTATH = 0x0;
374 ADCON5L = 0x0;
375 ADCON5H = 0x0;
376 ADCBUF0 = 0x0;
377 ADCBUF1 = 0x0;
378 ADCBUF2 = 0x0;
379 ADCBUF3 = 0x0;
380 ADCBUF4 = 0x0;
381 ADCBUF5 = 0x0;
382 ADCBUF6 = 0x0;
383 ADCBUF7 = 0x0;
384 ADCBUF8 = 0x0;
385 ADCBUF9 = 0x0;
386 ADCBUF10 = 0x0;
387 ADCBUF11 = 0x0;
388 ADCBUF12 = 0x0;
389 ADCBUF13 = 0x0;
390 ADCBUF14 = 0x0;
391 ADCBUF15 = 0x0;
392 ADCBUF16 = 0x0;
393 ADCBUF17 = 0x0;
394 ADCBUF18 = 0x0;
395 ADCBUF19 = 0x0;
396 ADCBUF20 = 0x0;
397}
398
400{
401 switch(core)
402 {
403 case ADC_CORE_0:
404 ADCON5Lbits.C0PWR = 1;
405 while(ADCON5Lbits.C0RDY == 0)
406 {
407 }
408 ADCON3Hbits.C0EN = 1;
409 break;
410 case ADC_CORE_1:
411 ADCON5Lbits.C1PWR = 1;
412 while(ADCON5Lbits.C1RDY == 0)
413 {
414 }
415 ADCON3Hbits.C1EN = 1;
416 break;
417 default:
418 break;
419 }
420}
421
422
424{
425 ADCON5Lbits.SHRPWR = 1;
426 while(ADCON5Lbits.SHRRDY == 0)
427 {
428 }
429 ADCON3Hbits.SHREN = 1;
430}
431
432void ADC1_CommonCallbackRegister(void(*callback)(void))
433{
434 if(NULL != callback)
435 {
436 ADC1_CommonHandler = callback;
437 }
438}
439
440void __attribute__ ((weak)) ADC1_CommonCallback (void)
441{
442
443}
444
445
446void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCInterrupt ( void )
447{
448 uint16_t adcVal;
449 if(NULL != ADC1_CommonHandler)
450 {
451 (*ADC1_CommonHandler)();
452 }
453
454 if(IFS6bits.ADCAN10IF == 1)
455 {
456 //Read the ADC value from the ADCBUF before clearing interrupt
457 adcVal = ADCBUF10;
458 if(NULL != ADC1_ChannelHandler)
459 {
460 (*ADC1_ChannelHandler)(FB_Vout, adcVal);
461 }
462 IFS6bits.ADCAN10IF = 0;
463 }
464 if(IFS6bits.ADCAN15IF == 1)
465 {
466 //Read the ADC value from the ADCBUF before clearing interrupt
467 adcVal = ADCBUF15;
468 if(NULL != ADC1_ChannelHandler)
469 {
470 (*ADC1_ChannelHandler)(FB_AC_N, adcVal);
471 }
472 IFS6bits.ADCAN15IF = 0;
473 }
474 if(IFS5bits.ADCAN0IF == 1)
475 {
476 //Read the ADC value from the ADCBUF before clearing interrupt
477 adcVal = ADCBUF0;
478 if(NULL != ADC1_ChannelHandler)
479 {
480 (*ADC1_ChannelHandler)(IL1_F, adcVal);
481 }
482 IFS5bits.ADCAN0IF = 0;
483 }
484 if(IFS5bits.ADCAN1IF == 1)
485 {
486 //Read the ADC value from the ADCBUF before clearing interrupt
487 adcVal = ADCBUF1;
488 if(NULL != ADC1_ChannelHandler)
489 {
490 (*ADC1_ChannelHandler)(IL2_F, adcVal);
491 }
492 IFS5bits.ADCAN1IF = 0;
493 }
494
495 // clear the ADC1 interrupt flag
496 IFS5bits.ADCIF = 0;
497}
498
499void __attribute__ ((weak)) ADC1_Tasks ( void )
500{
501 if(IFS5bits.ADCIF == 1)
502 {
503 if(NULL != ADC1_CommonHandler)
504 {
505 (*ADC1_CommonHandler)();
506 }
507
508 // clear the ADC1 interrupt flag
509 IFS5bits.ADCIF = 0;
510 }
511}
512
513void ADC1_ChannelCallbackRegister(void(*callback)(enum ADC_CHANNEL channel, uint16_t adcVal))
514{
515 if(NULL != callback)
516 {
517 ADC1_ChannelHandler = callback;
518 }
519}
520
521void __attribute__ ((weak)) ADC1_ChannelCallback (enum ADC_CHANNEL channel, uint16_t adcVal)
522{
523 (void)channel;
524 (void)adcVal;
525}
526
527
528void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCAN10Interrupt ( void )
529{
530 uint16_t valFB_Vout;
531 //Read the ADC value from the ADCBUF
532 valFB_Vout = ADCBUF10;
533
534 if(NULL != ADC1_ChannelHandler)
535 {
536 (*ADC1_ChannelHandler)(FB_Vout, valFB_Vout);
537 }
538
539 //clear the FB_Vout interrupt flag
540 IFS6bits.ADCAN10IF = 0;
541}
542
543void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCAN15Interrupt ( void )
544{
545 uint16_t valFB_AC_N;
546 //Read the ADC value from the ADCBUF
547 valFB_AC_N = ADCBUF15;
548
549 if(NULL != ADC1_ChannelHandler)
550 {
551 (*ADC1_ChannelHandler)(FB_AC_N, valFB_AC_N);
552 }
553
554 //clear the FB_AC_N interrupt flag
555 IFS6bits.ADCAN15IF = 0;
556}
557
558
559void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCAN0Interrupt ( void )
560{
561 uint16_t valIL1_F;
562 //Read the ADC value from the ADCBUF
563 valIL1_F = ADCBUF0;
564
565 if(NULL != ADC1_ChannelHandler)
566 {
567 (*ADC1_ChannelHandler)(IL1_F, valIL1_F);
568 }
569
570 //clear the IL1_F interrupt flag
571 IFS5bits.ADCAN0IF = 0;
572}
573
574void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCAN1Interrupt ( void )
575{
576 uint16_t valIL2_F;
577 //Read the ADC value from the ADCBUF
578 valIL2_F = ADCBUF1;
579
580 if(NULL != ADC1_ChannelHandler)
581 {
582 (*ADC1_ChannelHandler)(IL2_F, valIL2_F);
583 }
584
585 //clear the IL2_F interrupt flag
586 IFS5bits.ADCAN1IF = 0;
587}
588
589
590void __attribute__ ((weak)) ADC1_ChannelTasks (enum ADC_CHANNEL channel)
591{
592 uint16_t adcVal;
593
594 switch(channel)
595 {
596 case FB_Vout:
597 if((bool)ADSTATLbits.AN10RDY == 1)
598 {
599 //Read the ADC value from the ADCBUF
600 adcVal = ADCBUF10;
601
602 if(NULL != ADC1_ChannelHandler)
603 {
604 (*ADC1_ChannelHandler)(channel, adcVal);
605 }
606 }
607 break;
608 case FB_AC_N:
609 if((bool)ADSTATLbits.AN15RDY == 1)
610 {
611 //Read the ADC value from the ADCBUF
612 adcVal = ADCBUF15;
613
614 if(NULL != ADC1_ChannelHandler)
615 {
616 (*ADC1_ChannelHandler)(channel, adcVal);
617 }
618 }
619 break;
620 case IL1_F:
621 if((bool)ADSTATLbits.AN0RDY == 1)
622 {
623 //Read the ADC value from the ADCBUF
624 adcVal = ADCBUF0;
625
626 if(NULL != ADC1_ChannelHandler)
627 {
628 (*ADC1_ChannelHandler)(channel, adcVal);
629 }
630 }
631 break;
632 case IL2_F:
633 if((bool)ADSTATLbits.AN1RDY == 1)
634 {
635 //Read the ADC value from the ADCBUF
636 adcVal = ADCBUF1;
637
638 if(NULL != ADC1_ChannelHandler)
639 {
640 (*ADC1_ChannelHandler)(channel, adcVal);
641 }
642 }
643 break;
644 default:
645 break;
646 }
647}
648
649void ADC1_ComparatorCallbackRegister(void(*callback)(enum ADC_CMP comparator))
650{
651 if(NULL != callback)
652 {
653 ADC1_ComparatorHandler = callback;
654 }
655}
656
657void __attribute__ ((weak)) ADC1_ComparatorCallback (enum ADC_CMP comparator)
658{
659 (void)comparator;
660}
661
662
663
This is the generated driver header file for the ADC1 driver.
@ ADC_CORE_1
Definition adc_types.h:80
@ ADC_CORE_0
Definition adc_types.h:78
@ IL1_F
Definition adc_types.h:59
@ FB_AC_N
Definition adc_types.h:58
@ IL2_F
Definition adc_types.h:60
@ FB_Vout
Definition adc_types.h:57
static void(* ADC1_ComparatorHandler)(enum ADC_CMP comparator)
Definition adc1.c:46
void _ADCAN15Interrupt(void)
Definition adc1.c:543
void _ADCAN1Interrupt(void)
Definition adc1.c:574
static void(* ADC1_CommonHandler)(void)
Definition adc1.c:44
void _ADCAN0Interrupt(void)
Definition adc1.c:559
void _ADCAN10Interrupt(void)
Definition adc1.c:528
const struct ADC_MULTICORE adc1Multicore
Definition adc1.c:51
void _ADCInterrupt(void)
Definition adc1.c:446
static void(* ADC1_ChannelHandler)(enum ADC_CHANNEL channel, uint16_t adcVal)
Definition adc1.c:45
static bool ADC1_IsConversionComplete(enum ADC_CHANNEL channel)
This inline function returns the status of conversion.This function is used to determine if conversio...
Definition adc1.h:215
static void ADC1_InterruptFlagClear(void)
Clears interrupt flag manually.
Definition adc1.h:282
void ADC1_CommonCallback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
Definition adc1.c:440
static void ADC1_IndividualChannelInterruptPrioritySet(enum ADC_CHANNEL channel, enum INTERRUPT_PRIORITY priorityValue)
This inline function allows selection of priority for individual channel interrupt.
Definition adc1.h:426
static void ADC1_ResolutionSet(enum ADC_RESOLUTION_TYPE resolution)
This inline function helps to configure all cores with same resolution.
Definition adc1.h:247
static void ADC1_IndividualChannelInterruptDisable(enum ADC_CHANNEL channel)
This inline function disables individual channel interrupt.
Definition adc1.h:367
void ADC1_ComparatorCallback(enum ADC_CMP comparator)
Comparator callback function.
Definition adc1.c:657
void ADC1_Deinitialize(void)
Deinitializes the ADC1 to POR values.
Definition adc1.c:294
void ADC1_SharedCorePowerEnable(void)
Enables power for ADC1 shared Core This function is used to set the analog and digital power for ADC1...
Definition adc1.c:423
static void ADC1_IndividualChannelInterruptEnable(enum ADC_CHANNEL channel)
This inline function enables individual channel interrupt.
Definition adc1.h:336
void ADC1_Tasks(void)
This function is used to implement the tasks for polled implementations.
Definition adc1.c:499
ADC_CMP
Defines the ADC comparators that are available for the module to use.
Definition adc_types.h:105
static void ADC1_Enable(void)
This inline function enables the ADC1 module.
Definition adc1.h:109
void ADC1_ComparatorCallbackRegister(void(*callback)(enum ADC_CMP comparator))
This function can be used to override default callback and to define custom callback for ADC1_Compara...
Definition adc1.c:649
const struct ADC_INTERFACE ADC1
Structure object of type ADC_INTERFACE with the custom name given by the user in the Melody Driver Us...
Definition adc1.c:67
static void ADC1_InterruptEnable(void)
This inline function enables the ADC1 interrupt.
Definition adc1.h:260
static void ADC1_InterruptPrioritySet(uint16_t priorityValue)
This inline function allows selection of priority for interrupt.
Definition adc1.h:293
static void ADC1_IndividualChannelInterruptFlagClear(enum ADC_CHANNEL channel)
This inline function clears individual channel interrupt flag.
Definition adc1.h:398
void ADC1_ChannelTasks(enum ADC_CHANNEL channel)
This function call used only in polling mode, if channel conversion is done for requested channel,...
Definition adc1.c:590
void ADC1_ChannelCallback(enum ADC_CHANNEL channel, uint16_t adcVal)
This is the default callback function for all the analog channels. This callback is triggered once th...
Definition adc1.c:521
static void ADC1_SoftwareTriggerDisable(void)
This inline function resets software common trigger.
Definition adc1.h:148
ADC_DEDICATED_CORE
Defines the ADC cores that are available for the module to use.
Definition adc_types.h:76
static void ADC1_Disable(void)
This inline function disables the ADC1 module.
Definition adc1.h:122
void ADC1_Initialize(void)
Initializes ADC1 module, using the given initialization data This function must be called before any ...
Definition adc1.c:89
static void ADC1_InterruptDisable(void)
This inline function disables the ADC1 interrupt.
Definition adc1.h:271
static void ADC1_ChannelSelect(enum ADC_CHANNEL channel)
This inline function allows selection of a channel for conversion.
Definition adc1.h:161
static void ADC1_SoftwareTriggerEnable(void)
This inline function sets software common trigger.
Definition adc1.h:135
ADC_CHANNEL
Defines the ADC channles that are selected from the MCC Melody User Interface for the ADC conversions...
Definition adc_types.h:56
void ADC1_CommonCallbackRegister(void(*callback)(void))
This function can be used to override default callback and to define custom callback for ADC1 Common ...
Definition adc1.c:432
void ADC1_CorePowerEnable(enum ADC_DEDICATED_CORE core)
Enables analog and digital power for ADC1 dedicated core.
Definition adc1.c:399
static uint16_t ADC1_ConversionResultGet(enum ADC_CHANNEL channel)
Returns the conversion value for the channel selected.
Definition adc1.h:179
void ADC1_ChannelCallbackRegister(void(*callback)(enum ADC_CHANNEL channel, uint16_t adcVal))
This function can be used to override default callback ADC1_ChannelCallback and to define custom call...
Definition adc1.c:513
Structure containing the function pointers of ADC driver.
void(* Initialize)(void)
Pointer to ADCx_Initialize e.g. ADC1_Initialize.
Structure containing the function pointers of ADC driver.
void(* ChannelTasks)(enum ADC_CHANNEL channel)
Pointer to ADCx_ChannelTasks e.g. ADC1_ChannelTasks.