From 684760babd9d6209d1c7916fb415ce9fb150517e Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Sun, 20 Sep 2020 13:39:14 -0700 Subject: [PATCH] scale properly to volts --- firmware/analog_input.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/firmware/analog_input.cpp b/firmware/analog_input.cpp index 803e075..cb2b2fa 100644 --- a/firmware/analog_input.cpp +++ b/firmware/analog_input.cpp @@ -25,7 +25,9 @@ static float AverageSamples(adcsample_t* buffer, size_t idx) idx += ADC_OVERSAMPLE; } - return (float)sum / ADC_OVERSAMPLE; + constexpr float scale = 3.3f / (2048 * ADC_OVERSAMPLE); + + return (float)sum * scale; } AnalogResult AnalogSample()