Electronics > Beginners

Digital adjustable resistor

<< < (17/17)

eslavko:

--- Quote from: Nominal Animal on October 09, 2022, 07:19:36 pm ---
--- Code: ---#!/usr/bin/python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: CC0-1.0

if __name__ == '__main__':
    from sys import stdout, stderr, argv

    if len(argv) < 3:
        stderr.write('\n')
        stderr.write('Usage: %s [ -h | --help ]\n' % argv[0])
        stderr.write('       %s RESISTANCES...\n' % argv[0])
        stderr.write('\n')
        exit(0)

    R = [ float(argv[k]) for k in range(1, len(argv)) ]
    N = len(R)

    R.sort()
    value = []
    for k in range(1, 2**N):
        invsum = 0.0
        for n in range(0, N):
            if (k & (2**n)) > 0:
                invsum += 1.0 / R[n]
        value.append(1.0/invsum)
    value.sort()

    stdout.write('Resistors:')
    for n in range(0, N):
        stdout.write(' %.6f' % R[n])

    stdout.write('\nPossible parallel resistances:\n')

    for k in range(0, 2**N - 1):
        stdout.write("%.9f\n" % value[k])

--- End code ---

--- End quote ---

I already do near same python script using plot to show result.
When I playing with numbers I got interesting results.
Based on your writing the best I can get is with linear distribution betwen 1 and 0.5.
I do it like that:


--- Code: ---res=[]
stp=1500/12
for i in range(12):
    res.append(stp*i+1500)

--- End code ---

The result is 8% difference from 174.968535 to 2875.000000, with 12 bits
[attachimg=1]

With binary weightrd resistors (each one is double the size of previous) like:

--- Code: ---res=[150]
for i in range(11):
    res.append(res[-1]*2)

--- End code ---

I got 0.93% difference from 75.018315 to 2982.524272, with 12 bits.
[attachimg=2]

If I didn't make some mistake then seems that binary values will be better.
(I did mistake in 1st version of my script and based of bad result that thread is started at all)




Nominal Animal:
Like I said, the distribution of resistances in the upper half of your resistance range is the key, when the selectable resistances are in parallel.

If you want a 1/N distribution of resistances, then power of two sequence is likely optimal (each resistance double the previous one).
If you want a linear distribution of resistances, then linear sequence is optimal.

In my own circuits –– I'm a hobbyist who interfaces all kinds of sensor and display circuits to microcontrollers and single board computers –– I tend to need either precision resistors under 100 Ω (and current shunt resistors under 1 Ω), or larger resistors picked from one of the E series of preferred numbers.  So even a bumblefuck hobbyist like myself has quite different needs for resistors.

You seem to be undecided on what kind of distribution of resistances your switchable box needs; only that 50 Ω to 3000 Ω or maybe 4500 Ω would be useful.
Yet, it is exactly the resistance distribution you desire, especially in the upper half of the resistance range (so 1500 Ω to 3000 Ω, or 2250 Ω to 4500 Ω), that is the determining factor here.


Logarithmic resistance ranges are a bit more complicated than either 1/N or linear, as discussed above.  Considering the 50 Ω to 4500 Ω range:

For example, in the E6 series, the desired resistances would be 47, 68, 100, 150, 220, 330, 470, 680, 1000, 1500, 2200, 3300, 4700.
From the E6, only the three highest ones (2200, 3300, 4700) are needed for the upper half of the resistance range.

In the E12 series, the desired resistances would be 47, 56, 68, 82, 100, 120, 150, 180, 220, 270, 330, 390, 470, 560, 680, 820, 1000, 1200, 1500, 1800, 2200, 2700, 3300, 3900, 4700.
Only the four or five highest ones ([2200], 2700, 3300, 3900, 4700) are needed for the upper half of the resistance range –– without 2200, the closest value is 2131.4=2200-3.12%.

In the E24 series, the resistances would be 47, 51, 56, 62, 68, 75, 82, 91, 100, 110, 120, 130, 150, 160, 180, 200, 220, 240, 270, 300, 330, 360, 390, 430, 470, 510, 560, 620, 680, 750, 820, 910, 1000, 1100, 1200, 1300, 1500, 1600, 1800, 2000, 2200, 2400, 2700, 3000, 3300, 3600, 3900, 4300, 4700.
Only the eight or nine highest ones ([2200], 2400, 2700, 3000, 3300, 3600, 3900, 4300, 4700) are needed for the upper half of the resistance range.  Again, without 2200, the closest values the higher ones combine to are 2200+2.1% and 2200-3.12%.

I am not aware of any formula that directly generates the lower range resistances that (along with the fixed upper range resistors) yields the desired values, but a brute-force search ought to find good candidates that can be analysed to minimise relative error in the resistances.

eslavko:

--- Quote from: Nominal Animal on October 10, 2022, 09:44:46 pm ---I am not aware of any formula that directly generates the lower range resistances that (along with the fixed upper range resistors) yields the desired values, but a brute-force search ought to find good candidates that can be analysed to minimise relative error in the resistances.

--- End quote ---

As I write it's not adjustable resistor box but testing/callibrating device. Until now some parameters are adjusted automatically and other manual, and I wish to make all adjustment automated. For that I need specific resistor ranges (and there can be some gaps present). Now with working "python calculator" I can see results quick and can do some changes in resistor sets to get desired results using like brute force approach. At least in this thread I learned that in high range whatever I do the step will be coarser.

Thanks for support and all ideas.

Navigation

[0] Message Index

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod