Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ac phase control #118

Merged
merged 9 commits into from
Oct 25, 2023
Merged

Feature/ac phase control #118

merged 9 commits into from
Oct 25, 2023

Conversation

LukeWalker-CA
Copy link
Contributor

@LukeWalker-CA LukeWalker-CA commented Oct 13, 2023

Phase Control

Phase control works by aligning the start and end of the "on-period" of each heater. If the sum of the "on-period"s overlaps the "PWM period" (e.g. 1000 ms), then it simply loops around, as it is no longer possible to avoid the situation where more than one channel is on at a time

Example: 
Heater0=10%, Heater1=30%, Heater2=10%, Heater3=40%
PWM Period |-|-|-|-|-|-|-|-|-|-|
Heater0    |-|
Heater1      |-----|
Heater2            |-|
Heater3              |-------|
            |   |   |    |
            v   v   v    v
           |0|--1--|2|---3---| |

Heater0=20%, Heater1=50%, Heater2=60%, Heater3=60%
PWM Period |-|-|-|-|-|-|-|-|-|-|
Heater0    |---|
Heater1        |---------|
Heater2                  |-----------|
Heater3                              |-----------|
             |      |  |    |
             v      v  v    v
           |-0-|----1----|--2--|
           |--2--|-----3-----| |

In example 2, both 0 and 2 must be on at the same time, then 1 and 2, then 1 and 3, then 2 and 3. Finally, 2 will be on for 10% on its own.

Unit tests

Unit tests are implemented for several heatCtrl.c functions (not all, at time of writing, but more will come). Unit testing framework GoogleTest is used. Its relatively easy to get going with, and has a good Users Guide

…helloworld) and tests for AC board heatctrl module.

Added python script for running unit tests.
@freddyrios
Copy link

Some questions/comments on how this runs and how it relates to overall control:

what happens if LoopControl sends changes in the middle of a control period?
what happens if LoopControl resends the expected pwm in the middle of a control period?
on a system with 5 ac boards on the same phase, we will likely be turning on at least 5 heaters at a time
if we run pid control on the LoopControl side, is there an impact on when LoopControl vs. each ac board is running its control period?

Copy link

@freddyrios freddyrios left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the build need to be change to run these style of tests?

e.g. currently build steps make it seem not
image

STM32/AC/HeatCtrl/Src/HeatCtrl.c Outdated Show resolved Hide resolved
@LukeWalker-CA
Copy link
Contributor Author

LukeWalker-CA commented Oct 16, 2023

what happens if LoopControl resends the expected pwm in the middle of a control period?

Will be re-sent every 2 seconds. Given the PWM period gets re-organised every time (and is 1 second long), this could have quite a severe impact.

  • Will add an exception so that re-assertions of the same PWM don't reset re-organise the window.

@freddyrios
Copy link

For later reference, the answers we discussed:

what happens if LoopControl sends changes in the middle of a control period?
if we run pid control on the LoopControl side, is there an impact on when LoopControl vs. each ac board is running its control period?

We don't expect LoopControl to send changes more frequently than every 10 seconds when using this feature, so the impact should be well below 10%.

on a system with 5 ac boards on the same phase, we will likely be turning on at least 5 heaters at a time
The feature in this PR is not about max consumption, but about optimizing/minimising the consumption of the pwm values being requested.

Even when using this feature, LoopControl needs to explicitely decide the % it will allow for each heater.

@LukeWalker-CA on the last one, it does mean that we can't share cross boards without peaks e.g. if I want to keep it at 8A I can't give 50% for a heater in 2 AC boards, since they would both be turned on at the same time (well, technically we probably can but they might be turning on together). In that case, if we want to avoid the double on we might want to do it by using full ons and turning at different times on the LoopControl side.

@LukeWalker-CA
Copy link
Contributor Author

LukeWalker-CA commented Oct 16, 2023

After talking with Matias, I realise there will also be an impact on pwmDuration, since the periodBegin of some of the heaters could potentially be set far back in time

  • Remove pwmDuration bug

@LukeWalker-CA
Copy link
Contributor Author

LukeWalker-CA commented Oct 17, 2023

does the build need to be change to run these style of tests?

e.g. currently build steps make it seem not

Eventually the build should run these, but this is a scope creep I don't want for this sprint. adding the unit tests is already enough. I'll add it to next sprint - #119

@LukeWalker-CA
Copy link
Contributor Author

LukeWalker-CA commented Oct 17, 2023

@LukeWalker-CA on the last one, it does mean that we can't share cross boards without peaks e.g. if I want to keep it at 8A I can't give 50% for a heater in 2 AC boards, since they would both be turned on at the same time (well, technically we > probably can but they might be turning on together). In that case, if we want to avoid the double on we might want to do it by using full ons and turning at different times on the LoopControl side.

@freddyrios This behaviour will not have any improvement for the situation you describe, its only within the same board. Also this feature will not make it worse.
But if you wanted to run both heaters on the same board at 50%, then it would be 8A, 100% of the time.

@LukeWalker-CA LukeWalker-CA marked this pull request as ready for review October 17, 2023 13:43
@LukeWalker-CA LukeWalker-CA merged commit 5d74754 into main Oct 25, 2023
3 checks passed
@matias-cphatomics matias-cphatomics deleted the feature/ac-phase-control branch September 13, 2024 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants