-
Notifications
You must be signed in to change notification settings - Fork 13
Refactor core calculation out of buck / boost converters #407
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
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d2ae088
Update AbstractPowerConverters.py
ducky64 bfeb033
Update AbstractPowerConverters.py
ducky64 cededec
diff clean
ducky64 70d94e3
Update AbstractPowerConverters.py
ducky64 d038cca
boost converter update + better constraintexpr conversions
ducky64 2b1353c
Update ConstraintExpr.py
ducky64 d32609b
Update ConstraintExpr.py
ducky64 890e4fa
merge buckboost
ducky64 f3fd7d6
Update AbstractPowerConverters.py
ducky64 fd31e69
range hull / intersect unit test
ducky64 eaadc3a
Create test_switching_converters.py
ducky64 c4a9415
unit tests
ducky64 cc1cbd3
remove fcml specific params
ducky64 b69e287
wip
ducky64 d69cbd2
cleaning
ducky64 b536eaa
Update test_range.py
ducky64 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import unittest | ||
|
|
||
| from .AbstractPowerConverters import BuckConverterPowerPath, BoostConverterPowerPath | ||
| from ..core import Range | ||
|
|
||
|
|
||
| class BuckConverterCalculationTest(unittest.TestCase): | ||
| def test_buck_converter(self): | ||
| values_ref = BuckConverterPowerPath.calculate_parameters( | ||
| Range.exact(5), Range.exact(2.5), Range.exact(100e3), Range.exact(1), | ||
| Range.exact(0.1), 0.01, 0.001, | ||
| efficiency=Range.exact(1) | ||
| ) | ||
| self.assertEqual(values_ref.dutycycle, Range.exact(0.5)) | ||
| # validated against https://www.omnicalculator.com/physics/buck-converter | ||
| self.assertEqual(values_ref.inductance, Range.exact(125e-6)) | ||
|
|
||
| # test that component values are calculated for worst-case conversion | ||
| values = BuckConverterPowerPath.calculate_parameters( | ||
| Range(4, 5), Range(2.5, 4), Range.exact(100e3), Range.exact(1), | ||
| Range.exact(0.1), 0.01, 0.001, | ||
| efficiency=Range.exact(1) | ||
| ) | ||
| self.assertEqual(values_ref.inductance, values.inductance) | ||
| self.assertEqual(values_ref.input_capacitance, values.input_capacitance) | ||
| self.assertEqual(values_ref.output_capacitance, values.output_capacitance) | ||
|
|
||
| def test_buck_converter_example(self): | ||
| # using the example from https://passive-components.eu/buck-converter-design-and-calculation/ | ||
| values = BuckConverterPowerPath.calculate_parameters( | ||
| Range.exact(12 + 0.4), Range.exact(3.3 + 0.4), Range.exact(500e3), Range.exact(1), | ||
| Range.exact(0.35), 1, 0.0165, | ||
| efficiency=Range.exact(1) | ||
| ) | ||
| self.assertAlmostEqual(values.dutycycle.upper, 0.298, places=3) | ||
| self.assertAlmostEqual(values.inductance.upper, 14.8e-6, places=7) | ||
|
|
||
| # the example uses a ripple current of 0.346 for the rest of the calculations | ||
| values = BuckConverterPowerPath.calculate_parameters( | ||
| Range.exact(12 + 0.4), Range.exact(3.3 + 0.4), Range.exact(500e3), Range.exact(1), | ||
| Range.exact(0.346), 1, 0.0165, | ||
| efficiency=Range.exact(1) | ||
| ) | ||
| self.assertAlmostEqual(values.inductor_peak_currents.upper, 1.173, places=3) | ||
| self.assertAlmostEqual(values.output_capacitance.lower, 5.24e-6, places=7) | ||
|
|
||
| def test_boost_converter(self): | ||
| values_ref = BoostConverterPowerPath.calculate_parameters( | ||
| Range.exact(5), Range.exact(10), Range.exact(100e3), Range.exact(1), | ||
| Range.exact(0.1), 0.01, 0.001, | ||
| efficiency=Range.exact(1) | ||
| ) | ||
| self.assertEqual(values_ref.dutycycle, Range.exact(0.5)) | ||
| # validated against https://www.omnicalculator.com/physics/boost-converter | ||
| self.assertEqual(values_ref.inductance, Range.exact(250e-6)) | ||
|
|
||
| # test that component values are calculated for worst-case conversion | ||
| values = BoostConverterPowerPath.calculate_parameters( | ||
| Range(5, 8), Range(7, 10), Range.exact(100e3), Range.exact(1), | ||
| Range.exact(0.1), 0.01, 0.001, | ||
| efficiency=Range.exact(1) | ||
| ) | ||
| self.assertEqual(values_ref.inductance, values.inductance) | ||
| self.assertEqual(values_ref.input_capacitance, values.input_capacitance) | ||
| self.assertEqual(values_ref.output_capacitance, values.output_capacitance) | ||
|
|
||
| def test_boost_converter_example(self): | ||
| # using the example from https://passive-components.eu/boost-converter-design-and-calculation/ | ||
| # 0.4342A ripple current from .35 factor in example converted in output current terms | ||
| values = BoostConverterPowerPath.calculate_parameters( | ||
| Range.exact(5), Range.exact(12 + 0.4), Range.exact(500e3), Range.exact(0.5), | ||
| Range.exact(0.4342), 1, 1, | ||
| efficiency=Range.exact(1) | ||
| ) | ||
| self.assertAlmostEqual(values.dutycycle.upper, 0.597, places=3) | ||
| self.assertAlmostEqual(values.inductance.upper, 13.75e-6, places=7) | ||
|
|
||
| # the example continues with a normalized inductance of 15uH | ||
| values = BoostConverterPowerPath.calculate_parameters( | ||
| Range.exact(5), Range.exact(12 + 0.4), Range.exact(500e3), Range.exact(0.5), | ||
| Range.exact(.4342*13.75/15), 0.01, 0.06, | ||
| efficiency=Range.exact(1) | ||
| ) | ||
| self.assertAlmostEqual(values.dutycycle.upper, 0.597, places=3) | ||
| self.assertAlmostEqual(values.inductance.upper, 15.0e-6, places=7) | ||
| self.assertAlmostEqual(values.inductor_peak_currents.upper, 1.44, places=2) | ||
| # the example calculation output is wrong, this is the correct result of the formula | ||
| self.assertAlmostEqual(values.output_capacitance.lower, 9.95e-6, places=7) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using an
asserthere will be skipped if Python is run with optimizations. Consider raising aValueErrorfor invalid intersection to ensure the check always runs.