Subcircuits

Packaging a circuit in a chip


In order to create subcircuit "chips" we need:
- Subcircuit file
- Package file
- Add entry to subcircuits.xml

Subcircuit file:

Use Fixed Voltage component for inputs and Probe for outputs.
Set the Ids of these inputs and outputs as PackagePinN, where "N" is the pin Number of the chip as in the datasheet.

For example 74HC08.
In the right side we can see diagram from datasheet, in the left side the circuit created in SimulIDE.



Then right-click in any empty part of the circuit and select "Create SubCircuit".

A file named "subcirc.xml" will be saved to SimulIDE folder.

Rename this file as 74HC08.subcircuit.

Move 74HC08.subcircuit to data/logic/


Package file:

From the datasheet you can create the package file describing pins and package size.



Create a file with name 74HC08.package with this content and save in data/logic:


<!DOCTYPE SimulIDE>
<package name="74HC08" pins="14" width="4" height="8">

    <pin side="left" pos="1"  type="" id="1A"  label="1A" /><!-- packagePin1 -->
    <pin side="left" pos="2"  type="" id="1B"  label="1B" /><!-- packagePin2 -->
    <pin side="left" pos="3"  type="" id="1Y"  label="1Y" /><!-- packagePin3 -->
    <pin side="left" pos="4"  type="" id="2A"  label="2A" /><!-- packagePin4 -->
    <pin side="left" pos="5"  type="" id="2B"  label="2B" /><!-- packagePin5 -->
    <pin side="left" pos="6"  type="" id="2Y"  label="2Y" /><!-- packagePin6 -->
    <pin side="left" pos="7"  type="" id="GND" label="GND"/><!-- packagePin7 -->

    <pin side="right" pos="7" type="" id="3Y"  label="3Y" /><!-- packagePin8 -->
    <pin side="right" pos="6" type="" id="3A"  label="3A" /><!-- packagePin9 -->
    <pin side="right" pos="5" type="" id="3B"  label="3B" /><!-- packagePin10 -->
    <pin side="right" pos="4" type="" id="4Y"  label="4Y" /><!-- packagePin11 -->
    <pin side="right" pos="3" type="" id="4A"  label="4A" /><!-- packagePin12 -->
    <pin side="right" pos="2" type="" id="4B"  label="4B" /><!-- packagePin13 -->
    <pin side="right" pos="1" type="" id="Vcc" label="Vcc"/><!-- packagePin14 -->
   
</package>


Add entry to subcircuits.xml:

Open data/subcircuits.xml in a text editor
Add this line to 74 section:

<item name="74HC08" package="logic/74HC08.package" subcircuit="logic/74HC08.subcircuit" icon="ic2.png" ></item>

So it will look like this:

<!DOCTYPE SimulIDE>
<itemlib>
   
    <itemset category="IC 74" type="Ic74">

    <item name="74HC42"  package="logic/74HC42.package"  subcircuit="logic/74HC42.subcircuit"  icon="ic2.png" ></item>
    <item name="74XX90"  package="logic/74XX90.package"  subcircuit="logic/74XX90.subcircuit"  icon="ic2.png" ></item>
    <item name="74XX92"  package="logic/74XX92.package"  subcircuit="logic/74XX92.subcircuit"  icon="ic2.png" ></item>
    <item name="74XX93"  package="logic/74XX93.package"  subcircuit="logic/74XX93.subcircuit"  icon="ic2.png" ></item>
    <item name="74HC151" package="logic/74XX151.package" subcircuit="logic/74XX151.subcircuit" icon="ic2.png" ></item>
    <item name="74HC164" package="logic/74XX164.package" subcircuit="logic/74XX164.subcircuit" icon="ic2.png" ></item>
    <item name="74HC573" package="logic/74XX573.package" subcircuit="logic/74XX573.subcircuit" icon="ic2.png" ></item>
    <item name="74HC574" package="logic/74XX574.package" subcircuit="logic/74XX574.subcircuit" icon="ic2.png" ></item>
    <item name="74HC595" package="logic/74XX595.package" subcircuit="logic/74XX595.subcircuit" icon="ic2.png" ></item>
   
    <item name="74HC08" package="logic/74HC08.package" subcircuit="logic/74HC08.subcircuit" icon="ic2.png" ></item>
   
    </itemset>
   
</itemlib>


You are Done!
Open SimulIDE and test your new component.
 ____________________________________________________________________________________

Another Example: 

This is just a Voltage Divider, but could be any circuit.
Ok... not any, you can not use LCD's, Leds, potentiomenters, steepers or anyThing having buttons or so.

