# EEVblog Electronics Community Forum

## Electronics => Projects, Designs, and Technical Stuff => Topic started by: slugrustle on April 02, 2018, 02:25:26 am

Title: Voltage Divider Calculators
Post by: slugrustle on April 02, 2018, 02:25:26 am
I recently spruced up two voltage divider calculators

https://github.com/slugrustle/voltage_divider/releases (https://github.com/slugrustle/voltage_divider/releases)  (two resistor version)
https://github.com/slugrustle/high_voltage_divider/releases (https://github.com/slugrustle/high_voltage_divider/releases)  (three resistor version)

that solve for voltage dividers nearest a target ratio using real world resistor values (ones you can actually buy). Each calculator is a single .html file that you can run locally; the calculations are performed with inline Javascript.

Comments, feedback, and bug reports are welcome. I've found these useful and hope others do as well.
Title: Re: Voltage Divider Calculators
Post by: link87 on April 02, 2018, 07:29:41 pm
Nice work! I like that you account for tolerances on the resistors, too.
Title: Re: Voltage Divider Calculators
Post by: Simon on April 02, 2018, 08:31:53 pm
nice job
Title: Re: Voltage Divider Calculators
Post by: Vgkid on April 02, 2018, 08:55:30 pm
Nice job , had a quick mess around with it.
Title: Re: Voltage Divider Calculators
Post by: xani on April 03, 2018, 05:19:31 am
You can use Github pages ( https://pages.github.com/ ) to host your calculator directly :)

I've been using ElectroDroid (android app) for that and one thing it has over yours is ability to specify load resistance and include it into calculation. But it doesn't have 3 resistor mode so IMO it's a draw:). And the table output is very nice feature too.

Other is personal quirk but entering a ratio as a fraction doesn't seem very convenient, Vi/Vo as an option would be nice. ElectroDroid also had an option where you just entered input and output voltage and it calculated ratio for you
Title: Re: Voltage Divider Calculators
Post by: slugrustle on April 08, 2018, 09:15:27 pm
Thanks, xani, for the GitHub pages suggestion. I've put a page that links to both calculators at

https://slugrustle.github.io/ (https://slugrustle.github.io/)

Edit: A coworker asked for the ability to put a four-function calculator expression in the "Target Ratio" input. I've written a parser but have yet to fully test and integrate it. Your thoughts, xani?
Title: Re: Voltage Divider Calculators
Post by: slugrustle on April 11, 2018, 03:33:24 am
I just fixed a pretty serious bug that broke searches for minimum and maximum tolerance ratios in the three-resistor calculator. I also updated both calculators to accept mathematical expressions for the target ratio input (operators +, -, *, /, and parens). The latest is always at https://slugrustle.github.io/ (https://slugrustle.github.io/).

Not much else to do on these besides more testing, and maybe a nicer interface. I might make a calculator for comparator with hysteresis circuits at some point.
Title: Re: Voltage Divider Calculators
Post by: T3sl4co1l on April 11, 2018, 07:23:48 am
Cool!

Nice touch to use inline SVG and scripts, I guess, makes it nice and compact. Also didn't realize what's involved in creating (or conversely, parsing) an XLSX, interesting.

It's kinda redundant because these exist,
http://jansson.us/resistors.html (http://jansson.us/resistors.html)
http://kirr.homeunix.org/electronics/resistor-network-finder/ (http://kirr.homeunix.org/electronics/resistor-network-finder/)
https://www.seventransistorlabs.com/Calc/ResDiv.html (https://www.seventransistorlabs.com/Calc/ResDiv.html)
(among others)

Though it does have a slightly different twist, that's missing from the others, and may be helpful.

I noticed the problem, the other night, of having to combine the former two: one, to select resistors by given ratio; the other, to select resistors from a given set (not necessarily E-series, or the full series anyways).  Satisfying both, is not a problem solved by either, alone.

...Kirill lurks around here, maybe he's watching this thread? :D

Tim
Title: Re: Voltage Divider Calculators
Post by: slugrustle on April 15, 2018, 03:59:00 pm
Just updated the two-resistor divider calculator to make the interface nicer (and the underlying code cleaner). Will update the three-resistor one after I do my taxes.

Thanks, T3sl4co1l, for the links. I think jansson's is the closest to the design goals that I have for these calculators.

1. Find optimal dividers using resistor values that can be purchased
2. Calculator is a single file that can run locally on most computers
3. Ability to target minimum, nominal, or maximum ratio over resistor tolerance
4. Ability to limit results based on string resistance
5. Calculator interface contains all info required to use it
6. Results are computed quickly (< 1 second)

I had previously made a brute force program that solved two and three resistor dividers in various configurations, but it was command line based and written in python (three resistor case was slow). Rewriting in C++ gave a 30x speedup, but I wanted to use it at work and thought that program would be too difficult to explain or share if someone else wanted to use it. I realized that web technologies could solve both the portability and usability problems of a command line program, while still running locally. Learning to use JavaScript, CSS, SVG, etc. has been quite fun.

The spreadsheet output is a response to a feature request from a coworker. He wanted the calculator to compute quiescent current for the dividers. Since that requires information not related to the resistors themselves, I figured he could compute whatever he wanted if I added spreadsheet output. I would have left it at .csv, but I wrote a .docx report generator at a previous job and have wanted to figure out .xlsx spreadsheet generation ever since (they are both part of Office Open XML).

"Also didn't realize what's involved in creating (or conversely, parsing) an XLSX, interesting."

There are two ways to look at this:

1. XLSX is just some .xml files in a .zip archive. Put what you want in Excel, unzip it, and automate the parts that can change.
2. Read the ECMA376 standard; it's 6045 pages of interesting :)   https://www.ecma-international.org/publications/standards/Ecma-376.htm (https://www.ecma-international.org/publications/standards/Ecma-376.htm)

I did enough of (2) to make (1) efficient, and to be able to only keep in what I needed (e.g. not the standard office themes). ECMA376 is so long because it covers .docx, .xslx, .pptx, the markup for drawings in Office, and some other shared features. It's well organized and helpful and contains the unintentionally hilarious phrase "End of informative text."
Title: Re: Voltage Divider Calculators
Post by: Kirr on April 24, 2018, 01:18:34 am
Nice tool, slugrustle! I'd be curious to see it try other topologies automatically. I.e., three-resistor divider can use one upper and two lower resistors. Reminds me to try making a similar tool some day too. Fun! :-+
Title: Re: Voltage Divider Calculators
Post by: Kirr on April 24, 2018, 01:29:22 am
It's kinda redundant because these exist,
http://jansson.us/resistors.html (http://jansson.us/resistors.html)
http://kirr.homeunix.org/electronics/resistor-network-finder/ (http://kirr.homeunix.org/electronics/resistor-network-finder/)
https://www.seventransistorlabs.com/Calc/ResDiv.html (https://www.seventransistorlabs.com/Calc/ResDiv.html)
(among others)
My tool unfortunately does not care about ratio, so can't make an optimal divider. You have to fix either upper or lower resistance, and then it will find the fitting counterpart, but it does not optimize the entire divider. But as you say a number of nice divider finders exist already. Still I think much more can be done in this area.

Quote
...Kirill lurks around here, maybe he's watching this thread? :D
Now noticed it! ;)
Title: Re: Voltage Divider Calculators
Post by: german77 on April 24, 2018, 04:42:49 pm
Have a look on mine http://www.ifs.com.mx/Electric/ (http://www.ifs.com.mx/Electric/), it doesn't  calculate the value of the resistances. But takes on account tolerances, wattage and load.

It's a fantastic tool if you want to see the expected performance, efficiency and temperature. In a dynamic load.

It needs more work because it's not 100% reliable, specially calculating max and min values. But in most cases it's spot on.

I will be happy to work together and make a complete and reliable voltage divisor calculator, and we can use my domain to leave it public for everyone