Anda di halaman 1dari 14

ANTOMC13.QXP.

13019561 9/12/03 7:18 PM Page 448

CHAPTER 13
Microcontrollers

OBJECTIVES

In this chapter you will learn about:


• The nature of digital control systems
• The differences between microprocessors and microcontrollers
• Motorola’s 8-/16-/32-bit microcontrollers

KEY TERMS
Digital control system Flash memory ColdFire
Thermistor Durability CPU32
Microcontroller M*CORE
EEPROM Controller area network

13.1 INTRODUCTION

The purpose of this final chapter is to explain what a microcontroller is and to show why
the microcontroller is a good choice for many applications previously handled by micro-
processor-based systems. We will compare the similarities and differences between micro-
processors and microcontrollers in detail.
Section 13.2 describes the nature of digital control systems, followed by a discussion
of the similarities and differences between microcontrollers and microprocessors in
Section 13.3. In Section 13.4, we see why a microcontroller might be used in a new appli-
cation. Sections 13.5 through 13.7 provide information, respectively, on Motorola’s 8-bit,
16-bit, and 32-bit series of microcontrollers. Some final troubleshooting comments are
made in Section 13.8.

448
ANTOMC13.QXP.13019561 9/12/03 7:18 PM Page 449

13.3 MICROPROCESSOR VERSUS MICROCONTROLLER 449

13.2 DIGITAL CONTROL SYSTEMS

The world is not a digital environment! Things are not merely hot or cold, fast or slow, or
bright or dark. In reality, there are many different values of temperature, speed, and bright-
ness. The world we live in is actually an analog environment. Even so, at the heart of many
control processes involving temperature, speed, or brightness is a digital system performing
computations on binary numbers. This is possible through the use of special conversion cir-
cuitry between the digital system and the real-world application. For example, consider how
the temperature of a chemical process may be monitored by a digital system. First, a temper-
ature probe consisting of a thermistor (temperature sensitive resistor) is used to sense the
temperature of the chemical bath. A thermistor’s resistance changes linearly with a change in
temperature. Thus, as the temperature of the chemical process changes, the resistance of the
thermistor varies accordingly. The resistance value of the thermistor is used by a tempera-
ture-to-voltage converter (an operational amplifier circuit) to create a corresponding voltage
(e.g., 0 degrees Celsius equals 0 volts, 100 degrees Celsius equals 1000 millivolts). This
voltage is then fed into an analog-to-digital converter that produces an equivalent 8-bit bi-
nary number representative of the original temperature. Many other processes use a tech-
nique similar to this to convert real-world (analog) information into binary form.
Of course, there are also many applications where no conversion needs to be done. A
single binary bit often represents enough information to the digital system for action to be
taken. One binary input bit may represent any of the following: paper out (in a printer),
temperature too high (in a process where the maximum temperature has been preset), door
open/closed (in a burglar alarm), or start/stop (in a process utilizing push buttons to control
activity). In the same fashion, a single binary output bit can be used to turn on an indicator
light, sound a buzzer, or energize a relay.
Once the real-world interfacing has been performed, software takes over to control
the process. A control program stored in EEPROM and some RAM locations for tempo-
rary data storage are required to complete the system. The question then becomes: Do we
use a microprocessor or a microcontroller in the system?

13.3 MICROPROCESSOR VERSUS MICROCONTROLLER

Figure 13.1 illustrates some of the similarities and differences between microprocessors
and microcontrollers. In Figure 13.1(a), the microprocessor is just one component of many
in a system containing digital and analog I/O, timers, RAM, EEPROM, etc. In Figure
13.1(b), we see that all of the components in the microprocessor-based system are con-
tained within the microcontroller itself, with the exception of the D/A converter. How-
ever, the PWM (Pulse Width Modulation) output of the microcontroller can, through a
low-pass filter, generate an analog output voltage.
The microprocessor needs an external ROM or EEPROM to store its control pro-
gram. These memories are built into the microcontroller. Thus, instead of placing a ROM
into a burner to program it, the microcontroller is placed into the burner and programmed.
In addition, glue logic is required to interface the microprocessor with its external cir-
ANTOMC13.QXP.13019561 9/12/03 7:18 PM Page 450

