Lab 2
Lab 2
Winter 2021
2 Control Design
To control this system, you will design a proportional controller using the feedback loop in Figure 1 where
K(s) = KP .
1. Find the closed loop transfer function of the system with KP as a variable.
2. Choose a proportional gain to set the closed loop time constant to be less than 10 seconds.
page 1 of 3
Control Systems Winter 2021
𝐾(𝑠) 𝐺(𝑠)
3 Control Simulation
1. Create the feedback loop in Simulink with the proportional gain KP you found in the previous
section. Add a summing block after the plant to add in a room temperature offset (about 70◦ F).
This adjusted output should be connected to a scope to visualize the output. It should also be
connected to the summing block to complete the feedback loop.
2. Simulate this closed loop system with a step input with initial value 70◦ F a final value of 100◦ F.
Adjust the final simulation time to allow for the output value to settle.
3. One issue with this simulation is that the real system has saturation limits on the actuator because
we can apply a maximum of 5V and a minimum of -5V to the heater. Add a saturation block to
your simulation between the controller and the plant. Change the limits to be -5 and 5.
4. Simulate with the 90◦ step input and adjust your maximum simulation time to allow time for the
output to settle. Take a screenshot of a scope with the reference input and output signals on one
figure. You can do this by using a MUX block to combine two signals into one.
5. Replace the step input with a square wave input that alternates between 80◦ and 90◦ . You can
do this by using a pulse generator, a constant input, and a summing block to add them together.
Adjust the timing of the pulse generator so that the output has time to settle before the input value
switches.
6. At this point, take measurements of your rise time, settling time, and steady state error. Feel free
to modify your proportional gain value to improve performance. Make sure to document why you
made the change and explain in your report. Once you are done adjusting, take a screenshot of the
reference input and output signals on one figure.
page 2 of 3
Control Systems Winter 2021
1. Modify your MATLAB code from Lab 1 to add the controller. First, include a line to calculate the
error between your reference input and system output.
2. The error must be multiplied by your proportional gain Kp to calculate the control input (voltage
level to send to the heater).
3. Add code to configure the PWM pins and to convert from a control voltage to the two PWM duty
cycles.
4. To avoid errors in your code, you should add “if” statements to check if your PWM signals are
greater than 1. If greater than 1, the value should be set to 1 for maximum heating or cooling.
5. Test your control loop by setting the desired temperature to 90◦ and running for at least 8 minutes.
Make sure to store your timing data and sensor measurement data in vectors. Save the data in a
.mat file so you have access to it later.
6. Convert the voltage measurement data to temperature using your linear sensor calibration. Plot
this data and include in your report.
7. Test your controller by implementing the square wave you tested in Simulink. Control the resistor
temperature to 80◦ and 90◦ at least twice for each temperature setpoint. You will have to adjust
your timing so that the system has enough time to settle at each setpoint before switching to the
next value. Save the data in a .mat file so you have access to it later.
8. Convert this voltage measurement data to temperature values and plot. Also plot the setpoint using
a different line type so that you can visually show the actual temperature and the desired setpoint.
Include this plot in your report.
5 Lab Report
This lab is the second part of a two part lab. For this lab, you will individually write and turn in a
formal lab report. You should document your progress for Lab 1 and Lab 2. Your lab report should
be organized into sections such as Introduction, Temperature Sensor Calibration, System Identification,
Control Design, Control Simulation, Control Results, and Conclusions. Make sure to use formal writing
and label all figures and tables.
page 3 of 3