Skip to content

Commit

Permalink
Fix: VE.Direct: take the load current into account
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
SW-Niko authored and schlimmchen committed May 2, 2024
1 parent 686b5df commit 6620ab4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/VeDirectFrameHandler/VeDirectMpptController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int16_t>(_tmpFrame.batteryVoltage_V_mV * _tmpFrame.batteryCurrent_I_mA / 1000000);
// power into the battery, (+) means charging, (-) means discharging
_tmpFrame.batteryOutputPower_W = static_cast<int16_t>((_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<uint32_t>(_tmpFrame.panelPower_PPV_W * 1000000) / _tmpFrame.panelVoltage_VPV_mV;
_tmpFrame.panelCurrent_mA = static_cast<uint32_t>(_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<float>(_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; }
Expand Down

0 comments on commit 6620ab4

Please sign in to comment.