| Electronics > Projects, Designs, and Technical Stuff |
| standard value resistor / capacitor combination tool |
| << < (3/5) > >> |
| OM222O:
--- Quote from: Kirr on October 31, 2019, 02:12:36 am ---Right, "From ... to ..." is for specifying the range of the selected series. If left unspecified, the default is from 1 Ohm to 1 MOhm (indicated in the result report). However sometimes you may want to use larger range (e.g., till 22 MOhm range is still common depending on application), or reduce the range to speed up calculation (and avoid hitting the limit due to combinatorial explosion of possible networks). The "From .... to ..." range only applies to the fields above it in the form. I.e., to series and significands. The list of extra values does not care about range, because extra values are listed one by one. --- End quote --- I see! I get around that issue entirely by using these few lines to "normalize" the data to a range between 0 and 10: --- Code: --- unmodified_x = x scale_factor = 1 if (x>np.amax(values)): while(x>np.amax(values)): scale_factor *= 10 x /= 10 elif(x<np.amin(values)): while(x<np.amin(values)): scale_factor /= 10 x *= 10 --- End code --- I'm not sure which language you're using, but you should be able to do a very similar thing. In order to use values close to the desired one, I'm adding more values to the set which are one order of magnitude larger or smaller than the values in the series: --- Code: --- values = np.hstack((values/10 , values)) values = np.hstack((values , values*10)) --- End code --- I figured that 10 times larger and smaller should be good enough since the effects of resistors outside that range are either way too large (parallel resistors that are 10 times smaller or series resistors that are 10 times larger!) or way too small (opposite of what I said before). but you can easily add 100 times or even 1000 times values. this keeps the finite element analysis under control and prevents data sizes from exploding :-+ you can completely bypass the range issue this way. If you really want to use notations such as K m etc, it's as simple as keeping a copy of the notation used, normalizing and finding the values, then sticking the notation to the end of all the results. it's a really basic formatting issue haha. This greatly simplifies your code and makes the software less confusing in my opinion! --- Quote from: Kirr on October 31, 2019, 02:12:36 am ---The tool adds another resistor only if it did not hit the error target yet. Since 13 Ohm is already within 10% of 14 Ohm, the tool is satisfied, and does not add second resistor. If you are looking for the most precise fit possible, it's best to set the error to 0. Thanks for great questions and feedback! It seems I have work to do! :-+ --- End quote --- Oh! so this tries to find a best match that is larger than the provided tolerance, I see! it seems a bit of a backwards way to do things since you miss most of the values that actually meet the spec you want and seems like always choosing 0 is the best option ??? I tried it with 0 tolerance and it still only found one possible solution: 13 + 1, but there are indeed 3 solutions: 13 + 1 , 12 +2 and 11 + 3. the output is formatted like a table, so I assume you planned on displaying more than just a single result? I'm not sure tbh. |
| Kirr:
--- Quote from: OM222O on October 31, 2019, 02:28:18 am ---I see! I get around that issue entirely by using these few lines to "normalize" the data to a range between 0 and 10: ... --- End quote --- I see. So you are effectively auto-ranging the 3 decades of stock around the requested target value. I'm not a fan of this approach, because: 1. If the target value is close to the lower or upper bound of the actual stock range, your calculation will include values that are in fact not stocked. E.g., when requesting 1.12 Ohm value, your tool will assume I have values from 0.1 to 1 Ohm in stock, even though this might not be the case. 2. When requesting a value closer to the middle of actual stock, your tool won't use the entire stock, even though it might help to get a better fit for some values. (Though I don't have statistics about how often such remote values help). --- Quote from: OM222O on October 31, 2019, 02:28:18 am ---I'm not sure which language you're using, but you should be able to do a very similar thing. --- End quote --- I used D in this case. I also use auto-ranging, but for a different purpose. I calculate using rational numbers, and adjusting range helps to avoid overflows. --- Quote from: OM222O on October 31, 2019, 02:28:18 am ---In order to use values close to the desired one, I'm adding more values to the set which are one order of magnitude larger or smaller than the values in the series: --- Code: --- values = np.hstack((values/10 , values)) values = np.hstack((values , values*10)) --- End code --- --- End quote --- Not sure I read this correctly, but won't you end up with two copies of the original values? Since the second line takes the already doubled range? --- Quote from: OM222O on October 31, 2019, 02:28:18 am ---If you really want to use notations such as K m etc, it's as simple as keeping a copy of the notation used, normalizing and finding the values, then sticking the notation to the end of all the results. it's a really basic formatting issue haha. This greatly simplifies your code and makes the software less confusing in my opinion! --- End quote --- Yeah, adding unit prefixes is not a big problem. Though I prefer the other way around: "k" and "M". :) --- Quote from: OM222O on October 31, 2019, 02:28:18 am ---Oh! so this tries to find a best match that is larger than the provided tolerance, I see! it seems a bit of a backwards way to do things since you miss most of the values that actually meet the spec you want and seems like always choosing 0 is the best option ??? --- End quote --- For practical purposes, usually smaller network is preferable, among those satisfying the required tolerance. But possibly this shortcut can be counter-intuitive or unexpected. I'll think about how to better explain it. --- Quote from: OM222O on October 31, 2019, 02:28:18 am --- I tried it with 0 tolerance and it still only found one possible solution: 13 + 1, but there are indeed 3 solutions: 13 + 1 , 12 +2 and 11 + 3. the output is formatted like a table, so I assume you planned on displaying more than just a single result? I'm not sure tbh. --- End quote --- Yeah, displaying multiple results could be sometimes useful. I haven't needed this personally. In case if I don't like the particular suggested network, I can put one of the used values into Gaps list and recompute, to see what else is available. But may be I'll add multiple answers option some day. As for the table output - it's for cases when you request multiple target values. :) |
| OM222O:
--- Quote from: Kirr on October 31, 2019, 06:04:32 am --- --- Code: --- values = np.hstack((values/10 , values)) values = np.hstack((values , values*10)) --- End code --- --- End quote --- Not sure I read this correctly, but won't you end up with two copies of the original values? Since the second line takes the already doubled range? [/quote] Good catch haha |O it's a simple fix however: --- Code: --- values = np.hstack((values/10 , values , values*10)) --- End code --- it was just another one of the bugs left from the debugging stage :-DD --- Quote from: Kirr on October 31, 2019, 06:04:32 am ---1. If the target value is close to the lower or upper bound of the actual stock range, your calculation will include values that are in fact not stocked. E.g., when requesting 1.12 Ohm value, your tool will assume I have values from 0.1 to 1 Ohm in stock, even though this might not be the case. 2. When requesting a value closer to the middle of actual stock, your tool won't use the entire stock, even though it might help to get a better fit for some values. (Though I don't have statistics about how often such remote values help). --- End quote --- when requesting 1.12ohm for example, it's larger than the base value which is 1, so it searches from 0.1ohm to 10 ohm. if the stock is only limited to resistors of higher than 1 ohm, then parallel is your best bet, otherwise series is fine too. it just comes down to how you plan on designing the final schematic and here the advantage of having a large list of values helps ;D you choose the values that best fit your stock. I'm not sure what you mean by it doesn't use the entire stock if middle is chosen. It creates a list of all possible n element sub-arrays (where n is the number of resistors chosen) then calculates the sum based on the chosen method (parallel or series), stores all the values and filters the ones where the sum is within tolerance of the desired value. I'm not actually "solving a network", I'm doing finite element analysis and filtering the good values from all the possibilities. |
| Kirr:
--- Quote from: OM222O on October 31, 2019, 12:09:27 pm --- --- Code: --- values = np.hstack((values/10 , values , values*10)) --- End code --- --- End quote --- :-+ --- Quote from: OM222O on October 31, 2019, 12:09:27 pm ---I'm not sure what you mean by it doesn't use the entire stock if middle is chosen. It creates a list of all possible n element sub-arrays (where n is the number of resistors chosen) then calculates the sum based on the chosen method (parallel or series), stores all the values and filters the ones where the sum is within tolerance of the desired value. I'm not actually "solving a network", I'm doing finite element analysis and filtering the good values from all the possibilities. --- End quote --- OK, I played a bit with both our tools to work out some examples. Here is one: For example, let's say we have a full stock of E12 values, in the range from 1 Ohm to 1 MOhm. And let's say I we need three missing values: 6.73k, 67.3k and 673k, to be approximated using parallel networks of at most 2 resistors. My tool suggests the following: Formated as: "Request: Approximation = Network (Error)" 6.73k: ~6.733k = 6.8k || 680k (0.039%) 67.3k: ~67.754k = 82k || 390k (0.675%) 673k: 680k = 680k (1.040%) In other words, it respects the boundary of our stock at 1 MOhm. When we request a value closer to the middle of stock range (6.73k), the tool has more options and thus can find a closer fit. However as the request gets closer to the boundary, options get more limited, and error gets larger. I then tried your tool using: --- Code: ---print_results("Parallel combinations for 6.73k: " , find_combo(parallel,2,E12,6730,1)) print_results("Parallel combinations for 67.3k: " , find_combo(parallel,2,E12,67300,1)) print_results("Parallel combinations for 673k: " , find_combo(parallel,2,E12,673000,1)) --- End code --- which generates: --- Code: ---Parallel combinations for 6.73k: 0.7% -> 8200.00 39000.00 1.0% -> 12000.00 15000.00 ######################################## Parallel combinations for 67.3k: 0.7% -> 82000.00 390000.00 0.9% -> 120000.00 150000.00 ######################################## Parallel combinations for 673k: 0.7% -> 820000.00 3900000.00 1.0% -> 1200000.00 1500000.00 ######################################## --- End code --- Which means: 1. Your tool does not find the optimal approximation when extra range is available. It suggests 8.2k || 39k rather than more optimal 6.8k || 680k, because it looks only one decade away from the target value. (Of course you can add more decades by adding values*100 and values/100). 2. Your tool feels free to use values that we don't have in our stock: When building 673k it uses 3.9M, which we don't have. (Both issues are rooted in there being no interface to specify stock boundaries). Which summarily means that your tool uses the stock that it feels convenient to use, rather than the actual stock available to a project. I personally feel this is important limitation, as I like my actual stock to be respected and fully utilized. I guess your approach may be OK if you make sure to only request targets that are at least 1 decade away from your stock bondaries, and don't mind occasionally missing a better fit. |
| mariush:
I was bored and decided to complete a similar tool I started to write some time ago. So I uploaded it here: https://github.com/mariush-github/resistor-calculator-php It's written in PHP, you can simply download a Windows version of php and type php.exe calculator.php --value 100 to get combinations of resistors that produce 100 ohm resistor. It allows up to 4 resistors and mixes of series and parallel, but keep in mind it's a memory hog : if you choose 3 or 4 resistors, you may have to go in php.in and raise the memory limit from 128 MB to 1024-2048 MB. I may rewrite it in Go as an exercise, for faster speed and less memory usage, and to play around with the concurrency features of Go. I suppose you could also add a feature to import a list of resistors you actually own. Example: php.exe calculator.php --min 100 --max 10000 --e 24 --tol 1 --mix 1 --results 50 --count 4 --value 470 will give 938 results, which are dumped in CSV files (three separate files). The closest are printed on screen, up to 100. Results are grouped by resistor count by default (there's parameter you can set to 0 to disable this) --- Code: ---2 470 0.000% 360 + 110 2 470 0.000% 270 + 200 3 470 0.000% 390 + 2p160 3 470 0.000% 360 + 2p220 3 470 0.000% 160 + 2p620 3 470 0.000% 130 + 2p680 3 470 0.000% 270 + 100 + 100 3 470 0.000% 240 + 130 + 100 3 470 0.000% 240 + 120 + 110 3 470 0.000% 220 + 150 + 100 3 470 0.000% 220 + 130 + 120 3 470 0.000% 200 + 160 + 110 3 470 0.000% 200 + 150 + 120 3 470 0.000% 180 + 180 + 110 3 470 0.000% 180 + 160 + 130 3 470 0.000% 160 + 160 + 150 4 470 0.000% 2p430 + 2p510 4 470 0.000% 430 + 3p120 4 470 0.000% 300 + 3p510 4 470 0.000% 390 + 3p240 4 470 0.000% 360 + 3p330 4 470 0.000% 220 + 3p750 4 470 0.000% 2p120 + 2p820 4 470 0.000% 180 + 110 + 2p360 4 470 0.000% 160 + 130 + 2p360 4 470 0.000% 220 + 100 + 2p300 4 470 0.000% 200 + 120 + 2p300 4 470 0.000% 160 + 160 + 2p300 4 470 0.000% 300 + 110 + 2p120 4 470 0.000% 300 + 120 + 2p100 4 470 0.000% 270 + 100 + 2p200 4 470 0.000% 270 + 110 + 2p180 4 470 0.000% 270 + 120 + 2p160 4 470 0.000% 270 + 150 + 2p100 4 470 0.000% 240 + 110 + 2p240 4 470 0.000% 220 + 130 + 2p240 4 470 0.000% 240 + 120 + 2p220 4 470 0.000% 200 + 150 + 2p240 4 470 0.000% 240 + 130 + 2p200 4 470 0.000% 240 + 180 + 2p100 4 470 0.000% 240 + 150 + 2p160 4 470 0.000% 200 + 160 + 2p220 4 470 0.000% 220 + 150 + 2p200 4 470 0.000% 220 + 200 + 2p100 4 470 0.000% 180 + 180 + 2p220 4 470 0.000% 220 + 160 + 2p180 4 470 0.000% 200 + 180 + 2p180 4 470 0.000% 160 + 110 + 100 + 100 4 470 0.000% 150 + 120 + 100 + 100 4 470 0.000% 150 + 110 + 110 + 100 --- End code --- |
| Navigation |
| Message Index |
| Next page |
| Previous page |