Professional Documents
Culture Documents
Overview, AVR
Hardware/Software Introduction
1
Embedded Systems Overview
• Computing systems are everywhere
• Most of us think of “desktop” computers
– PC’s
– Laptops
– Mainframes
– Servers
• But there’s another type of computing
system
– Far more common...
2
Embedded Systems Overview
• Embedded computing systems
– Computing systems embedded Computers are in here...
3
A “short list” of embedded
systems
Anti-lock brakes Modems
Auto-focus cameras MPEG decoders
Automatic teller machines Network cards
Automatic toll systems
Automatic transmission
Network switches/routers
Avionic systems On-board navigation
Battery chargers Pagers
Camcorders Photocopiers
Cell phones Point-of-sale systems
Cell-phone base stations
Cordless phones
Portable video games
Cruise control Printers
Curbside check-in systems Satellite phones
Digital cameras Scanners
Disk drives Smart ovens/dishwashers
Electronic card readers
Electronic instruments
Speech recognizers
Electronic toys/games Stereo systems
Factory control Teleconferencing systems
Fax machines Televisions
Fingerprint identifiers Temperature controllers
Home security systems
Life-support systems
Theft tracking systems
Medical testing systems TV set-top boxes
VCR’s, DVD players
Video game consoles
Video phones
Washers and dryers
6
Designing Embedded Systems
• Microcontrollers
– Don’t have keyboard and monitor jacks
– Must use ports to perform I/O
• Inputs – to sense things
• Outputs – to control things
• Related Component Topics
– Common Interfaces
– Part Packages
7
What you will do:
• Labs
– Lab 1: Introduction to AVR STK500
Hardware/Software, a couple of simple c programs
– Lab 2: A/D converter
– Lab 3: Optical Sensors
– Lab 4: 2 bits D/A converter
– Lab 5: Controls and Feedback
– Lab 6: Motor Control - open loop
– Lab 7: Motor Control - simple feedback control
– Lab 8: Motor Control - proportional feedback control
8
What you will do:
• Presentation – your proposed project
• Final Project
– Hardware
– Software
– Presentation
– Report
9
Introduction to AVR
• CodeVision AVR C Compiler Professional
version
– Installed in 20 PCs in room EN229
– Compile programs with more than a thousand
instructions.
– Provides many useful assembly programs used by
your C programs. You write your programs in C
completely. AVR C compiler will integrate all required
programs together
– More about AVR C compiler when presenting Lab 1
10
History of AVR
11
Introduction to AVR
12
Used in Lab
13
AVR Architecture
• What are the features of RISC?
– 1 instruction per clock cycle (pipelined)
– Lots of registers: 32 GP registers
– Register-to-register operation
• Variations in the parts:
– TINY to MEGA
– ATtiny10
• Processor has only 8 pins
– ATmega128 (128K bytes flash)
• Processor has 64 pins
14
AVR Architecture
15
AVR RISC Architecture
• Single Cycle Instructions:
8mhz = 8mips.
• Large register file (32).
• Every register an
accumulator.
• 3 index register pairs
• Register & IO are
mapped in SRAM space.
16
On Chip
Debugger
17
18
Typical Hardware Support
19
20
21
22
PB2 PB3 also used as Analog Input 0 (AIN0) and
Analog Input 1 (AIN1)
23
The Analog Comparator compares
the input values on the positive pin AIN0 and negative pin
AIN1.
When the voltage on the positive pin AIN0 is higher than the
voltage on the negative pin AIN1, the Analog Comparator
Output, ACO, is set. ACO is kept in bit 5 of Analog
Comparator Control and Status Register
24
AVR Memory Space
• Program Flash
– Vectors, Code, and
(Unchangeable) Constant Data
• Working Registers
– Includes X, Y, and Z registers.
• I/O Register Space
– Includes “named” registers
• SRAM – Data Space
– Runtime Variables and Data
– Stack space
• EEPROM space
– For non-volatile but alterable data
25
AVR Addressing Modes
26
Register Direct: 1 Register
27
Register Direct: 2 Registers
28
I/O Direct
29
Data Direct
30
Data Indirect
31
Data Indirect w/ Displacement
32
Data Indirect: Pre-Decrement
33
Data Indirect: Post-Increment
34
Status Register: SREG
35
Interesting Instruction Examples:
36
Timers: Why we need them
37
AVR Timer/Counter 0
• 8 Bit
• Wrap-Around
Up Counter
• Interrupt on
overflow
38
AVR Timer/Counter 0
• 8 Bit Up Counter
– counts from 0 to 255 (0xFF), then loops to 0
– Internal or External Clock source
• Prescaler
• Output capture through OC0, i.e. PB3, pin 4
• Interrupt on Overflow
– Transition from 255 to 0 can trigger interrupt if
desired
39
AVR Timer/Counter 0
OC0, Output Compare Match output:
40
AVR Timer/Counter 1
– 16 Bit
– Dual Comparators A,B (output compares)
– Up Counter
– Interrupt on:
• Overflow
• Compare A/B
• Input Capture of external event on ICP pin.
– Can also act as an 8, 9 or 10 bit PWM Up-
Down Counter.
41
AVR Timer/Counter 1
The Input Capture unit of Timer/Counter captures
external events and gives them a time-stamp
indicating time of occurrence.
43
Timer 1 and PWM
• Pulse-Width Modulation
– Useful for using digital circuits to achieve analog-
like control of motors, LEDs, etc
– Timer 1 has two channels of PWM output on OCR1A
and OCR1B
44
Timer Control
• Timer 0:
– Control Register (TCCR0) for clock selection, external
clock or internal clock, prescaler etc.
– Timer/Counter0 (TCNT0) holding counter value
• Timer 1:
– Control Register A & B (TCCR1A/B)
– Input Capture Register (ICR1)
– Timer/Counter1 Output Compare Register A and B
(OCR1A/B)
– Timer/Counter1 (TCNT1)
• Timer Interrupt Registers (Mask and Flag Registers) are
Common to Both Timers
45
AVR Timer/Counter Sources
• Shut Off
• CPU frequency divided by 1,8,64,256,1024
• At 8MHz that’s: 1/8us, 1us, 8us, 32us,
128us
• External Input (rising or falling).
46
Interrupts
47
48
Watchdog Timer: reset the MCU
The Watchdog Timer is clocked from a separate
On-chip Oscillator which runs at 1 MHz
49
Reading Assignment:
Chapter 1 of Embedded C Programming and the Atmel AVR
50