|  | Dual Active Bridge Development Board (Part-No. ) |
Content |  |  |  |  |  |

Loading...
Searching...
No Matches
adc1.h
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#ifndef ADC1_H
39#define ADC1_H
40
41// Section: Included Files
42
43#include <xc.h>
44#include <stdbool.h>
45#include <stdint.h>
46#include "adc_types.h"
47#include "adc_interface.h"
48#ifdef __cplusplus //Provide C++ Compatibility
49
50 extern "C" {
51
52#endif
53
54// Section: Data Types
55
60#define ADC1_SCAN_MODE_SELECTED true
61
66#define ADC1_RESOLUTION 12
67
68// Section: Data Type Definitions
69
78extern const struct ADC_INTERFACE ADC1;
79
80
81// Section: Driver Interface Functions
82
90void ADC1_Initialize (void);
91
98void ADC1_Deinitialize(void);
99
108 inline static void ADC1_Enable(void)
109{
110 ADCON1Lbits.ADON = 1;
111}
112
121 inline static void ADC1_Disable(void)
122{
123 ADCON1Lbits.ADON = 0;
124}
125
134 inline static void ADC1_SoftwareTriggerEnable(void)
135{
136 ADCON3Lbits.SWCTRG = 1;
137}
138
147 inline static void ADC1_SoftwareTriggerDisable(void)
148{
149 ADCON3Lbits.SWCTRG = 0;
150}
151
160 inline static void ADC1_ChannelSelect( enum ADC_CHANNEL channel )
161{
162 //This function does not have any implementation since
163 //Shared channels are selected from UI.
164 //Dedicated channels are selected from UI.
165
166 (void)channel;
167}
168
178 inline static uint16_t ADC1_ConversionResultGet( enum ADC_CHANNEL channel )
179{
180 uint16_t result = 0x0U;
181
182 switch(channel)
183 {
184 case VSEC:
185 result = ADCBUF2;
186 break;
187 case IPRI_CT:
188 result = ADCBUF7;
189 break;
190 case VPRI:
191 result = ADCBUF10;
192 break;
193 case TEMP:
194 result = ADCBUF14;
195 break;
196 case VRAIL_5V:
197 result = ADCBUF19;
198 break;
199 case ISEC_CT:
200 result = ADCBUF0;
201 break;
202 case ISEC_AVG:
203 result = ADCBUF1;
204 break;
205 default:
206 break;
207 }
208 return result;
209}
210
223 inline static bool ADC1_IsConversionComplete(enum ADC_CHANNEL channel)
224{
225 bool status = false;
226
227 switch(channel)
228 {
229 case VSEC:
230 status = ADSTATLbits.AN2RDY;
231 break;
232 case IPRI_CT:
233 status = ADSTATLbits.AN7RDY;
234 break;
235 case VPRI:
236 status = ADSTATLbits.AN10RDY;
237 break;
238 case TEMP:
239 status = ADSTATLbits.AN14RDY;
240 break;
241 case VRAIL_5V:
242 status = ADSTATHbits.AN19RDY;
243 break;
244 case ISEC_CT:
245 status = ADSTATLbits.AN0RDY;
246 break;
247 case ISEC_AVG:
248 status = ADSTATLbits.AN1RDY;
249 break;
250 default:
251 break;
252 }
253
254 return status;
255}
256
264 inline static void ADC1_ResolutionSet(enum ADC_RESOLUTION_TYPE resolution)
265{
266 ADCORE0Hbits.RES = resolution;
267 ADCORE1Hbits.RES = resolution;
268 ADCON1Hbits.SHRRES = resolution;
269}
270
277 inline static void ADC1_InterruptEnable(void)
278{
279 IEC5bits.ADCIE = 1;
280}
281
288 inline static void ADC1_InterruptDisable(void)
289{
290 IEC5bits.ADCIE = 0;
291}
292
299 inline static void ADC1_InterruptFlagClear(void)
300{
301 IFS5bits.ADCIF = 0;
302}
303
310 inline static void ADC1_InterruptPrioritySet( uint16_t priorityValue )
311{
312 IPC22bits.ADCIP = (uint16_t)0x7 & priorityValue;
313}
314
323void ADC1_CommonCallbackRegister(void(*callback)(void));
324
332 void ADC1_CommonCallback(void);
333
334
345 void ADC1_Tasks(void);
346
353 inline static void ADC1_IndividualChannelInterruptEnable(enum ADC_CHANNEL channel)
354{
355 switch(channel)
356 {
357 case VSEC:
358 IEC5bits.ADCAN2IE = 1;
359 ADIELbits.IE2 = 1;
360 break;
361 case IPRI_CT:
362 IEC6bits.ADCAN7IE = 1;
363 ADIELbits.IE7 = 1;
364 break;
365 case VPRI:
366 IEC6bits.ADCAN10IE = 1;
367 ADIELbits.IE10 = 1;
368 break;
369 case TEMP:
370 IEC6bits.ADCAN14IE = 1;
371 ADIELbits.IE14 = 1;
372 break;
373 case VRAIL_5V:
374 IEC6bits.ADCAN19IE = 1;
375 ADIEHbits.IE19 = 1;
376 break;
377 case ISEC_CT:
378 IEC5bits.ADCAN0IE = 1;
379 ADIELbits.IE0 = 1;
380 break;
381 case ISEC_AVG:
382 IEC5bits.ADCAN1IE = 1;
383 ADIELbits.IE1 = 1;
384 break;
385 default:
386 break;
387 }
388}
389
396 inline static void ADC1_IndividualChannelInterruptDisable(enum ADC_CHANNEL channel)
397{
398 switch(channel)
399 {
400 case VSEC:
401 IEC5bits.ADCAN2IE = 0;
402 ADIELbits.IE2 = 0;
403 break;
404 case IPRI_CT:
405 IEC6bits.ADCAN7IE = 0;
406 ADIELbits.IE7 = 0;
407 break;
408 case VPRI:
409 IEC6bits.ADCAN10IE = 0;
410 ADIELbits.IE10 = 0;
411 break;
412 case TEMP:
413 IEC6bits.ADCAN14IE = 0;
414 ADIELbits.IE14 = 0;
415 break;
416 case VRAIL_5V:
417 IEC6bits.ADCAN19IE = 0;
418 ADIEHbits.IE19 = 0;
419 break;
420 case ISEC_CT:
421 IEC5bits.ADCAN0IE = 0;
422 ADIELbits.IE0 = 0;
423 break;
424 case ISEC_AVG:
425 IEC5bits.ADCAN1IE = 0;
426 ADIELbits.IE1 = 0;
427 break;
428 default:
429 break;
430 }
431}
432
439 inline static void ADC1_IndividualChannelInterruptFlagClear(enum ADC_CHANNEL channel)
440{
441 switch(channel)
442 {
443 case VSEC:
444 IFS5bits.ADCAN2IF = 0;
445 break;
446 case IPRI_CT:
447 IFS6bits.ADCAN7IF = 0;
448 break;
449 case VPRI:
450 IFS6bits.ADCAN10IF = 0;
451 break;
452 case TEMP:
453 IFS6bits.ADCAN14IF = 0;
454 break;
455 case VRAIL_5V:
456 IFS6bits.ADCAN19IF = 0;
457 break;
458 case ISEC_CT:
459 IFS5bits.ADCAN0IF = 0;
460 break;
461 case ISEC_AVG:
462 IFS5bits.ADCAN1IF = 0;
463 break;
464 default:
465 break;
466 }
467}
468
476 inline static void ADC1_IndividualChannelInterruptPrioritySet(enum ADC_CHANNEL channel, enum INTERRUPT_PRIORITY priorityValue)
477{
478 switch(channel)
479 {
480 case VSEC:
481 IPC23bits.ADCAN2IP = priorityValue;
482 break;
483 case IPRI_CT:
484 IPC24bits.ADCAN7IP = priorityValue;
485 break;
486 case VPRI:
487 IPC25bits.ADCAN10IP = priorityValue;
488 break;
489 case TEMP:
490 IPC26bits.ADCAN14IP = priorityValue;
491 break;
492 case VRAIL_5V:
493 IPC27bits.ADCAN19IP = priorityValue;
494 break;
495 case ISEC_CT:
496 IPC22bits.ADCAN0IP = priorityValue;
497 break;
498 case ISEC_AVG:
499 IPC23bits.ADCAN1IP = priorityValue;
500 break;
501 default:
502 break;
503 }
504}
505
514void ADC1_ChannelCallbackRegister(void(*callback)(enum ADC_CHANNEL channel, uint16_t adcVal));
515
525 void ADC1_ChannelCallback(enum ADC_CHANNEL channel, uint16_t adcVal);
526
527
535void ADC1_ComparatorCallbackRegister(void(*callback)(enum ADC_CMP comparator));
536
543 void ADC1_ComparatorCallback(enum ADC_CMP comparator);
544
545
558 void ADC1_ChannelTasks(enum ADC_CHANNEL channel);
559
560
561// Section: Interface functions: Dedicated Core
562
569void ADC1_CorePowerEnable(enum ADC_DEDICATED_CORE core);
570
571
580void ADC1_SharedCorePowerEnable(void);
581
582
595void ADC1_PWMTriggerSourceSet(enum ADC_CHANNEL channel, enum ADC_PWM_INSTANCE pwmInstance, enum ADC_PWM_TRIGGERS triggerNumber);
596
597#ifdef __cplusplus // Provide C++ Compatibility
598
599 }
600
601#endif
602
603#endif //_ADC1_H
604
adc_types.h
This is the generated driver types header file for the ADC driver.
ADC_RESOLUTION_TYPE
ADC_RESOLUTION_TYPE
Definition adc_types.h:94
ADC_PWM_TRIGGERS
ADC_PWM_TRIGGERS
Definition adc_types.h:138
ADC_CMP
ADC_CMP
Definition adc_types.h:108
ADC_PWM_INSTANCE
ADC_PWM_INSTANCE
Definition adc_types.h:121
ADC_DEDICATED_CORE
ADC_DEDICATED_CORE
Definition adc_types.h:79
ADC_CHANNEL
ADC_CHANNEL
Definition adc_types.h:56
ISEC_CT
@ ISEC_CT
Definition adc_types.h:62
VSEC
@ VSEC
Definition adc_types.h:57
IPRI_CT
@ IPRI_CT
Definition adc_types.h:58
TEMP
@ TEMP
Definition adc_types.h:60
VPRI
@ VPRI
Definition adc_types.h:59
VRAIL_5V
@ VRAIL_5V
Definition adc_types.h:61
ISEC_AVG
@ ISEC_AVG
Definition adc_types.h:63
status
size_t status
Definition uart1.c:99
ADC1_IsConversionComplete
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
ADC1_InterruptFlagClear
static void ADC1_InterruptFlagClear(void)
Clears interrupt flag manually.
Definition adc1.h:299
ADC1_CommonCallback
void ADC1_CommonCallback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
ADC1_IndividualChannelInterruptPrioritySet
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
ADC1_ResolutionSet
static void ADC1_ResolutionSet(enum ADC_RESOLUTION_TYPE resolution)
This inline function helps to configure all cores with same resolution.
Definition adc1.h:264
ADC1_IndividualChannelInterruptDisable
static void ADC1_IndividualChannelInterruptDisable(enum ADC_CHANNEL channel)
This inline function disables individual channel interrupt.
Definition adc1.h:396
ADC1_ComparatorCallback
void ADC1_ComparatorCallback(enum ADC_CMP comparator)
Comparator callback function.
ADC1_Deinitialize
void ADC1_Deinitialize(void)
Deinitializes the ADC1 to POR values.
Definition adc1.c:310
ADC1_PWMTriggerSourceSet
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
ADC1_SharedCorePowerEnable
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
ADC1_IndividualChannelInterruptEnable
static void ADC1_IndividualChannelInterruptEnable(enum ADC_CHANNEL channel)
This inline function enables individual channel interrupt.
Definition adc1.h:353
ADC1_Tasks
void ADC1_Tasks(void)
This function is used to implement the tasks for polled implementations.
ADC1_Enable
static void ADC1_Enable(void)
This inline function enables the ADC1 module.
Definition adc1.h:108
ADC1_ComparatorCallbackRegister
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
ADC1
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
ADC1_InterruptEnable
static void ADC1_InterruptEnable(void)
This inline function enables the ADC1 interrupt.
Definition adc1.h:277
ADC1_InterruptPrioritySet
static void ADC1_InterruptPrioritySet(uint16_t priorityValue)
This inline function allows selection of priority for interrupt.
Definition adc1.h:310
ADC1_IndividualChannelInterruptFlagClear
static void ADC1_IndividualChannelInterruptFlagClear(enum ADC_CHANNEL channel)
This inline function clears individual channel interrupt flag.
Definition adc1.h:439
ADC1_ChannelTasks
void ADC1_ChannelTasks(enum ADC_CHANNEL channel)
This function call used only in polling mode, if channel conversion is done for requested channel,...
ADC1_ChannelCallback
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...
ADC1_SoftwareTriggerDisable
static void ADC1_SoftwareTriggerDisable(void)
This inline function resets software common trigger.
Definition adc1.h:147
ADC1_Disable
static void ADC1_Disable(void)
This inline function disables the ADC1 module.
Definition adc1.h:121
ADC1_Initialize
void ADC1_Initialize(void)
Initializes ADC1 module, using the given initialization data This function must be called before any ...
Definition adc1.c:113
ADC1_InterruptDisable
static void ADC1_InterruptDisable(void)
This inline function disables the ADC1 interrupt.
Definition adc1.h:288
ADC1_ChannelSelect
static void ADC1_ChannelSelect(enum ADC_CHANNEL channel)
This inline function allows selection of a channel for conversion.
Definition adc1.h:160
ADC1_SoftwareTriggerEnable
static void ADC1_SoftwareTriggerEnable(void)
This inline function sets software common trigger.
Definition adc1.h:134
ADC1_CommonCallbackRegister
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
ADC1_CorePowerEnable
void ADC1_CorePowerEnable(enum ADC_DEDICATED_CORE core)
Enables analog and digital power for ADC1 dedicated core.
Definition adc1.c:405
ADC1_ConversionResultGet
static uint16_t ADC1_ConversionResultGet(enum ADC_CHANNEL channel)
Returns the conversion value for the channel selected.
Definition adc1.h:178
ADC1_ChannelCallbackRegister
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
ADC_INTERFACE
Structure containing the function pointers of ADC driver.
Definition adc_interface.h:62