# Simulations Install ngspice to simulate circuits. ``` sudo apt install ngspice -y ``` Then run `magic` to extract spice description of the circuit. ``` magic -T sky130A.tech designs/counter/runs/RUN_2024.03.23_12.36.33/results/final/mag/counter ``` When you open magic's terminal, choose one of the below simulations by running appropriate commands. As the result you find a file named counter.spice in OpenLane directory. ## Post-synthesis Run following command in magic's terminal. ``` extract all ext2spice lvs ext2spice subcircuit on ext2spice quit ``` ## Post-layout Run following command in magic's terminal. ``` extract all ext2spice lvs ext2spice cthresh 0.01 ext2spice subcircuit on ext2spice quit ``` ## SPICE Open a new terminal and find counter.spice file in the OpenLane directory and add the following text to the file. ``` VDD VPWR 0 3.3V VSS VGND 0 0.0V .param mc_mm_switch=0 .param mc_pr_switch=1 .lib /home/debian/.volare/sky130A/libs.tech/ngspice/sky130.lib.spice tt Xcounter VGND VPWR clk p q[0] q[1] q[2] q[3] counter Vclk clk VGND PULSE(0V 3.3V 0ns 0.1ns 0.1ns 2ns 4ns) .tran 1ns 60ns .control set ngbehavior=hsa set ng_nomodcheck run plot "q[0]" "q[1]"-3.3 "q[2]"-6.6 "q[3]"-9.9 .endc .end ``` Then run ngspice to simulate the circuit. ``` ngspice counter.spice ``` ![Quartus](plot.png)