CHAPTER 13
Microcontrollers
OBJECTIVES
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
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?
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
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
ROM EEPROM
RAM
CPU
core Parallel I/O
Timer
Analog
out
PWM filter
Microcontroller
Digital
PWM
(b) Microcontroller-based system
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.
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
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
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)
Bus A/D
RAM ROM EEPROM Flash Serial Frequency Converter PWM
Family (bytes) (bytes) (bytes) (bytes) (channels) Timers (MHz) (channels) (channels) I/O
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
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.
Mode
PA0-PA7 Port A Timer system
control
68HCII
CPU
Interrupt
PC0-PC7 IRQ
Port C Address/data logic
EEPROM
PE0-PE7 RAM
Port E A/D converter
V ref
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.
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
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.
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:
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
Bus A/D
RAM ROM EEPROM Flash Serial Frequency Converter PWM
Family (bytes) (bytes) (bytes) (bytes) (channels) Timers (MHz) (channels) (channels) I/O
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
;
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
Inter-
module
bus
(b) Analog to digital converter
FIGURE 13.3 68HC16 peripherals
ANTOMC13.QXP.13019561 9/12/03 7:18 PM Page 457
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
Y port
Immediate PC Branch
MUX Inc. adder
Barrel shifter
Multiplier
Divider
Instruction
decode
MUX MUX
Instruction
pipeline
Adder/Logical
priority encoder / Zero detect
result MUX
SUMMARY 459
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
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