Signal generation by an RC circuit
We consider the RC circuit with time constant tau= RC driven by a time-dependent external source signal of triangular shape with period T . We wish to calculate the voltage across the capacitor.
We begin with the problem for a single cycle of the source voltage, and then generalize to obtain the voltage for a finite number of cycles. We find the capacitor voltage for the regime of T < tau, and study the transition from the transient to the steady-state capacitor voltage.
We proceed as in the worksheet RLCcirc.mws to generate the time evolution of the current (or voltage across the resistor) using Kirchhoff's law and the relationships between voltage and current for the two elements. We need to modify the rhs of Kirchhoff's loop rule to allow for a time-dependent electric potential.
> restart;
We begin by defining the voltage drops across the resistor and the capacitor.
> V_R:=R*i(t);
> V_C:=(1/C)*Int(i(s),s=0..t);
According to Kirchhoff's rule we equate the sum of the drops across R and C to the applied time-dependent signal voltage U ( t ):
> KL_RC:=V_R+V_C=U(t);
We differentiate the relationship to obtain a differential equation for the current i ( t ):
> KL_RC:=diff(KL_RC,t);
Note that in the case of a constant source voltage U the value of the applied voltage disappeared from the equation due to the differentiation. However, it entered the solution through the initial condition. In the case of a time-dependent U ( t ) the derivative U '( t ) appears in the differentiated Kirchhoff rule.
We need to define the external voltage as a function of time. We consider a triangle-shaped function. First we have a linear rise from zero to a maximum value for
t < T /2 . We choose a slope of 1, i.e., the rise is 1 V/s:
> U1:=t->t;
> KL_RC1:=simplify(subs(U(t)=U1(t),KL_RC));
Without simplification the rhs would not have been evaluated. This would have caused dsolve to fail in the lines below. The initial current vanishes, as there is no voltage applied at t =0, and we assume that the capacitor is uncharged. Therefore, the initial condition reads:
> IC1:=i(0)=U1(0)/R;
> sol_c:=dsolve({KL_RC1,IC1},i(t));
> i_RCc:=rhs(sol_c);
We need to know the voltage across the capacitor in order to be able to start the solution for the 'discharge' phase. By 'discharge' we mean the second half of the pulse during which the source voltage decreases. We obtain the capacitor voltage as the complement of U _R to the battery voltage U ( t ). We also introduce tau= RC , the time constant of the circuit.
The voltage drop across the resistor during the 'charge' phase is given as:
> U_Rc:=subs(i(t)=i_RCc,V_R);
> U_Rc:=simplify(subs(R=tau/C,U_Rc));
The voltage across the capacitor is obtained as the complement between the voltage applied to the circuit and the drop across the resistor:
> U_Cc:=U1(t)-U_Rc;
This function describes how the voltage builds up across the capacitor from a value of zero at t =0 up to asymptotic times. We explore its time behaviour for a linearly increasing source voltage U ( t ).
> plot([U1(t),subs(tau=1,U_Cc)],t=0..10,color=[blue,red]);
We see that the capacitor voltage is non-linear for small times, but approaches a linear regime with a time delay as compared to the source voltage. We can explore the short-time behaviour:
> taylor(U_Cc,t=0,3);
The quadratic dependence on time, as well as the dependence of the coefficient on the time constant of the RC circuit should be noted.
Now we introduce T, i.e., the period of the triangle-wave signal that drives the RC circuit. At t = T /2 the wave stops growing, and the discharge regime begins.
The so-called duty cycle for the driving signal was chosen to be 50%. An interesting extension of this worksheet would consist of introducing the ratio of charge to discharge regimes during the period T as a variable (e.g., charge regime: 0 < t < T /3, and discharge regime: T /3 < t < T corresponding to a 1/3 duty cycle).
We denote the voltage to which the capacitor was charged at the time t = T /2 as U0:
> U_Th:=simplify(subs(t=T/2,U_Cc));
We formulate the solution for the discharge regime. We note that with the choice for U 1 ( t )= t , and a given choice of the period (e.g. T =1) we imply a scale for the voltage axis, since the source voltage at t = T /2 will rise to some maximum value ( U _max=1/2 for T =1). The source voltage for T /2 < t < T is given as:
> U2:=t->T-t;
Kirchhoff's law is now formulated as follows:
> KL_RC2:=simplify(subs(U(t)=U2(t),KL_RC));
The initial condition on the current is given by the amount that flows at the end of the charge cycle:
> IC2:=i(T/2)=simplify(subs(t=T/2,i_RCc));
> sol_d:=dsolve({KL_RC2,IC2},i(t));
We combine the exponentials in the solution:
> i_RCd:=combine(subs(C=tau/R,rhs(sol_d)),exp);
The voltage drop across the resistor is calculated in order to obtain the voltage across the capacitor:
> U_Rd:=simplify(subs(i(t)=i_RCd,V_R));
> U_Cd:=simplify(U2(t)-U_Rd);
The voltage at t=T will be needed to continue the solution in the next cycle.
> U_T:=subs(t=T,U_Cd);
Now we have the voltage across the capacitor for the charge regime valid up until t = T /2, as well as for the discharge regime voltage valid between T /2 and T . We need to piece them together, and to display them for one period T as a function of time with a choice of the parameter tau. The voltage scale for the y axis is set by U 1 ( t ) and U 2 ( t ) once we choose T =1 to set a scale for the time axis.
We reassign the previously defined voltages across the capacitor at the end of the charge and discharge cycles to refer specifically to the case of T =1:
> U_Cc:=simplify(subs(T=1,U_Cc));
> U_Cd:=simplify(subs(T=1,U_Cd));
It is of interest to observe the results of the charge&discharge cycles for the case where the time constant of the RC circuit tau is shorter than the period T of the driving signal. With the scale set by T we can choose tau << T as tau <<1:
> P1c:=plot(subs(tau=1/10,U_Cc),t=0..1/2,color=red):
> P1d:=plot(subs(tau=1/10,U_Cd),t=1/2..1,color=blue):
> with(plots):
> display(P1c,P1d);
We see that the capacitor voltage nearly follows the source voltage with some rounding off occuring. The voltage to which the capacitor charges at the end of the rise in the source voltage is:
> evalf(subs(T=1,tau=1/10,U_Th));
The value at the end of the cycle can be read off as:
> evalf(subs(T=1,tau=1/10,U_T));
For comparable time constants of the RC circuit and the square wave signal, tau= T we obtain:
> P2c:=plot(subs(tau=1,U_Cc),t=0..1/2,color=red):
> P2d:=plot(subs(tau=1,U_Cd),t=1/2..1,color=blue):
> display(P2c,P2d);
The voltage to which the capacitor charges at T /2 is given as:
> evalf(subs(T=1,tau=1,U_Th));
while at the end of the period we have:
> evalf(subs(T=1,tau=1,U_T));
We observe that as tau, i.e. , the time constant of the RC circuit approaches the time constant of the source voltage, T , the capacitor voltage does not follow the source voltage. In fact, the capacitor charged during the 'discharge' phase to a higher voltage! Further below we will demonstrate that this is so only during the transient regime when the capacitor is charged to a low voltage as compared to the maximum value (set by a scale of U _max=1/2 in the source voltage U ( t )).
Finally we go to the other extreme given by tau >> T :
> P3c:=plot(subs(tau=10,U_Cc),t=0..1/2,color=red):
> P3d:=plot(subs(tau=10,U_Cd),t=1/2..1,color=blue):
> display(P3c,P3d);
The answer is clearly not periodic after a single cycle, we would need to piece together several charge/discharge segments to see whether a steady-state solution will be achieved.
The signal is strongly attenuated. The RC circuit acts as a low-pass filter: the voltage across the capacitor reflects the triangular-wave input to the circuit for low frequencies (time constant T large compared to tau) with a rounding effect on the edges of the pulse. It suppresses throughput at high frequencies while distorting the shape considerably. The details of this behaviour are shown in the solution for many periods T .
The voltage to which the capacitor charges at T /2 and T respectively is:
> evalf(subs(T=1,tau=10,U_Th));
> evalf(subs(T=1,tau=10,U_T));
The long-time behaviour of the capacitor voltage
The solution to a first-order equation depends on a single integration constant. It is the actual value of the current at the end of the previous time segment that determines the further time evolution. The solution to the problem is continuous and differentiable in this case as there are no discontinuities in the source voltage (the derivative of the source voltage is discontinuous). Given that the source voltage does not change abruptly at t = T /2 we should assume as the correct initial condition for the discharge cycle that the final value of the current in the charge cycle represents the correct initial value for the discharge cycle.
Now we are interested in piecing together a solution over several periods, e.g. nmax=20 of them.
We follow a simple strategy and let Maple do the work. We integrate the equation for the current i ( t ) as derived from the Kirchhoff rules for the charge and discharge regimes respectively, and calculate the voltages as before. We pick the case where the period of the driving signal T equals the time constant tau of the RC circuit.
> i0:=0: T:=1: tau:=1; nmax:=20;
> for j from 1 to nmax do:
> tj:=(j-1)*T;
> solc:=dsolve({KL_RC1,i(tj)=i0},i(t));
> U_Rc:=subs(i(t)=rhs(solc),V_R);
> U_Rc:=simplify(subs(R=tau/C,U_Rc));
> U_Cc:=U1(t-tj)-U_Rc;
> U_Ccj[j]:=U_Cc;
> P_c[j]:=plot(U_Ccj[j],t=tj..tj+T/2,color=red):
> i0:=evalf(subs(t=tj+T/2,R=tau/C,rhs(solc)));
> sold:=dsolve({KL_RC2,i(tj+T/2)=i0},i(t));
> U_Rd:=subs(i(t)=rhs(sold),V_R);
> U_Rd:=simplify(subs(R=tau/C,U_Rd));
> U_Cd:=U2(t-tj)-U_Rd;
> U_Cdj[j]:=U_Cd;
> P_d[j]:=plot(U_Cdj[j],t=tj+T/2..tj+T,color=blue):
> i0:=evalf(subs(t=tj+T,R=tau/C,rhs(sold)));
> print(`U_CTh: `,evalf(subs(t=tj+T/2,U_Ccj[j]),3),` U_CT: `,evalf(subs(t=tj+T,U_Cdj[j]),3));
> od:
We can display the sequences of graphs for the charge and discharge cycles:
> display(seq(P_c[j],j=1..nmax),seq(P_d[j],j=1..nmax));
We observe that after a few cycles of the square-wave signal a steady-state regime is reached if tau=1. For larger tau it takes more cycles to reach the steady state. The steady-state regime is reached as the oscillations become symmetric with respect to the midpoint voltage U =1/4.
Various properties of this solution can be exploited in practice: we mentioned the low-pass filtering property already; another property is the fact that under the right circumstances, i.e., for T << tau, we can consider the circuit to be an approximate integrator. We learned that it turns a square-wave signal into an approximately triangular shape (in RLCcircuit.mws ). This was found to be correct in the sense that an exponential function is approximated for small arguments by a straight line. Here we explored the response to a triangular-shape source signal and found that the response is a sequence of parabolic pieces that look alomost like a sine function in the steady-state regime.
Thus, one can use this circuit in function generators to generate interesting shapes. One can feed the near-sine wave signal coming from one RC circuit to drive a second one. To understand the response of the second RC circuit one then needs to solve a differential equation with a time-dependent driving force U ( t ). This worksheet can be used for many further explorations in this respect, as the user has control over the input voltages U1( t ) and U2( t ).
We explore the behaviour of the solution in the steady-state regime:
> U_Ccj[20];
> P1:=plot(U_Ccj[20],t=19..19.5,color=green): display(P1);
We calculate the precise location of the minimum to be able to compare the solution with a sine shape. The sine needs to be phase shifted for comparison, and we can use the location of the minimum for this purpose.
> t_min:=solve(diff(U_Ccj[20],t)=0,t);
We also need the amplitude precisely. We assume (observe from the graph) that we have symmetrical oscillations about U_avg=0.25, and obtain for the expected amplitude:
> A:=evalf(0.25-subs(t=t_min,U_Ccj[20]));
The capacitor voltage is nearly periodic in the steady-state regime. We can compare it to a sine function with the expected period (2 Pi/ T ), the expected average voltage of 0.25 and an amplitude A and phase shift (related to t_min) derived from the solution:
> P2:=plot(0.25-A*sin((2*Pi/T)*(t-t_min)+Pi/2),t=19..19.5,color=maroon): display(P1,P2);
This justifies the use of a single RC integrator circuit as an approximate sine-wave generator. Better generators are based on the property that differential equations can be modelled by coupling several elements with feedback (two integrators can model a second-order differential equation), ie., true sine solutions can be obtained in electronics. The interesting message from this worksheet is (apart from explaining the images generated often on oscilloscopes and probably rarely understood) that piecing together exponential solutions can result in a nearly periodic response. This is the result of mathematics that leads to a limit cycle in the solution.
On modern digital oscilloscopes it is relatively straightforward to record the transient (turn-on) behaviour by single-shot triggering.
>