The Fundamentals of
Microcontroller
Learning Module 05
Microcontroller Basic
Learning Packet 5.1
Objectives
At the end of the discussion of the course
packet, the students will be able to:
• Discuss the basic principle and functions of
different elements of microcontroller.
Introduction
• Even at a time when Intel presented the first microprocessor with
the 4004 there was already a demand for microcontrollers:
• The contemporary TMS1802 from Texas Instruments, designed for
usage in calculators, was by the end of 1971 advertised for
applications in cash registers, watches and measuring instruments.
• The TMS 1000, which was introduced in 1974, already included
RAM, ROM, and I/O on-chip and can be seen as one of the first
microcontrollers, even though it was called a microcomputer.
• The first controllers to gain really widespread use were the Intel
8048, which was integrated into PC keyboards, and its successor,
the Intel 8051, as well as the 68HCxx series of microcontrollers
from Motorola.
Introduction
Today, microcontroller production counts are in the billions per year, and
the controllers are integrated into many appliances we have grown used
to, like
1. household appliances (microwave, washing machine, coffee
machine, . . . )
2. telecommunication (mobile phones)
3. automotive industry (fuel injection, ABS, . . . )
4. aerospace industry
5. industrial automation
6. Among others
Introduction
Assume that we want to:
1. periodically read the temperature (analog value, is digitized by
sensor; uses 4-bit interface),
2. control heating according to the temperature (turn heater on/off;
1 bit),
3. display the current temperature on a simple 3-digit numeric
display (8+3 bits),
4. allow the user to adjust temperature thresholds (buttons; 4 bits),
and
5. be able to configure/upgrade the system over a serial interface.
Introduction
• So we design a printed-circuit board (PCB) using Zilog’s Z80
processor.
• On the board, we put a Z80 CPU,
• 2 PIOs (parallel I/O; each chip has 16 I/O lines, we need 20),
• 1 SIO (serial I/O; for communication to the PC),
• 1 CTC (Timer; for periodical actions),
• SRAM (for variables),
• Flash (for program memory), and
• EEPROM (for constants).
Introduction
The resulting board layout is depicted in Figure 5.1; as you can see,
there are a lot of chips on the board, which take up most of the
space (euro format, 10 × 16 cm).
Introduction
• A reset button and connectors for the SIO and PIO pins was added, but leave
out the power supply circuitry and the serial connector to avoid cluttering
the layout.
• Incidentally, we could also solve the problem with the ATmega16 board we
use in the Microcontroller lab.
• In Figure 5.2, you can see the corresponding part of this board superposed on
the Z80 PCB.
• The reduction in size is about a factor 5-6, and the ATmega16 board has even
more features than the Z80 board (for example an analog converter)!
• The reason why we do not need much space for the ATmega16 board is that
all those chips on the Z80 board are integrated into the ATmega16
microcontroller, resulting in a significant reduction in PCB size.
ATmega16 board superposed on the Z80
board.
difference between microcontroller and
microprocessor
• A microcontroller is a processor with memory and a whole lot of other
components integrated on one chip.
• The example also illustrates why microcontrollers are useful:
• The reduction of PCB size saves time, space, and money.
• also obvious from their pinouts. Figure 5.3 shows the pinout of the Z80
processor.
• You see a typical processor pinout,
• with address pins A0-A15,
• data pins D0-D7,
• and some control pins like INT, NMI or HALT.
• In contrast, the ATmega16 has neither address nor data pins. Instead, it
has 32 general purpose I/O pins PA0-PA7, PB0-PB7.
a typical processor pinout
• with address pins A0-A15,
• data pins D0-D7,
• and some control pins like
INT, NMI or HALT.
• In contrast, the ATmega16
has neither address nor
data pins. Instead, it has
32 general purpose I/O
pins PA0-PA7, PB0-PB7.
PC0-PC7, PD0-PD7 functions
• PD0 and PD1 can be used as the receive and transmit lines
of the built-in serial interface.
• Apart from the power supply, the only dedicated pins on
the ATmega16 are RESET,
• external crystal/oscillator XTAL1 and XTAL2,
• and analog voltage reference AREF.
controller family
• The first choice a designer has to make is the controller family – it
defines the controller’s architecture.
• All controllers of a family contain the same processor core and hence
are code-compatible,
• but they differ in the additional components
• like the number of timers or
• the amount of memory.
• Different controller families like
• 8051,
• PIC,
• HC,
• ARM to name just a few
Comparison of AVR 8-bit controllers (AVR,
ATmega, ATtiny)
Comparison of AVR 8-bit controllers (AVR,
ATmega, ATtiny)
• Table above shows a selection of microcontrollers of Atmel’s AVR family.
• The one thing all these controllers have in common is their AVR processor core, which contains 32
general purpose registers and executes most instructions within one clock cycle.
• After the controller family has been selected, the next step is to choose the right controller for the job.
• As you can see in Table 5.1 (which only contains the most basic features of the controllers, namely
memory, digital and analog I/O, and interfaces), the controllers vastly differ in their memory
configurations and I/O.
• The chosen controller should of course cover the hardware requirements of the application, but it is also
important to estimate the application’s speed and memory requirements and to select a controller that
offers enough performance.
• For memory, there is a rule of thumb that states that an application should take up no more than 80% of
the controller’s memory – this gives you some buffer for later additions.
• The rule can probably be extended to all controller resources in general; it always pays to have some
reserves in case of unforseen problems or additional features.
Comparison of AVR 8-bit controllers (AVR,
ATmega, ATtiny)
• Of course, for complex applications a before-hand estimation is not
easy. Furthermore, in 32-bit microcontrollers you generally also
include an operating system to support the application and its
development, which increases the performance demands even
more.
• For small 8-bit controllers, however, only the application has to be
considered.
• Here, rough estimations can be made for example based on
previous and/or similar projects.
internal designs of microcontrollers
• The basic internal designs of microcontrollers are
pretty similar. Figure 5.4 shows the block diagram of
a typical microcontroller.
• All components are connected via an internal bus
and are all integrated on one chip.
• The modules are connected to the outside world via
I/O pins.
internal designs of microcontrollers
modules in a microcontroller
• Processor Core: The CPU of the controller. It contains the
arithmetic logic unit, the control unit, and the registers
(stack pointer, program counter, accumulator register,
register file, . . . ).
• Memory: The memory is sometimes split into program
memory and data memory. In larger con-trollers, a DMA
controller handles data transfers between peripheral
components and the memory.
• Interrupt Controller: Interrupts are useful for interrupting
the normal program flow in case of (important) external or
internal events. In conjunction with sleep modes, they help
to conserve power.
modules in a microcontroller
• Timer/Counter: Most controllers have at least one and
more likely 2-3 Timer/Counters, which can be used to
timestamp events, measure intervals, or count events.
• Many controllers also contain PWM (pulse width
modulation) outputs, which can be used to drive motors
or for safe breaking (antilock brake system, ABS).
Furthermore the PWM output can, in conjunction with an
external filter, be used to realize a cheap digital/analog
converter.
modules in a microcontroller
• Digital I/O: Parallel digital I/O ports are one of the main
features of microcontrollers. The number of I/O pins
varies from 3-4 to over 90, depending on the controller
family and the controller type.
• Analog I/O: Apart from a few small controllers, most
microcontrollers have integrated analog/digital
converters, which differ in the number of channels (2-16)
and their resolution (8-12 bits). The analog module also
generally features an analog comparator. In some cases,
the microcontroller includes digital/analog converters.
modules in a microcontroller
• Interfaces: Controllers generally have at least one serial
interface which can be used to download the program and
for communication with the development PC in general.
Since serial interfaces can also be used to communicate with
external peripheral devices, most controllers offer several
and varied interfaces like SPI and SCI.
• Many microcontrollers also contain integrated bus controllers
for the most common (field)busses. IIC and CAN controllers
lead the field here. Larger microcontrollers may also contain
PCI, USB, or Ethernet interfaces.
modules in a microcontroller
• Watchdog Timer: Since safety-critical systems form a major
application area of microcontrollers, it is important to guard
against errors in the program and/or the hardware. The
watchdog timer is used to reset the controller in case of
software “crashes”.
• Debugging Unit: Some controllers are equipped with
additional hardware to allow remote debug-ging of the chip
from the PC. So there is no need to download special
debugging software, which has the distinct advantage that
erroneous application code cannot overwrite the debug-ger.
modules in a microcontroller
• Contrary to CPU, microcontrollers do not contain a MMU
(Memory Management Unit),
• have no or a very simplified instruction pipeline, and
• have no cache memory, since both costs and the ability
to calculate execution times (some of the embedded
systems employing controllers are real-time systems, like
X-by-wire systems in automotive control) are important
issues in the microcontroller market.
modules in a microcontroller
• To summarize, a microcontroller is a (stripped-down)
processor which is equipped with
• memory,
• timers,
• (parallel) I/O pins and
• other on-chip peripherals.
• The driving element behind all this is cost: Integrating all
elements on one chip saves space and leads to both
lower manufacturing costs and shorter development
times.
Advantages of microcontrollers
Advantages of microcontrollers because of the integration
of all elements in one chip:
1. Saves both time and money, which are key factors in
embedded systems.
2. Saves space and leads to both lower manufacturing
costs and shorter development times.
3. Easy upgradability, lower power consumption, and
higher reliability, which are also very important aspects
in embedded systems.
Disadvantages of microcontrollers
• Using a microcontroller to solve a task in software
that could also be solved with a hardware solution
will not give you the same speed that the hardware
solution could achieve.
• Hence, applications which require very short
reaction times might still call for a hardware
solution.
Advantage of microcontroller in applications
•Most applications, however, and in
particular those that require some sort of
human interaction (microwave, mobile
phone), do not need such fast reaction
times,
•so for these applications microcontrollers
are a good choice.
Frequently Used Terms in Embedded System
Microprocessor: This is a normal CPU (Central
Processing Unit) as you can find in a PC.
• Communication with external devices is achieved via a
data bus, hence the chip mainly features data and
address pins as well as a couple of control pins.
• All peripheral devices (memory, floppy controller, USB
controller, timer, etc.) are connected to the bus.
• A microprocessor cannot be operated stand-alone, at
the very least it requires some memory and an output
device to be useful.
Frequently Used Terms in Embedded System
Microcontroller: A microcontroller already contains all
components which allow it to operate stand-alone, and it has
been designed in particular for monitoring and/or control
tasks.
• In addition to the processor it includes memory, various
interface controllers, one or more timers, an interrupt
controller, and last but definitely not least general purpose
I/O pins which allow it to directly interface to its
environment.
• Microcontrollers also include bit operations which allow you
to change one bit within a byte without touching the other
bits.
Frequently Used Terms in Embedded System
Mixed-Signal Controller: This is a microcontroller which can process both digital and
analog signals.
Embedded System: A major application area for microcontrollers.
• the control unit is integrated into the system.
• As an example, think of a cell phone, where the controller is included in the
device.
• This is easily recognizable as an embedded system.
• On the other hand, if you use a normal PC in a factory to control an assembly line,
this also meets many of the definitions of an embedded system.
• The same PC, however, equipped with a normal operating system and used by the
night guard to kill time is certainly no embedded system.
Frequently Used Terms in Embedded System
Real-Time System:
- Controllers are frequently used in real-time
systems, where the reaction to an event has to
occur within a specified time.
- This is true for many applications in aerospace,
railroad, or automotive areas, e.g., for brake-by-
wire in cars.
Frequently Used Terms in Embedded System
Embedded Processor:
- This term often occurs in association with embedded
systems, and the differences to controllers are often
very blurred.
- In general, the term “embedded processor” is used for
high-end devices (32 bits), whereas “controller” is
traditionally used for low-end devices (4, 8, 16 bits).
- Motorola for example files its 32-bit controllers under
the term “32-bit embedded processors”.
Frequently Used Terms in Embedded System
Digital Signal Processor (DSP):
- Signal processors are used for applications that need to process
signals.
- An important area of use are telecommunications, so your mobile
phone will probably contain a DSP.
- Such processors are designed for fast addition and multi-plication,
which are the key operations for signal processing.
- Since tasks which call for a signal processor may also include
control functions, many vendors offer hybrid solutions which com-
bine a controller with a DSP on one chip, like Motorola’s
DSP56800.
Frequently Used Terms in Embedded System
Embedded System:
A special-purpose computer system built into
a larger device.
An embedded system is typically required to
meet very different requirements than a
general-purpose personal computer.