450 CHAPTER 13 MICROCONTROLLERS

ROM EEPROM

RAM

Microprocessor
Serial I/O

A/D
Parallel I/O
Analog Input Input
I/O and and
output output
D/A Timer
ports ports

PWM

(a) Microprocessor-based system

ROM EEPROM

RAM

Analog A/D Serial I/O


in

CPU
core Parallel I/O

Timer

Analog
out
PWM filter
Microcontroller
Digital
PWM
(b) Microcontroller-based system

FIGURE 13.1 Microprocessor versus microcontroller


ANTOMC13.QXP.13019561 9/12/03 7:18 PM Page 451

13.4 WHY USE A MICROCONTROLLER? 451

cuitry. None is required in the microcontroller-based system, since most of the circuitry is
already inside the microcontroller.
The instruction set of the microprocessor is more powerful than that of the micro-
controller. For example, there may be microprocessor instructions to support multitasking,
memory management, and floating-point calculations, but these instructions are not typi-
cally found in a microcontroller. Thus, the complexity of the application or process helps
determine whether or not to use a microcontroller.

13.4 WHY USE A MICROCONTROLLER?

As stated in Section 13.3, the difference between a microprocessor, which can do nothing
by itself, and a microcontroller is clear. Even so, the applications for microprocessor-based
systems are numerous. The popular personal computer stands out as one of the most im-
portant and useful applications.
But many applications do not require the impressive power of the 32-bit micro-
processor or the extensive expandability that is available on many microprocessor-based
motherboards. Applications such as Electronic ‘Times-Square’ displays, credit card
readers, automatic teller machines, and others can be handled easily with the power of an
8-bit microprocessor and some external support circuitry for I/O. When this is the case, a
microcontroller becomes a suitable substitute.
The microcontroller is a good alternative to microprocessor-based systems, bundling
many of the features of the system on a single chip! For instance, one model of the Mo-
torola 6811 microcontroller that we will be covering contains all of the following on a
single chip:
• 12K bytes of EPROM
• 512 bytes of EEPROM
• 512 bytes of RAM
• 16-bit Timer
• serial I/O capability
• 8-channel analog-to-digital conversion
Another popular microcontroller, the Intel 8051, is similarly organized. Its internal hard-
ware includes RAM, EPROM, timers, interrupt circuitry, and both serial and parallel I/O.
Clearly, the microcontroller is almost a complete system by itself, containing internally
many of the most desirable functions found in a microprocessor-based system. One can
only assume that the term microcontroller was derived from the usefulness of this device
in many control applications.
One could easily argue that the microcontrollers currently available do not compare
to the powerful 32-bit microprocessors that can access billions of bytes of memory, have
powerful instruction sets that support multitasking, are optimized for multimedia pro-
cessing, and run at clock speeds upward from 2 GHz. On the other hand, it would be a
waste of technology to put a 32-bit microprocessor inside a robot arm dedicated to welding
frame joints on an assembly line or inside a credit card machine, microwave oven, or personal
ANTOMC13.QXP.13019561 9/12/03 7:18 PM Page 452

452 CHAPTER 13 MICROCONTROLLERS

TABLE 13.1 Motorola 8-


/16-/32-bit microcontrollers Data Size Microcontrollers Number of Models

8 bits M68HC05 44
M68HC08 55
M68HC11 19
16 bits HCS12 22
M68HC12 16
M68HC16 3
32 bits 68K M683XX 9
M*CORE 5
MPC500 11
ColdFire MCF5XXX 3

computer keyboard. In small, dedicated applications like these, an 8-bit microcontroller is


