Experiment BULB Bulb Control Hardware Requirements 1. Test board with power supply, amplifier, bulb and photodiode. 2. LPC 2138 microprocessor for controller implementation (has 2 analogue inputs, and one output, sampling rate: 100Hz) 3. Skeleton Code for running/ implementing compensator using the above 4. Signal Generator 5. Power supply, for generating d.c inputs in the range 0V-3V 6. Digital Storage Oscilloscope 7. BNC-BNC cables, BNC T connectors 8. Computer with Keil compiler, Philips Flash Utility, and Matlab Version 2.5 Experiment BULB: Bulb Control 2.5 EEE2/ISE2 Spring 2008 1. System Characterisation The system that will be studied in this experiment consists of a bulb which is driven by an opamp circuit with a certain frequency response. The output from the bulb (the light intensity) is then measured through a photodiode. The full schematic for the system is shown in Appendix A. A simplified linear model for the opamp circuitry, bulb and diode is depicted below. In(s) Gamp(s) Gbulb(s) Out(s) GL(s) Figure 1. Simplified Linear Plant The transfer functions for the bulb (which has been determined experimentally) and the opamp circuit (which can be derived analytically from the circuit diagram) are given respectively by: So the overall Plant transfer function 1.1 Measuring Input/Output Steady State Characteristics The transfer function GL(s) can be re-expressed as For d.c inputs, that is, , , that is the output/ input relationship is theoretically linear, with gain equal to 1. The objective of this experiment is to verify the validity of the simplified linear model presented in Figure 1. Page 2 Experiment BULB: Bulb Control 2.5 EEE2/ISE2 Spring 2008 The steps to be taken are: - apply a dc value, measure corresponding output, - repeat for a range of values (0-3V) - plot output (in V) against input (in V) Experiment 1 1. Power up the Lightbulb system. 2. Use the Hameg signal Generator (Or a power supply), to provide a DC input. 3. Connect the 50 ohm output of the Hameg to the input terminal of the board. 4. Connect the output of the box to one of the inputs of the Oscilloscope. 5. Take input/ output measurements for inputs of up to 3V and plot your results. 6. Describe your results with respect to linearity. Based on the linear transfer function of equation [3], is it what you expect? What can you conclude about the simple model of Figure 1? Nonlinearity The previous results clearly show that the relationship Out = In does not hold. This is due to the nonlinear characteristic of the bulb and photodiode, described in Figure 2. Figure 2 Bulb and Photodiode The nonlinear characteristic can be incorporated into the system model, as shown in Figure 3, where GL(s) is as defined before and NL represents the non linear curve which you have just measured in Experiment 1. GL(s) Nonlinearity Figure 3 System with Non linearity 1.2 Frequency Response The behaviour of the system with frequency can be determined by setting s=jw1and finding the system gain GL(jw1). This can be done in practice by applying a sine wave of known amplitude, measuring the output and hence obtaining the gain, and repeating for several frequencies. Page 3 Experiment BULB: Bulb Control 2.5 EEE2/ISE2 Spring 2008 In our case, a sine wave with a peak to peak voltage of 0.2V and a d.c offset of approximately 1 V will be used as input. Based on your findings from experiment 1, can you suggest why a d.c offset is needed, and why the sine wave amplitude is chosen to be small? Experiment 2 Note on procedure. in order to obtain a suitable DC offset you will need to use the PSU in series with the signal generator as in Figure 3a below. (The signal generators have available only a limited range of internal voltage offset, and this facility should not be used). outer Board Signal inner inner generator WARNING - PSU output - Gnd + must be less than 5V. black green red blue black red Note alternate colours for Minus/Gnd/Plus PSU connections of PSU Figure 3a - PSU connection in series with Signal Generator 1. Adjust Hameg Signal Generator to give the desired signal. The same signal amplitude and offset will be used throughout this test, for different frequencies. 2. Confirm that the input signal is what you expect, by using a BCN T connector and connecting the output of the Hameg to the 2nd channel of the oscilloscope. 3. Once you are happy with your signal, connect the signal generator output to the Input of the board and the output of the board to the 1st channel oscilloscope. 4. Keeping the sine wave amplitude and d.c offset fixed, vary the frequency and measure the (peak-to-peak) output of the bulb for each value of frequency. 5. Start from around 0.5 Hz and test until 10 Hz. 6. Use the Matlab script (see Appendix B) provided to plot the Gain variation (in dB) against frequency. The provided script also compares this against the linear model. 7. Comment on the difference between the two traces. [Hint: Find the gain (the slope) from the Output-Input Curve of Experiment 1 at an input of 1V]. Also, remember that the theoretical model is represented Figure 1, while the practical model is depicted by Figure 3. 1.3 Open Loop Step Response A test signal which is often used as a measure of system performance is the unit step, which models sudden disturbances. It is mathematically defined as ( ): Experiment 3 In practice, a step input can be simulated by applying a low frequency (~0.5Hz) square wave. Here, use a square wave rising form 0.5V to 1.5V. Measure the steady state value1 and rise time2 of your system. {Sketch/save a copy of the observed trace for future reference} 1 2 The value to which the response settles to after all oscillations have died out The time taken for the response to rise form 10% to 90% of the steady state value Page 4 Experiment BULB: Bulb Control 2.5 EEE2/ISE2 Spring 2008 2. Closed Loop Control Feedback can be used to force a system to exhibit desired characteristics. A typical feedback arrangement is shown below (Figure 4) y(t) r(t) Controller ∑ Plant − Figure 4 Feedback System For a given plant, GL(s), with a compensator C(s), and a constant gain K, the closed loop transfer function can be shown to be: Closed Loop = , where As an exercise, derive the above. R(s) E(s) ∑ K H(s) = C(s) × GL(s) Y(s) − Figure 5 Feedback With controller C(s) and constant gain K Most of the advantages of feedback are fully reaped if a large loop gain, that is, a large value of K, is used. This, however, tends to drive the system into instability. Techniques such as Root Locus and Routh-Hurwitz Criterion (a summary of these will be presented later) enable us to determine the upper limit on the gain K. 2.1 Pole Locations & their Contribution The system characteristics depend on the position of the poles. Poles in the right hand plane have exponentially increasing contributions and cause system instability. Poles on the imaginary axis are purely oscillatory and are marginally stable. Negative real poles are pure exponential decay. Complex poles with negative real parts are oscillatory with exponential decay. The larger the imaginary component, the larger the frequency of oscillations. The further left a pole is (i.e the larger the magnitude of the real component), the faster the rate of decay. The above ideas are illustrated in Figure 6 below. Page 5 Experiment BULB: Bulb Control 2.5 EEE2/ISE2 Spring 2008 Figure 6 Impulse response of Poles at different positions in the s-plane (complex conjugate not shown) 2.2 Root Locus (RL) For the closed loop system described in Figure 5, with transfer function => Y(s)/R(s) = KH(s)∕(1+KH(s)), the RL is a plot of the roots of the characteristic equation (closed-loop poles) as K varies from 0 to ∞. (Note, for K=0, the closed-loop poles are equal to the open loop poles) Hence, the RL gives an indication of what type of response to expect from a system as the gain is varied, since the behaviour of the closed-loop system is largely determined by the location of its poles. Also, the root locus indicates if the closed loop poles cross the jw axis (and at what value of K this happens) and therefore indicates when instability will occur (if at all). Drawing the RL by hand can be done quickly using certain procedures described in the Lecture Notes. In this Experiment, Matlab will be used to draw these. [see Appendix B] 2.3 Routh-Hurwitz Stability Criterion This is an analytical procedure for determining if all roots of a polynomial lie in the left half plane (i.e are stable) without actually evaluating them. For our closed loop system, , and the characteristic equation is . From this, the Routh array is first formed, as described in Figure 7. Then from the Routh-Hurwitz Criterion, The number of unstable roots is equal to the number of sign changes in the first column of the array. Page 6 Experiment BULB: Bulb Control 2.5 EEE2/ISE2 Spring 2008 Some of the coefficients will be functions of K, and hence an upper bound on K can be found using the above condition. Figure 7 Formation of the Routh Array 2.4 Final Value theorem For an output Y(s) = G(s) × R(s), where R(s) is the input, and G(s) is a transfer function, the final value of the output, is given by: Page 7 Experiment BULB: Bulb Control 2.5 EEE2/ISE2 Spring 2008 2.5 Behaviour of Plant in closed loop Mode Using Matlab [see Appendix B], draw the root locus of the plant: You should get the following. Note that the complex pole pair closer to the vertical axis correspond to the poles of the opamp circuit, while the real pole corresponds to the pole of the bulb. Root Locus 80 60 System: fw dpath Gain: 0.235 Pole: -0.726 + 33i Damping: 0.022 Overshoot (%): 93.3 Frequency (rad/sec): 33 40 Imaginary Axis 20 0 -20 -40 -60 -80 -100 -80 -60 -40 -20 0 20 40 Real Axis Figure 8 Root Locus, Plant Only Experiment 4 1. Evaluate the maximum proportional gain that can be applied before the system goes unstable. [using Routh-Hurwitz stability Criterion] 2. What is the steady state value of the closed loop system ( ) for a gain K = 0.2 (which is slightly under the maximum allowable gain). {hint: use the final value theorem} 3. Using Matlab (see Appendix B), find the step response of the closed loop system for K=0.2. - First set C(s) = 1 and K = 0.2 - H(s) = C(s)×G(s) - Find the closed loop transfer function. - find the step response of the closed loop transfer function. Page 8 Experiment BULB: Bulb Control 2.5 EEE2/ISE2 Spring 2008 2.6 Hardware Implementation of Control Loop A microcontroller, the LPC2138, will be used in this lab to implement the feedback loop. (All you need to know about this is in Appendix C) e[t] = r[t] – Linear[y(t)] r(t) ADC ∑ 1/NL K×C(s) y(t) DAC GL(s) NL − Linear[y(t)] 1/NL ADC This part of the loop is implemented in the microcontroller Figure 9 Closed Loop Implementation using Microprocessor The microcontroller includes a lineariser which measures the nonlinearity (a bit like what you did in experiment 1) and builds a look up table from which it is able to linearise values of y(t). The lineariser, however, works only for a certain range of values of y(t) : [roughly 0.3V to 3V, but this might vary slightly depending on your test board]. The ADC and DAC operate at a sampling frequency of 100Hz, which is ~10 times the maximum frequency of interest here (see results of Experiment 2). Hence for the purposes of this experiment, the digital domain controller can be assumed to approximate a continuous time domain controller very well. To set the transfer function of the controller, open the Coffs.h file and modify the coefficients accordingly. (See Appendix C for more details) 2.7 Compensator Design. The objective of this section is to come up with a suitable design for a compensator using Root Locus technique. From the RL of the plant (Figure 8), it is clear that the system is dangerous as a small gain in the forward path is enough to cause instability. To solve that, the RL needs to be shifted to the left of the s-plane. One way could be to implement a compensator that cancels out the contribution of the amplifier poles Gamp(s) (see equation [2] and Figure 8). These poles are closer to the imaginary axis and removing them is one way of shifting the RL to the left and therefore allowing a larger value of K. Page 9 Experiment BULB: Bulb Control 2.5 EEE2/ISE2 Spring 2008 Experiment 5 1. Investigate the behaviour of such a compensated system by plotting its root locus in Matlab [Appendix B]. - Define a controller . , where is the plant transfer function - Plot root locus of H(s) - Explain, with respect to stability and maximum value of K, how this root locus implies a better, more desirable properties than the uncompensated system of Figure 8. 2. The above transfer function cannot be implemented in practice as it is non-causal. For a system to be causal, the order (that is, the highest power of ) of the numerator must be less than or equal to the order of the denominator. 3. To make it causal, increase order of the denominator by 2, i.e, insert a double pole at the origin. So, . 4. Plot the root locus of the compensated system (by using the same steps as in part 1). Why will this compensator not work? 5. To further shift the root locus to the left, move one of the poles you inserted to s= -100. Plot the RL. How is this better? What is the maximum gain that is tolerable? 6. Notice that one of the compensator poles is kept at s=0. Such a pole is called a free integrator and its effect is to set the steady state error to a step input to zero. By considering the error signal (see Figure 5, with K=1), – , and the final value theorem, show that the steady state error ( ) to a step input (that is, ) is indeed zero, and explain how the free integrator enables that type of response. Another point to note with the root locus from part 5 is that, for a certain gain, the two real poles closest to the imaginary axis converge to a certain value before they break away from the real axis and become a complex pole pair. At this point, the compensated system is said to be critically damped. Using Matlab, find the value of the gain, at which this happens. 2.8 Implementation of controller. Using the controller transfer function, Cs, designed above, and the value of discrete-time equivalent transfer function using the following Matlab command: , find the Cz = c2d (Kdamped*Cs, 0.01,'zoh'); Open the Coffs.h file and change the coefficients accordingly. Program the microprocessor and run it. [Note, the microprocessor initially builds up a look up table. During that time, an error message “Error - bad f(x)” may appear. Do not worry about this.] Experiment 6 1. To verify the performance, apply a step input 0.5V-1.5V 2. Measure rise time. 3. Verify that it corresponds to the ideal implementation of the same system. 4. Compare the step response of the compensated system w.r.t the uncompensated open loop response (experiment 3) Dr I. Jaimoukha/ K. Choonee (2008) Page 10 Experiment BULB: Bulb Control 2.5 In(s) EEE2/ISE2 Spring 2008 Gamp(s) Gbulb(s) Out(s) GL(s) Page 11 Experiment BULB: Bulb Control 2.5 EEE2/ISE2 Spring 2008 Appendix B: Matlab 1) Modelling transfer functions: Gbulb = tf([1],[0.038 1]); %bulb and diode transfer function Gamp = tf([1000],[1 5 1000]);% amplifier G3 = Gamp*Gbulb;% overall plant 2) Plotting Theoretical Transfer function and measured transfer function on the same axes. % frequency response of fully built board % Instructions: fill in the three vectors below with the applied % % % input peak to peak voltage, the frequency, and the measured output % peak to peak voltage a_in = ***; % input sinewave peak to peak, dc level = 1.0V f =[* * *]; % fill this out with the applied frequencies a_out [* * *];% fill with corresponding output peak to peak voltage w_exp = 2*pi*f; gain_exp = a_out/a_in; dbgain_exp = 20*log10(gain_exp); % theoretical freq response G3snum = 1000; G3sden = [0.038 1.19 43 1000]; s = (i*w_exp); G3s_gain = 1000./abs(polyval(G3sden,s)); dbG3s_gain = 20*log10(G3s_gain); % Comparison of theoretical with experimental figure plot(f,dbG3s_gain,'-o',f,dbgain_exp,'-x'); legend('Theoretical','Experimental'); grid xlabel('Frequency/Hz');ylabel('Gain/dB'); title('Theoretical frequency response and Experimental Freq Response'); 3) Step Response: First define the transfer function of the system, as in part 1) above. step(G3); 4) Closed Loop: i. Applying Feedback: Suppose we want to model the topology of Figure 5. First Define H(s) and K in the Matlab workspace. Then: clsys = feedback(K*Hs,1); % negative feedback ii. Root Locus Analysis: Suppose we want to observe the position of the closed loop poles of figure 5as K varies from 0 to ∞: rlocus(Hs) Page 12 Experiment BULB: Bulb Control 2.5 EEE2/ISE2 Spring 2008 Appendix C: Microprocessor The enclosed code, from the zip file ExptD.zip, contains a Keil project .\ExptDCode\ExptD which will compile to file ExptD.hex. The hex file can be downloaded to the LPC2138 board. Full instructions on how to compile & download a Keil project can be found on lab web: https://intranet.ee.ic.ac.uk/t.clarke/ee2lab/expts/exptU/EEE_Board_QuickStart.htm Board connections (from left to right) are: Input from waveform generator (in range 0-3v) Input from lightbulb board photodiode (in range 0-3v) Output to lightbulb board (in range 0-3v) not used Code as written here will first calibrate the board and sort out any nonlinearity, then run the controller. Note that the lineariser does not fully compensate for the nonlinearity. Modifying the controller transfer Function: Open the ExptD.Uv2 Keil Project, located in the ExptD directory. You should see the following: Figure 10 screenshot of Keil Click on the coffs tab. You do not need to worry about the rest of the tabs. ac_n : coefficient of zn in the controller numerator bc_n: coefficient of zn in the controller denominator For example for a controller of (z2+0.2)/(z2+z) =(z2+0×z +0.2)/(z2+z+0), ac_2 =1, ac_1=0, ac_0=0.2, bc_1=1, bc_0=0 Page 13