From 6d908fb11042bfd4f3a0bd49df93bdcfb917530f Mon Sep 17 00:00:00 2001 From: rusefillc <48498823+rusefillc@users.noreply.github.com> Date: Sat, 4 Feb 2023 21:21:22 -0500 Subject: [PATCH] f1_dual: sample PWM pins first than do math (#190) Co-authored-by: Andrey Gusakov --- firmware/boards/f1_dual/port.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/firmware/boards/f1_dual/port.cpp b/firmware/boards/f1_dual/port.cpp index 5e5f65f..e0d6a9a 100644 --- a/firmware/boards/f1_dual/port.cpp +++ b/firmware/boards/f1_dual/port.cpp @@ -89,13 +89,16 @@ AnalogResult AnalogSample() adcConvert(&ADCD1, &convGroup, adcBuffer, ADC_OVERSAMPLE); - if ((l_heater) && (!palReadPad(L_HEATER_PORT, L_HEATER_PIN))) + bool l_heater_new = !palReadPad(L_HEATER_PORT, L_HEATER_PIN); + bool r_heater_new = !palReadPad(R_HEATER_PORT, R_HEATER_PIN); + + if (l_heater && l_heater_new) { float vbatt_raw = GetMaxSample(adcBuffer, 6) / BATTERY_INPUT_DIVIDER; l_vbatt = BATTERY_FILTER_ALPHA * vbatt_raw + (1.0 - BATTERY_FILTER_ALPHA) * l_vbatt; } - if ((r_heater) && (!palReadPad(R_HEATER_PORT, R_HEATER_PIN))) + if (r_heater && r_heater_new) { float vbatt_raw = GetMaxSample(adcBuffer, 7) / BATTERY_INPUT_DIVIDER; r_vbatt = BATTERY_FILTER_ALPHA * vbatt_raw + (1.0 - BATTERY_FILTER_ALPHA) * r_vbatt;