From 81dedcbf6eb77a9455ad3187c22686b258b06fab Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Tue, 26 Sep 2023 20:40:46 +0200 Subject: [PATCH] Fix for negative calculated L2 current --- src/IEC6205675.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/IEC6205675.cpp b/src/IEC6205675.cpp index 1922abfe..5dc8f03f 100644 --- a/src/IEC6205675.cpp +++ b/src/IEC6205675.cpp @@ -488,7 +488,8 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, MeterConfig* meterCo if(meterConfig->distributionSystem == 1) { if(threePhase) { if(l2current == 0.0 && l1current > 0.0 && l3current > 0.0) { - l2current = (((activeImportPower - activeExportPower) * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage; + int32_t absPower = ((int32_t) activeImportPower) - ((int32_t) activeExportPower); + l2current = ((absPower * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage; if(activeExportPower == 0.0) { l2current = max((float) 0.0, l2current); }