Professional Documents
Culture Documents
Introduction to Microcontrollers
1.0
INTRODUCTION
Creating applications for the microcontrollers is different than any other development job in
electronics and computing. Before selecting a particular device for an application, it is important
to understand what the different options and features are and what they can mean with regard
to developing the application.
The purpose of this chapter is to introduce the concept of a microcontroller, present
features of microcontrollers and its applications. The reminder of the book will go through and
present different types of microcontrollers and also programming and interfacing techniques
of microcontroller, mainly 8051, in detail.
1.1
EMBEDDED CONTROLLER
1.2
MICROCONTROLLER
A controller is used to control some process. At one time, controllers were built exclusively
from logic components, and were usually large, heavy boxes. Later on, microprocessors were
1
Microcontrollers
used and the entire controller could fit on a small circuit board. This is still commonone can
find many controllers powered by one of the many common microprocessors (including Zilog
Z80, Intel 8088, Motorola 6809, and others).
As the process of miniaturization continued, all of the components needed for a controller
were built right onto one chip. A one chip computer, or microcontroller was born. A CPU built
into a single VLSI chip is called microprocessor. A digital computer having microprocessor as
the CPU along with I/O devices and memory is known as microcomputer.
A microcontroller is a highly integrated chip which includes, on one chip, all or most of
the parts needed for a controller. The microcontroller could be called a one-chip solution. It
typically includes: CPU (central processing unit), RAM (Random Access Memory), EPROM/
PROM/ROM (Erasable Programmable Read Only Memory), I/O (input/output)serial and
parallel timers interrupt controller.
By only including the features specific to the task (control), cost is relatively low. A
typical microcontroller has bit manipulation instructions, easy and direct access to I/O (input/
output), and quick and efficient interrupt processing. Microcontrollers are a one-chip solution
which drastically reduces parts count and design costs. Figure 1.1 shows the block diagram of
a typical microcontroller.
SP
I/O
Port
Timer/Counter
ACC
I/O
Port
Register(s)
Internal
RAM
Internal
ROM
Interrupt
circuits
Clock
Circuit
ALU
Program Counter
Figure 1.1
dharm
d:\N-MICRO\MIC1-1
Introduction to Microcontrollers
1.3
MICROCONTROLLER FEATURES
Instruction decode
Program
ROM
Data
Variable
RAM
Addr
Ctrl
Memory
Interface
unit
Processor
and built-in
registers
Stack
RAM
Figure 1.2
dharm
d:\N-MICRO\MIC1-1
Von-Neuman Architecture
Microcontrollers
HARVARD ARCHITECTURE
Microcontrollers based on the Harvard Architecture have separate data bus and an instruction
bus. This allows execution to occur in parallel. As an instruction is being pre-fetched,
the current instruction is executing on the data bus. Once the current instruction is complete,
the next instruction is ready to go. This pre-fetch theoretically allows for much faster execution
than Von-Neuman architecture, but there is some added fabrication complexity. Figure 1.3
shows the Harvard Architecture.
Control space
Data
Addr
Instruction
decode
Ctrl
Register
space
Program
ROM
PC stack
Data
Processor and
register interface
Figure 1.3
Addr
Ctrl
Harvard Architecture
CISC
Almost all of todays microcontrollers are based on the CISC (Complex Instruction Set Computer)
concept. The typical CISC microcontroller has well over 80 instructions, many of them very
powerful and very specialized for specific control tasks. It is quite common for the instructions
to all behave quite differently. Some might only operate on certain address spaces or registers,
and others might only recognize certain addressing modes.
The advantages of the CISC architecture is that many of the instructions are macrolike, allowing the programmer to use one instruction in place of many simpler instructions.
RISC
The industry trend for microprocessor design is for Reduced Instruction Set Computers (RISC)
designs. This is beginning to spill over into the microcontroller market. By implementing fewer
instructions, the chip is able to implement some performance enhancing features. The benefits
of RISC design simplicity are a smaller chip, smaller pin count, and very low power consumption.
Among some of the typical features of a RISC processor-Harvard architecture allows
simultaneous access of program and data, and overlapping of some operations for increased
processing performance, Instruction pipelining increases execution speed, Orthogonal
(symmetrical) instruction set for programming simplicity: allows each instruction to operate
on any register or use any addressing mode: instructions have no special combinations,
exceptions, restrictions, or side effects
dharm
d:\N-MICRO\MIC1-1
Introduction to Microcontrollers
SISC
Actually, a microcontroller is by definition a Reduced Instruction Set Computer. It could really
be called a Specific Instruction Set Computer (SISC). The [original] idea behind the
microcontroller was to limit the capabilities of the CPU itself, allowing a complete computer
(memory, I/O, interrupts, etc) to fit on the available chip. At the expense of the more general
purpose instructions that make the standard microprocessors (8088, 68000, 32032) so easy to
use, the instruction set was designed for the specific purpose of control (powerful bit
manipulation, easy and efficient I/O, and so on).
1.3.3 Advanced Memory Options
EEPROM (Electrically Erasable Programmable Read Only Memory)
Many microcontrollers have limited amounts of EEPROM on the chip. EEPROM seems more
suited (because of its economics) for small amounts of memory that hold a limited number of
parameters that may have to be changed from time to time. This type of memory is relatively
slow, and the number of erase/write cycles allowed in its lifetime is limited.
FLASH (EPROM)
Flash provides a better solution than regular EEPROM when there is a requirement for large
amounts of non-volatile program memory. It is both faster and permits more erase/write cycles
than EEPROM.
BATTERY BACKED-UP STATIC RAM
Battery backed-up static RAM is useful when a large non-volatile program and DATA space is
required. A major advantage of static RAM is that it is much faster than other types of nonvolatile memory so it is well suited for high performance application. Also there are no limits
as to the number of times that it may be written to so it is perfect for applications that keep
and manipulate large amounts of data locally.
FIELD PROGRAMMING/REPROGRAMMING
Using nonvolatile memory as a place to store program memory allows the device to be
reprogrammed in the field without removing the microcontroller from the system that it controls.
One such application is in automotive engine controllers. Reprogrammable non-volatile program
memory on the engines microcontroller allows the engine controller program to be modified
during routine service to incorporate the latest features.
A OTP (One Time Programmable) part uses standard EPROM, but the package has no
window for erasing. Once your program is written into the device with a standard EPROM
programmer, it cannot be erased or modified.
As product design cycles get shorter, it is more important for micro manufacturers to
offer OTPs as an option. This was commonly used for limited production runs before a ROM
mask in order to test code.
Either by encryption or fuse protection, the programmed software is protected against
unauthorized snooping (reverse engineering, modifications, piracy, etc.).
This is only an option on OTPs and Windowed devices. On Masked ROM devices, security
is not neededthe only way to read code would be to rip the microcontroller apart with a
scanning electron microscope.
dharm
d:\N-MICRO\MIC1-1
Microcontrollers
dharm
d:\N-MICRO\MIC1-1
Introduction to Microcontrollers
MULTI-INPUT WAKEUP
The Multi-Input Wakeup (MIWU) feature is used to return (wakeup) the microcontroller from
either HALT or IDLE modes. Alternately MIWU may also be used to generate up to 8 edge
selectable external interrupts. The user can select whether the trigger condition on the pins is
going to be either a positive edge (low to high) or a negative edge (high to low).
1.3.5 Input/Output
UART
A UART (Universal Asynchronous Receiver Transmitter) is a serial port adapter for
asynchronous serial communications.
USART
A USART (Universal Synchronous/Asynchronous Receiver Transmitter) is a serial port adapter
for either asynchronous or synchronous serial communications. Communications using a USART
are typically much faster (as much as 16 times) than with a UART.
SYNCHRONOUS SERIAL PORT
A synchronous serial port doesnt require start/stop bits and can operate at much higher clock
rates than an asynchronous serial port. Used to communicate with high speed devices such as
memory servers, display drivers, additional A/D ports, etc. Can also be used to implement a
simple microcontroller network.
ANALOG TO DIGITAL CONVERSION (A/D)
Converts an external analog signal (typically relative to voltage) and converts it to a digital
representation. Microcontrollers that have this feature can be used for instrumentation,
environmental data logging, or any application that lives in an analog world.
The various types of A/D converters that can be found in microcontrollers are:
SUCCESSIVE APPROXIMATION A/D CONVERTERS
This the most common type of A/D and is used in the majority of microcontrollers. In this
technique, the converter figures out each bit at a time (most significant first) and finds if the
next step is higher or lower. This way has some benefitsit takes exactly the same amount of
time for any conversionit is very common(and therefore very cheap). However it also has
some disadvantagesit is slowfor every bit it takes at least one clock cycle.
DELTA-SIGMA A/D CONVERTERS
This type of A/D converter is found on higher-end DSPs. Delta sigma A/Ds can be broken down
into two main parts.
The modulator which does the A/D conversion and the filter, which turns the output of
the modulator into a format suitable for the microcontroller (or Digital Signal Processor).
The filter comes after the modulator, and this filter is essentially a Digital Signal
Processor block.
FLASH A/D
This is the basic architecture for the fastest category of A/Ds. The flash converter involves
looking at each level that is possible and instantaneously saying what level the voltage is at.
dharm
d:\N-MICRO\MIC1-1
Microcontrollers
This is done by setting up comparators as threshold detectors with each detector being set up
for a voltage exactly 1 LSB higher than the detector below it. The benefit of this architecture is
that with a single clock cycle, one can tell exactly what the input voltage isthat is why it is so
fast. The disadvantage is that to achieve 8-bit accuracy one need 256 comparators and to
achieve 10-bit accuracy one need 1024 comparators. To make these comparators operate at
higher speeds, they have to draw large amount of current, and beyond 10 bits, the number of
comparators required becomes unmanageable.
POLLING
Polling is a software technique whereby the controller continually asks a peripheral if it needs
servicing. The peripheral sets a flag when it has data ready for transferring to the controller,
which the controller notices on its next poll. Several such peripherals can be polled in succession,
with the controller jumping to different software routines, depending on which flags have
been set.
INTERRUPTS
Rather than have the microcontroller continually pollingthat is, asking peripherals (timers/
UARTS / A/Ds / external components) whether they have any data available (and finding most
of the time they do not), a more efficient method is to have the peripherals tell the controller
when they have data ready. The controller can be carrying out its normal function, only
responding to peripherals when there is data to respond to. On receipt of an interrupt, the
controller suspends its current operation, identifies the interrupting peripheral, then jumps to
the appropriate interrupt service routine.
The advantage of interrupts, compared with polling, is the speed of response to external
events and reduced software overhead.
Most microcontrollers have at least one external interrupt, which can be edge selectable
(rising or falling) or level triggered. Both systems (edge/level) have advantages. Edgeis not
time sensitive, but it is susceptible to glitches. Level must be held high (or low) for a specific
duration.
4 bit microcontrollers usually have either a polling or non-vectored type of interrupt
scheme. 8 and 16 bit microcontrollers usually have some type of vectored arbitration type of
interrupt scheme. 32 bit microcontrollers usually will have some type of vectored priority type
of interrupt scheme. One should consult data sheet to make sure type of interrupts available
before designing the project.
MASKABLE AND NONMASKABLE INTERRUPTS
A maskable interrupt is one that can be disable or enable (masking it out means disabling the
interrupt), whereas non-maskable interrupts cant be disable. The benefit of maskable interrupts
is that one can turn off a particular interrupts (for example a UART) during some time critical
task. Then, those particular interrupts will be ignored thus allowing the microcontroller to
deal with the task at hand. Most microcontrollers (as well as most microprocessors) have some
type of Global Interrupt Enable (GIE) which allows to turn off (or ON) all of the maskable
interrupts with one bit. (GIE usually does not effect any NMI)
VECTORED AND NONVECTORED INTERRUPTS
Simple (non-vectored) interrupts is one of the simplest interrupt schemes. Whenever there is
an interrupt, the system needs to check the interrupts (one at a time) to see which peripheral
dharm
d:\N-MICRO\MIC1-1
Introduction to Microcontrollers
has caused the interrupt to occur. The time between the interrupt happening and the time the
service routine is entered depends on how the system designer sets up their ranking. The
peripheral that is checked last takes the longest to process. Most microcontrollers that have
fewer than 3 5 interrupts use this method. The benefit of this is that the system designer can
set the priority. The most important peripheral gets checked first, and you get to decide which
peripheral that is.
Vectored interrupts are easier to set up, but the system designer has less control of the
system. When an interrupt occurs, the hardware interrupt handler automatically branches to
a specific address (called as vector address) depending on what interrupt occurred. This is
much faster than the non-vectored approach described, however the system designer does not
get to decide what peripheral gets checked first.
1.3.6 OTHER SPECIAL FEATURES
WATCHDOG TIMER
A watchdog timer provides a means of graceful recovery from a system problem. System problem
could be a program that goes into an endless loop, or a hardware problem that prevents the
program from operating correctly. If the program fails to reset the watchdog at some
predetermined interval, a hardware reset will be initiated. The bug may still exist, but at least
the system has a way to recover. This is especially useful for unattended systems.
DIGITAL SIGNAL PROCESSORS (DSP)
Microcontrollers react to and control eventsDSPs execute repetitive math-intensive
algorithms. Today many embedded applications require both types of processors, and
semiconductor manufacturers have responded by introducing microcontrollers with on-chip
DSP capability and DSPs with on-chip microcontrollers.
The most basic thing a DSP will do is a MACC (Multiply and Accumulate). The number
of data bits a DSP can multiply and Accumulate will determine the dynamic range (and therefore
the application).
CLOCK MONITOR
A clock monitor can shut the microcontroller down (by holding the microcontroller in reset) if
the input clock is too slow. This can usually be turned on or off under software control.
RESIDENT PROGRAM LOADER (RPL)
Loads a program by Initializing program/data memory from either a serial or parallel port.
RPL is convenient for prototyping or trying out new features, eliminates the erase/burn/program
cycle typical with EPROMs, and allows convenient updating of a system even from an offsite
location.
MONITOR
A monitor is a program installed in the microcontroller which provides basic development and
debug capabilities. Typical capabilities of a microcontroller monitor include: loading object
files into system RAM, executing programs, examining and modifying memory and registers,
code disassembly, setting breakpoints, and single- stepping through code. Some simple monitors
dharm
d:\N-MICRO\MIC1-1
10
Microcontrollers
only allow basic functions such as memory inspection, and the more sophisticated monitors
are capable of a full range of debug functions.
Monitors can either communicate with a dumb terminal or with a host computer such
as a PC. Much of the work of the monitor (such as user interface) can be offloaded to the host
PC running a program designed to work with the monitor. This makes it possible to reduce the
size and complexity of the code that must be installed in the target system.
1.4
APPLICATIONS
In addition to control applications such as the home monitoring system, microcontrollers are
frequently found in embedded applications. Among the many uses that you can find one or
more microcontrollers: automotive applications, appliances (microwave oven, refrigerators,
television and VCRs, stereos), automobiles (engine control, diagnostics, climate control),
environmental control (greenhouse, factory, home), instrumentation, aerospace, and thousands
of other uses.
Microcontrollers are used extensively in robotics. In this application, many specific tasks
might be distributed among a large number of microcontrollers in one system. Communications
between each microcontroller and a central, more powerful microcontroller (or microcomputer)
would enable information to be processed by the central computer, or to be passed around to
other microcontrollers in the system.
A special application that microcontrollers are well suited for is data logging. Stick one
of these chips out in the middle of a corn field or up in a balloon, and monitor and record
environmental parameters (temperature, humidity, rain, etc). Small size, low power
consumption, and flexibility make these devices ideal for unattended data monitoring and
recording.
1.5
MICROCONTROLLER TYPES
Microcontrollers come in many flavors and varieties. Depending on the power and features
that are needed, one might choose a 4 bit, 8 bit, 16 bit, or 32 bit microcontroller. In addition,
some specialized versions are available which include features specific for communications,
keyboard handling, signal processing, video processing, and other tasks. The examples of
different types of microcontrlles are given in Tables.
Table 1.0 4 bit Microcontroller
Model (Manufacturer)
Features
dharm
d:\N-MICRO\MIC1-1
Introduction to Microcontrollers
Table 1.0
11
8 bit Microcontrollers
Model (Manufacturer)
Features
8048 (Intel)
8051 (Intel)
6805 (Motorola)
68hc11 (Motorola)
PIC (MicroChip)
dharm
d:\N-MICRO\MIC1-1
12
Microcontrollers
Table 1.0
16 bit Microcontrollers
Model (Manufacturer)
Features
80c196 (Intel)
1.6
UNSOLVED PROBLEMS
1. Write major differences between a microprocessor and a microcontroller.
2. Discuss the evolution of microcontrollers.
3. Write short notes on following microcontroller features:
Fabrication Techniques
Power Management and Low Voltage
Input/Output
Watchdog timer
Monitor
4. What are the applications of microcontrollers?
5. Discuss architectural features of microcontrollers.
dharm
d:\N-MICRO\MIC1-1