Add filter to current shaper output. #920
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As I described in #901, I've been having problems with instabilities in the current shaper. From looking at the issues, it appears that others have as well. I can replicate the problem by artificially delaying the incoming live power samples by about one sample. (This kind of delay is not unreasonable given that the live power may travel from the meter to some cloud provider and back to the evse.) This makes sense since the current implementation has unit gain, ie it tries to correct the entire power mismatch in one step. If the input power is delayed one step, that will then put the corrections 90 degrees out of phase with the input, causing instability.
This PR adds an instance of the IIR filter used for input smoothing to the current shaper calculated max current. By filtering the shaper output so it doesn't attempt to correct the entire mismatch in one step, the gain can be lowered so it's stable regardless of input delay.
The graph below shows a test. Initially the filter time constant is set to zero, mimicking the current implementation. The session starts at 8:57, and just after 9:00 a load is switched on and the shaper becomes active. The max current is 20A and the shaper should limit the charge current to 10A, but oscillates between 6-16A. At 9:04 another load is switched on and the shaper pauses the charge. At 9:06 that load switches off and the charge resumes, reentering the same oscillation.
Just before 9:10, the filter time constant is changed to 10s and the change in this PR becomes active. 10s is enough filtering for the oscillation to damp out in about 90s and the charge current stabilizes with a live load of 20A as designed. Just after 9:17, all loads are disconnected and, after a small overshoot, the current shaper stabilizes at 19A free current which is larger than the pilot max, so it becomes inactive.