Avr Microcontrollers

24
AVR Microcontrollers What is a microcontroller? microprocessor Read-write memory Flash memory EEPROM Input/Output Control Peripheral Devices (AD/DA) Billions sold per year, most processors Emphasis is on cost. (pennies) Alternative/paired to ASIC/DSP Emphasis on power consumption

Transcript of Avr Microcontrollers

Page 1: Avr Microcontrollers

AVR Microcontrollers

What is a microcontroller? microprocessor Read-write memory Flash memory EEPROM Input/Output Control Peripheral Devices (AD/DA)

Billions sold per year, most processors Emphasis is on cost. (pennies) Alternative/paired to ASIC/DSP Emphasis on power consumption

Page 2: Avr Microcontrollers

Uses

Consumer electronics Appliances Automotive Electrical/Heating Computers / Hard Drives Hobbyist projects!

Installation art Musical instruments Home automation Audio Distribution Web Server!! MANY MORE!!

Page 3: Avr Microcontrollers

Other Examples

Page 4: Avr Microcontrollers

Other Examples

Page 5: Avr Microcontrollers

Manufacturers

Intel, Freescale, Microchip (PIC), TI, Zilog Atmel AVR

Many Types, tinyAT, megaAT, automotive Lighting, LCD Share unified platform Different #s of I/O control Built-in Pull-up resistors Ethernet, Serial Data, Auxiliary Power, USB Analog I/O, Packaging, Interrupts, Math, JTAG Get the right amount of memory for the job

Page 6: Avr Microcontrollers

Development Platforms

Everything Needed, All-In-One Arduino / Diecimila

ATMega8 / ATMega168 based Open source, multiplatform IDE Cheap ($33 assembled!) Great Online Community USB, power, protoshield available, breadboard,

LEDs Parallax (PIC) PICAXE (PIC) ArmExpress Many Others

Page 7: Avr Microcontrollers

Cheaper

A Transistor Saved is a Transistor Earned No Lack Floating Point Non-Pipeline No cache Limited Math / Branching Very Slow (1 to 32MHz) Very Little Memory (64bytes to 256KB) From under a dollar to $20 for advanced

Cheaper in volume Important for large product runs

Page 8: Avr Microcontrollers

Atmel / AVR History

Conceived by two students at Norwegian Institute of Technology (NTH) Alf-Egil Bogen and Vegard Wollan

Originally Known as μRISC (Micro RISC) Sold to Atmel, continued working under

Atmel Norway subsidiary AVR supposedly not acronym

May mean Advanced Virtual RISC Beauty in simplicity

Can wrap mind around entire CPU

Page 9: Avr Microcontrollers

ATMega168 Specifications

Low-Power 8-bit AVR Microcontroller Modified Harvard Architecture Around $4 individual, $2.50 in Volume 32 8-bit general-purpose registers 131 Instructions, Multi-cycle Implementation

Most are single-cycle 2-cycle multiply, 2-cycle memory access Thus up to 1MIPS/MHz

20MHz, up to 20MIPS 16KB self-programmable Flash 512 Bytes EEPROM 1KB SRAM

Page 10: Avr Microcontrollers

ATMega168 IO

6 PWM Shared Input/Outputs (Analog) 8 digital input/outputs SPI-serial, 2-wire serial, ISP, others

Monitoring, debugging, programming, power USART serial interface

(interfaces with USB on Arduino)

Page 11: Avr Microcontrollers
Page 12: Avr Microcontrollers
Page 13: Avr Microcontrollers

Instruction Set

Mostly unified across all AVR With exceptions for feature differences

32 or 16 bit instructions 8-bit fields, vary depending on instructions I/O manipulation treated in similar fashion to

registers Allows for clean and simple usage

Parallel Instruction Fetch Uses Skip instead of Branches Use software libraries for more complex

functionality (divide)

Page 14: Avr Microcontrollers

Example Code

Assembly Code Example(1) ... ; Define pull-ups and set outputs high ; Define directions for port pins ldi r16,(1<<PB7)|(1<<PB6)|(1<<PB1)|(1<<PB0)

ldi r17,(1<<DDB3)|(1<<DDB2)|(1<<DDB1)|(1<<DDB0)

out PORTB,r16 out DDRB,r17 ; Insert nop for synchronization nop ; Read port pins in r16,PINB ...

Page 15: Avr Microcontrollers

Registers

32 general purpose registers Addressable as first 32 memory addresses 4 Different Simultaneous Access Schemes X, Y, Z registers for indirect memory

Dual-purpose, 16 bit 26/27, 28/29, 30/31

200+ I/O, settings, timers, interrupts registers Overflow at 256 / 65K!

Page 16: Avr Microcontrollers

Registers

Page 17: Avr Microcontrollers

Memories

3 different memories SRAM Flash EEPROM

Direct/Indirect Addressing (5 modes total) Flash is divided into two 8KB sections

Independently addressable Flash has reserved Bootloader section for

software security

Page 18: Avr Microcontrollers

Additional Functionality

Registers for serial access Interrupts External Interrupts Power Management Timers Analog Comparators Other Goodies All handled via special registers

Some settings via bit-flags

Page 19: Avr Microcontrollers

Compilers

Meant for Assembly Programming Many environments available

BASIC and FORTRAN compilers available Open Source Tools and Compilers avr-GCC for C/C++ support AVR Studio Assembler / Simulator

Supported, official, Windows-only IDE

Page 20: Avr Microcontrollers

Operating System?

No common operating systems available None would work! EEPROM Bootloader / Initializer Real-Time Operating Systems Commercial Systems:

Salvo AVRX NutOS Proc

Page 21: Avr Microcontrollers

FreeRTOS

Free and Open Source Operating System Portable across many platforms Royalty Free

1-2KB storage 50-100Bytes Memory Can spawn off “tasks”

Guaranteed timings, simple “Coroutines”

Less memory, more complex, coexist, portable Commercial Sister Projects

Page 22: Avr Microcontrollers

Loading

EEPROM burner / custom Programmer ISP-interface

Serial / Parallel Programming (AVRdude) USB tty support Most IDE's available will make this job easy

Page 23: Avr Microcontrollers

Future

Smaller, Better, Faster, Cheaper Many new products become possible

Children's toys Ubiquitous Computing Physical Computing

Becoming very popular among Hobbyists Great introduction for CS people into EE-land

Page 24: Avr Microcontrollers

Websites / References

ATMEL www.atmel.com

Arduino www.arduino.cc

Adafruit Industries www.adafruit.com

FreeRTOS www.freertos.org

AVR Freaks www.avrfreaks.net