Author Topic: Parallel Resistor Calculation  (Read 3180 times)

0 Members and 1 Guest are viewing this topic.

Offline ramin110Topic starter

  • Contributor
  • !
  • Posts: 23
  • Country: ir
Parallel Resistor Calculation
« on: March 11, 2017, 10:26:56 am »
Hi guys, I just wrote a program to calculate parallel resistor values for all possible combinations that I needed for specified values.I think maybe someone needs this kind of program and I uploaded it on the forum. It's on beta version I have to do a lot of work for refactoring and multi threading for avoiding program freezing and etc. :blah: :blah: :blah:
please look at the program and help me about extra features and English grammar correction  ;D.

https://drive.google.com/open?id=0B_tpqPwA_7owNXAxRGpSVkRKR2c

Thanks.
« Last Edit: March 11, 2017, 10:29:31 am by ramin110 »
 

Offline bitwelder

  • Frequent Contributor
  • **
  • Posts: 972
  • Country: fi
Re: Parallel Resistor Calculation
« Reply #1 on: March 11, 2017, 06:20:35 pm »
Ah, it's a *Windows* application.

Pass.
 
The following users thanked this post: drussell, ramin110

Offline Benta

  • Super Contributor
  • ***
  • Posts: 6208
  • Country: de
Re: Parallel Resistor Calculation
« Reply #2 on: March 11, 2017, 06:29:42 pm »
Given that parallel resistor calculation can be done in a few seconds on my (RPN ;) ) calculator, I fail to see the need of a program.
And I have an allergy against unknown .exe files.

Pass.
 
The following users thanked this post: ramin110

Offline orolo

  • Frequent Contributor
  • **
  • Posts: 352
  • Country: es
Re: Parallel Resistor Calculation
« Reply #3 on: March 11, 2017, 06:49:19 pm »
For my filter experiments I use that same idea, but an executable is overkill. I just store my 10% SMD resistor by bins, the program merges the values in a single list, and iterates for single resistor, series pair or parallel pair, giving relative error and precision of the result:

Code: (Python) [Select]
#SMD resistor bins.
res100  = [1., 5.1, 9.1, 33., 43., 47., 75., 82.]
res1k   = [100., 110., 160., 180., 240., 390., 430., 750.]
res10k  = [1.2e3, 1.5e3, 2.4e3, 3.3e3, 3.6e3, 3.9e3, 4.7e3, 5.1e3, 6.2e3, 7.5e3, 9.1e3]
res100k = [12e3, 15e3, 24e3, 36e3, 43e3, 47e3, 51e3, 68e3]
res1meg = [100e3, 120e3, 150e3, 180e3, 240e3, 300e3, 330e3, 360e3, 430e3, 670e3]
res10m  = [1e6, 2.7e6, 4.7e6, 3.3e6]

res = [res100, res1k, res10k, res100k, res1meg, res10m]

target = input("Target: ")

# One resistor:
found  = -1
diff   = 10e10
eps    =  0

for l in res:
    for x in l:
        eps = abs(x - target)
        if (eps < diff):
            found = x
            diff = eps

print "\n\n1 resistor: ", found
print "Bounds: %f to %f"% (found * 0.99, found * 1.01)
print "Relative error: %f%%\n" % (100.0 * (found - target) / target)

#Pair:
found_s  = -1
found_p  = -1
diff_s   = 10e10
diff_p   = 10e10
eps_s    =  0
eps_p    =  0

for l1 in res:
    for l2 in res:
        for x in l1:
            for y in l2:
                eps_s = abs(x + y - target)
                eps_p = abs(1/(1/x + 1/y) - target)
                if (eps_s < diff_s):
                    found_s = (x,y)
                    diff_s = eps_s
                if (eps_p < diff_p):
                    found_p = (x,y)
                    diff_p = eps_p


print "Series pair: ", found_s
print "Bounds: %f to %f" % ((found_s[0] + found_s[1])*0.99, (found_s[0] + found_s[1])*1.01)
print "Relative error: %f%%\n" % (100.0 * ((found_s[0] + found_s[1]) - target) / target)

print "Parallel pair: ", found_p
print "Bounds: %f to %f" % (1/(1/(found_p[0]*0.99) + 1/(found_p[1]*0.99)), 1/(1/(found_p[0]*1.01) + 1/(found_p[1]*1.01)))
print "Relative error: %f%%\n" % (100.0 * (1/(1/found_p[0] + 1/found_p[1]) - target) / target)

So, for example, if I need 374.628 ohms (as in a thread in other subforum  :) ), my program gives:

Code: [Select]
Target: 374.628

1 resistor:  390.0
Bounds: 386.100000 to 393.900000
Relative error: 4.103270%

Series pair:  (180.0, 180.0)
Bounds: 356.400000 to 363.600000
Relative error: -3.904673%

Parallel pair:  (750.0, 750.0)
Bounds: 371.250000 to 378.750000
Relative error: 0.099299%

So a parallel combination of 750 ohms nails it. I've been thinking about getting serious and redoing the program with arbitrary depth, like A, A+B, A||B, A+B+C, A+(B||C), (A+B)||C, A||B||C, etc. But given the limitation of 2% precision in capacitance I work with, it'd be overkill.

Another very interesting problem is getting the minimum collection of resistor values that will guarantee less than 1% relative error for any value from 100 ohm to 1 meg, so I can get lots of these values and be done with that. I've never got serious enough to actually sit and compute it.
 
The following users thanked this post: ramin110

Online Alex Eisenhut

  • Super Contributor
  • ***
  • Posts: 3424
  • Country: ca
  • Place text here.
Re: Parallel Resistor Calculation
« Reply #4 on: March 11, 2017, 09:37:17 pm »
"It's on beta version I have to do a lot of work for refactoring and multi threading for avoiding program freezing and e"

 :palm:

For calculating two resistors in parallel?

 :o

What do you need to calculate a mortgage? Half of Google's server farm?
Hoarder of 8-bit Commodore relics and 1960s Tektronix 500-series stuff. Unconventional interior decorator.
 
The following users thanked this post: ramin110

Offline FrankBuss

  • Supporter
  • ****
  • Posts: 2368
  • Country: de
    • Frank Buss
Re: Parallel Resistor Calculation
« Reply #5 on: March 12, 2017, 01:54:53 am »
Doesn't work on a German Windows version, shows lots of duplicate values (so why doesn't it delete these values automatically?). I guess some problems with the decimal point, which is a comma here.
So Long, and Thanks for All the Fish
Electronics, hiking, retro-computing, electronic music etc.: https://www.youtube.com/c/FrankBussProgrammer
 
The following users thanked this post: ramin110

Online mariush

  • Super Contributor
  • ***
  • Posts: 5134
  • Country: ro
  • .
Re: Parallel Resistor Calculation
« Reply #6 on: March 12, 2017, 07:24:03 am »
I got bored and wrote a "calculator" in PHP while watching a couple of movies.  Here you go : http://savedonthe.net/a/resistorcalc.php  (download : http://savedonthe.net/a/resistorcalc.zip )

It's not optimized in any way, so prevent people from killing the server the live version is restricted to 2 resistors max. You can edit the source code to raise the limit.

 
The following users thanked this post: ramin110

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13038
Re: Parallel Resistor Calculation
« Reply #7 on: March 12, 2017, 07:46:07 am »
Heck, all you need is a laminated A3 sized nomogram, with extra tick marks the opposite side of each scale to the graduation indicating the E12/E24 preferred values, and auxiliary scales for parallel combos of the order of a decade apart + a straightedge.  Its going to be faster and easier to use than any dedicated calculator.

If you have to show off, write your electrical calculators in Javascript, so they can be tried online, but please make sure they will still work if the user saves the page locally.
 
The following users thanked this post: ramin110

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11705
  • Country: my
  • reassessing directives...
Re: Parallel Resistor Calculation
« Reply #8 on: March 12, 2017, 09:24:04 am »
well this is my parallel resistor program (attached), 3 resistors parallel max, i dont see why i need more. i'll make one for you if i need more than 3 resistors. and its not a beta test since if you put 0 ohm it will throw "division by zero" at you and quit just to show how stupid are you ;D. and its super efficient since it only needs single thread. if you an exephobolic or has new Windows that cant run it well too bad.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 
The following users thanked this post: ramin110

Offline ZeTeX

  • Frequent Contributor
  • **
  • !
  • Posts: 610
  • Country: il
  • When in doubt, add more flux.
Re: Parallel Resistor Calculation
« Reply #9 on: March 12, 2017, 09:37:47 pm »
its physically faster for me to go to google and write "parallel resistor calc" instead of pulling a calculator or a software.
 
The following users thanked this post: ramin110

Offline ramin110Topic starter

  • Contributor
  • !
  • Posts: 23
  • Country: ir
Re: Parallel Resistor Calculation
« Reply #10 on: March 12, 2017, 09:46:09 pm »
New Changes :popcorn:
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19884
  • Country: gb
  • 0999
Re: Parallel Resistor Calculation
« Reply #11 on: March 13, 2017, 01:39:09 pm »
Another very interesting problem is getting the minimum collection of resistor values that will guarantee less than 1% relative error for any value from 100 ohm to 1 meg, so I can get lots of these values and be done with that. I've never got serious enough to actually sit and compute it.
All you need is the E24 series, from 1R and 10M. Any E96 value can be made, to within 0.2% using two E24 values in series or parallel.

I did a table awhile ago.
 
The following users thanked this post: bitwelder, orolo

Offline cncjerry

  • Supporter
  • ****
  • Posts: 1308
Re: Parallel Resistor Calculation
« Reply #12 on: March 13, 2017, 08:39:10 pm »
Let's see how complicated we can makes this:

1) When I was fixing my fluke 332D, I needed a parallel resistor combination that came within .01% of 9.9925K ideally with opposing TCs.  I made a simple spreadsheet and sub'ed available resistors into it after measuring the TCs of the two types I had. It took me about 90 minutes of screwing around with parallel and series combinations.  I used a selected 10K in parallel with a series combination of selected 3.3M and 8M.  The combination calculated to 9.99116K and measured pretty close to 9.9925K when done.

2) I did a program like this in Prolog a couple years ago that had one table of 1% values and could do as many parallel combinations as you would like pretty quickly. I then added the option of doing series or parallel whichever came closest.  That was basically an iterative process and required a lot of CPU.  The problem with Prolog was setting the accuracy needed.  If you asked it for a minimum of .01% variance and it found a combination, it stops even though a future combination could be lower.  The only way to find the minimum was to calculate all parallel combinations and then use a minimum function on the resulting stage one table.  This added to the calculation time as you can imagine, but we are talking microseconds here.

3) I've been studying TensorFlow for machine learning.  This is the modern way  :-DD  to do it but I haven't had success yet which speaks to my Tensorflow skills.
 

Offline cncjerry

  • Supporter
  • ****
  • Posts: 1308
Re: Parallel Resistor Calculation
« Reply #13 on: March 14, 2017, 01:39:34 am »
for the heck of it, I rewrote the Prolog version of my code as I couldn't find it (of course).  The program is nothing more than a table of values of resistors in the form of value(10.0) for instance.  I could have just used the 1% bins and multiplied them but I didn't to keep the goal seeking program easily understandable so you wouldn't have to go learn Prolog.  I used SWI Prolog by the way.

The command 'value(A)' looks in the 'value' table and assigns the first value to the variable 'A'.  It then does the same with the next goal 'value(B)'.  After assigning values to A and B, it does the parallel resistor math resulting in the instantiation of C.  If C is equal to the required value or within a range, the program succeeds, otherwise you get a false return meaning it couldn't find a solution.  You can ask for more solutions by pressing the space bar.

Here is the goal and the output for finding a resistor between 70 and 70.1:

Code: [Select]
?- value(A), value(B), C is (1/(1/A + 1/B)), C > 70.0, C<70.2.
A = 76.8,
B = 806.0,
C = 70.11871318531944

A = 78.7,
B = 634.0,
C = 70.00954118142276

A = 78.7,
B = 649.0,
C = 70.18867665246668

A = 80.6,
B = 536.0,
C = 70.06422315926045

A = 82.5,
B = 464.0,
C = 70.04574565416286

A = 84.5,
B = 412.0,
C = 70.11883182275932

A = 97.6,
B = 249.0,
C = 70.11656087709174

A = 249.0,
B = 97.6,
C = 70.11656087709174

A = 412.0,
B = 84.5,
C = 70.11883182275932

A = 464.0,
B = 82.5,
C = 70.04574565416286

A = 536.0,
B = 80.6,
C = 70.06422315926045

A = 634.0,
B = 78.7,
C = 70.00954118142276

A = 649.0,
B = 78.7,
C = 70.18867665246668

A = 806.0,
B = 76.8,
C = 70.11871318531944


That's about as easy as it gets and it finds the first solution as fast as you press enter with each additional solution just as fast.  This is using a table of values from .1 to 1000.

When I tested it originally I knew there was a value of 140 in the table so I tried the following thinking it would spit out A=140 and B = 140 with C = 70:

Code: [Select]

?- value(A), value(B), C is (1/(1/A + 1/B)), C = 70.0.
A = 105.0,
B = 210.0,
C = 70.0

A = B, B = 140.0,
C = 70.0

A = 210.0,
B = 105.0,
C = 70.0
false.

I was surprised to see the 105 and 210 come up first followed by A and B being equal to 140.  How many of us would have grabbed two 140 ohm resistors to hit 70 in parallel (assuming there is no 70 ohm resistor) without thinking of 105 and 210?

This one threw me off as well:

Code: [Select]
?- value(A), value(B), C is (1/(1/A + 1/B)), C = 50.0.
A = 75.0,
B = 150.0,
C = 50.0
 
A = B, B = 100.0,
C = 50.0

A = 150.0,
B = 75.0,
C = 50.0

false.


I am always grabbing two, 100 ohm resistors to make a perfect 50 ohms without thinking of 150 and 75 ohms.

Anyway, I plan to keep this around and expand it to the next few decades up to 10Meg.
 

Offline Conrad Hoffman

  • Super Contributor
  • ***
  • Posts: 1979
  • Country: us
    • The Messy Basement
Re: Parallel Resistor Calculation
« Reply #14 on: March 14, 2017, 04:10:32 am »
I've got a bunch of Excel utilities like that I use constantly. If you're old enough to remember the dawn of the PC, all the electronic magazines had BASIC programs for common calculations that you could type in and run with IBM basica and other similar languages. I think most designers use Excel these days, though I still have a few exe utilities wrote and find useful.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf