Basic RLC simulation in Xschem

Ming Sun

Ming Sun / November 01, 2022

12 min read––– views

Step 1 - Create a new schematic

First go to your schematic folder and type the following command to create a schematic named rlc.sch.

xschem rls.sch
Start Xschem and create a new schematic named rlc.sch
Fig. 1Start Xschem and create a new schematic named rlc.sch[1]

There will be an Alert pop up, which we can ignore.

Xschem startup screen
Fig. 2Xschem startup screen[1]

Step 2 - insert component symbol

Right click on Xschem schematic, and choose insert symbol.

Insert symbol
Fig. 3Insert symbol[1]

In the pop up window, choose xschem_library => devices. In the File/Search window, type cap.

Find out capacitor symbol
Fig. 4Find out capacitor symbol[1]

Choose capa.sym and click ok button.

Insert capacitor symbol into schematic
Fig. 5Insert capacitor symbol into schematic[1]

Follow the same procedure and insert the inductor, resistor and voltage source symbol.

inductor => ind.sym

resistor => res.sym

voltage source => vsource_arith.sym

Insert inductor, resistor and voltage source symbol into schematic
Fig. 6Insert inductor, resistor and voltage source symbol into schematic[1]

Now, we can use option+R and m key to move the component. Use w key to connect the component. Fig. 6 will become to:

Wiring and re-arranging the schematic
Fig. 7Wiring and re-arranging the schematic[1]

Step 3 - change component value

Next, select resistor and right click, then select Edit attributes option.

Changing capacitor value
Fig. 8Changing capacitor value[1]

In the pop up window, change the capacitor value to 50nF.

Set capacitor value to 50nF
Fig. 9Set capacitor value to 50nF[1]

Follow the same procedure and set inductor and voltage source value as shown in Fig. 10.

Modifed schematic with inductor and voltage source attribute updated
Fig. 10Modifed schematic with inductor and voltage source attribute updated[1]

Notice, for the voltage source, set its attribute to be "'3*cos(time*time*time*1e11)'" (include quotes, single and double).

Step 4 - add label

First, insert lab_pin into the schematic.

Insert label (lab_pin) into the schematic
Fig. 11Insert label (lab_pin) into the schematic[1]

Change the attribute for each label and attach it to Vin and Vout net as shown in Fig. 12.

Add Vin and Vout label for the net into the schematic
Fig. 12Add Vin and Vout label for the net into the schematic[1]

Add simulation command

Insert code.sym symbol into the schematic with the content as shown in Fig. 13.

Add simulation stimulus
Fig. 13Add simulation stimulus[1]

Add title block

Insert title.sym and modify its attribute. Up to this point, the schematic is completed.

Completed schematic
Fig. 14Completed schematic[1]

Run simulation

Click Netlist and then click Simulate. Then the Ngspice window will pop up.

Ngspice terminal window
Fig. 15Ngspice terminal window[1]

In Fig. 15, I change Xschem theme to white so that it is easier to see the Ngspice pop up window. In the Ngspice pop up window, type plot Vin Vout. The waveform is shown in Fig. 16.

Simulation result of RLC circuit
Fig. 16Simulation result of RLC circuit[1]

Verify the result from Matlab[2]

We can verify the Ngspice simulation result from Fig. 16 through Matlab by using the following script.

clc;clear;close all;
% component parameter
R = 1e3;
L = 10e-3;
C = 50e-9;
% time 
t = linspace(0,2e-3,10000);
% Input
Vin = 3*cos(t.*t.*t*1e11);
% Transfer function
s = tf('s');
G = R/(R + s*L + 1/(s*C));
% Calculate Vout
Vout = lsim(G, Vin, t);
% Plot
plot(t*1e3, Vin, 'b', 'LineWidth',1.5);
hold on;
plot(t*1e3, Vout, 'r', 'LineWidth',1.5);
ylim([-4, 4]);
xlabel("time [ms]");
grid on;
legend(["Vin", "Vout"]);

Matlab simulation results are shown in Fig. 17.

Simulation result from Matlab
Fig. 17Simulation result from Matlab



[2] MathWorks blog post

[3] Matlab script - download

[4] rlc.sch download

Google ScholarLinkedIn