SlideShare a Scribd company logo
1 of 91
AVR
Modified Harvard architecture 8-bit RISC single
chip microcontroller
Complete System-on-a-chip
   On Board Memory (FLASH, SRAM & EEPROM)
   On Board Peripherals
Advanced (for 8 bit processors) technology
Developed by Atmel in 1996
First In-house CPU design by Atmel
8 Bit tinyAVR
   Small package – as small as 6 pins
8 Bit megaAVR
   Wide variety of configurations and packages
8 / 16 Bit AVR XMEGA
   Second Generation Technology
32 Bit AVR UC3
   Higher computational throughput
Processor core
Peripherals
Hardware Example – Polulu 3pi robot
Development Environments
Software Example - PID algorithm walkthrough
What is Harvard Architecture?
Before we can answer that…
Separate instruction and data paths
Simultaneous accesses to instructions & data
Hardware can be optimized for access type and
bus width.
Special instructions can access data from program
space.
Data memory is more expensive than program
memory
Don’t waste data memory for non-volatile data
Reduced Instruction Set Computer
As compared to Complex Instruction Set
Computers, i.e. x86
Assumption: Simpler instructions execute faster
Optimized most used instructions
Other RISC machines: ARM, PowerPC, SPARC
Became popular in mid 1990s
Faster clock rates
Single cycle instructions (20 MIPS @ 20 MHz)
Better compiler optimization
Typically no divide instruction in core
32 8 Bit registers
Mapped to address 0-31 in data space
Most instructions can access any register and
complete in one cycle
Last 3 register pairs can be used as 3 16 bit index
registers
32 bit stack pointer
7          0   addr

    R0         0x00
    R1         0x01
    R3         0x02
    R4         0x03
    R5         0x04
    R6         0x05

     •••
    R26        0x1A   x register low byte
    R27        0x1B   x register high byte
    R28        0x1C   y register low byte
    R29        0x1D   y register high byte
    R30        0x1E   z register low byte
    R31        0x1F   z register high byte
Non-volatile program space storage
16 Bit width
Some devices have separate lockable boot
section
At least 10,000 write/erase cycles
ATmega 48                 ATmega 88/168/328
                    0x000                        0x000
Application Flash            Application Flash




                                                 0x1FFF
                                                 0x3FFF
                    0x7FF
                                Boot Flash       0x7FFF
Data space storage
8 Bit width
0x0000 – 0x001F
   32 Registers
                       0x0020 – 0x005F
  64 I/O Registers
                       0x00060– 0x00FF
160 External I/O Reg
                       0x0100
  Internal SRAM
(512/1024/2048x8)      0x04FF/0x6FF/0x8FF




  External SRAM
Electrically Erasable Programmable Read Only
Memory
8 bit width
Requires special write sequence
Non-volatile storage for program specific data,
constants, etc.
At least 100,000 write/erase cycles
DEVICE        FLASH       EEPROM      SRAM
ATmega48A     4K Bytes    256 Bytes   512 Bytes
ATmega48PA    4K Bytes    256 Bytes   512 Bytes
ATmega88A     8K Bytes    512 Bytes   1K Bytes
ATmega88PA    8K Bytes    512 Bytes   1K Bytes
ATmega168A    16K Bytes   512 Bytes   1K Bytes
ATmega168PA   16K Bytes   512 Bytes   1K Bytes
ATmega328     32K Bytes   1K Bytes    2K Bytes
ATmega328P    32K Bytes   1K Bytes    2K Bytes
I/O registers visible in data space
   I/O can be accessed using same instructions as data
   Compilers can treat I/O space as data access
Bit manipulation instructions
   Set/Clear single I/O bits
   Only work on lower memory addresses
Directly connected to all 32 general purpose
registers
Operations between registers executed within a
single clock cycle
Supports arithmetic, logic and bit functions
On-chip 2-cycle Multiplier
131 instructions
   Arithmetic & Logic
   Branch
   Bit set/clear/test
   Data transfer
   MCU control
Register ↔ register in 1 cycle
Register ↔ memory in 2 cycles
Branch instruction 1-2 cycles
Subroutine call & return 3-5 cycles
Some operations may take longer for external
memory
Clock control module generates clocks for
memory and IO devices
Multiple internal clock sources
Provisions for external crystal clock source (max
20 MHz)
Default is internal RC 8 MHz oscillator with ÷ 8
prescale yielding 1 MHz CPU clock
Default is only 5-10% accurate
Timer/Counter                                    Timer/
   Oscillator                                    Counters



                                                   IO
    Crystal                                      Modules
   Oscillator

                                                   ADC
                            System      AVR
 External Clock    Clock     Clock
                   Mux     Prescaler
                                        Clock
                                                 CPU Core
                                       Control

Low Freq Crystal             ÷8
   Oscillator                                      RAM



 Calibrated RC                                   FLASH &
  Oscillator                                     EEPROM
Multiple power down modes
  Power down mode
    Wake on external reset or watchdog reset
  Power save mode
    Wake on timer events
  Several standby modes
