diff --git a/firmware/config/boards/hellen/hellen_board_id.cpp b/firmware/config/boards/hellen/hellen_board_id.cpp index 3c648c271d..8a297ed3db 100644 --- a/firmware/config/boards/hellen/hellen_board_id.cpp +++ b/firmware/config/boards/hellen/hellen_board_id.cpp @@ -85,28 +85,16 @@ float HellenBoardIdSolver::solve(float Tc1, float Tc2, float x0, float y, float k1 = iC * Td; k2 = iC * (Tc1 + Td); k3 = iC * (Tc1 - Tc2); - + // the same method works for R (if C is known) or C (if R is known) - float Xcur, Xnext; - Xnext = x0; + auto result = NewtonsMethodSolver::solve(x0, deltaX, 20); - // since we had https://github.com/rusefi/rusefi/issues/4084 let's add paranoia check - // All real cases seem to converge in <= 5 iterations, so we don't need to try more than 20. - int safetyLimit = 20; - do { - if (safetyLimit-- < 0) { - firmwareError(OBD_PCM_Processor_Fault, "hellen boardID is broken"); - break; - } - Xcur = Xnext; - Xnext = Xcur - fx(Xcur) / dfx(Xcur); + if (!result) { + firmwareError(OBD_PCM_Processor_Fault, "hellen boardID is broken"); + return 0; + } -#ifdef HELLEN_BOARD_ID_DEBUG - efiPrintf ("* %f", Xnext); -#endif /* HELLEN_BOARD_ID_DEBUG */ - } while (absF(Xnext - Xcur) > deltaX); - - return Xnext; + return result.Value; } float HellenBoardIdFinderBase::findClosestResistor(float R, bool testOnlyMajorSeries, int *rIdx) { diff --git a/firmware/config/boards/hellen/hellen_board_id.h b/firmware/config/boards/hellen/hellen_board_id.h index d27c55e03d..c6e39ab0b8 100644 --- a/firmware/config/boards/hellen/hellen_board_id.h +++ b/firmware/config/boards/hellen/hellen_board_id.h @@ -27,15 +27,15 @@ public: // We need to solve the following equation for R or C: // X^Td - X^(Tc1+Td) + X^(Tc2-Tc1) - 1 = 0 // where: X = exp(-1/(RC)) -class HellenBoardIdSolver +class HellenBoardIdSolver : public NewtonsMethodSolver { public: - float fx(float x) { + float fx(float x) override { return exp(k1 / x) - exp(k2 / x) + exp(k3 / x) - 1.0; } // first-order derivative - float dfx(float x) { + float dfx(float x) override { return (-1.0f / (x * x)) * (k1 * exp(k1 / x) - k2 * exp(k2 / x) + k3 * exp(k3 / x)); } diff --git a/firmware/libfirmware b/firmware/libfirmware index 8e65946de9..163cee4279 160000 --- a/firmware/libfirmware +++ b/firmware/libfirmware @@ -1 +1 @@ -Subproject commit 8e65946de929c7fafa00ca23f57c86b4e9c4177f +Subproject commit 163cee4279c83f46efccd279ce22006d039fb2bb