From 6620ab487a898c102158351941450ac0c8a6fbd6 Mon Sep 17 00:00:00 2001 From: SW-Nico Date: Thu, 11 Apr 2024 10:03:55 +0200 Subject: [PATCH] Fix: VE.Direct: take the load current into account when calculating efficiency, we need to take into account that the load might also sink a significant amount of current and power, which adds to the total output of the charge controller. --- .../VeDirectMpptController.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/VeDirectFrameHandler/VeDirectMpptController.cpp b/lib/VeDirectFrameHandler/VeDirectMpptController.cpp index de3a7a59b..f1bd00dec 100644 --- a/lib/VeDirectFrameHandler/VeDirectMpptController.cpp +++ b/lib/VeDirectFrameHandler/VeDirectMpptController.cpp @@ -84,15 +84,23 @@ bool VeDirectMpptController::processTextDataDerived(std::string const& name, std * This function is called at the end of the received frame. */ void VeDirectMpptController::frameValidEvent() { - _tmpFrame.batteryOutputPower_W = static_cast(_tmpFrame.batteryVoltage_V_mV * _tmpFrame.batteryCurrent_I_mA / 1000000); + // power into the battery, (+) means charging, (-) means discharging + _tmpFrame.batteryOutputPower_W = static_cast((_tmpFrame.batteryVoltage_V_mV / 1000.0f) * (_tmpFrame.batteryCurrent_I_mA / 1000.0f)); + // calculation of the panel current if ((_tmpFrame.panelVoltage_VPV_mV > 0) && (_tmpFrame.panelPower_PPV_W >= 1)) { - _tmpFrame.panelCurrent_mA = static_cast(_tmpFrame.panelPower_PPV_W * 1000000) / _tmpFrame.panelVoltage_VPV_mV; + _tmpFrame.panelCurrent_mA = static_cast(_tmpFrame.panelPower_PPV_W * 1000000.0f / _tmpFrame.panelVoltage_VPV_mV); + } else { + _tmpFrame.panelCurrent_mA = 0; } + // calculation of the MPPT efficiency + float totalPower_W = (_tmpFrame.loadCurrent_IL_mA / 1000.0f + _tmpFrame.batteryCurrent_I_mA / 1000.0f) * _tmpFrame.batteryVoltage_V_mV /1000.0f; if (_tmpFrame.panelPower_PPV_W > 0) { - _efficiency.addNumber(static_cast(_tmpFrame.batteryOutputPower_W * 100) / _tmpFrame.panelPower_PPV_W); + _efficiency.addNumber(totalPower_W * 100.0f / _tmpFrame.panelPower_PPV_W); _tmpFrame.mpptEfficiency_Percent = _efficiency.getAverage(); + } else { + _tmpFrame.mpptEfficiency_Percent = 0.0f; } if (!_canSend) { return; }