powerful enough to handle the job with a minimum of external circuitry. With its built-in
EEPROM and RAM, serial I/O and timer capability, and self-contained operation, why use
anything else for a small control application? It would be too expensive in terms of component
count, layout, board space, and troubleshooting to use anything but a microcontroller.
Now that we have an exposure to the basics of the microcontroller, we can concen-
trate on the specifics. Table 13.1 lists the many different types of Motorola microcon-
trollers. The number of models of each type of microcontroller allows the designer to
choose the microcontroller that best fits the needs of a new system.
The differences between models include the amount of internal EEPROM and
RAM, the number of serial and parallel I/O lines, the number of timers, PWM outputs, and
A/D channels, and so on. Let us take a look at some actual devices.

13.5 8-BIT MICROCONTROLLERS

Just as important as their 16-bit and 32-bit counterparts, the 8-bit family of microcon-
trollers fulfills the low-cost, medium-performance requirements for many small systems.
Table 13.2 lists the type and quantity of hardware features provided by the three 8-bit mi-
crocontroller families. There are many models within each family (refer back to Table 13.1)

TABLE 13.2 8-bit Microcontroller features

Bus A/D
RAM ROM EEPROM Flash Serial Frequency Converter PWM
Family (bytes) (bytes) (bytes) (bytes) (channels) Timers (MHz) (channels) (channels) I/O

M68HC05 920 32768 7936 x 2 8 4 8 3 80


M68HC08 2048 25088 1024 61872 3 8 8 15 16 52
M68HC11 1024 32768 640 x 2 8 5 8 4 62

Note: All values in the table denote the maximum available feature across the family of devices.
ANTOMC13.QXP.13019561 9/12/03 7:18 PM Page 453

13.5 8-BIT MICROCONTROLLERS 453

because each model offers a different amount of RAM, ROM, or EEPROM or has a dif-
ferent number of timers, A/D channels, PWM channels, etc.
Although it may seem redundant to include both EEPROM (Electrically Eraseable
PROM) and flash memory on the same chip, they are not the same type of memories, as
the following example illustrates.

Example 13.1: EEPROM allows any single location to be updated. In a flash memory,
the entire memory must be loaded with new data at the same time (bulk) or an entire por-
tion of locations (sector). Let us consider a 32-KB EEPROM and a 32-KB flash memory
and their function in a small control system. A programmer may only require the use of 20
locations in the EEPROM to store status and data. Since the EEPROM retains its informa-
tion when power is off, the status and data continue through power cycles and may be used
to restart the system into a good state.
During normal execution, the 20 EEPROM locations are read and written as the
system state changes. Updates are performed at the rate of four times per day. The nature
of the EEPROM architecture limits the number of updates that may be reliably performed
on a single location (the durability of the memory). At least 10,000 updates are typically
possible. For the small control system, this indicates an operational period of 2,500 days
(almost seven years) before the EEPROM locations holding the system information lose
their reliability. To keep operating, we could then replace the microcontroller (getting a
new internal EEPROM in the process) or switch to a different 20 locations in the same
EEPROM. The durability applies to each location, so switching to a new set of locations
starts the clock over. The control system must keep track of how many updates have been
performed and switch to the new locations at the proper time.
The 32-KB flash memory in the small control system is used to store the control pro-
gram. It is written once, or perhaps several times, during production of the control system
circuit boards so as to load the control program. If a new version of the program is made
available, the entire flash memory is updated with the new control program. The durability
of the flash may be lower than the EEPROM, from 100 to 1000 updates, but this does not
have much of an effect on the small control system. Even with ten updates during produc-
tion, a minimum durability of 100 updates would leave 90 additional updates. This would
average to 13 updates each year for the seven-year operational period set by the EEPROM
durability, which should be enough updates to satisfy the programmer.
Therefore, EEPROM is used to store data that may be updated frequently and thus
has a high durability. Flash memory is updated less frequently, so a lower durability does
not degrade performance.

The popular 68HC11 microcontroller, illustrated in Figure 13.2, is literally a system-


on-a-chip. Features provided include all necessary types of memory (RAM, EEPROM,
and ROM/EPROM), 38 bits of general purpose I/O (bidirectional and one-way), timers, an
8-channel analog-to-digital converter, and support for serial communication.
What might we do with the 68HC11? It may be too much to ask the 68HC11 to be the
ANTOMC13.QXP.13019561 9/12/03 7:18 PM Page 454

