Author Topic: Script to calculate best resistor pairs  (Read 1878 times)

0 Members and 1 Guest are viewing this topic.

Offline cellularmitosisTopic starter

  • Supporter
  • ****
  • Posts: 1111
  • Country: us
Script to calculate best resistor pairs
« on: April 14, 2017, 05:07:18 am »
I've been working on some circuits which use difference amplifiers, which need very closely matched resistors in order to perform well.  (Actually, all that matters is that the ratios of the two resistor pairs are matched.)

It turns out that if you grab 10 random 1% resistors, if you consider all possible pairings, the best pairing is usually pretty good.

I wrote a script which does all of the combinatorics for you.  Just list out your resistors in a file and feed it to the script.  Note: this script assumes all of your resistors are of equal nominal value (i.e, you are designing a diff-amp with a gain of 1x).

Here's 10 resistors from my drawer (cheap 10k 1% metal films):

Code: [Select]
10.004
9.990
9.999
9.865
9.953
9.869
9.889
9.917
9.881
9.922

Here's what the script prints out:

Code: [Select]
Best result:
Pair 1: r1/r10 (10.004/9.922), ratio: 1.00826446281
Pair 2: r3/r8 (9.999/9.917), ratio: 1.00826862963
These pairs form ratios which are mis-matched by 0.000413%

Here's the script: https://gist.github.com/cellularmitosis/20f882025756ceb0d0eb408d1e38e799

Enjoy!
LTZs: KX FX MX CX PX Frank A9 QX
 
The following users thanked this post: mrflibble, moz

Offline cellularmitosisTopic starter

  • Supporter
  • ****
  • Posts: 1111
  • Country: us
Re: Script to calculate best resistor pairs
« Reply #1 on: April 14, 2017, 05:22:56 am »
Of course, you have to watch out for heat-induced permanent drift when soldering resistors, so take these calculations with a grain of salt :)

https://www.eevblog.com/forum/projects/vishay-bulk-foil-drift-after-soldering/
LTZs: KX FX MX CX PX Frank A9 QX
 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 2051
  • Country: nl
Re: Script to calculate best resistor pairs
« Reply #2 on: April 14, 2017, 11:39:19 am »
Thanks! Added to the collection.  :-+
Of course, you have to watch out for heat-induced permanent drift when soldering resistors, so take these calculations with a grain of salt :)

https://www.eevblog.com/forum/projects/vishay-bulk-foil-drift-after-soldering/

Speaking of which, what might be interesting is doing a before and after comparison for a batch of same make & model resistors. The "interesting" part being see if there is any way to minimize the expected post-soldering target value mismatch purely based on pre-soldering resistance measurements. (For a given maximum number of resistors you are allowed to parallel.)

 

Offline Back2Volts

  • Supporter
  • ****
  • Posts: 495
  • Country: us
Re: Script to calculate best resistor pairs
« Reply #3 on: April 14, 2017, 07:00:13 pm »
Would it make a difference preheating the resistors ?    Will they still drift the same or less when soldering ?
 

Online T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 21658
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 
The following users thanked this post: ratio

Offline cellularmitosisTopic starter

  • Supporter
  • ****
  • Posts: 1111
  • Country: us
Re: Script to calculate best resistor pairs
« Reply #5 on: April 14, 2017, 10:45:43 pm »
Those look super useful!  Thanks Tim!
LTZs: KX FX MX CX PX Frank A9 QX
 

Offline cellularmitosisTopic starter

  • Supporter
  • ****
  • Posts: 1111
  • Country: us
Re: Script to calculate best resistor pairs
« Reply #6 on: April 15, 2017, 01:47:23 am »
Speaking of which, what might be interesting is doing a before and after comparison for a batch of same make & model resistors. The "interesting" part being see if there is any way to minimize the expected post-soldering target value mismatch purely based on pre-soldering resistance measurements. (For a given maximum number of resistors you are allowed to parallel.)

I decided to perform a bit of experimentation here, and soldered up some resistors to measure their drift.

One group was normally laid out, another had extra long leads, and another hung far enough off the board to sit in an alcohol bath while being soldered.  There was also a "control" group which I had soldered ~6 hours earlier, so the "before" and "after" measurements for those don't involve effects from soldering.  I also logged the time and ambient temperature at a few points along the way.

(See the attached screenshots of the setup and results)

The results were somewhat surprising -- soldering doesn't seem to make much of a difference at all for these cheap 1% metal film resistors (they either came from Tayda or eBay, I can't remember).  The soldered resistors drifted about as much as the "control" resistors.

(Note: all measurements taken with a UNI-T UT61-E)
LTZs: KX FX MX CX PX Frank A9 QX
 

Offline not1xor1

  • Frequent Contributor
  • **
  • Posts: 716
  • Country: it
Re: Script to calculate best resistor pairs
« Reply #7 on: April 15, 2017, 05:55:12 am »
I decided to perform a bit of experimentation here, and soldered up some resistors to measure their drift.

One group was normally laid out, another had extra long leads, and another hung far enough off the board to sit in an alcohol bath while being soldered.  There was also a "control" group which I had soldered ~6 hours earlier, so the "before" and "after" measurements for those don't involve effects from soldering.  I also logged the time and ambient temperature at a few points along the way.

(See the attached screenshots of the setup and results)

The results were somewhat surprising -- soldering doesn't seem to make much of a difference at all for these cheap 1% metal film resistors (they either came from Tayda or eBay, I can't remember).  The soldered resistors drifted about as much as the "control" resistors.

(Note: all measurements taken with a UNI-T UT61-E)

those cheap Chinese resistors drove me crazy when I used them to build an instrumentation amplifier (for a milliohm meter)

according to your tests it looks like their quality now is much better, but I still prefer only brand 1% 50ppm resistors when I need a fair precise and stable value (of course depending on your requirements and budget there are many other solutions: PGA, INA, precision resistor network, 0.1% and better resistors, etc.)

so far I've tested vishay, yageo and royalohm who provide a datasheet where you can know about maximum voltage etc.
I paid just 1-2 euros for 100 pieces of the same value and since you do not need so many different values for differential/instrumentation amplifiers that's a good bargain

IMHO it just doesn't make sense to buy unknown quality components and then spend a lot of time wondering why your circuit doesn't behave as expected (that's not your case, but a generic advice  :))
 

Offline Brutte

  • Frequent Contributor
  • **
  • Posts: 614
Re: Script to calculate best resistor pairs
« Reply #8 on: April 15, 2017, 10:16:05 am »
My topic about more general concept.

You pick 4 resistors out of 10 that minimize CMRR while in my post I was picking 2 out of N (where N is a parameter) that minimize |r1-r2| in a simple divider.
 

Offline KMoffett

  • Regular Contributor
  • *
  • Posts: 96
  • Country: us
Re: Script to calculate best resistor pairs
« Reply #9 on: April 16, 2017, 03:58:28 pm »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf