joe_schmoe All American 18758 Posts user info edit post |
given "x" number of fixed resistors switched into a parallel network, how would you go about writing code to calculate which resistor(s) to switch "on" to get a certain total parallel resistance.
for exampe: if I want a total resistance of ~25K .... out of 8 resistors in the parallel network, the closest that will get me to 25K is the 80.6K and the 40.2K, which give me 26.8K in parallel.
and applicable to any other total resistance value, of course.
obviously this is trivial to do in your head. but i need to automate this selection process for an in-house test program that does impedance gain testing of circuits.
i know i can figure it out with a little time and a little google, which is where i'm headed now... and i may figure it out on my own before someone here gives an answer. but i'll be interested to see anyone elses ideas.
[Edited on July 16, 2007 at 8:39 PM. Reason : ] 7/16/2007 8:28:36 PM |
Aficionado Suspended 22518 Posts user info edit post |
i started to think about it
it is a lot more complicated than i initially thought 7/16/2007 8:33:10 PM |
joe_schmoe All American 18758 Posts user info edit post |
ah, i should give the parallel resistance formula:
R(parallel) = 1 / (1/R1 + 1/R2 + 1/R3 + ... + 1/Rx) 7/16/2007 8:33:11 PM |
joe_schmoe All American 18758 Posts user info edit post |
^^ yah, thats what happened to me about 10 mins ago
7/16/2007 8:33:41 PM |
moron All American 34144 Posts user info edit post |
The algorithm can change depending on the relationship between the value of the resistors (it's not just a bunch of random resistors right?).
Generally, I would think you switch on the highest to lowest until you get within 1 resistor of the value you're looking for, then start skipping resistors until you get a minimal value. Kind of like successive approximation digital-analog conversion. 7/16/2007 8:34:50 PM |
joe_schmoe All American 18758 Posts user info edit post |
yes, the individual R values (R1 thru Rx) are fixed and known.
but variable, in that the code must be able to be ported to another similar network but with different resistance values and perhaps different total nubmer of resistors. but thats "extra credit" i guess. im just looking for the basic algorithm.
[Edited on July 16, 2007 at 8:40 PM. Reason : ] 7/16/2007 8:38:25 PM |
Aficionado Suspended 22518 Posts user info edit post |
what about creating an array with all the possibilities and scanning the list to see which one is closest
it would be quite a few possibilities
it isnt pretty
[Edited on July 16, 2007 at 8:40 PM. Reason :
7/16/2007 8:40:38 PM |
moron All American 34144 Posts user info edit post |
What I posted I think will work for any set of resistors, just as long as you can sort and access them by resistor values, highest to lowest. 7/16/2007 8:41:17 PM |
joe_schmoe All American 18758 Posts user info edit post |
^^ yeah, thats kind of a worst-case scenario. would work, but i wouldnt be proud of it
^ im gonna give that a try and see what happens. should actually be pretty quick to implement. thanks 7/16/2007 8:48:34 PM |
moron All American 34144 Posts user info edit post |
That bit of advice costs you $200
[Edited on July 16, 2007 at 9:07 PM. Reason : ] 7/16/2007 9:07:13 PM |
gephelps All American 2369 Posts user info edit post |
What makes this hard? You know your target value which I will call RP. You know all of your resistor values in the network. When those are read in, store their inverse values and sort them.
So then 1/RP = 1/R + 1/RX +1/RY
Which is a simple subtraction problem. Start with the highest value in the list and work your way down. Algebra anyone? 7/16/2007 9:28:35 PM |
moron All American 34144 Posts user info edit post |
^ Maybe I don't understand what you're saying, but it seems you are only able to address 1 permutation of the resistor values. 7/16/2007 9:31:06 PM |
gephelps All American 2369 Posts user info edit post |
^ Then I don't understand the problem. 7/16/2007 9:37:33 PM |
moron All American 34144 Posts user info edit post |
^ You're almost saying the same thing i'm saying, except you seem to only be subtracting the highest value... but what if the value you need requires a mixed set of intermediate values, not just the set of lowest to a highest? once you get to the point where subtraction overshoots the value you're looking for, you can start adding in a higher value, then subtracting a lower value, to get a more fine-tuned result (this is the process of successive approximation). 7/16/2007 9:59:53 PM |
cdubya All American 3046 Posts user info edit post |
I'd go with the precalculation route, resulting in a hash with the key holding the resistors involved and the value containing the parallel resistance. Calculation complexity nor storage size would be too big of a concern, especially since this is parallel and not series. 7/17/2007 2:45:28 AM |
moron All American 34144 Posts user info edit post |
True... 2^8 different states isn't too bad even for a linear search. 7/17/2007 3:05:28 AM |
Chance Suspended 4725 Posts user info edit post |
Well, he did say x fixed resistors, but I can't imagine he has a huge network. Processing power is cheap. If I were doing it, I'd write an excel macro with a column or row being the possible resistor values for input to the macro and stop when I found the combination that was within x percent (1, .1?) of the target value if the run times seem to be too long (or write it in C I guess) 7/17/2007 7:34:14 AM |
Aficionado Suspended 22518 Posts user info edit post |
what if he takes the precalcuation route
and then when check each value, see if it is closer to the target value than the one before
run through the whole list and youve got the closest value rather than trying to get within a certain percentage 7/17/2007 8:23:06 AM |
joe_schmoe All American 18758 Posts user info edit post |
i didnt work on this yesterday at all, trying to sort through it now.
moron has the closest idea of how to do this. the problem is, the target value will not usually equal any available parallel combo. it just has to be close. and there could be any number of resistors involved in the parallel circuit, up to the total number of resistors available.
i dont want to build a fixed array of 2^8 parallel combinations. what if the number of resistors go to 12 or 16. this is for embedded test, so repeatedly searching through 65K combinations for the closest value to each test's desired target would kind of suck. even searching for the closest of 256 is kind of ugly.
cdubya's idea of a keyed hash combination would be nice, but the problem is that the target wont typically match any of the pre-calculated values. 7/18/2007 4:56:52 PM |
BigMan157 no u 103354 Posts user info edit post |
does it have to be a software solution?
can you not just shove a digital pot in parallel to the whole thing and use a feedback loop to adjust it? 7/18/2007 5:16:15 PM |
joe_schmoe All American 18758 Posts user info edit post |
thats an interesting thought...
but no, the jigs have already been built 7/18/2007 5:34:57 PM |
joe_schmoe All American 18758 Posts user info edit post |
ah fuck this.
im just going to fill an array and do a linear or log search on it for the closest value.
i wanted to do something "elegant" or "clever"...
but with 2 and 3 GHz processors on the host workstation, "elegant" and "clever" really means "simple" and "git-r-dun"
i need to quit trying to turn this my work into an extra-credit problem. 7/18/2007 6:22:54 PM |
Chance Suspended 4725 Posts user info edit post |
Seriously, a column of values for your resistor values, 1 cell for your target value, and one cell for the precision, and a little bit of VB work will have this pretty easily.
You still haven't really made clear what your setup look like outside of "parallel" network.
You claimed the jigs are already built. What does that mean? Is there an upper bound on the # of resistors allowed to arrive at the value you need? What precision resistors are you using to begin with, 1%, 2%, 5%?
How are you "switching" these resistors on? Manual switch? Transistor? Relay? 7/18/2007 6:59:18 PM |
joe_schmoe All American 18758 Posts user info edit post |
im using a national instruments NI DAQ (digital acquisition) card and LabWindows CVI (C-language) to switch digitally controlled ports, which then operate FETs on a jig. the FETs are inline with each parallel path so that one digital port line essentially switches ON or OFF one resistor in the parallel network.
the resistors are all SMT 1%, there are 7 of them on this particular jig. the values could change with future tweaking. there 8 of them on another jig different values but also could change. there are an unknown number of resistors on future as-yet unbuilt jigs, but very likely could go up to 16 different resistors. the design principle is not driven so much by # of resistors, but impedance total range and resolution, so you could conceivably use all of the resistors in the parallel network.
obviously i want this software to "plug and play" with numerous different test jigs in the future with minimal (or no!) amount of recompiling, hence the portability issue. 7/18/2007 7:59:50 PM |
joe_schmoe All American 18758 Posts user info edit post |
you know, its funny. it really wasn't but about 10mins after i posted "ah fuck it", and was going build a fixed array of values, that it just occurred to me in a flash how to do this. its quite easy after all.
just run through the permutations (be it 2^8 or 2^16 or 2^whatever) and calculate each one, keeping track of which one has the lowest error. and skipping all instances that contain any resistances less than the target impedance, using a bit mask and a FOR/CONTINUE loop so the path values don't have to be in any sequential order
now i don't know why it was so damn hard to see. its kind of retarded anyhow, because this is all processing power and doesnt involve any digital card switching until its calculated. so, speed is a non-issue anyhow.
[Edited on July 18, 2007 at 9:55 PM. Reason : ] 7/18/2007 9:54:27 PM |