Microcontrollers
Microcontroller Vs Microprocessor
There are notable differences between the internal architecture of
microprocessors and microcontroller, given as follows.
i) Microprocessor consists of only a central processing unit (CPU) only,
whereas microcontroller contains a CPU, memory (such as RAM, ROM,
EEPROM) and I/O peripherals like I/O ports, ADC, timer etc. integrated into
one chip.
ii) Microprocessors are widely used in personal computers and microcontrollers
are used in embedded systems.
iii) Microprocessor uses an external bus to interface to RAM, ROM, and other
peripherals, on the other hand, Microcontroller uses an internal controlling bus.
iv) Microprocessors are based on Von Neumann model Microcontrollers are
based on Harvard architecture.
v) Microprocessor is complicated and expensive, with large number of
instructions to process but microcontroller is inexpensive and straightforward
with fewer instructions to process.
Note: Nowadays microprocessors are called general purpose processors,
are designed for general purpose computers such as PCs or workstations.
These processors have high computational speed, also has on chip cache
and DMAs.
Microcontrollers in Embedded Systems
An embedded system is a microcontroller or microprocessor (mostly
microcontroller) based system which is designed to perform a specific task.
Typically, in a microcontroller based embedded system, the microcontroller
ROM is burned with a purpose for specific functions. So, in an embedded
system, typically only one application software is burned into ROM.
Example for embedded system are Keyboard, Printer, Modem, Mouse,
Video games, Remote controller, Air bag, ABS, Fax machine, Microwaves etc.
Although microcontrollers are the preferred choice for many embedded
systems, some time a microcontroller is inadequate for the task. For this reason,
in recent years many manufactures like Intel, Freescale semiconductors etc.,
have been developed many microprocessors for this high end of the embedded
market. Optimized general purpose microprocessor designed for embedded
market is available, known as high end embedded processors.
Overview of AVR family of Microcontrollers
AVR is a family of microcontrollers developed since 1996 by Atmel
Corporation, later acquired by Microchip Technology in 2016. The basic
architecture of AVR was designed by two students of Norwegian Institute of
Technology (NTH), Alf Egil Bogen and Vegard Wollan, and then was bought
and developed by Atmel in 1996.
There are many kinds of AVR microcontroller with different attributes.
Except for AVR 32, which is a 32-bit microcontroller, AVR are all 8bit
microcontrollers, meaning that the CPU in microcontroller can work on only 8-
bit of data at a time. AVR are generally classified into four broad groups: Mega,
Tiny, Special purpose, and classic. Here we discuss mostly about Mega family
because these microcontrollers are widely used.
AVR Features
The AVR is an 8-bit RISC (Reduced Instruction Set Computer) single
chip microcontroller with Harvard architecture that comes with some standard
features such as on-chip program ROM, data RAM, data EEPROM, timers and
I/O ports. Most AVRs have some additional features like ADC, PWM and
different kind of serial interface such as USART, SPI, CAN etc.. Internal block
diagram of a typical AVR microcontroller is given below
Note: Harvard architecture is computer architecture with
separate storage and signal pathways for instruction and data.
i) AVR Microcontroller Program ROM
In microcontrollers, ROM is used to store programs (codes) and for
that reason it is called program or code ROM. Although the AVR has 8M
(megabytes) of program ROM space, size of the ROM can vary from 1K to
256K, depending on the family member. Program ROM is a flash memory,
can be erased in seconds compared to the 20 minutes or more time needed
for UV-EPROM.
ii) AVR microcontroller data RAM and EEPROM
In AVR microcontrollers RAM is used to store data. The AVR
has a maximum of 64K Bytes of data RAM space. Data RAM space
has three components, general purpose registers, I/O memory and
internal SRAM. There are 32 general purpose registers in all of the
AVRs, but SRAM’s and I/O memories size varies from chip to chip.
In AVR we also have small amount of EEPROM, to store critical data
that does not need to be changed very often.
iii) AVR microcontroller I/O pins
The AVR can have 3 to 86 pins for I/O. The number of I/O pins
depends on the number of pins in the package itself. The number of
pins of the AVR package goes from 8 to 100 at this time. AT90S2323
is an 8-pin microcontroller with 3 pin dedicated for I/O. ATmega1280
is an 100 pin microcontroller with 86 pins for I/O.
iv) AVR microcontroller peripherals
Most of the AVRs come with ADC (Analog to Digital
Converter), timers and USART (Universal Synchronous
Asynchronous Receiver Transmitter) as standard peripherals. ADC in
microcontroller is 10-bit and the number of ADC channels in AVR
chip varies and can be up to 16. The AVR can have up to 6 timers
besides the watchdog timer.
AVR architecture and Assembly language Programming
A detailed knowledge of the architecture of a microcontroller is
necessary for programming in assembly language. Here in this session
we will discuss about different kinds of memory, instructions used in
assembly language programming, status registers etc.
AVR Memory organization
AVR has two different kinds of memory, Code memory and data
memory, which are classified as follows. From here onwards we can
take any one of the microcontroller in AVR family for the purpose of
discussion, we will focus on ATmega32 since it is powerful, widely
available and used.
Program memory
Normally microcontrollers are used in special purpose devices, program
memory or code memory in a microcontroller is the place to store
application program. It is a flash memory where programs content are
saved as a chunk of two bytes known as a word. Taking ATmega32 as an
example, program memory is 32KB. Memory mapping is done such that
the address of the first word being 0x0000 and that of the last word
0x3FFF.
Data Memory
As name indicated data memory is the space for storing data. Data memory
is composed of three parts
i) General purpose Registers (GPRs)
AVR microcontrollers have 32 eight bit general purpose registers
(GPR), given as R0, R2, R3………R30, R31. These GPRs are like
accumulators in microprocessor, used in all arithmetic and logical
instructions (Arithmetic and logical unit takes data from GPR). GPRs are
used for storing data which is to be processed or an address pointing to the
data to be fetched. Addressing of this registers starts from 0x0000 (R0) and
ends with 0x001F (R31).
ii) I/O Memory (Special function registers)
/O Memory or Special function registers are registers dedicated to
specific functions such as status register, I/O ports, timers, Serial
Communication, ADC and so on. The AVR /O memory is made of 8 bit
registers. Size of this memory can vary from chip to chip depending on the
number of peripheral functions supported and the pin numbers. In AVR
with more than 32 pins there is also an extended I/O memory which
contains registers for controlling extra port and extra peripherals. In
ATmega32 there is a 64 Byte I/O memory or special function registers
involved which are holding 16 bit address in between 0x0020 to 0x0057.
iii) Internal data SRAM
Internal data SRAM is widely used for storing data and parameters by
AVR programmers and C compilers. Generally, this is called scratch pad.
Each location of the SRAM can be accessed directly by its address. Each
location is 8 bit wide with a 16 bit address. Size of SRAM can vary from
chip to chip. In the case of ATmega32 SRAM is 2Kbytes.
iv) EEPROM
The AVR has an EEPROM memory that is used for storing data.
EEPROM does not lose its data when power is off, whereas SRAM does.
So, the EEPROM is used for storing data that should rarely be changed and
should not be lost when the power is off. ATmega32 contains 1024 bytes of
data EEPROM memory. It is organized as a separate data space. The
EEPROM data bytes are addressed linearly between 0x0000 to 0x03FF.
Dr. Bhagyaraj .C
St.Marys College, S. Bathery