From 5aa7d936f3aa87b5303af4783e61ba69208c3d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Fri, 3 Mar 2023 13:11:20 +0100 Subject: [PATCH] voltage / current measure fixed --- solar_panel.X/measure.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/solar_panel.X/measure.c b/solar_panel.X/measure.c index fc8a60c..7033ae2 100644 --- a/solar_panel.X/measure.c +++ b/solar_panel.X/measure.c @@ -42,7 +42,7 @@ uint16_t measure_voltage() sum += measure_adc(VOLTAGE_CHANNEL); } sum /= AVERAGE_SAMPLES; - sum = (sum * ADC_RESOLUTION) / ADC_REFH; + sum = (sum * ADC_REFH) / ADC_RESOLUTION; return (uint16_t)(sum); } @@ -52,9 +52,11 @@ uint16_t measure_current(uint16_t offset) for(int i = 0; i< AVERAGE_SAMPLES; i++){ sum += measure_adc(CURRENT_CHANNEL); } - uint32_t m = (sum / AVERAGE_SAMPLES); + uint32_t m = (sum / AVERAGE_SAMPLES); // m is bits + m = (m * ADC_REFH) / ADC_RESOLUTION; // m is mV + m *= 1000; // m is uV m /= GAIN; - m /= RESISTOR; + m /= RESISTOR; // m is uA if(m <= offset){ m = 0; } else {