![]() | ![]() | ![]() |
| |||||||
| Chit-Chat Relax for a bit and have a general conversation (off topic is allowed!) with other members. Please be polite and respect your fellow members. |
![]() |
| | Tools |
| | #1 |
|
I've being trying to write a program that calculates the nearest set of parallel or series resistors to a specified value. One thing that's made it more difficult is that the some E24 values deviate from the geometric sequence. Correct rounded geometric sequance: 10 11 12 13 15 16 18 20 22 24 26 29 32 35 38 42 46 51 56 62 68 75 83 91 E24 values 10 11 12 13 15 16 18 20 22 24 27 30 33 36 39 43 47 51 62 68 75 82 91 Why couldn't they have just stuck to the rounded geometric sequence? The E192 values also differs too but it's not too bad, 920 instead of 919. I don't know why it's not like they're rounding to the nearest decade when they have 301. ![]() I don't suppose anyone cares, just letting off steam.
__________________ I do not answer private messages asking for help because no one else can: benefit from advice I may give or correct me if I'm wrong. Please ask on the open forum if you have a question and I'll be happy to help, if I know the answer. | |
| |
| | #2 |
|
Probably so they could still use some of the E12 values. Imagine how many 2.7k and 330 ohm resistors are out there!
__________________ IF YOU WANT TO HELP FINE IF NOT PLEASE DON"T PEE IN MY CHEERO'S | |
| |
| | #3 |
|
Why would not been in an exact geometric sequence make any difference to your program?. As suggested, it's probably because it's an extension of E12. | |
| |
| | #4 |
|
Even if it's an extension of the E12 series, it's still wrong because the E12 series was wrong: 27, 33, 39, 47, 82 are all wrong. It does make a difference for the program: the formula The first part of the program just gets the nearest E24 value, it works but because of the errors, I've had to fiddle it so it generates the right values.
__________________ I do not answer private messages asking for help because no one else can: benefit from advice I may give or correct me if I'm wrong. Please ask on the open forum if you have a question and I'll be happy to help, if I know the answer. | |
| |
| | #5 | |
| Quote:
I think I mentioned before, years back (pre-Windows) I wrote a program for parallel resistors. Just give it a value, and it displayed the most accurate results using two resistors in parallel - plus the percentage of error for each combination. Unfortunately it was on a long defunkt DOS 386 laptop, but it wasn't a very long program, and was written in Turbo Pascal. Last edited by Nigel Goodwin; 23rd May 2009 at 07:26 PM. | ||
| |
| | #6 |
|
It's not just E24 values I'm doing it for the E192 values too. In the end I want to make it so you can choose between E3, E6, E12, E24, E48, E96 and E192 values. There's nothing weird about that formula, it's just a standard geometric sequence, i is the index and b is the base. For example to calculate the 21th E48 value R = 10^(21/48) = 2.74. To get the index from the value, transpose the formula. i = 48*log10(2.74) = 21. If the value is not an exact E value then all we need to do is round the result to the nearest integer and it gives the index of nearest E value. i = 48*log10(2.7) = 20.7 = 21. I am using look up tables. The formula creates all the values and the above transposition of the formula indexes the tables. I could have used a search to find the value but that would probably have proven slow on the E192 values. First the arrays are filled with E24 and E192 values and which are fiddled so they equal the standard EA values. The program requests the desired value from the user. The transposition of the origional formula is used to index the array to get the nearest value. This is compared with the mantissa, if it's too big the next smallest value is used, if it's too bit the next largest value is used. I'm using old QBasic because it's the only language I know. You can still download it from the MS website and there's an open-source clone FreeBasic which is 95% QB compatible. Here's the program: Code: DEFINT A-Z ' Set default variable type to integer. DIM SHARED values(1 TO 216)' An array for the E24 values and E192 values. DIM SHARED lgb10 AS DOUBLE ' Define log10 so we don't have to recalculate it. lgb10 = LOG(10) CLS FOR n = 1 TO 24 ' Calculate the E24 values. values(n) = 10 ^ (1 + n / 24) IF n >= 10 AND n <= 16 THEN values(n) = values(n) + 1 'Fiddle to fit E24 values(n) = values(n) * 10 NEXT values(22) = 820' Fiddle to fit E24 FOR n = 1 TO 192 values(n + 24) = 10 ^ (2 + n / 192) NEXT values(209) = 920' Fiddle to fit E192 FOR n = 1 TO 24 PRINT values(n) NEXT INPUT "Enter value"; value# lgval# = LOG(value#) / lgb10' Take log10 of the value. ex = INT(lgval#)' Exponent is the integer part of log 10 of the value. dec#= lgval# - ex' store the decimal part of log10. el = dec#* 24' Work out the nearest preferred number. mnt = 10 ^ (2 + dec#)' get the mantissa. ex = ex - 2' Preferred numbers in the array are multiplied by 100 so /100. IF el = 0 THEN ' If zero, wrap round to highest value and /10 to compensate. ex = ex - 1 el = 24 mnt = mnt * 10 END IF ' A fiddle to align the result to the preferred number. dif = values(el) - mnt' The difference between the ideal and preferred value. IF el > 1 THEN IF dif > mnt - values(el - 1) THEN el = el - 1 IF el < 24 THEN IF dif < mnt - values(el + 1) THEN el = el + 1 PRINT "Index"; el PRINT "Mantissa"; mnt PRINT "Exponent:"; ex PRINT "Nearest E24 Value"; values(el) * 10 ^ ex Code: DIM lg10 AS DOUBLE DEFINT A-Z lg10 = LOG(10) INPUT "Enter value"; r# lg10r# = LOG(r#) / lg10 ex = INT(lg10r#) PRINT ex E96 = CINT(10 ^ (2 + CINT(96 * LOG(10 ^ (lg10r# - ex)) / lg10) / 96)) * 10 ^ (ex - 2) PRINT E96 CINT rounds the number to an integer, i.e CINT(9.6) = 10 and INT converts the number an integer simply by removing all the decimal places, i.e INT(9.6) = 9. When a interger variable is set to a floating point value, it's just rounded to the nearest integer. LOG is the natural logarithm, there's no way to to Log to the base x in QB, you have to do LOG(n)/LOG(b).
__________________ I do not answer private messages asking for help because no one else can: benefit from advice I may give or correct me if I'm wrong. Please ask on the open forum if you have a question and I'll be happy to help, if I know the answer. Last edited by Hero999; 24th May 2009 at 12:03 AM. | |
| |
| | #7 |
| Tables are incredibly fast, FAR faster than any maths you might be doing, I don't see any reason for a formula at all, which as you say, doesn't work anyway.
| |
| |
| | #8 |
|
Why create the tables on the fly? Are you that short on eeprom or data flash space?
__________________ "Because I be what I be. I would tell you what you want to know if I could, mum, but I be a cat, and no cat anywhere ever gave anyone a straight answer, har har." | |
| |
| | #9 | |
| Quote:
| ||
| |
| | #10 |
|
Woah... I missed that he was doing this on a PC just kind of went in one eye and out the other typical for me.Yeah, no point in using a calculation when you can just drop in a static table for something like that.
__________________ "Because I be what I be. I would tell you what you want to know if I could, mum, but I be a cat, and no cat anywhere ever gave anyone a straight answer, har har." Last edited by Sceadwian; 25th May 2009 at 04:10 AM. | |
| |
| | #11 |
|
With QBasic you might put entire look-up tables in data lines to read on request. Still faster than Turbo-Pascal. Boncuk
__________________ Proper Planning Prevents Piss Poor Performance | |
| |
| | #12 | |
| Quote:
![]() You've obviously never used Turbo Pascal, it compiles blindingly fast, and runs blindingly fast. The Borland Turbo range of compilers were named that for good reason, incredible speed from them, particularly the Pascal version. | ||
| |
| | #13 |
|
Will Qbasic programs even run on windows?
__________________ Pay it forward. Last edited by Mikebits; 25th May 2009 at 11:07 AM. | |
| |
| | #14 |
| Same applies to Turbo Pascal, both are DOS only - but may run in a DOS window. Anything compiled with Turbo Pascal may also need the EXE file patching, if it uses the delay() function - as faster processors mean the original code isn't capable of working, the delay loops exceed their maximum capacity - same for all the Borland Turbo series. But you can download a simple patch program, that rewrites the EXE file. | |
| |
| | #15 | |
| Quote:
We made a speed test simply using a stop watch for the same math problem to be executed using Turbo Pascal and QBasic. There were some complicated formulas involved to calculate a certain retirement payment for a certain time and how many years someone would have to save a certain amount of money in monthly deposits to have the money "consumed" after the time period calculated for. QBasic was the winner - almost double speed.
__________________ Proper Planning Prevents Piss Poor Performance | ||
| |
|
| Tags |
| e24, values, wrong |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| Resistor Values | MrDEB | Electronic Projects Design/Ideas/Reviews | 5 | 21st May 2008 03:49 AM |
| A/D Values | Omar.M | Micro Controllers | 0 | 16th April 2007 10:56 PM |
| Resistor values...... | madmikejt12 | General Electronics Chat | 12 | 11th October 2005 04:12 PM |
| need a circuti with values | samratyuvi | General Electronics Chat | 15 | 23rd September 2005 11:06 PM |
| How to compare values? | Lac | Micro Controllers | 7 | 26th January 2005 03:45 PM |