adc: helper to get voltage

This commit is contained in:
Andrey Gusakov 2022-03-18 12:00:15 +03:00
parent 9add16109b
commit b4c4592972
2 changed files with 8 additions and 2 deletions

View File

@ -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);

View File

@ -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);