.. _pyopus.lib : ../../../demo/kicad/01-schem/pyopus.lib .. _pyopus.dcm : ../../../demo/kicad/01-schem/pyopus.dcm .. _kicad-pyopus-library: Using the pyopus.lib library in eeschema ======================================== For drawing schematics that will be used for generating netlists you can use arbitrary KiCad schematic components. But the most straightforward way is to use the pyopus.lib_ library of schematic components. Predefined rules exist for netlisting these components. For other KiCad schematic components you will have to write your own netlisting rules. In some cases even the default netlisting rule will be good enough. One KiCad schematic can be subdivied in several .sch files, but in the end this hierarchy will be flattened to produce one netlist file which is either a top-level netlist or defines one subcircuit. First you should copy the pyopus.lib_ and pyopus.dcm_ files to the folder where your schematic files will be stored. To introduce the PyOPUS netlister for KiCad we are going to draw two schematics. The first one (``miller.sch``) defines a Miller operational transconductance amplifier (OTA) as a subcircuit. The second one (``topdc.sch``) uses this subcircuit and simulates its DC and AC behavior. In the folder where the schematic files will be stored start eeschema to create ``miller.sch`` by typing .. code-block:: none eeschema miller.sch Now you must add pyopus.lib_ to the list of libraries, In the main menu choose Preferences/Component Libraries. In the window that pops up click on the Add button. Browse to the folder with your schematic project and select pyopus.lib_. Confirm selection and ckick OK. Under Windows first start eeschema and select File/Save Current Sheet As in the menu. Save the empty sheet in the folder where you put the pyopus.lib_ and pyopus.dcm_ files. After that you can proceed with adding pyopus.lib_ to the list fo libraries. The Miller OTA schematic is constructed using the following components from pyopus.lib_ * NMOS and PMOS for the MOS transistors * RES and CAP for the resistor and capacitor * ISRC for the independent current source * OUTPUT_FILE for defining the output netlist file name * SUBCKT for defining the subciruit name and pin order .. figure:: kicad-miller.png :scale: 60% Miller OpAmp schematic. Note that at netlisting KiCad will insist that all your component names end with a number. So don't waste your time trying to force Ma as the MOS transistor name. Name it Ma1 instead. MOS transistors have 3 numbers associated with every symbol. The bold one is the channel width (W). Right above/below it (depending on symbol's rotation) is the channel length (L). Somewhat further away is the multiplier factor (M). The model name is specified as the Model filed. By default the netlister will recognize components GND, GNDA, GNDD, GNDPWR, and GNDREF as ground nodes. You can change this in the netlister configuration. See the documentation of :mod:`pyopus.netlister` on how to do this. The customized configuration must be stored in a ``netlister.json`` file in the folder where the intermediate XML netlists will be generated by KiCad. The pins of the subcircuit must be named with global labels. If you place a SUBCKT component from pyopus.lib_ the whole schematic will be treated as a subcircuit definition. The name of the subcircuit and the net names of its pins are defined as Fields of the SUBCKT component. To define subcircuit parameters use the SUBCKT_PARAM components (one for every parameter). Arbitrary parameters can be defined using the PARAM component (one per parameter). Every PARAM component translated to one ``.param`` statement inside the subcircuit definition (or in the top-level netlist of the schematic defines a top-level netlist). To generate the netlist you must first add the netlister plugin to KiCad. The instructions for this are availabel in the documentation of :mod:`pyopus.netlister.kicad`. This needs to be done only once. KiCad will remember your plugin's settings even after you close eeschema. Select Tools/Generate Netlist File in the eeschema menu. A window will pup up. Select the Spice Opus tab and click on the Generate button. A file dialog will pup up asking you for the netlist file name, After entering it and clicking the Save button the intermediate XML netlist will be generated and the PyOPUS KiCad netlister plugin will be invoked. This plugin reads the XML file and the netlister configuration files (.json files) that customize its behavior. After that it outputs the nelist. If you place an OUTPUT_FILE component in your schematic this component will define the name of the netlist file regardless of what you specify in the file dialog (the file name will only be used for the intermediate netlist). After the netlist file is generated a window will pop up showing the contents of the netlist file ``miller.inc``. .. literalinclude:: ../demo/kicad/01-schem/miller.inc :language: none You can close it by pressing ``Enter`` or ``Esc`` or clicking on the Close button. To define the top-level netlist start another instance of eeschema by typing .. code-block:: none eeschema topdc.sch Note eeschema will complaint that it is already running. Simply ignore the message and click Yes top continue. Add pyopus.lib_ to the list of libraries. The top level schematic uses the following pyopus.lib_ components * VSRC for the independent voltage sources * VCVS for the voltage-controlled voltage source * RES and CAP for resistors and capacitors * OPAMP for the opamp * OUTPUT_FILE for specifying the output netlist file name * INCLUDE for including an external file (``miller.inc``) * LIB for including section ``tm`` of the library file (``cmos180n.lib``) .. figure:: kicad-topdc.png :scale: 60% Testbench circuit schematic. All nodes that will be accessed by the Spice Opus commands are named explicitly with global labels. The Value filed of the OPAMP is set to the name of the subcircuit that defines the Miller OTA (included from file ``miller.inc``). By default all components that do not have a netlisting rule defined are netlisted as subcircuits. The Value field specifies the subcircuit name. The nodes of the subcircuit instance are dumped in the increasing pin number order of the component. Any text block will be added to the netlist above/below netlisted components if it starts with the line .. code-block:: none Text position=top|bottom If there are multiple text blocks they are dumped in in the increasing number order. Note that the schematic file must be saved before netlisting so that the netlister can extract the text blocks from the schematic file. We use this text block feature to add a ``.control`` block to the netlist with the commands thet will run a DC and an AC analysis and plot the results. After netlisting the ``topdc.sch`` file the following netlist will be written to the ``topdc.cir`` file (due to the OUTPUT_FILE component). .. literalinclude:: ../demo/kicad/01-schem/topdc.cir :language: none You can run the simulation by typing .. code-block:: none spiceopus topdc.cir Demo files for this section can be found `here <../../../demo/kicad/01-schem>`_.