Microcontroller-based experiments for a control systems course in electrical engineering technology Albert Lozano-Nieto Penn State University, Wilkes-Barre Campus, Lehman, PA, USA E-mail: AXL17@psu.edu Abstract A microcontroller-based system is used to illustrate experimental concepts in a Control Systems course in an Electrical Engineering Technology program. Students are able to experiment with different control strategies ranging from an open-loop to PID control. Students are asked to reason and discuss the benefits and drawbacks associated with each strategy. The microcontroller system has been chosen to minimize the learning curve for the students in such a way that they are mostly concerned with acquiring and representing the appropriate signals from the system as well as experimenting with changing the parameters of the system in each case. Keywords closed loop; control systems; derivative gain; integral gain; microcontroller; open-loop; proportional gain Engineering technology students benefit from intense and meaningful experimental activities that give them the necessary technical skills and perspective to complement the concepts developed in lectures. Experimental learning is especially important in courses which, because of their strong theoretical and mathematical content, cause students to focus on equations rather than on acquiring a broad vision of the subject matter. The author s experience of teaching on a Baccalaureate degree in an Electrical Engineering Technology program is that Control Systems is one such type of course. We need to place a strong emphasis on experimental learning as a tool to give the students a breadth of perspective regarding the varied and very different applications of control systems as well as the necessary content depth for them to master its critical concepts. Simulation packages are routinely used by some academic programs as a method to incorporate experimental learning in this type of course by simulating the behavior of complex systems. However, although useful, simulation activities by themselves are not enough to give students a solid understanding of the complexities and variables that must be considered when dealing with dynamic systems. They may also contribute to make students lose some perspective on reality. There is also evidence that shows how students have serious difficulties in transcending the understanding of a system s functioning toward more formal definitions of the control process. 1 For these reasons is important to develop educational activities that will help students master these difficult concepts, in particular hands-on experiments. 2 Previous work in developing meaningful laboratory experiences in control systems course describe the use of spreadsheets to simulate Proportional- Integrative-Derivative (PID) control, 3 magnetic levitation systems, 4 and the use of http://dx.doi.org/10.7227/ijeee.51.1.4
44 A. Lozano-Nieto microcontrollers for specific areas of control systems 5 or even developing a microcontroller-based circuit as the main control system. 6 The goal of this paper is to contribute to the body of experimental learning in this type of course by sharing the author s experiences in developing a series of microcontroller-based experiments to expose students to the basics of PID control. These are the first experiments using microcontrollers that we have used in our Control Systems course. Past experiences were focused on both simulations and the use of analog feedback loops. Because of timing reasons, the current syllabus for the course does not cover PID control, so these experiments also serve to give the students a basic understanding of these control methods. When students take the Controls System course they have already taken an introductory course on microprocessors and microcontrollers and are somewhat familiar with their functionality. Furthermore, because a large number of students choose to incorporate a microcontroller in their capstone (final year) design project, this course helps them to gain a deeper knowledge of these systems. One final reason to incorporate a microcontroller for these experiments is that a large number of graduates from our program use microcontrollers in their professional careers, thus contributing to their overall success. The microcontroller-based experimental platform The experimental platform used in these experiments is based on the Basic Stamp system manufactured by Parallax Inc. These boards are based on a PIC microcontroller manufactured by Microchip to which Parallax has added external memory, input/output control and devices as well as a programming language very similar to BASIC. We have chosen the Basic Stamp modules as they provide a simple and integrated platform to change the parameters of the PID system as well as record that data acquired. This module has a total of 16 input/output ports that are more than sufficient for these purposes. The Basic Stamp modules interpret coding without being first compiled. This means a large amount of CPU time is being used in reading instructions. In an industrial setting it would be necessary to migrate the application to a single microcontroller system with compiled code in order to reduce the execution times as well as the costs associated with the hardware of the system. However, the Basic Stamp modules present the advantage of using a very simple programming language and a very easy input/output interface. This fact allows students to learn how to operate them very quickly, moving the focus away from the intricacies of the microcontroller to the subject matter of control systems. In this course, students are given the code as well as an explanation of how it works. Their interaction with the software is focused on changing the values of the diverse parameters of the PID system and acquiring and recording its output. This allows students to evaluate the effects of their changes on the system output. The goal of the experiments described in this paper is to maintain a specific environment at a constant temperature, compensating for several disturbances introduced
Microcontroller-based control course 45 in the system. In these experiments, the environment is a film canister that has been chosen because its small size results in faster temperature changes. One of these elements is a resistor used to increase the temperature inside the canister due to the power dissipated and the second one is a temperature sensor. The heater consists of a 47 Ω resistor using a bipolar transistor to switch it on or off. The base of the transistor is connected to one of the microcontroller I/O pins for control. The temperature sensor is the LM34 from National Semiconductor that has a sensitivity of 10.0 mv/f. 7 The output of the temperature sensor is connected to an ADC 0831 Analog-to-Digital converter. 8 Pins 1 and 3 of the ADC0831 A/D converter are controlled by the Basic Stamp module providing the device with the adequate clock and chip select signals. The output of the converter is also connected to the Basic Stamp module. Students are presented with the schematic shown in Fig. 3 and the specifications of the ADC. First, they are asked to set the values of the two potentiometers for the control system to be able to regulate temperatures between 70 F and 120 F. The ADC0831 is a differential converter, converting the voltage difference between pins 2 and 3. Therefore, because the lower desired temperature range is 70 F that corresponds to 700 mv, a voltage of 700 mv in pin 3 produces a converter output of zero. This pin is used to adjust the lower temperature to be converted. Pin 5 is used to adjust the conversion span. In order to reach a highest temperature equal to 120 F that corresponds to a temperature span of 50 F, the voltage at pin 5 must be equal to 500 mv. Disturbances are created by using a small fan placed directly across the canister that can switched on or off manually or through a control signal from the microcontroller. Experimental work The experimental work for the students is divided into two parts. In the first part, the control system is configured as an open-loop system. This part also serves for the students to become familiar with the microcontroller and its environment as well as to establish a baseline on the system that will be controlled by characterizing the system. The second part is focused on studying the different strategies for closedloop control and learning the benefits and drawbacks for each strategy. Open-loop and system characterization This first set of experiences is focused on characterizing the open-loop response of the system when the control system is operating in open-loop. These experiences are also aimed towards familiarizing the students with the microcontroller, its software and the data acquisition and plotting interface. Figure 1 shows a typical temperature plot obtained for these initial experiments. In addition to the temperature behavior, the display also shows the status of the heater either on or off. In addition to the graphical information, the display shows the current temperature value (Last Analog Data on the right side of the display), and the Maximum and Minimum temperature values. The time information is presented in arbitrary units that, once the students have accounted for the delays specifically introduced by the software,
46 A. Lozano-Nieto Fig. 1 Display presented to students showing temperature versus time as well as the status of the heater. can be easily converted to seconds. Students are also given the possibility to save the data to a file by checking the box located in the left hand side of the graph. After successfully completing this part, students are asked to answer several questions regarding the system. The following are examples of the type of work and questions presented to the students: Using the graph of temperature, calculate the time constant of this system (Wait until the temperature has stabilized and consider the loop delays). After the temperature has reached a stable value, turn the heater off and calculate the time constant of the system as it cools off. Compare the two time constants. Comment on your fi ndings. Remove the lid of the fi lm canister. Repeat the previous measurements. Comment on the differences between the system with and without the lid. Comment on the heat losses in both cases. The previous experiences have been carried out with the heater being constantly ON. It is also possible instruct to the microcontroller to regulate the amount of current injected into the heating resistor by using a Pulse-Width Modulator (PWM) approach. In the next experiment, students are asked to modify the appropriate
Microcontroller-based control course 47 Fig. 2 Students can evaluate the effect of disturbances (electric fan) on the temperature of the system and extract parametric information. parameter in the microcontroller code to change the duty cycle of the PWM signal from 0% to 100% at 10% intervals. They are also asked to construct a table with the stabilized temperature of the canister with the lid on for each one of the duty cycles being tested. Given that the course is part of an Electrical Engineering Technology program we also ask students to measure the duty cycle directly on the appropriate pin of the microcontroller and compare it to the desired duty cycle. The last part of this first set of experiences is focused on evaluating the response of the open- loop system to external disturbances. In this case, students are asked to set the duty cycle to achieve a specific temperature value. After the system has stabilized, they place the fan two inches away from the canister turning it on. The fan acts like a disturbance by removing heat from the system from which it cannot compensate as shown in Fig. 2. This gives students the opportunity to experience the limitations of open-loop systems. Strategies for closed-loop control During the previous experiments, students have experienced the inability of an openloop control system to compensate for disturbances. Compensation for disturbances requires a closed-loop system that takes into account information about the state of
48 A. Lozano-Nieto the output when generating the command signal. In the following experiments students are exposed to three different strategies for closed-loop control in increasing complexity. These are: Simple ON-OFF control ON-OFF control with hysteresis PID (Proportional-Integral-Derivative) control Simple ON-OFF control is a straightforward control method. It is based on turning the heater ON or OFF depending on whether the measured variable is above or below a value that is normally called setpoint. First, students are asked to choose a setpoint within the temperature range for the system and program it into the software used for this control approach. In the absence of disturbances they record a graph similar to the one shown in Fig. 3. The temperature plot shows an initial temperature increase due to the heater being on until the system reaches its setpoint. Afterwards, the heater enters a period of rapid fluctuations between On and Off that is also reflected in fast temperature changes. During these measurements, students are asked to answer several questions regarding this control approach. These are: Explain the behavior of the system with this control approach. Do you see fast changes? What may cause them even in the absence of external perturbations? Fig. 3 Simple ON OFF control showing fast cycling in heating element.
Microcontroller-based control course 49 What are the maximum and minimum temperatures for the system after it has reached its setpoint? (Analyze the data fi le collected by the plotting software). Can you relate the behavior of this control approach to using a simple Op-Amp based comparator? Explain the advantages and drawbacks of this type of control. When would you use this type of control? The next step involves the creation of external disturbances by once again placing the fan at a distance of two inches away from the canister and turning it manually. After repeating the procedure from the previous exercise, students have to respond to the following questions: Is the system able to reach the desired setpoint while there is a disturbance? Measure again the maximum and minimum temperatures with the disturbance affecting the system. Compare it to the case without disturbances. Describe your observations, in particular the ability of this control approach to compensate for disturbances. After evaluating the performance of the Simple ON-OFF control strategy, students are introduced to the ON-OFF with hysteresis control approach. They choose two setpoints, one above the original setpoint and one below it. The software for this control mode allows the students to change the two setpoints in order to experiment with different values. After experiencing the response of the system with and without external disturbances, students can answer the following questions: In the absence of disturbances, compare the behavior of the system with and without hysteresis. Comment on the effect of increasing the distance between the two setpoints. What are the benefi ts and drawbacks of increasing this distance? Once the system has stabilized, introduce a disturbance using the fan. Keep it for some time and then remove it. Compare the behavior of the system affected by the disturbance with how it was affected without the hysteresis. What can you tell about an ON-OFF control with hysteresis? When would you use it? The final control strategy studied in these laboratory experiments is PID control. It is necessary to mention once again that the goal of these activities is not an in-depth study of PID control but rather to give a practical and basic introduction to this control approach. The microcontroller software used for these activities allows students to change the values of the proportional gain (K p ), integral gain (K i ) and differential gain (K d ). First, students are asked to set up the control system keeping the three gains at zero (K p = K i = K d = 0) and observe its response. They should recognize that this is the same as operating in open-loop. The second step involves studying the behavior of the system using only proportional control. Students experiment with several values for K p while keeping both the integral and derivative gains to zero (K i = K d = 0). Figure 7 shows a temperature plot obtained in these circumstances that is used
50 A. Lozano-Nieto for the students to realize that a proportional-only control strategy needs an error signal in order to achieve the correct temperature. However, the presence of the error signal means a departure from the setpoint, thus giving origin to the oscillations around the setpoint shown in Fig. 4. The final experiences for proportional-only control involve studying the effects of both long-term and short-term external disturbances. Students need to answer the following questions for this control strategy: Comment on the temperature graph that you have obtained. Is your system able to reach and maintain its setpoint temperature? What is the (average) temperature at which your system settles? Explain the oscillations that you see in your graph around the setpoint. Does the system respond differently for short-term and long-term disturbances? Comment on your fi ndings. The experiments continue with a short introduction to integral control, especially focused on how this type of control is used to compensate the shortcomings from proportional-only control. For different values of proportional gain (K p ) and integral gain (K i ) while keeping the derivative gain at zero (K d = 0), students evaluate the response of the system with and without disturbances. In addition to being able to change the values of proportional and integral gains it is possible for the students to experiment with different values for the integration period. They can also experiment with the response of the system after the disturbance has been removed by 97 Target: 96 F 96 95 94 93 92 91 90 89 1 7 13 19 25 31 37 43 49 55 61 67 73 79 85 91 97 103 109 115 121 127 133 139 145 151 157 163 169 Fig. 4 Effects of proportional control on the hearing system. Vertical axis is temperature in degrees C; horizontal axis shows time event.
Microcontroller-based control course 51 turning the fan off as shown in Fig. 5. After these experiences students are asked the following questions: Comment on the temperature plot obtained with this control strategy, especially the differences with previous strategies. How long does it take for the temperature of your system to reach a value close to the setpoint? Explain the effect of the integration interval (T i ) on the settling time. What happens if we increase and/or decrease the integration interval? Relate the temperature overshoot after removing the disturbance with the values of K i, K p and T i. Do the same for the settling time after removing the disturbance. The final set of experiences introduces the derivative gain to the previously used proportional and integral gains in order to create the full PID control system. Following the approach to studying the response of the system from previous experiences, students are now asked to create their own set of experiments to characterize the behavior of the PID control system. They are also asked to develop the appropriate methods to characterize the response of the PID control system to long-term and short-term disturbances. Students must also extract meaningful conclusions about this control method as well as its benefits and potential drawbacks. Temp - remove fan. SP = 86F 92 90 Gp = Gi = 0.1 Remove Fan after temp. stable (point 109) 88 86 84 82 80 78 1 12 23 34 45 56 67 78 89 100111122133144155166177188199210221232243254265276287298309320331342353 Fig. 5 Effects of proportional-integrative control. Students can evaluate the response of the heating system to a disturbance. In this case, the fan used to remove excess heat was turned off at data point 109.
52 A. Lozano-Nieto Conclusion This paper has described a set of laboratory experiences designed to expose students enrolled in a control systems course to different control strategies. We developed these activities for students to interact with a physical system rather than a mathematical model. This is achieved, in part, through using a simple microcontroller as the central element in the control system. These activities are also designed so they can be expanded in order to include further data and signal processing, datalogging or similar approaches. We have run these experimental activities for two semesters. The feedback from students has been very positive, indicating that not only do they like this type of approach but they feel that their understanding of the big picture in control systems has improved. They also value the fact that these experiments include concepts from previous courses such as microcontroller, analog electronics, data processing, etc. We can state that student response has, in general, been satisfactory. We have measured this by indirect methods such as student surveys as well by direct methods focusing on the specific learning outcomes of this course. In particular, the course contains a specific learning outcome on students being able to conduct experiments and evaluate their results as applied to control systems. This outcome, in turn, supports the outcome for the academic program that is focused on supporting experimental learning. While this paper is not primarily concerned with assessment methods for the course or the program, it is important to note that the introduction of these laboratory experiments has increased student performance in their ability to conduct experiments and interpret their results. We believe that students feel more comfortable with using systems in which they already have experience such as microcontrollers rather than analog feedback loops. The activities described here are a basic approach to the use of microcontrollers in the control systems laboratory in electrical engineering technology programs. The author hopes that other faculty members teaching similar courses will follow on them and will share their experiences in different forums to build a body of knowledge and best practice for these courses. References 1 I. Levin and D. Mioduser, A multiple-constructs framework for teaching control concepts, IEEE Trans. Educ., 39(4) (1996), 488 496. 2 A. Leva, A hands-on experimental laboratory for undergraduate courses in automatic control, IEEE Trans. Educ., 46(2) (2003), 263 272. 3 K. K. Tan and H. Goh, Development of a mobile spreadsheet-based PID control simulation system, IEEE Trans. Educ., 49(2) (2006), 199 207. 4 A. Lozano-Nieto, Magnetic levitation experiments for a control systems course in an electrical engineering technology program, The Technology Interface Journal, 10(1) (2009). 5 M. T. Hagan, A microcomputer-controlled experiment: root locus design, IEEE Trans. Educ., 27(2) (1984), 79 85. 6 A. Kulatunga and R. Muir, Embedded controller development for closed-loop process control learning, The Technology Interface Journal, 9(2) (2009).
Microcontroller-based control course 53 7 National Semiconductor LM34 Precision Fahrenheit Temperature Sensor. Available at http://www. national.com/mpf/lm/lm34.html#overview, last accessed April 2013. 8 National Semiconductor AD0831 8-Bit Serial I/O A/D Converter with Multiplexer Option. Available at http://www.national.com/mpf/dc/adc0831.html#overview, last accessed April 2013.