When you make a schematic in KiCAD, you place components and then interconnect them with wires by clicking on the green place wire icon and clicking on the pins of the components you want to connect, one after the other. Pretty simple. When you export a spice netlist, the default setting is that the wires are given numbers as their names. In fact you can specify this setting in the export netlist dialog. It is however easier in spice simulation, especially if you are using ngspice in a Linux terminal, if the wires had meaningful names.
The resulting netlist is as follows:
* Sheet Name: / R2 1 3 470 R1 1 2 1k v1 2 3 DC 12 .control op tran 0.5s 1s tf v(vout,0) v1 print all .endc .end
One way to make the wires or nodes in your circuit have meaningful names is to add net labels to the wires. These are fine, but when you export spice netlists from KiCAD with these net labels attached to your wires, the net names are usually preceded by a forward slash /. I found this annoying to remove throughout the spice netlist. The simulation wont work with this kind of netlist. You can use Global labels instead of net name labels. When you use Global labels, the net names in the netlist are OK. Use 0 for reference instead of GND or Ground. That way it will be interpreted as 0 volts in the simulation. You can insert graphic text and write your spice simulation code in there, starting with +PSPICE line, which tells KiCAD to append the lines that follow in the graphic text into the spice netlist as spice code.
The resulting spice netlist is as follows:
* Sheet Name: / R2 vout 0 470 R1 vout vin 1k v1 vin 0 DC 12 .control op tran 0.5s 1s tf v(vout,0) v1 print all .endc .end
If you don’t already have ngspice program installed, just install it in the terminal and run it, providing your netlist file.
sudo apt install ngspice cd src/kicad_boards/voltage_divider/ ngspice voltage_divider.cir
The output you will get will be something like this:
****** ** ngspice-26 : Circuit level simulation program ** The U. C. Berkeley CAD Group ** Copyright 1985-1994, Regents of the University of California. ** Please get your ngspice manual from http://ngspice.sourceforge.net/docs.html ** Please file your bug-reports at http://ngspice.sourceforge.net/bugrep.html ** Creation Date: Sun Feb 7 10:53:02 UTC 2016 ****** Circuit: * /home/karibe/src/kicad_boards/voltage_divider/voltage_divider.cir Doing analysis at TEMP = 27.000000 and TNOM = 27.000000 No. of Data Rows : 1 Doing analysis at TEMP = 27.000000 and TNOM = 27.000000 Initial Transient Solution -------------------------- Node Voltage ---- ------- vout 3.83673 vin 12 v1#branch -0.00816327 No. of Data Rows : 59 Doing analysis at TEMP = 27.000000 and TNOM = 27.000000 No. of Data Rows : 1 transfer_function = 3.197279e-01 output_impedance_at_v(vout,0) = 3.197279e+02 v1#input_impedance = 1.470000e+03
So ngspice calculates for you the output voltage, and determines the transfer function of the voltage divider giving the ratio as approximately 0.32, input impedance as 147 Ohms and output impedance as 319.73 Ohms. Pretty neat.