Bar Logo 4kW dsPIC33C PSFB DC-DC DA (Part-No. )
 
Content
     
Loading...
Searching...
No Matches
drv_mcc_extension_adc.h
Go to the documentation of this file.
1
7#ifndef DRV_MCC_EXTENSION_ADC_H
8#define DRV_MCC_EXTENSION_ADC_H
9
10#include <xc.h>
11#include <stdint.h> // include standard integer data types
12#include <stdbool.h> // include standard boolean data types
13#include <stddef.h> // include standard definition data types
14
15
24
26
27
42
44
45
53inline static void ADC_Filter_Enable(uint16_t filterIndex, bool enable)
54{
55 switch (filterIndex)
56 {
57 case 0:
58 ADFL0CONbits.FLEN = (uint16_t)enable;
59 break;
60 case 1:
61 ADFL1CONbits.FLEN = (uint16_t)enable;
62 break;
63 case 2:
64 ADFL2CONbits.FLEN = (uint16_t)enable;
65 break;
66 case 3:
67 ADFL3CONbits.FLEN = (uint16_t)enable;
68 break;
69 default:
70 // index out of range, do nothing
71 break;
72 }
73}
74
75
84inline static void ADC_Filter_Mode(uint16_t filterIndex, ADC_FILTER_MODE_t mode)
85{
86 switch (filterIndex)
87 {
88 case 0:
89 ADFL0CONbits.MODE = (uint16_t)mode;
90 break;
91 case 1:
92 ADFL1CONbits.MODE = (uint16_t)mode;
93 break;
94 case 2:
95 ADFL2CONbits.MODE = (uint16_t)mode;
96 break;
97 case 3:
98 ADFL3CONbits.MODE = (uint16_t)mode;
99 break;
100 default:
101 // do nothing
102 break;
103 }
104}
105
106
115inline static void ADC_Filter_Averaging(uint16_t filterIndex, ADC_FILTER_OVRSAM_AVG_t averagingRatio)
116{
117 switch (filterIndex)
118 {
119 case 0:
120 ADFL0CONbits.OVRSAM = (uint16_t)averagingRatio;
121 break;
122 case 1:
123 ADFL1CONbits.OVRSAM = (uint16_t)averagingRatio;
124 break;
125 case 2:
126 ADFL2CONbits.OVRSAM = (uint16_t)averagingRatio;
127 break;
128 case 3:
129 ADFL3CONbits.OVRSAM = (uint16_t)averagingRatio;
130 break;
131 default:
132 // do nothing
133 break;
134 }
135}
136
137
145inline static void ADC_Filter_Input(uint16_t filterIndex, uint16_t channelIndex)
146{
147 if (channelIndex <= 25)
148 {
149 switch (filterIndex)
150 {
151 case 0:
152 ADFL0CONbits.FLCHSEL = channelIndex;
153 break;
154 case 1:
155 ADFL1CONbits.FLCHSEL = channelIndex;
156 break;
157 case 2:
158 ADFL2CONbits.FLCHSEL = channelIndex;
159 break;
160 case 3:
161 ADFL3CONbits.FLCHSEL = channelIndex;
162 break;
163 default:
164 // do nothing
165 break;
166 }
167 }
168}
169
170
177inline static uint16_t ADC_Filter_GetResult(uint16_t filterIndex)
178{
179 uint16_t filterResult = 0;
180 switch (filterIndex)
181 {
182 case 0:
183 filterResult = ADFL0DAT;
184 break;
185 case 1:
186 filterResult = ADFL1DAT;
187 break;
188 case 2:
189 filterResult = ADFL2DAT;
190 break;
191 case 3:
192 filterResult = ADFL3DAT;
193 break;
194 default:
195 break;
196 }
197 return (filterResult);
198}
199
200#endif /* DRV_MC_EXTENSION_ADC_H */
201
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