A medical instrument is most useful when it can both read information and act on it. Bioen 337 Winter 2012: develop a control system that uses feedback to maintain a target temperature. A medical device can be loosely divided into the part that actually takes the action (the actuator) and the part that determines how hard the actuator will work (the controller)
A medical instrument is most useful when it can both read information and act on it. Bioen 337 Winter 2012: develop a control system that uses feedback to maintain a target temperature. A medical device can be loosely divided into the part that actually takes the action (the actuator) and the part that determines how hard the actuator will work (the controller)
A medical instrument is most useful when it can both read information and act on it. Bioen 337 Winter 2012: develop a control system that uses feedback to maintain a target temperature. A medical device can be loosely divided into the part that actually takes the action (the actuator) and the part that determines how hard the actuator will work (the controller)
Project 4: PID Controller for a Resistive Heating Element Objective: Develop a control system that uses feedback to maintain a target temperature. Background Just as medicine involves both understanding a patients needs and acting on them, a medical instrument is most useful when it can both read information and use that information to establish some condition such as position, force, temperature, or drug concentration. Any piece of equipment that is intended to modify its environment ranging from a hot plate to a computerized robot can be loosely divided into the part that actually takes the action (the actuator) and the part that determines how hard the actuator will work (the controller). The controller usually has two input signals, one from a sensor that measures the condition of the system, and one from a user or program that indicates the desired condition (the setpoint). Together, the properties of the controller, the actuator, and the environment will determine how the system will respond to a command from the user. Control systems can be divided into two types. Open loop systems supply an output in response to some user input but do not monitor the result that the output is having on the system or environment. One example is a burner on a typical stove. The user selects the power input to the burner, but the actual temperature at the burner will depend on the burner characteristics as well as the condition of the material that is being heated and the temperature of the surrounding air. Effective openloop control requires that the user understand how the input affects the system output. Closed loop systems compare the user input to a value measured from the system to determine the output to send to the actuator. One simple example is an oven with a thermostatic switch. The user needs only to set the desired temperature and the switch controls the average power input by turning the heat on and off. The use of feedback in a closedloop control system can accommodate a large degree of ignorance of the system characteristics. However, in order to create a control system that follows the desired output closely, we usually want to apply some knowledge of how the system responds to actuation. In addition, high performance control systems usually respond to the difference between the desired and measured values (the error), not just to being over or under the setpoint. Temperature control For this weeks lab we will heat resistors by passing current through them. We will assume that the resistors have a uniform temperature T R (t), so we can ignore heat conduction and consider temperature only as a function of time. As you know from BIOEN 325 and 327, the rate at which the temperature of an object rises is a function of the heat capacity, mass, and applied power. Write the formula for rate of change of temperature here, including units. dT/dt = ?
BIOEN 337 Winter 2012
print date: 2/21/2012 2 Prelab Exercises Write three formulas for the power P dissipated in a resistor as a function of voltage v, current I, and resistance R. P = ? These equations show that we can control how fast a resistor heats by controlling the applied power, and hence the applied voltage or current.
Proportional control For the following discussion, let us define the error E as the difference between the desired and measured temperatures: E = T SET T MEAS . Each gain component is G and the subscripts P, I and D, stand for proportional, integral and differential. The gain can have whatever units you need to get the input and output to match up. The simplest feedback control system is proportional, such that the controller output equals G P E. For a thermal system we want the output to be power: the farther the measured temperature is below the setpoint, the more power we want to apply. On the other hand, if the measured temperature is above the setpoint, we want to pull power out. This is very difficult (aka impossible) to do with a resistor. *
Therefore, we will control the heating and let the room air cool off the resistor passively. Specifically, if the resistor heats the air so it rises and carries away the heat, we are using the process of _________________ __________________. For this lab project you will set up an electrical circuit and write a control program with LabView. Somehow the values that your control program produces (numbers in a computer) need to be converted into actual power. Lets start at the resistor and work backwards. Heating power is produced by current passing through the resistor, so we are actually controlling the current. It will be a lot more current than the computer can generate, and in addition, the computers DAQ module supplies a voltage, not a current. What we really need is a hefty voltagecontrolled current source. For this we will use a transistor and one of our big power supplies, such that the DAQ output is connected to the base of the transistor (or the gate of a MOSFET). PID control To improve system performance, integral and differential terms can be added, such that
This type of system is known as a proportionalintegraldifferential (PID) controller. The flow chart for every PID controller is the same, and the gains G P,I,D
are adjusted to produce the desired system behavior. Note that the gains G P,I,D are scalars, but the overall system gain V SENS /V CMD is usually complex and is represented by a transfer function H(s), where s = + j.
* There are a few ways to remove heat at a controllable rate. One is to control the speed of a fan or cooling pump. Another is to use a Peltier cooler, which acts as a solidstate heat pump when a voltage is applied. dt dE G dt E G E G v D I P out
BIOEN 337 Winter 2012
print date: 2/21/2012 3 In today's lab exercise we will set up a heater circuit and start a process called system identification, in which we model our system based on knowledge about its physical construction, and on data that we have collected from it. Next week we will use this model to design a controller and test it on our thermal system. Nomenclature E Error: difference between measured and desired sensor value G P Proportional gain G I Integral gain G D Differential gain NTC Negative temperature coefficient V SENS Sensor voltage, hence the environmental value that the controller is trying to control V CMD Command voltage, the input from the user or program T SET
Temperature setpoint T MEAS
Measured or actual temperature
PID control theory assumes that we have a linear system. The implication here is that if we double the value produced by our controller, we will double the power into the resistor. However, this linearity assumption does not match our thermal system in a few ways. First, the current through the transistor is not proportional to the voltage at its base. Second, the power in the resistor is not proportional to the current (or voltage). Of course, you could write a mathematical function in LabView to adjust the DAQ output voltage, making the power proportional to the controller output. There is a more subtle problem, though. Unlike the resistor (for which V=IR), the voltage across the transistor is almost independent of the current. In fact, the voltage often goes down as the current goes up. Consider three cases in our heater circuit. 1) The base voltage is low, the transistor current and resistor voltage are both zero, and the voltage across the transistor is the supply voltage V CC . In this case, the power dissipated in the transistor is P = IV = 0*Vpower = 0. Thats nice. 2) The base voltage is high, the transistor current and resistor voltage are both high, and the voltage across the transistor is as low as it can get. In this case, the power dissipated in the transistor is P = IV = high*low = not too bad. 3) The base voltage, transistor current, resistor voltage and transistor voltage are all midrange. In this case, the power dissipated in the transistor is P = IV = mid range*midrange >> 0. That means that a lot of the heat is dissipated in the transistor, although we want it to heat up only the resistor. You can verify that there is a maximum amount of power dissipated when V R = V CC /2. We see that it is more efficient to operate with the transistor at zero or full current. In order not to convert nice clean electricity into waste heat, we can use
BIOEN 337 Winter 2012
print date: 2/21/2012 4 Pulse width modulation For purposes of heating a resistor, it works just as well if we control the average power rather than keeping the power exactly right all of the time. This power averaging is the basis of a method of power control pulse width modulation (PWM). PWM controllers provide an output that is either off or at full power, but with timing that is determined by the error signal. Whereas an oven with a standard on/off thermostat would be at full power all of the time as the temperature rose from T target 20 to T target 1, an oven with a proportional thermostat using PWM might be at full output 80% of the time when the temperature deficit is 20, but only 5% of the time when the temperature deficit is 1. The fluctuations are typically rapid, cycling several times per second. The resistor has some heat capacity and heat resistance, so it behaves like a lowpass filter that damps out the thermal oscillations. At locations away from the actual point of heat application (e.g. at the thermistor), it is impossible to tell that the heat has been applied in pulses. We calculate average power = max power * ontime fraction, where ontime fraction is pulse width / pulse period. When we use PWM, we use LabView to calculate a percent ontime, also called the duty cycle. Obviously the duty cycle must be between 0 and 100%. This limitation does not seem so bad when we realize that the DAQ output is finite too, ranging from 0 to 5 V. We use LabView to turn the the DAQ output on and off, where off is usually 0 V and on is somewhere from 3 to 5 V, whatever is necessary to permit maximum current through the transistor. Note that pulse width modulation permits us to choose either the analog outputs or the digital outputs from our data I/O device. The analog outputs can be varied in very fine increments over a wide voltage range, but we dont need that here. The digital outputs are either 0 or 5 V, so they are good for proportional control only with a PWM controller. Each digital output is one bit of a binary number, so to use these outputs for thermal control we simply turn the desired bit on or off at the appropriate rate. * In either case, the current supplied by the data I/O device is small, so it is necessary to amplify the current with a transistor before applying it to the heater.
* The analog outputs from an Arduino microprocessor board are actually digital, operated in pulse width mode. BIOEN 337 Winter 2012
print date: 2/21/2012 5 Lab Exercise The goal of this lab project is to create a PID controller that regulates the temperature of a resistorthermistor. This controller can then be the basis for the thermal control system in an environmental control chamber. The major steps in this project are: Assemble a circuit that can be used to heat a resistor and measure its temperature; Acquire step response data and use it to create a Laplacedomain model of the heater system; Determine appropriate PID gains both analytically and by trial and error; Create a feedback controller using Labview; Test the behavior of the controlled system. Equipment Breadboard & connecting wire TIP121 or TIP115 or 2N6292 or 2N6107 power transistor with heat sink 4.7, 5, or 10 resistor, rated for 1 W (2), called lowvalue resistor below Thermistor: 135202FAGJ01, 135103LAGJ01, or similar 1 k resistor (2) 1 or 10 k trim pot for Wheatstone bridge [we will actually just use a voltage divider set up] Power supply USB6009 data I/O device Computer with LabView Circuit setup a) Prepare the lowvalue resistor and thermistor by sliding wire insulation over the leads; this provides electrical isolation. b) Join the resistor and thermistor with heatshrink tubing. [this may be modified epoxy instead] c) Create a Wheatstone bridge for the thermistor, using the 1 k resistors, the trim pot, and the thermistor. The output from this bridge is the input to your data I/O device. [we will actually just use a voltage divider] d) Connect the lowvalue resistor(s) in series with the power transistor, i.e. between the emitter and ground. The input to the transistor's base will be the voltage from one of the analog outputs from Labview. e) Test the operation of the circuit with a power supply and multimeter, or power supply, function generator, and oscilloscope. Test the output voltage from the bridge as you vary the voltage at the base of the transistor. Dont burn yourself! Software setup a) Plug the USB6009 data I/O device into an available USB port on your computer. Complete the installation steps if necessary. b) Create a LabView VI that contains one data acquisition channel and a pulse width modulation output for one analog output channel. Create the front panel BIOEN 337 Winter 2012
print date: 2/21/2012 6 controls necessary to set the output duty cycle manually. This VI can be built around the VI that you created for the colorimeter, but you are going to need a lot of help with the PWM part. We will give it to you, and will provide an example. System identification Once the circuit and software are complete, our first goal is to estimate an impulse response and a transfer function for the heater system. a) Apply a step change to the duty cycle and measure both the input and output voltages until an equilibrium voltage is reached. Estimate the time constant of the transient response, e.g. by measuring the slope at t=0. This time constant will probably be different for the cooling and heating cases; although you will not control the cooling phase, it will be interesting to compare the two results. Therefore, perform at least one experiment for each case. In each one, record the command voltage V CMD (i.e. the voltage applied to the base of the transistor) and the sensor voltage V SENS (i.e. the voltage from the bridge). b) Use the input and output voltage signals with the VI that fits transfer functions to response data. You will be shown how to do this in lab. Obtain three transfer functions: 1) firstorder, 2) secondorder with no zeros, and 3) secondorder with one zero. Choose one of the transfer functions with no zeros to proceed with PID control development. PID controller development a) Plug your coefficients into the closedloop PID control simulation VI and experiment with the PID gains. Your goal is to minimize the rise time and settling time, and overshoot. The overshoot can be most important in a biological control system, because excessive concentrations or temperatures can kill. b) Plug your coefficients into the general form for a transfer function in a PID controlled system (assuming two poles and no zeros), and solve for PID constants that produce a critically damped system. Test those constants in the closedloop PID control simulation VI. c) Add a PID control loop to your input/output VI. You may do these calculations with mathematical icons, express (interactive) math functions, or by using a MathScript node, which allows you to enter MATLAB script that operates on the LabView variables. LabView also includes a variety of PID control functions that do not require you to do your own mathematical programming, but they do not tend to work any better and you might not learn as much if you rely solely on LabView functions. Your VI will need to include a conversion from the voltage produced by your PID controller into output duty cycle. d) Set the gains determined previously and test the response of the system to a step input. BIOEN 337 Winter 2012
print date: 2/21/2012 7
Lab write-up: 1. See separate document for guidelines for this lab writeup.
In conclusion By the end of the project, you should have learned... In any system that needs some input just to stay at a constant value, a proportional control system will produce a steadystate error. The integral gain in a PID controller can eliminate the steadystate error. The differential part of a PID controller can reduce overshoot, allowing you to use higher proportional and integral gains. A feedback controlled system with only one energy storage element (e.g., the heat capacity of the resistor+thermistor) can act like a secondorder system.
Additional information can be found at http://en.wikipedia.org/wiki/PID_controller and http://en.wikipedia.org/wiki/Control_system BIOEN 337 Winter 2012
print date: 2/21/2012 8 NOT USED [The original handout mentioned a linearity compensator and low pass filter. We did not include these this year so you do not need to include them in the diagram. The linearity compensator adjusts for the offset between the base and emitter voltages at the transistor. A lowpass filter is needed if the data is noisy, because voltage fluctuations cause rapid changes in the time derivative. Our signals looked pretty smooth this year.]