Bar Logo Dual Active Bridge Development Board (Part-No. )
 
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
73
74//Defines an object for ADC_MULTICORE.
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 = {
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 1; CLKSEL FOSC/2;
126 ADCON3H = (uint16_t)0x83 & (uint16_t)0xFF00; //Disabling C0EN, C1EN, C2EN, C3EN and SHREN bits
127 // SAMC0EN enabled; SAMC1EN enabled;
128 ADCON4L = 0x3;
129 // C0CHS AN0; C1CHS ANA1;
130 ADCON4H = 0x4;
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 disabled; 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 = 0x0;
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
275 // Setting WARMTIME bit
276 ADCON5Hbits.WARMTIME = 0xF;
277 // Enabling ADC Module
278 ADCON1Lbits.ADON = 0x1;
279 // Enabling Power for Core0
281 // Enabling Power for Core1
283 // Enabling Power for the Shared Core
285
286 //TRGSRC0 Common Software Trigger; TRGSRC1 Common Software Trigger;
287 ADTRIG0L = 0x101;
288 //TRGSRC2 Common Software Trigger; TRGSRC3 None;
289 ADTRIG0H = 0x1;
290 //TRGSRC4 None; TRGSRC5 None;
291 ADTRIG1L = 0x0;
292 //TRGSRC6 None; TRGSRC7 Common Software Trigger;
293 ADTRIG1H = 0x100;
294 //TRGSRC8 None; TRGSRC9 None;
295 ADTRIG2L = 0x0;
296 //TRGSRC10 Common Software Trigger; TRGSRC11 None;
297 ADTRIG2H = 0x1;
298 //TRGSRC12 None; TRGSRC13 None;
299 ADTRIG3L = 0x0;
300 //TRGSRC14 Common Software Trigger; TRGSRC15 None;
301 ADTRIG3H = 0x1;
302 //TRGSRC16 None; TRGSRC17 None;
303 ADTRIG4L = 0x0;
304 //TRGSRC18 None; TRGSRC19 Common Software Trigger;
305 ADTRIG4H = 0x100;
306 //TRGSRC24 None; TRGSRC25 None;
307 ADTRIG6L = 0x0;
308}
309
311{
312 ADCON1Lbits.ADON = 0;
313
314 ADCON1L = 0x0;
315 ADCON1H = 0x60;
316 ADCON2L = 0x0;
317 ADCON2H = 0x0;
318 ADCON3L = 0x0;
319 ADCON3H = 0x0;
320 ADCON4L = 0x0;
321 ADCON4H = 0x0;
322 ADMOD0L = 0x0;
323 ADMOD0H = 0x0;
324 ADMOD1L = 0x0;
325 ADMOD1H = 0x0;
326 ADIEL = 0x0;
327 ADIEH = 0x0;
328 ADSTATL = 0x0;
329 ADSTATH = 0x0;
330 ADCMP0ENL = 0x0;
331 ADCMP1ENL = 0x0;
332 ADCMP2ENL = 0x0;
333 ADCMP3ENL = 0x0;
334 ADCMP0ENH = 0x0;
335 ADCMP1ENH = 0x0;
336 ADCMP2ENH = 0x0;
337 ADCMP3ENH = 0x0;
338 ADCMP0LO = 0x0;
339 ADCMP1LO = 0x0;
340 ADCMP2LO = 0x0;
341 ADCMP3LO = 0x0;
342 ADCMP0HI = 0x0;
343 ADCMP1HI = 0x0;
344 ADCMP2HI = 0x0;
345 ADCMP3HI = 0x0;
346 ADFL0DAT = 0x0;
347 ADFL1DAT = 0x0;
348 ADFL2DAT = 0x0;
349 ADFL3DAT = 0x0;
350 ADFL0CON = 0x0;
351 ADFL1CON = 0x0;
352 ADFL2CON = 0x0;
353 ADFL3CON = 0x0;
354 ADTRIG0L = 0x0;
355 ADTRIG0H = 0x0;
356 ADTRIG1L = 0x0;
357 ADTRIG1H = 0x0;
358 ADTRIG2L = 0x0;
359 ADTRIG2H = 0x0;
360 ADTRIG3L = 0x0;
361 ADTRIG3H = 0x0;
362 ADTRIG4L = 0x0;
363 ADTRIG4H = 0x0;
364 ADTRIG6L = 0x0;
365 ADCMP0CON = 0x0;
366 ADCMP1CON = 0x0;
367 ADCMP2CON = 0x0;
368 ADCMP3CON = 0x0;
369 ADLVLTRGL = 0x0;
370 ADLVLTRGH = 0x0;
371 ADCORE0L = 0x0;
372 ADCORE1L = 0x0;
373 ADCORE0H = 0x300;
374 ADCORE1H = 0x300;
375 ADEIEL = 0x0;
376 ADEIEH = 0x0;
377 ADEISTATL = 0x0;
378 ADEISTATH = 0x0;
379 ADCON5L = 0x0;
380 ADCON5H = 0x0;
381 ADCBUF0 = 0x0;
382 ADCBUF1 = 0x0;
383 ADCBUF2 = 0x0;
384 ADCBUF3 = 0x0;
385 ADCBUF4 = 0x0;
386 ADCBUF5 = 0x0;
387 ADCBUF6 = 0x0;
388 ADCBUF7 = 0x0;
389 ADCBUF8 = 0x0;
390 ADCBUF9 = 0x0;
391 ADCBUF10 = 0x0;
392 ADCBUF11 = 0x0;
393 ADCBUF12 = 0x0;
394 ADCBUF13 = 0x0;
395 ADCBUF14 = 0x0;
396 ADCBUF15 = 0x0;
397 ADCBUF16 = 0x0;
398 ADCBUF17 = 0x0;
399 ADCBUF18 = 0x0;
400 ADCBUF19 = 0x0;
401 ADCBUF24 = 0x0;
402 ADCBUF25 = 0x0;
403}
404
406{
407 switch(core)
408 {
409 case ADC_CORE_0:
410 ADCON5Lbits.C0PWR = 1;
411 while(ADCON5Lbits.C0RDY == 0)
412 {
413 }
414 ADCON3Hbits.C0EN = 1;
415 break;
416 case ADC_CORE_1:
417 ADCON5Lbits.C1PWR = 1;
418 while(ADCON5Lbits.C1RDY == 0)
419 {
420 }
421 ADCON3Hbits.C1EN = 1;
422 break;
423 default:
424 break;
425 }
426}
427
428
430{
431 ADCON5Lbits.SHRPWR = 1;
432 while(ADCON5Lbits.SHRRDY == 0)
433 {
434 }
435 ADCON3Hbits.SHREN = 1;
436}
437
438static uint16_t ADC1_TriggerSourceValueGet(enum ADC_PWM_INSTANCE pwmInstance, enum ADC_PWM_TRIGGERS triggerNumber)
439{
440 uint16_t adcTriggerSourceValue = 0x0U;
441 switch(pwmInstance)
442 {
444 if(triggerNumber == ADC_PWM_TRIGGER_1)
445 {
446 adcTriggerSourceValue = PWM8_TRIGGER1;
447 }
448 else if(triggerNumber == ADC_PWM_TRIGGER_2)
449 {
450 adcTriggerSourceValue = PWM8_TRIGGER2;
451 }
452 break;
454 if(triggerNumber == ADC_PWM_TRIGGER_1)
455 {
456 adcTriggerSourceValue = PWM7_TRIGGER1;
457 }
458 else if(triggerNumber == ADC_PWM_TRIGGER_2)
459 {
460 adcTriggerSourceValue = PWM7_TRIGGER2;
461 }
462 break;
464 if(triggerNumber == ADC_PWM_TRIGGER_1)
465 {
466 adcTriggerSourceValue = PWM6_TRIGGER1;
467 }
468 else if(triggerNumber == ADC_PWM_TRIGGER_2)
469 {
470 adcTriggerSourceValue = PWM6_TRIGGER2;
471 }
472 break;
474 if(triggerNumber == ADC_PWM_TRIGGER_1)
475 {
476 adcTriggerSourceValue = PWM5_TRIGGER1;
477 }
478 else if(triggerNumber == ADC_PWM_TRIGGER_2)
479 {
480 adcTriggerSourceValue = PWM5_TRIGGER2;
481 }
482 break;
484 if(triggerNumber == ADC_PWM_TRIGGER_1)
485 {
486 adcTriggerSourceValue = PWM4_TRIGGER1;
487 }
488 else if(triggerNumber == ADC_PWM_TRIGGER_2)
489 {
490 adcTriggerSourceValue = PWM4_TRIGGER2;
491 }
492 break;
494 if(triggerNumber == ADC_PWM_TRIGGER_1)
495 {
496 adcTriggerSourceValue = PWM3_TRIGGER1;
497 }
498 else if(triggerNumber == ADC_PWM_TRIGGER_2)
499 {
500 adcTriggerSourceValue = PWM3_TRIGGER2;
501 }
502 break;
504 if(triggerNumber == ADC_PWM_TRIGGER_1)
505 {
506 adcTriggerSourceValue = PWM2_TRIGGER1;
507 }
508 else if(triggerNumber == ADC_PWM_TRIGGER_2)
509 {
510 adcTriggerSourceValue = PWM2_TRIGGER2;
511 }
512 break;
514 if(triggerNumber == ADC_PWM_TRIGGER_1)
515 {
516 adcTriggerSourceValue = PWM1_TRIGGER1;
517 }
518 else if(triggerNumber == ADC_PWM_TRIGGER_2)
519 {
520 adcTriggerSourceValue = PWM1_TRIGGER2;
521 }
522 break;
523 default:
524 break;
525 }
526 return adcTriggerSourceValue;
527}
528
529void ADC1_PWMTriggerSourceSet(enum ADC_CHANNEL channel, enum ADC_PWM_INSTANCE pwmInstance, enum ADC_PWM_TRIGGERS triggerNumber)
530{
531 uint16_t adcTriggerValue;
532 adcTriggerValue= ADC1_TriggerSourceValueGet(pwmInstance, triggerNumber);
533 switch(channel)
534 {
535 case VSEC:
536 ADTRIG0Hbits.TRGSRC2 = adcTriggerValue;
537 break;
538 case IPRI_CT:
539 ADTRIG1Hbits.TRGSRC7 = adcTriggerValue;
540 break;
541 case VPRI:
542 ADTRIG2Hbits.TRGSRC10 = adcTriggerValue;
543 break;
544 case TEMP:
545 ADTRIG3Hbits.TRGSRC14 = adcTriggerValue;
546 break;
547 case VRAIL_5V:
548 ADTRIG4Hbits.TRGSRC19 = adcTriggerValue;
549 break;
550 case ISEC_CT:
551 ADTRIG0Lbits.TRGSRC0 = adcTriggerValue;
552 break;
553 case ISEC_AVG:
554 ADTRIG0Lbits.TRGSRC1 = adcTriggerValue;
555 break;
556 default:
557 break;
558 }
559}
560
561void ADC1_CommonCallbackRegister(void(*callback)(void))
562{
563 if(NULL != callback)
564 {
565 ADC1_CommonHandler = callback;
566 }
567}
568
570{
571
572}
573
574
575void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCInterrupt ( void )
576{
577 uint16_t adcVal;
578 if(NULL != ADC1_CommonHandler)
579 {
580 (*ADC1_CommonHandler)();
581 }
582
583 if(IFS5bits.ADCAN2IF == 1)
584 {
585 //Read the ADC value from the ADCBUF before clearing interrupt
586 adcVal = ADCBUF2;
587 if(NULL != ADC1_ChannelHandler)
588 {
589 (*ADC1_ChannelHandler)(VSEC, adcVal);
590 }
591 IFS5bits.ADCAN2IF = 0;
592 }
593 if(IFS6bits.ADCAN7IF == 1)
594 {
595 //Read the ADC value from the ADCBUF before clearing interrupt
596 adcVal = ADCBUF7;
597 if(NULL != ADC1_ChannelHandler)
598 {
599 (*ADC1_ChannelHandler)(IPRI_CT, adcVal);
600 }
601 IFS6bits.ADCAN7IF = 0;
602 }
603 if(IFS6bits.ADCAN10IF == 1)
604 {
605 //Read the ADC value from the ADCBUF before clearing interrupt
606 adcVal = ADCBUF10;
607 if(NULL != ADC1_ChannelHandler)
608 {
609 (*ADC1_ChannelHandler)(VPRI, adcVal);
610 }
611 IFS6bits.ADCAN10IF = 0;
612 }
613 if(IFS6bits.ADCAN14IF == 1)
614 {
615 //Read the ADC value from the ADCBUF before clearing interrupt
616 adcVal = ADCBUF14;
617 if(NULL != ADC1_ChannelHandler)
618 {
619 (*ADC1_ChannelHandler)(TEMP, adcVal);
620 }
621 IFS6bits.ADCAN14IF = 0;
622 }
623 if(IFS6bits.ADCAN19IF == 1)
624 {
625 //Read the ADC value from the ADCBUF before clearing interrupt
626 adcVal = ADCBUF19;
627 if(NULL != ADC1_ChannelHandler)
628 {
629 (*ADC1_ChannelHandler)(VRAIL_5V, adcVal);
630 }
631 IFS6bits.ADCAN19IF = 0;
632 }
633 if(IFS5bits.ADCAN0IF == 1)
634 {
635 //Read the ADC value from the ADCBUF before clearing interrupt
636 adcVal = ADCBUF0;
637 if(NULL != ADC1_ChannelHandler)
638 {
639 (*ADC1_ChannelHandler)(ISEC_CT, adcVal);
640 }
641 IFS5bits.ADCAN0IF = 0;
642 }
643 if(IFS5bits.ADCAN1IF == 1)
644 {
645 //Read the ADC value from the ADCBUF before clearing interrupt
646 adcVal = ADCBUF1;
647 if(NULL != ADC1_ChannelHandler)
648 {
649 (*ADC1_ChannelHandler)(ISEC_AVG, adcVal);
650 }
651 IFS5bits.ADCAN1IF = 0;
652 }
653
654 // clear the ADC1 interrupt flag
655 IFS5bits.ADCIF = 0;
656}
657
658void __attribute__ ((weak)) ADC1_Tasks ( void )
659{
660 if(IFS5bits.ADCIF == 1)
661 {
662 if(NULL != ADC1_CommonHandler)
663 {
664 (*ADC1_CommonHandler)();
665 }
666
667 // clear the ADC1 interrupt flag
668 IFS5bits.ADCIF = 0;
669 }
670}
671
672void ADC1_ChannelCallbackRegister(void(*callback)(enum ADC_CHANNEL channel, uint16_t adcVal))
673{
674 if(NULL != callback)
675 {
676 ADC1_ChannelHandler = callback;
677 }
678}
679
680void __attribute__ ((weak)) ADC1_ChannelCallback (enum ADC_CHANNEL channel, uint16_t adcVal)
681{
682 (void)channel;
683 (void)adcVal;
684}
685
686
687void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCAN2Interrupt ( void )
688{
689 uint16_t valVSEC;
690 //Read the ADC value from the ADCBUF
691 valVSEC = ADCBUF2;
692
693 if(NULL != ADC1_ChannelHandler)
694 {
695 (*ADC1_ChannelHandler)(VSEC, valVSEC);
696 }
697
698 //clear the VSEC interrupt flag
699 IFS5bits.ADCAN2IF = 0;
700}
701
702void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCAN7Interrupt ( void )
703{
704 uint16_t valIPRI_CT;
705 //Read the ADC value from the ADCBUF
706 valIPRI_CT = ADCBUF7;
707
708 if(NULL != ADC1_ChannelHandler)
709 {
710 (*ADC1_ChannelHandler)(IPRI_CT, valIPRI_CT);
711 }
712
713 //clear the IPRI_CT interrupt flag
714 IFS6bits.ADCAN7IF = 0;
715}
716
717void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCAN10Interrupt ( void )
718{
719 uint16_t valVPRI;
720 //Read the ADC value from the ADCBUF
721 valVPRI = ADCBUF10;
722
723 if(NULL != ADC1_ChannelHandler)
724 {
725 (*ADC1_ChannelHandler)(VPRI, valVPRI);
726 }
727
728 //clear the VPRI interrupt flag
729 IFS6bits.ADCAN10IF = 0;
730}
731
732void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCAN14Interrupt ( void )
733{
734 uint16_t valTEMP;
735 //Read the ADC value from the ADCBUF
736 valTEMP = ADCBUF14;
737
738 if(NULL != ADC1_ChannelHandler)
739 {
740 (*ADC1_ChannelHandler)(TEMP, valTEMP);
741 }
742
743 //clear the TEMP interrupt flag
744 IFS6bits.ADCAN14IF = 0;
745}
746
747void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCAN19Interrupt ( void )
748{
749 uint16_t valVRAIL_5V;
750 //Read the ADC value from the ADCBUF
751 valVRAIL_5V = ADCBUF19;
752
753 if(NULL != ADC1_ChannelHandler)
754 {
755 (*ADC1_ChannelHandler)(VRAIL_5V, valVRAIL_5V);
756 }
757
758 //clear the VRAIL_5V interrupt flag
759 IFS6bits.ADCAN19IF = 0;
760}
761
762
763void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCAN0Interrupt ( void )
764{
765 uint16_t valISEC_CT;
766 //Read the ADC value from the ADCBUF
767 valISEC_CT = ADCBUF0;
768
769 if(NULL != ADC1_ChannelHandler)
770 {
771 (*ADC1_ChannelHandler)(ISEC_CT, valISEC_CT);
772 }
773
774 //clear the ISEC_CT interrupt flag
775 IFS5bits.ADCAN0IF = 0;
776}
777
778void __attribute__ ( ( __interrupt__ , auto_psv, weak ) ) _ADCAN1Interrupt ( void )
779{
780 uint16_t valISEC_AVG;
781 //Read the ADC value from the ADCBUF
782 valISEC_AVG = ADCBUF1;
783
784 if(NULL != ADC1_ChannelHandler)
785 {
786 (*ADC1_ChannelHandler)(ISEC_AVG, valISEC_AVG);
787 }
788
789 //clear the ISEC_AVG interrupt flag
790 IFS5bits.ADCAN1IF = 0;
791}
792
793
794void __attribute__ ((weak)) ADC1_ChannelTasks (enum ADC_CHANNEL channel)
795{
796 uint16_t adcVal;
797
798 switch(channel)
799 {
800 case VSEC:
801 if((bool)ADSTATLbits.AN2RDY == 1)
802 {
803 //Read the ADC value from the ADCBUF
804 adcVal = ADCBUF2;
805
806 if(NULL != ADC1_ChannelHandler)
807 {
808 (*ADC1_ChannelHandler)(channel, adcVal);
809 }
810 }
811 break;
812 case IPRI_CT:
813 if((bool)ADSTATLbits.AN7RDY == 1)
814 {
815 //Read the ADC value from the ADCBUF
816 adcVal = ADCBUF7;
817
818 if(NULL != ADC1_ChannelHandler)
819 {
820 (*ADC1_ChannelHandler)(channel, adcVal);
821 }
822 }
823 break;
824 case VPRI:
825 if((bool)ADSTATLbits.AN10RDY == 1)
826 {
827 //Read the ADC value from the ADCBUF
828 adcVal = ADCBUF10;
829
830 if(NULL != ADC1_ChannelHandler)
831 {
832 (*ADC1_ChannelHandler)(channel, adcVal);
833 }
834 }
835 break;
836 case TEMP:
837 if((bool)ADSTATLbits.AN14RDY == 1)
838 {
839 //Read the ADC value from the ADCBUF
840 adcVal = ADCBUF14;
841
842 if(NULL != ADC1_ChannelHandler)
843 {
844 (*ADC1_ChannelHandler)(channel, adcVal);
845 }
846 }
847 break;
848 case VRAIL_5V:
849 if((bool)ADSTATHbits.AN19RDY == 1)
850 {
851 //Read the ADC value from the ADCBUF
852 adcVal = ADCBUF19;
853
854 if(NULL != ADC1_ChannelHandler)
855 {
856 (*ADC1_ChannelHandler)(channel, adcVal);
857 }
858 }
859 break;
860 case ISEC_CT:
861 if((bool)ADSTATLbits.AN0RDY == 1)
862 {
863 //Read the ADC value from the ADCBUF
864 adcVal = ADCBUF0;
865
866 if(NULL != ADC1_ChannelHandler)
867 {
868 (*ADC1_ChannelHandler)(channel, adcVal);
869 }
870 }
871 break;
872 case ISEC_AVG:
873 if((bool)ADSTATLbits.AN1RDY == 1)
874 {
875 //Read the ADC value from the ADCBUF
876 adcVal = ADCBUF1;
877
878 if(NULL != ADC1_ChannelHandler)
879 {
880 (*ADC1_ChannelHandler)(channel, adcVal);
881 }
882 }
883 break;
884 default:
885 break;
886 }
887}
888
889void ADC1_ComparatorCallbackRegister(void(*callback)(enum ADC_CMP comparator))
890{
891 if(NULL != callback)
892 {
893 ADC1_ComparatorHandler = callback;
894 }
895}
896
897void __attribute__ ((weak)) ADC1_ComparatorCallback (enum ADC_CMP comparator)
898{
899 (void)comparator;
900}
901
902
903
ADC_PWM_TRIGGERS
Definition adc_types.h:138
@ ADC_PWM_TRIGGER_1
Definition adc_types.h:139
@ ADC_PWM_TRIGGER_2
Definition adc_types.h:140
ADC_CMP
Definition adc_types.h:108
ADC_PWM_INSTANCE
Definition adc_types.h:121
@ ADC_PWM_GENERATOR_2
Definition adc_types.h:128
@ ADC_PWM_GENERATOR_4
Definition adc_types.h:126
@ ADC_PWM_GENERATOR_5
Definition adc_types.h:125
@ ADC_PWM_GENERATOR_7
Definition adc_types.h:123
@ ADC_PWM_GENERATOR_1
Definition adc_types.h:129
@ ADC_PWM_GENERATOR_8
Definition adc_types.h:122
@ ADC_PWM_GENERATOR_3
Definition adc_types.h:127
@ ADC_PWM_GENERATOR_6
Definition adc_types.h:124
ADC_DEDICATED_CORE
Definition adc_types.h:79
@ ADC_CORE_1
Definition adc_types.h:83
@ ADC_CORE_0
Definition adc_types.h:81
ADC_CHANNEL
Definition adc_types.h:56
@ ISEC_CT
Definition adc_types.h:62
@ VSEC
Definition adc_types.h:57
@ IPRI_CT
Definition adc_types.h:58
@ TEMP
Definition adc_types.h:60
@ VPRI
Definition adc_types.h:59
@ VRAIL_5V
Definition adc_types.h:61
@ ISEC_AVG
Definition adc_types.h:63
ADC_PWM_TRIG_SRCS
Definition adc1.c:55
@ 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
void __attribute__((weak))
Definition adc1.c:569
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:438
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:223
static void ADC1_InterruptFlagClear(void)
Clears interrupt flag manually.
Definition adc1.h:299
void ADC1_CommonCallback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
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:476
static void ADC1_ResolutionSet(enum ADC_RESOLUTION_TYPE resolution)
This inline function helps to configure all cores with same resolution.
Definition adc1.h:264
static void ADC1_IndividualChannelInterruptDisable(enum ADC_CHANNEL channel)
This inline function disables individual channel interrupt.
Definition adc1.h:396
void ADC1_ComparatorCallback(enum ADC_CMP comparator)
Comparator callback function.
void ADC1_Deinitialize(void)
Deinitializes the ADC1 to POR values.
Definition adc1.c:310
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:529
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:429
static void ADC1_IndividualChannelInterruptEnable(enum ADC_CHANNEL channel)
This inline function enables individual channel interrupt.
Definition adc1.h:353
void ADC1_Tasks(void)
This function is used to implement the tasks for polled implementations.
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:889
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:277
static void ADC1_InterruptPrioritySet(uint16_t priorityValue)
This inline function allows selection of priority for interrupt.
Definition adc1.h:310
static void ADC1_IndividualChannelInterruptFlagClear(enum ADC_CHANNEL channel)
This inline function clears individual channel interrupt flag.
Definition adc1.h:439
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
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:288
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
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:561
void ADC1_CorePowerEnable(enum ADC_DEDICATED_CORE core)
Enables analog and digital power for ADC1 dedicated core.
Definition adc1.c:405
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:672
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.