Unused modules can be shut down
Power on reset
External reset
Watchdog system reset
Brown out detect (BOD) reset
ATmega328 has 26 reset/interrupt sources
1 Reset source
2 External interrupt sources
I/O Pin state change on all 24 GPIO pins
Peripheral device events
Each vector is a 2 word jump instruction
Vectors start at program memory address 0
Reset vector is at address 0
Sample vector table:
Address Labels   Code           Comments
0x0000           jmp RESET      ; Reset Handler
0x0002           jmp EXT_INT0   ; IRQ0 Handler
0x0004           jmp EXT_INT1   ; IRQ1 Handler
0x0006           jmp PCINT0     ; PCINT0 Handler
0x0008           jmp PCINT1     ; PCINT1 Handler
                 ...
Fuses configure system parameters
   Clock selection and options
   Boot options
   Some IO pin configurations
   Reset options
Three 8 bit fuse registers
Use caution! Some configurations can put the
device in an unusable state!
23 General Purpose IO Bits
Two 8 bit & one 16 bit timer/counters
Real time counter with separate oscillator
6 PWM Channels
6 or 8 ADC channels (depends on package)
Serial USART
SPI & I2C Serial Interfaces
Analog comparator
Programmable watchdog timer
Three 8 Bit IO Ports
   Port B, Port C & Port D
   Pins identified as PBx, PCx or PDx (x=0..7)
Each pin can be configured as:
   Input with internal pull-up
   Input with no pull-up
   Output low
   Output high
Most port pins have alternate functions
Internal peripherals use the alternate functions
Each port pin can be assigned only one function at
a time
8/16 Bit register
   Increments or decrements on every clock cycle
   Can be read on data bus
   Output feeds waveform generator
Clock Sources
   Internal from clock prescaler
   External Tn Pin (Uses 1 port pin)
Multiple Operating modes
  Simple timer / counter
  Output Compare Function
    Waveform generator
       Clear/set/toggle on match
    Frequency control
    Pulse Width Modulation (PWM)
DATA BUS
                                     IRQ



                                       Waveform
                                 =     Generator       OCnA
     TCCRnA          OCRnA




      Clock
Tn    Select
                     TCNTn


                                     IRQ


     TCCRnB              OCRnB
                                           Waveform
                                 =         Generator   OCnB



          DATA BUS
Use Clear Timer on Compare Match (CTC) Mode
OCnx Toggles on Compare Match
TOP = OCRnx




            0


 OCnx
 (toggle)
Dynamically change duty cycle of a waveform
Used to control motor speed
Fast PWM Mode
  Counter counts from BOTTOM (0) to MAX
  Counter reset to 0 at MAX
  OCnx cleared at TOP
  OCnx set at BOTTOM
Clear on
             TOP

MAX
TOP




BOTTOM



        Set on
       BOTTOM




OCnx
Timer 1 has capture mode
Capture can be triggered by ICP1 pin or ACO from
analog comparator
Capture event copies timer into input capture
register ICR1
Can be used to time external events or measure
pulse widths
Range finders generate pulse width proportional
to distance
10 Bit Successive Approximation ADC
8 Channel multiplexer using port pins ADC0-7
Max conversion time 260 μsec.
Compares voltage between pins AIN0 and AIN1
Asserts AC0 when AIN0 > AIN1
AC0 can trigger timer capture function
  Range finders indicate distance with pulse with
  Timer capture mode can compute pulse width
Industry standard serial protocol for
communication between local devices
Master/Slave protocol
3 Wire interface
Slaves addressed via Slave Select (SS) inputs
SCLK   Serial Clock
MOSI   Master Out Slave In
MISO   Master In Slave Out
SS     Slave Select
Industry standard serial protocol for
communication between local devices
Master/Slave protocol
2 Wire interface
Byte oriented messages
Slave address embedded in command
SDA   Serial Data
SCL   Serial Clock
EEPROM
IO Expanders
Real Time Clocks
ADC & DAC
Temperature sensors
Ultrasonic range finders
Compass
Servo / Motor Controller
LED Display
Universal Synchronous and Asynchronous serial
Receiver and Transmitter
Full Duplex Operation
High Resolution Baud Rate Generator
Can provide serial terminal interface
Some chips have JTAG interface
  Industry standard for debugging chips in circuit
  Connect to special JTAG signals
  Can program
    FLASH
    EEPROM
    All fuses
    Lock bits
ISP (In-System Programmer)
Connect to 6 or 10 pin connector
SPI interface
Special cable required
   Can program
     FLASH
     EEPROM
     Some fuses
     Lock bits
CW: PD5 & PD6 PWM mode (OC0B, OC0A)
CCW: PD3 & PB3 PWM mode (OC2B, OC2A)
Motor interface uses H-Bridge controller
Speed and direction controlled by port bits
Controller standby controlled by PC6
V+


1        2

    M

3            4




        V-
V+


PD5=1   1        2

            M

        3            4   PD6 (OC0A) PMW




                V-
V+


        1        2       PB3 (OC2A) PMW


            M

PD3=1   3            4




                V-
PC5 enables the IR emitters
One port pin for each of 5 sensors, PC0-4
Port pin used as input and output
   Set pin as output high for 10 μsec to charge RC
   circuit
   Set pin as input
   Measure time for voltage to drop (using TCNT2)
   Time indicates level of light
1. Output: 10 μsec pulse on PC0




2. Input: measure decay


                          t   indicates amount
                               of reflected light
ADC6: battery voltage monitor
ADC7: reads trimmer pot voltage
Buzzer: Timer1 PB2 (OC1B)
User defined (can be USART) : PD0, PD1
Device (ISP) Programming: PB3, PB4, PB5
20 MHz crystal: PB6, PB7
Choose a language
  BASCOM
  C/C++
  Assembler (machine language)
