Bar Logo 4kW dsPIC33C PSFB DC-DC DA (Part-No. )
 
Content
     
Loading...
Searching...
No Matches
adc1.h
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#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
108inline static void ADC1_Enable(void)
109{
110 ADCON1Lbits.ADON = 1;
111}
112
121inline static void ADC1_Disable(void)
122{
123 ADCON1Lbits.ADON = 0;
124}
125
134inline static void ADC1_SoftwareTriggerEnable(void)
135{
136 ADCON3Lbits.SWCTRG = 1;
137}
138
147inline static void ADC1_SoftwareTriggerDisable(void)
148{
149 ADCON3Lbits.SWCTRG = 0;
150}
151
160inline 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
178inline static uint16_t ADC1_ConversionResultGet( enum ADC_CHANNEL channel )
179{
180 uint16_t result = 0x0U;
181
182 switch(channel)
183 {
184 case FB_VOUT:
185 result = ADCBUF2;
186 break;
187 case FB_VCAP:
188 result = ADCBUF9;
189 break;
190 case VIN_INT_AN:
191 result = ADCBUF10;
192 break;
193 case FB_TEMP:
194 result = ADCBUF14;
195 break;
196 case Channel_AN15:
197 result = ADCBUF15;
198 break;
199 case FB_5V:
200 result = ADCBUF19;
201 break;
202 case FB_P_CT_FILT:
203 result = ADCBUF0;
204 break;
205 case I_SEC_AVG_FILT:
206 result = ADCBUF1;
207 break;
208 default:
209 break;
210 }
211 return result;
212}
213
226inline static bool ADC1_IsConversionComplete(enum ADC_CHANNEL channel)
227{
228 bool status = false;
229
230 switch(channel)
231 {
232 case FB_VOUT:
233 status = ADSTATLbits.AN2RDY;
234 break;
235 case FB_VCAP:
236 status = ADSTATLbits.AN9RDY;
237 break;
238 case VIN_INT_AN:
239 status = ADSTATLbits.AN10RDY;
240 break;
241 case FB_TEMP:
242 status = ADSTATLbits.AN14RDY;
243 break;
244 case Channel_AN15:
245 status = ADSTATLbits.AN15RDY;
246 break;
247 case FB_5V:
248 status = ADSTATHbits.AN19RDY;
249 break;
250 case FB_P_CT_FILT:
251 status = ADSTATLbits.AN0RDY;
252 break;
253 case I_SEC_AVG_FILT:
254 status = ADSTATLbits.AN1RDY;
255 break;
256 default:
257 break;
258 }
259
260 return status;
261}
262
270inline static void ADC1_ResolutionSet(enum ADC_RESOLUTION_TYPE resolution)
271{
272 ADCORE0Hbits.RES = resolution;
273 ADCORE1Hbits.RES = resolution;
274 ADCON1Hbits.SHRRES = resolution;
275}
276
283inline static void ADC1_InterruptEnable(void)
284{
285 IEC5bits.ADCIE = 1;
286}
287
294inline static void ADC1_InterruptDisable(void)
295{
296 IEC5bits.ADCIE = 0;
297}
298
305inline static void ADC1_InterruptFlagClear(void)
306{
307 IFS5bits.ADCIF = 0;
308}
309
316inline static void ADC1_InterruptPrioritySet( uint16_t priorityValue )
317{
318 IPC22bits.ADCIP = (uint16_t)0x7 & priorityValue;
319}
320
329void ADC1_CommonCallbackRegister(void(*callback)(void));
330
339
340
351void ADC1_Tasks(void);
352
360{
361 switch(channel)
362 {
363 case FB_VOUT:
364 IEC5bits.ADCAN2IE = 1;
365 ADIELbits.IE2 = 1;
366 break;
367 case FB_VCAP:
368 IEC6bits.ADCAN9IE = 1;
369 ADIELbits.IE9 = 1;
370 break;
371 case VIN_INT_AN:
372 IEC6bits.ADCAN10IE = 1;
373 ADIELbits.IE10 = 1;
374 break;
375 case FB_TEMP:
376 IEC6bits.ADCAN14IE = 1;
377 ADIELbits.IE14 = 1;
378 break;
379 case Channel_AN15:
380 IEC6bits.ADCAN15IE = 1;
381 ADIELbits.IE15 = 1;
382 break;
383 case FB_5V:
384 IEC6bits.ADCAN19IE = 1;
385 ADIEHbits.IE19 = 1;
386 break;
387 case FB_P_CT_FILT:
388 IEC5bits.ADCAN0IE = 1;
389 ADIELbits.IE0 = 1;
390 break;
391 case I_SEC_AVG_FILT:
392 IEC5bits.ADCAN1IE = 1;
393 ADIELbits.IE1 = 1;
394 break;
395 default:
396 break;
397 }
398}
399
407{
408 switch(channel)
409 {
410 case FB_VOUT:
411 IEC5bits.ADCAN2IE = 0;
412 ADIELbits.IE2 = 0;
413 break;
414 case FB_VCAP:
415 IEC6bits.ADCAN9IE = 0;
416 ADIELbits.IE9 = 0;
417 break;
418 case VIN_INT_AN:
419 IEC6bits.ADCAN10IE = 0;
420 ADIELbits.IE10 = 0;
421 break;
422 case FB_TEMP:
423 IEC6bits.ADCAN14IE = 0;
424 ADIELbits.IE14 = 0;
425 break;
426 case Channel_AN15:
427 IEC6bits.ADCAN15IE = 0;
428 ADIELbits.IE15 = 0;
429 break;
430 case FB_5V:
431 IEC6bits.ADCAN19IE = 0;
432 ADIEHbits.IE19 = 0;
433 break;
434 case FB_P_CT_FILT:
435 IEC5bits.ADCAN0IE = 0;
436 ADIELbits.IE0 = 0;
437 break;
438 case I_SEC_AVG_FILT:
439 IEC5bits.ADCAN1IE = 0;
440 ADIELbits.IE1 = 0;
441 break;
442 default:
443 break;
444 }
445}
446
454{
455 switch(channel)
456 {
457 case FB_VOUT:
458 IFS5bits.ADCAN2IF = 0;
459 break;
460 case FB_VCAP:
461 IFS6bits.ADCAN9IF = 0;
462 break;
463 case VIN_INT_AN:
464 IFS6bits.ADCAN10IF = 0;
465 break;
466 case FB_TEMP:
467 IFS6bits.ADCAN14IF = 0;
468 break;
469 case Channel_AN15:
470 IFS6bits.ADCAN15IF = 0;
471 break;
472 case FB_5V:
473 IFS6bits.ADCAN19IF = 0;
474 break;
475 case FB_P_CT_FILT:
476 IFS5bits.ADCAN0IF = 0;
477 break;
478 case I_SEC_AVG_FILT:
479 IFS5bits.ADCAN1IF = 0;
480 break;
481 default:
482 break;
483 }
484}
485
493inline static void ADC1_IndividualChannelInterruptPrioritySet(enum ADC_CHANNEL channel, enum INTERRUPT_PRIORITY priorityValue)
494{
495 switch(channel)
496 {
497 case FB_VOUT:
498 IPC23bits.ADCAN2IP = priorityValue;
499 break;
500 case FB_VCAP:
501 IPC25bits.ADCAN9IP = priorityValue;
502 break;
503 case VIN_INT_AN:
504 IPC25bits.ADCAN10IP = priorityValue;
505 break;
506 case FB_TEMP:
507 IPC26bits.ADCAN14IP = priorityValue;
508 break;
509 case Channel_AN15:
510 IPC26bits.ADCAN15IP = priorityValue;
511 break;
512 case FB_5V:
513 IPC27bits.ADCAN19IP = priorityValue;
514 break;
515 case FB_P_CT_FILT:
516 IPC22bits.ADCAN0IP = priorityValue;
517 break;
518 case I_SEC_AVG_FILT:
519 IPC23bits.ADCAN1IP = priorityValue;
520 break;
521 default:
522 break;
523 }
524}
525
534void ADC1_ChannelCallbackRegister(void(*callback)(enum ADC_CHANNEL channel, uint16_t adcVal));
535
545void ADC1_ChannelCallback(enum ADC_CHANNEL channel, uint16_t adcVal);
546
547
555void ADC1_ComparatorCallbackRegister(void(*callback)(enum ADC_CMP comparator));
556
563void ADC1_ComparatorCallback(enum ADC_CMP comparator);
564
565
579
580
581// Section: Interface functions: Dedicated Core
582
590
591
601
602
615void ADC1_PWMTriggerSourceSet(enum ADC_CHANNEL channel, enum ADC_PWM_INSTANCE pwmInstance, enum ADC_PWM_TRIGGERS triggerNumber);
616
617#ifdef __cplusplus // Provide C++ Compatibility
618
619 }
620
621#endif
622
623#endif //_ADC1_H
624
This is the generated driver types header file for the ADC driver.
@ 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
size_t status
Definition uart1.c:99
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_RESOLUTION_TYPE
Defines the supported ADC resolution types.
Definition adc_types.h:95
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...
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.