06-19-2014, 03:46 PM (This post was last modified: 06-20-2014 08:39 AM by Ángel Martin.)
Post: #1
 Ángel Martin Senior Member Posts: 1,254 Joined: Dec 2013
Like me, you may have also missed the excellent article in the old forum by Guillermo Castarés with programs to solve electric circuits:

http://www.hpmuseum.org/software/41/41elcirc.htm

The approached he followed was remarkable in two aspects – first it had a precise usage of the PVT routine from the Math Pac using complex matrices; which wasn’t documented at all in the flimsy manual that was provided with that module.

More interesting was his idea of using ASCII files to define the circuit topology: type, elements, values, etc. This approach allows a very effective use of the system capabilities, without the need to re-enter all data each time allowing quick what-if scenarios for component value changes.

Not to mention that you could build up a library of circuits in X-memory very nicely. For example, these are the files for the Math Pac and the Advantage Pac manuals (Remember student “AC Dimmer”?), listed with their respective solutions.

Code:
 MPAC        ACDIM I4        0    I2 0V1 34 0    1    0V1 5 0 0R1 1        2    0Z1 10 1R2 1        3    1Z2 0 200 0R2 1        4    0Z2 0 -30 2R3 1        5    END 0R3 1             3R4 1        I1 = 0.0372 + 0.1311 0R4 2        I2 = 0.0437 + 0.1543 END                          I1 = 21             I2 = 8             I3 = 3             I4 = 1

I’ve taken the opportunity to update the program, replacing the PVT call with the much faster MSYS in the Advantage Pac (or in the SandMatrix, of course); an splendid example of the MCODE advantages.

And to round up the task a new data-entry program is also provided, which builds the ASCII file from the scratch in an interactive way just entering the information in the prompts.

The new data-entry program “EEE” is completely independent, and its end result is an ASCII file to use as input for “EEA”, the circuit solver program.

Raw files are attached if you want to take them for a spin. Note that they use functions form the AMC_OSX module for a more convenient UI – but you can replace them with those in the CCD with the same names.

Code:
 1    LBL "EEE"  2    "NAME? "  3    PMTA 4    15 5    SF 25 6    CLFL 7    FC?C 25 8    CRFLAS 9    , 10    SEEKPTA 11    "TYPE? VI"  12    PMTK 13    CF 02 14    E  15    X#Y? 16    SF 02 17    "V" 18    FS? 02 19    "I" 20    CLA 21    XTOA 22    APPREC 23    "#NODE"  24    FS? 02 25    "#LOOP"  26    "|-S=?"  27    PROMPT 28    STO 02 29    CLA 30    ARCLI 31    APPCHR 32    "ELMNTS=?"  33    PROMPT 34    E3/3+ 35    STO 00 36    LBL 00 37    CF 00 38    CLA 39    RCL 00 40    ARCLI 41    "|-: "  42    FC? 02 43    "|-I" 44    FS? 02 45    "|-V" 46    "|-RGLCXBYZY" 47    PMTK 48    XEQ IND X 49    STO 01 50    LBL 12 51    "FROM^TO=?"  52    PROMPT 53    X=Y? 54    GTO 12 55    RCL 02 56    X<Y? 57    GTO 12 58    X<> Z 59    RCL 02 60    X<Y? 61    GTO 12 62    RDN 63    XEQ 10 64    0 65    "VALUE=?"  66    FS? 00 67    "IM^RE=?" 68    PROMPT 69    XEQ 11 70    FS? 00 71    XEQ 11 72    ISG 00 73    GTO 00 74    "END" 75    APPREC 76    RTN 77    LBL 01 78    SF 00 79    86 80    FC? 02 81    73 82    RTN 83    LBL 02 84    82 85    RTN 86    LBL 03 87    71 88    RTN 89    LBL 04 90    76 91    RTN 92    LBL 05 93    67 94    RTN 95    LBL 06 96    88 97    RTN 98    LBL 07 99    66 100    RTN 101    LBL 08 102    SF 00 103    90 104    RTN 105    LBL 09 106    SF 00 107    89 108    RTN 109    LBL 10 110    CLA 111    ARCLI 112    RCL 01 113    XTOA 114    X<> Z 115    ARCLI 116    "|- "  117    APPREC 118    RTN 119    LBL 11 120    CF 01 121    CLA 122    FRC 123    X=0? 124    SF 01 125    X<> L 126    FS? 01 127    ARCLI 128    FC? 01 129    ARCL X 130    "|- " 131    APPCHR 132    X<>Y 133    END          289 bytes

Modified EEA Program follows - maintains the same logic as the original to read the circuit file and create the system matrices, only slightly modified the data output routine to account for the differences between PVT and MSYS. Refer to the original article for user instructions and documentation.

Code:
 1    LBL " EEA" 2    CLRG 3    CLX 4    SEEKPTA 5    GETREC 6    ATOX 7    STO 09 8    ANUM 9    ST+ X 10    STO 14 11    X^2 12    LASTX 13    ST+ X 14    + 15    15 16    + 17    SF 25 18    ARCL IND X 19    FC?C 25 20    PSIZE 21    SF 00 22    SF 01 23    LBL 08 24    GETREC 25    AVIEW 26    ATOX 27    48 28    - 29    STO 00 30    ATOX 31    STO 07 32    ATOX 33    48 34    - 35    STO 01 36    ANUM 37    STO 02 38    ATOX 39    LBL 09 40    ATOX 41    44 42    X<=Y? 43    GTO 09 44    CLX 45    ANUM 46    STO 03 47    CLA 48    RCL 09 49    XTOA 50    "|-ELS" 51    ASTO X 52    XEQ IND X 53    FC? 00 54    GTO 07 55    FS? 02 56    XEQ 01 57    FC? 02 58    XEQ 03 59    GTO 08 60    LBL 07 61    "WAIT…"  62    AVIEW 63    RCL  14 64    X^2 65    LASTX 66    + 67    14 68    + 69    STO 00 70    "R" 71    AIP 72    RCL 14 73    2E-3 74    + 75    MATDIM 76    RCL 14 77    E3 78     / 79    RCL 14 80    STO 13 81    + 82    ASTO 12 83    "R14" 84    MATDIM 85    "|-," 86    ARCL 12 87    MSYS 88    LBL 10 89    RCL 13 90    2E3 91     / 92    E  93    + 94    STO 01 95    LBL 12 96    RCL 00 97    RCL 01 98    ST+ X 99    E 100    - 101    + 102    STO 02 103    CLA 104    RCL 09 105    XTOA 106    RCL 01 107    AIP 108    ASTO 10 109    "|-(RE)=" 110    ARCL IND 02 111    PROMPT 112    CLA 113    ARCL 10 114    "|-(IM)=" 115    RCL 13 116    RCL 02 117    + 118    ARCL IND X 119    PROMPT 120    ISG 01 121    GTO 12 122    GTO 10 123    ….     the rest is as the original      [code]

Hope you enjoy it - Many thanks to Guillermo for the original contribution!

Attached File(s)