|  | 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
20 enum ADC_FILTER_MODE_e
21{
22 ADC_FILTER_MODE_OVERSAMPLING = 0,
23 ADC_FILTER_MODE_AVERAGING = 3
24};
25
26 typedef enum ADC_FILTER_MODE_e ADC_FILTER_MODE_t;
27
28
32 enum ADC_FILTER_OVRSAM_AVG_e
33{
34 ADC_FILTER_OVRSAM_AVG_2x = 0,
35 ADC_FILTER_OVRSAM_AVG_4x = 1,
36 ADC_FILTER_OVRSAM_AVG_8x = 2,
37 ADC_FILTER_OVRSAM_AVG_16x = 3,
38 ADC_FILTER_OVRSAM_AVG_32x = 4,
39 ADC_FILTER_OVRSAM_AVG_64x = 5,
40 ADC_FILTER_OVRSAM_AVG_128x = 6,
41 ADC_FILTER_OVRSAM_AVG_256x = 7,
42};
43
44 typedef enum ADC_FILTER_OVRSAM_AVG_e ADC_FILTER_OVRSAM_AVG_t;
45
46
54 inline 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
85 inline 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
116 inline 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
146 inline 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
178 inline 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
ADC_FILTER_MODE_t
enum ADC_FILTER_MODE_e ADC_FILTER_MODE_t
Definition drv_mcc_extension_adc.h:26
ADC_FILTER_OVRSAM_AVG_t
enum ADC_FILTER_OVRSAM_AVG_e ADC_FILTER_OVRSAM_AVG_t
Definition drv_mcc_extension_adc.h:44
ADC_Filter_Input
static void ADC_Filter_Input(uint16_t filterIndex, uint16_t channelIndex)
Sets the ADC instance to be filtered.
Definition drv_mcc_extension_adc.h:146
ADC_Filter_Mode
static void ADC_Filter_Mode(uint16_t filterIndex, ADC_FILTER_MODE_t mode)
Sets the ADC instance filter mode.
Definition drv_mcc_extension_adc.h:85
ADC_Filter_Enable
static void ADC_Filter_Enable(uint16_t filterIndex, bool enable)
Enables the ADC filter feature of the ADC.
Definition drv_mcc_extension_adc.h:54
ADC_Filter_Averaging
static void ADC_Filter_Averaging(uint16_t filterIndex, ADC_FILTER_OVRSAM_AVG_t averagingRatio)
Sets the ADC instance number of samples to average.
Definition drv_mcc_extension_adc.h:116
ADC_FILTER_MODE_e
ADC_FILTER_MODE_e
ADC Filter Modes of operation.
Definition drv_mcc_extension_adc.h:21
ADC_FILTER_OVRSAM_AVG_e
ADC_FILTER_OVRSAM_AVG_e
ADC Filter Oversampling Ratio when in averaging mode.
Definition drv_mcc_extension_adc.h:33
ADC_Filter_GetResult
static uint16_t ADC_Filter_GetResult(uint16_t filterIndex)
Gets the ADC filter result.
Definition drv_mcc_extension_adc.h:178
ADC_FILTER_MODE_AVERAGING
@ ADC_FILTER_MODE_AVERAGING
Definition drv_mcc_extension_adc.h:23
ADC_FILTER_MODE_OVERSAMPLING
@ ADC_FILTER_MODE_OVERSAMPLING
Definition drv_mcc_extension_adc.h:22
ADC_FILTER_OVRSAM_AVG_8x
@ ADC_FILTER_OVRSAM_AVG_8x
Definition drv_mcc_extension_adc.h:36
ADC_FILTER_OVRSAM_AVG_4x
@ ADC_FILTER_OVRSAM_AVG_4x
Definition drv_mcc_extension_adc.h:35
ADC_FILTER_OVRSAM_AVG_64x
@ ADC_FILTER_OVRSAM_AVG_64x
Definition drv_mcc_extension_adc.h:39
ADC_FILTER_OVRSAM_AVG_16x
@ ADC_FILTER_OVRSAM_AVG_16x
Definition drv_mcc_extension_adc.h:37
ADC_FILTER_OVRSAM_AVG_32x
@ ADC_FILTER_OVRSAM_AVG_32x
Definition drv_mcc_extension_adc.h:38
ADC_FILTER_OVRSAM_AVG_256x
@ ADC_FILTER_OVRSAM_AVG_256x
Definition drv_mcc_extension_adc.h:41
ADC_FILTER_OVRSAM_AVG_2x
@ ADC_FILTER_OVRSAM_AVG_2x
Definition drv_mcc_extension_adc.h:34
ADC_FILTER_OVRSAM_AVG_128x
@ ADC_FILTER_OVRSAM_AVG_128x
Definition drv_mcc_extension_adc.h:40