CHAPTER 2 Introduction to Microprocessor Based Control Eng. Hussien A. Alqupati OBJECTIVES After studying this chapter, you should be able to: • Understand what a microprocessor is, what it does, and how it works. • Understand the concepts of RAM and ROM computer memory and how memory is accessed via the address and data buses. • Understand how parallel and serial data interfaces work. • Perform relevant calculations pertaining to analog-to-digital converters and digital-to-analog converters • Understand the principles of digital controller software. • Recognize and describe the characteristics of the various types of available digital controllers, that is, microcontrollers, single-board computers, programmable logic controllers, and personal computers. INTRODUCTION microprocessor is an digital integrated circuit (IC). This revolution has occurred because the microprocessor brings the flexibility of program control and the computational power of a computer to bear on any problem. microprocessor-based control systems are rapidly replacing many older control systems based on analog circuits or electromechanical relays. One of the first microprocessor-based controllers made specifically for control applications was the programmable logic controller (PLC) . A microprocessor by itself is not a computer; additional components such as memory and input/output circuits are required to make it operational the microcontroller 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. • 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. Why studding microprocessor in Mechatronics I have included this material because the student of modern control systems should have at least a general knowledge of how the microprocessor performs its job. 2.1 INTRODUCTION TO MICROPROCESSOR SYSTEM HARDWARE A computer is made up of four basic functional units: the central processing unit (CPU), memory, input, and output (I/ O). The central processing unit does the actual computing and is composed of two subparts: the arithmetic logic unit and control sections . 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. • Digital data is in the form of bits, where each bit has a value of either 1 or 0 . • Digital circuits usually use 5 Vdc to represent logic 1 and 0 Vdc to represent logic 0. • Eight bits together is called a byte. A microprocessor handles digital data in words, where a word may be 8, 16, or 32 bits wide. • an 8-bit microprocessor has a byte-sized word, with a maximum decimal value of 255. • • EXAMPLE 2.1 Find the decimal value of the 8-bit binary number 10110011. 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. • 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. • 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 . • Disk drives also store digital data but in a form that must be processed before they are accessible to the microprocessor . 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. Bus • connected by three lines labeled address bus, data bus, and control 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 data bus is a group of eight wires that carries the actual numerical data from place to place within the computer. • The control bus (see Figure 2.2) 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. 2.3 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. Both data formats are discussed next. • The Parallel Interface • The Serial 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. • Digital-to-Analog Conversion The digital-to-analog converter (DAC) is a circuit that converts a digital word into an analog voltage. 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 V ( ref) must be supplied to the DAC. This voltage defines the maximum analog voltage—that is, for a digital input of 11111111, out is essentially V ref. If the input is 00000000,Vthe out will be 0 Vdc. For all values in between, the output voltage is a linear percentage V of ref. Specifically, the output voltage for any digital input (for the 8-bit DAC) is • EXAMPLE 2.2 An 8-bit DAC has aV ref of 10 V. The binary input is 10011011. Find the analog output voltage. • • An important consideration of digital-to-analog conversion is resolution . • if more is needed, two (or more) 8-bit ports can be used together. Two ports provide 16 bits of data. The maximum decimal value of 16 bits is 65,535. Being able to divide an analog number into 65,535 parts means that each part will be much smaller, so we can more precisely represent that number • The time to complete a conversion is a fast 150 ns (nanoseconds). • This device comes as a 16-pin DIP (dual in-line package) and uses an external op-amp . •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. Analogto-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 V in can be any voltage between 0 V and V ref. When V in is 0Vdc, the output is 00000000; when V in is ref, the output is 11111111 (255 decimal). For input voltages between 0 V and ref, the output increases linearly Vwith in; therefore, we can develop a simple ratio for the ADC: A Control System Using Parallel Ports The Serial Interface • In a serial interface, the data are sent 1 bit after the other on a single wire. There are a number of good reasons for doing this. • First, the cabling is simpler because only two wires are needed (at a minimum), those being “data” and “return.” • Second, shielding a small group of wires, which is often necessary in an electrically noisy industrial environment, is easier. • Third, serial data can make use of existing single-channel data lines such as the telephone system (which may require using a modem). • serial data transfer is usually recommended for distances greater than 10-30 ft. • al data transfer is usually recommended for distances greater than 10-30 ft. Because data always exist in a parallel form inside the computer, it must be converted to serial data before coming out the serial port. This is accomplished with a special parallel-to-serial converter IC called a universal asynchronous receiver transmitter (UART). • Serial data are classified as being either synchronous or asynchronous.Synchronous data require that the data bytes be sent as a group in a “package.” It is used in sophisticated communication systems that move a lot of data and will not be further discussed here. Asynchronous data transfer is the more common (but slower) type of serial transfer and allows for individual bytes to be sent when needed. • standard format for asynchronous serial data. First, a start bit is sent, then the data (LSB first), then a parity-error checking bit, and finally the stop bit(s). • The other important parameter in serial transmission is the number of bits sent per second (frequently called the baud rate ). • .Serial data transmission is much slower than parallel transmission. • for many applications, particularly process control, the longer datatransfer times are not a problem. • In order to make the serial interface practical, a set of specifications called the RS-232 standard . • the RS-232 standard specifies the serial data interface between data terminal equipment (DTE) and data communication equipment (DCE). • A common application of RS-232 is the interface between a PC and the modem, in which case the computer is the DTE and the modem is the DCE . • A modem is a device that converts digital data into audio tones so that it can be transmitted over the telephone lines. • the RS-232 interface consists of seven signals; the serial data is sent on pin 2 and received on pin 3; the other signals, such as “Request to send” and Clear to send,” are used to confirm that the two units are ready to communicate. • the RS-232 standard can be applied to any serial interface as long as one unit acts as a DTE and the other as a DCE . • If two DTE units need to interface with each other—for example, a PC to a PC—a special cable called a null modem or crossover cable is used. RS-232 is commonly used in the control field when two units need to exchange data—for example, to connect a PC to a local control unit for the purpose of downloading a new control program. • Networking Probably the most common use of serial data is in networking. More and more, networks are being used to interconnect all the units and devices in the control system. • Network cabling differs depending on the type of local area network (LAN), but most use the generalized bus system . • The interface between the network cable and the PC is done through a commercially available interface expansion card called a network interface card (NIC). 2.4 INTRODUCTION TO CONTROLLER PROGRAMMING 2.5 MICROPROCESSOR-BASED CONTROLLERS • • • • Single-Chip Microcomputers (Microcontrollers) . Single-Board Computers . Programmable Logic Controllers . Personal Computers Used in Control Systems • microcontroller is a computer on a single IC, designed specifically for control applications. • Having the complete controller on a single chip allows the hardware design to be simple and very inexpensive. • Microcontrollers are showing up increasingly in products as varied as industrial applications, home appliances, and toys. • In such uses as these, they are called embedded controllers because the controller is located physically in the equipment being controlled. popular microcontroller is the PIC from Microchip Technology. • Single-Board Computers • Single-board computers are off-the-shelf microprocessor-based computers built on a single printed-circuit card (Figure 2.17). They come in many configurations, but in general they use a standard microprocessor such as the Zilog Z80, the Intel x86 family, the Motorola 68000, or a microcontroller. They also include memory ICs (both RAM and ROM), I/O capability, and perhaps special interface circuits such as ADCs or DACs. • Single-board computers are manufactured by major microprocessor producers such as Intel and Motorola as well as many other smaller companies. Programmable Logic Controllers • A programmable logic controller (PLC) is a self-contained microprocessor-based unit, designed specifically to be a controller. The PLC includes an I/O section that can interface directly to such system components as switches, relays, small motors, and lights. • Developed in the late 1960s to replace relay logic controllers. • PLCs have evolved to be able to handle sophisticated motion control applications. • PLC has the microprocessor, ports, and power supply built into a package that has been ruggedized for an industrial environment. • Installation is very easy because in many cases the sensors and actuators can be connected directly to the PLC. • Multiple PLCs in a plant can be networked so the individual units can be monitored and programmed from a single station. This is a form of distributed computer control (DCC) Personal Computers Used in Control Systems