First Order Time Domain Response - rioleo First Order Time Domain Response ... In a simplified...

27
E11 First Order Time Domain Response Engineering Department, Swarthmore College Nicholas Szapiro · Ryo Akasaka Performed: October 4 th Turned-in: October 25 th , 2006

Transcript of First Order Time Domain Response - rioleo First Order Time Domain Response ... In a simplified...

E11 First Order Time Domain Response Engineering Department, Swarthmore College

Nicholas Szapiro · Ryo Akasaka Performed: October 4th

Turned-in: October 25th, 2006

Introduction When a resistor is connected in series or in parallel to a capacitor, an RC circuit is created. In equilibrium state, that is, with a constant voltage source, a capacitor acts as an open circuit, building up the voltage of the DC source. The voltage in a capacitor cannot change instantaneously, so as soon as a capacitor experiences a voltage change, we can observe an exponential decay or growth of the initial voltage stored in the capacitor with respect to time. The experiments conducted in this lab help understand the way voltage behaves when energy is released by a capacitor in response to such changes, or the ‘step response’ of the circuit. Practical applications of RC circuits in modern life include flashing bulbs of cameras, electronic timing mechanisms and even windshields1. Theory 555 Integrated Circuit The 555 integrated circuit can be represented in the following diagram.

Figure X details the internal circuitry of the IC chip as well as the pin functions. Image courtesy of National Semiconductors. In this lab the IC, coupled with two resistors and a capacitor, is operated under an astable condition, allowing it to act as a continuous open-and-close ‘switch’ based on the behaviour of the capacitor. Two comparators exist within the 555 chip; they function by comparing two voltages or currents and switching their output to reflect the larger of the two. One comparator – the ‘lower’ comparator – triggers a ‘flip-flop’ set/reset control that causes the output, pin 3, to switch high when the voltage source is initially connected, and the internal switch is effectively

‘open’. As a result, the capacitor begins charging through resistors A and B with 31 the input

voltage. As the capacitor charges towards 32 the input voltage, the other comparator – the

1 “Capacitors and RC Circuits” Accessed October 19, 2006. <http://www.rwc.uc.edu/koehler/biophys/4g.html>.

‘upper’ comparator – is triggered and causes the ‘flip-flop’ control to be reset, causing the output at pin 3 to switch low and the capacitor to discharge through Rb. This is the reason behind the oscillating action seen in graph X.

In Figure X we note the internal switch mechanism connecting pin 7 to pin 1.It is open when the voltage source is initially connected, causing the capacitor to charge through Ra and Rb. The output is ‘low’. Image courtesy of Erik Cheever.

Figure X: At point a, we note that the capacitor begins charging through Ra and Rb, eventually reaching 2/3 V0,, or point b. Then the flip flop is reset and the capacitor begins to discharge through Rb. t1 signifies the time taken for the capacitor to charge, and t2 the time taken for the capacitor to discharge. Image courtesy of National Semiconductor.

Figure X. This is the initial setup of an astable 555 timing circuit. Vcc is the voltage source, and RL is the circuit element which uses the timing device. We used either a LED (light-emitting diode) or a speaker in the position of RL. Image courtesy of National Semiconductors.

Figure X. In a simplified version of the 555 IC in astable operation, the capacitor charges through Ra and Rb as the lower comparator triggers the flip flop such that a RC circuit with Vcc, Ra and Rb is formed.

Figure X. The capacitor discharges through Rb as we note a simple RC circuit being formed once the

032V point has been reached by the charging capacitor.

Step Response of 1st order RC circuits

Figure X shows the circuitry of a first-order RC circuit with a function generator attached. Repeated switching between switches 1 or 2 allows for the square wave to be formed. Rs is the resistance internal to the function generator.

Figure X allows an easier derivation of the input and output voltages of an RC circuit, using a Norton equivalent.

Taking KCL at node ‘a’ shown above, having replaced the function generator with a Norton equivalent, with Is the current source that replaced the voltage source and resistor of the function generator, vc the voltage across the capacitor, R the resistor in parallel to the capacitor, and C the capacitance of the capacitor:

dtdvC

RvI cc

