Larry said:
[Regarding finding accurate resistor combinations]
I do this with Brute Force (ie matlab). I have a simple s-file that takes an array of available values, which may or may not be
entire ranges - smt design optimisation usually involves minimising the number of different parts.
Then I calculate every possible 1,2,3,4 resistor combination, using:
1 resistor
2 series
2 parallel
1 paralleled with (2 series)
2 paralleled with (2 series)
and for each of the 5 cases sort the result in order of increasing error
I specify a required accuracy, then throw away all results which are worse.
then display the first 10 entries in each of the 5 combinations.
Yeah, it makes HAL9000 do a *lot* of calculations, but so what - it results in a barely perceptible delay between hitting <enter>
and getting the answers.
What I did is almost brute force, in that it tries
a number of combinations. But because of the
algorithmic derivation of available value from
desired value, it is much less brutish than the
approach you outline. That said, I would not
be the one to criticize the approach merely
for using more likely spare cycles. Wetware
cycles are becoming the scarcer resource
these days, (excepting, naturally, the most
brilliant among us, whoever they are.)
If you are willing to share that code, I would
like to see it (via email).
Its pretty easy really:
R is a row vector containing all the resistor values you have to work
with (in our case, all the ones fitted to the smt machine)
the only subtlety here is an s-file prints a variable (or calculation
result) if you dont put a ';' after it - that is what the "bestfit"
lines by themselves do.
function bestfit=resistor(rnom);
%find best fit for limited set of resistors
%connected as (R1+R2) // R3 // R4
%0 means not fitted
R = [1.5, 3.3, 10, 24, 47, 100, 150, 330, 470, 1000, 1330, 3010, 3300,
4700, 6650, 10000, 16500, 20000, 26700, 33000, 47000, 63400, 100000,
330000, 470000, 1000000];
besterror = 100;
% R3 only
for n3=1:1:length(R)
r=R(n3);
error = (r-rnom)/rnom;
if abs(error) < abs(besterror)
besterror = error;
bestfit = [0, 0, R(n3), 0, besterror*100];
end
end
bestfit
% R3 // R4 only
for n3=1:1:length(R)
for n4=n3:1:length(R)
r=R(n3)*R(n4)/(R(n3)+R(n4));
error = (r-rnom)/rnom;
if abs(error) < abs(besterror)
besterror = error;
bestfit = [0, 0, R(n3), R(n4), besterror*100];
end
end
end
bestfit
% R1 + R2 only
for n1=1:1:length(R)
for n2=1:1:length(R)
r = R(n1) + R(n2);
error = (r-rnom)/rnom;
if abs(error) < abs(besterror)
besterror = error;
bestfit = [R(n1), R(n2), 0, 0, besterror*100];
end
end
end
bestfit
% (R1 + R2) // R3
for n1=1:1:length(R)
for n2=1:1:length(R)
for n3=1:1:length(R)
rser = R(n1) + R(n2);
r = rser*R(n3)/(rser+R(n3));
error = (r-rnom)/rnom;
if abs(error) < abs(besterror)
besterror = error;
bestfit = [R(n1), R(n2), R(n3), 0, besterror*100];
end
end
end
end
bestfit
% (R1 + R2) // R3 // R4
for n1=1:1:length(R)
for n2=1:1:length(R)
for n3=1:1:length(R)
for n4=n3:1:length(R)
rser = R(n1) + R(n2);
r = 1/(1/rser + 1/R(n3) + 1/R(n4));
error = (r-rnom)/rnom;
if abs(error) < abs(besterror)
besterror = error;
bestfit = [R(n1), R(n2), R(n3), R(n4), besterror*100];
end
end
end
end
end
bestfit
Pretty easy really, and a doddle to implement in any programming
language. Here's a calculated result:
resistor(6.33125e3);
bestfit =
1.0e+003 *
0 0 6.65000000000000
0 0.00503455083909
[so a 6.65k resistor (which I have) is within 5.034%]
bestfit =
1.0e+005 *
0 0 0.06650000000000
1.00000000000000 -0.00001514720263
[6k65//100k within 1.514%]
bestfit =
1.0e+003 *
3.01000000000000 3.30000000000000 0
0 -0.00033563672261
[3k01 + 3k3 within 0.3356%]
bestfit =
1.0e+005 *
0.33000000000000 1.00000000000000 0.06650000000000
0 0.00000032905561
[ (33k + 100k)//6k65 within 0.0329% ]
bestfit =
1.0e+004 *
0.47000000000000 0.47000000000000 3.30000000000000
4.70000000000000 -0.00000100731309
[ (4k7 + 4k7)//33k//47k within 0.01007% ]
which checks out as 6.330612k.
Voila. Utterly trivial to have, say, E12 version. But ultimately I only
care about the bits I have in stock.
the moderately evil output scaling is just a matlab thing, I could
change it if I wanted to, but who cares
Cheers
Terry