Choose a platform
  Linux
  Windows
Text Editor / IDE
Tool Chain
   Compiler
   Libraries
Programmer (cable & software)
Windows based BASIC compiler for AVR Family
Complete IDE
Includes simulator
Extensive library for AVR peripheral control
Includes ISP programmer
Demo versions available – limited code space
Linux
  AVR-GCC
    Based on GNU toolset
    Open Source AVR-LIBC libraries
Windows
  WIN-AVR
    Port of AVR-GCC to Windows
Linux
  Editors & command line tools
  Eclipse IDE
Windows
  Atmel AVR Studio
    Includes ISP programming support
  Eclipse IDE
STK 200/300/400/500
  Atmel AVR starter kit and development system
  Interfaces to AVR Studio
avrdude
  Programming support for all memories
Win-AVR
AVR-Studio
Proprietary libraries
PID Algorithm
PID Code Walkthrough
Simple Line Follower
Three sensors can provide position information
   left of center
   on center
   right of sensors
React to current position only
Three choices:
Guaranteed to zig-zag
back and fort h
Anticipates where we want to go
Continuously adjusts direction to get there
Adjustable constants control behavior
P
                +           Error                     Output
  Set point
                        Σ           I   Σ   Process
(center line)
                    –
                                    D
(P) Proportional
   Where we are relative to where we want to be.
(I) Integral
   Sum of previous errors. History of where we were.
(D) Derivative
   Rate of change. Affects how fast we react to
   changes.
Useful functions
   read_line
     Returns a value between 0 – 4000
       0 – 1000: robot is far right of line
       1000 – 3000: robot is approximately centered
       3000 – 4000: robot is far left of line
   set_motors
     Set speed and direction of both motors
        -255 – 0 : reverse direction
        0 – 255: forward direction
// Introductory messages. The "PROGMEM" identifier causes the data to
// go into program space.
const char welcome_line1[] PROGMEM = " Pololu";
const char welcome_line2[] PROGMEM = "3xf7 Robot";
const char demo_name_line1[] PROGMEM = "PID Line";
const char demo_name_line2[] PROGMEM = "Follower";

// A couple of simple tunes, stored in program space.
const char welcome[] PROGMEM = ">g32>>c32";
const char go[] PROGMEM = "L16 cdegreg4";A
// Auto-calibration: turn right and left while calibrating the
// sensors.
for(counter=0;counter<80;counter++)
{
          if(counter < 20 || counter >= 60)
                    set_motors(40,-40);
          else
                    set_motors(-40,40);

         // This function records a set of sensor readings and keeps
         // track of the minimum and maximum values encountered. The
         // IR_EMITTERS_ON argument means that the IR LEDs will be
         // turned on during the reading, which is usually what you
         // want.
         calibrate_line_sensors(IR_EMITTERS_ON);

         // Since our counter runs to 80, the total delay will be
         // 80*20 = 1600 ms.
         delay_ms(20);
}
set_motors(0,0);
// Get the position of the line. Note that we *must* provide
// the "sensors" argument to read_line() here, even though we
// are not interested in the individual sensor readings.
unsigned int position = read_line(sensors,IR_EMITTERS_ON);
// The "proportional" term should be 0 when we are on the line.
int proportional = ((int)position) - 2000;

// Compute the derivative (change) and integral (sum) of the position.
int derivative = proportional - last_proportional;
integral += proportional;

// Remember the last position.
last_proportional = proportional;

// Compute the difference between the two motor power settings,
// m1 - m2. If this is a positive number the robot will turn
// to the right. If it is a negative number, the robot will
// turn to the left, and the magnitude of the number determines
// the sharpness of the turn.
int power_difference = proportional/20 + integral/12000 + derivative*7/4;
// Compute the actual motor settings.    We never set either motor
// to a negative value.
const int max = 250;
if(power_difference > max)
          power_difference = max;
if(power_difference < -max)
          power_difference = -max;

// One Motor will always be full speed

if(power_difference < 0)
          set_motors(max+power_difference, max);
else
          set_motors(max, max-power_difference);
Open source elections prototyping platform
Hardware
  Based on Atmega (328 & others)
Software
  Wiring language, based on c++
  Boot loader
  Arduino IDE
ATmega 48/88/168/328
  What we have been talking about
ATmega 164/324/644/1284
  JTAG interface
  All 4 IO Ports A,B,C & D
  More memory
PDIP – Plastic Dual In-line Package
   Good for hobbyists
TQFP – Thin Quad Flat Pack
   Surface mount
MLF – MicroLeadFrame
   28 & 32 pin
   Surface mount / higher temperature
www.atmel.com
www.polulu.com
http://winavr.sourceforge.net
www.avrfreaks.net
www.wrighthobbies.net
www.eclipse.org
Just Google AVR

More Related Content

What's hot

Architecture of 8051
Architecture of 8051Architecture of 8051
Architecture of 8051hello_priti
 
INTRODUCTION TO MICROCONTROLLER
INTRODUCTION TO MICROCONTROLLERINTRODUCTION TO MICROCONTROLLER
INTRODUCTION TO MICROCONTROLLERAnkita Jaiswal
 
Microprocessor Presentation
Microprocessor PresentationMicroprocessor Presentation
Microprocessor Presentationalaminmasum1
 
8051 microcontroller
8051 microcontroller8051 microcontroller
8051 microcontrollerJhemi22
 
Introduction to Embedded Systems
Introduction to Embedded SystemsIntroduction to Embedded Systems
Introduction to Embedded SystemsSudhanshu Janwadkar
 
Advance Microcontroller AVR
Advance Microcontroller AVRAdvance Microcontroller AVR
Advance Microcontroller AVRDaksh Raj Chopra
 
PIC 16F877A by PARTHIBAN. S.
PIC 16F877A   by PARTHIBAN. S.PIC 16F877A   by PARTHIBAN. S.
PIC 16F877A by PARTHIBAN. S.parthi_arjun
 
Microcontroller presentation
Microcontroller presentationMicrocontroller presentation
Microcontroller presentationxavierpaulino
 
Embedded Systems - Training ppt
Embedded Systems - Training pptEmbedded Systems - Training ppt
Embedded Systems - Training pptNishant Kayal
 
Introducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptxIntroducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptxDr.YNM
 
8051 MICROCONTROLLER ARCHITECTURE.pptx
 8051 MICROCONTROLLER ARCHITECTURE.pptx 8051 MICROCONTROLLER ARCHITECTURE.pptx
8051 MICROCONTROLLER ARCHITECTURE.pptxMemonaMemon1
 
microcontroller vs microprocessor
microcontroller vs microprocessormicrocontroller vs microprocessor
microcontroller vs microprocessorsobhadevi
 

What's hot (20)

Architecture of 8051
Architecture of 8051Architecture of 8051
Architecture of 8051
 
INTRODUCTION TO MICROCONTROLLER
INTRODUCTION TO MICROCONTROLLERINTRODUCTION TO MICROCONTROLLER
INTRODUCTION TO MICROCONTROLLER
 
Embedded system
Embedded systemEmbedded system
Embedded system
 
Microprocessor Presentation
Microprocessor PresentationMicroprocessor Presentation
Microprocessor Presentation
 
8051 microcontroller
8051 microcontroller8051 microcontroller
8051 microcontroller
 
Introduction to Embedded Systems
Introduction to Embedded SystemsIntroduction to Embedded Systems
Introduction to Embedded Systems
 
Advance Microcontroller AVR
Advance Microcontroller AVRAdvance Microcontroller AVR
Advance Microcontroller AVR
 
Interfacing Stepper motor with 8051
Interfacing Stepper motor with 8051Interfacing Stepper motor with 8051
Interfacing Stepper motor with 8051
 
8255 PPI
8255 PPI8255 PPI
8255 PPI
 
PIC 16F877A by PARTHIBAN. S.
PIC 16F877A   by PARTHIBAN. S.PIC 16F877A   by PARTHIBAN. S.
PIC 16F877A by PARTHIBAN. S.
 
Microcontroller presentation
Microcontroller presentationMicrocontroller presentation
Microcontroller presentation
 
Embedded Systems - Training ppt
Embedded Systems - Training pptEmbedded Systems - Training ppt
Embedded Systems - Training ppt
 
Introducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptxIntroducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptx
 
Memory interfacing of microcontroller 8051
Memory interfacing of microcontroller 8051Memory interfacing of microcontroller 8051
Memory interfacing of microcontroller 8051
 
Introduction to Microcontroller
Introduction to MicrocontrollerIntroduction to Microcontroller
Introduction to Microcontroller
 
8051 MICROCONTROLLER ARCHITECTURE.pptx
 8051 MICROCONTROLLER ARCHITECTURE.pptx 8051 MICROCONTROLLER ARCHITECTURE.pptx
8051 MICROCONTROLLER ARCHITECTURE.pptx
 
microcontroller vs microprocessor
microcontroller vs microprocessormicrocontroller vs microprocessor
microcontroller vs microprocessor
 
Arduino Uno Pin Description
Arduino Uno Pin DescriptionArduino Uno Pin Description
Arduino Uno Pin Description
 
8051 timer counter
8051 timer counter8051 timer counter
8051 timer counter
 
Communication Protocols (UART, SPI,I2C)
Communication Protocols (UART, SPI,I2C)Communication Protocols (UART, SPI,I2C)
Communication Protocols (UART, SPI,I2C)
 

Similar to AVR Fundamentals (20)

Atmega 32
Atmega 32Atmega 32
Atmega 32
 
Atmega32
Atmega32Atmega32
Atmega32
 
Atemega saya
Atemega sayaAtemega saya
Atemega saya
 
Overview of LPC213x MCUs
Overview of LPC213x MCUsOverview of LPC213x MCUs
Overview of LPC213x MCUs
 
A tmega16A Microcontroller Data Sheet
A tmega16A Microcontroller Data SheetA tmega16A Microcontroller Data Sheet
A tmega16A Microcontroller Data Sheet
 
microcontroller 8051 17.07.2023.pdf
microcontroller 8051 17.07.2023.pdfmicrocontroller 8051 17.07.2023.pdf
microcontroller 8051 17.07.2023.pdf
 
Overview Study on PIC32MX3XX / 4XX 32-Bit Controller
Overview Study on PIC32MX3XX / 4XX 32-Bit ControllerOverview Study on PIC32MX3XX / 4XX 32-Bit Controller
Overview Study on PIC32MX3XX / 4XX 32-Bit Controller
 
Overview of LPC214x MCUs
Overview of LPC214x MCUsOverview of LPC214x MCUs
Overview of LPC214x MCUs
 
Doc32059
Doc32059Doc32059
Doc32059
 
32059 sistem
32059 sistem32059 sistem
32059 sistem
 
8051 Presentation
8051 Presentation8051 Presentation
8051 Presentation
 
Study on 32-bit Cortex - M3 Powered MCU: STM32F101
Study on 32-bit Cortex - M3 Powered MCU: STM32F101Study on 32-bit Cortex - M3 Powered MCU: STM32F101
Study on 32-bit Cortex - M3 Powered MCU: STM32F101
 
unit-2.pptx
unit-2.pptxunit-2.pptx
unit-2.pptx
 
Atmega16 datasheet
Atmega16 datasheetAtmega16 datasheet
Atmega16 datasheet
 
Atmega16 Microconntroller Data sheet
Atmega16 Microconntroller Data sheetAtmega16 Microconntroller Data sheet
Atmega16 Microconntroller Data sheet
 
dsPIC33FJ06GSXXX DSCs
dsPIC33FJ06GSXXX DSCsdsPIC33FJ06GSXXX DSCs
dsPIC33FJ06GSXXX DSCs
 
Introduction2_PIC.ppt
Introduction2_PIC.pptIntroduction2_PIC.ppt
Introduction2_PIC.ppt
 
Microcontroller from basic_to_advanced
Microcontroller from basic_to_advancedMicrocontroller from basic_to_advanced
Microcontroller from basic_to_advanced
 
Pic microcontroller [autosaved] [autosaved]
Pic microcontroller [autosaved] [autosaved]Pic microcontroller [autosaved] [autosaved]
Pic microcontroller [autosaved] [autosaved]
 
8051 presentation
8051 presentation8051 presentation
8051 presentation
 

More from Vinit Vyas

Hiroshima and nagasaki
Hiroshima and nagasakiHiroshima and nagasaki
Hiroshima and nagasakiVinit Vyas
 
Hardware Memory
Hardware MemoryHardware Memory
Hardware MemoryVinit Vyas
 
Core Java Slides
Core Java SlidesCore Java Slides
Core Java SlidesVinit Vyas
 
Albert Einstein
Albert EinsteinAlbert Einstein
Albert EinsteinVinit Vyas
 
World’s Greatest Writers
World’s Greatest WritersWorld’s Greatest Writers
World’s Greatest WritersVinit Vyas
 
Why Do We Need God?
Why Do We Need God?Why Do We Need God?
Why Do We Need God?Vinit Vyas
 

More from Vinit Vyas (6)

Hiroshima and nagasaki
Hiroshima and nagasakiHiroshima and nagasaki
Hiroshima and nagasaki
 
Hardware Memory
Hardware MemoryHardware Memory
Hardware Memory
 
Core Java Slides
Core Java SlidesCore Java Slides
Core Java Slides
 
Albert Einstein
Albert EinsteinAlbert Einstein
Albert Einstein
 
World’s Greatest Writers
World’s Greatest WritersWorld’s Greatest Writers
World’s Greatest Writers
 
Why Do We Need God?
Why Do We Need God?Why Do We Need God?
Why Do We Need God?
 

Recently uploaded

Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...Authentic No 1 Amil Baba In Pakistan
 
办理西悉尼大学毕业证成绩单、制作假文凭
办理西悉尼大学毕业证成绩单、制作假文凭办理西悉尼大学毕业证成绩单、制作假文凭
办理西悉尼大学毕业证成绩单、制作假文凭o8wvnojp
 
Inspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptxInspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptxShubham Rawat
 
E J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptxE J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptxJackieSparrow3
 
西伦敦大学毕业证学位证成绩单-怎么样做
西伦敦大学毕业证学位证成绩单-怎么样做西伦敦大学毕业证学位证成绩单-怎么样做
西伦敦大学毕业证学位证成绩单-怎么样做j5bzwet6
 
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilable
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 AvilableCall Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilable
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilabledollysharma2066
 
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ EscortsDelhi Escorts Service
 
Call Girls in Govindpuri Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Govindpuri Delhi 💯Call Us 🔝8264348440🔝Call Girls in Govindpuri Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Govindpuri Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls In Dwarka Sub City ☎️7838079806 ✅ 💯Call Girls In Delhi
Call Girls In Dwarka Sub City  ☎️7838079806 ✅ 💯Call Girls In DelhiCall Girls In Dwarka Sub City  ☎️7838079806 ✅ 💯Call Girls In Delhi
Call Girls In Dwarka Sub City ☎️7838079806 ✅ 💯Call Girls In DelhiSoniyaSingh
 
南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证kbdhl05e
 
(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)oannq
 

Recently uploaded (12)

Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
 
办理西悉尼大学毕业证成绩单、制作假文凭
办理西悉尼大学毕业证成绩单、制作假文凭办理西悉尼大学毕业证成绩单、制作假文凭
办理西悉尼大学毕业证成绩单、制作假文凭
 
Inspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptxInspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptx
 
E J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptxE J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptx
 
西伦敦大学毕业证学位证成绩单-怎么样做
西伦敦大学毕业证学位证成绩单-怎么样做西伦敦大学毕业证学位证成绩单-怎么样做
西伦敦大学毕业证学位证成绩单-怎么样做
 
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilable
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 AvilableCall Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilable
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilable
 
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts
 
Call Girls in Govindpuri Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Govindpuri Delhi 💯Call Us 🔝8264348440🔝Call Girls in Govindpuri Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Govindpuri Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls In Dwarka Sub City ☎️7838079806 ✅ 💯Call Girls In Delhi
Call Girls In Dwarka Sub City  ☎️7838079806 ✅ 💯Call Girls In DelhiCall Girls In Dwarka Sub City  ☎️7838079806 ✅ 💯Call Girls In Delhi
Call Girls In Dwarka Sub City ☎️7838079806 ✅ 💯Call Girls In Delhi
 
Model Call Girl in Lado Sarai Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Lado Sarai Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Lado Sarai Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Lado Sarai Delhi reach out to us at 🔝9953056974🔝
 
南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证
 
(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)
 

AVR Fundamentals

  • 1. AVR
  • 2. Modified Harvard architecture 8-bit RISC single chip microcontroller Complete System-on-a-chip On Board Memory (FLASH, SRAM & EEPROM) On Board Peripherals Advanced (for 8 bit processors) technology Developed by Atmel in 1996 First In-house CPU design by Atmel
  • 3. 8 Bit tinyAVR Small package – as small as 6 pins 8 Bit megaAVR Wide variety of configurations and packages 8 / 16 Bit AVR XMEGA Second Generation Technology 32 Bit AVR UC3 Higher computational throughput
  • 4. Processor core Peripherals Hardware Example – Polulu 3pi robot Development Environments Software Example - PID algorithm walkthrough
  • 5. What is Harvard Architecture? Before we can answer that…
  • 6.
  • 7.
  • 8. Separate instruction and data paths Simultaneous accesses to instructions & data Hardware can be optimized for access type and bus width.
  • 9.
  • 10. Special instructions can access data from program space. Data memory is more expensive than program memory Don’t waste data memory for non-volatile data
  • 11. Reduced Instruction Set Computer As compared to Complex Instruction Set Computers, i.e. x86 Assumption: Simpler instructions execute faster Optimized most used instructions Other RISC machines: ARM, PowerPC, SPARC Became popular in mid 1990s
  • 12. Faster clock rates Single cycle instructions (20 MIPS @ 20 MHz) Better compiler optimization Typically no divide instruction in core
  • 13. 32 8 Bit registers Mapped to address 0-31 in data space Most instructions can access any register and complete in one cycle Last 3 register pairs can be used as 3 16 bit index registers 32 bit stack pointer
  • 14. 7 0 addr R0 0x00 R1 0x01 R3 0x02 R4 0x03 R5 0x04 R6 0x05 ••• R26 0x1A x register low byte R27 0x1B x register high byte R28 0x1C y register low byte R29 0x1D y register high byte R30 0x1E z register low byte R31 0x1F z register high byte
  • 15. Non-volatile program space storage 16 Bit width Some devices have separate lockable boot section At least 10,000 write/erase cycles
  • 16. ATmega 48 ATmega 88/168/328 0x000 0x000 Application Flash Application Flash 0x1FFF 0x3FFF 0x7FF Boot Flash 0x7FFF
  • 17. Data space storage 8 Bit width
  • 18. 0x0000 – 0x001F 32 Registers 0x0020 – 0x005F 64 I/O Registers 0x00060– 0x00FF 160 External I/O Reg 0x0100 Internal SRAM (512/1024/2048x8) 0x04FF/0x6FF/0x8FF External SRAM
  • 19. Electrically Erasable Programmable Read Only Memory 8 bit width Requires special write sequence Non-volatile storage for program specific data, constants, etc. At least 100,000 write/erase cycles
  • 20. DEVICE FLASH EEPROM SRAM ATmega48A 4K Bytes 256 Bytes 512 Bytes ATmega48PA 4K Bytes 256 Bytes 512 Bytes ATmega88A 8K Bytes 512 Bytes 1K Bytes ATmega88PA 8K Bytes 512 Bytes 1K Bytes ATmega168A 16K Bytes 512 Bytes 1K Bytes ATmega168PA 16K Bytes 512 Bytes 1K Bytes ATmega328 32K Bytes 1K Bytes 2K Bytes ATmega328P 32K Bytes 1K Bytes 2K Bytes
  • 21. I/O registers visible in data space I/O can be accessed using same instructions as data Compilers can treat I/O space as data access Bit manipulation instructions Set/Clear single I/O bits Only work on lower memory addresses
  • 22. Directly connected to all 32 general purpose registers Operations between registers executed within a single clock cycle Supports arithmetic, logic and bit functions On-chip 2-cycle Multiplier
  • 23. 131 instructions Arithmetic & Logic Branch Bit set/clear/test Data transfer MCU control
  • 24. Register ↔ register in 1 cycle Register ↔ memory in 2 cycles Branch instruction 1-2 cycles Subroutine call & return 3-5 cycles Some operations may take longer for external memory
  • 25.
  • 26. Clock control module generates clocks for memory and IO devices Multiple internal clock sources Provisions for external crystal clock source (max 20 MHz) Default is internal RC 8 MHz oscillator with ÷ 8 prescale yielding 1 MHz CPU clock Default is only 5-10% accurate
  • 27. Timer/Counter Timer/ Oscillator Counters IO Crystal Modules Oscillator ADC System AVR External Clock Clock Clock Mux Prescaler Clock CPU Core Control Low Freq Crystal ÷8 Oscillator RAM Calibrated RC FLASH & Oscillator EEPROM
  • 28. Multiple power down modes Power down mode Wake on external reset or watchdog reset Power save mode Wake on timer events Several standby modes Unused modules can be shut down
  • 29. Power on reset External reset Watchdog system reset Brown out detect (BOD) reset
  • 30. ATmega328 has 26 reset/interrupt sources 1 Reset source 2 External interrupt sources I/O Pin state change on all 24 GPIO pins Peripheral device events
  • 31. Each vector is a 2 word jump instruction Vectors start at program memory address 0 Reset vector is at address 0 Sample vector table: Address Labels Code Comments 0x0000 jmp RESET ; Reset Handler 0x0002 jmp EXT_INT0 ; IRQ0 Handler 0x0004 jmp EXT_INT1 ; IRQ1 Handler 0x0006 jmp PCINT0 ; PCINT0 Handler 0x0008 jmp PCINT1 ; PCINT1 Handler ...
  • 32. Fuses configure system parameters Clock selection and options Boot options Some IO pin configurations Reset options Three 8 bit fuse registers Use caution! Some configurations can put the device in an unusable state!
  • 33. 23 General Purpose IO Bits Two 8 bit & one 16 bit timer/counters Real time counter with separate oscillator 6 PWM Channels 6 or 8 ADC channels (depends on package) Serial USART SPI & I2C Serial Interfaces Analog comparator Programmable watchdog timer
  • 34. Three 8 Bit IO Ports Port B, Port C & Port D Pins identified as PBx, PCx or PDx (x=0..7) Each pin can be configured as: Input with internal pull-up Input with no pull-up Output low Output high
  • 35. Most port pins have alternate functions Internal peripherals use the alternate functions Each port pin can be assigned only one function at a time
  • 36.
  • 37. 8/16 Bit register Increments or decrements on every clock cycle Can be read on data bus Output feeds waveform generator Clock Sources Internal from clock prescaler External Tn Pin (Uses 1 port pin)
  • 38. Multiple Operating modes Simple timer / counter Output Compare Function Waveform generator Clear/set/toggle on match Frequency control Pulse Width Modulation (PWM)
  • 39. DATA BUS IRQ Waveform = Generator OCnA TCCRnA OCRnA Clock Tn Select TCNTn IRQ TCCRnB OCRnB Waveform = Generator OCnB DATA BUS
  • 40. Use Clear Timer on Compare Match (CTC) Mode OCnx Toggles on Compare Match TOP = OCRnx 0 OCnx (toggle)
  • 41. Dynamically change duty cycle of a waveform Used to control motor speed
  • 42. Fast PWM Mode Counter counts from BOTTOM (0) to MAX Counter reset to 0 at MAX OCnx cleared at TOP OCnx set at BOTTOM
  • 43. Clear on TOP MAX TOP BOTTOM Set on BOTTOM OCnx
  • 44. Timer 1 has capture mode Capture can be triggered by ICP1 pin or ACO from analog comparator Capture event copies timer into input capture register ICR1 Can be used to time external events or measure pulse widths Range finders generate pulse width proportional to distance
  • 45. 10 Bit Successive Approximation ADC 8 Channel multiplexer using port pins ADC0-7 Max conversion time 260 μsec.
  • 46. Compares voltage between pins AIN0 and AIN1 Asserts AC0 when AIN0 > AIN1 AC0 can trigger timer capture function Range finders indicate distance with pulse with Timer capture mode can compute pulse width
  • 47. Industry standard serial protocol for communication between local devices Master/Slave protocol 3 Wire interface Slaves addressed via Slave Select (SS) inputs
  • 48. SCLK Serial Clock MOSI Master Out Slave In MISO Master In Slave Out SS Slave Select
  • 49. Industry standard serial protocol for communication between local devices Master/Slave protocol 2 Wire interface Byte oriented messages Slave address embedded in command
  • 50. SDA Serial Data SCL Serial Clock
  • 51. EEPROM IO Expanders Real Time Clocks ADC & DAC Temperature sensors Ultrasonic range finders Compass Servo / Motor Controller LED Display
  • 52. Universal Synchronous and Asynchronous serial Receiver and Transmitter Full Duplex Operation High Resolution Baud Rate Generator Can provide serial terminal interface
  • 53. Some chips have JTAG interface Industry standard for debugging chips in circuit Connect to special JTAG signals Can program FLASH EEPROM All fuses Lock bits
  • 54. ISP (In-System Programmer) Connect to 6 or 10 pin connector SPI interface Special cable required Can program FLASH EEPROM Some fuses Lock bits
  • 55.
  • 56.
  • 57.
  • 58.
  • 59. CW: PD5 & PD6 PWM mode (OC0B, OC0A) CCW: PD3 & PB3 PWM mode (OC2B, OC2A) Motor interface uses H-Bridge controller Speed and direction controlled by port bits Controller standby controlled by PC6
  • 60. V+ 1 2 M 3 4 V-
  • 61. V+ PD5=1 1 2 M 3 4 PD6 (OC0A) PMW V-
  • 62. V+ 1 2 PB3 (OC2A) PMW M PD3=1 3 4 V-
  • 63. PC5 enables the IR emitters One port pin for each of 5 sensors, PC0-4 Port pin used as input and output Set pin as output high for 10 μsec to charge RC circuit Set pin as input Measure time for voltage to drop (using TCNT2) Time indicates level of light
  • 64. 1. Output: 10 μsec pulse on PC0 2. Input: measure decay t indicates amount of reflected light
  • 65. ADC6: battery voltage monitor ADC7: reads trimmer pot voltage
  • 66. Buzzer: Timer1 PB2 (OC1B) User defined (can be USART) : PD0, PD1 Device (ISP) Programming: PB3, PB4, PB5 20 MHz crystal: PB6, PB7
  • 67. Choose a language BASCOM C/C++ Assembler (machine language) Choose a platform Linux Windows
  • 68. Text Editor / IDE Tool Chain Compiler Libraries Programmer (cable & software)
  • 69. Windows based BASIC compiler for AVR Family Complete IDE Includes simulator Extensive library for AVR peripheral control Includes ISP programmer Demo versions available – limited code space
  • 70.
  • 71.
  • 72. Linux AVR-GCC Based on GNU toolset Open Source AVR-LIBC libraries Windows WIN-AVR Port of AVR-GCC to Windows
  • 73. Linux Editors & command line tools Eclipse IDE Windows Atmel AVR Studio Includes ISP programming support Eclipse IDE
  • 74. STK 200/300/400/500 Atmel AVR starter kit and development system Interfaces to AVR Studio avrdude Programming support for all memories
  • 76. PID Algorithm PID Code Walkthrough
  • 77. Simple Line Follower Three sensors can provide position information left of center on center right of sensors React to current position only
  • 80. Anticipates where we want to go Continuously adjusts direction to get there Adjustable constants control behavior
  • 81. P + Error Output Set point Σ I Σ Process (center line) – D
  • 82. (P) Proportional Where we are relative to where we want to be. (I) Integral Sum of previous errors. History of where we were. (D) Derivative Rate of change. Affects how fast we react to changes.
  • 83. Useful functions read_line Returns a value between 0 – 4000 0 – 1000: robot is far right of line 1000 – 3000: robot is approximately centered 3000 – 4000: robot is far left of line set_motors Set speed and direction of both motors -255 – 0 : reverse direction 0 – 255: forward direction
  • 84. // Introductory messages. The "PROGMEM" identifier causes the data to // go into program space. const char welcome_line1[] PROGMEM = " Pololu"; const char welcome_line2[] PROGMEM = "3xf7 Robot"; const char demo_name_line1[] PROGMEM = "PID Line"; const char demo_name_line2[] PROGMEM = "Follower"; // A couple of simple tunes, stored in program space. const char welcome[] PROGMEM = ">g32>>c32"; const char go[] PROGMEM = "L16 cdegreg4";A
  • 85. // Auto-calibration: turn right and left while calibrating the // sensors. for(counter=0;counter<80;counter++) { if(counter < 20 || counter >= 60) set_motors(40,-40); else set_motors(-40,40); // This function records a set of sensor readings and keeps // track of the minimum and maximum values encountered. The // IR_EMITTERS_ON argument means that the IR LEDs will be // turned on during the reading, which is usually what you // want. calibrate_line_sensors(IR_EMITTERS_ON); // Since our counter runs to 80, the total delay will be // 80*20 = 1600 ms. delay_ms(20); } set_motors(0,0);
  • 86. // Get the position of the line. Note that we *must* provide // the "sensors" argument to read_line() here, even though we // are not interested in the individual sensor readings. unsigned int position = read_line(sensors,IR_EMITTERS_ON); // The "proportional" term should be 0 when we are on the line. int proportional = ((int)position) - 2000; // Compute the derivative (change) and integral (sum) of the position. int derivative = proportional - last_proportional; integral += proportional; // Remember the last position. last_proportional = proportional; // Compute the difference between the two motor power settings, // m1 - m2. If this is a positive number the robot will turn // to the right. If it is a negative number, the robot will // turn to the left, and the magnitude of the number determines // the sharpness of the turn. int power_difference = proportional/20 + integral/12000 + derivative*7/4;
  • 87. // Compute the actual motor settings. We never set either motor // to a negative value. const int max = 250; if(power_difference > max) power_difference = max; if(power_difference < -max) power_difference = -max; // One Motor will always be full speed if(power_difference < 0) set_motors(max+power_difference, max); else set_motors(max, max-power_difference);
  • 88. Open source elections prototyping platform Hardware Based on Atmega (328 & others) Software Wiring language, based on c++ Boot loader Arduino IDE
  • 89. ATmega 48/88/168/328 What we have been talking about ATmega 164/324/644/1284 JTAG interface All 4 IO Ports A,B,C & D More memory
  • 90. PDIP – Plastic Dual In-line Package Good for hobbyists TQFP – Thin Quad Flat Pack Surface mount MLF – MicroLeadFrame 28 & 32 pin Surface mount / higher temperature

Editor's Notes

  1. 11/07/12 20:08 © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
  2. 11/07/12 20:08 © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
  3. 11/07/12 20:08 © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
  4. 11/07/12 20:08 © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.