Wednesday, December 15, 2010

Voltage dividers

A common problem in electrical engineering is the use of a resistor divider to create a circuit which derives a second (lower) voltage from a known voltage.  This can be for a reference voltage to an ADC (as on the Arduino), to set the voltage on an adjustable regulator (where the regulator seeks to maintain an output voltage adequate to produce a set voltage at a feedback node), or to calculate the gain on an amplifier circuit, among other possibilities.

The canonical voltage divider circuit
Usually, we know Vin and Vout, but R1 and R2 are unknowns.  We usually pick one of them (based on what's on hand, in the parts library, time of day, dog's birthday, roll of a 20-sided die, etc), then calculate the other.  Almost always, that results in a value which is not readily available, so we pick the closest value, calculate the error, decide it's too much, and pick another resistor value and start over.

Error in the output voltage has a number of possible sources:  input error (typically, we're pulling Vin off a supply rail, which means it's only as accurate as our supply; for a cheap 7805 shunt regulator that may be as much as 5%), bias current error of the sampling circuit (typically fairly minimal in most circuits, but if you want to use high-value resistors to minimize waste current for battery life issues, you may find that the minimal current drawn at the Vout node introduces significant error), variation of the selected resistor values from the ideal values, and error in the actual resistor values from their nominal value.  Depending on what you want to use the output voltage for, even a fairly small error can be quite significant: many devices want power supplies to be within 5% or less, and every little bit of error reduces your design margin.

There are calculators all over the web that will do some of this work for you but they are usually only algebra cranks- they ask for three values and calculate the fourth; they rarely look for a "real" value that will work, and they don't usually tell you what kind of error you're introducing.

Since the values available are discrete and with a fixed tolerance, it's fairly easy to write a program that accepts Vin and Vout as parameters and returns an arbitrary number of solutions based on real values.  Sure, it requires many thousands of calculations (for standard 1% resistors, there are 9,216 possible combinations if you consider only those within one multiplier (i.e., 1.00k<= R < 10.0k); if you expand the range (i.e., 100<=R < 100k), that number quintuples, but what are computers for if not for automating repetitive tasks?

Here's a program that uses Python (2.7) to solve for an arbitrary (default 5) number of solutions to the resistor divider problem.  As arguments it accepts:
  • Vin
  • Vout
  • Series (standard 5% (E24) values, 1% (E96) values, or an arbitrary list from a file)
  • number of results desired
  • whether to include values one step above or below the nominal range
It returns a list to the command line which specifies:
  • multiplier for R1
  • multiplier for R2
  • absolute nominal error
  • worst case errors, +/- (given the tolerance of the parts specified)
  • parallel resistance of R1 and R2 (valuable if output impedance of circuit is important)
The worst case errors are only calculated for standard values- if you input a text file, both worst-case values will be the signed value calculated for the nominal value.

As an example, the TI TPS73201 regulator sets its output voltage based on a voltage divider- Vin is the desired output voltage, Vout is 1.204V, and by selecting appropriate resistor values, Vout can be set.  Furthermore, the datasheet indicates that to minimize error, R1||R2 should be 19k.

A chart is provided in the datasheet for various common voltages; for 1.5V, the suggested resistors are 23.2k and 95.3k (both standard 1% E96 values).  Running the script shows us 24 value combinations that have a better nominal error than that combination, BUT none of those combinations comes as close to the 19k parallel impedance requirement.

Maybe at some point I'll get this script executing in some fashion on a website; if I do, I'll link it.  For now, download it and play with it yourself.  Execute it from a command line; the -h switch will print a fairly comprehensive help list.

No comments:

Post a Comment