454 CHAPTER 13 MICROCONTROLLERS

Mode
PA0-PA7 Port A Timer system
control

PB0-PB7 Bus expansion OSC


Port B
address clock

68HCII
CPU
Interrupt
PC0-PC7 IRQ
Port C Address/data logic

PD0-PD5 Port D Serial interface


EPROM

EEPROM

PE0-PE7 RAM
Port E A/D converter

V ref

FIGURE 13.2 68HC11 block diagram

central component of a digital-analog flight control system for an aircraft. Smaller applica-
tions, such as controlling a pay phone or credit card reader, monitoring several voltage levels,
or controlling a keyboard, require less performance and are good fits for the 68HC11.

13.6 16-BIT MICROCONTROLLERS

The three main 16-bit microcontroller families are listed in Table 13.3. Again, the type
and amount of internal support hardware (timers, serial channels, I/O, etc.) differ between
models.
One family, the 68HC16 microcontrollers, are the 16-bit enhancements of the 8-bit
68HC11 microcontroller. With 16-, 20-, and 25-MHz versions available, the 68HC16 is
designed to provide many powerful features without the need for CPU intervention, in-
cluding multichannel timers, analog-to-digital converters, and networking activities. For
example, Figure 13.3(a) shows the block diagram of the Time Processor Unit in the
68HC16. Sixteen timer channels are controlled by a Micro-engine, freeing the CPU of the
ANTOMC13.QXP.13019561 9/12/03 7:18 PM Page 455

13.7 32-BIT MICROCONTROLLERS 455

chore. In a similar fashion, the 8-channel analog-to-digital converter in Figure 13.3(b) uses
a single Successive Approximation Register (SAR, a fast A/D converter) and analog mul-
tiplexer to process eight analog input channels.
The 68HC16 also provides a Controller Area Network (CAN) interface, allowing the
68HC11 to use asynchronous serial communication to exchange data with industrial and
automotive control systems at a speed of 1 Mbps.

13.7 32-BIT MICROCONTROLLERS

Table 13.4 lists the features of Motorola’s four families of 32-bit microcontrollers. Each
family has architectural differences, but also provides many of the same support features
(serial I/O, A/D conversion, timers, etc.).
The computing architectures of each family are as follows:

• M683XX: 32-bit CPU32 processing core


• M*CORE: 32-bit microRISC Engine
• MPC500: 32-bit PowerPC core
• MCF5XXX: 32-bit ColdFire Version 2 core

Let us take a closer look at these powerful microcontroller families.

MC683XX Family
This family contains several different microcontroller models, each specializing in a dif-
ferent area. These microcontrollers are as follows:
• MC68302: Integrated Multi-Protocol Processor
• MC68306: Integrated EC000 Processor
• MC68331/332/336: 32-bit Microcontroller
• MC68340: Integrated Processor with DMA
• MC68360: Quad Integrated Communication Controller
• MC68F375/376: 32-bit Microcontroller

TABLE 13.3 16-bit Microcontroller features

Bus A/D
RAM ROM EEPROM Flash Serial Frequency Converter PWM
Family (bytes) (bytes) (bytes) (bytes) (channels) Timers (MHz) (channels) (channels) I/O

HCS12 12288 x 4096 262144 6 8 25 16 8 99


M68HC12 8000 32000 4096 128000 3 16 8 8 8 91
M68HC16 4096 8192 x x 2 8 25 8 x 24

Note: All values in the table denote the maximum available feature across the family of devices.
ANTOMC13.QXP.13019561 9/12/03 7:18 PM Page 456

456 CHAPTER 13 MICROCONTROLLERS

;
Scheduler Requests
Host Timer
interface Control channels

Channel
0
1

’ Timer
T2 ’ signals
TCR1 ’
CLK ’
TCR2 ’

