Professional Documents
Culture Documents
AVR Microcontroller
Introduction
Lecture 1
Introduction to AVR
The AVR architecture was conceived by two
students at the Norwegian Institute of Technology
(NTH)
Alf-Egil Bogen (A) and
Vegard Wollan (V)
RISC (R)
1
1/17/2017
Introduction to AVR
The AVR is a Harvard architecture machine with
separate memories and buses for program and data
AVR or Atmel AVR are RISC based family of
microcontroller produced by Atmel Corporations
Device Architecture
Program Execution
Atmel's AVRs have a pipeline design. This means the next
machine instruction is fetched as the current one is
executing. This concept enables instructions to be
executed in every clock cycle
Most instructions take just one or two clock cycles, making
AVRs relatively fast among the eight-bit microcontrollers.
The AVR family of processors were designed with the
efficient execution of compiled C code in mind and has
several built-in pointers for the task.
2
1/17/2017
Device Architecture
Program ROM
ROM is used to store program. AVR microcontroller has
Flash memory for program storage. The program ROM
size can vary from 1K to 256K, depending on the AVR
controller being used.
Data RAM
RAM is space for data storage. Data RAM space has
three components
General Purpose Registers
I/O Memory
Internal SRAM
EEPROM
AVR also have small amount of EEPROM to store
critical data. Unlike RAM the data stored in EEPROM
memory can save stored data when power is cut off.
@ Dr Javaid, M.H Fidai 5 / 54
Features
Current AVRs offer a wide range of features:
Multifunction, Bi-directional General Purpose I/O ports with
configurable, built-in pull-up resistors
Multiple Internal Oscillators
Internal SRAM up to 8 K
3
1/17/2017
Features
8-Bit and 16-Bit Timers
Brownout Detection
Watchdog Timer (WDT)
Multiple Power-Saving Sleep Modes
Motor control (PWM Specific) Controller models
10-Bit A/D Converters, with multiplex of up to 16 channels
Ethernet Controller Support
LCD Controller Support
Low-voltage Devices Operating Down to 1.8v
picoPower Devices
Analog Comparators
Features
A variety of serial interfaces, including
Synchronous/Asynchronous Serial Peripherals (UART/USART)
(used with RS-232, RS-485, and more)
Serial Peripheral Interface Bus (SPI)
Universal Serial Interface (USI) for Two/Three-Wire Synchronous
Data Transfer
IC Compatible Two-Wire Interface (TWI)
CAN Controller Support
USB Controller Support
4
1/17/2017
Why AVR
There are various microcontrollers available from different
vendors like PIC, Motorola , Texas Instruments then why we
choose AVR?
Relatively low cost, ICs available from college Road
Dynamic engineer, IC master, Gharyan Electronics.
Efficient RISC architecture, almost 10 times faster than
CISC
Crystal Clock is not divided and is given directly to the
processor.
8051 divides clock by 12
Microchip divides clock by 4
Motorola divides clock by 3
So generally speaking, an AVR running at 16 MHz
crystal (Max speed of some AVRs) is equivalent to a
192 MHz 8051 or a 64 MHz PIC or a 36 MHz 68HC11
in general, but variations do exist
Why AVR
Although the assembly language of AVR is completely
different from 8051, as that of Motorola and Microchip too,
but:
WINAVR (previously called AVRGCC), A High Quality free
C/C++ compiler is available from the open source (Linux)
community, and it runs in all windows
5
1/17/2017
Why AVR
In system programmable via different methods
A simple low cost trivial to make programming circuit is
required to program most AVRs (Feature also available
in most PIC and some 8051 too)
Latest AVRs support on-chip Boot program this
completely eliminates the need for any external
programming hardware and the AVR can be
programmed through its built-in UART or other
communication ports. (Motorola has been offering this
feature for a long time.)
Why AVR
Most AVRs have built-in 10 to 16-bit PWM channels
generated automatically by timers. Number of channels
ranges from 2 to 6
Most AVRs have built-in 10- bit ADC and MUX with
number of channels ranging from 4 to 8
Large variety of Flash Memory ranging from 1KB to 128
KB
Large variety of SRAM ranging up to 4 KB
Built-in EEPROM support up to 4 KB
I2C and SPI synchronous serial communication for short
distance networking of microcontrollers and other
peripherals DACs, ADCs, Flash memory, MP3 decoder
ICs etc.
6
1/17/2017
Different AVRs
Size
Features
Different AVRs
AVRs are generally classified in four broad groups
tinyAVRs
1-8 kB program memory
8-20-pin package
Limited peripheral set
megaAVRs
4-256 kB program memory
28-100-pin package
Extended instruction set and peripheral set
7
1/17/2017
Different AVRs
XMEGA AVRs
16-384 kB program memory
44-100 pin package
Software Required
Software we are going to use are
1. AVR Studio
8
1/17/2017
Software Required
AVR Studio
AVR Studio is the Integrated Development Environment (IDE)
for developing 8-bit AVR applications in Windows
Many other software are also available for the purpose like
MikroC you can use any of them
The greatest advantage of AVR Studio is that it is provided by
Atmel as a freeware
AVR Studio provides a complete set of features including
debugger supporting run control including source and
instruction-level stepping and breakpoints; registers, memory
and I/O views; and target configuration and management as
well as full programming support for standalone
Debugging is mostly not available in other software but they do
have some exciting features which AVR Studio lacks.
Software Required
WinAVR
It is compiler for C/C++
It integrates with AVR Studio
Open Source software can be downloaded from web (It is
packaged with AVR Studio 5 and above so no need for separate
installation)
Pony Prog
Used for burning firmware in the controller
Freeware easily available
Cannot be used with usb programmer
eXtreme burner-AVR
For USB Programmer
9
1/17/2017
Getting Started
AVR Studio
10
1/17/2017
PonyProg
eXtreme Burner-AVR
11
1/17/2017
1.Parallel Port
2.Serial Port
3.USB Port
12
1/17/2017
13
1/17/2017
USB Programmer
Link http://www.fischl.de/usbasp/
USB Programmer
Firmware and Layout of the above programmer
are available on the given link
Required Drivers for the USB Programmers
are also available at the link
Number of programming software are available
for download on the above link which work with
this USB programmer (eXtreme burner-AVR is
one of them)
14
1/17/2017
Atmega16
15
1/17/2017
ATmega16 Features
High-performance, Low-power AVR 8-bit Microcontroller
Advanced RISC Architecture
131 Powerful Instructions Most Single-clock Cycle
Execution
32 x 8 General Purpose Working Registers
Up to 16 MIPS Throughput at 16 MHz
ATmega16 Features
Nonvolatile Program and Data Memories
16K Bytes of In-System Self-Programmable Flash
program memory (ROM)
Endurance: 10,000 Write/Erase Cycles
512 Bytes EEPROM (Data Memory)
Endurance: 100,000 Write/Erase Cycles
1K Byte Internal SRAM (Data Memory )
Programming Lock for Software Security
16
1/17/2017
ATmega16 Features
Peripheral Features
Two 8-bit Timer/Counters with Separate Prescalers and Compare
Modes
One 16-bit Timer/Counter with Separate Prescaler, Compare Mode,
and Capture Mode
Real Time Counter with Separate Oscillator
Four PWM Channels
8-channel, 10-bit ADC
8 Single-ended Channels
7 Differential Channels in TQFP Package Only
2 Differential Channels with Programmable Gain at 1x, 10x, or 200x
I2C Two-wire Serial Interface (TWI)
Programmable Serial USART
Master/Slave SPI Serial Interface
Programmable Watchdog Timer with Separate On-chip Oscillator
On-chip Analog Comparator
ATmega16 Features
Special Microcontroller Features
Power-on Reset and Programmable Brown-out Detection
Internal Calibrated RC Oscillator
External and Internal Interrupt Sources
Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-
down, Standby
and Extended Standby
JTAG (IEEE std. 1149.1 Compliant) Interface
Boundary-scan Capabilities According to the JTAG Standard
Extensive On-chip Debug Support
Programming of Flash, EEPROM, Fuses, and Lock Bits through the
JTAG Interface
17
1/17/2017
ATmega16 Features
I/O and Packages
32 Programmable I/O Lines
40-pin PDIP, 44-lead TQFP, and 44-pad MLF
Operating Voltages
2.7 - 5.5V for ATmega16L
4.5 - 5.5V for ATmega16
Speed Grades
0 - 8 MHz for ATmega16L
0 - 16 MHz for ATmega16
18
1/17/2017
Fuse Bits
There are few parameters in the chip which are used to configure it
before it can be used for external environment. These parameters
are set with the use of FUSE BITS
The fuse bit determines the behavior of the chip, whether it has a
boot loader, what is the speed and voltage it runs at, the Watchdog
Timer conditions, etc.
Fuse Bits
Once the fuse bits are set for a particular configuration, the
controller can be used again and again (program can be burned
again and again)
There is no need to set the fuse bits every time using the controller
till the time you want to use it under the same configuration
Fuse bits need to be changed only in case you want to change the
initial configuration of the controller.
19
1/17/2017
Fuse Bits
Atmega16 has two fuse bytes
Fuse high byte
Fuse low byte
These two bytes have the bits which
Enable/Disable on-circuit Debugging
Enable/Disable JTAG
Enable/Disable SPI Interface
Enable/Disable Brown-out detection
Selects the clock source (speed of the controller)
Fuse Bits
The fuses are read as logical zero, 0, if they
are programmed
If the fuse bit is set 0 it means it is enabled
If the fuse bit is set 1 it means it is disabled
20
1/17/2017
Fuse Bits
Fuse High Byte
Fuse Bits
Fuse Low Byte
21
1/17/2017
Fuse Bits
It is really important to set the fuse bits correctly clearing
or writing the fuse bits accidentally may cause weird
controller behavior.
22
1/17/2017
Ext. Clock - - 0 0 0 0
Int. Osc 1 1 0 0 0 1
Int. Osc 2 1 0 0 1 0
Int. Osc 4 1 0 0 1 1
Int. Osc 8 1 0 1 0 0
SUT 01 determines the startup time and does not effect the operating frequency setting.
46 / 54
23
1/17/2017
47 / 54
24
1/17/2017
Since the controller frequency should be 4 MHz so the value of the Fuse
Low Byte should be 11100011 or E3
@ Dr Javaid, M.H Fidai 50 / 54
25
1/17/2017
26
1/17/2017
http://www.ladyada.net/learn/avr/fuses.html
http://embedderslife.wordpress.com/2012/08/20/fu
se-bits-arent-that-scary/
Calculator
http://www.engbedded.com/fusecalc
27