Microcomputer systems:Pin Coniguration

Pin Coniguration

Descriptions of the various pins are given below.

Microcomputer-Systems0023_thumb

RST

This is the reset input. This input should normally be at logic 0. A reset is accomplished by holding the RST pin high for at least two machine cycles. Power-on reset is normally performed by connecting an external capacitor and a resistor to this pin (see Figs 1.3 and 1.4).

P3.0

This is a bi-directional I/O pin (bit 0 of port 3) with an internal pull-up resistor. This pin alsoacts as the data receive input (RXD) when the device is used as an asynchronous UART to receive serial data.

Microcomputer-Systems0024_thumb

P3.7

This is a bi-directional I/O pin (bit 1 of port 3) with an internal pull-up resistor. This pin also acts as the data transmit output (TXD) on the 8051 when the device is used as an asynchronous UART to transmit serial data.

XTAL7 and XTAL2

These pins are where an external crystal should be connected for the operation of the internal oscillator. Normally two 33 pF capacitors are connected with the crystal as shown in Figs 1.3 and 1.4. A machine cycle is obtained by dividing the crystal frequency by 12. Thus, with a 12 MHz crystal, the machine cycle is 1 fls. Most machine instructions execute in one machine cycle.

P3.2

This is a bi-directional I/O pin (bit 2 of port 3) with an internal pull-up resistor. This pin is alsothe external interrupt 0 (INT0) pin.

Microcomputer-Systems0025_thumb

P3.3

This is a bi-directional I/O pin (bit 3 of port 3) with an internal pull-up resistor. This pin is alsothe external interrupt 1 (INT1) pin.

P3.4

This is a bi-directional I/O pin (bit 4 of port 3) with an internal pull-up resistor. This pin is alsothe counter 0 input (T0) pin.

Microcomputer-Systems0026_thumbP3.5

This is a bi-directional I/O pin (bit 5 of port 3) with an internal pull-up resistor. This pin is alsothe counter 1 input (T1) pin.

GND

Ground pin.

P3.6

This is a bi-directional I/O pin. This pin is not available on the AT89C2051. It is alsothe external memory write (WR) pin.

P3.7

This is a bi-directional I/O pin for bit 7 of port 3. On the standard 8051, this pin is alsothe external data memory read (RD) pin.

P7.0

This is a bi-directional I/O pin for bit 0 of port 1. This pin has no internal pull- up resistors on the 20-pin devices. It is also used as the positive input of the analogue comparator (AIN0) on the 20-pin device.

P7.7

This is a bi-directional I/O pin for bit 1 of port 1. This pin has no internal pull- up resistors on the 20-pin devices. It is also used as the positive input of the analogue comparator (AIN1) on the 20-pin device.

P7.2 to P7.7

These are the remaining bi-directional I/O pins of port 1. These pins have internal pull-up resistors.

vee

Supply voltage.

P0.0 to P0.7

These are the eight I/O pins of port 0 of the standard 8051. These pins have no pull-up resistors. P0.0 to P0.7 are also used to provide the low addresses (A0 to A7) and the data during fetches from external program memory and during accesses toexternal data memory.

P2.0 to P2.7

These are the eight I/O pins of port 2 of the standard 8051. These pins have pull-up resistors. P2.0 toP2.7 are alsoused toprovide the high address (A8 to A15) byte during fetches from external program memory and during accesses toexternal data memory.

EA/vPP

This is the external access enable pin on the standard 8051. EA should be connected to VCC for internal program executions. This pin also receives the programming voltage during programming.

PSEN

This is the program store enable pin on the 8051 devices. This pin is activated when the device is executing code from external memory.

ALE/PROG

This is the address latch enable pin on the standard 8051 devices. This pin is used to latch the low byte of the address during accesses to external memory.

 

Microcomputer systems:Project Development

Project Development

Development of a AT89C2051 microcontroller project requires several development tools. The following is a list of the tools that are essential:

• Suitable assembler or compiler which can generate machine code for the AT89C2051 microcontroller. In this book we shall be developing the projects using a C compiler.

• Chip programmer suitable to program AT89C2051 devices. There are

many programmers available on the market for this purpose. For example, PG302 by Inguana labs, Evalu8r by Equinox Technologies, and others. The programmer should be compatible with the code generated by the assembler or the compiler so that the code can be downloaded to the microcontroller. Notice that there is no ultraviolet erasing process. AT89C2051 devices contain reprogrammmable flash memories which can be erased and reprogrammed by electrical signals.

