Bar Logo 3.8/7.6 kw Totem pole Demonstration Application (Part-No. (not specified))
 
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
39#ifndef ADC1_H
40#define ADC1_H
41
42// Section: Included Files
43
44#include <xc.h>
45#include <stdbool.h>
46#include <stdint.h>
47#include "adc_types.h"
48#include "adc_interface.h"
49#ifdef __cplusplus //Provide C++ Compatibility
50
51 extern "C" {
52
53#endif
54
55// Section: Data Types
56
61#define ADC1_SCAN_MODE_SELECTED true
62
67#define ADC1_RESOLUTION 12
68
69// Section: Data Type Definitions
70
79extern const struct ADC_INTERFACE ADC1;
80
81
82// Section: Driver Interface Functions
83
91void ADC1_Initialize (void);
92
99void ADC1_Deinitialize(void);
100
109inline static void ADC1_Enable(void)
110{
111 ADCON1Lbits.ADON = 1;
112}
113
122inline static void ADC1_Disable(void)
123{
124 ADCON1Lbits.ADON = 0;
125}
126
135inline static void ADC1_SoftwareTriggerEnable(void)
136{
137 ADCON3Lbits.SWCTRG = 1;
138}
139
148inline static void ADC1_SoftwareTriggerDisable(void)
149{
150 ADCON3Lbits.SWCTRG = 0;
151}
152
161inline static void ADC1_ChannelSelect( enum ADC_CHANNEL channel )
162{
163 //This function does not have any implementation since
164 //Shared channels are selected from UI.
165 //Dedicated channels are selected from UI.
166
167 (void)channel;
168}
169
179inline static uint16_t ADC1_ConversionResultGet( enum ADC_CHANNEL channel )
180{
181 uint16_t result = 0x0U;
182
183 switch(channel)
184 {
185 case FB_Vout:
186 result = ADCBUF10;
187 break;
188 case FB_AC_N:
189 result = ADCBUF15;
190 break;
191 case IL1_F:
192 result = ADCBUF0;
193 break;
194 case IL2_F:
195 result = ADCBUF1;
196 break;
197 default:
198 break;
199 }
200 return result;
201}
202
215inline static bool ADC1_IsConversionComplete(enum ADC_CHANNEL channel)
216{
217 bool status = false;
218
219 switch(channel)
220 {
221 case FB_Vout:
222 status = ADSTATLbits.AN10RDY;
223 break;
224 case FB_AC_N:
225 status = ADSTATLbits.AN15RDY;
226 break;
227 case IL1_F:
228 status = ADSTATLbits.AN0RDY;
229 break;
230 case IL2_F:
231 status = ADSTATLbits.AN1RDY;
232 break;
233 default:
234 break;
235 }
236
237 return status;
238}
239
247inline static void ADC1_ResolutionSet(enum ADC_RESOLUTION_TYPE resolution)
248{
249 ADCORE0Hbits.RES = resolution;
250 ADCORE1Hbits.RES = resolution;
251 ADCON1Hbits.SHRRES = resolution;
252}
253
260inline static void ADC1_InterruptEnable(void)
261{
262 IEC5bits.ADCIE = 1;
263}
264
271inline static void ADC1_InterruptDisable(void)
272{
273 IEC5bits.ADCIE = 0;
274}
275
282inline static void ADC1_InterruptFlagClear(void)
283{
284 IFS5bits.ADCIF = 0;
285}
286
293inline static void ADC1_InterruptPrioritySet( uint16_t priorityValue )
294{
295 IPC22bits.ADCIP = (uint16_t)0x7 & priorityValue;
296}
297
306void ADC1_CommonCallbackRegister(void(*callback)(void));
307
315void ADC1_CommonCallback(void);
316
317
328void ADC1_Tasks(void);
329
337{
338 switch(channel)
339 {
340 case FB_Vout:
341 IEC6bits.ADCAN10IE = 1;
342 ADIELbits.IE10 = 1;
343 break;
344 case FB_AC_N:
345 IEC6bits.ADCAN15IE = 1;
346 ADIELbits.IE15 = 1;
347 break;
348 case IL1_F:
349 IEC5bits.ADCAN0IE = 1;
350 ADIELbits.IE0 = 1;
351 break;
352 case IL2_F:
353 IEC5bits.ADCAN1IE = 1;
354 ADIELbits.IE1 = 1;
355 break;
356 default:
357 break;
358 }
359}
360
368{
369 switch(channel)
370 {
371 case FB_Vout:
372 IEC6bits.ADCAN10IE = 0;
373 ADIELbits.IE10 = 0;
374 break;
375 case FB_AC_N:
376 IEC6bits.ADCAN15IE = 0;
377 ADIELbits.IE15 = 0;
378 break;
379 case IL1_F:
380 IEC5bits.ADCAN0IE = 0;
381 ADIELbits.IE0 = 0;
382 break;
383 case IL2_F:
384 IEC5bits.ADCAN1IE = 0;
385 ADIELbits.IE1 = 0;
386 break;
387 default:
388 break;
389 }
390}
391
399{
400 switch(channel)
401 {
402 case FB_Vout:
403 IFS6bits.ADCAN10IF = 0;
404 break;
405 case FB_AC_N:
406 IFS6bits.ADCAN15IF = 0;
407 break;
408 case IL1_F:
409 IFS5bits.ADCAN0IF = 0;
410 break;
411 case IL2_F:
412 IFS5bits.ADCAN1IF = 0;
413 break;
414 default:
415 break;
416 }
417}
418
426inline static void ADC1_IndividualChannelInterruptPrioritySet(enum ADC_CHANNEL channel, enum INTERRUPT_PRIORITY priorityValue)
427{
428 switch(channel)
429 {
430 case FB_Vout:
431 IPC25bits.ADCAN10IP = priorityValue;
432 break;
433 case FB_AC_N:
434 IPC26bits.ADCAN15IP = priorityValue;
435 break;
436 case IL1_F:
437 IPC22bits.ADCAN0IP = priorityValue;
438 break;
439 case IL2_F:
440 IPC23bits.ADCAN1IP = priorityValue;
441 break;
442 default:
443 break;
444 }
445}
446
455void ADC1_ChannelCallbackRegister(void(*callback)(enum ADC_CHANNEL channel, uint16_t adcVal));
456
466void ADC1_ChannelCallback(enum ADC_CHANNEL channel, uint16_t adcVal);
467
468
476void ADC1_ComparatorCallbackRegister(void(*callback)(enum ADC_CMP comparator));
477
484void ADC1_ComparatorCallback(enum ADC_CMP comparator);
485
486
499void ADC1_ChannelTasks(enum ADC_CHANNEL channel);
500
501
502// Section: Interface functions: Dedicated Core
503
511
512
522
523
524#ifdef __cplusplus // Provide C++ Compatibility
525
526 }
527
528#endif
529
530#endif //_ADC1_H
531
This is the generated driver types header file for the ADC driver.
@ 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
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:215
static void ADC1_InterruptFlagClear(void)
Clears interrupt flag manually.
Definition adc1.h:282
ADC_RESOLUTION_TYPE
Defines the supported ADC resolution types.
Definition adc_types.h:91
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.