Simulation of RC Circuit
Simulation of RC Circuit
RC Circuits
Article 2
ARTICLE 1
Simulation of
Simple RC Circuit
CONTENTS
1.1 Introduction to Simple RC Circuit
1.2 Mathematical Modeling of RC circuit
1.3 Simulation with MATLAB
1.4 Simulation with SIMULINK
Appendix
Section 1.1
Introduction to simulation
For example when you turn on a flashlight current stare to flow almost immediately
through the bulb, batteries, and connecting metal parts. The current continues to flow
steadily until you turn of the switch. When you insert the capacitor in to the simple R
circuit, this picture changes. A capacitor introduces time dependence. The circuit that
contains a dc voltage source V, resister R and a capacitor C is called a simple RC circuit.
In simple RC circuit quantities change more gradually because of the capacitor. The Vc
builds up as charge accumulates on the plates of the capacitor. And the polarity of the
voltage Vc is such that it opposes the applied voltage V. In the simple RC circuit, we
change the capacitor charge by moving charge on or off the capacitor plate. Because the
charge and voltage are proportional in a capacitor it is not possible to change the voltage
across the capacitor with out changing the charge. Therefore, we conclude that the
voltage across the capacitor cannot change instantaneously, and this makes a simple RC
circuit a time dependent circuit.. As more time pass, the voltage Vc increase, so the
current through the capacitor ic decrease until such time as C if fully charged (Vc=V).
The main objectives of this article are:
To
learn (by simulation) how the voltage and the current changes with
verify (by simulation) the equations the describe voltage and current
s
Ein
Eout
Article1
Let i represent the current that pass through the resistor and the capacitor. For the
resistor, the current (i) is equal to the voltage difference (Ein - Eout) divided by the
resistance (R).
i
E in E out
R
(2.0)
For the capacitor, the current i is equal to the capacitor C times the instantaneous rate of
change of the capacitor voltage.
iC
dE out
dt
(2.1)
By equating the right-hand side of equation (2.0) and (2.1) we obtain that
RC
dE out
E out Ein
dt
(2.2)
We can easily see that equation (2.2) is a first order ordinary differential equation of type:
dx
x
dt
(2.3)
(2.4)
Ein
(2.5)
The proof is given in appendix A, and for more detail explanation the reader my consult any differential
equation book ,
Eout e
E out
Ein
e
E out
dt Ke
E out
(2.6)
Section 1.2
System Analysis
E out Ein (1 e )
(2.7)
From equation (2.1) and (2.7) it follow that current through the capacitor C is given by
t
Ein
e
R
(2.8)
Now we exam the significant of the time constant of the circuit. To do so we make the
table shown below with different values of .
t
iout in e
R
Ein 1
E
1
e 36.6 in
R
R
Ein 2
Ein
2
e 13.5
R
R
Ein 3
E
3
e 5 in
R
R
Ein 5
5
e 0
R
E out Ein (1 e )
Eout Ein (1 e 1 ) 63.2 Ein
Eout Ein (1 e 2 ) 86.5Ein
Table 1.1,
out ( the capacitor voltage ) with different values of
the time constant . From the table we observe the significant of the time constant . In
fact, one time constant after the application of the source voltage Eout ( the capacitor
voltage has risen to 63.2% of its steady- state value, and the current i has decay to 36.8%
of its initial value. In similar way, we can observe that at t = 2, Eout = 86.5% of it steadystate value and i=13.5% of its initial value. At t = 5 the capacitor is essentially fully
charged (Eou = Ein) and i 0, so we say that steady-state conditions have been reached
after an elapse of time equal to 5 time constants.
If we replace the voltage source Ein with a short-circuit, after the capacitor has been
allowed to charge fully, i.e., after the steady state condition have been reached when this
Article1
happen, the charge on the capacitor flows from one plate through the resistance R to other
plate , and thus discharge. Note that the discharge current is opposite direction from
which that it followed when the capacitor was charging. When the capacitor discharges
the voltage Eout decay toward zero volts and the current decays toward zero amperes.
The equation that describe decay of voltage and current are respectively:
t
E out Ein e
(2.9)
Ein
e
R
(2.10)
1.3 System Simulation: In preceding paragraph we discussed the significant of the time
constant . Now by using the following MATLAB code we simulate the step response of
thevalue
step
response
the%Script
system with (1.1)
three different
of time
constant of E out with
Section 1.3
System Simulation
Figure 1.2 The rise of the capacitor voltages when =0.5, 5.5,10.5,15.5
The following MATLAB code (script 1.2) computes the step response of the output
current (the capacitor current) with different values of time constant .
Articler1
%Script
(1.3)
Charge
and
discharge
step
%responses of the circuit. This program plots
%the step responses of the circuit when the
%capacitor charges and discharges.
ein=1; % input value (step)
t=0:0.1:10;% vector of time points
R=10000; % the value of the restore
% for each value of the time constant tau, plot
the step response
for tau= 0.5:5:20;
eout_charge=ein*(1-exp(-t/tau));% the
voltage across the capacitor.
subplot(2,2,1)
plot(t,ein);
ylabel('Amplitude [Volt]')
Figure 1.3 The decay of the capacitor current when =0.5,5.5,10.5,15.5
title('step input')
subplot(2,2,2)
plot(t,eout_charge)
Section 1.3
System Simulation
ylabel('Amplitude[Volt]')
title('The step responses')
if ishold~=1,hold on,end
eout_dis=ein*exp(-t/tau);
subplot(2,2,3)
plot(t,ein),
xlabel('time
[sec]'),ylabel('Amplitude[Volt]')
title('step input')
subplot(2,2,4)
plot(t,eout_dis),
xlabel('time
[sec]'),ylabel('Amplitude[Volt]')
title('The step responses')
if ishold~=1, hold on
end,
grid
end
9
hold off % turn hold of after the last curve
10
Article 1
11
Section 1.3
System Simulation
12
Article1
Figure 1.5 The decay of the capacitor current during charge and discharge
We pick the upper left corner to plot the decay of the capacitor current during charge, and
we pick the lower left corner to plot the decay of the capacitor current during discharge.
We use the red, brown, blue and green colors to indicate the outputs when = 0.5, 5.5,
10.5, and 15.5 respectively. By comparing the above graphs we can easily observe that
the circuit has fast decay response when the time constant is small, and slow decay
response when the time constant is big.
13
Section 1.3
System Simulation
Now we apply the MATLAB Control Tool Box to analyze the circuit. To do so we need
to build the simulator block by using SIMULINK.To simulate a dynamic system with
SIMULINK we need to calculate the transfer function of the system in exam. The
frequency-domain algebraic equation is obtained by applying the Laplace transformation
to each term in equation (2.2).
deout
eout ein )
dt
(2.11)
(2.12)
E out 1 s
(2.13)
Articler2
Circuit
Simulation of Simple RC
For: tau=15
1
0.9
0.8
0.7
A
M
P
L
I
T
U
D
E
0.6
0.5
0.4
0.3
0.2
0.1
0
30
60
900
30
60
900
30
60
90
Time
(sec.)
Now we use the simulation block diagrams to observe the step response in scope. The
three step responses obtained by using three different time constant are shown below.
Figures 1.1d. 1.2d, and 1.3d show the step response of the system when the time constant
is equal to 5, 10 and 15 respectively.
1
The block diagram for the step response for different value of time constant
0.2s+1
Output Point 1
Transf er Fcn1
1
Step Input Point
0.1s+1
Output Point 2
Transf er Fcn2
Scope1
1
0.0667s+1
Transf er Fcn3
Output Point 3
15
Section 1.3
1
To:
Output
Point3
A
m
p
L
i
t
u
d
e
System Simulation
0.5
0
1
To:
Output
0.5
Point2
0
1
To:
Output
Point1 0.5
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Time (sec.)
We can also obtain the three step responses of the system by connecting the block
diagram as shown below.
In the block diagram shown above we used the transfer function method to simulate our
system. We can obtain the same result by using equation (1.2d). For commodity we
rewrite it below
sE out E out Ein
16
Article 1
The block diagram for the step response for different value of time constant tau
1
0.2
s
Integrator
Gain
Gain1
Output Point1
0.2
1
0.1
Step Input Point
s
Integrator1
Gain3
Output Point2
Scope
Gain2
0.1
1
0.667
s
Integrator2
Gain4
Output Point3
Gain5
0.667
To:
Output
Point3
To:
Output
Point1
0.5
A
m 0
p 1
L
i 0.5
t
u 0
d 1
e
0.5
We already
visualize the effect of change in the
0
0
10
15
20
25
30
35
Time (sec.)
17
Section 1.3
Section 1.3
System Simulation
System Simulation
We already visualize the effect of change in the time constant of the transfer function on
the system. Now We create the script file called meshpolt.m to demonstrate the effect of
change in the time constant value on the step response of the system in 3-dimennsion.
18
With more sampling points the mesh plots look like shown below
time
inputs
19