I will use Fixed volt, ground and probe as subcircuit input/output.
These ones will not be in the subcircuit, they will be subtituted by chip pins.
As you see i edited the names of these components to match package pins.
These names MUST be in the format PackagePinN, where "N" is the package number pin (note uppercase "P").
To edit component names, select it, open Properties tab (left Panel), edit "Id" field and set "Show Id" as true.
When you have the circuit with all inputs/ouputs configured, Right-Cilck on any empty part of the circuit and select "Create Subcircuit".
A file named "subcirc.xml" will be in simulide executable folder.
Rename it to "voltdiv.subcircuit" and move to data/logic/ (replace "voltdiv" by any name you want).
Ok... we already have the subcircuit file, now we need a package file describing component geometry, pin positions and pin names:
Create a file in data/logic/ with name voltdiv.package, define all the data like this:
<!DOCTYPE SimulIDE>

<package name="voltdiv" pins="3" width="4" height="5">

    <pin side="top"    pos="1"  type="" id="1"  label="1" /><!-- packagePin1 -->
    <pin side="right"  pos="1"  type="" id="2"  label="2" /><!-- packagePin2 -->
    <pin side="bottom" pos="1"  type="" id="3"  label="3" /><!-- packagePin3 -->

</package>
Now edit data/subcircuits.xml file to add the entry of our new component.
We will add it in a new category:
<!DOCTYPE SimulIDE>

<itemlib>

    <itemset category="IC 74" type="Ic74">

    <item name="74HC42"  package="logic/74HC42.package"  subcircuit="logic/74HC42.subcircuit"  icon="ic2.png" ></item>
    <item name="74XX90"  package="logic/74XX90.package"  subcircuit="logic/74XX90.subcircuit"  icon="ic2.png" ></item>
    <item name="74XX92"  package="logic/74XX92.package"  subcircuit="logic/74XX92.subcircuit"  icon="ic2.png" ></item>
    <item name="74XX93"  package="logic/74XX93.package"  subcircuit="logic/74XX93.subcircuit"  icon="ic2.png" ></item>
    <item name="74HC151" package="logic/74XX151.package" subcircuit="logic/74XX151.subcircuit" icon="ic2.png" ></item>
    <item name="74HC164" package="logic/74XX164.package" subcircuit="logic/74XX164.subcircuit" icon="ic2.png" ></item>
    <item name="74HC573" package="logic/74XX573.package" subcircuit="logic/74XX573.subcircuit" icon="ic2.png" ></item>
    <item name="74HC574" package="logic/74XX574.package" subcircuit="logic/74XX574.subcircuit" icon="ic2.png" ></item>
    <item name="74HC595" package="logic/74XX595.package" subcircuit="logic/74XX595.subcircuit" icon="ic2.png" ></item>

    </itemset>

    <itemset category="Custom" type="Subcircuit">

    <item name="Volt. Div."  package="logic/voltdiv.package"  subcircuit="logic/voltdiv.subcircuit"  icon="ic2.png" ></item>

    </itemset>

</itemlib>
type must be "Subcircuit" if it is not a 74 series chip.
category can be whatever yo want.
Now if we open SimulIDE we will se our new component in a new category "Custom", and if we drag and drop it to the circuit it will be look like this:

Now we can understand how package file works.
Note the positions and labels of the pins we created, now let's review package file:
First line is about component:
<package name="voltdiv" pins="3" width="4" height="5">
name: whatever you want.
pins: Number of pins.
width & height: Size of the component in simulide's grid squares.
Now each pin description:
<pin side="bottom" pos="1"  type="" id="3"  label="3" />
side: In wich side of the component is the pin. Options are: top, right, bottom, left.
pos: Position of pin in this side, position are counted from top to bottom or left to right.
id: Internal Id of the pin.
label: Label shown in the circuit.
To understand it better, lets change some things in the package file:
<!DOCTYPE SimulIDE>

<package name="voltdiv" pins="3" width="6" height="10">

    <pin side="left"  pos="8"  type="" id="1"  label=" Jonh" /><!-- packagePin1 -->
    <pin side="right" pos="1"  type="" id="2"  label="2"     /><!-- packagePin2 -->
    <pin side="right" pos="2"  type="" id="3"  label="Hello "/><!-- packagePin3 -->

</package>
Restart simulide to take the changes...
Size is now 6x10, different sides and positions, same ids but different labels (note spaces before " Jonh" and afther "Hello ").
It will look like this: