From 52f306b6f5f8c5a4adf3d84dbd5dac7fe9fc466c Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Fri, 17 Nov 2023 18:19:55 -0800 Subject: [PATCH] avoid NaN in case of zero battery voltage --- firmware/heater_control.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/heater_control.cpp b/firmware/heater_control.cpp index 7594814..a0b5244 100644 --- a/firmware/heater_control.cpp +++ b/firmware/heater_control.cpp @@ -178,7 +178,7 @@ void HeaterControllerBase::Update(const ISampler& sampler, HeaterAllow heaterAll } // duty = (V_eff / V_batt) ^ 2 - float voltageRatio = heaterVoltage / batteryVoltage; + float voltageRatio = (batteryVoltage < 1.0f) ? 0 : heaterVoltage / batteryVoltage; float duty = voltageRatio * voltageRatio; #ifdef HEATER_MAX_DUTY