Chapter 2 PDF
Chapter 2 PDF
and Microcontroller
Resources
Chapter Objectives
~ :7 43 0 11 8 7 0 8
~~ P2l I P2H I PCH PCl
8 Decoder
~ 14* 4*
,,
4
--,,
8
I INTERNAL BUS
,,
,
,.-----,
-t18 8 8
1
I IR
7 07 0
r 10 I TEMP 1 IIFrom ACC ~
Condition
based I-4--_U..,.8 1=8"7=:t::j~
branch
logic
:/, /
Tr-++~'----q I adjustor
I Decimal
, -'
:
,
L- __
'
I
RD WRAlE EA
Figure 2.1 Functional overview (block diagram) of an exemplary 8048 microcomputer (microcontrolier).
Overview of Architecture and Microcontroller Resources 23
It shows the CPU, clock circuit (oscillator circuit), and reset circuit as in a microprocessor. There is
ntrol and sequencing logic with signals like in a microprocessor. There are flags for the processor
ill as in the microprocessor. Abbreviations used in Figure 2.1 are as follows: PCL-program counter
-er byte; PCH-program counter higher byte register and its 2-bit out bus to program memory in
, 3-bit in 8049 and 4-bit in the 8050 and unextended 805118052 families; P2H-Port 2 higher
ble (4-bit); P2L-Port 2 lower nibble (4-bit); MUX- Data/address multiplexer; IR-instruction
regi ter; ID-instruction decoder; ACC- accumulator latch; A-Accumulator; EA - external address
le signal (to disable use of on-chip ROM when = 1 kB); RESET-signal to reset the CPU when 0;
• ~ AL2 and XTALl-crystal oscillator inputs for the processor clock; PSEN - program store enable
en 0 (means read the byte from external program memory); RD - read the byte from external data
mory; WR - write the byte to external data memory.
ections other than CPU are as follows:
1. Since an MCU can be used as a single-chip microcomputer with embedded program in ROM
there is an extra feature-on-chip ROM. The ROM is 1 kB in 8048 and 2 kB in 8049. An internal
RAM saves the temporary variables and stack. The RAM is 64 Bin 8048 and 128 B in 8049.
/ '\ CHIP/PROGRAM
Vcc
supply
Voo
Standby
- power supply
INT
MICROCOMPUTER
(Microcontroller )
8048 lJ pO.o-PO.7
ADo-AD7
PIN
2. For connecting to additionally needed external memory, there is a program counter lower byte
MAR (memory address register), which can also be used as port (connects through bus buffer)
when the MCU operates in a single-chip mode. There is program counter higher byte MAR which
can also be used as Port 2 (connects through bus buffer) when the MCU operates in single-chip
mode. In this case the Port 2 has the latch and buffer for the port operations.
24 Microcontrollers
3: Since an MCV is expected to interact with the I/O devices (ports) like the key board and LCD
display, it has I/O ports unlike the microprocessor. For example, there is Port 1. It has the latch
and buffer for the port operations in that case.
4. Since I/O devices may be interrupt driven, there is an interrupt service mechanism and interrupt
circuit, priority assignment, and interrupt mask. The mask is to disable an interrupt source during
a specific time critical action(s).
5. Since an MCV may be required to do real time control of events and tasks, there is a program-
mable timer/event counter(s).
The 8048 microcontroller has the following sections.
1. CPU of 8048 to process instruction within the instruction set.
2. Address cum data time multiplexed bus signals ADO to AD7, RD, WR, ALE, and PSEN. In
expended chip mode bus is connected to the external pins for address bus signals ADO to AD7.
When active, the address latch enables signal at pin ALE and the bus separates address signals.
- - --
Whenever ADO to AD7 bus has the data signals, the signals at RD, WR, and PSEN select
data- either reads from data memory or writes to data memory or reads from program memory.
In a single-chip mode, instead of the signals ADO to AD7, the same pins are for bidirectional Port
- -
o
pins-PO.O to PO.7. In a single-chip mode, the RD and WR pins become P3.7, P3.6 pins to
provide bidirectional signals for Port 3.
3. Address bus A8 to A 15 output bits. In single-chip mode, these are the input cum output Port 2
pins-P2.0 to P2.7. In expended mode, it provides output as the external address bus signals A8
to A15.
4. Oscillator. It connects the XT AL 1 and XT AL2 pins.
5. Reset circuit, which connects to RESET pin.
6. ROM 1 kB (EPROM 1 kB in 8748).
7. RAM 64 B (128 in 8049).
8. Interrupt external through !NT pin.
9. An 8-bit timer/even counter
(Contd.)
Overview of Architecture and Microcontroller Resources 25
microcontroller family member has the same basic architecture, but can differ in the number of pins
d the mode of packaging. Further, there are different variants as shown in Tables 1.1 and 1.2 for the
-I and 68HCIlJ12 families. Figures 2.3 and 2.4 show the families of 8051 series and 68HCIlJ12/16
ries and resources in these.
ternal Figure 2.1 shows the internal bus width of 8048 as equal to 8. Similarly, 8051 and 8096
ilies have the 8-bit bus width. A control and sequencing unit activates different sections and subsec-
at different instances, therefore, the same 8-bit bus is used for internally carrying all the data,
e es, and instruction codes. Registers and internal RAMs need only 8-bit addresses.
Bu width equal to 8 is sufficient because two operands of 8 bits each only can be added or subtracted
_ .he ALU of 8048 as well as 8051. A 16-bit operation has to be performed in two separate instruction
__ .e and the 32-bit operation in four cycles .
. IC68HC 11 internal 16-bit address bus accesses in single cycle and that facilitates access to
- = 64 kB. The 8048/8051/8096 facilitates access only in two cycles.
ernal External address bus width (AOto A15) is 16 in 8048/8051 as well as 68HC 11. Therefore,
.ernal address space is 216 = 64 kB. (lkB memory = 1024 B.)
External data bus DOto D7 multiplexes with AOto A7 by time division multiplexing in 8048/8051 as
U as 68HC II. A byte of code or data can be transferred at an instance. The time during which address
h enable (ALE) is active (=1) there is the address at bus. The time during which the ALE is inactive
= 0). there can be the data on the bus (ALE is called ADV (address valid) in 68 HCll).
26 Microcontroiiers
1 8051 Series
T
I I
I I
Unified 64 MB
8-bit data bus program/data
16-bit address bus 8051 with 128 kB internal/external
64 kB ROM external data, extended 16 8MB ROM +8
64 kB external data MBROM MB constants
Timers TO,T1 extented 16 MB
UART, synchronous serial data 256 B 16 bit
internal ROM 4 KB, RAM 128 B internal RAM configurable stack
Two external interrupts pointer
768 B RAM
80251 Intel/Atmel
8051 with 256 B
8/16/32 bit
internal RAM
address space plus timer T2
like 8051 MX
68HC11 /12/16
Familes
r 1 1
8 bit family 16 bit family Family 68HC16
68HC11 with 68HC12 16 bit HC11
variants extended 68HC11 HLL support
0-12 kB ROM 4 MB space programmable
EEPROM 8 channel timers sample hold, 16
ADC or No ADC 16 bit pulse channel queued
64 kB counter ADC,
unified data/ accumlator system integator
program address 12 Ports for
---
space programmable chips.
4 ports 1MB + I MB
68HC11
8051 series ALU 8096 series
ALU 8-bit 8-bit ALU 16-bit 18-bit
operands operands operands
'I'D TJ "I'D
15-
...
...
1\
' '
o 0 ... o ... 8 0 ...
--
'~I 1: 1:1 :1
Instructions: 1,8,
16-bit operands
Instructions: 1,8,
16-bit operands
O~
II \
Instructions: 1,
8,16 or 32-bit
operands
D..
... ADo-AD? external 8 bit multiplexed lower bits
Program memory Program functions and routine in an MeV are mostly in a non-volatile r
only memory (ROM). Table 2.2 gives the exemplary contents at the program memories in the Cl-
based system .
Program Program functions, routines, boot-up program, and interrupt On-chip or extema
memory" service routines for the system after the development phase EPROM or Flash a
is over. Standard macros and functions for program building laboratory test stage
blocks functions, for example for preset delay, for UART masked ROM at ma
communication at the pre-select baud rates; needed library production stage.
functions, for example for finding maximum, minimum,
average, and standard deviation values among the set of
values, for sorting the set of values in descending or
ascending order.
Permanent constants for the bytes for displaying the On-chip EPROM or
pictogram for the companies emblem on LCD display; Flash at laboratory
constants for maximum and minimum limits, for example, test stages, Masked
channels 0 to 99 in a TV remote control, number of ROM at mass
maximum acceptable digits in the phone number when production staqe."
dialing.
Strings for the product version, welcome messages at the On-chip EPROM or
start of the system, messages for system-status display, Flash at laboratory
operational menus for selection (like in press 1 for measuring test stages, masked
voltage, 2 for current, 3 for resistance, and 4 for frequency in ROM at mass
a MCU-based multimeter test equipment), name and contact production staqe."
addresses of the manufacturer.
Modifiable constants and intermediate non-volatile data for On-chip EEPROM
the current values or results for validity date for an account, or Flash."
password, and user ID and present balance in the account,
data and time of last transaction, calibration constants of a
sensor element or telephone numbers in a digital diary.
ta memory Data variables and stacks in an MCV are mostly in a volatile read and write memory
Yi) or registers. Table 2.3 gives the exemplary contents at the data memories in an MCV-based
~ em. (Note that Table 2.2 referred to constants and strings not in internal on-chip program memory
e that can also be at the data memory space.)
Data memory Direct or indirect or both addressable bytes for On-chip RAM
the variables, pointers, look-up table, limited size
array and individually addressable bits.
Stack of all program function program counters
and saved variables.
Device (includes port) control parameters and On-Chip registers
status parameters, the device/port individually (special function
addressable bits. registers in 8051
families) if available,
else on-chip RAM
(Contd.)
30 Microcontrollers
Note: (1) Data memory can have distinct separate address spaces like program for the individual bits and bytes,
for the stack, for the registers and RAM in 8051 families.
(2) In separate address space than the program memory in Harvard memory architecture and in common
address space in Princeton memory architecture.
MCUs mostly have on-chip program memory as the ROM or EPROM or flash and internal RAM and
registers.
Port latch
Port latch 8
Bus buffer
(a) (b)
={i
Port
Port
AMUX Port
~----
Port
l
latch
(d)
Figure 2.6 (a) An 8-bit 10 port. (b) An 8-bit port with the bus buffer. (c) An 8-bit port with a data
direction register bit for each port bit, which sets to either 1 or 0 (in 68HC11/12).
(d) An 8-bit port analog as well digital inputs for either multi-channel ADC or for port
input operations. (e) An 8-bit port with two handshaking signals-STAA for strobe or
acknowledgement signal from the external device and STAS for port to the device
(Section 14.3.1).
Eight-bit port with latch for Port P1 in 8048 and in 8051 classic family members
input or output or 10
operations (Fig. 2.6(a»
Eight-bit port with latch as Port POand P2 in 8048 and in 8051 family members, which are also
well as bus buffer for usable as the for ADo-AD7 and A8-A 15 bus as well as the 1/0 ports
address, data, and control with a latch.
buses (Fig. 2.6(b)) Port PB output port as well as A8-A 15 bus and Port PC for the 1/0
with handshaking mode also usable as ADO-AD7 in expanded
mode in 68HC11.
(Contd.)
32 Microcontrollers
General notes and instructions for using the parallel ports are as follows:
1. One handshaking signal for strobe request from an input device or acknowledgement from an
external output device. The other handshaking signal is port acknowledgement for port ready
signal to the inputting device or port buffer output full signal to an output device.
2. If an OD port is to be used for the input, the l(s) must be first written. This is to bring output stage
transistor to a non-conducting state from the last state, which may be a conducting state when 0
was sent to the output.
It should be noted that an MCU has a few parallel ports usually, 8 bits each. Port bits can also be put
to the alternate uses and the external buses to the interfacing chips.
EEPROM
Case 1: It is assumed that the integrator-l design is such that the output V is maximum when p = 255
and is 0 when p = O.
Case 2: It is assumed that the integrator-2 design is such that the output v is maximum when p = 255
and is - v when p = O.
Figure 2.8 (c) shows the application of the MCV pulse count and control registers for the pulse width
modulation. This is assuming that there is an 8-bit internal PWM output control register,
PWM_CONTROL. Software can write p at its address in the MCV. Let a counter run in a free running
mode and the count value be c at an instant. A PWM output will be obtained by an operation in which
at the port bit or PWM output pin the output is 1 when c > = p, and 0 when c < p.
(256-p)T
/ r-. 256-p
// ! "",~ulse width percentage =~ 100
," I •••
PWM input
----lIINTEGARATOR -1 1
(a)
analog output
0
z~------>
V
o
5001
128 255
pulse width
• P
v
+v
PWM input analog output
-~-~----l---~P
---IINTEGARATOR -21 0
-v
o
-----r------r--------~
50% 100% pulse width
-v
(b)
clock
pulses
PWM
'0' for
I I
I I pulse control duration p.T
~ •• )I I
register
Figure 2.81 (a) PWM output. (b~AnaIOg outputs in two cases as a function of pulse width percentage
and pulse control register parameter p. (c) Application of the MCU pulse count and control
registers for pulse width modulation.
Overview of Architecture and Microcontroller Resources 35
PWM_control register can be an out-compare register (OCR) in an MCV. The OCR can be loaded
value p, which it compares with the count value c in the free running counter. The MeV generate
interrupts-one on c = p and other when c = 0 after c = 255. A program loads the value of p as per
needed width percentage.
The count register can be a PACT (Pulse count accumulator) in an MCV. The PACT is periodically
ed with the modulation parameter such that the interrupts at that instances generate Is and Osat each
_ CT overflow interrupt.
An MCV with on-chip PWM operation is needed in many instrumentation and control related opera-
n for obtaining a DAC facility. It generates the pulse of width percentage as per the bits loaded into
ulse accumulator register or PWM-control. Analog output voltage v generates from an integrator. It
z: 'e the output such that it maps to the decimal value loaded in the register. Many MCV variants have
-chip PWM device and the device is used to generate analog outputs through an external integrator.
'M operations can also be implemented indirectly by using a non-stop, no reset timer.
V at a port pin
Analog GND
-
End of
r---- V·ref= GND
conversion
option 1
~
+~ f--- V~ef programmable ] option 2
->
ctI~
resister
E-
n-bit 'u>
Ql •
ADC -0;:- option 3
register lii ,
-c:
.!!1N r---- Vief programmable
Ol~
~ II resister
! oQl
02
«~
Conversion over'---
interrupt
1
Start of
conversion( s)
In certain MCVs, V;ef is programmable or not programmable but fixed by an external circuit. The
V~ef is fixed and is equal to analog ground potential. In certain MCUs the programmability of the V~ef
become extremely valuable for instrumentation and control related applications, when both the V;ef and
V ~ef are programmable.
An MCV with on-chip ADC operation is needed in many instrumentation and control related opera-
tions. It converts analog input voltage v and gives the digital bits in the output such that the decimal
value for these maps to the signal ratio is [v / (V ;ef - V~ef)]' The converted bits can be latched to a port
or used for control applications. Here, V;ef and V~ef are the analog inputs to the ADC, set such that when
v = V;ef the all output bits = 1 and v = V~ef' all output bits = O.Many MCV variants have on-chip ADC
device and the device accepts multiple analog inputs one by one.
Overview of Architecture and Mir.rocontroller Resources 37
2.3.8 Reset Circuit
Certain processors start like 8051 MCU processing from OxOOOO (OxFFFFOin 80x86). Certain proce -
ors tart from an address as per the bytes programmed earl ier at a fixed memory location. For example,
68HClll12 starts processing from the address defined by the bytes programmed at OxFFFE (caJled
vector address for the reset). The MCUs 68HCll and HCl2 have two start-up addres es. One is as per
power-up reset vector address OxFFFE bytes and the other is as per reset vector at OxFFFC bytes. The
latter is for start after the Reset instruction executes or after a time-out from a watchdog timer occurs.
Reset circuit forces a processor to start the processing of in tructions from a starting address
moothly. Processor inputs should not misread any pin logic state by not letting in the intermediate state
voltage levels. Smooth starts mean without glitches-sharp variations between low voltage and needed
oltage. The intermediate levels must not exist in the MCU, for example, between 0.33 Voo and 0.66Voo,
where Voo is the MCU supply voltage and Vss is the supply negative end, which is tied to the ground
potential.
A push-button switch may also be interfaced with MCU through the reset circuit to start the processor
from the beginning start-up address. When there is a power glitch, the processor reset circuit should let
the processor start smoothly from the beginning and prevent the intermediate voltage levels. In addition,
when a clock monitor detects the MCU slowdown below certain frequencies due to a fault, the reset
must activate.
The reset circuit activates for a few clock cycles and then deactivate to let the MCU processor start
executing the instructions. There is a reset pin (Table 2.1) in the MCU. It becomes input on power-up
and becomes output pin for a few clock cycles to enforce reset state in other interfaced external devices
with the system. The pin finally deactivates after the program execution begins.
Reset circuit (Fig. 2.10(a)) can be an external IC circuit like MAX 6314 and Motorola MC 34064.
ote that on reset, not only the program counter reloads but also the default processor values reload.
A reset circuit or device resets the microcontrollers so that a processor starts smoothly. This means
that the processing of instructions from a starting address prevents the intermediate voltages between
o and 1, and all the processor registers and devices and interfaced devices get the default values. The
tart address on reset is programmable in certain MCUs. Reset activates for a few clock cycles.
INPUT
" Active low for a few clocks cycles
I
r--------,
LTr-------, Reset
Trigger on power up or by a
pushdown button
circuit
MCU
RESET
OUTPUT
Active high for a few clock cycles
(a)
WOTI disable by
Progra mmable WOT writing a code
presca led timerl
interna I counter --+-
clock in put
WOTI
Compare
r-
WOT enable by
writing a code
WOT register
(b)
Figure 2.10 (a) Reset circuit. (b) Watchdog timer device in the MCU.
Consider a system controlling the pressure in a tank in an industrial process. A sume that when the
program starts executing, the pressure transducer inputs work. However, before the de ired pressure is
achieved, the input circuit develops some fault. The controller will continue to boost the pressure in the
tank. The boosting will continue jf the system is not reset. Absence of watchdog time facility can thus be
catastrophic due to tank burst.
Figure 2.1O(b) shows the working of a non-stop timer/counter used as a watchdog timer. V Value at
a reset pin becomes identical to the one expected after a +5V power up or on an external reset signal at
the microcontroller, The watchdog timer is usually programmable. It is like a free running counter with
an output compare register, which on equality situation causes the program counter to be loaded with the
initial value.
A watchdog timer device is a timer provided within the microcontroller, which resets it such that it
starts execution of the instructions from the beginning. The timer initial value, which loads, can be
programmable in certain MCUs. The start address on watchdog timer reset can be programmable in
certain MCUs.
Overview of Architecture and Microcontroller Resources 39
2.3.10 Bit-Wise Manipulation Capability
Figure 2.11 shows the various bit transfer or manipulation instructions. The 8051 family MCU has
powerful bit manipulation capability and has a bit manipulation capability with the carry bit playing th
role of an accumulator. The role is similar to the accumulator A during the ALU operations. A flag ca
be set or reset. A port bit can be set, reset, complemented, transferred or logically operated. The bit ca
perform these operations in a bit-address space.
--- OPERATION--
--- OPERANDS -
Figure 2.11 Bit manipulation operations by a Boolean processing unit in 8051 family.
2.3.12 Timers
Timers are a must for the real time operations in any system (Chapter 6). Figure 2.12 shows the impor-
tant modes of timer functioning in the MCUs.
o Microcontrollers
Clock
Prescaler 8 or 16-bit timer f---- Timeout loverflow
interrupts
Fixed or Real Time Clock
(a)
programmable Interrupts (RTCI)
Timer feature L- __ Output transition or
toggle
I
Free running Pre loadable Resettable Stopable Auto reload
counter (FRC)
(b)
FRC FRC
(e)
A timer counts the equal interval clock pulses from an oscillator circuit. The pulses are used after a
suitable fixed or programmable pre-scaling (division) factor.
1. A timer can be used in different modes.
2. A timer/counter mode runs in a non-stop, reset, and load disabled state. It, therefore, is also used
as a recorder of an actual time (real time) since the start.
3. For example, we capture the time at the start of the swimming and recapture the time at the end of
swimming. The difference gives the time clocked by the swimmer. Similarly, a timer in non-stop,
reset, and load disabled state can be used for capturing the times at the different input instances.
The timer saves the current timer value into an input capture register for use as a time recorder for
an instance of occurrence and for the interval between the two events.
4. We preset a time instance in an alarm and the clock on reaching that time alarms a ring. Similarly,
a timer in non-stop, reset, and load-disabled state can be used for comparing the different
predefined instances for the programmed outputs (Is or Os) or toggled outputs and generates
interrupts on each successful comparison.
5. Use of the timer in another mode as a real time clock is described in the next section. It gives the
repeated interrupts in order to initiate the events at regular intervals.
8051 family MCU has two programmable timers, TOand Tl. The 8052 variants in the family have an
additional timer T2. 8096 family MCU has the two programmable timers, TI and T2. Tl facilitates the
high-speed inputs unit. It captures the time instances into a FIFO and records up to eight events in quick
Overview of Architecture and Microcontroller Resources 41
S::;:::'Ce'~sion.It facilitates the high-speed outputs (HSO) unit. It compares the time instances with t
time instances and initiates the HSO actions. It compares up to 16 channel instances in quit
R::'Ce'~sion.
HClll12 family has a main timer, which is a free running counter (FRC). It is used as inp
e . as real time clock and as out compare modes described above. Motorola family MCUs have
erful unit for real time processing. It is called a timer processing unit (TPU). The 68HC16 has
• ·ith a microprogrammed control unit, control memory, and a library of more than 20 differer
:::functions. This facilitates the fast real time controls because of the separate instruction processin
- d in processing the capture operations and compare operations with the timers .
To timer
--~ Set prescaling factor - +-
i- - - (FRC)
ClK L..- -' Cl K1
RTCI
II RTCI service routine
I
If---~ Update time
number of ticks
Real time clock is an important resource in a microcontroller because using this, an as sets the
_ tern clock and schedules the tasks and time-delay functions. It is an on-chip device made from the
er working in non-reset, non-loadable and non-stop mode. The interrupts from this timer are the real
e clock ticks, which also update time information at certain memory addresses.
In this communication, a byte or frame of bits on the serial Serial synchronous communication
line need not maintain same phase differences between means each byte (or frame of bits)
them. The transmitter does not communicate explicitly or on the serial line needs to maintain
implicitly clock bit to the receiver for synchronisation of same phase differences between
receiver clock in the same phase. An example-mostly in them. The transmitter does
MCUs-the asynchronous communication is in the UART communicate explicitly or implicitly
UART format (Fig. 2.14(a)). Each bit is for a period T, clock bit to the receiver for sync-
which is the reciprocal of a rate called baud rate. (Saud hronisation of the receiver clock
is a German word meaning a drop. The bytes pour on in the same phase. An example-
the line like raindrops). In this format, there is a start mostly in MCUs-the serial bits
bit = 0 after a 1 to 0 transition on the line. After start bit, and the clock bits are sent on two
the eight data bits for the transmitting byte follow, each separate lines. This mode is called
for the interval T. Now, there is 10T UART format. In this synchronous serial communication
format, the next bit is stop bit, which is 1 for a period T. with a separate clock signal.
In addition, there is 11T UART format. In this format, the (Figure 2.14(b)). This mode is also
next bit after data bits and before the stop bit, is a bit for used for interprocessor comm-
error checking or a bit to indicate the meaning of the prece- unication between the systems.
ding 8 bits as an address or data (or instruction or data). Each bit is for the period T, which
It can also be used as parity bit to reflect odd or even is the reciprocal of a rate called
parity in the 8 bits for checking the error due to any of bit rate. The rate is usually express-
the bits being corrupted due to line noise. ed in kbps unit.
Most MCUs have an UART device in two formats, 10T and 11T with programmable baud rate for the
asynchronous serial communication. These also possess a synchronous serial line with accompanying
sycnchronising clock. This facilitates interprocessor transfers.
Advanced MCUs have ALUs with arithmetic logical subunit, auxiliary logic subunit, multiplier subunit,
floating point processing subunit, assembly optimiser, and C compiler. An MCU can have the CAN
module. (CAN means a network with a bus called control area network bus). MCU can have 7-12
PWM Channels for multi-channel analog outputs. There can be communication IIF, 8 or 16 HPI (host
port interface), 6 or more external DMA channels support, two or more standard serial ports, time-
division multiplexed serial ports, multi-channel and bidirectional serial ports. There can be a special
port that has analog input and output with the CODECs. CODEC is used in telecommunication. It is a
unit for digital PCM coding by ADC and other operations and decoding of analog signals by DAC and
other operations at the output and input, respectively.
Overview of Architecture and Microcontroller Resources
10010001
00-07
Start
,...•••
---------------------,. i 10 T format
~:
i i
:
lJl~1 2 3 4 5
I---+--+--
6 7 8
-----+-----.
9 10
11T Format
2 3 4 5 6 7 8 9 10 11
Parity bit (even)
or
parity bit (odd)
or
data or instruction
or
address
(a) indicating bit
Synchronous
10010001
Data
2 3 4 5 6 7 8
2 3 4 5 6 7 8
Shift clock
-ve transition :
of edge :
2 3 4 5 6 7 8
(b)
Figure 2.14 (a) UART communication formats for 8 bits = 10010001. (b) Synchronous serial
communication for 10010001.
ext generation MCUs (Chapter 15) have the 32-bit RISC processor core with CISC instruction et
d on-chip compilation unit. These have super scaling multi-stage integer pipeline (s). They have multi-
entry write buffers. This avoids blocking (waiting) of the processor during the external memory writes.
The 0.13 urn foundry processes deliver 350 to 500+ MHz and over 1 GHz on next generation 0.1 urn
44 Microcontrollers
processes. For example, ARM 11-based families have the instructions sets, which give reduced code
densities. It has the ARM DSP extensions, and SIMD media processing extensions.
SUMMARY
KEY TERMS
DAC: A unit for obtaining analog output using the digital bit at an input or at a register.
Data bus: A bus to carry the data bits or code bits.
Data direction register: A register in which each bit can be programmed to set each bit at a
parallel port as input or output after the programming.
Data memory: A separate memory with adress space separate from the program memory.
EEPROM: Electrically erasable electrically programmable read only memory.
Erase: A process that makes all bits as the 1s.
Free running counter: A counter in non-reset, non-stop and non-loadable state, which
timeouts at regular intervals and interrupts on overflow .
Flash: An EEPROM in which a sector(s) of byte can be era ed simulatenously using the float-
ing gates technology.
Handshaking: A mechanism by which firstly two signals communicate and then a port sends
the latched byte or strobes the byte into it.
Input capture: A mechanism by which a time register captures the instances of the events at an
input pin or at another device and there is interrupt on each capture.
Instruction decoder: A decoding unit attached to the instruction register, which stores the code
just before execution. The unit intiates the 'controller and sequencer' actions to execute the
code.
Integrator: A circuit based on OPAMP and resistor and capacitors to integrate the input up to
a certain time. If its input is PWM output of an MCU, it implements the DAC operation.
Inter-processor communication: A communication (serial sysnchronous) between two
systems.
Internal bus: A bus to carry data byte(s) or code(s) at an instance from one structural unit of
MCU to another.
Internal RAM: A RAM internally available in the MCU for the registers and/or data variables
and stack.
Interrupt mask: A register where a bit can be set or reset to enable or disable a maskable
source of interrupt from the devices or external sources.
Interrupt source: A hardware or software related event, which interrupts the foreground pro-
gram to enable execution of a service routine called interrupt service routine.
Interrupt mechanism: A mechanism by the interrupting sources are serviced in an MCU or
CPU.
10 devices: The devices or ports to latch the bits for further processing by the MCU or to
accept the latched bits.
kbps: Kilo bits per second-a unit to express the rates of bits transfer on a serial line.
Keyboard: A unit which provides interaction to a user when using a computing system.
Laboratory device programmer: A unit to program the on-chip and off-chip CPLDs,
EPROMs, EEPROMS. and flashes.
Masked ROM: A ROM ready to finally install in the system after undergoing a process to
fabricate a mask as per the program and then etch the unetched metal layers in the ROM
memory unit.
LCD display: A liquid crystal based one line or multiline display.
Open drain port: A port with each bit needing external passive or active pull up when interfac-
ing it. It must also be written Is before using the same as an input port.
46 Microcontrollers
(~ R_E_V_IE_W_Q_U__ES_T_IO_N_S ~J
What are the resources available at the 8048 and hence explain the difference in functional over-
view of the 8048 and a microprocessor?
_ Define (a) input port. (b) output port.
- What is a bus cycle? If the internal bus width is 8, then explain why the 16-bit operations take two
bus cycles.
- What is the advantage of having the program memory and data memory at a unified address space
in Princeton architecture?
- \ hat is the advantage of having the program memory and data memory at distinct address spaces
in Harvard architecture?
_ List the benefits of EEPROM and flash.
Vhen should an EEPROM be used and when should a flash be used?
_ Parallel port can be used for short distances, while the serial port can be used for long distances
and remote locations. Why?
_ Internal buses are not serial buses. Explain.
_ Vhat is the advantage of the data and address buses multiplexing at an MCU?
'hat is the advantage of the bus-buffer and port latch multiplexing at an MCU?
'hen should on-chip ports and off-chip ports be used?
_fCUs have the memory mapped I/O operations unlike 80x86. What is the advantage?
'hen do we use a parallel port with and without handshaking signals? List the merits.
- De cribe the different uses of the asynchronous and synchronous serial ports.
_fCUs have a PWM unit in place of the on-chip DACs. Why?
- De cribe the PWM width percentage that is mapped with the bits in an MCU register. If the clock
rate is halved, what happens to the width percentage?
De cribe on-chip multi-channel ADC applications and how the analog input maps with the con-
erted bits.
De cribe reset operation in an MCU. Reset circuitry in the MCU needs special design. Why?
Explain the use of a watchdog timer.
Vhen we use a STOP instruction in a program and the MCU provides for its enabling and dis-
bling, we should disable the STOP instruction execution when using a watchdog timer. Why?
- A watchdog timer timeout period in an MCU is fixed as 2048/ls for 12 MHz CPU clock and we
need timeout 2048 timer, 1024/ls. (Hint: Restart the watchdog timer 1024 times before the expiry
of 2048/ls).
MIen should the watchdog timer be disabled? At what instance and in which application should
'e enable the watchdog timer?
'hat are the uses of a power-down mode in an MCU? When does an MCU run in this mode?
'hat are the applications of the timer in an MCU? Why do the MCUs need at least one timer?
Give an example of the resources in the new generation MCUs.
Li t the applications of an MCU resource.
Explain uses of the open-drain output and quasi open-drain output.
E plain how to obtain a real-time clock in a system.
E plain how you will use a data direction register with a parallel port.
De cribe the synchronous serial port and asynchronous serial port.
Explain an UAR~ port and its operations in lOT and lIT modes.
48 Microcontrollers
(~ P_RA__ C_T_IC_E_E_X_E_R_C_IS_E_S__ ~)
1. Explain the 8048 pins/signals.
2. Advanced MCUs have RISC core, on-chip CISC compiler and caches. What are their applica-
tions? List 10 examples.
3. How many bus cycles for fetch and execution are needed to fetch a 16-bit instruction of 3 byte
long?
4. An MCU has registers, ports, and internal RAM at the unified address space and with the same
set of addressing methods. What is the advantage?
5. An MCU has registers, ports and internal RAM at the non-unified address space (for example.
special function registers and internal RAM between Ox80 and OxFF) and with a different set of
addressing methods (for example, direct and indirect addressing modes for Ox80 - OxFF SFR
and RAM ). What is the advantage?
6. An MCU has a set of 8-bit addresses for each byte and set of 8-bit addresses for the bits in certain
bytes in the RAM and registers, (for example, OxOO-OxFFfor the internal RAM and OxOO-OxFF
for the bits in certain RAM and SFRs). What is the advantage?
7. An MCU has 8-bit addresses for each byte and does not provide for the 8-bit addresses for the bits
in certain bytes in the RAM and registers. What is the advantage?
8. Why can the constants and strings be placed in EEPROM and OTP data-memory space as well as
in masked ROM and program memory space?
9. How do you quantify the parallel port driving capability and portloading capability?
10. A watchdog timer timeout period in an MCU is fixed as 20481ls for 12 MHz CPU clock. If the
CPU clock is operated at 8 MHz, when will be the enabled case watchdog timer timeout?
11. A timer interrupts after 1024 us. Let the pre-scaling factor now set to 16 in place of 1 earlier out
of four possible values (1, 4, 16, and 64). What will be the timeout-overflow intervals now? What
are the four possible intervals for the timeout interrupts?
12. An MCU has a 16-bit PWM pulse accumulator register. How can we get a duty cycle (PWM
width %) be equal to 75%?
13. Give an integrator design when the analog output is 0 at 50% duty cycle, +ve at < 50% and -ve
at> 50%.
14. How does a single timer create the multiple applications and multiple timings in a system?
15. Show the timing diagrams for handshaking signals and input bits at (i) an input port (ii) an output
port (iii) an I/O port.
16. How do we program software codes for a timing operation? (Hint: Use a loop and on enter and
exit from loop, toggle a port bit and set the number of looping cycles such that the desired time
is set.)
17. An MCU has a memory mapped I/O. How will you create eight external ports between OxEFF8
and OEFF.
18. Using multiplexers and demultiplexers, how can there be more ports from two parallel ports given
in an MCU?
19. Let a microcontroller interface four modems. How will we use the TxD and RxD signals of an
asynchronous serial interface in an MCU using two or four parallel port bits?
Overview of Architecture and Microcontroller Resources 49
9. An MCU does not have bit-manipulation instructions and only the byte operations are feasible.
To reset the bit 0 and bit 7, the following operations are needed.
(a) AND with 10000001
(b) XOR with 10000001
(c) XOR with 1111 1111
(d) OR with 10000001 when all the bits were Is earlier
10. EEPROM
(a) is flash also
(b) is for erase at a time of one byte and flash for a sector of bytes
(c) is different from flash
'(d) works identically for erase as well as write
11. A pulse width modulator gives an output pulse width of nl % and after integrator circuit gives 2V
when the pulse accumulator loads Ox40 (= 40H).1t gives the width n2% and -2V when the pulse
accumulator loads Ox80 (= 80H). The nl and n2 are
(a) 0 and 50 (b) -2/25 and +2/25
(c) 50 and 100 (d) 25 and 75
12. A single reference input ADC operated on 5V power supply input to its circuit and gives an output
of 0000 1000. When input is 50 mV and 0000 1001 when input is 56.25 mY. It can measure
maximum
(a) 1.6V
(b) 3.2V
(c) 5V
(d) maximum cannot be determined with this much information alone
13. An 8-bit auto reload timer is loaded to an initial value of 40. It is given an input at the start of a
race from a clock of 8 MHz after pre-scaling by a factor of 64. Now, the timer will overflow
(timeout) in
(a) (256 - 40) us (b) every (40/64) us
(c) every (256 - 40)/8 us (d) (40/8) us
14. A byte 10011110 is sent on an asynchronous UART in lOT periods where T determines the baud
rate of 9600. For how much minimum interval from the first start transition will there be 1s when
this byte is sent twice successively with a gap of 100 us,
(a) (12 x 104 +100) us (b) (11 x 104 +100) us
(c) (10 x 104 +100) us (d) (16 x 104 +100) us
15. A watchdog timer is loaded 2048 in 8051. It is reloaded when the program was running after 1000
us. Watchdog timer will reset the MCU in
(a) 4096 us (b) cannot reset when reloaded
(c) 1000 us (d) 3048 us
16. A free running counter is driven by 16 us period inputs. On the start of a race, its content was
captured and 16384 (= 0100 0000 0000 0000). At the stop ofthe race its contents were captured
again and showed 65530 ( = 1111 1111 1111 1010). The race period is given by the formula
(a) 16 x (65530 - 16384)
(b) 16 x [(65530 - 16384) + 65536 x n]
(c) 16 x [(65536 - 16384 + 65530) + 65536 x n]
(d) 16 x n x (65530 - 16384), where n is the number of times it overflows