From b4cfb40bb7469135e8037bb5bf2caa286c4db8e6 Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Fri, 31 Jul 2020 18:22:52 +0200 Subject: [PATCH] fw: Fix battery voltage calculation --- firmware/batmon.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/firmware/batmon.c b/firmware/batmon.c index aafc715..c70e9ca 100644 --- a/firmware/batmon.c +++ b/firmware/batmon.c @@ -33,15 +33,14 @@ uint8_t batmon_proc() if (ADCSRA & (1 << ADIF)) { sum += ADCH; - if (!(cnt++)) { + if (!(++cnt)) { vbat = sum >> 8; sum = 0; + if (vbat < BAT_THRES_POWER_OFF) + return 1; } - vbat = ADCH; ADCSRA &= ~(1 << ADIF); ADCSRA |= (1 << ADSC); // TODO: I want this to work off TIMER0 - if (vbat < BAT_THRES_POWER_OFF) - return 1; } return 0; }