• A minimum AT89C2051 microcontroller hardware. Many manufacturers offer development systems, consisting of a basic microcontroller, LED lights, switches, buzzers etc. Some development systems include both language compilers and hardware and such systems can be very useful during project development.

Although the microcontroller used in the projects is the 20-pin AT89C2051, the code given will run on all members of the 8051 family provided that there is enough program and data memories.

 

Microcomputer systems:Minimum Microcontroller Coniguration

Minimum Microcontroller Coniguration

The minimum microcontroller configurations of the 8051- and AT89C2051- based microcontroller systems are shown in Figs 1.3 and 1.4. As can be seen

from these figures, only the following external components are required to have a working microcontroller:

Microcomputer-Systems0030_thumb

We shall be using the circuit in Fig. 1.4 in all of the projects described in this book, except the last project which is based on a 40-pin device. The crystal chosen for the projects is 12 MHz, which gives a basic instruction timing of 1 fls. The power supply current of the AT89C2051 is around 15 mA, but a power supply which can deliver up to a few hundred milliamperes is recommended so that the interface circuitry attached to the microcontroller can be powered.

 

Microcomputer systems:Microcontroller Evolution

Introduction

The term microcomputer is used to describe a system that includes a microprocessor, program memory, data memory, and an input/output (I/O). Some microcomputer systems include additional components such as timers, counters, analogue-to-digital converters and so on. Thus, a microcomputer system can be anything from a large computer system having hard disks, floppy disks and printers, tosingle chip computer systems.

In this book we are going to consider only the type of microcomputers that consist of a single silicon chip. Such microcomputer systems are also called microcontrollers.

Microcontroller Evolution

First, microcontrollers were developed in the mid-1970s. These were basically calculator-based processors with small ROM program memories, very limited RAM data memories, and a handful of input/output ports.

As silicon technology developed, more powerful, 8-bit microcontrollers were produced. In addition to their improved instruction sets, these microcontrollers included on-chip counter/timers, interrupt facilities, and improved I/O handling. On-chip memory capacity was still small and was not adequate for many applications. One of the most significant developments at this time was the availability of on-chip ultraviolet erasable EPROM memory. This simpli- fied the product development time considerably and, for the first time, also allowed the use of microcontrollers in low-volume applications.

The 8051 family was introduced in the early 1980s by Intel. Since its introduction, the 8051 has been one of the most popular microcontrollers and has been second-sourced by many manufacturers. The 8051 currently has many different versions and some types include on-chip analogue-to-digital converters, a considerably large size of program and data memories,

pulse-width modulation on outputs, and flash memories that can be erased and reprogrammed by electrical signals.

Microcontrollers have now moved into the 16-bit market. 16-bit micro- controllers are high-performance processors that find applications in real-time and compute intensive fields (e.g. in digital signal processing or real-time control). Some of the 16-bit microcontrollers include large amounts of program and data memories, multi-channel analogue-to-digital converters, a large number of I/O ports, several serial ports, high-speed arithmetic and logic operations, and a powerful instruction set with signal processing capabilities.

 

Microcomputer systems:Microcontroller Architecture

Microcontroller Architecture

The simplest microcontroller architecture consists of a microprocessor, memory, and input/output. The microprocessor consists of a central processing unit (CPU) and the control unit (CU).

The CPU is the brain of a microprocessor and is where all of the arithmetic and logical operations are performed. The control unit controls the internal operations of the microprocessor and sends control signals to other parts of the microprocessor to carry out the required instructions.

Memory is an important part of a microcomputer system. Depending upon the application we can classify memories into two groups: program memory and data memory. Program memory stores all the program code. This memory is usually a read-only memory (ROM). Other types of memories, e.g. EPROM and PEROM flash memories, are used for low-volume applications and also during program development. Data memory is a read/write memory (RAM). In complex applications where there may be need for large amounts of memory it is possible to interface external memory chips to most microcontrollers.

Input/Output (I/O) ports allow external digital signals to be connected to the microcontroller. I/O ports are usually organized into groups of 8 bits and each group is given a name. For example, the 8051 microcontroller contains four 8-bit I/O ports named P0, P1, P2, and P3. On some microcontrollers the direction of the I/O port lines are programmable so that different bits of a port can be programmed as inputs or outputs. Some microcontrollers (including the 8051 family) provide bi-directional I/O ports. Each I/O port line of such microcontrollers can be used as inputs and outputs. Some microcontrollers provide ‘open-drain’ outputs where the output transistors are left floating (e.g. port P0 of the 8051 family). External pull-up resistors are normally used with such output port lines.

 