Inter-
module 14
bus 15
Micro-engine
Data Control
and data
(a) Time Processor Unit
RC DAC array
and comparator

Analog Analog
MUX inputs
SAR

Result
registers

0
1

;;



’ Mode

’ and
6 timing
7 control CLK
select/
prescale

Bus interface unit

Inter-
module
bus
(b) Analog to digital converter
FIGURE 13.3 68HC16 peripherals
ANTOMC13.QXP.13019561 9/12/03 7:18 PM Page 457

13.7 32-BIT MICROCONTROLLERS 457

TABLE 13.4 32-bit Microcontroller features

Bus A/D
RAM ROM EEPROM Flash Serial Frequency Converter PWM
Family (bytes) (bytes) (bytes) (bytes) (channels) Timers (MHz) (channels) (channels) I/O

M683XX 10 K x x 256 K 4 16 33 16 x 48
M*CORE 32 K x x 256 K 2 2 33 8 x 104
MPC500 36 K x x 1024 K 3 70 66 40 x 101
MCF5XXX 64 K x x x 5 4 66 x x 150

Note: All values in the table denote the maximum available feature across the family of devices.

The heart of each of the 683xx microcontrollers (except for the 68302) is the CPU32 core, a
32-bit processing unit based on the 68000 software model and instruction set, with additional
features from the 68010 and 68020 as well as new features specifically added for control op-
erations. There are seven addressing modes (no pre-decrement or post-increment). Although
the data registers are the familiar 32-bits wide, 64-bit integer operations are provided.

M*CORE Family
The M*CORE family of microcontrollers are built around a new processing core called the
M*CORE microRISC Engine, which was designed to provide high performance with low
system power. This makes the M*CORE family suitable for battery-operated and mobile
applications.
Figure 13.4 shows a block diagram of the microRISC core. Although the load/store
architecture is 32 bits wide, instructions are fixed at 16 bits wide for fast instruction
throughput between the core and the memory system. There are sixteen 32-bit general pur-
pose registers, support for arithmetic and logical operations, and a four-stage instruction
pipeline that allows most instructions to complete in one clock cycle.

MPC500 Family
For systems designed around the PowerPC architecture, the MPC500 family provides 11
models of PowerPC microcontrollers. This provides compatibility with the PowerPC
instruction set, including floating-point operations. With either 512 KB or 1 MB of flash
memory, these microcontrollers are suitable for scientific applications involving complex
operations and large control programs. See Appendix I for additional information on the
PowerPC architecture and family of processors.

MCF5XXX Family
This family of microcontrollers utilize the ColdFire Version 2 core, which contains an en-
hanced multiply-and-accumulate unit (eMAC) designed to support DSP applications. Ad-
ditional microcontroller features include DMA, I2C bus support, Ethernet, CAN, and
on-board cache.
ANTOMC13.QXP.13019561 9/12/03 7:18 PM Page 458

458 CHAPTER 13 MICROCONTROLLERS

Data calculation Address generation

General Alternate Control


purpose register register
register file file
Address
file
MUX

Y port

Immediate PC Branch
MUX Inc. adder

Sign ext. Scale


Data Address
bus bus

Barrel shifter
Multiplier
Divider

Instruction
decode

MUX MUX
Instruction
pipeline

Adder/Logical
priority encoder / Zero detect
result MUX

Writeback bus Hardware


accelerator
bus

FIGURE 13.4 M*CORE microRISC engine block diagram


ANTOMC13.QXP.13019561 9/12/03 7:18 PM Page 459

SUMMARY 459

The ColdFire Version 2 processing core is a variable instruction-length RISC archi-


tecture. Instruction fetch and decode/execute units are pipelined and process ColdFire in-
structions, which are similar to those in the 680x0 instruction set.
No matter which microcontroller you may choose for an application, it is important
to have access to support tools that you will need during development, such as a universal
programmer, C compiler, and in-circuit emulator. Many of the newer microcontrollers
have built-in debug interfaces that provide real-time debugging, assisting with trou-
bleshooting and simplifying the development process. Links to these tools, as well as tech-
nical documentation and other resources, are available on Motorola’s Web site.

