Professional Documents
Culture Documents
Vijay Iyengar
Atmel AVR
? The Atmel AVR is a family of RISC microcontroller from Atmel. ? AVR stands for Advanced Virtual RISC and/or the initials of the two company founders Alf- Egil Bogen and Vegard Wollans RISC ? It uses single cycle instructions and a well-defined I/O structure that limits the need for external components. ? Internal oscillators, timers, UART, SPI, pull-up resistors, pulse width modulation, ADC, analog comparator and watch-dog timers are some of the features you will find in AVR devices. ? AVR instructions are tuned to decrease the size of the program whether the code is written in C or Assembly.
Vijay Iyengar
Vijay Iyengar
AVR Overview
? Features- High Performance ? True RISC architecture ? True single cycle execution ? One MIPS per MHz ? 32 general purpose registers ? Harvard architecture ? AVR Flash microcontrollers operate with clock rates up to 20 MHz, achieving close to 20 MIPS. ? With 32 general purpose registers, the AVR delivers unmatched performance and flexibility, especially when you program in high-level languages, like C, Pascal or Basic.
Vijay Iyengar
AVR Overview
? Features- Low Power Consumption ? 1.8 to 5.5V operation ? A variety of sleep modes ? Fast wake-up from sleep modes ? Software controlled frequency ? Single cycle and high code density ? A wide operating range ensures great flexibility when it comes to power supplies. ? The microcontroller providing different sleep modes assures that between real-time events, AVR does not consume power while ensuring the fastest possible wakeup time. ? High code density ensures that a minimum of instructions and clock cycles are needed to execute a task, thereby reducing the power consumption significantly.
Vijay Iyengar
AVR Overview
? Features- Scalable ? Large device range ? Variety of pin counts ? Full code compatibility ? Pin/feature compatible families ? A large family of processors that share a single core architecture. This makes it easy to reuse code
Vijay Iyengar
AVR Overview
? Features- In-System Development: ? In-System Programming ? On-Chip Debugging ? In-system verification ? The device is its own emulator which ensures actual behavior and electrical characteristics. ? All the resources required for debugging is available on the tiniest 8-pin parts to the large 100-pin devices. ? Lock-bits protect your code from being inappropriately read or copied. ? Using any existing communication interface, the AVR devices also support self-programming, allowing them to upgrade their own firmware.
Vijay Iyengar
AVR Overview
? Features- Development Tools: ? Assemblers/ Simulator- AVR Studio ? Starter Kits ? Evaluation Boards ? On-chip Debuggers ? Emulators ? There is only one tool chain to learn for the whole range of AVR Flash microcontrollers.
Vijay Iyengar
Vijay Iyengar
AVR Classifications
Vijay Iyengar
AVR microcontrollers
? The AVR microcontrollers are divided into three groups: ? TinyAVR ? AVR (Classic AVR) ? megaAVR ? The difference between these devices mostly lies in the available features. ? The tinyAVR microcontrollers are usually devices with lower pin-count or reduced feature set compared to the megaAVR's . ? All AVR devices have the same instruction set and memory organization, so migrating from one device to another AVR is easy.
Vijay Iyengar
AVR microcontrollers
? In addition, the classic AVR is mostly EOL'd (End of life), so if you are looking to be able to buy replacements ever, go for the Mega or Tiny series. ? Some AVR's contain SRAM, EEPROM, External SRAM interface, Analog to Digital Converters, Hardware Multiplier, UART, USART and the list goes on. ? So which AVR microcontroller must one choose? ? For a tight power budget, you should only select an AVR that only includes the features you need. ? However, if size or power usage is not a problem, you should go for the biggest AVR possible.
Vijay Iyengar
AVR microcontrollers
The available tiny and mega AVR microcontrollers
Vijay Iyengar
AVR Packages
Vijay Iyengar
AVR Packages
? AVR microcontrollers come in the following packages: ? TQFP (Thin Quad Flat Pack): The Thin Quad Flat Pack (TQFP) package is a cost-effective packaging solution for moderate performance and lower lead count applications, where a lightweight, low profile package is required. ? PDIP (Plastic Dual In-Line): It comes in a wide range of lead counts: from 8 - 48 leads with a lead pitch of 100 mils. SPDIP package which is a shrink version of the PDIP with a 70 mil lead pitch and lead counts ranging from 30 - 64 leads. The SPDIP provides the option of decreasing the package size while maintaining the same lead count.
Vijay Iyengar
Packaging
Vijay Iyengar
Vijay Iyengar
Tiny AVR
? The tinyAVR devices are general purpose flash-based microcontroller. ? They offer an unrivaled combination of price, performance and flexibility. ? The same Flash-based microcontroller can be used for design, prototype evaluation and volume production resulting in cost reduction by minimizing inventory. ? The TinyAVR are available from 1K bytes to 8K bytes Flash program memory in very small packages.
Vijay Iyengar
Tiny AVR
? Features: ? internal RC Oscillator ? integrated EEPROM ? A/D Converter ? On-Chip 8-bit/16-bit timers and Watchdog ? High Frequency PWM with PLL ? On-Chip debug interface (debugWIRE)
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
MegaAVR
? The megaAVR devices are developed for applications that need to store a large amount of program code. ? The megaAVR offers substantial program and data memories, and performance approaching 1 MIPS per MHz. ? It delivers the power of self-programmability for fast, secure , cost-effective remote upgrades.
Vijay Iyengar
MegaAVR
? Features: ? Single cycle 8-bit RISC architecture ? Complete Family with 4K to 256K Bytes Flash ? Self programming Flash memory with boot block ? 10-bit A/D converter ? 8 x 8 Hardware Multiplier ? integrated EEPROM ? internal RC Oscillator ? USART, SPI and TWI compliant serial interfaces ? On-Chip 8-bit/16-bit timers and Watchdog ? On-Chip debug through JTAG or (debugWIRE) ? Extended voltage range ? Package range from 28-pin to 100-pin in DIP, TQFP and MLF types
Vijay Iyengar
Comparison of MegaAVR
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
CAN Networking
? It is a two-wire, half duplex, high-speed network system and is well suited for high speed applications using short messages, can theoretically link up to 2032 devices on a single network ? Atmel offer a family of product dedicated to advanced CAN bus standard (2.0A & 2.0B) with 80C51 core and AVR core. ? These microcontrollers with Flash memory provide the ultimate solution for designing advanced CAN based systems.
Vijay Iyengar
Vijay Iyengar
USB Controllers
? Atmel offers an extensive portfolio of USB products that include USB hubs, microcontrollers with integrated USB interface, and embedded USB hosts. ? These devices are designed specifically to hide the complexities of USB protocol from your embedded design. ? The availability of the USB firmware library, sample code, and software design tools such as the USB Wizard (a GUI based source code generator) further reduces your learning curve and ensures the shortest design cycle and the fastest time to market.
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
Clock Systems
? The clock frequency determines the rate at which the programs will execute. ? The clock can be operated with variety of components. ? Some processor have an internal RC oscillator.
Vijay Iyengar
Clock Systems
Clock Distribution
Vijay Iyengar
Clock Distribution
? CPU Clock clk CPU: Required for the operation of AVR core. ? I/O Clock clk I/O: The I/O clock is used by the majority of the I/O modules, like Timer/Counters, SPI, and USART. ? Flash Clock clk FLASH: The Flash clock controls operation of the Flash interface. ? Asynchronous Timer Clock clk ASY: It allows the Asynchronous Timer/Counter to be clocked directly from an external 32 kHz clock crystal. ? ADC Clock clk ADC: The ADC is provided with a dedicated clock domain.
Vijay Iyengar
Clock Sources
? ? ? ? ? External Crystal/Ceramic Resonator External Low-frequency Crystal External RC Oscillator Calibrated Internal RC Oscillator External Clock
Vijay Iyengar
Vijay Iyengar
RESET
? During Reset, all I/O registers are set to their initial values, and the program starts execution from the Reset Vector. ? The ATmega has certain sources of reset: ? Power-on Reset. The MCU is reset when the supply voltage is below the Power-on Reset threshold (V POT ). ? External Reset. The MCU is reset when a low level is present on the RESET pin for longer than the minimum pulse length. ? Watchdog Reset. The MCU is reset when the Watchdog Timer period expires and the Watchdog is enabled. ? Brown-out Reset. The MCU is reset when the supply voltage VCC is below the Brown-out Reset threshold .
Vijay Iyengar
RESET
RESET CIRCUIT:
Vijay Iyengar
Vijay Iyengar
Writing Code!
? In order to write an assembly code, we make use of the instruction set. ? We first see what is assembly language programming, followed by the instruction set. ? Prior to which we go through the I/O Port of the AVR microcontroller. ? Once our assembly code is ready, we then go ahead and learn how to assemble the code. ? Then we move on to program our controller. ? Our first assignment is to blink LEDs that are connected to a port of a AVR microcontroller.
Vijay Iyengar
Vijay Iyengar
What is I/O?
? I/O is Input or Output (Input/Output). ? It can be: ? A number of digital bits formed into a number of digital inputs or outputs called a port ? A serial line from or to the microprocessor (Tx /Rx) allowing serial data communication in the form of a bit stream on a two wire interface ? Other I/O devices such as ADC DAC, Timer modules, Interrupt controllers etc. ? A digital I/O port can be realized using a number of D type Flip-Flops
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
LEDs connections
Vijay Iyengar
LEDs
VCC_ARROW
PB0
? We make use of common anode type LEDs. ? This means that the LEDs will glow only when the PORT provides a logic 0
PB7
Vijay Iyengar
Switches
? This is how a switch is connected to a pin of a port. ? The switches are passive type of devices, that do not have a voltage source of its own. ? When these switches are connected to the input port we have to provide a pull up resistor so as to source current.
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
Instruction Set
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
Branch Instructions
? BRNE - Branch if Not Equal ? Description: Conditional relative branch. Tests the Zero flag (Z) and branches relatively to PC if Z is cleared. If the instruction is executed immediately after any of the instructions CP, CPI, SUB, SUBI, the branch will occur if and only if the unsigned or signed binary number represented in Rd was not equal to the unsigned or signed binary number represented in Rr. 1,k). ? Operation: If Rd ? Rr (Z = 0) then PC ? PC + k + 1, else PC ? PC + 1 ? Syntax: Operands: Program Counter: ? BRNE k -64 = k = +63 PC <- PC + k + 1 PC <- PC + 1, if condition is false
Vijay Iyengar
Branch Instructions
? RJMP - Relative Jump: ? Description: Relative jump to an address within PC - 2K +1 and PC + 2K (words). In the assembler, labels are used instead of relative operands. For AVR microcontrollers with program memory not exceeding 4K words (8K bytes) this instruction can address the entire memory from every address location. ? Operation: (i) PC ? PC + k + 1 Syntax: RJMP k Operands: -2K = k < 2 PC: PC ? PC + k + 1 Stack Unchanged
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
Assembly Code
.include
m8def. Inc rjmp ABC: ABC: ldi r16, 0XFF out DDRB,r16 Loop ldi r19,0x00 ldi r17, 0X06H DELAY: dec r16 brne DELAY dec r18 brne DELAY: dec r17 brne DELAY comp r19 out PORTB rjmp loop
; Delay subroutine
Vijay Iyengar
Vijay Iyengar
AVR Studio
? AVR Studio is an integrated development environment (IDE) for developing and debugging AVR applications. ? AVR Studio provides a project management tool, source file editor, simulator, in-circuit emulator interface and programming interface
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
Vijay Iyengar
Megaload
? MegaLoad is a Windows based boot loader for all Atmel ATmega microcontrollers that support the Bootloader function. ? MegaLoad is a solution for everybody who wants fast loading (~8k in 3 seconds) and easy software upgrade via MCU RS232 port.
Vijay Iyengar
Vijay Iyengar
Bootloader
? Boot loader: ? A program that is programmed into flash boot which allows the reprogramming of the AVR microcontroller ? This allows the self-programming feature of AVR ? Once the boot loader is programmed, it remains resident until the chip is erased. ? The flash memory is divided into two parts: ? Application Section: ?It is the section used for storing the application code ? Boot loader Section (BLS): ?The boot loader is stored in this section. ?The protection level is selected by the Boot Loader Lock bits.
Vijay Iyengar
Using MegaLoaod
? Run the MegaLoad program ? Click Open and locate the HEX file to program ? Select the COM port that the ATmega is connected to (only COM1-COM6 are supported) ? Select "Bootload on Reset" ? Connect the ATmega to the Windows PC ? Reset the ATmega ? MegaLoad should see the ATmega reset and will program the ATmega at the speed of light!
Vijay Iyengar
Vijay Iyengar
STK board
? The STK500 is controlled from AVR Studio, version 3.2 and higher. ? To program a hex file into the target AVR device, select STK500 from the Tools menu in AVR Studio. ? Select the AVR target device from the pull-down menu on the Program tab and locate the intel -hex file to download. ? The status LED will now turn yellow while the part is programmed, and when programming succeeds, the LED will turn green. If programming fails, the LED will turn red after programming.
Vijay Iyengar
Vijay Iyengar
Assignments
1. 2. Go through the Atmega8 datasheet Down Count Set a register as a down count register. Every time decrement the value of the register Out the value of register to PORT. Up Count Set a register as an up count register. Every time increment the value of the register. Send the value of register to PORT. Roll LEDs Blink one LED after another in succession. Set one bit in a temporary register. Rotate register using suitable instruction. Out the value of register to PORT.
Embedded Computing Machines Pvt. Ltd. support@embeddedmachines.com
2005 All Rights Reserved.
3.
4.
Vijay Iyengar
Assignments
5. Use the switches to choose an arithmetic or logical
operation and display the result on the LEDs. Initially put a zero on the LEDs and assign one of the following tasks to each switch: Increment (UP) Decrement (DOWN) Set all (OK) Clear all (Cancel) Pressing a switch should perform the task assigned to it using the data that currently exists on the LEDs. .
Vijay Iyengar