Resistor Selection Program

My design and implementation of an algorithm to quickly identify the optimal configuration of resistors for a target value  (3-6 min read)

In electronics engineering it is a common practice to create an equivalent desired resistance by combining two resistors in a series or parallel connection. This is usually doable in a reasonable amount of time, but can cause frustration in some situations since there is no straightforward way to identify which component resistors should be used. It is simply a matter of guesswork to consider, "of the resistors I have available, which combination will give me a value reasonably close to my target."

This leaves some people with a feeling of curiosity. Since there are an extraordinary amount of possible combinations, it's almost impossible that the engineer in question will pick the closest solution. Sure they'll likely get within one percent or so of the target after a few guesses, and that's almost always good enough considering the accuracy of the resistors in question likely won't be any better than one percent anyways, but I hated the gnawing feeling that there is an equally simple and inarguably best solution out there that I am ignorant to.

The program I have designed answers that question in excruciating detail by taking inputs from the user of a desired component accuracy rating, a target resistance value, and a range of resistors to be used.

Only the most commonly available(read, cheapest) resistor values are considered.

The program runs and the output is a set of instructions detailing three configuration options to the user(one using 3 resistors, one using 2, and the last using 1 resistor). Series, parallel, and a combination of both configurations are considered for all possibilities. Here we can see that a one in series and two in parallel was the ideal configuration when using three resistors(specified in the Format column), and a two in series format was ideal for two resistors(as opposed to two in parallel).

The user is allowed to specify specific upper and lower bounds of components to address concerns with noise, footprint size, or frequency response. 

The user can easily view these three options, consider which option has acceptably high accuracy and acceptably low total component cost, then use the component resistors detailed in the values column.

During a simulation of three hundred different resistor values, this is the spread of the accuracies of the results when only combinations of two components are considered.

Given the error spread of about ±0.04%, it is obvious that we can have a practically perfect result for any scenario

This is the accuracy chart for the same simulation when three components are considered. There was absolutely no observable deviation. 

I can't imagine when this accuracy is needed over the accuracy exemplified in the previous graph, but hey, now I can rest assured knowing there are perfect answers for these questions. Also, it was a fun problem to solve, and just look at how pretty that histogram is.

Creating this program involved developing an algorithm to consider every possible combination and configuration of resistors up to a quantity of three components, then comparing them against one another and exporting the results, all through a GUI. The sections considering all the different configurations of three resistors at a time was particularly interesting to develop. It was one of my favorite coding projects so far.

I alluded before to the idea that this is somewhat solving a problem that no one is complaining about. People have historically been designing electronics by traditional methods just fine. Still, I would argue that this application has real benefits. Companies commonly spend huge amounts of money to bring production costs down by pennies at a time. This program could instantly show designers where they could swap out expensive specific value resistors for cheaper typical value components instead. 

I would do a segment by segment write-up on the nearly 500 line program posted below, but unfortunately the reading time would far exceed what I'm aiming for in a portfolio showcase. If you're interested to learn more please reach out and I'd be happy to discuss it as interview material.

To view the full code, click one of these buttons to view or download the code. Otherwise, read on below.