13.8 TROUBLESHOOTING TECHNIQUES

Using a microcontroller instead of a microprocessor in a new system automatically re-


duces the troubleshooting requirements of the system, since a great deal of the external
circuitry of the microprocessor-based system has been moved inside the microcontroller.
Where there may have been many individually integrated circuits and components to
check while troubleshooting the microprocessor-based system, there is just the micro-
controller and a small number of external components in the microcontroller-based
system.
For many technicians in the field, troubleshooting simply involves replacing the cir-
cuit board containing the fault with a working board. A microprocessor-based system may
contain several circuit boards, forcing the technician to swap boards out one by one until
the problem goes away. It is not hard to imagine that there may be only one circuit board
in a microcontroller-based system, which greatly simplifies the troubleshooting process.

SUMMARY

In this chapter we examined the similarities and differences between microprocessors and
microcontrollers. Many of the most common forms of input/output hardware were dis-
cussed and shown to be available both within a microcontroller and a configured micro-
processor-based system. The nature of a particular application determines whether or not a
microcontroller should be used as the control mechanism, and examples were given to show
what these applications might involve. With the wide range of 8-, 16-, and 32-bit microcon-
trollers available from Motorola, the applications for these powerful devices are endless.
ANTOMC13.QXP.13019561 9/12/03 7:18 PM Page 460

460 CHAPTER 13 MICROCONTROLLERS

STUDY QUESTIONS
1. List five real-world quantities or items that require an analog classification.
2. List five real-world quantities or items that may be classified by a single digital bit.
3. Why is A/D conversion required in a real-world control system?
4. Why are there so many models of Motorola microcontrollers?
5. Why can’t the microprocessor do anything by itself?
6. Why would a microcontroller be unsuitable as the brains in a new personal computer?
7. In addition to the Motorola and Intel microcontrollers, what other devices are avail-
able? Search the Web for microcontrollers and make a list.
8. Although a microcontroller contains an internal A/D converter, it has no D/A con-
verter. How does the microcontroller create an analog output voltage?
9. Research the features of the Intel 8051 microcontroller. Which Motorola microcon-
troller does it most closely resemble?
10. If a microcontroller has many of the features found in a microprocessor-based system,
why are these systems still being built?
11. List five applications that would require a microprocessor for control and five that a
microcontroller could handle.
12. Consider the features of the 68HC11. Which features might be used if the 6811 was
controlling a heart-rate monitor? Which might be used in a temperature-control unit?
13. Why use a microcontroller in a computer keyboard instead of a microprocessor?
14. Explain how the internal functions of a microcontroller (A/D converter, timer, PWM,
etc.) might be used in the following systems:
a) burglar alarm
b) laser printer
c) children’s toy with flashing lights, buttons, and speaker for sounds.
15. How might two microcontrollers be used together?
16. What are some differences between the 8-bit and 16-bit microcontrollers?
17. How does a microcontroller provide multiple A/D channels with only one internal
A/D converter?
18. What are some examples of dedicated microcontrollers?
19. What are some differences between the 16-bit and 32-bit microcontrollers?
20. What is lacking from the M*CORE microRISC engine that is typically found in RISC
architecture?
21. Which 32-bit microcontroller family offers embedded PowerPC architecture?
22. How might a microcontroller by used in the calculator project?
23. Visit http://www.jameco.com or any other electronic parts supplier and search for mi-
crocontrollers. What types are available? What do they cost?
ANTOMC13.QXP.13019561 9/12/03 7:18 PM Page 461

STUDY QUESTIONS 461

24. Consider two different companies, one manufacturing a microprocessor-based circuit


board and the second using a microcontroller. In each company, what are the advan-
tages or disadvantages of simply throwing a non-working board away compared to
spending time troubleshooting the board?
25. If possible, take the keyboard of a personal computer apart and locate the internal mi-
crocontroller (if there is one). Who makes it? What other circuitry is present?

Anda mungkin juga menyukai