s +=

RCv

CI

dtdv csc

−=

dtRvI

Cdv c

sc ⎟⎠⎞

⎜⎝⎛ −=

1

( )dtRIvRC

dv scc −−=1

( ) dtRCRIv

dvsc

c 1−=

Solving explicitly using x and y as integrating variables:

( ) ∫∫ −=−

ttv

v sdy

RCdx

RIx

c

c 0

)(

)0(

11

RCt

RIvRItvsc

sc−=

−−

)0()(ln

RCt

sc

sc eRIvRItv −

=−−

)0()(

( )RIveRItv scRCt

sc −=−−

)0()(

( ) RIRIvetv sscRCt

c +−=−

)0()(

( )RIveRItv scRCt

sc −+=−

)0()( This is the equation for the step response of an RC circuit, where vc(0) is the initial voltage across the capacitor. The voltage drop across the resistor is IsR. When the initial voltage across the capacitor is 0 right after the switch has been closed, the equation reduces to

)1()( RCt

sc eRItv−

−=

Charging and discharging of the Capacitor: Another derivation With the function generator supplying a voltage of Vi, we apply KVL when the switch in Figure X is moved to 1 and assuming Rs to be internal to the generator:

0)()(0 =−−CtqRtIV

where V0 is the voltage supplied by the function generator, and C

q(t) is the voltage drop across

the capacitor. Since I = dtdq and dividing by R:

RCtq

RV

dtdq )(0

−=

Rearranging and integrating gives us:

∫∫ =−

t

dtRCCVtq

dq

00

1)(

RCt

CVCVtq

−=⎟⎠⎞

⎜⎝⎛

−−

0

0)(ln

)()( 00 CVeCVtq RCt

−+=−

or )1()( 0 RCt

eCVtq−

−= Since q(t) = CV(t) we obtain

)1()( 0 RCt

eVtV−

−= This models the behaviour of the capacitor as it is charging. RC is often replaced by the letter τ.

RC=τ

When RCt = , we note that the voltage across the capacitor is at e11− , or 0.631 its final value.

We employ KVL when the switch in Figure X is moved to 2:

0)()( =−−CtqRtI

to obtain ultimately

)()( 0 RCt

eVtV−

= modelling the behaviour of the capacitor as it discharges.

555 Oscillator Circuit In considering the action of the flashing LED in the circuit we construct later in the lab, we consider t = 0 when the internal switch of the 555 chip has just opened, and thus the capacitor has just begun charging, and the output is high.

vc(0) = 31 Vcc

With the equation for the step response of a RC circuit, we note: vc(t) = Vcc + (Vc(0) - Vcc)e-t/RC Rearranging, we obtain

RCVVVVt

cc

ccc

−−

=max

)0(ln

where Vmax is 32 Vcc, the point where the capacitor then begins discharging. Hence:

RCVVVVt

cccc

cccc

−−

=3/23/1ln = ln(2)RC, where R is equal to Ra + Rb

Similarly, when the output is low, the capacitor discharging from 32 Vcc is interrupted halfway

to its steady state, and therefore the time taken to discharge is ln(2)RC, where R = Rb. Since the period of oscillation is both the time taken to charge and discharge the capacitor, we obtain

[ ] [ ]C)ln(2)(RC)Rln(2)(R bba21 ⋅+⋅+=+ tt [ ])R2(Rln(2)C ba21 +⋅=+ tt

Since frequency,period

f 1= , we derive [ ])R2(Rln(2)C

1

ba +⋅=f = [ ])R2(RC

442.1

ba +⋅

Graph X, a collation of two results obtained in this lab, shows the exponential growth and decay as derived, with the time constants labelled as a function of the initial voltage, V0. Since the graph is a combination of two separately obtained results, the time label has been removed. Nevertheless, t1 – t2 is equal to the time taken for the capacitor to charge, and t3 – t2 is the time taken to discharge.

Microcontroller and level-shifter circuits In considering the following simplified diagram of a microcontroller, where the area within the dotted lines can be considered as the level-shifter circuit discussed in the first lab, we seek to obtain the value of VAIN as accurately as possible with respect to the input on the analog-to-digital converter marked by the square box with the diagonal lines.

Figure X. Simplified diagram of a PIC microcontroller. We note the dotted area equivalent to a level shifter circuit, the capacitance internal to the microcontroller, and ANx the input to an A/D converter. Image courtesy of Erik Cheever. The manufacturer recommends that Rs in the level shifter (within the dotted lines) be no greater than 10kΩ. In the static operation of the circuit, since the capacitor acts as an open circuit we note that the voltage measured at the microcontroller pin, Vx will be

sLAINx RIVV −= where IL is the current leakage. In order to minimize the difference between Vx and VAIN, we want to minimize ILRs. IL is constant and cannot be changed. Hence Rs must be kept at a minimum. When the input voltage is changing, the capacitor is discharging with a time constant of RC, because the equivalent resistance of the level-shifter voltage, the resistor and the current source is R. If R is too high, the response of VAIN will be slower, since it would take longer for the current to decay to 37% its original value. As a result, the manufacturer’s recommendation for Rs to be no greater than 10kΩ is based on that necessity to minimize the difference between VAIN and ANx. In the static operation of the circuit, for example, we see that the ‘error’, or the discrepancy between Vx and VAIN is limited to ILR, or 500(10-9)(10E3) or 5mV. With the input voltage changing, we see that the time constant is RC or (10E3)(51.2E-12) or 0.512µs. In order to minimize Rs, then, the most effective way to do so with three resistors R1, R2 and R3 is by adding the third constraint that Rs = R1 || R2 || R3, since the resulting equivalent resistance would be less that any single resistance.

Figure X. The level-shifter circuit and a separate simplified interpretation of the circuit. Vdd (voltage drain-drain) is equivalent to the positive supply voltage, while Vss (voltage source-source) is equivalent to the negative supply voltage and ground.2 Image courtesy of Electronic Design and Erik Cheever. PCB Circuit and Behaviour The figure below represents the circuit soldered as described in the procedure section:

2 http://encyclobeamia.solarbotics.net/articles/vxx.html

Figure X: The complete circuitry of the flashing LED-sound and 555 oscillator system. Image courtesy of Erik Cheever. For an analysis of the circuit with an open switch at U3, we can consider each third of the circuit independently. The two ‘islands’ with 555 timers operate as described before with the frequency of the oscillation inversely dependent on the 10 kΩ and 100 kΩ resistors with the 10 µF capacitor for the left island and the 1 kΩ and 10 kΩ resistors with the 0.1 µF capacitor for the right island. Using the previously derived expression for the frequency of oscillation, we can see that the frequency of oscillation of the right island has roughly a thousand times greater factor of magnitude than that of the left island. With the switch open, the speaker gives a sound with constant pitch determined entirely by the switching mechanism of the right 555 timer. When we press the button closing the switch, the pitch of the sound oscillates in coordination with the charging and discharging of the 10 µF capacitor at C4. We know that when the output voltage from the left island is high, the LED at L2 is off (no potential difference between Vcc and the node connecting the output of the left 555 timer to the switch) and the current passes to the right through the switch. When the output is low, the light is on and current passes to the left through the switch. The effect of the synchronization of the sound with the charging of the capacitor is especially notable when we short the capacitor at C4 – the pitch from the speaker oscillates in relation to the square wave signal coming from the output of the left 555 timer. When the capacitor at C4 is not shorted the spacing between high and low pitches is asymmetrical, as can be inferred from the exponential decay characteristic of the charging of the capacitor. The synchronization of the lighting of the LED at L2 and the lowering of pitch from the speaker is dependent on the switching of the direction of the current through the switch. Curve fitting with The MathWorks3 In order to more accurately analyze the data provided by the oscilloscope, and determine the time constant, we employed a function called fminsearch in MatLab, which determines the minimum of a function without using derivatives. By using fminsearch, we can minimize the sum of squares of errors between the data and an exponential function we seek to fit it to, A = e-λt. The m-file fitcurvedemo (see appendix) “accepts vectors corresponding to the x- and y-coordinates of the data and returns the parameters of the exponential function that best fits the data” (Ibid). In order to generate the most accurate fit, we removed the first 25 and the last 20 data points retrieved using the Agilent function in Excel, because the data points included unnecessary points prior to the actual discharging of the capacitor, as well as points where the capacitor just begins to charge once again.

3 http://www.mathworks.com/access/helpdesk/help/techdoc/math/index.html?/access/helpdesk/help/techdoc/math/f2-939909.html

Procedure For the first part of this lab, we used a function generator set to a square wave signal of a frequency of 50 Hz ranging from 0 to 1 V (approximately). We connected a resistor box set to 1 kΩ (3% tolerance) in series with a capacitor box set to 1 µF to the function generator, measuring the input and output voltages with an oscilloscope. With ground as one reference point, the reference points are as shown:

Using the Agilent function in Excel, we were able to store the data points from the oscilloscope connected to the computer. We then switched the resistor to 2 kΩ and noted a more gradual exponential curve (the voltage takes longer to decay). Using the slope option to trigger the oscilloscope, we recorded data for increasing and decreasing curves. We then set the resistor box back to 1 kΩ and changed the capacitor box to .5 µF noting the effect of halving the time constant on the output voltage (a sharper exponential curve). For the second part of the lab, we configured the circuit below on a breadboard located on the desk:

RA=33 kΩ RB=20 kΩ C=0.1 µF Vcc=5 V

Although the circuit on the breadboard was not very elegant, colour-coding the wires (grey to ground, etc.) greatly increased the simplicity of the design and quickened the troubleshooting.

After successfully configuring the circuit, we could hear an oscillating pitch coming from the speaker. The oscillation comes from the internal switching mechanism of the LM555 timer as described in the theory section of this report. By turning the knob of the potentiometer, we could control the frequency of the changes in pitch. As an optional part of the lab, we then configured a resistor-inductor circuit analogous to the RC circuit in the first part of the lab with R = 1 kΩ and L = 112 mH. Interestingly, the output voltage was double the input voltage every time the square signal switched between -1 and 1 V and then decayed to 0 as the change in current through the inductor approached 0. For the third part of the lab, we soldered a circuit onto a printed circuit board (following the step-by-with the configuration shown in the figure located in the theoretical section of this report. To solder, we used a heating element (around 750° F) to melt a metal wire mainly composed of tin to fill in the connection between the circuit element and the circuit board. After the connection was secure, we removed the excess wire of the circuit element that poked through the other side of the board with clippers. In order to secure the battery to the board, we used hot glue on a plastic holder that contains the battery. We connected the terminals of the battery to the board with wires connected to the battery through the plastic container. To amplify the sound of the circuit, we connected a stereo speaker to the circuit and, surprisingly, the circuit created enough current to power the speaker. Results With a capacitor of 10µF and a resistor of 1kΩ, we note that the expected time constant would be

Ω× 3-6 1010 F or 310− seconds RC Circuit

Input Voltage (V) Output Voltage (V) Initial Final Initial Final

Measured Time

constant (sec)

Expected Time

constant (sec)

Curve-fitted Time

constant (sec)

1.044 0.0625 1.056 0.075 0.0012 0.001 0.0015 Table X details the initial and final voltages for both input and output, as well as the measured time constant using Matlab and the closest data point, the expected value for the time constant, and the curve-fitted time constant. Using the best fit exponential equation retrieved by the function fitcurvedemo: y = 0.9407e -647.1949t we calculate the time constant by comparing it to the equation vc(t) = V0e-t/τ

Hence 647.19491−=

τ

or τ = 0.0015

Percent deviation: 001.0

001.00012.0 − = 20%

RC Circuit with 2R

Input Voltage (V) Output Voltage (V) Initial Final Initial Final

Measured Time

constant (sec)

Expected Time

constant (sec)

Curve-fitted Time

constant (sec)

1.044 0.05625 1.025 0.1 0.00232 0.002 0.0027 Using the best fit exponential equation retrieved by the function fitcurvedemo: y = 0.9631e -363.9050t

9050.3631−=

τ

or τ = 0.0027

Percent deviation: 002.0

002.000232.0 − = 16%

RC Circuit with rising slope

Input Voltage (V) Output Voltage (V) Initial Final Initial Final

Measured Time

constant (sec)

Expected Time

constant (sec)

Curve-fitted Time

constant (sec)

0.06875 1.05 0.08125 1.05 0.00088 0.001 N/A The Matlab code could not be configured for a rising slope exponential curve. Frequency of Oscillation for 55 oscillator For the expected frequency, we employ the derived equation, substituting RA=33 kΩ, RB=20 kΩ and C=0.1 µF:

[ ])R2(Rln(2)C ba21 +⋅=+ tt [ ])(202(33)ln(2)(0.1 E3E36-E

21 +⋅=+ tt [ ])(202(33)ln(2)(0.1 E3E36-E

21 +⋅=+ tt 0050599.021 =+ tt

Measured Expected

t1 point of reference: just before capacitor

discharges

t1 point of reference: just before capacitor charges

t1 (sec) t2 (sec) t1 (sec) t2 (sec) 6.099(10-20)) 0.0056 0.00144 0.00704

Period (with point of

reference before capacitor discharges) (sec)

Period (with point of reference before

capacitor charges) (sec)

Expected period (sec)

0.0056 0.0056 0.0051

Frequency (Hz) Frequency (Hz) Expected

frequency (Hz)

178.57 178.57 197.63

Table X shows the data points retrieved for the analysis of the period and frequency. With two reference points, when the period is measured with respect to the point just before the capacitor discharges, and when the period is measured just before the capacitor charges, we tried to get a more accurate value- they proved to be identical.

Percent deviation = 197.63

178.57- 197.63 = 9.6%

Graph X shows the exponential decay of the voltage in the capacitor in the ‘low’ part of the output of the function generator. Since essentially there is no longer any current supplied to the capacitor, it begins discharging. We can see that the capacitor immediately begins charging once current begins to flow.

Graph X shows the best fit curve using the fminsearch code provided by MathWorks as a suitable method to fitting to data with exponential decay of the form Ae-λt. Though non-ideal, it does a relatively accurate job as compared to other software, such as Kaleidagraph.

Graph X shows the input and output voltages of a RC circuit. We note the exponential decay from the capacitor, and compare it to the previous graph: the slope is less steep, since by doubling of the resistance, the time constant gets larger. If the time constant is larger, the voltage across the capacitor takes longer to decay to 37% its original value.

Graph X shows the curve fitting as done by The MathWorks’ fminsearch function4 which minimizes the sum of squares of errors between the data and the exponential function Ae-λt. As a result, we obtain the equation y = 0.9631e

-363.9050t.

4 http://www.mathworks.com/access/helpdesk/help/techdoc/math/index.html?/access/helpdesk/help/techdoc/math/f2-939909.html

Graph X shows the charging of the capacitor when the flip flop allows the input voltage to flow through the 555 and

into the capacitor. When the capacitor reaches ccV32

the capacitor begins discharging, as can be seen on the right of

the graph.

Graph X shows the input voltage and the capacitor voltage for a 555 oscillator circuit in an astable operation. By observing pin 3 and 6 on the oscilloscope, we are effectively examining the voltage of the capacitor, reflected in this graph.

Graph X. For the optional part of the lab, we assembled a RL circuit. By translating the equation derived in the lab, we note that the behaviour of the inductor in an RL circuit is (VL-IsR)e-(R/L)t, which reflects the exponential nature of the curves we see.

Error Analysis

A few preventable errors should be noted and avoided in all future similar experiments of this kind. Firstly, we noted that by assuming that the Agilent function in Excel would retrieve the most accurate representation of what is being seen on the oscilloscope, as opposed to directly recording off of the machine, we failed to realize that the data points in the set were not accurate enough to reflect a value for the time constant closer to the expected solution. Furthermore, by failing to make the oscilloscope reading large on the main screen, our Agilent data was not sufficiently accurate. Though the curve-fitting gave a reasonable estimate for the curve, it did not allow us to obtain an accurate value for the time constant that was 36.78% the original value (or 63.21%, for the rising slope).

Appendix

function [estimates, model] = fitcurvedemo(xdata, ydata) % Call fminsearch with a random starting point. start_point = rand(1, 2); model = @expfun; estimates = fminsearch(model, start_point); % expfun accepts curve parameters as inputs, and outputs sse, % the sum of squares error for A * exp(-lambda * xdata) - ydata, % and the FittedCurve. FMINSEARCH only needs sse, but we want to % plot the FittedCurve at the end. function [sse, FittedCurve] = expfun(params) A = params(1); lambda = params(2); FittedCurve = A .* exp(-lambda * xdata); ErrorVector = FittedCurve - ydata; sse = sum(ErrorVector .^ 2); end end

The above M-file uses the MatLab function fminsearch to minimize the sum of squares of the differences between the extracted data and the exponential function Aeλt. The function expfun computes the sum of squares. Extracted from The Math Works > Mathematics > “Fitting a Curve to Data” online.

% Extracts data from imported Excel file. Note it would be best to ‘clean’ % the data first by removing unnecessary points immediately before and after % the points of interest as described in the lab xdata = data(:,1); ydata = data(:,3); % Asks for the estimates for the function A = e^(-λt) using the function % embedded in the file fitcurvedemo.m [estimates, model] = fitcurvedemo(xdata,ydata) plot(xdata, ydata); hold on % Ensures that subsequent changes to the graph add on to the existing graph [sse, FittedCurve] = model(estimates); plot(xdata, FittedCurve, 'r') % Adds axis labels, titles, and legend xlabel('Time (sec)') ylabel('Voltage (V)') title(['Fitting to function using fitcurvedemo/expfun']); legend('Output voltage (V)', ['fit using ', func2str(model)]) hold off

The above M-file extracts data from an imported file and employs the fitcurvedemo function to generate and plot the best fit exponential curve to the data set. It also prints the best estimate it can provide for the coefficients of the equation Ae-λt. Extracted from The Math Works > Mathematics > “Fitting a Curve to Data” online.

Bibliography 223 Physics Lab: The RC Circuit. Clemson University. January 27, 2006. Accessed October

19th, 2006. <http://phoenix.phys.clemson.edu/labs/223/rc/index.html> Capacitors and RC Circuits. Koehler, Kenneth R, Raymond Walters College. 1996. Accessed

October 12th, 2006. <http://www.rwc.uc.edu/koehler/biophys/4g.html> Cheever, Erik. “E11 Lab #3: 1st order time domain response.” Accessed October 4th, 2006.

<http://www.swarthmore.edu/NatSci/engineering/engr011/Labs/E11L2/Lab2(Report).html>

“E11 Formal Lab Report Format.” <http://www.swarthmore.edu/NatSci/engineering/engr011/Labs/Formal_report.html> Accessed October 10th, 2006

National Semiconductor. “LM 555 Timer” (Datasheet). February 2000. Accessed October 12th,

2006. <http://www.swarthmore.edu/NatSci/echeeve1/Ref/DataSheet/LM555.pdf> Nilsson, James and Susan A. Riedel. “Electric Circuits: Seventh Edition”. 2005, Pearson

Education International. Mathematics, Fitting a Curve to Data. The Math Works. 2006. Accessed October 18th.

<http://www.mathworks.com/access/helpdesk/help/techdoc/math/index.html?/access/helpdesk/help/techdoc/math/f2-939909.html>

Soma, Mani. “Step Response of RC Circuits”. University of Washington. Accessed October

22nd, 2006. <http://faculty.washington.edu/manisoma/labs/RCstepsimple.pdf> The 555 Timer IC. Bigelow, Ken. 2000-2006 Accessed October 19th, 2006. <http://www.play-

hookey.com/digital/timer_555.html> Vcc, Vdd, Vss, etc. Eric Seale and Wilf Rigter. July 11, 2003. Accessed October 18th, 2006.

<http://encyclobeamia.solarbotics.net/articles/vxx.html> Wrate, Glenn. “Step Response of RC Circuits”. Spring 2003. Milwaukee School of

Engineering. Accessed October 22nd, 2006. <http://people.msoe.edu/~wrate/ee202/rc_step_response.pdf>