0% found this document useful (0 votes)
11 views

Microcontrollers

Introduction to micro controller
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Microcontrollers

Introduction to micro controller
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

TOPICS

• General MCU Components


Microcontroller Components
The processor core (CPU) is the main part of any
microcontroller
• A basic CPU architecture is depicted in Figure
above It consists of the data path, which
executes instructions, and of the control unit,
which basically tells the data path what to do.
Arithmetic Logic Unit
At the core of the CPU is the arithmetic logic
unit (ALU), which is used to perform
computations (AND, ADD, INC, . . . ). Several
control lines select which operation the ALU
should perform on the input data.
• The ALU takes two inputs and returns the
result of the operation as its output
Source and destination are taken from registers
or from memory. In addition, the ALU stores
some information about the nature of the result
in the status register (also called condition code
register)
• Z (Zero): The result of the operation is zero.
• N (Negative): The result of the operation is negative
• O (Overflow): The operation produced an overflow, that is,
there was a change of sign in a two’s complement
operation.
• C (Carry): The operation produced a carry.
Register File
• Small storage locations nearest the CPU used
for storing the data and instructions that are
nearest to being calculated by the ALU
• Register file contains the working registers of
the CPU. It may either consist of a set of
general purpose registers
General purpose Registers
It allow developers and programmers to use
them as they are not detrimental to the
processor (spare and unused). They have no
specific roles and are often addressed as R0, R1
etc.
Dedicated Registers
• Program Counter :an incrementing counter
that keeps track of the memory address of
which instruction is to be executed next.
• Memory Address Register (MAR) : holds the
address in memory of the next instruction to
be executed
• Memory Buffer Register (MBR)
a two way register that holds data fetched from
memory (and ready for the CPU to process) or
data waiting to be stored in memory
• Current Instruction register (CIR)
a temporary holding ground for the instruction
that has just been fetched from memory
• Accumulator Register (ACC)
holds the data result of a current calculation
Instruction cycle
is the basic operational process of a computer. It
is the process by which a computer retrieves a
program instruction from its memory,
determines what actions the instruction
dictates, and carries out those actions.
Execute Cycle
Stack Pointer
The stack is a portion of consecutive memory in
the data space which is used by the CPU to store
return addresses and possibly register contents
during subroutine and interrupt service routine
calls. It is accessed with the commands PUSH
(put something on the stack) and POP (remove
something from the stack).
To store the current fill level of the stack, the
CPU contains a special register called the stack
pointer (SP), which points to the top of the stack
Control Unit
It determine which operation should be executed
next and to configure the data path accordingly.
• To do so, another special register, the program
counter (PC), is used to store the address of the
next program instruction. The control unit loads
this instruction into the instruction register (IR),
decodes the instruction, and sets up the data path
to execute it. Data path configuration includes
providing the appropriate inputs for the ALU
(from registers or memory), selecting the right
ALU operation )
Instruction Set
The instruction set is an important characteristic of
any CPU. It influences the code size, that is, how
much memory space your program takes.
• RISC: take only one or a few clock cycles to
execute, small and fixed code size with
comparatively few instructions and few
addressing modes. As a result, execution of
instructions is very fast.
• CISC: The CISC architecture is characterized by its
complex microcode instructions which take many
clock cycles to execute.
Execution Speed
The execution speed of an instruction depends
on several factors. It is mostly influenced by the

• complexity of the architecture


• Word size
• the oscillator frequency defines the absolute
speed of the execution
Harvard architecture

has separate data and instruction busses, allowing


transfers to be performed simultaneously on both
busses.

Von Neumann architecture

has only one bus which is used for both data transfers
and instruction fetches, and therefore data transfers
and instruction fetches must be scheduled - they can
not be performed at the same time.
Difference
Memory
Volatile Memory
Retains its contents only so long as the system is
powered on.

SRAM
Chip consists of an array of cells, each capable of
storing one bit of information. To store a bit of
information, a so-called flip-flop is used.
DRAM
The number of transistors needed per bit of
information was brought down to one. This, of
course, reduced the silicon area for a given cell
count. So at the same chip size, a DRAM has
much larger storage capacity compared to an
SRAM.
Non-volatile Memory
Type of memory that retain their content even
when power is cut.

ROM
It is the first types of non-volatile semiconductor
memories. As the name implies, you simply
cannot write to a ROM. If you want to use
ROMs, you have to hand the data over to the
chip manufacturer, where a specific chip is
made containing your data.
PROM
Is read-only memory that can be modified once
by a user. PROM is a way of allowing a user to
tailor a microcode program using a special
machine called a PROM programmer
EPROM
Erasable Programmable Read Only Memory

UV light source is needed for erasing


EEPROM
Electrically Erasable and Programmable ROM

• are used quite regularly in microcontroller


applications.
• EEPROMs have their limitations, too: They
endure a limited number of write/erase cycles
only. How many??
Flash
Now, EEPROM seems to be the perfect choice
for non-volatile memory. However, there is one

drawback: It is rather expensive. As a


compromise, Flash EEPROM is available.
Flash is a variant of EEPROM where erasing is
not possible for each address, but only for larger
blocks or even the entire memory (erased ‘in a
flash’, so to speak). That way, the internal logic
is simplified, which in turn reduces the price
considerably.
Digital I/O
I/O pins are generally grouped into ports of 8
pins, which can be accessed with a single byte

access. Pins can either be input only, output


only, or bidirectional, that is, capable of both
input and output.

• As far as digital I/O is concerned, three


