IPE 301
Automation and Control Engineering
Chapter 2
Introduction to Microprocessor Based Control
Introduction
The digital integrated circuit (IC) called a microprocessor
[Figure 1(a)], has ushered in a whole new era for control
systems electronics. Microprocessor-based control
systems are rapidly replacing many older control systems
based on analog circuits or electromechanical relays. A
microprocessor by itself is not a computer; additional
components such as memory and input/output circuits
are required to make it operational. However, the
microcontroller [Figure 1(b)], which is a close relative of
the microprocessor, does contain all the computer
functions on a single IC. Microcontrollers lack some of
the power and speed of the newer microprocessors, but
their compactness is ideal for many control applications;
most so-called microprocessor-controlled devices, such
as vending machines, are really using microcontrollers.
Introduction
Some specific reasons for using a digital, microprocessor design in control systems are the following:
• Low-level signals from sensors, once converted to digital, can be transmitted long distances virtually error-
free.
• A microprocessor can easily handle complex calculations and control strategies.
• Long-term memory is available to keep track of parameters in slow-moving systems.
• Changing the control strategy is easy by loading in a new program; no hardware changes are required.
• Microprocessor-based controllers are more easily connected to the computer network within an
organization. This allows designers to enter program changes and read current system status from their desk
terminals.
Figure 2.
Microcontroller
(ATMEL ATMEGA 32)
MICROPROCESSOR SYSTEM HARDWARE
A computer is made up of four basic functional units: the central processing unit (CPU), memory, input, and
output (I/O).
Central Processing Unit
The central processing unit does the actual computing and is composed of two subparts: the arithmetic logic
unit and control sections (Figure 3). The arithmetic logic unit (ALU) performs the actual numerical and logic
calculations such as addition, subtraction, AND, OR, and so on. The control section of the CPU manages the
data flow, such as reading and executing the program instructions. If data require calculations, the control
section hands it over to the ALU for processing. In a microprocessor-based computer, the microprocessor is the
CPU.
MICROPROCESSOR SYSTEM HARDWARE
Memory
The memory section of the computer is a place where
digital data in binary form (1s and 0s) are stored.
Memory consists of cells organized in 8-bit groups.
Each byte is given a unique numeric address, which
represents its location just as a street address
represents the location of a house. Data are written
into memory and read out of memory, based solely on
their address. In a particular memory circuit, the
addresses might start at 1000 and run consecutively to
2000. Figure 4 diagrams a section of memory. Note that
the first byte of data has a decimal value of 2
(00000010 = 2 decimal) and an address of 1000.
MICROPROCESSOR SYSTEM HARDWARE
Memory
Computers usually have two kinds of addressable memory. The first is random access memory (RAM), which
allows the computer to read and write data at any of its addresses (it is also called read/write memory, or
RWM). All data in this type of memory are lost when the power is turned off and is called volatile memory (an
exception is designs where RAM is kept “alive” with a small battery). The second type of memory is read-only
memory (ROM), which is similar to RAM except that new data cannot be written in; all data in ROM are loaded
at the factory and cannot be changed by the computer. This memory does not lose its data when power is
turned off and is called nonvolatile memory. Most microprocessor systems have both RAM and ROM. RAM is
used for temporary program storage and as a temporary scratch-pad memory for the CPU. ROM is used to store
programs and data that need to be always available. Actually, many computers use an EPROM (erasable
programmable read-only memory) or an EEPROM (electrically erasable programmable ROM) instead of a ROM
for long-term memory. EPROMs can be erased with a strong UV light and reprogrammed. EEPROMs can be
erased and reprogrammed electrically. Disk drives also store digital data but in a form that must be processed
before they are accessible to the microprocessor.
MICROPROCESSOR SYSTEM HARDWARE
Input/Output (I/O)
The input/output (I/O) section of the computer allows
it to interface with the outside world. The input
section is the conduit through which new programs
and data are entered into the computer, and the
output section allows the computer to communicate
its results. An I/O interface is called a port. An input
port is a circuit that connects input devices to the
computer; examples of input devices are keyboards,
sensors, and switches. An output port is a circuit that
connects the computer to output devices. Examples of
output devices are indicator lamps, actuators, and
monitors.
MICROPROCESSOR SYSTEM HARDWARE
Referring again to Figure 3, we see that the blocks are connected by three lines labeled address bus, data bus,
and control bus.
Address Bus
The address bus is a group of wires that carries an address (in binary form) from the CPU to the memory and
I/O circuits. The need for memory to receive addresses has already been discussed, but you may wonder why
I/O ports need addresses. It turns out that all I/O ports are assigned addresses and are treated essentially like
memory locations by the CPU. The CPU outputs data to the outside world by sending them to a port address.
When the circuitry of the designated output port detects its assigned address on the address bus, it opens and
allows data to pass from the data bus to whatever is connected to the port. There are two ways that I/O
addressing is done. Some microprocessors use what is called memory-mapped input/output, where an I/O
address is treated just like another memory address. Other microprocessors treat I/O addresses completely
separate from memory addresses.
Data Bus
The data bus is a group of eight wires that carries the actual numerical data from place to place within the
computer. Figure 3 shows how the data bus interconnects all blocks. Data flow in both directions on the data
bus. For example, input data enter through the input port and proceed through the data bus to the CPU. If the
CPU needs to store these data, it will send them back through the data bus to memory. Data to be outputted
are sent (by the CPU) through the data bus to the output port.
MICROPROCESSOR SYSTEM HARDWARE
Data Bus
If the data bus connects to all blocks, how do the data know which block to go to? The answer is the address
system. For example, when the CPU sends data to memory, it does it in two steps: First, it puts the destination
memory address on the address bus; second, it puts the data on the data bus. When the designated memory
detects its own address, it “wakes up” and takes the data from the data bus. The other blocks connected to the
buses will ignore the whole sequence because they were not addressed. A good analogy here is the phone
system, where the phone number is analogous to the memory address. Even though thousands of phones may
be connected to the system, when you dial a number, only the designated phone rings. The beauty of the bus
system is that it is expandable. Memory or addressable I/O units can be added to the system by simply
connecting them to the buses
Control Bus
The control bus (see Figure 3) consists of timing and event-control signals from the CPU. These signals are used
to control the data flow on the data bus. For example, one of the control signals is the read/write (R/W) line.
This signal informs the memory if the CPU wishes to read existing data out of memory or write new data into
memory. Non-memory-mapped machines have a memory-I/O control line. This signal informs the system if the
current data exchange involves memory or an I/O port. In general, the control bus is not as standardized as are
the address and data buses.
INTERFACING TO A MICROPROCESSOR CONTROLLER
An important part of any control system is the link between the controller and the real world. For a digital
controller, data enter and exit through a parallel interface or through a serial interface.
The Parallel Interface
The parallel interface transfers data 8 bits (or more) at the same time, using eight separate wires. It is
essentially an extension of the data bus into the outside world. The parallel interface is ideal for inputting or
outputting data from devices that are either on or off. For example, a single limit switch uses only one input bit,
and an on-off signal to a motor requires only one output bit. These 1-bit signals are called logic variables, and
eight such signals can be provided from a single (8-bit) port. This concept will be expanded on later in this
section. In other applications, the controller may use a parallel interface to connect to an analog device—for
example, driving a variable-speed DC motor. In such a case, the binary output of the controller must first be
converted into an analog voltage before it can drive the motor. This operation is performed by a special circuit
called a digital-to analog converter.
INTERFACING TO A MICROPROCESSOR CONTROLLER
Digital-to-Analog Conversion
The digital-to-analog converter (DAC) is a circuit that converts a digital word into an analog voltage. It is not
within the scope of this text to describe the internal workings of the DAC, but a general understanding of the
operating parameters is appropriate. Figure 2.5 shows the block diagram of a typical 8-bit DAC. The input is an
8-bit digital word. The output is a current that is proportional to the binary input value and must be converted
to a voltage with an op-amp. A stable reference voltage (Vref) must be supplied to the DAC. This voltage
defines the maximum analog voltage—that is, for a digital input of 11111111, Vout is essentially Vref. If the
input is 00000000, the Vout will be 0 Vdc. For all values in between, the output voltage is a linear percentage of
Vref.
Specifically, the output voltage for any digital input
(for the 8-bit DAC) is
where
Vout = DAC output analog voltage
input = decimal value of the binary input
Vref = reference voltage to the DAC
INTERFACING TO A MICROPROCESSOR CONTROLLER
Digital-to-Analog Conversion
INTERFACING TO A MICROPROCESSOR CONTROLLER
Digital-to-Analog Conversion
INTERFACING TO A MICROPROCESSOR CONTROLLER
Analog-to-Digital Conversion
An analog-to-digital converter (ADC) is a circuit that converts an analog voltage into a digital word. A typical
ADC consists of a single IC with a few support components. Analog-to-digital conversion is a more complicated
process (than for the DAC), and the hardware requires some conversion time, which is typically in the
microsecond range. The conversion time required depends on the type of ADC, the applied clock frequency,
and the number of bits being converted. Figure 2.7 shows a block diagram for an 8-bit ADC. The input Vin can
be any voltage between 0 V and Vref. When Vin is 0 Vdc, the output is 00000000; when Vin is Vref, the output is
11111111 (255 decimal). For input voltages between 0 and Vref,, the output increases linearly with Vin;
therefore, we can develop a simple ratio for the ADC:
Solving for output gives the following:
where
output = decimal output value of an 8-bit ADC
Vin = analog input voltage to the ADC
Vref = ADC reference voltage
INTERFACING TO A MICROPROCESSOR CONTROLLER
Analog-to-Digital Conversion
INTERFACING TO A MICROPROCESSOR CONTROLLER
Analog-to-Digital Conversion
INTERFACING TO A MICROPROCESSOR CONTROLLER
A Control System Using Parallel Ports
Figure 2.9 shows a position control system using a microprocessor-
based controller with parallel ports. This particular system has one
output port and three input ports (each port has its own address).
The output port is partitioned: Six bits are converted in a DAC to
provide the analog motor-drive signal, the seventh bit specifies
motor direction (1 = clockwise, 0 = counterclockwise), and the eighth
bit turns on an audio alarm if some emergency situation is detected.
The first input port inputs the set-point data, the second inputs the
ADC data from the sensor, and the third inputs various 1-bit logical
variables. In this case, the system has three front-panel switches as
well as two limit switches. The limit switches are used as a “back up”
to detect it if the load has gone out of its designated range.
Operation of the system proceeds as follows: The controller inputs
the data from port 03 to determine if the start (or stop) button has
been pressed. If the start button has been pressed, then the set
point is read in from port 01 and the digitized sensor data is read in
from port 02. Based on its control strategy, the controller outputs to
port 00 a binary word representing the motor-control voltage. This
digital data is converted to an analog voltage with the DAC. This
entire sequence is repeated over and over until the stop button is
pushed.
INTERFACING TO A MICROPROCESSOR CONTROLLER
INTERFACING TO A MICROPROCESSOR CONTROLLER
INTERFACING TO A MICROPROCESSOR CONTROLLER
INTRODUCTION TO CONTROLLER PROGRAMMING
A digital controller is a computer operating in real time. This means that the
program is running all the time—repeatedly taking in the newest sensor data
and then calculating a new output for the actuator.
The basic structure of a controller program is a loop. In a loop structure, the
same sequence of instructions is executed over and over again, and each pass
through the loop is called an iteration, or scan. Figure 2.14 shows a generalized
controller program, and an explanation of the program follows:
1. The program reads in the set-point data (recall that the set point is the
desired position of the controlled variable). This data could be read in from
an input port or from memory
2. The program directs the computer to read (from a sensor) the actual value of
the controlled variable.
3. The actual data are subtracted from the set point to get the error.
4. Based on the error data, the computer calculates a new actuator control
signal.
5. The new output is sent to the actuator.
6. The programs loops back to step 1 and starts over again.
INTRODUCTION TO CONTROLLER PROGRAMMING
The time it takes for the computer to execute one pass through the loop determines the time interval between input
readings (known as the sampling rate). If this interval is too long, the computer may not get an accurate picture of
what the controlled variable is really doing (see Chapter 11 for a discussion of aliasing). Execution of the loop can be
accelerated by specifying a faster computer or streamlining the program. In other situations, the computer must
pause and wait. For example, a pause might be inserted to give an operator time to make some adjustment or to
allow time for a motor to “spin down.” This is done by inserting time-delay loops in the program. A time-delay loop is
simply a do-nothing, “wheel-spinning” loop where the computer is instructed to count up to some large number.
Using this technique, we can make the program pause for any length of time—from a few microseconds to hours. If a
time-delay loop is inserted in the main program loop (as shown in Figure 2.14), the effect is to slow the cycle time for
the main loop. This is sometimes done to force matching of the sample rate to some predetermined value.
At one time, people thought that the best and most efficient microprocessor programs were those written directly in
assembly language—that is, the programmer would directly select the machine language instructions. Today,
sophisticated programs (called Time delay (optional)compilers) can convert a program written in a high-level
language, primarily C, into very efficient machine language. High-level languages use English-sounding words and a
set of powerful commands to specify simple and complicated programming operations with a minimum of
instructions. Using a high-level language to write programs for a microprocessor offers big advantages, such as more
compact program listing, ease of writing equations, and more comprehensible documentation. Also, programs
written in a high-level language can be compiled to run on any model of microprocessor.
INTRODUCTION TO CONTROLLER PROGRAMMING
INTRODUCTION TO CONTROLLER PROGRAMMING