Creating Custom Components
The simulator allows, through an XML-based file format, for custom components to be defined as subcircuits of other, fundamental, components. Custom graphics, if required for custom component packages, can also be created using a syntax based upon the WPF Path Markup Syntax (see Microsoft's reference.) This section is intended primarily for "power users", so some basic familiarity with XML syntax is assumed.
Component Data Files
Files containing component models are located in the res/models/ folder in the folder where the program was installed to. Each file contains model for a different type of component:
- 7seg.xml: 7-segment displays
- diodes.xml: diodes
- ics.xml: analog and digital ICs
- leds.xml: LEDs
- transistors.xml: NPN, PNP and NMOS transistors
A sample entry in one of these files is that for the 555 Timer, which is included below
<model name="555 Timer" category="Analog" footprint="DIP8"> <data>RES {r}.R1 {8} {5} res=5000 RES {r}.R2 {5} {r}.VL res=5000 RES {r}.R3 {r}.VL {1} res=5000 OPAMP {r}.U1 {6} {5} {r}.UC {1} {8} OPAMP {r}.U2 {r}.VL {2} {r}.LC {1} {8} LOGIC_NOT {r}.U3 {4} {r}.R_INV {1} {8} LOGIC_OR {r}.U4 {r}.R_INV {r}.UC {r}.RES {1} {8} LOGIC_RS_FLIP_FLOP {r}.U5 {r}.RES {r}.LC {3} {r}.QB {1} {8} RES {r}.R4 {r}.QB {r}.DC res=1000 BJT {r}.Q1 {7} {r}.DC {1} type=npn is=19e-15 bf=150 br=7.5 rb=50 re=0.4 rc=0.3</data> <label pin="1" name="Ground"/> <label pin="2" name="Trigger"/> <label pin="3" name="Output"/> <label pin="4" name="Reset"/> <label pin="5" name="Control Voltage"/> <label pin="6" name="Threshold"/> <label pin="7" name="Discharge"/> <label pin="8" name="Supply"/> </model>
Firstly, various pieces of information are specified about the component in the model tag parameters:
- name specifies a user-friendly name for the component. Integrated circuit labels only display the first word of the name
- category allows parts to be specified into categories. For integrated circuits, this can be Analog or Digital. For transistors, this can be NPN, PNP or NMOS
- footprint specifies the name of a footprint for the component (see below for custom footprints). The simulator includes the following standard IC and transistor footprints: DIP8, DIP14, DIP16, TO-92 and TO-220-GDS.
- LEDs and 7-segment displays also support an extra parameter: colour which, using HTML style syntax, specifies the fully illuminated colour.
Inside the <data> tags contain the subcircuit data itself, which is described in the next section.
Each label tag specifies a user friendly name for a pin, with pin being the pin number and name being the label to display.
Defining Components
An example of a component defined as a subcircuit is a 555 Timer. The subcircuit data for this component is shown in the above section - refer to the content inside the <data> tags
Each line defines a component. Component definitions consist of the following elements, in this order:
- Component type (e.g. RES for resistor)
- Component name
- Name of net connected to each pin - see below for pin ordering
- Component parameters
The following component types are supported by the simulator
- RES: resistor
- CAP: capacitor
- DIODE: diode
- BJT: bipolar (NPN or PNP) transistor
- NMOS: N-channel MOSFET
- OPAMP: op-amp
- LOGIC_type: logic gate of a given type. Supported types are AND, OR, XOR, NOT, NAND, NOR, XNOR, DTYPE (D-type flip flop), DCOUNTER (decade counter), BRCOUNTER (7-bit binary ripple counter), RS_FLIP_FLOP, DISPDECODER (4511 style display decoder)
The pin ordering for common components (where pin ordering is important) are as follows:
- Diodes: anode, cathode
- BJTs: collector, base, emitter
- N-channel MOSFETs: source, gate, drain
- Op-amps: Non-inverting Input, Inverting Input, Output, Negative Supply, Positive Supply
- Logic Gates: Inputs, Outputs, Ground, Positive Supply. In particular:
- AND, OR, XOR, NAND, NOR, XNOR: Inputs: A, B; Outputs: Q
- NOT: Inputs: A; Outputs: Q
- DTYPE: Inputs: D, CLK, S, R; Outputs: Q, Q
- DCOUNTER: Inputs: CLK, INHIBIT, RESET; Outputs: Q0-Q9, CARRY
- BRCOUNTER: Inputs: CLK, RESET; Outputs: Q1-Q7
- RS_FLIP_FLOP: Inputs: R, S; Outputs: Q, Q
- DISPDECODER: Inputs: BCD A-D, Latch, Blank, Lamp Test; Outputs: Segments a-g
The following parameters are supported: (note that all parameters are optional, although many parameters are effectively required)
- Resistors: res=resistance
- Capacitors: cap=capacitance rser=seriesResistance
- Diodes: is=saturationCurrent n=idealityFactor rser=seriesResistance
- BJTs: type=(npn|pnp) is=saturationCurrent bf=forwardGain br=reverseGain rc=collectorResistance rb=baseResistance re=emitterResistance
- N-channel MOSFETs: k=transconduction lambda=channelLengthModulation vth=thresholdVoltage rgs=gateSourceResistance
- Op-amps: rin=differentialInputResistance aol=openLoopGain vosatp=positiveSaturationVoltage vosatn=negativeSaturationVoltage rout=outputSeriesResistance
- Logic Gates: vth=thresholdVoltage rin=inputResistance rout=outputSeriesResistance
Note that {r} is replaced with the unique (in the circuit) name of the component - for a custom IC this would be in the form ICn, where n is an integer, and {n} (where n is an integer between 1 and the number of pins) is replaced with the name of the net connected to pin n. In order to ensure multiple instances of the same subcircuit can be placed, all internal net and component names should be prefixed with "{r}.".
Defining Component Footprints
If you need to add a component which has a package type not included in the default set of footprints, you will need to add an entry to the footprints.xml file. An example entry in this file, for the DIP8 package, is:
<footprint name="DIP8"> <!-- PINS --> <pin number="1" x="0" y="3"/> <pin number="2" x="1" y="3"/> <pin number="3" x="2" y="3"/> <pin number="4" x="3" y="3"/> <pin number="5" x="3" y="0"/> <pin number="6" x="2" y="0"/> <pin number="7" x="1" y="0"/> <pin number="8" x="0" y="0"/> <path name="pin8" fillcolour="Gray" linecolour="Gray">M -0.2, -0.2 h 0.4 v 0.6 h -0.4 v -0.6</path> <path name="pin7" fillcolour="Gray" linecolour="Gray">M 0.8, -0.2 h 0.4 v 0.6 h -0.4 v -0.6</path> <path name="pin6" fillcolour="Gray" linecolour="Gray">M 1.8, -0.2 h 0.4 v 0.6 h -0.4 v -0.6</path> <path name="pin5" fillcolour="Gray" linecolour="Gray">M 2.8, -0.2 h 0.4 v 0.6 h -0.4 v -0.6</path> <path name="pin1" fillcolour="Gray" linecolour="Gray">M -0.2, 2.6 h 0.4 v 0.6 h -0.4 v -0.6</path> <path name="pin2" fillcolour="Gray" linecolour="Gray">M 0.8, 2.6 h 0.4 v 0.6 h -0.4 v -0.6</path> <path name="pin3" fillcolour="Gray" linecolour="Gray">M 1.8, 2.6 h 0.4 v 0.6 h -0.4 v -0.6</path> <path name="pin4" fillcolour="Gray" linecolour="Gray">M 2.8, 2.6 h 0.4 v 0.6 h -0.4 v -0.6</path> <!-- CHIP BODY --> <path fillcolour="Black" linecolour="Black">M -0.4, 0.4 H 3.4 V 2.6 H -0.4 V 0.4</path> <!-- CHIP NOTCH --> <path fillcolour="DarkGray" linecolour="DarkGray">M -0.4, 1.2 H 0 V 1.8 H -0.4 V 1.2</path> <text name="_Model" X="0.5" Y="0.9" size="1" colour="White">DIP8</text> </footprint>
All locations and sizes inside the footprint definition - in pin, path and text elements - are given in a format such at (0, 0) is the 'origin' of the component and each unit represents the space between two adjacent holes.
pin elements specify the location of a pin. It takes three attributes: the pin number, and the x and y locations of that pin.
path elements specify graphics using the WPF Path Markup Syntax. The name attribute gives the name of the path. A name of the type pinn sets that path to be a pin, where n is the pin number. This enables the tooltips that display pin names, voltages and currents.
fillcolour sets the colour with which closed parts of the path are filled. linecolour sets the colour of the lines. Optionally, the thickness attribute can be set to change the line thickness. Inside the path element is the path data itself - see the Microsoft reference linked above.
text elements can be used to add text to the component. The name attribute can be used to make 'special' text elements - setting it to _Model makes it display the model name, and _Value makes it display the component value. X and Y set the position of the text, size sets the font size and colour the colour of the text. Optionally, the font attribute can be used to specify the name of a font to use when displaying the text. Inside the element is the default text to display. All dimensions and positions use the units described above.