Post Reply 
(48G/S) Closest Standard-Resistor Values
09-24-2020, 11:40 AM
Post: #1
(48G/S) Closest Standard-Resistor Values
An excerpt from Calculator program finds closest standard-resistor values, EDN (magazine), Francesc Casanellas, February 3, 2005, pg.86

"  You can use a Hewlett-Packard HP-48or HP-49 calculator and one of the following programs written in RPN (Reverse-Polish Notation) to compute the nearest standard value that’s closest to a required value.You enter a required resistor value, and the program returns the closest higher or lower value in the selected series …

EDN050203DI3580—LISTINGS 1, 2, and 3
“Calculator program finds closest standard-resistor values,” EDN, Feb 3, 2005, pg
86 …

BEST!
SlideRule
Find all posts by this user
Quote this message in a reply
09-24-2020, 01:18 PM
Post: #2
RE: (48G/S) Closest Standard-Resistor Values
This is a very useful program, and I wrote a more compact version several years ago which is for the 48G and later, because it uses DOLIST::

Code:

\<< DUP MANT { 1. 1.1 1.2 1.3 1.5 1.6 1.8 2. 2.2 2.4 2.7 3. 3.3 3.6 3.9 4.3 4.7
5.1 5.6 6.2 6.8 7.5 8.2 9.1 10. } \-> r m L1
  \<< L1 1.
    \<< m >
    \>> DOLIST 1. POS DUP 'L1' SWAP GET m / SWAP 1. - 'L1' SWAP GET m / INV DUP2 <
{ DROP r * } { SWAP DROP r SWAP / } IFTE -2. RND
  \>>
\>>
Find all posts by this user
Quote this message in a reply
09-25-2020, 12:23 AM
Post: #3
RE: (48G/S) Closest Standard-Resistor Values
I've done similar programs, with E48/96/E192 versions below.

Code:

@ Closest Standard Resistor Values
E48
\<< 
@ E48 2%
    DUP DUP XPON SWAP MANT
     [ 0.909 0.953 1 1.05 1.1 1.15 1.21 1.27 1.33 1.4 1.47 1.54 1.62 1.69 1.78 1.87 1.96 2.05 2.15 2.26 2.37 2.49 2.61 2.74 2.87 3.01 3.16 3.32 3.48 3.65 3.83 4.02 4.22 4.42 4.64 4.87 5.11 5.36 5.62 5.9 6.19 6.49 6.81 7.15 7.5 7.87 8.25 8.66 9.09 9.53 10 10.5] 
     0 
    \-> InitialValue Power Val StdVal ii
      \<< 
      @ DO...UNTIL...END
        DO 'ii' INCR
    DROP
        UNTIL StdVal ii
    GET Val >
        END StdVal ii
    GET Val - Val ii 1
    - StdVal SWAP GET -
        IF <
        THEN ii
        ELSE ii 1 -
        END StdVal SWAP
    GET Power ALOG *
    'ClosestE48' \->TAG
    DUP DUP InitialValue SWAP - SWAP / 100 *  -2 RND 'ERROR% ' \->TAG
      \>> 
\>>

E96
@ E96 1%
\<< 

    DUP DUP XPON SWAP MANT
     [ .953 .976 1 1.02 1.05 1.07 1.1 1.13 1.15 1.18 1.21 1.24 1.27 1.3 1.33 1.37 1.4 1.43 1.47 1.5 1.54 1.58 1.62 1.65 1.69 1.74 1.78 1.82 1.87 1.91 1.96 2 2.05 2.1 2.15 2.21 2.26 2.32 2.37 2.43 2.49 2.55 2.61 2.67 2.74 2.8 2.87 2.94 3.01 3.09 3.16 3.24 3.32 3.4 3.48 3.57 3.65 3.74 3.83 3.92 4.02 4.12 4.22 4.32 4.42 4.53 4.64 4.75 4.87 4.99 5.11 5.23 5.36 5.49 5.62 5.76 5.9 6.04 6.19 6.34 6.49 6.65 6.81 6.98 7.15 7.32 7.5 7.68 7.87 8.06 8.25 8.45 8.66 8.87 9.09 9.31 9.53 9.76 10 10.2 ] 
     0 
    \-> InitialValue Power Val StdVal ii
      \<< 
      @ DO...UNTIL...END
        DO 'ii' INCR
    DROP
        UNTIL StdVal ii
    GET Val >
        END StdVal ii
    GET Val - Val ii 1
    - StdVal SWAP GET -
        IF <
        THEN ii
        ELSE ii 1 -
        END StdVal SWAP
    GET Power ALOG *
    'ClosestE96' \->TAG
    DUP DUP InitialValue SWAP - SWAP / 100 *  -2 RND 'ERROR% ' \->TAG
      \>> 
\>>

