adc: helper to get voltage
This commit is contained in:
parent
9add16109b
commit
b4c4592972
|
@ -58,10 +58,14 @@ static adcsample_t getAvgAdcValue(int index, adcsample_t *samples, int bufDepth,
|
|||
return static_cast<adcsample_t>(result / bufDepth);
|
||||
}
|
||||
|
||||
adcsample_t getAdcValue(int channel) {
|
||||
adcsample_t getAdcRawValue(int channel) {
|
||||
return getAvgAdcValue(channel, samples, ADC_GRP_BUF_DEPTH, ADC_GRP_NUM_CHANNELS);
|
||||
}
|
||||
|
||||
float getAdcValue(int channel) {
|
||||
return (float)getAdcRawValue(channel) * ADC_VREF / 4096;
|
||||
}
|
||||
|
||||
void initAnalogInputs() {
|
||||
palSetPadMode(GPIOF, 3, PAL_MODE_INPUT_ANALOG);
|
||||
palSetPadMode(GPIOF, 4, PAL_MODE_INPUT_ANALOG);
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
typedef uint16_t adcsample_t;
|
||||
|
||||
#define ADC_GRP_NUM_CHANNELS 3
|
||||
#define ADC_VREF (3.300f)
|
||||
|
||||
void initAnalogInputs();
|
||||
adcsample_t getAdcValue(int channel);
|
||||
adcsample_t getAdcRawValue(int channel);
|
||||
float getAdcValue(int channel);
|
||||
|
|
Loading…
Reference in New Issue