Microcomputer systems:Interrupt Control

Interrupt Control

The standard 8051 and AT89C2051 provide six interrupt sources:

Microcomputer-Systems0029_thumb

Each interrupt is assigned a fixed location in memory and an interrupt causes the CPU tojump tothat location, where it executes the interrupt service routine. Table 1.5 gives the interrupt sources and the start of their service routines in memory. Note that the serial port receive and transmit interrupts point to the same location.

Each interrupt source can be individually enabled or disabled by setting or clearing its interrupt enable bit. Table 1.6 gives the interrupt enable bit patterns.

 

Microcomputer systems:Architecture of the 8051 Family

Architecture of the 8051 Family

The 8051 is an 8-bit, low-power, high-performance microcontroller. There are a large number of devices in the 8051 family with similar architecture and each member of the family is downward compatible with each other. The basic 8051 microcontroller has the following features:

• 4 Kbytes of program memory

• 256 x 8 RAM data memory

• 32 programmable I/O lines

• Two16-bit timer/counters

• Six interrupt sources

• Programmable serial UART port

• External memory interface

• Standard 40-pin package

The EPROM versions of the family (e.g. 8751) are used for development and the program memory of these devices is erased with an ultraviolet light source. The pin configuration of the standard 8051 microcontroller is shown in Fig. 1.1.

The AT89C2051 is a low-end member of the 8051 family, aimed for less complex applications. This device contains a 2 Kbyte flash programmable memory (PEROM) which can be erased and reprogrammed using a suitable programmer. The AT89C2051 contains 128 bytes of RAM and 15 program- mable I/O lines. The code developed for this device runs on a standard 8051 without any modification. As shown in Fig. 1.2, the AT89C2051 is housed in a 20-pin package.

 

SYSTEM MODELLING:THERMAL SYSTEMS

THERMAL SYSTEMS

Thermal systems are encountered in chemical processes, heating, cooling and air conditioning systems, power plants, etc. Thermal systems have two basic components: thermal resistance and thermal capacitance. Thermal resistance is similar to the resistance in electrical circuits. Similarly, thermal capacitance is similar to the capacitance in electrical circuits. The across variable, which is measured across an element, is the temperature, and the through variable is the heat flow rate. In thermal systems there is no concept of inductance or inertance. Also, the product of the across variable and the through variable is not equal to power. The mathematical modelling of thermal systems is usually complex because of the complex distribution of the temperature. Simple approximate models can, however, be derived for the systems commonly used in practice.

Thermal resistance, R, is the resistance offered to the heat flow, and is defined as:

System Modelling-0068

where T1 and T2 are the temperatures, and q is the heat flow rate.

Thermal capacitance is a measure of the energy storage in a thermal system. If q1 is the heat flowing into a body and q2 is the heat flowing out then the difference q1 − q2 is stored by the body, and we can write

System Modelling-0069

System Modelling-0070

An example thermal system model is given below.

Example 2.14

Figure 2.25 shows a room heated with an electric heater. The inside of the room is at temperature Tr and the walls are assumed to be at temperature Tw . If the outside temperature is To, develop a model of the system to show the relationship between the supplied heat q and the room temperature Tr .

Solution

The heat flow from inside the room to the walls is given by

System Modelling-0071

Figure 2.26 shows a heated stirred tank thermal system. Liquid enters the tank at the temperature Ti with a flow rate of W . The water is heated inside the tank to temperature T . The temperature leaves the tank at the same flow rate of W . Derive a mathematical model for the system, assuming that there is no heat loss from the tank.

Solution

The following equation can be written for the conservation of energy:

System Modelling-0073

where C is the thermal capacity, i.e. C = ρ VC p and V is the volume of the tank. Substituting (2.114)–(2.116) into (2.113) gives

System Modelling-0074

 

Microcomputer systems:8051 Family

8051 Family

