Bar Logo Dual Active Bridge Development Board (Part-No. )
 
Content
     
Loading...
Searching...
No Matches
drv_mcc_extension_adc.h
Go to the documentation of this file.
1
8#ifndef DRV_MCC_EXTENSION_ADC_H
9#define DRV_MCC_EXTENSION_ADC_H
10
11#include <xc.h>
12#include <stdint.h> // include standard integer data types
13#include <stdbool.h> // include standard boolean data types
14#include <stddef.h> // include standard definition data types
15
16
25
27
28
43
45
46
54inline static void ADC_Filter_Enable(uint16_t filterIndex, bool enable)
55{
56 switch (filterIndex)
57 {
58 case 0:
59 ADFL0CONbits.FLEN = (uint16_t)enable;
60 break;
61 case 1:
62 ADFL1CONbits.FLEN = (uint16_t)enable;
63 break;
64 case 2:
65 ADFL2CONbits.FLEN = (uint16_t)enable;
66 break;
67 case 3:
68 ADFL3CONbits.FLEN = (uint16_t)enable;
69 break;
70 default:
71 // index out of range, do nothing
72 break;
73 }
74}
75
76
85inline static void ADC_Filter_Mode(uint16_t filterIndex, ADC_FILTER_MODE_t mode)
86{
87 switch (filterIndex)
88 {
89 case 0:
90 ADFL0CONbits.MODE = (uint16_t)mode;
91 break;
92 case 1:
93 ADFL1CONbits.MODE = (uint16_t)mode;
94 break;
95 case 2:
96 ADFL2CONbits.MODE = (uint16_t)mode;
97 break;
98 case 3:
99 ADFL3CONbits.MODE = (uint16_t)mode;
100 break;
101 default:
102 // do nothing
103 break;
104 }
105}
106
107
116inline static void ADC_Filter_Averaging(uint16_t filterIndex, ADC_FILTER_OVRSAM_AVG_t averagingRatio)
117{
118 switch (filterIndex)
119 {
120 case 0:
121 ADFL0CONbits.OVRSAM = (uint16_t)averagingRatio;
122 break;
123 case 1:
124 ADFL1CONbits.OVRSAM = (uint16_t)averagingRatio;
125 break;
126 case 2:
127 ADFL2CONbits.OVRSAM = (uint16_t)averagingRatio;
128 break;
129 case 3:
130 ADFL3CONbits.OVRSAM = (uint16_t)averagingRatio;
131 break;
132 default:
133 // do nothing
134 break;
135 }
136}
137
138
146inline static void ADC_Filter_Input(uint16_t filterIndex, uint16_t channelIndex)
147{
148 if (channelIndex <= 25)
149 {
150 switch (filterIndex)
151 {
152 case 0:
153 ADFL0CONbits.FLCHSEL = channelIndex;
154 break;
155 case 1:
156 ADFL1CONbits.FLCHSEL = channelIndex;
157 break;
158 case 2:
159 ADFL2CONbits.FLCHSEL = channelIndex;
160 break;
161 case 3:
162 ADFL3CONbits.FLCHSEL = channelIndex;
163 break;
164 default:
165 // do nothing
166 break;
167 }
168 }
169}
170
171
178inline static uint16_t ADC_Filter_GetResult(uint16_t filterIndex)
179{
180 uint16_t filterResult = 0;
181 switch (filterIndex)
182 {
183 case 0:
184 filterResult = ADFL0DAT;
185 break;
186 case 1:
187 filterResult = ADFL1DAT;
188 break;
189 case 2:
190 filterResult = ADFL2DAT;
191 break;
192 case 3:
193 filterResult = ADFL3DAT;
194 break;
195 default:
196 break;
197 }
198 return (filterResult);
199}
200
201#endif /* DRV_MC_EXTENSION_ADC_H */
202
enum ADC_FILTER_MODE_e ADC_FILTER_MODE_t
enum ADC_FILTER_OVRSAM_AVG_e ADC_FILTER_OVRSAM_AVG_t
static void ADC_Filter_Input(uint16_t filterIndex, uint16_t channelIndex)
Sets the ADC instance to be filtered.
static void ADC_Filter_Mode(uint16_t filterIndex, ADC_FILTER_MODE_t mode)
Sets the ADC instance filter mode.
static void ADC_Filter_Enable(uint16_t filterIndex, bool enable)
Enables the ADC filter feature of the ADC.
static void ADC_Filter_Averaging(uint16_t filterIndex, ADC_FILTER_OVRSAM_AVG_t averagingRatio)
Sets the ADC instance number of samples to average.
ADC_FILTER_MODE_e
ADC Filter Modes of operation.
ADC_FILTER_OVRSAM_AVG_e
ADC Filter Oversampling Ratio when in averaging mode.
static uint16_t ADC_Filter_GetResult(uint16_t filterIndex)
Gets the ADC filter result.
@ ADC_FILTER_MODE_AVERAGING
@ ADC_FILTER_MODE_OVERSAMPLING
@ ADC_FILTER_OVRSAM_AVG_8x
@ ADC_FILTER_OVRSAM_AVG_4x
@ ADC_FILTER_OVRSAM_AVG_64x
@ ADC_FILTER_OVRSAM_AVG_16x
@ ADC_FILTER_OVRSAM_AVG_32x
@ ADC_FILTER_OVRSAM_AVG_256x
@ ADC_FILTER_OVRSAM_AVG_2x
@ ADC_FILTER_OVRSAM_AVG_128x