registers control the behavior of the pins:
• Data Direction Register (DDR)
Each bidirectional port has its own DDR, which
contains one bit for each pin of the port. The
functionality of a pin (input or output) is
determined by clearing or setting its bit in the
DDR. Different pins of a port may be configured
differently, so it is perfectly okay to have three
pins configured to output and use the other five
as inputs.
• Port Register (PORT)
This register is used to control the voltage level
of output pins. Assuming a pin has been
configured to output, then if its bit in the PORT
register is set, the pin will be high; if the bit is
cleared, the pin will be low.
• Port Input Register (PIN):
The PIN register is generally read-only and
contains the current state (high or low) of all
pins, whether they are configured as output or
as input. It is used to read the state of input
pins, but it can also be used to read the state of
output pins to verify that the output was taken
over correctly. A write to this register generally
has no effect.
Digital Input
The digital input functionality is used whenever
the monitored signal should be interpreted
digitally, that is, when it only changes between
the two states “high” (corresponding to logic 1)
and “low” (corresponding to 0).
• Digital Sampling
Since the digital signal is just a voltage value, the
question arises how this voltage value is
transformed into a binary value within a
register.
• Noise Cancellation
Some controllers provide noise cancellation. If
enabled, the controller samples the pin

• Pull Resistors
Many controllers integrate pull resistors into
their input circuitry
• Digital Output
The digital output functionality is used to set
output pins to given voltage levels. The levels
corresponding to high and low are again
specified by the controller and depend on the
controller’s operating voltage.
Mostly VCC = 5V, the maximum output low
voltage is 0.7 V, and the minimum output high
voltage is 4.2 V.
An output pin generally has to sink or source
current, so we can again distinguish between a
sink output and a source output. The maximum
current ratings discussed in the previous section
apply, so we are talking about 4-20 mA
maximum current
Analog I/O
There are situations in which the actual voltage
of the line transports information, for example
when using a photo transistor as light sensor. In
this aspect ,the following are to be considered.
• Analog Comparator
The simplest way to deal with analog inputs in a
microcontroller is to compare them to each
other or to a known reference voltage.
Analog I/O
There are situations in which the actual voltage
of the line transports information, for example
when using a photo transistor as light sensor
Interrupt Control
Two bits form the main interface to the
interrupt logic of the microcontroller:

• The interrupt enable (IE) bit is set by the


application programmer to indicate that the
controller should call an ISR in reaction to the
event. The interrupt flag (IF) bit is set by the
microcontroller
• whenever the event occurs, and it is cleared
either automatically upon entering the ISR or
manually by the programmer.

• Basically, the IF bit shows that the interrupt


condition has occurred, whereas the IE bit
allows the interrupt itself to occur
• Interrupt Service Routine
The interrupt service routine contains the code
necessary to react to the interrupt. This could
include clearing the interrupt flag if it has not
already been cleared, or disabling the interrupt
if it is not required anymore
• Interrupt Vector Table

• Interrupt Priority and Handling


Polling
is the process where the computer or
controlling device waits for an external device to
check for its readiness or state, often with
low-level hardware.
• In the Polling method, the microcontroller
must "access by himself" the device and “ask”
for the information it needs for processing.
Timers
Example delay. Mostly used in many application.

Typically 8bit or 16bit in many microcontroller


Counter
Each timer is basically a counter which is either
incremented or decremented upon every clock
tick.
Watchdog Timer
The watchdog timer, also sometimes called COP
(computer operates properly), is used to monitor
software execution. The basic idea behind this
timer is that once it has been enabled, it starts
counting down. When the count value reaches
zero, a reset is triggered, thus reinitializing the
controller and
restarting the program.
Reset
The reset is another important feature of
microcontrollers, which are often deployed
under environmental conditions that can lead to
software or hardware failures.
The following are different types of rest
approaches,
• Power-On Reset
The power-on reset (POR) causes a reset
whenever the supply voltage exceeds a certain
threshold level. This ensures that the system is
reset after power-on, thus initializing the
controller.
• External Reset
The external reset is triggered through a usually
dedicated reset pin.
• Internal Reset
Some controllers offer an instruction that causes
a software reset. This can be useful if a data
corruption or some other failure has been
detected by the software
• Brown-Out Reset
It simply puts the controller into its reset state
whenever the supply voltage falls below a given
threshold
Communication Interfaces
Although communication interface modules are
often integrated into the controller and can
therefore be seen as controller components.
Not all MCU supports communication or all
types of communication , it depends on the
particular microcontroller.

Consider the following,


• SCI (UART)
The Serial Communication Interface (SCI)
provides an asynchronous communication
interface (Universal Asynchronous Receiver
Transmitter, UART). The UART module utilizes
two wires, a transmit (TXD) and a receive (RXD)
line, for full- or half-duplex communication.
• SPI
The Serial Peripheral Interface (SPI), is a simple
synchronous point-to-point interface based on a
master-slave principle. It provides full-duplex
communication between a master (generally a
controller) and one (or more) slaves (generally
peripheral devices). The interface consists of
four single ended lines:
• MOSI (Master Out, Slave In): This line is used
by the master to transmit data to the slave.
• MISO (Master In, Slave Out): This line is used
by the slave to transmit data to the master.
• SCK (System Clock): This line is used by the
master to transmit the clock signal.
• SS (Slave Select): This line is used by the
master to select a slave.
• IIC (I2C)
The Inter-IC bus (IIC) is a synchronous bus that
operates on a master-slave principle. It uses two

single-ended wires SCL (Serial Clock Line) and


SDA (Serial Data Line) for half-duplex
communication. The protocol is widely used for
(short distance) communication between one or
more controllers and peripheral devices.

You might also like