Microcontrollers
RoboCamp `09
Embedded Systems
An embedded system is a special-purpose computer system designed to perform
one or a few dedicated functions.
In contrast, a general-purpose computer, such as a personal computer, can do
many different tasks depending on programming.
A wide variety of the electronic devices we use today come under embedded
systems.
From a simple toy car ,traffic lights to cell phones but of different complexity.
Since the embedded system is dedicated to specific tasks, design engineers can
optimize it, reducing the size and cost of the product, or increasing the reliability
and performance.
Hence the Microcontroller.
Why Microcontrollers?
A microcontroller is a complete
microprocessor system built on a
single IC.
Microcontrollers were developed to
meet a need for microprocessors to be
put into low cost products.
Building a complete microprocessor
system on a single chip substantially
reduces the cost of building simple
products, which use the
microprocessor's power to implement
their function.
By reducing the size and cost
compared to a design that uses a
separate microprocessor, memory, and
input/output devices, microcontrollers
make it economical to digitally control
even more devices and processes.
Microcontroller
So a microcontroller combines onto the same microchip :
The CPU core
Memory (both ROM and RAM)
Some parallel digital I/O
Peripherals like ADC ,SPI etc
The Microcontroller is a simple microprocessor which just acts like a computer
doing what it is programmed to do.
The program is stored in the Flash memory.
Blocks of a Microcontroller
CPU core
This is the processing unit which executes the program.
Flash Memory
The place where the program is stored. This is read by the CPU core and executes each
instruction.
Non-volatile (remains even after device power off)
SRAM
RAM used by the CPU to store temporary variables.
Volatile
EEPROM
ROM for storing finished results or data for future use.
Non-volatile
I/O ports
Digital ports used for input/output to control leds etc
Peripherals
ADC
Timers
AVR Microcontrollers
8 –bit
•
RISC
•
Mixed Harvard
•
architecture
•One of the first
microcontroller
families to use
on-chip flash
memory for
program storage,
as opposed to
one time
programmable
ROM.
Atmega8
16K Bytes of In-System Self-programmable Flash program memory
512 Bytes EEPROM
1K Byte Internal SRAM
Operating voltages 3.3v-5.5v
Internal calibrated oscillator 1,2,4,8Mhz
Two 8 bit Timers/ Counters
One 16 bit timer/ counter
10 bit ADC
Analog Comparator
Two wire interface (I2C bus)
Connects to external devices that talk through this bus, for eg SRF-04 sonar rangers
SPI serial interface
A serial protocol/ standard for talking to external devices, developed by Motorola. Analog
devices’ accelerometers use this interface
Programmable serial USART
Pin-out
Reset( idealy high, pull to low to
reset)
ADC[0-5] ADC input
Vcc, Gnd power
Avcc, Aref ADC
Hardware Requirements
USB programmer
Used to transfer program from the computer to the microcontroller using USB port
Power Supply
Through a 5v regulator
Simple connectors
Push button
Leds,resistance,capacitors
Basic I/O port configuration
Use I/O ports, to write values to port pins and read values from them.
Glowing LED or activating/enabling external circuits by writing a high or low to
them.
Readings states from sensors.
Ports and Port Pins
4 I/O ports: Port A, B, C, D also denoted as PA, PB,
PC, PD
Each port has 8 lines that can be independently set as
H/L
Each of the 8 lines can be configured independently as
an input or an output pin
The above feature is called True Read Modify Write
Functionality
Pin drivers are strong enough to drive LEDs directly
All pins have voltage invariant internal pull up resistors
Each of them can be individually pulled up as H/L
Registers Associated With Ports
Each port is associated with 3
registers: The data registers
(PORTa), the data direction
register (DDRa) and the Input
pin register (PINa)
Each port pin, PA3 for eg, is
associated with 3 pins: DDa3,
PORTa3, PINa3
While programming the
letters are capped.
Example
Peripheral Programming
Important Registers to be considered while using peripherals
Control register
Used to specify mode of operation, control interrupts
Status register
Contains interrupt flags and other flags indicating state of operation
Data register
Contains end data,finished results
ADC
10 bit successive approximation ADC
Reference voltage provided by
AVcc pin = Vcc or 5v
AREF = external voltage reference pin
2.56 V (internal reference)
Runs in Single Conversion Mode or Free Running Mode