E192
@ E192 0.5%
\<< 

    DUP DUP XPON SWAP MANT
     [0.976 0.988 1 1.01 1.02 1.04 1.05 1.06 1.07 1.09 1.1 1.11 1.13 1.14 1.15 1.17 1.18 1.2 1.21 1.23 1.24 1.26 1.27 1.29 1.3 1.32 1.33 1.35 1.37 1.38 1.4 1.42 1.43 1.45 1.47 1.49 1.5 1.52 1.54 1.56 1.58 1.6 1.62 1.64 1.65 1.67 1.69 1.72 1.74 1.76 1.78 1.8 1.82 1.84 1.87 1.89 1.91 1.93 1.96 1.98 2 2.03 2.05 2.08 2.1 2.13 2.15 2.18 2.21 2.23 2.26 2.29 2.32 2.34 2.37 2.4 2.43 2.46 2.49 2.52 2.55 2.58 2.61 2.64 2.67 2.71 2.74 2.77 2.8 2.84 2.87 2.91 2.94 2.98 3.01 3.05 3.09 3.12 3.16 3.2 3.24 3.28 3.32 3.36 3.4 3.44 3.48 3.52 3.57 3.61 3.65 3.7 3.74 3.79 3.83 3.88 3.92 3.97 4.02 4.07 4.12 4.17 4.22 4.27 4.32 4.37 4.42 4.48 4.53 4.59 4.64 4.7 4.75 4.81 4.87 4.93 4.99 5.05 5.11 5.17 5.23 5.3 5.36 5.42 5.49 5.56 5.62 5.69 5.76 5.83 5.9 5.97 6.04 6.12 6.19 6.26 6.34 6.42 6.49 6.57 6.65 6.73 6.81 6.9 6.98 7.06 7.15 7.23 7.32 7.41 7.5 7.59 7.68 7.77 7.87 7.96 8.06 8.16 8.25 8.35 8.45 8.56 8.66 8.76 8.87 8.98 9.09 9.2 9.31 9.42 9.53 9.65 9.76 9.88 10 10.1] 
     0 
    \-> InitialValue Power Val StdVal ii
      \<< 
      @ DO...UNTIL...END
        DO 'ii' INCR
    DROP
        UNTIL StdVal ii
    GET Val >
        END StdVal ii
    GET Val - Val ii 1
    - StdVal SWAP GET -
        IF <
        THEN ii
        ELSE ii 1 -
        END StdVal SWAP
    GET Power ALOG *
    'ClosestE192' \->TAG
    DUP DUP InitialValue SWAP - SWAP / 100 *  -2 RND 'ERROR% ' \->TAG
      \>> 
\>>
Find all posts by this user
Quote this message in a reply
09-26-2020, 02:25 PM (This post was last modified: 09-26-2020 02:28 PM by John Keith.)
Post: #4
RE: (48G/S) Closest Standard-Resistor Values
Those are great, thanks for posting them! The output of the programs are very nice.

The problem with all of these programs is the size of the lists of resistor values. The array from E192, the worst case, takes over 1800 bytes.

The standard resistor values are based on the nth root of 10, where n is 24, 48, 96 or 192. Unfortunately the R24 values are somewhat arbitrary and several of them differ from the calculated values by + or - 0.1 Ohms.

Luckily the R48 and R96 values are exact and we can save much of the memory required by the program by computing the lists directly. Here is a version of my program from above for the R96 values:

Code:

\<< DUP MANT 96. 10. OVER XROOT SWAP x DUP 0. 4. ROLL 1. SEQ ^ -3. RND \-> r m L1
  \<< L1 1.
    \<< m >
    \>> DOLIST 1. POS DUP 'L1' SWAP GET m / SWAP 1. - 'L1' SWAP GET m / INV DUP2 < { DROP r * } { SWAP DROP r SWAP / } IFTE -3. RND
  \>>
\>>

The program for the R48 values is nearly the same, just substituting the number 48 for 96.

The R192 values do have one value that is off by 0.01 Ohms- the calculated value of 9.2 is actually 9.19. The program is thus a bit longer and less elegant but not too bad:

Code:

\<< DUP MANT 192. 10. OVER XROOT SWAP x DUP 0. 4. ROLL 1. SEQ ^ -3. RND 186. { 9.2 } REPL \-> r m L1
  \<< L1 1.
    \<< m >
    \>> DOLIST 1. POS DUP 'L1' SWAP GET m / SWAP 1. - 'L1' SWAP GET m / INV DUP2 < { DROP r * } { NIP r SWAP / } IFTE -3. RND
  \>>
\>>

Since the format of the arrays in your programs differs from the list in the original program, there would be some additional complexity but probably well worth it for the saving of precious calculator memory.
Find all posts by this user
Quote this message in a reply
09-27-2020, 02:43 PM
Post: #5
RE: (48G/S) Closest Standard-Resistor Values
It occurred to me that since the standard values are (mostly) exact for E48, E96 and E192 we can dispense with lists entirely. I have stolen some of David Bengston's code for the following programs because the method of the original program does not work well with the one exception for E192.

First the program for E96. The program for E48 is again the same except for replacing the number 96 with 48.

Code:

\<< DUP DUP XPON SWAP MANT 10. 96. INV ^ \-> val xpon mant r
  \<< mant LN r LN / IP r SWAP DUP2 ^ ROT ROT 1. + ^ DUP2 mant - SWAP mant - NEG <
{ SWAP } IFT DROP -3. RND xpon ALOG *
  \>>
\>>

For E192 we must add a check for the errant value but the program is otherwise the same:

Code:

\<< DUP DUP XPON SWAP MANT 10. 192. INV ^ \-> val xpon mant r
  \<< mant LN r LN / IP r SWAP DUP2 ^ ROT ROT 1. + ^ DUP2 mant - SWAP mant - NEG <
{ SWAP } IFT DROP -3. RND DUP 9.19 SAME { DROP 9.2 } IFT xpon ALOG *
  \>>
\>>

Both programs work with all RPL calculators from the HP-28C through the 50g.
Find all posts by this user
Quote this message in a reply
09-27-2020, 08:50 PM
Post: #6
RE: (48G/S) Closest Standard-Resistor Values
Thanks! With the memory in a 50G being so (relatively) large, I wasn't too concerned about saving bits, unlike an equivalent program in a 41 or 42S. This was for sure a quick hack, but it's been useful over the years. Your improvements in size are nice though. This makes it possible to incorporate this into other programs I'm working on.

Dave
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)