From e2d7e3e360e7ebfec6793f0e63ea3d3329bef8f7 Mon Sep 17 00:00:00 2001 From: Patrik Jonsson Date: Tue, 22 Oct 2024 09:31:04 +0200 Subject: [PATCH] Add filter to current shaper output. --- src/current_shaper.cpp | 9 +++++---- src/current_shaper.h | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/current_shaper.cpp b/src/current_shaper.cpp index 100359fa..533ae1f1 100644 --- a/src/current_shaper.cpp +++ b/src/current_shaper.cpp @@ -177,15 +177,16 @@ void CurrentShaperTask::shapeCurrent() { // if (livepwr > max_pwr) { // livepwr = max_pwr; // } + double max_cur; if(!config_threephase_enabled()) { - _max_cur = ((max_pwr - livepwr) / evse.getVoltage()) + evse.getAmps(); + max_cur = ((max_pwr - livepwr) / evse.getVoltage()) + evse.getAmps(); } else { - _max_cur = ((max_pwr - livepwr) / evse.getVoltage() / 3.0) + evse.getAmps(); + max_cur = ((max_pwr - livepwr) / evse.getVoltage() / 3.0) + evse.getAmps(); } - - + // Smooth shaper output to avoid instability with delayed live power samples. + _max_cur = _outputFilter.filter(max_cur, _max_cur, current_shaper_smoothing_time); _changed = true; } diff --git a/src/current_shaper.h b/src/current_shaper.h index eee7ab28..d6474499 100644 --- a/src/current_shaper.h +++ b/src/current_shaper.h @@ -40,6 +40,7 @@ class CurrentShaperTask: public MicroTasks::Task uint32_t _pause_timer; bool _updated; InputFilter _inputFilter; + InputFilter _outputFilter; protected: void setup();