The 8051 family is a popular, industry standard 8-bit single chip micro- computer (microcontroller) family, manufactured by various companies with many different capabilities. The basic standard device, which is the first member of the family, is the 8051, which is a 40-pin microcontroller. This basic device is now available in several configurations. The 80C51 is the low- power CMOS version of the family. The 8751 contains EPROM program memory, used mainly during development work. The 89C51 contains flash programmable and erasable memory (PEROM) where the program memory can be reprogrammed without erasing the chip with ultraviolet light. The 8052 is an enhanced member of the family which contains more RAM and also more timer/counters. There are many versions of the 40-pin family which contain on- chip analogue-to-digital converters, pulse-width modulators, and so on. At the lower end of the 8051 family we have the 20-pin microcontrollers which are code compatible with the 40-pin devices. The 20-pin devices have been manufactured for less complex applications where the I/O requirements are not very high and where less power is required (e.g. in portable applications). The AT89C1051 and AT89C2051 (manufactured by Atmel) are such micro- controllers, which are fully code compatible with the 8051 family and offer reduced power and less functionality. Table 1.1 gives a list of the characteristics of some members of the 8051 family.

Microcomputer-Systems0022_thumb

In this book all the projects are based upon the AT89C2051 microcontroller. The code given will run on other members of the family, including the 40-pin devices. The reasons for choosing the AT89C2051 are its low cost, low power consumption, small space (20 pin), and powerful features.

In this chapter we shall be looking at the features of the 8051 family briefly with more emphasis on the smaller AT89C2051. More information on these microcontrollers can be obtained from the manufacturers’ data sheets.

 

INTRODUCTION TO THE IDEA OF SYSTEM CONTROL

THE IDEA OF SYSTEM CONTROL

Control engineering is concerned with controlling a dynamic system or plant. A dynamic system can be a mechanical system, an electrical system, a fluid system, a thermal system, or a combination of two or more types of system. The behaviour of a dynamic system is described by differential equations. Given the model (differential equation), the inputs and the initial conditions, we can easily calculate the system output.

A plant can have one or more inputs and one or more outputs. Generally a plant is a continuous-time system where the inputs and outputs are also continuous in time. For example, an electromagnetic motor is a continuous-time plant whose input (current or voltage) and output (rotation) are also continuous signals. A control engineer manipulates the input variables and shapes the response of a plant in an attempt to influence the output variables such that a required response can be obtained.

A plant is an open-loop system where inputs are applied to drive the outputs. For example, a voltage is applied to a motor to cause it to rotate. In an open-loop system there is no knowledge of the system output. The motor is expected to rotate when a voltage is applied across its terminals, but we do not know by how much it rotates since there is no knowledge about the output of the system. If the motor shaft is loaded and the motor slows down there is no knowledge about this. A plant may also have disturbances affecting its behaviour and in an open-loop system there is no way to know, or to minimize these disturbances.

Figure 1.1 shows an open-loop system where the system input is expected to drive the system output to a known point (e.g. to rotate the motor shaft at a specified rate). This is a single-input, single-output (SISO) system, since there is only one input and also only one output is available. In general, systems can have multiple inputs and multiple outputs (MIMO). Because of the unknowns in the system model and the effects of external disturbances the open-loop control is not attractive. There is a better way to control the system, and this is by using a sensor to measure the output and then comparing this output with what we would like to see at the system output. The difference between the desired output value and the actual output value is called the error signal. The error signal is used to force the system output to a point such that the desired output value and the actual output value are equal. This is termed closed- loop control, or feedback control. Figure 1.2 shows a typical closed-loop system. One of the advantages of closed-loop control is the ability to compensate for disturbances and yield the correct output even in the presence of disturbances. A controller (or a compensator) is usually employed to read the error signal and drive the plant in such a way that the error tends to zero.

Digital-Control-0011_thumb

Closed-loop systems have the advantage of greater accuracy than open-loop systems. They are also less sensitive to disturbances and changes in the environment. The time response and the steady-state error can be controlled in a closed-loop system.

Sensors are devices which measure the plant output. For example, a thermistor is a sensor used to measure the temperature. Similarly, a tachogenerator is a sensor used to measure the rotational speed of a motor, and an accelerometer is used to measure the acceleration of a moving body. Most sensors are analog devices and their outputs are analog signals (e.g. voltage or current). These sensors can be used directly in continuous-time systems. For example, the system shown in Figure 1.2 is a continuous-time system with analog sensors, analog inputs and analog outputs. Analog sensors cannot be connected directly to a digital computer. An analog-to-digital (A/D) converter is needed to convert the analog output into digital form so that the output can be connected to a digital computer. Some sensors (e.g. temperature sensors) provide digital outputs and can be directly connected to a digital computer.

With the advent of the digital computer and low-cost microcontroller processing elements, control engineers began to use these programmable devices in control systems. A digital computer can keep track of the various signals in a system and can make intelligent decisions about the implementation of a control strategy.