Copyright © 19961FAC 13th Triennial World Congress. San Francisco, USA
4c-034
LABORATORY IN DISTRIBUTED MICROPROCESSOR CONTROL
Peter H. Meckl, Daniel Maguire, and Galen King
School of Mechanical Engineering Purdue University West Lafayette.IN 47907·1288 E-mail:
[email protected]_edu
Abstract: This paper describes the laboratory facilities for a course on Microprocessors in Electromechanical Systems. This course is designed lo introduce mechanical engineers to basic concepts of microprocessor architcctures, programming, and interfacing, with special focus on implementation of digital controllers for real-world electromechanical systems. Laboratory facilities at each lab station include a Pentium-based PC for code development and an 8018B·based single board computer (SBC) for real-time embedded control. Since both the PC and the SBe have their own analog JJO capabilities, true distributed control is possible. with the PC acting as process monitor. plant simulator, or control supervisor. capable of down loading new controller selpoints to the SBC as process conditions change. Keywords: Laboratory techniques, Microprocessor control, Distributed control
1. INTRODUcnON
2. COURSE OVERVIEW
With the advent of the microprocessor in 'he 1970's. the number of products incorporating electronic control has proliferated_ Even traditionally mechanical systems, such as automotive engines. have been impacted by the unique capabilities of microprocessor-based control systems_ In today's environment, it is vital that mechanical engineers be exposed to the fundamentals of microprocessor prograrruning and electronic control. For over a decade, the School of Mechanical Engineering has offered a course in Microprocessors for Electromechanical Sysrems to both undergraduate and graduate students. That course has effectively introduced mechanical engineers to the programming and interfacing of microprocessors for control. Laboratory enhancements have brought this course by introducing powerful single· board up·to·date microcomputers that work together with personal computers to establish a true distributed control environment.
The current course on microprocessors in electromechanical systems (ME 586) focuses on the·use of microprocessors for control system implementation. The lectures and laboratory assignments have been designed to satisfy the following three objectives: (I) provide a basic knowledge of microprocessors, their architecture, and their programming; (2) provide the tools for inlerfa(;ing microprocessors with peripheral devices, including digital I/O, analog I/O, and serial conununication; and (3) provide experiences in utilizing microprocessors for real-time measurement and control. Although this courst: is a graduate course, undergraduates are encouraged La participate. Thus. both lectures and laboratory a!;signments have been designed to provide the necessary background to make sure that both undergraduates and graduate , students make similar progress. Supplementary references arc provided as necessary.
2981
been mounted inside a box. One board contains the 16 MHz Intel 80188, along \\ith facililies for serial communication via an RS·232 connection, an 8255 for digilal UO, a Monitor ROM thal permits downloading and debugging assembly code. and RAM memory for sloring code and data. The second hoard includes an analog mulliplexer for up to 8 channels of analog input, a MAXIM analog-to-digital converter, and two MX7542 digilal-toanalog converters. Special op-amp circuitry on the analog inputs permits scaling and buffering of analog inpur signals.
Since mechanical engineering curricula typically do not include courses on digital logic circuits, assembly language progranuning. and microprocessor interfacing, this course is designed to introduce these topics to mechanical engineers. In this way, they can develop their expertise for implemenLing microprocessor-based controllers toward the end of the semester, without having to take several courses that cover these topics in depth in the electrical engineering department. The ultimate goal is to have the students with control actual electromechanical systems microprocessors.
One of the features of the 80188-based microcomputer boards is Ihe ability to be programmed in C, the programming language of choi:e for embedded control applications. A new software package by Paradigm permits compiled C code to be downloaded to Ihe 80188 microcompuler board and remotely debugged from the PC. Thus, the capabilities and programming ease of a high-level language like C is coupled with the embedded conlrol environment provided by stand-alone processors.
Lectures have been designed to introduce students to various basic concepts that are crucial to prograrruning and interfacing with microprocessors. These topics include digital logic, microprocessor architecture. assembly language programming, digital I/O, serial communication, interrupts, and analog-to-digital conversion. [n addition, since not all students have the same level of control back.ground. some le<:tures are devoted to fundamentals of classical control design, including PlO gain selection, integrator windup. and digital implementation. Since actuators and ScnsO~ represent a vital connection between the microprocessor controller and the system to be controlled, some time is devoted to a discussion of stepper motors and drivers, incremental optical encoders for position measurement, and issues of digital sampling and aliasing.
In the laboratory, students use the Pes for software development and user interfa.;es for their embedded conlrollers. They use the KOl88-based single-board microcomputers for interrupt-driven programming and implementation of most of their (;ontrol schemes. With the expansion board, which contains both analog-ta-digital and digital-ta-analog converters. the single-board microcomputer can be used as ~I stand-alone processor to control a variety of electromechanical systems. The singleboard microcomputer is an excdlent vehicle to introduce students to the lowest levf.1 of real-time control progranuning, providing the ability to "burn" program code inlo an EPROM (Erasable Programmable Read-Only Memory) for direct control of the microprocessor. As such, it represents an analog of the typ: of stand-alone electronic control module found. for example, on automotive engines.
3. MICROPROCESSOR CONTROL LABORATORY The microprocessor laboratory complements the lectures by providing hands-on experiences for learning the course concepts. Students have opportunities to actually build circuits and to program microprocessors to achieve desired control objectives. The laboratory includes 12 stations, each of which consists of a personal computer with data acquisilion board. an 801 88·based single-board microcomputer with its own analog I/O capabilities, a DigiDesigner proto-board, and an oscilloscope. In addition, a variety of digital logic chips and discrete electronic components are available.
All students perform the first six labs, which are designed to introduce the fundamentals of microcomputer hardware, software, and interfacing. After that, students are free to select three projects from a list of different electromechanical project setups. These include a two-link. robotic manipulator, a de notor speed control, a heating/cooling system, an inv1:rted pendulum, a fourcylinder air-driven engine, and a (;ontrollable refrigerator.
The personal computers (from Micron) are based on the 100 MHz Inlel Penlium microprocessor. with 16 MB of RAM, 1.2 GB hard drive, and 3.5" floppy drive. All res are interconnected on a local area network (LAN). and have access to an HP LaserJet 4 laser printer. In addition, the LAN is connected to the engineering-wide computer network so that students have access to their "home" computer account, where they can create and store files.
In the first laboratory assignment, students are acquainted with the hardware and software I!nvironment that they will he using for the semester. Even though they have not yet been exposed to assembly lan~:uage progranuning, it is essential that students become ff.miliar with the Microsoft MASM 6.11 programming environment thal they will be using for the rest of the seme.:;ter. Thus, students are provided with a panial assembly program. with a listing of
Tht:: 80lg8-based single-board microcomputers (from Midwest Micro-Tek) each consist of two boards that have
2982
Monitor program. Their task this week is to convert their earlier assembly program to a ·~orm that will run on the SBC. Most of the required "hanges have to do with segment assignment and the location of the data. Once these changes have been made, students can assemble and link their code using MASM 6.1 : as before. However, one finaJ step is required to generate executable code on the SBC; they must use the MMTLOC program, provided by Midwest Micro-Tek, to reconeil€ any relocatable addresses and to generate a HEX file that contains the actual ASCII representation of the code to be downloaded to the SBC. Once in this form. they can usc the Monitor to down load the code directly to the RAM on the SBC and then run the code_ A fina1 task is to write a progr"m that mimics the digital logic circuit that was wrinen in Lab 2. In this way, it exeroises their ability to handle digital 110 with Ihe 8255 chip.
what the completed code should look like. They then use the editor within MASM 6.11 to finish typing up the assembly code. Once they set the required options for " building the project," they compile and link their program. If any errors occur, they can ask for "Next Error" in the Project menu , which takes them right back to the editor, with the cursor positioned at the code statement where the error occurred. Once they get an error~free executable file, they can run the program directly, or trace through its execution within Code View to debug their logic. All steps of the program development process are integrated within MASM 6.11 as one seamless software system. In the first lab, students also become e1tposed to Microsoft Visual Basic progranuning. a tool that they will use as the primary graphical user interface on the PC side for interacting with the 80188 single-board computer. In this first exposure, students learn how to set up visual interfaces for input and output, how to set the properties of these controls and screens, and how to write code that dictates how inputs are used to generate the outputs. Eventually, they will tie the inputs to the serial line so Ihat they can be used as setpoints for their microprocessor-based controller, and tie the outpUt.Ci to the serial line so that important sensor information can be sent to the PC for graphical display.
#4 focuses on serial Laboratory Assignment communication. The ultimate objective is to link the SHC with the PC via the serial line so that programs can exchange infonnation in both din~cti.ons. This is a valuable contribution, since eventually. students will be programming their SBC to perform real~tirne control while the PC is configured as a user interface to send setpoints and display signals. Initially. students use the BIOS and DOS functions on the PC to establish serial communication and to organize their screen displays. However, having been exposed lO Visual Basic, tbey are also encouraged 10 develop more sophisticated graphical user interfaces on the PC usi ng Visual Basic. On Ihe SBC, they use serial routines accessible via the Monitor program to minimi ze the amount of additional programming required.
The second laboratory assignment focuses on digital logic circuits, both combinational and sequential. It is designed to expose students to [he fundamental binary operations that take place in the heart of the microprocessor. First, students are asked to build simple half-adder and full-adder circuits out of TTL logic devices to construct a 4-bit adding machine. They also build a logic circuit that sets several different outputs, depending on whether two binary input numbers are equal. even or odd, or positive or negative. Finally. they use several NOR gates with feedback to construct an SR flip-flop. which they tnen use to construct a memory register.
Laboratory Assignment #5 expcses students to interrupts and interrupt programming. Students use a clock signal of varying frequencies as an extenal interrupt input lO the Sac. Thcy develop an interrul>' service routine (hat, at each cycle of the external clock, increments a counter. An internal timer, set to a specified frequency. generates another interrupt, which instructs the processor to store the counter associated with the external clock signal. The number of counts divided by the time programmed into the timer gives the external clock fr~uency. This lab illustrates the ability to use external events to alter program exec ution, and develops the programming skills necessary (0 establish interrupt-driven timing for real-time control.
Laboratory Assignment #3 introduces students to assembly language programming. Since both the Pentium and the 80188 are based on Ihe 8086 processor, basic 8086 code is used as the medium to teach assembly programming. During the first week, students look at some simple code, perform a program assembly and disassembly, and become familiar with the operations associated with several inslructions using different addressing modes. They use CodeView within the MASM 6.11 environment to examine the microprocessor registers before and after each operation. They are [hen asked to write a simple program that takes a set of integers and finds the average. This program is to run successfully on the Pentium PC.
Laboratory Assignment #6 introduces students to anaJog-todigital (ADC) and digitnJ-to-ar.alog conversion (DAC). After building a simple 4-bit DAC, students use the digital inpul on the SBC together with the DAC to develop a counting (or successive approxir!l.ation) ADC. Once they understand the hardware associated with analog/digital conversion. they write assembly routines on the SBC to
During the second week, students learn about the 80188h.sed single-hoard e<>mpuler (SBC) and its associated
2983
access ilS own ADC and DAC. These routines then serve as building blocks for writing control code for the eleClromechanical projeclS.
the unstable dynamics of the inverted pendulum while ensuring that the cart does not run off the ends of £he track. The four-cylinder engine represents a table-lOp model tbat operates on shop air. A computer-conLIolled valve regulates the air pressure to the individual :ytinders so as to maintain desired speed. A de generator, mounted to the engine cranksbaft, can be used as a dynamometer to absorb varying loads from the engine. The objective of the project is to adjust tbe air valve so as to mairltain speed in the presence of torque disturbances from the generator, The challenge is lhe friction associated with the valve, typically requiring that students add a local feedback loop around the valvc itself to ensure reliable operation.
Once all six of these labs have been completed, students begin their selected projects. Each setup is an electromechanical system, comp1ete with required sensors and actuators, Most of the interfacing circuitry has already been incorporated to allow students to focus on real-time control programming. Each system has inherent nonlinearities that must be addressed during control design and implementation. For each project, students must calibrate the sensors, perform some system identification to ubtain approximate system models, design a suitable controller, and finally, implement their controller using the 80188 mieroproce.'i\.c;;or and its associated data acquisition board. Students are encouraged to use timer interrupts to establish a uniform sample rate at which to run their digital controllers.
The controllable refrigerator is cl conventional refrigerator compres.c;;or, condensor. and (:oil, but which uses a computer-operated valve in place of the capillary tube. In this way, the flow of coolant c~ n be controlled so as to achieve maximum efficiency while maintaining desired cold temperatures. Several temperature and pressure sensors are distributed throughout the coolant circuit. Students must decide which of the sensors to USt: to achieve their feedback control strategy.
A brief description of several of the projects follows. The two-link robotic manipulator has a cylindrical base joint that allows rotation about a venical axis and a second rotational joint that permits motion in a vertical plane. Both axes are dri ven by stepper motors. Students must develop the appropriate open-Loop commands to the stepper motors to achieve a desired trajectory. In addition, they must coordinate the motions of the two axes to ensure that the desired trajectory is followed accurately.
4. DISTRIBUTED CONTROL Since the 80188 microcomputers, with associated expansion boards, have the capability of acquiring and generating analog signals, they can be used as stand-alone processors to do all of the real-time control functions for a variety of electromechanical systems. The PCs are used to develop and debug Ihe embedded control ~ ode and down load il onto the microcomputer boards. The resulting configuralion, shown in Figure I, demonstra es the design of fixed embedded conlTollers.
The dc motor includes an incremental optical encoder that generates a pulse ttain as function of angular rotation. Students must develop the software to convert this signal to a velocity measurement. and then must develop a suitable control scheme to maintain motor speed in the presence of torque disturbances. The heating/cooling system represents a simple model of a heating, ventilating, and air-conditioning system that would be used in a commercial building. A resistance heater is used to heat up a small aluminum block, while a small computer fan is used to achieve cooling. Both actuators only work in one direction; the heater only heats, while the fan only cools. Thus, students must develop a strategy that uses the temperature of the block as single input to determine the action of the two different actuators. Students must achieve desired temperature settings while minimiz.ing encrgy consumption.
Once the control code is resident on the single-board microcomputers, the pes are available for 8 variety of other purposes, providing a true distributed control environment that can be used Lo illustrate supplementary topics in adaptive control and signal pf(lcessing. The PC could simply act as a user interface, providing setpoints for £he controlling microcomputer and monitoring the outputs. More significantly, the PC codd be used as a system simulator that demonstrates unique capabilities. or a parallel processing computer that can re:onfigure the struclure of the embedded controller in response to various contingencies and disturbances.
The invertoo pendulum is a classic project, consisting of a two· fool rod hinged at the bottom and connected to a movable cart, powered by a dc motor. Potentiometers at the hinge and along the track indicate rod angle and cart po~i(ion. Student,,- must use these two signals to generate an appropriate control strategy for the cart motor that stabilizes
The use of the personal computer to monitor the performance of the stand-alone processor uses the analog· to-digita1 converter of the PC to display or log controller
2984
Gain
S""",,,,, OpefallOg
Condition S,rialLinI
InllrT\lPtLin'
Fig. \. Standard operating configuration for 80188 Slandalone controller and real-world plant. The personal computer, in this configuration. is used as an offline programming unit and downloader. performance. In addition to having more acquisition channels than the laboratory chart recorders, the serial link between the embedded controller and the personal computer provides the ability to coordinate data acquisition to internal states within the controlled plant. When the controller is controlling plants that allow sufficiently low sample rates, (he rc:sults of internal stale (,;alculations can also be uploaded to the personal computer during processing.
Fig. 3. Configuration of gain scheduling controller using a personal computer as tbe adaptation unit and a stand-alone controller as a cOn/rol engine. can then be measured using the PC itself, which is computing the plant output, or a chart recorder connected to an analog output of the PC. This configuration is shown in Figure 2. A third configuration. which was considered in the current design of the laboratory hardware , is the use of the personal computer as a supervisory proc~ssor for adaptation. As examples. both gain schedf4-lillg and model reference adaptive system (MRAS ) adaptive control can be implemented in this manner. Using this configuration. the personal computer acts as a high performance coprocessing system. The personal computer provides the 80188 slandalone conlroller, which is acting 5lrictly as a control engi"e. with improved operating parameters whenever performance degrades away from desired specifications. Using the personal computer as an adaptation unit offioads the computationally intensive adaptation process, reducing the computational delay.
A second possible configuration for the personal computer is to use it to simulate either unique fixed or time-varying plants. The fixed plants simulated with the personal computer may have unstable or highly nonlinear behavior. Personal computers with analog UO can also be easily programmed to implement time-varying plants in which the behavior varies within precise bounds. These plants can, if desired , include fixed or varying time-delays, presenting a genuine challenge to the student of adaptive or robust conlroller design (Forsylhe and Goodall, 1991 ).
The gain scheduling implementa1]on is shown in Figure 3. Using the gain scheduling approach, plant operating conditions or environmental varhbles are measured by the personal computer and used to detennine which of a set of precalculated controner gains or parameters is best. Gain scheduling has been used successfully in systems as diverse as flight control and combustiJn control (Stein. 1980; Kallstrom . el al ., 1979).
In the cases where the personal computer is used as a plant, the student uses an appropriate design method to design either a robust or adaptive controller , The form and parameters of thi s controller are then programmed on [he PC and downloaded to the stand-alone processor. Control is Ihen initiated. The personal computer can now be activated as a "plant." The resulting controller performance
An MRAS control implementation is shown in Figure 4. In this arrangement, the personal computer measures the command input and uses it to cal:ulate the expected output based on a desired internal fixed controller. The desired output is compared to the real measured output and the error is used with the current control dfort to calculate updated controller parameters (Jacobs, 1985; Astrom and WiUenmark, 1995).
Fig, 2. The use of a personal computer as a simulated plant.
2985
changes occur and can down load new controller parameters to the microcomputer 10 ensure desirable perfonnance over the full range of disturbances. Thus, the two computer systems work together, the single-board microcomputer focusing on the low-level control tasks, while the personal computer supervises the process and makes controller changes accordingly.
S.SUMMARY The microprocessor laboratory provides personal computers for program development and stand-alone single-board computers for embedded control applications. By using the single-board microcomputers entirely for real-time control, the Pes are a vailable to monitor the processes and la act as supervisors to reconfigure the embedded controllers. Thus, students develop an appreciation ::or the current state-of-mean in distributed embedded contmJ.
Fig. 4. Configuration of model reference adaptive system (MRAS) controller using a personal computer as an adaptation unit and a stand-alone controller as a
control engine. In either of the above adaptive implementations, when the updated controller parameters have been calculated, the personal computer uses the interrupt line to notify the stand· alone controller. The stand-alone controller then requests updated parameters via the serial link. Once downloaded, control is reinitiated with the revised parameters. Care must be taken so as not to disrupt the real-time control during the update process. Shared memory or incremental downloading can be used to accomplish this.
6. ACKNOWLEIIGMENTS The authors would like to thank the AT&T Foundation for providing a Special Purpose Grant, which allowed the purchase of much of the updated laboratory equipment. In addition, they appreciate the support provided by the School of Mechanical Engineering, in particular its Head, Frank Incropera, who made it possible to develop and implement the new lab.
The use of the personal computer is not limited to these two forms of control. Many methods of system identification and control can be implemented in this manner. These methods include frequency-domain identification and adaptive inverse control (Ljung, 1994; Widrow and Walach, 1996; Widrow and Stearns, 1985). By preprogramming the stand·alone controller to implement down loaded difference equations, the student can concentrate on the design and programming of the adaptive supervisory portion.
REFERENCES Astrom, K. J. and WiUenmark, B. (1995). Adaptive Control, 2nd Ed. Addison-Wesley, New York. Forsythe, W. and Goodall , R.M . (1991). Digital Control. McGraw-Hill, New York. Jacobs, O.L.R. (1985). "Introduc :ion to Adaptive Control." In: Self Tuning and Adaptive Control: Theory and Applications ( HaITis, CJ. and Billings, S.A., (Ed.)), pp. 1-31. Peregrinus, London. Kallstrom, CG., Astram, K.J., Thorell, N.E., Eriksson, J., and Sten, L. (1979). "Adaptive autopilots for tankers," Automatica, 20"p. 241-254. Ljung, L. and Glad, T. (1994) . Modeling of Dynamic Systems. Prentice-Hall, Ennlewood Cliffs, NJ. Stein, G. (1980). "Adaptive 11i:!hl control: A pragmatic view." In : ApplicationJ of Adaptive Control (Narendra, K.S . and MonollOli, R.V., (Ed.», pp. 291312. Academic Press, New York. Widrow, B. and Stearns, S.D. (1985). Adaptive Signal Processing . Prentice-Hall, ·Englewood Cliffs, NJ. Widrow, B. and Walach, E. 11996). Adaptive Inverse Control. Prentice-Hall, Englewood Cliffs, NJ.
A good illustration of this distributed control strategy involves the four-cylinder engine project. In this system. a variable-orifice valve under computer control is used to modul ate the flow of air to the engine. The objective is to maintain engine speed in the presence of torque load disturbances. By monitoring the speed within the feedback loop, the single-board microcomputer can maintain a desired speed for a limited range of torque disturbances. When load torques exceed this range, the inherent nonlinearities present in the engine dynamics cause system performance to significantly deviate from the nominal model for which the original controller gains were determined . The personal computer, by monitoring the change in engine speed with time, can recognize when load
2986