Bar Logo 4kW dsPIC33C PSFB DC-DC DA (Part-No. )
 
Content
     
Loading...
Searching...
No Matches
adc1.c
Go to the documentation of this file.
1
17/*
18© [2025] 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
73
74//Defines an object for ADC_MULTICORE.
76 .ChannelTasks = &ADC1_ChannelTasks,
77 .ComparatorTasks = NULL,
78 .IndividualChannelInterruptEnable = &ADC1_IndividualChannelInterruptEnable,
79 .IndividualChannelInterruptDisable = &ADC1_IndividualChannelInterruptDisable,
80 .IndividualChannelInterruptFlagClear = &ADC1_IndividualChannelInterruptFlagClear,
81 .IndividualChannelInterruptPrioritySet = &ADC1_IndividualChannelInterruptPrioritySet,
82 .ChannelCallbackRegister = &ADC1_ChannelCallbackRegister,
83 .ComparatorCallbackRegister = &ADC1_ComparatorCallbackRegister,
84 .CorePowerEnable = &ADC1_CorePowerEnable,
85 .SharedCorePowerEnable = &ADC1_SharedCorePowerEnable,
86 .PWMTriggerSourceSet = &ADC1_PWMTriggerSourceSet
87};
88
89//Defines an object for ADC_INTERFACE.
90
91const struct ADC_INTERFACE ADC1 = {
92 .Initialize = &ADC1_Initialize,
93 .Deinitialize = &ADC1_Deinitialize,
94 .Enable = &ADC1_Enable,
95 .Disable = &ADC1_Disable,
96 .SoftwareTriggerEnable = &ADC1_SoftwareTriggerEnable,
97 .SoftwareTriggerDisable = &ADC1_SoftwareTriggerDisable,
98 .ChannelSelect = &ADC1_ChannelSelect,
99 .ConversionResultGet = &ADC1_ConversionResultGet,
100 .IsConversionComplete = &ADC1_IsConversionComplete,
101 .ResolutionSet = &ADC1_ResolutionSet,
102 .InterruptEnable = &ADC1_InterruptEnable,
103 .InterruptDisable = &ADC1_InterruptDisable,
104 .InterruptFlagClear = &ADC1_InterruptFlagClear,
105 .InterruptPrioritySet = &ADC1_InterruptPrioritySet,
106 .CommonCallbackRegister = &ADC1_CommonCallbackRegister,
107 .Tasks = &ADC1_Tasks,
108 .adcMulticoreInterface = &adc1Multicore,
109};
110
111// Section: Driver Interface Function Definitions
112
114{
115 // ADSIDL disabled; ADON enabled;
116 ADCON1L = (uint16_t)0x8000 & (uint16_t)0x7FFF; //Disabling ADON bit
117 // SHRRES 12-bit resolution; FORM Integer;
118 ADCON1H = 0x60;
119 // SHRADCS 2; SHREISEL Early interrupt is generated 1 TADCORE clock prior to data being ready; PTGEN disabled; EIEN disabled; REFERCIE disabled; REFCIE disabled;
120 ADCON2L = 0x0;
121 // SHRSAMC 0;
122 ADCON2H = 0x0;
123 // CNVCHSEL AN0; SWCTRG disabled; SWLCTRG disabled; SHRSAMP disabled; SUSPCIE disabled; SUSPEND disabled; REFSEL disabled;
124 ADCON3L = 0x0;
125 // C0EN enabled; C1EN enabled; SHREN enabled; CLKDIV 4; CLKSEL AFVCODIV;
126 ADCON3H = (uint16_t)0x8383 & (uint16_t)0xFF00; //Disabling C0EN, C1EN, C2EN, C3EN and SHREN bits
127 // SAMC0EN enabled; SAMC1EN enabled;
128 ADCON4L = 0x3;
129 // C0CHS ANA0; C1CHS ANA1;
130 ADCON4H = 0x5;
131 // SIGN0 disabled; DIFF0 disabled; SIGN1 disabled; DIFF1 disabled; SIGN2 disabled; DIFF2 disabled; SIGN3 disabled; DIFF3 disabled; SIGN4 disabled; DIFF4 disabled; SIGN5 disabled; DIFF5 disabled; SIGN6 disabled; DIFF6 disabled; SIGN7 disabled; DIFF7 disabled;
132 ADMOD0L = 0x0;
133 // SIGN8 disabled; DIFF8 disabled; SIGN9 disabled; DIFF9 disabled; SIGN10 disabled; DIFF10 disabled; SIGN11 disabled; DIFF11 disabled; SIGN12 disabled; DIFF12 disabled; SIGN13 disabled; DIFF13 disabled; SIGN14 disabled; DIFF14 disabled; SIGN15 disabled; DIFF15 disabled;
134 ADMOD0H = 0x0;
135 // SIGN16 disabled; DIFF16 disabled; SIGN17 disabled; DIFF17 disabled; SIGN18 disabled; DIFF18 disabled; SIGN19 disabled; DIFF19 disabled;
136 ADMOD1L = 0x0;
137 // SIGN24 disabled; DIFF24 disabled; SIGN25 disabled; DIFF25 disabled;
138 ADMOD1H = 0x0;
139 // IE0 enabled; IE1 disabled; 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;
140 ADIEL = 0x1;
141 // IE16 disabled; IE17 disabled; IE18 disabled; IE19 disabled; IE24 disabled; IE25 disabled;
142 ADIEH = 0x0;
143 //
144 ADSTATL = 0x0;
145 //
146 ADSTATH = 0x0;
147 // 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;
148 ADCMP0ENL = 0x0;
149 // 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;
150 ADCMP1ENL = 0x0;
151 // 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;
152 ADCMP2ENL = 0x0;
153 // 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;
154 ADCMP3ENL = 0x0;
155 // CMPEN16 disabled; CMPEN17 disabled; CMPEN18 disabled; CMPEN19 disabled; CMPEN24 disabled; CMPEN25 disabled;
156 ADCMP0ENH = 0x0;
157 // CMPEN16 disabled; CMPEN17 disabled; CMPEN18 disabled; CMPEN19 disabled; CMPEN24 disabled; CMPEN25 disabled;
158 ADCMP1ENH = 0x0;
159 // CMPEN16 disabled; CMPEN17 disabled; CMPEN18 disabled; CMPEN19 disabled; CMPEN24 disabled; CMPEN25 disabled;
160 ADCMP2ENH = 0x0;
161 // CMPEN16 disabled; CMPEN17 disabled; CMPEN18 disabled; CMPEN19 disabled; CMPEN24 disabled; CMPEN25 disabled;
162 ADCMP3ENH = 0x0;
163 // CMPLO 0x0;
164 ADCMP0LO = 0x0;
165 // CMPLO 0x0;
166 ADCMP1LO = 0x0;
167 // CMPLO 0x0;
168 ADCMP2LO = 0x0;
169 // CMPLO 0x0;
170 ADCMP3LO = 0x0;
171 // CMPHI 0x0;
172 ADCMP0HI = 0x0;
173 // CMPHI 0x0;
174 ADCMP1HI = 0x0;
175 // CMPHI 0x0;
176 ADCMP2HI = 0x0;
177 // CMPHI 0x0;
178 ADCMP3HI = 0x0;
179 //
180 ADFL0DAT = 0x0;
181 //
182 ADFL1DAT = 0x0;
183 //
184 ADFL2DAT = 0x0;
185 //
186 ADFL3DAT = 0x0;
187 // FLCHSEL AN0; IE disabled; OVRSAM 4x; MODE Oversampling Mode; FLEN disabled;
188 ADFL0CON = 0x400;
189 // FLCHSEL AN0; IE disabled; OVRSAM 4x; MODE Oversampling Mode; FLEN disabled;
190 ADFL1CON = 0x400;
191 // FLCHSEL AN0; IE disabled; OVRSAM 4x; MODE Oversampling Mode; FLEN disabled;
192 ADFL2CON = 0x400;
193 // FLCHSEL AN0; IE disabled; OVRSAM 4x; MODE Oversampling Mode; FLEN disabled;
194 ADFL3CON = 0x400;
195 // LOLO disabled; LOHI disabled; HILO disabled; HIHI disabled; BTWN disabled; IE disabled; CMPEN disabled;
196 ADCMP0CON = 0x0;
197 // LOLO disabled; LOHI disabled; HILO disabled; HIHI disabled; BTWN disabled; IE disabled; CMPEN disabled;
198 ADCMP1CON = 0x0;
199 // LOLO disabled; LOHI disabled; HILO disabled; HIHI disabled; BTWN disabled; IE disabled; CMPEN disabled;
200 ADCMP2CON = 0x0;
201 // LOLO disabled; LOHI disabled; HILO disabled; HIHI disabled; BTWN disabled; IE disabled; CMPEN disabled;
202 ADCMP3CON = 0x0;
203 // 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;
204 ADLVLTRGL = 0x0;
205 // LVLEN16 disabled; LVLEN17 disabled; LVLEN18 disabled; LVLEN19 disabled; LVLEN24 disabled; LVLEN25 disabled;
206 ADLVLTRGH = 0x0;
207 // SAMC 0;
208 ADCORE0L = 0x0;
209 // SAMC 0;
210 ADCORE1L = 0x0;
211 // ADCS 2; RES 12-bit resolution; EISEL Early interrupt is generated 1 TADCORE clock prior to data being ready;
212 ADCORE0H = 0x300;
213 // ADCS 2; RES 12-bit resolution; EISEL Early interrupt is generated 1 TADCORE clock prior to data being ready;
214 ADCORE1H = 0x300;
215 // 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;
216 ADEIEL = 0x0;
217 // EIEN16 disabled; EIEN17 disabled; EIEN18 disabled; EIEN19 disabled; EIEN24 disabled; EIEN25 disabled;
218 ADEIEH = 0x0;
219 // 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;
220 ADEISTATL = 0x0;
221 // EISTAT16 disabled; EISTAT17 disabled; EISTAT18 disabled; EISTAT19 disabled; EISTAT24 disabled; EISTAT25 disabled;
222 ADEISTATH = 0x0;
223 // C0CIE disabled; C1CIE disabled; SHRCIE disabled; WARMTIME 16 Source Clock Periods;
224 ADCON5H = (uint16_t)0x400 & (uint16_t)0xF0FF; //Disabling WARMTIME bit
225 //
226 ADCBUF0 = 0x0;
227 //
228 ADCBUF1 = 0x0;
229 //
230 ADCBUF2 = 0x0;
231 //
232 ADCBUF3 = 0x0;
233 //
234 ADCBUF4 = 0x0;
235 //
236 ADCBUF5 = 0x0;
237 //
238 ADCBUF6 = 0x0;
239 //
240 ADCBUF7 = 0x0;
241 //
242 ADCBUF8 = 0x0;
243 //
244 ADCBUF9 = 0x0;
245 //
246 ADCBUF10 = 0x0;
247 //
248 ADCBUF11 = 0x0;
249 //
250 ADCBUF12 = 0x0;
251 //
252 ADCBUF13 = 0x0;
253 //
254 ADCBUF14 = 0x0;
255 //
256 ADCBUF15 = 0x0;
257 //
258 ADCBUF16 = 0x0;
259 //
260 ADCBUF17 = 0x0;
261 //
262 ADCBUF18 = 0x0;
263 //
264 ADCBUF19 = 0x0;
265 //
266 ADCBUF24 = 0x0;
267 //
268 ADCBUF25 = 0x0;
269
273
274 // Clearing FB_P_CT_FILT interrupt flag.
275 IFS5bits.ADCAN0IF = 0;
276 // Enabling FB_P_CT_FILT interrupt.
277 IEC5bits.ADCAN0IE = 1;
278
279 // Setting WARMTIME bit
280 ADCON5Hbits.WARMTIME = 0xF;
281 // Enabling ADC Module
282 ADCON1Lbits.ADON = 0x1;
283 // Enabling Power for Core0
285 // Enabling Power for Core1
287 // Enabling Power for the Shared Core
289
290 //TRGSRC0 PWM1 Trigger2; TRGSRC1 PWM1 Trigger2;
291 ADTRIG0L = 0x505;
292 //TRGSRC2 PWM1 Trigger2; TRGSRC3 None;
293 ADTRIG0H = 0x5;
294 //TRGSRC4 None; TRGSRC5 None;
295 ADTRIG1L = 0x0;
296 //TRGSRC6 None; TRGSRC7 None;
297 ADTRIG1H = 0x0;
298 //TRGSRC8 None; TRGSRC9 Common Software Trigger;
299 ADTRIG2L = 0x100;
300 //TRGSRC10 Common Software Trigger; TRGSRC11 None;
301 ADTRIG2H = 0x1;
302 //TRGSRC12 None; TRGSRC13 None;
303 ADTRIG3L = 0x0;
304 //TRGSRC14 Common Software Trigger; TRGSRC15 Common Software Trigger;
305 ADTRIG3H = 0x101;
306 //TRGSRC16 None; TRGSRC17 None;
307 ADTRIG4L = 0x0;
308 //TRGSRC18 None; TRGSRC19 Common Software Trigger;
309 ADTRIG4H = 0x100;
310 //TRGSRC24 None; TRGSRC25 None;
311 ADTRIG6L = 0x0;
312}
313
315{
316 uint16_t dummy; //buffers has to be read before clearing interrupt flags
317 ADCON1Lbits.ADON = 0;
318
319 dummy = ADCBUF0;
320 IFS5bits.ADCAN0IF = 0;
321 IEC5bits.ADCAN0IE = 0;
322
323 ADCON1L = 0x0;
324 ADCON1H = 0x60;
325 ADCON2L = 0x0;
326 ADCON2H = 0x0;
327 ADCON3L = 0x0;
328 ADCON3H = 0x0;
329 ADCON4L = 0x0;
330 ADCON4H = 0x0;
331 ADMOD0L = 0x0;
332 ADMOD0H = 0x0;
333 ADMOD1L = 0x0;
334 ADMOD1H = 0x0;
335 ADIEL = 0x0;
336 ADIEH = 0x0;
337 ADSTATL = 0x0;
338 ADSTATH = 0x0;
339 ADCMP0ENL = 0x0;
340 ADCMP1ENL = 0x0;
341 ADCMP2ENL = 0x0;
342 ADCMP3ENL = 0x0;
343 ADCMP0ENH = 0x0;
344 ADCMP1ENH = 0x0;
345 ADCMP2ENH = 0x0;
346 ADCMP3ENH = 0x0;
347 ADCMP0LO = 0x0;
348 ADCMP1LO = 0x0;
349 ADCMP2LO = 0x0;
350 ADCMP3LO = 0x0;
351 ADCMP0HI = 0x0;
352 ADCMP1HI = 0x0;
353 ADCMP2HI = 0x0;
354 ADCMP3HI = 0x0;
355 ADFL0DAT = 0x0;
356 ADFL1DAT = 0x0;
357 ADFL2DAT = 0x0;
358 ADFL3DAT = 0x0;
359 ADFL0CON = 0x0;
360 ADFL1CON = 0x0;
361 ADFL2CON = 0x0;
362 ADFL3CON = 0x0;
363 ADTRIG0L = 0x0;
364 ADTRIG0H = 0x0;
365 ADTRIG1L = 0x0;
366 ADTRIG1H = 0x0;
367 ADTRIG2L = 0x0;
368 ADTRIG2H = 0x0;
369 ADTRIG3L = 0x0;
370 ADTRIG3H = 0x0;
371 ADTRIG4L = 0x0;
372 ADTRIG4H = 0x0;
373 ADTRIG6L = 0x0;
374 ADCMP0CON = 0x0;
375 ADCMP1CON = 0x0;
376 ADCMP2CON = 0x0;
377 ADCMP3CON = 0x0;
378 ADLVLTRGL = 0x0;
379 ADLVLTRGH = 0x0;
380 ADCORE0L = 0x0;
381 ADCORE1L = 0x0;
382 ADCORE0H = 0x300;
383 ADCORE1H = 0x300;
384 ADEIEL = 0x0;
385 ADEIEH = 0x0;
386 ADEISTATL = 0x0;
387 ADEISTATH = 0x0;
388 ADCON5L = 0x0;
389 ADCON5H = 0x0;
390 ADCBUF0 = 0x0;
391 ADCBUF1 = 0x0;
392 ADCBUF2 = 0x0;
393 ADCBUF3 = 0x0;
394 ADCBUF4 = 0x0;
395 ADCBUF5 = 0x0;
396 ADCBUF6 = 0x0;
397 ADCBUF7 = 0x0;
398 ADCBUF8 = 0x0;
399 ADCBUF9 = 0x0;
400 ADCBUF10 = 0x0;
401 ADCBUF11 = 0x0;
402 ADCBUF12 = 0x0;
403 ADCBUF13 = 0x0;
404 ADCBUF14 = 0x0;
405 ADCBUF15 = 0x0;
406 ADCBUF16 = 0x0;
407 ADCBUF17 = 0x0;
408 ADCBUF18 = 0x0;
409 ADCBUF19 = 0x0;
410 ADCBUF24 = 0x0;
411 ADCBUF25 = 0x0;
412}
413
415{
416 switch(core)
417 {
418 case ADC_CORE_0:
419 ADCON5Lbits.C0PWR = 1;
420 while(ADCON5Lbits.C0RDY == 0)
421 {
422 }
423 ADCON3Hbits.C0EN = 1;
424 break;
425 case ADC_CORE_1:
426 ADCON5Lbits.C1PWR = 1;
427 while(ADCON5Lbits.C1RDY == 0)
428 {
429 }
430 ADCON3Hbits.C1EN = 1;
431 break;
432 default:
433 break;
434 }
435}
436
437
439{
440 ADCON5Lbits.SHRPWR = 1;
441 while(ADCON5Lbits.SHRRDY == 0)
442 {
443 }
444 ADCON3Hbits.SHREN = 1;
445}
446
447static uint16_t ADC1_TriggerSourceValueGet(enum ADC_PWM_INSTANCE pwmInstance, enum ADC_PWM_TRIGGERS triggerNumber)
448{
449 uint16_t adcTriggerSourceValue = 0x0U;
450 switch(pwmInstance)
451 {
453 if(triggerNumber == ADC_PWM_TRIGGER_1)
454 {
455 adcTriggerSourceValue = PWM8_TRIGGER1;
456 }
457 else if(triggerNumber == ADC_PWM_TRIGGER_2)
458 {
459 adcTriggerSourceValue = PWM8_TRIGGER2;
460 }
461 break;
463 if(triggerNumber == ADC_PWM_TRIGGER_1)
464 {
465 adcTriggerSourceValue = PWM7_TRIGGER1;
466 }
467 else if(triggerNumber == ADC_PWM_TRIGGER_2)
468 {
469 adcTriggerSourceValue = PWM7_TRIGGER2;
470 }
471 break;
473 if(triggerNumber == ADC_PWM_TRIGGER_1)
474 {
475 adcTriggerSourceValue = PWM6_TRIGGER1;
476 }
477 else if(triggerNumber == ADC_PWM_TRIGGER_2)
478 {
479 adcTriggerSourceValue = PWM6_TRIGGER2;
480 }
481 break;
483 if(triggerNumber == ADC_PWM_TRIGGER_1)
484 {
485 adcTriggerSourceValue = PWM5_TRIGGER1;
486 }
487 else if(triggerNumber == ADC_PWM_TRIGGER_2)
488 {
489 adcTriggerSourceValue = PWM5_TRIGGER2;
490 }
491 break;
493 if(triggerNumber == ADC_PWM_TRIGGER_1)
494 {
495 adcTriggerSourceValue = PWM4_TRIGGER1;
496 }
497 else if(triggerNumber == ADC_PWM_TRIGGER_2)
498 {
499 adcTriggerSourceValue = PWM4_TRIGGER2;
500 }
501 break;
503 if(triggerNumber == ADC_PWM_TRIGGER_1)
504 {
505 adcTriggerSourceValue = PWM3_TRIGGER1;
506 }
507 else if(triggerNumber == ADC_PWM_TRIGGER_2)
508 {
509 adcTriggerSourceValue = PWM3_TRIGGER2;
510 }
511 break;
513 if(triggerNumber == ADC_PWM_TRIGGER_1)
514 {
515 adcTriggerSourceValue = PWM2_TRIGGER1;
516 }
517 else if(triggerNumber == ADC_PWM_TRIGGER_2)
518 {
519 adcTriggerSourceValue = PWM2_TRIGGER2;
520 }
521 break;
523 if(triggerNumber == ADC_PWM_TRIGGER_1)
524 {
525 adcTriggerSourceValue = PWM1_TRIGGER1;
526 }
527 else if(triggerNumber == ADC_PWM_TRIGGER_2)
528 {
529 adcTriggerSourceValue = PWM1_TRIGGER2;
530 }
531 break;
532 default:
533 break;
534 }
535 return adcTriggerSourceValue;
536}
537
538void ADC1_PWMTriggerSourceSet(enum ADC_CHANNEL channel, enum ADC_PWM_INSTANCE pwmInstance, enum ADC_PWM_TRIGGERS triggerNumber)
539{
540 uint16_t adcTriggerValue;
541 adcTriggerValue= ADC1_TriggerSourceValueGet(pwmInstance, triggerNumber);
542 switch(channel)
543 {
544 case FB_VOUT:
545 ADTRIG0Hbits.TRGSRC2 = adcTriggerValue;
546 break;
547 case FB_VCAP:
548 ADTRIG2Lbits.TRGSRC9 = adcTriggerValue;
549 break;
550 case VIN_INT_AN:
551 ADTRIG2Hbits.TRGSRC10 = adcTriggerValue;
552 break;
553 case FB_TEMP:
554 ADTRIG3Hbits.TRGSRC14 = adcTriggerValue;
555 break;
556 case Channel_AN15:
557 ADTRIG3Hbits.TRGSRC15 = adcTriggerValue;
558 break;
559 case FB_5V:
560 ADTRIG4Hbits.TRGSRC19 = adcTriggerValue;
561 break;
562 case FB_P_CT_FILT:
563 ADTRIG0Lbits.TRGSRC0 = adcTriggerValue;
564 break;
565 case I_SEC_AVG_FILT:
566 ADTRIG0Lbits.TRGSRC1 = adcTriggerValue;
567 break;
568 default:
569 break;
570 }
571}
572
573void ADC1_CommonCallbackRegister(void(*callback)(void))
574{
575 if(NULL != callback)
576 {
577 ADC1_CommonHandler = callback;
578 }
579}
580
582{
583
584}
585
586
587void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCInterrupt ( void )
588{
589 uint16_t adcVal;
590 if(NULL != ADC1_CommonHandler)
591 {
592 (*ADC1_CommonHandler)();
593 }
594
595 if(IFS5bits.ADCAN2IF == 1)
596 {
597 //Read the ADC value from the ADCBUF before clearing interrupt
598 adcVal = ADCBUF2;
599 if(NULL != ADC1_ChannelHandler)
600 {
601 (*ADC1_ChannelHandler)(FB_VOUT, adcVal);
602 }
603 IFS5bits.ADCAN2IF = 0;
604 }
605 if(IFS6bits.ADCAN9IF == 1)
606 {
607 //Read the ADC value from the ADCBUF before clearing interrupt
608 adcVal = ADCBUF9;
609 if(NULL != ADC1_ChannelHandler)
610 {
611 (*ADC1_ChannelHandler)(FB_VCAP, adcVal);
612 }
613 IFS6bits.ADCAN9IF = 0;
614 }
615 if(IFS6bits.ADCAN10IF == 1)
616 {
617 //Read the ADC value from the ADCBUF before clearing interrupt
618 adcVal = ADCBUF10;
619 if(NULL != ADC1_ChannelHandler)
620 {
621 (*ADC1_ChannelHandler)(VIN_INT_AN, adcVal);
622 }
623 IFS6bits.ADCAN10IF = 0;
624 }
625 if(IFS6bits.ADCAN14IF == 1)
626 {
627 //Read the ADC value from the ADCBUF before clearing interrupt
628 adcVal = ADCBUF14;
629 if(NULL != ADC1_ChannelHandler)
630 {
631 (*ADC1_ChannelHandler)(FB_TEMP, adcVal);
632 }
633 IFS6bits.ADCAN14IF = 0;
634 }
635 if(IFS6bits.ADCAN15IF == 1)
636 {
637 //Read the ADC value from the ADCBUF before clearing interrupt
638 adcVal = ADCBUF15;
639 if(NULL != ADC1_ChannelHandler)
640 {
641 (*ADC1_ChannelHandler)(Channel_AN15, adcVal);
642 }
643 IFS6bits.ADCAN15IF = 0;
644 }
645 if(IFS6bits.ADCAN19IF == 1)
646 {
647 //Read the ADC value from the ADCBUF before clearing interrupt
648 adcVal = ADCBUF19;
649 if(NULL != ADC1_ChannelHandler)
650 {
651 (*ADC1_ChannelHandler)(FB_5V, adcVal);
652 }
653 IFS6bits.ADCAN19IF = 0;
654 }
655 if(IFS5bits.ADCAN0IF == 1)
656 {
657 //Read the ADC value from the ADCBUF before clearing interrupt
658 adcVal = ADCBUF0;
659 if(NULL != ADC1_ChannelHandler)
660 {
661 (*ADC1_ChannelHandler)(FB_P_CT_FILT, adcVal);
662 }
663 IFS5bits.ADCAN0IF = 0;
664 }
665 if(IFS5bits.ADCAN1IF == 1)
666 {
667 //Read the ADC value from the ADCBUF before clearing interrupt
668 adcVal = ADCBUF1;
669 if(NULL != ADC1_ChannelHandler)
670 {
671 (*ADC1_ChannelHandler)(I_SEC_AVG_FILT, adcVal);
672 }
673 IFS5bits.ADCAN1IF = 0;
674 }
675
676 // clear the ADC1 interrupt flag
677 IFS5bits.ADCIF = 0;
678}
679
680void __attribute__ ((weak)) ADC1_Tasks ( void )
681{
682 if(IFS5bits.ADCIF == 1)
683 {
684 if(NULL != ADC1_CommonHandler)
685 {
686 (*ADC1_CommonHandler)();
687 }
688
689 // clear the ADC1 interrupt flag
690 IFS5bits.ADCIF = 0;
691 }
692}
693
694void ADC1_ChannelCallbackRegister(void(*callback)(enum ADC_CHANNEL channel, uint16_t adcVal))
695{
696 if(NULL != callback)
697 {
698 ADC1_ChannelHandler = callback;
699 }
700}
701
702void __attribute__ ((weak)) ADC1_ChannelCallback (enum ADC_CHANNEL channel, uint16_t adcVal)
703{
704 (void)channel;
705 (void)adcVal;
706}
707
708
709void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCAN2Interrupt ( void )
710{
711 uint16_t valFB_VOUT;
712 //Read the ADC value from the ADCBUF
713 valFB_VOUT = ADCBUF2;
714
715 if(NULL != ADC1_ChannelHandler)
716 {
717 (*ADC1_ChannelHandler)(FB_VOUT, valFB_VOUT);
718 }
719
720 //clear the FB_VOUT interrupt flag
721 IFS5bits.ADCAN2IF = 0;
722}
723
724void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCAN9Interrupt ( void )
725{
726 uint16_t valFB_VCAP;
727 //Read the ADC value from the ADCBUF
728 valFB_VCAP = ADCBUF9;
729
730 if(NULL != ADC1_ChannelHandler)
731 {
732 (*ADC1_ChannelHandler)(FB_VCAP, valFB_VCAP);
733 }
734
735 //clear the FB_VCAP interrupt flag
736 IFS6bits.ADCAN9IF = 0;
737}
738
739void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCAN10Interrupt ( void )
740{
741 uint16_t valVIN_INT_AN;
742 //Read the ADC value from the ADCBUF
743 valVIN_INT_AN = ADCBUF10;
744
745 if(NULL != ADC1_ChannelHandler)
746 {
747 (*ADC1_ChannelHandler)(VIN_INT_AN, valVIN_INT_AN);
748 }
749
750 //clear the VIN_INT_AN interrupt flag
751 IFS6bits.ADCAN10IF = 0;
752}
753
754void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCAN14Interrupt ( void )
755{
756 uint16_t valFB_TEMP;
757 //Read the ADC value from the ADCBUF
758 valFB_TEMP = ADCBUF14;
759
760 if(NULL != ADC1_ChannelHandler)
761 {
762 (*ADC1_ChannelHandler)(FB_TEMP, valFB_TEMP);
763 }
764
765 //clear the FB_TEMP interrupt flag
766 IFS6bits.ADCAN14IF = 0;
767}
768
769void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCAN15Interrupt ( void )
770{
771 uint16_t valChannel_AN15;
772 //Read the ADC value from the ADCBUF
773 valChannel_AN15 = ADCBUF15;
774
775 if(NULL != ADC1_ChannelHandler)
776 {
777 (*ADC1_ChannelHandler)(Channel_AN15, valChannel_AN15);
778 }
779
780 //clear the Channel_AN15 interrupt flag
781 IFS6bits.ADCAN15IF = 0;
782}
783
784void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCAN19Interrupt ( void )
785{
786 uint16_t valFB_5V;
787 //Read the ADC value from the ADCBUF
788 valFB_5V = ADCBUF19;
789
790 if(NULL != ADC1_ChannelHandler)
791 {
792 (*ADC1_ChannelHandler)(FB_5V, valFB_5V);
793 }
794
795 //clear the FB_5V interrupt flag
796 IFS6bits.ADCAN19IF = 0;
797}
798
799
800void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCAN0Interrupt ( void )
801{
802 uint16_t valFB_P_CT_FILT;
803 //Read the ADC value from the ADCBUF
804 valFB_P_CT_FILT = ADCBUF0;
805
806 if(NULL != ADC1_ChannelHandler)
807 {
808 (*ADC1_ChannelHandler)(FB_P_CT_FILT, valFB_P_CT_FILT);
809 }
810
811 //clear the FB_P_CT_FILT interrupt flag
812 IFS5bits.ADCAN0IF = 0;
813}
814
815void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCAN1Interrupt ( void )
816{
817 uint16_t valI_SEC_AVG_FILT;
818 //Read the ADC value from the ADCBUF
819 valI_SEC_AVG_FILT = ADCBUF1;
820
821 if(NULL != ADC1_ChannelHandler)
822 {
823 (*ADC1_ChannelHandler)(I_SEC_AVG_FILT, valI_SEC_AVG_FILT);
824 }
825
826 //clear the I_SEC_AVG_FILT interrupt flag
827 IFS5bits.ADCAN1IF = 0;
828}
829
830
831void __attribute__ ((weak)) ADC1_ChannelTasks (enum ADC_CHANNEL channel)
832{
833 uint16_t adcVal;
834
835 switch(channel)
836 {
837 case FB_VOUT:
838 if((bool)ADSTATLbits.AN2RDY == 1)
839 {
840 //Read the ADC value from the ADCBUF
841 adcVal = ADCBUF2;
842
843 if(NULL != ADC1_ChannelHandler)
844 {
845 (*ADC1_ChannelHandler)(channel, adcVal);
846 }
847 }
848 break;
849 case FB_VCAP:
850 if((bool)ADSTATLbits.AN9RDY == 1)
851 {
852 //Read the ADC value from the ADCBUF
853 adcVal = ADCBUF9;
854
855 if(NULL != ADC1_ChannelHandler)
856 {
857 (*ADC1_ChannelHandler)(channel, adcVal);
858 }
859 }
860 break;
861 case VIN_INT_AN:
862 if((bool)ADSTATLbits.AN10RDY == 1)
863 {
864 //Read the ADC value from the ADCBUF
865 adcVal = ADCBUF10;
866
867 if(NULL != ADC1_ChannelHandler)
868 {
869 (*ADC1_ChannelHandler)(channel, adcVal);
870 }
871 }
872 break;
873 case FB_TEMP:
874 if((bool)ADSTATLbits.AN14RDY == 1)
875 {
876 //Read the ADC value from the ADCBUF
877 adcVal = ADCBUF14;
878
879 if(NULL != ADC1_ChannelHandler)
880 {
881 (*ADC1_ChannelHandler)(channel, adcVal);
882 }
883 }
884 break;
885 case Channel_AN15:
886 if((bool)ADSTATLbits.AN15RDY == 1)
887 {
888 //Read the ADC value from the ADCBUF
889 adcVal = ADCBUF15;
890
891 if(NULL != ADC1_ChannelHandler)
892 {
893 (*ADC1_ChannelHandler)(channel, adcVal);
894 }
895 }
896 break;
897 case FB_5V:
898 if((bool)ADSTATHbits.AN19RDY == 1)
899 {
900 //Read the ADC value from the ADCBUF
901 adcVal = ADCBUF19;
902
903 if(NULL != ADC1_ChannelHandler)
904 {
905 (*ADC1_ChannelHandler)(channel, adcVal);
906 }
907 }
908 break;
909 case FB_P_CT_FILT:
910 if((bool)ADSTATLbits.AN0RDY == 1)
911 {
912 //Read the ADC value from the ADCBUF
913 adcVal = ADCBUF0;
914
915 if(NULL != ADC1_ChannelHandler)
916 {
917 (*ADC1_ChannelHandler)(channel, adcVal);
918 }
919 }
920 break;
921 case I_SEC_AVG_FILT:
922 if((bool)ADSTATLbits.AN1RDY == 1)
923 {
924 //Read the ADC value from the ADCBUF
925 adcVal = ADCBUF1;
926
927 if(NULL != ADC1_ChannelHandler)
928 {
929 (*ADC1_ChannelHandler)(channel, adcVal);
930 }
931 }
932 break;
933 default:
934 break;
935 }
936}
937
938void ADC1_ComparatorCallbackRegister(void(*callback)(enum ADC_CMP comparator))
939{
940 if(NULL != callback)
941 {
942 ADC1_ComparatorHandler = callback;
943 }
944}
945
946void __attribute__ ((weak)) ADC1_ComparatorCallback (enum ADC_CMP comparator)
947{
948 (void)comparator;
949}
950
951
952
This is the generated driver header file for the ADC1 driver.
@ ADC_PWM_TRIGGER_1
Definition adc_types.h:140
@ ADC_PWM_TRIGGER_2
Definition adc_types.h:141
@ ADC_PWM_GENERATOR_2
Definition adc_types.h:129
@ ADC_PWM_GENERATOR_4
Definition adc_types.h:127
@ ADC_PWM_GENERATOR_5
Definition adc_types.h:126
@ ADC_PWM_GENERATOR_7
Definition adc_types.h:124
@ ADC_PWM_GENERATOR_1
Definition adc_types.h:130
@ ADC_PWM_GENERATOR_8
Definition adc_types.h:123
@ ADC_PWM_GENERATOR_3
Definition adc_types.h:128
@ ADC_PWM_GENERATOR_6
Definition adc_types.h:125
@ ADC_CORE_1
Definition adc_types.h:84
@ ADC_CORE_0
Definition adc_types.h:82
@ Channel_AN15
Definition adc_types.h:61
@ FB_TEMP
Definition adc_types.h:60
@ FB_P_CT_FILT
Definition adc_types.h:63
@ FB_VOUT
Definition adc_types.h:57
@ I_SEC_AVG_FILT
Definition adc_types.h:64
@ FB_5V
Definition adc_types.h:62
@ VIN_INT_AN
Definition adc_types.h:59
@ FB_VCAP
Definition adc_types.h:58
void __attribute__((weak))
Definition adc1.c:581
static void(* ADC1_ComparatorHandler)(enum ADC_CMP comparator)
Definition adc1.c:46
static void(* ADC1_CommonHandler)(void)
Definition adc1.c:44
const struct ADC_MULTICORE adc1Multicore
Definition adc1.c:75
static uint16_t ADC1_TriggerSourceValueGet(enum ADC_PWM_INSTANCE pwmInstance, enum ADC_PWM_TRIGGERS triggerNumber)
Definition adc1.c:447
static void(* ADC1_ChannelHandler)(enum ADC_CHANNEL channel, uint16_t adcVal)
Definition adc1.c:45
@ PWM7_TRIGGER2
Definition adc1.c:58
@ PWM2_TRIGGER1
Definition adc1.c:69
@ PWM3_TRIGGER2
Definition adc1.c:66
@ PWM6_TRIGGER1
Definition adc1.c:61
@ PWM2_TRIGGER2
Definition adc1.c:68
@ PWM8_TRIGGER1
Definition adc1.c:57
@ PWM5_TRIGGER1
Definition adc1.c:63
@ PWM8_TRIGGER2
Definition adc1.c:56
@ PWM1_TRIGGER1
Definition adc1.c:71
@ PWM3_TRIGGER1
Definition adc1.c:67
@ PWM4_TRIGGER2
Definition adc1.c:64
@ PWM4_TRIGGER1
Definition adc1.c:65
@ PWM5_TRIGGER2
Definition adc1.c:62
@ PWM1_TRIGGER2
Definition adc1.c:70
@ PWM7_TRIGGER1
Definition adc1.c:59
@ PWM6_TRIGGER2
Definition adc1.c:60
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:226
static void ADC1_InterruptFlagClear(void)
Clears interrupt flag manually.
Definition adc1.h:305
ADC_PWM_TRIGGERS
Defines the PWM triggers that are available in each individual PWM.
Definition adc_types.h:139
void ADC1_CommonCallback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
ADC_PWM_TRIG_SRCS
Defines the PWM ADC TRIGGER sources available for the module to use.
Definition adc1.c:55
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:493
static void ADC1_ResolutionSet(enum ADC_RESOLUTION_TYPE resolution)
This inline function helps to configure all cores with same resolution.
Definition adc1.h:270
static void ADC1_IndividualChannelInterruptDisable(enum ADC_CHANNEL channel)
This inline function disables individual channel interrupt.
Definition adc1.h:406
void ADC1_ComparatorCallback(enum ADC_CMP comparator)
Comparator callback function.
void ADC1_Deinitialize(void)
Deinitializes the ADC1 to POR values.
Definition adc1.c:314
void ADC1_PWMTriggerSourceSet(enum ADC_CHANNEL channel, enum ADC_PWM_INSTANCE pwmInstance, enum ADC_PWM_TRIGGERS triggerNumber)
Sets PWM trigger source for corresponding analog input.
Definition adc1.c:538
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:438
static void ADC1_IndividualChannelInterruptEnable(enum ADC_CHANNEL channel)
This inline function enables individual channel interrupt.
Definition adc1.h:359
void ADC1_Tasks(void)
This function is used to implement the tasks for polled implementations.
ADC_CMP
Defines the ADC comparators that are available for the module to use.
Definition adc_types.h:109
static void ADC1_Enable(void)
This inline function enables the ADC1 module.
Definition adc1.h:108
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:938
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:91
static void ADC1_InterruptEnable(void)
This inline function enables the ADC1 interrupt.
Definition adc1.h:283
ADC_PWM_INSTANCE
Defines the ADC PWM trigger sources that are available for the module to use.
Definition adc_types.h:122
static void ADC1_InterruptPrioritySet(uint16_t priorityValue)
This inline function allows selection of priority for interrupt.
Definition adc1.h:316
static void ADC1_IndividualChannelInterruptFlagClear(enum ADC_CHANNEL channel)
This inline function clears individual channel interrupt flag.
Definition adc1.h:453
void ADC1_ChannelTasks(enum ADC_CHANNEL channel)
This function call used only in polling mode, if channel conversion is done for requested channel,...
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...
static void ADC1_SoftwareTriggerDisable(void)
This inline function resets software common trigger.
Definition adc1.h:147
ADC_DEDICATED_CORE
Defines the ADC cores that are available for the module to use.
Definition adc_types.h:80
static void ADC1_Disable(void)
This inline function disables the ADC1 module.
Definition adc1.h:121
void ADC1_Initialize(void)
Initializes ADC1 module, using the given initialization data This function must be called before any ...
Definition adc1.c:113
static void ADC1_InterruptDisable(void)
This inline function disables the ADC1 interrupt.
Definition adc1.h:294
static void ADC1_ChannelSelect(enum ADC_CHANNEL channel)
This inline function allows selection of a channel for conversion.
Definition adc1.h:160
static void ADC1_SoftwareTriggerEnable(void)
This inline function sets software common trigger.
Definition adc1.h:134
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:573
void ADC1_CorePowerEnable(enum ADC_DEDICATED_CORE core)
Enables analog and digital power for ADC1 dedicated core.
Definition adc1.c:414
static uint16_t ADC1_ConversionResultGet(enum ADC_CHANNEL channel)
Returns the conversion value for the channel selected.
Definition adc1.h:178
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:694
Structure containing the function pointers of ADC driver.
Structure containing the function pointers of ADC driver.