Create a custom library schematic
Download the simulation filesIn this example we will create a custom library block for a reverse protection schematic. The circuit components in the schematic are exported as a subsystem into a library block. This library block can than be used in any other schematic.
We will cover the basics of building and testing the library block, such as:
- Create a library block from a schematic
- Select the nodes to export as connecting nodes of the library block
- Export the library block into a *.lib file
- Access and test the library block
- Edit the library block
- Adjust the size of the library block
- Add a custom drawing over the library block
- Creating a custom folder in the Components/Library section where we can select the block
We start with schematic that we can test before we place it inside a library block. Our goal is to make a reverse protection circuit using a pMosfet. The circuit is shown twice below, on the left side with a correct connection and on the right side the source is reverse connected, so the protection circuit, basically the pMosfet should block.
The first goal is to create the block from a section of this schematic. We could select a part of the schematic to be exported, but it is much easier to remove everything that should not be exported and then perform the export. Be sure you saved this schematic as we are going to delete many components.
Since we only want the pMosfet and the two resisters in the library block, we remove everything except for those components. Please also note that we have assigned the label GND to the bottom node
Only nodes that have a label can be exported. Therefore we label all nodes that are required by clicking them with the right mouse button. At the same time we can define that it has to be exported. Since the connections on the library block can go in four directions, we have to specify on which side of the library block the node should be exported. This is indicated in the dialog box for setting the label of the node as being left, right, top or bottom.
NOTE!
Please note that you can only define an export direction if the node has a label. If you open the dialog box on a node that had no label before, you can not assign it an export direction. In that case, give the node a label, close the dialog box and reopen it with the right mouse button. When you open the dialog box for the second time and the label was previously assigned, you can define an export direction for that node.
First we define that the node labelled S has to be exported to the left.
We do the same for the node D, but define it to be exported to the right.
The bottom node will get the label GND and is exported to the bottom.
NOTE!
While editing the schematic, the program is asking you to include a GROUND node. If you do not need such a ground node, it makes no sense to include one, however, Caspoc will include one automatically during editing. Take care to remove this label before we do the export.
The next step is to export the schematic into a single library block. Check if all nodes that have to be exported are having a label and then select from the menu Edit/Export Library which will show you the dialog box for exporting the schematic, or click the button as indicated below.
Here you can add additional info regarding the block and/or even assign more nodes to be exported. The contents of the text fields are displayed when the users clicks on the help button for this library block. Finally after adding some info in the text fields you can export the block by clicking the [Export] button
A SaveAs dialog box will pop up and you can save the block, preferably to the folder where you have your examples.
To test the block and use it, we have three methods to import:
- Selecting it by clicking Edit/Import Library in the menu
- selecting the import button
- Selecting it in the Windows File Browser, dragging and dropping it onto the workscreen
For the first two, a file browser will open where you can select the file.
You can browse the file and select it. After selecting the file, or after dragging and dropping the block onto the workscreen, you will be prompted for the name of the block. You can leave the default name by clicking [OK]
In case you did not have any ground node in the schematic, you will be prompted with a message saying that a ground node will be assigned automatically. You can always remove or replace the ground node label
Finally the imported library sticks to your mouse pointer and you can drag it over the workscreen. The block can be position by clicking and release it with the left mouse button.
Insert a ground block to have a more cleaner schematic and remove the label ground if its assigned automatically, by clicking that node with the right nouse button and deleting the text 'GROUND'
After dropping the block onto the workscreen you will see the block with its labels. You can test the block in a new schematic and even import it twice to compare for various parameters.
First we will test the block and see if it works. We add a voltage source and resistor from the components/circuit/RLC and components/circuit/Sources section. If a ground node was not added previously, we add a ground node by clicking the ground symbol button on the bottom button bar.
Drag all components on the workscreen as shown below.
To change the parameters, click the component with the right mouse button and change the parameters.
Connect the components through wires by clicking the left mouse button over the starting node, drag the mouse over the end node and release the left mouse button.
Tee test circuit will feed the output resistor of 10Ω from a 48volt DC voltage source.
If all are connected in a good way, we can start the simulation and prove the result by checking the current through the load resistor. First we connect a positive voltage and start the simulation by clicking Simulation/Start Simulation from the menu. Hover the mouse cursor over the resistor and you can read the voltage over and current through the resistor.
The voltage over the resistor is close to the input voltage and a current of 4.7 Ampere is flowing through the load resistor. Next we change the value of the voltage source from 48 to -48 volt. Start the simulation and again hover the mouse cursor over the resistor. Now the voltage over the resistor is close to zero and there is nearly no current flowing through the resistor. The reverse voltage protection seems to work.
The next step to improve this mode is by adding a current sensor inside the library block and to export that measured value. To do this we open the library block by clicking it with the right mouse button and selecting the [Edit] button in the opened dialog box.
A new workscreen opens with the contents of the library block. From components/circuit/RLC we select(1) a resistor and connect it to the GND labelled node. Change the value of the sensing resistor to a low value of 1mΩ(2)
Next assign a label to the new node(3), for example [out] and finally define that it is exported on the right side of the block(4).
To measure the current through that sense resistor, we include a block that measures the current through the resistor. Select the block Current from Components/Blocks/Source and place it on the workscreen(1). Right click the block Current and enter the name of the resistor in the Text field(2). Next right click the output node of the block and give it the label I(3). Finally assign the node to be exported to the right side(4).
If all components are added, the block can be closed and we return tot the main schematic.
After saving the library block, we noticed that the nodes are somehow strangely placed. Using this library block would always require extra wires for connecting the block. It would be nicer if we could change the size and position of the nodes on the library block.
This can be done if we insert dummy exported nodes in the library block. What we would like to change is to have two nodes on the left side for connecting the voltage source and on the right side two nodes where the load resistor is going to be connected. Open the library block by right clicking it and select the button [Edit].
The library block is opened in the workscreen and first we are going to change the direction of the export of some nodes. The node with the label GND should be exported tot he right as indicated above. If we do this we will have two nodes on the left side of the block, two nodes on the right side of the block and the output I being exported to the top of the library block.
However, since the order in which the nodes are exported is alphabetically, to node S and GND would be upside down. To make sure that the node previously labelled GND is exported below the other node, we assign it the label Z.
We also want some space between the nodes so that the distance between the connections is equal to the size of a circuit component. To do this, we insert dummy nodes that are exported between the nodes S and Z, but are not visible. We can make these dummy nodes by assigning a node a dummy label that starts with an underscore _NotExportedLabel in its label. The exported node is sorted according to the first characters following the undescrore.
To make a dummy node we have to insert a short piece of wire and assign it a label, starting with an underscore and an export direction. The easiest to make a short piece of dummy wire is to start from an existing node, drag a short piece of wire(1), start again a short piece of wire from the newly formed node(2) and remove the previous wire connected to the output of the starting node(3). This gives a piece of wire that can have its own label. Right click the newly node and first assign it a label starting with an underscore. Since it has to be sorted between the nodes S and Z, we will label the node _S1(4). After assigning the label we right click the node again and specify the export direction to be [left](5).
A second dummy node can be created in the same way, as we will need two dummy nodes on the left side. However Copy and Paste is easier. Drag a rubber band with the left mouse button down around the last dummy node with wire and press the key combination Ctrl-C on your keyboard. Pressing Ctrl-V on your keyboard inserts a new dummy wire with a new dummy label. Place this dummy wire with dummy label by clicking the left mouse button.
On the right side we also want to have two dummy nodes and that is done by Copy [Ctrl]-[C] and Paste [Ctrl]-[V] of the two existing dummy nodes.
Click the [Save] button to close the window and return to the workscreen. Now the block has two nodes on each side and is ready to be connected into a schematic.
The block has the same distance between the nodes as the height of a circuit component. Therefore it can be easily connected.
However, the block still looks ugly and we want to place an icon on top of the block. Right click the block and select the button [Edit VEC] to open the vector icon editor.
Click [Yes] to create the new file
A notepad or other text-file editor will open where you can enter the commands for drawing vectorized diagrams. A full list of vector drawing commands is given in this section "Userguide/BasicUserInterfaceTopics/Library/Creating a customized drawing on the library block" in the on-line help.
We start with drawing some basic rectangle around the block and just to get starting it is handsome to know that the distance in pixels between nodes on a library block equals 20,also for non-visible nodes. This means that the size of out block is 40 * 100 pixels.
The command for drawing a rectangle of this size is "Rectangle 0 0 40 100"
Click Ctrl-S on your keyboard to save the changes and return to your workscreen (ALT-TAB)
The make the vector graphics visible, we have to enable the VEC drawing, and disable all others. Click [OK] to close the dialog box and return to the workscreen
The rectangle is drawn as a gray outlined box, exactly fitting the size of the block.
Next we will add some more graphics on the block. Each time you add something and want to see the result, simply click [Ctrl]-[S] in notepad, [Alt]-[TAB] to go to Caspoc and [F5] to resize the screen. Return to notepad using [Alt]-[TAB].
Add some color and a nicer rectangle by using the roundrect and solidpen and solidbrush commands
Play around with the drawing commands and enjoy your imagination!
To view the contents of your library block (even during simulation!!!) select on the left side the name of the library block under Project/Schematic