The Switch-Resistor Circuit Analysis Program
Providing input to the program
The program for analyzing switch-resistor circuits
takes as input a textual 'netlist' file,
in a 'spice'-like format. That means:
- The input is read line-by-line. Lines with an unfamiliar
first character are silently ignored.
This tool will interpret lines that start with R, Q, and V.
- A node in the network is a set of electrically connected terminals (pins).
Nodes are numbered from 0 upwards, where the number 0 is reserved for GND, and
is the reference for the other node voltages.
- R[identifier] [node-a] [node-b] [optional model name] [value]
describes a resistor. The value is a floating-point number or a number
in the electrical-engineering style as 4K7.
- Q[identifier] [node-1] [node-c] [node-0]
describes a switch. Apology to those who know that I mis-use Q here :-(
- Vin [node-in] 0
Vout [node-out] 0
these indicate to the program which two nodes are input and output terminals.
You can create such a text-file with your familiar text editor ('notepad'??),
or with a real schematic editor.
I used Micro-Cap
for this purpose.
You can cut-n-paste the created text into the text-box below.
If appropriate for your circuit, you choose a small value for the max nr switches set.
(For the 'rotary switch' example this would be 1,
indicating that you intend to close only one switch at a time.
This saveguards you for an explosion of the amount of program output.
Your beginners example is:
R1 1 2 1K
R2 2 0 1K
Vin 1 0
Vout 2 0
And the example circuits from the circuits page:
rotary switch,
logarithmic ladder,
2-stage pot.
Run the program
Capture the program output
After pressing the compute button, the program
will create its textual output in a new window.
It will provide some feedback on the read circuit.
If no errors are detected, a line of =====
is printed, followed by the computed circuit behavior.
There is a header line with names,
and one subsequent line with numbers for every switch open/close combination.
Although the formatting might seem to be messed-up,
all these lines together form a table. Table entries
per line are separated by tab characters,
allowing cut-n-paste of a properly formatted table in a real text editor.
The program assumes a source-resistance for Vin of 0 ohm,
and no load resistance connected to Vout. You might want to add such resistances to the circuit.
To avoid numeric exceptions in processing the output, two precautions are implemented:
-
If for some switch combination the output signal becomes truly 0
(not connected to the input, or shorted to gnd),
the program prints '-999' dB attenuation.
-
If for some switch combination an input or output resistance becomes infinitely high
(unconnected) the program prints a resistance of 1.0E9 ohm
To create graphical output, you copy the data into Excel as follows:
- Copy-and-paste all lines below the ==== into a notepad window,
and save as a .txt file.
- Open Excel
- Click Data->Import External Data->Import Data and select your file.
- In the appeared Text Import Wizard:
- mark Delimited (default),
start import at row 1, click Next
- mark Tab delimiter (default), click Next
- choose General Column data format(default),
In non-US versions (as my Dutch) you might need to click
Advanced and set Decimal separator to '.'
and Thousands separator to ',', click OK.
- mark Existing worksheet (default)
- Now the table appears in the spreadsheet fields.
Select field A1 (showing 'Vout/Vin[dB]') with a click.
- Click Data->Sort..., Sort by 'Vout/Vin[dB]', mark Descending
- Delete rows which contain unintended switch combinations, by clicking the row number
and select Edit->Delete
- To make pictures from the data, you click Insert->Chart
So far with this Excel course....
Success with your own circuits!
(An interesting site with free software tools for Electrical Engineering is
Greg's downloadpage.)
Jos van Eijndhoven, January 2004,
Back to the Switch-Resistor page,
Back to my home page
-- For this program I used SUN's
Java2 SDK (1.4.2),
and a great freeware
JCreator LE (2.5) development tool