Post Reply 
41 voltage divider calculation
02-09-2017, 02:49 PM (This post was last modified: 02-10-2017 07:46 AM by damaltor.)
Post: #1
41 voltage divider calculation
I made a small program for calculating voltage dividers. It allows the calculation of both resistors and the input and output voltage.
Code:
U_in --+
       |
       R1
       |
       +--- U_out
       |
       R2
       |
GND ---+--- GND

The program works similar to the TVM program on the advantage module: It starts with displaying a menu
Code:
R1 R2  UI UO
which is mapped to the top row of keys (A/B/D/E). To enter a value for one of the four variables, simply type in the value and press the corresponding button. To calculate one of the four variables after entering values for the others, press the corresponding button without entering a value before. To show the menu again, press J. This will not work if any of the keys A,B,D,E or J has assigned functions, as the program uses the user mode for the "softkeys".
If any of the values should be changed, you do not need to re-enter all values - simply enter the new value followed by the appropriate softkey and then press the key for the desired variable again.

Please note that this program is made for ease of use and is certainly not the smallest possible.

Example 1: Calculate R1 if U_in is 10V, U_out should be 3V, and R2 is 5kOhm
Code:
Input       Output
XEQ RDIV    R1 R2  UI UO (Menu)
10 D        U.IN=10.000 (Set U_in to 10V)
3 E         U.OUT=3.000 (Set U_out to 3V)
5 EEX 3 B   R2=5,000.000 (Set R2 to 5kOhm)
J           R1 R2  UI UO (Menu, optional)
A           R1=11,666.667 (Calculated optimal value for R1)

Example 2: Calculate U_out if U_in is 5V, R1 is 5kOhm and R2 is 10 kOhm. Same if input voltage is 10V.
Code:
Input       Output
XEQ RDIV    R1 R2  UI UO (Menu)
5 D         U.IN=5.000 (Set U_in to 5V)
5 EEX 3 A   R1=5,000.000 (Set R1 to 5kOhm)
10 EEX 3 B  R2=10,000.000 (Set R2 to 10kOhm)
J           R1 R2  UI UO (Menu, optional)
E           U.OUT=3.333 (Calculated output voltage)
10 D        U.IN=10.000 (Set U_in to 10V)
E           U.OUT=6.667 (new output voltage)

Example 3: Find a good resistor pair to divide 5V to 3.3V
Code:
Input       Output
XEQ RDIV    R1 R2  UI UO (Menu)
5 D         U.IN=5.000 (Set U_in to 5V)
10 EEX 3 B  R2=10,000.000 (Set R2 to 10kOhm as a guess)
3.3 E       U.OUT=3.300 (Set U_out to 3.3V)
A           R1=5,151.151 (Calculated optimal value for R1)
5.1 EEX 3 A R1=5,100.000 (as 5.1kOhm is the next standard value, select this as R1)
E           U.OUT=3.311 (If the standard valued resistor is used, the voltage will be 3.311V which should be ok for most uses)

Here is the program. It has 77 steps in 22 registers and fits on one magnetic card, using both sides. It uses storage registers 01 to 04.
Code:
01 LBL RDIV
02 LBL J
03 SF 27
04 CF 22
05 "R1 R2  UI UO" (two spaces in the middle)
06 PROMPT
07 GTO J
08 LBL A
09 "R1"
10 STO 03
11 FC?C 22
12 XEQ 33
13 GTO 99
14 LBL B
15 "R2"
16 STO 04
17 FC?C 22
18 XEQ 44
19 GTO 99
20 LBL D
21 "U.IN"
22 STO 01
23 FC?C 22
24 XEQ 11
25 GTO 99
26 LBL E
27 "U.OUT"
28 STO 02
29 FC?C 22
30 XEQ 22
31 GTO 99
32 LBL 11
33 RCL 02
34 RCL 03
35 *
36 RCL 04
37 /
38 RCL 02
39 +
40 STO 01
41 RTN
42 LBL 22
43 RCL 01
44 RCL 03
45 RCL 04
46 +
47 /
48 RCL 04
49 *
50 STO 02
51 RTN
52 LBL 33
53 RCL 01
54 RCL 02
55 -
56 RCL 04
57 *
58 RCL 02
59 /
60 STO 03
61 RTN
62 LBL 44
63 RCL 03
64 RCL 02
65 *
66 RCL 01
67 RCL 02
68 -
69 /
70 STO 04
71 RTN
72 LBL 99
73 "꜔=" (append =)
74 ARCL X
75 PROMPT
76 GTO J
77 END
Find all posts by this user
Quote this message in a reply
02-13-2017, 07:17 AM (This post was last modified: 02-13-2017 07:20 AM by Ángel Martin.)
Post: #2
RE: 41 voltage divider calculation
Neat example, thanks for sharing it. It actually should be added to the recently published Equation Library - using SOLVE, and therefore not directly comparable with your program. (see here)

Under that framework the routine to use is below - 17 steps in all but not as fast.

Code:
01  LBL "UDIV"
02  FS? 06
03  GTO 00
04  STO IND 00
05  RCL 01
06  RCL 01
07  RCL 02
08  +
09  /
10  RCL 03
11  *
12  RCL 04
13  -
14  RTN
15  LBL 00
16  "R1 R2 U1 U2"
17  END

Cheers,
'AM
Find all posts by this user
Quote this message in a reply
02-13-2017, 08:22 AM
Post: #3
RE: 41 voltage divider calculation
Interesting idea. Feel free to add it - it would surely fit in there. I also made a version including "SOLVE" a while ago, but that would not work without the advantage module. i unfortunately lost the code... I really like that equ library!
Find all posts by this user
Quote this message in a reply
Post Reply 




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