Standard Table 2-Resistor Divider Calculator
See Under the Hood for why this uses NumPy. I'm (maybe unfairly) assuming you have NumPy installed if you are using this outside of Circuits 101.
usage: Standard Table 2-Resistor Divider Calculator [-h]
[--table {E12,E24,E48,E96}]
[--prefer-over]
[--prefer-under]
Vin Vout
positional arguments:
Vin divider input voltage
Vout divider output voltage
optional arguments:
-h, --help show this help message and exit
--table {E12,E24,E48,E96}
resistor table, defaults to E12
--prefer-over ignore solutions with lower Vout
--prefer-under ignore solutions with higher Vout
I search a pairwise error grid to find the resistor pair (calculation is very fast, I promise). A pairwise grid of numbers is a matrix. NumPy is the go-to for dealing with matrices in Python.
Really, I was avoiding homework.
Technically, voltage dividers only prescribe a ratio (hence "divider"), but a standard form voltage divider needs 2 resistors. That's 1 equation, 2 unknowns. Futhermore, resistors are only available in certain values. This gives the circuit designer a knapsack problem to solve, instead of a degree of freedom to fix arbitrarily.
If you haven't seen standard resistor tables, you very much should. They are a manufacturing and supply chain wonder.
Admittedly, it is good/quick enough to pick a few resistors and find their relevant pair, but again, I was avoiding homework.
- Compute the divider resistor ratio,
k
- Constrain the resistor ratio to [1,10] using
log10
. - Compute the error ratio error matrix,
d = rtable*k-rtable.T
- Only look at the upper triangular portion of
d
, which is skew-symmetric - Ignore positive, negative, or no error entries, depending on user input
- Convert to absolute error
- Construct the "best column" - for each row, find the column with least absolute error
- Find the "best row" - the row with least absolute error in the "best column"
- The best column index gives R1, and the best row index gives R2
- Scale R1 by the the original
k
order of magnitude - Print R1,R2
Claim: Consider a solved minimum-error resistor ratio pair, R1 and R2. In implementation and in theory, if the ratio is increased by a factor of 10, there exists a minimum-error solution such that R2'=R2 and R1'=10R1.
Proof:
- Notice that R1 scales with the ratio. That handles the "theory" part nicely
- As for practice, resistor values come in "decades," or multiples of 10. For every resistor value listed in a table, a resistor with the same coefficient, but a different order of magnitude is available, e.g. 1.2->12->120->0.0012->etc. Such is the wonder of standard resistor tables.
Corollary: Any minimum-error voltage divider problem can be solved using the coefficient of the desired resistor ratio, as it would appear represented in scientific notation, without loss of generality.
The resistor values used in this CLI were downloaded and regex'd from this electronics-notes.com article. Although resistor tables are standardized, the article embedded the values in an html table, which made automating input very easy.
This project is licensed under the MIT License. See LICENSE for more details.