Microcontroller Systems. ELET 3232 Topic 3: AVR Architecture

Similar documents
8-bit Microcontroller with 1K Bytes In-System Programmable Flash. ATtiny13V ATtiny13

MICROPROCESSOR. Exclusive for IACE Students iacehyd.blogspot.in Ph: /422 Page 1

8-bit Microcontroller with 16K Bytes In-System Programmable Flash. ATmega162 ATmega162V. Features

Microprocessor & Assembly Language

8-bit Microcontroller with 2K Bytes In-System Programmable Flash. ATtiny2313/V. Preliminary

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

8-Bit Flash Microcontroller for Smart Cards. AT89SCXXXXA Summary. Features. Description. Complete datasheet available under NDA

ATtiny4 / ATtiny5 / ATtiny9 / ATtiny10. Introduction. Feature. Atmel 8-bit AVR Microcontroller with 512/1024 Bytes In-System Programmable Flash

MICROPROCESSOR AND MICROCOMPUTER BASICS

PART B QUESTIONS AND ANSWERS UNIT I

Chapter 13. PIC Family Microcontroller

CHAPTER 7: The CPU and Memory

8-bit Microcontroller with 1K Bytes In-System Programmable Flash. ATtiny13A

8-bit Microcontroller with 2/4/8K Bytes In-System Programmable Flash. ATtiny24 ATtiny44 ATtiny84

ATmega8A. Introduction. Features. 8-bit AVR Microcontroller DATASHEET COMPLETE

MACHINE ARCHITECTURE & LANGUAGE

Chapter 2 Logic Gates and Introduction to Computer Architecture

8-bit Atmel Microcontroller with 128KBytes In-System Programmable Flash. ATmega128 ATmega128L

Building A RISC Microcontroller in an FPGA

8-bit Microcontroller with 4/8/16/32K Bytes In-System Programmable Flash. ATmega48PA ATmega88PA ATmega168PA ATmega328P

8-bit Microcontroller with 8K Bytes In-System Programmable Flash. ATmega8515 ATmega8515L

ATmega16U4/ATmega32U4

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

Microcontroller Basics A microcontroller is a small, low-cost computer-on-a-chip which usually includes:

Atmel 8-bit AVR Microcontroller with 2/4/8K Bytes In-System Programmable Flash. ATtiny25/V / ATtiny45/V / ATtiny85/V. Features

8-bit Microcontroller with 32K/64K/128K Bytes of ISP Flash and CAN Controller AT90CAN32 AT90CAN64 AT90CAN128

8-bit Microcontroller with 16K Bytes In-System Programmable Flash. ATmega16 ATmega16L

An Introduction to the ARM 7 Architecture

8-bit Atmel with 8KBytes In- System Programmable Flash. ATmega8 ATmega8L

8-bit Microcontroller with 2K Bytes Flash. ATtiny26 ATtiny26L

(Refer Slide Time: 00:01:16 min)

An Overview of Stack Architecture and the PSC 1000 Microprocessor

8051 MICROCONTROLLER COURSE

CSE2102 Digital Design II - Topics CSE Digital Design II

Z80 Microprocessors Z80 CPU. User Manual UM Copyright 2014 Zilog, Inc. All rights reserved.

8085 INSTRUCTION SET

8-bit Microcontroller with 2/4/8K Bytes In-System Programmable Flash. ATtiny261/V* ATtiny461/V ATtiny861/V. *Mature

The AVR Microcontroller and C Compiler Co-Design Dr. Gaute Myklebust ATMEL Corporation ATMEL Development Center, Trondheim, Norway

Serial Communications

Instruction Set Architecture

ATmega128A. Introduction. Features. 8-bit AVR Microcontroller DATASHEET COMPLETE

Chapter 2 Basic Structure of Computers. Jin-Fu Li Department of Electrical Engineering National Central University Jungli, Taiwan

Atmel Norway XMEGA Introduction

8-bit Atmel Microcontroller with 8K/16K Bytes In-System Programmable Flash and LIN Controller. ATtiny87 ATtiny167

8-bit Microcontroller with 64K/128K/256K Bytes In-System Programmable Flash. ATmega640/V ATmega1280/V ATmega1281/V ATmega2560/V ATmega2561/V

8-bit Microcontroller. Application Note. AVR400: Low Cost A/D Converter

The Programming Interface

Central Processing Unit

Keil C51 Cross Compiler

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-17: Memory organisation, and types of memory

Introduction to Microcontrollers

Central Processing Unit (CPU)

Lecture N -1- PHYS Microcontrollers

Instruction Set Architecture. or How to talk to computers if you aren t in Star Trek

Chapter 1 Computer System Overview

8051 hardware summary

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-12: ARM

Logical Operations. Control Unit. Contents. Arithmetic Operations. Objectives. The Central Processing Unit: Arithmetic / Logic Unit.

LSN 2 Computer Processors

Technical Note. Micron NAND Flash Controller via Xilinx Spartan -3 FPGA. Overview. TN-29-06: NAND Flash Controller on Spartan-3 Overview

POCKET SCOPE 2. The idea 2. Design criteria 3

125kHz LF Reader/Writer with Integrated Atmel AVR Microcontroller. Atmel ATA5505. Preliminary

ET-BASE AVR ATmega64/128

2.0 Command and Data Handling Subsystem

CHAPTER 11: Flip Flops

ATmega32A. Introduction. Features. 8-Bit AVR Microcontroller DATASHEET COMPLETE

Faculty of Engineering Student Number:

Data Cables. Schmitt TTL LABORATORY ELECTRONICS II

Microcontroller Based Low Cost Portable PC Mouse and Keyboard Tester

8-bit Microcontroller with 8K/16K Bytes In-System Programmable Flash

Chapter 4 Register Transfer and Microoperations. Section 4.1 Register Transfer Language

PROBLEMS (Cap. 4 - Istruzioni macchina)

Introduction to Microcontrollers

Web Site: Forums: forums.parallax.com Sales: Technical:

Overview. CISC Developments. RISC Designs. CISC Designs. VAX: Addressing Modes. Digital VAX

User s Manual of Board Microcontroller ET-MEGA2560-ADK ET-MEGA2560-ADK

8-bit Atmel megaavr Microcontroller

AVR151: Setup and Use of the SPI. Introduction. Features. Atmel AVR 8-bit Microcontroller APPLICATION NOTE

Computer Organization. and Instruction Execution. August 22

Z80 Family. CPU User Manual

Chapter 1 Lesson 3 Hardware Elements in the Embedded Systems Chapter-1L03: "Embedded Systems - ", Raj Kamal, Publs.: McGraw-Hill Education

Exception and Interrupt Handling in ARM

İSTANBUL AYDIN UNIVERSITY

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Block 3 Size 0 KB 0 KB 16KB 32KB. Start Address N/A N/A F4000H F0000H. Start Address FA000H F8000H F8000H F8000H. Block 2 Size 8KB 16KB 16KB 16KB

CHAPTER 4 MARIE: An Introduction to a Simple Computer

USER GUIDE EDBG. Description

A 5 Degree Feedback Control Robotic Arm (Haptic Arm)

Chapter 6: From Digital-to-Analog and Back Again

8-bit RISC Microcontroller. Application Note. AVR910: In-System Programming

AVR Timer/Counter. Prof Prabhat Ranjan DA-IICT, Gandhinagar

RAM & ROM Based Digital Design. ECE 152A Winter 2012

Module 2. Embedded Processors and Memory. Version 2 EE IIT, Kharagpur 1

STEPPER MOTOR SPEED AND POSITION CONTROL

Serial port interface for microcontroller embedded into integrated power meter

Z80 Instruction Set. Z80 Assembly Language

1 Classical Universal Computer 3

MICROPROCESSOR BCA IV Sem MULTIPLE CHOICE QUESTIONS

How It All Works. Other M68000 Updates. Basic Control Signals. Basic Control Signals

Display Message on Notice Board using GSM

Transcription:

Microcontroller Systems ELET 3232 Topic 3: AVR Architecture

Objectives Examine the architecture of the AVR core Function of registers Interrupts ALU Status Register Memory map Stack and Stack Pointer Examine the block diagram of the ATmega128 Pin descriptions 1/5/2011 2

AVR Core Architecture Block diagram of the AVR Core architecture. Note the: -Different memories -Special Purpose Registers -General Purpose Registers -Special Purpose units -ALU 1/5/2011 3

AVR Core Architecture The blocks shown in blue are typical of a microprocessor. The other blocks, e.g. memories and special purpose units are what defines the difference between a microprocessor and a microcontroller. The main function of the CPU core is to ensure correct program execution. The CPU must therefore be able to access memories, perform calculations, control peripherals and handle interrupts. : ATmega128 Data Sheet, downloaded from http://www.atmel.com 1/5/2011 4

Harvard Architecture In order to maximize performance and parallelism, the AVR uses a Harvard architecture with separate memories and buses for program and data. Instructions in the program memory are executed with a single level pipelining. While one instruction is being executed, the next instruction is pre-fetched from the program memory. This concept enables instructions to be executed in every clock cycle. The program memory is In-System Reprogrammable Flash memory. : ATmega128 Data Sheet, downloaded from http://www.atmel.com 1/5/2011 5

Fast-Access Register File The fast-access Register file contains 32 x 8-bit general purpose working registers with a single clock cycle access time. This allows single-cycle Arithmetic Logic Unit (ALU) operation. In a typical ALU operation, two operands are output from the Register file, the operation is executed, and the result is stored back in the Register file in one clock cycle. : ATmega128 Data Sheet, downloaded from http://www.atmel.com 1/5/2011 6

Fast-Access Register File Six of the 32 registers can be used as three 16-bit indirect address register pointers for Data Space addressing enabling efficient address calculations. One of the these address pointers can also be used as an address pointer for look up tables in Flash Program memory. These added function registers are the 16-bit X-register, Y-register and Z- register, described later. : ATmega128 Data Sheet, downloaded from http://www.atmel.com 1/5/2011 7

ALU The ALU supports arithmetic and logic operations between registers or between a constant and a register. Single register operations can also be executed in the ALU. After an arithmetic operation, the Status Register is updated to reflect information about the result of the operation. : ATmega128 Data Sheet, downloaded from http://www.atmel.com 1/5/2011 8

AVR Instructions Program flow is provided by conditional and unconditional jump and call instructions, able to directly address the whole address space. Most AVR instructions have a single 16-bit word format. Every program memory address contains a 16- or 32-bit instruction. : ATmega128 Data Sheet, downloaded from http://www.atmel.com 1/5/2011 9

Memory Program Flash memory space is divided in two sections, the Boot Program section and the Application Program section. Both sections have dedicated Lock bits for write and read/write protection. The SPM instruction that writes into the Application Flash Memory section must reside in the Boot Program section. : ATmega128 Data Sheet, downloaded from http://www.atmel.com 1/5/2011 10

Interrupts During interrupts and subroutine calls, the return address Program Counter (PC) is stored on the Stack. The Stack is effectively allocated in the general data SRAM, and consequently the stack size is only limited by the total SRAM size and the usage of the SRAM. All user programs must initialize the SP in the reset routine (before subroutines or interrupts are executed). The Stack Pointer SP is read/write accessible in the I/O space. The data SRAM can easily be accessed through the five different addressing modes supported in the AVR architecture. : ATmega128 Data Sheet, downloaded from http://www.atmel.com 1/5/2011 11

Interrupts A flexible interrupt module has its control registers in the I/O space with an additional global interrupt enable bit in the Status Register. All interrupts have a separate interrupt vector in the interrupt vector table. The interrupts have priority in accordance with their interrupt vector position. The lower the interrupt vector address, the higher the priority. : ATmega128 Data Sheet, downloaded from http://www.atmel.com 1/5/2011 12

I/O Memory Space The I/O memory space contains 64 addresses which can be accessed directly, or as the Data Space locations following those of the Register file, $20 - $5F. In addition, the ATmega128 has Extended I/O space from $60 - $FF in SRAM where only the ST/STS/STD and LD/LDS/LDD instructions can be used. : ATmega128 Data Sheet, downloaded from http://www.atmel.com 1/5/2011 13

ALU The high-performance AVR ALU operates in direct connection with all the 32 general purpose working registers. Within a single clock cycle, arithmetic operations between general purpose registers or between a register and an immediate are executed. The ALU operations are divided into three main categories arithmetic, logical, and bit-functions. Some implementations of the architecture also provide a powerful multiplier supporting both signed/unsigned multiplication and fractional format. : ATmega128 Data Sheet, downloaded from http://www.atmel.com 1/5/2011 14

Status Register The Status Register contains information about the result of the most recently executed arithmetic instruction. This information can be used for altering program flow in order to perform conditional operations. Note that the Status Register is updated after all ALU operations, as specified in the Instruction Set Reference. This will in many cases remove the need for using the dedicated compare instructions, resulting in faster and more compact code. The status register is not automatically stored when entering an interrupt routine and restored when returning from an interrupt. This must be handled by software. : ATmega128 Data Sheet, downloaded from http://www.atmel.com 1/5/2011 15

Status Register Bits Bit 7 I: Global Interrupt Enable The Global Interrupt Enable bit must be set for the interrupts to be enabled. The individual interrupt enable control is then performed in separate control registers. If the Global Interrupt Enable Register is cleared, none of the interrupts are enabled independent of the individual interrupt enable settings. The I-bit is cleared by hardware after an interrupt has occurred, and is set by the RETI instruction to enable subsequent interrupts. The I-bit can also be set and cleared in software with the SEI and CLI instructions, as described in the instruction set reference. : ATmega128 Data Sheet, downloaded from http://www.atmel.com 1/5/2011 16

Status Register Bits Bit 6 T: Bit Copy Storage The Bit Copy instructions BLD (Bit LoaD) and BST (Bit STore) use the T-bit as source or destination for the operated bit. A bit from a register in the Register file can be copied into T by the BST instruction, and a bit in T can be copied into a bit in a register in the Register file by the BLD instruction. : ATmega128 Data Sheet, downloaded from http://www.atmel.com 1/5/2011 17

Status Register Bits Bit 5 H: Half Carry Flag The Half Carry Flag H indicates a half carry in some arithmetic operations. Half carry is useful in BCD arithmetic. See the Instruction Set Description for detailed information. Bit 4 S: Sign Bit, S = N EOR V The S-bit is always an exclusive or between the negative flag N and the two s complement overflow flag V. See the Instruction Set Description for detailed information. : ATmega128 Data Sheet, downloaded from http://www.atmel.com 1/5/2011 18

Status Register Bits Bit 3 V: Two s Complement Overflow Flag The Two s Complement Overflow Flag V supports two s complement arithmetic. See the Instruction Set Description for detailed information. Bit 2 N: Negative Flag The Negative Flag N indicates a negative result in an arithmetic or logic operation. See the Instruction Set Description for detailed information. : ATmega128 Data Sheet, downloaded from http://www.atmel.com 1/5/2011 19

Status Register Bits Bit 1 Z: Zero Flag The Zero Flag Z indicates a zero result in an arithmetic or logic operation. See the Instruction Set Description for detailed information. Bit 0 C: Carry Flag The Carry Flag C indicates a carry in an arithmetic or logic operation. See the Instruction Set Description for detailed information. : ATmega128 Data Sheet, downloaded from http://www.atmel.com 1/5/2011 20

The Register File The Register file is optimized for the AVR Enhanced RISC instruction set. In order to achieve the required performance and flexibility, the following input/output schemes are supported by the Register file: One 8-bit output operand and one 8-bit result input Two 8-bit output operands and one 8-bit result input Two 8-bit output operands & one 16-bit result input One 16-bit output operand & one 16-bit result input Most of the instructions operating on the Register file have direct access to all registers, and most of them are single cycle instructions. As shown above, each register is also assigned a data memory address, mapping them directly into the first 32 locations of the user Data Space. Although not being physically implemented as SRAM locations, this memory organization provides great flexibility in access of the registers, as the X-, Y-, and Z-pointer Registers can be set to index any register in the file. : ATmega128 Data Sheet, downloaded from http://www.atmel.com 1/5/2011 21

The X, Y, and Z Registers The R26..R31 registers have some added functions to their general purpose usage. These registers are 16-bit address pointers for indirect addressing of the Data Space. The three indirect address registers X, Y, and Z are shown above. In the different addressing modes these address registers have functions as fixed displacement, automatic increment, and automatic decrement. 1/5/2011 : ATmega128 Data Sheet, downloaded from http://www.atmel.com 22

The Stack and Stack Pointer The Stack is mainly used for storing temporary data, for storing local variables and for storing return addresses after interrupts and subroutine calls. The Stack Pointer Register always points to the top of the Stack. Note that the Stack is implemented as growing from higher memory locations to lower memory locations. This implies that a Stack PUSH command decreases the Stack Pointer. The AVR Stack Pointer is implemented as two 8-bit registers in the I/O space. The number of bits actually used is implementation dependent. Note that the data space in some implementations of the AVR architecture is so small that only SPL is needed. In this case, the SPH Register will not be present. 1/5/2011 : ATmega128 Data Sheet, downloaded from http://www.atmel.com 23

The Stack and Stack Pointer The Stack Pointer points to the data SRAM stack area where the Subroutine and Interrupt Stacks are located. This Stack space in the data SRAM must be defined by the program before any subroutine calls are executed or interrupts are enabled. The Stack Pointer must be set to point above $60. The Stack Pointer is decremented by one when data is pushed onto the Stack with the PUSH instruction, and it is decremented by two when the return address is pushed onto the Stack with subroutine call or interrupt. The Stack Pointer is incremented by one when data is popped from the Stack with the POP instruction, and it is incremented by two when data is popped from the Stack with return from subroutine RET or return from interrupt RETI.. 1/5/2011 : ATmega128 Data Sheet, downloaded from http://www.atmel.com 24

Instruction Timing The AVR CPU is driven by the CPU clock, directly generated from the selected clock source for the chip. No internal clock division is used. The image shows the parallel instruction fetches and instruction executions enabled by the Harvard architecture and the fast-access Register file concept. This is the basic pipelining concept to obtain up to 1 MIPS per MHz with the corresponding unique results for functions per cost, functions per clocks, and functions per power-unit. 1/5/2011 : ATmega128 Data Sheet, downloaded from http://www.atmel.com 25

Instruction Timing This image shows the internal timing concept for the Register file. In a single clock cycle an ALU operation using two register operands is executed, and the result is stored back to the destination register. 1/5/2011 : ATmega128 Data Sheet, downloaded from http://www.atmel.com 26

Interrupts The AVR provides several different interrupt sources. These interrupts and the separate reset vector each have a separate program vector in the program memory space. All interrupts are assigned individual enable bits to which must be written a logic one together with the Global Interrupt Enable bit in the Status Register in order to enable the interrupt. Depending on the Program Counter value, interrupts may be automatically disabled when Boot Lock bits BLB02 or BLB12 are programmed. 1/5/2011 : ATmega128 Data Sheet, downloaded from http://www.atmel.com 27

Interrupts The complete list of vectors and priority levels of the different interrupts are shown to the right. The lower the address the higher is the priority level. RESET has the highest priority, and next is INT0 the External Interrupt Request 0. 1/5/2011 : ATmega128 Data Sheet, downloaded from http://www.atmel.com 28

Interrupts When an interrupt occurs, the Global Interrupt Enable I-bit is cleared and all interrupts are disabled. The user software can write logic one to the I-bit to enable nested interrupts. All enabled interrupts can then interrupt the current interrupt routine. The I-bit is automatically set when a Return from Interrupt instruction RETI is executed. 1/5/2011 : ATmega128 Data Sheet, downloaded from http://www.atmel.com 29

Remembered Interrupts There are basically two types of interrupts. The first type is triggered by an event that sets the interrupt flag. For these interrupts, the Program Counter is vectored to the actual interrupt vector in order to execute the interrupt handling routine, and hardware clears the corresponding interrupt flag. Interrupt flags can also be cleared by writing a logic one to the flag s bit position(s). If an interrupt condition occurs while the corresponding interrupt enable bit is cleared (0), the interrupt flag will be set and remembered until the interrupt is enabled, or the flag is cleared by software. Similarly, if one or more interrupt conditions occur while the global interrupt enable bit is cleared, the corresponding interrupt flag(s) will be set and remembered until the global interrupt enable bit is set, and will then be executed by order of priority. 1/5/2011 : ATmega128 Data Sheet, downloaded from http://www.atmel.com 30

Time-Sensitive Interrupts The second type of interrupt will trigger as long as the interrupt condition is present. These interrupts do not necessarily have interrupt flags. If the interrupt condition disappears before the interrupt is enabled, the interrupt will not be triggered. When the AVR exits from an interrupt, it will always return to the main program and execute one more instruction before any pending interrupt is served. Note that the Status Register is not automatically stored when entering an interrupt routine, nor restored when returning from an interrupt routine. This must be handled by software. 1/5/2011 : ATmega128 Data Sheet, downloaded from http://www.atmel.com 31

Interrupts When using the CLI instruction to disable interrupts, the interrupts will be immediately disabled. No interrupt will be executed after the CLI instruction, even if it occurs simultaneously with the CLI instruction. The following example shows how this can be used to avoid interrupts during the timed EEPROM write sequence. When using the SEI instruction to enable interrupts, the instruction following SEI will be executed before any pending interrupts. 1/5/2011 : ATmega128 Data Sheet, downloaded from http://www.atmel.com 32

Memory The AVR architecture has two main memory spaces, the Data Memory and the Program Memory space. In addition, the ATmega128 features an EEPROM Memory for data storage. The ATmega128 contains 128K bytes On-chip In-System Reprogrammable Flash memory for program storage. Since all AVR instructions are 16 or 32 bits wide, the Flash is organized as 64K x 16. For software security, the Flash Program memory space is divided into two sections, Boot Program section and Application Program section. The Flash memory has an endurance of at least 10,000 write/erase cycles. The ATmega128 Program Counter (PC) is 16 bits wide, thus addressing the 64K program memory locations. 1/5/2011 : ATmega128 Data Sheet, downloaded from http://www.atmel.com 33

Block Diagram of the ATmega128 The AVR core combines a rich instruction set with 32 general purpose working registers. All the 32 registers are directly connected to the Arithmetic Logic Unit (ALU), allowing two independent registers to be accessed in one single instruction executed in one clock cycle. The resulting architecture is more code efficient while achieving throughputs up to ten times faster than conventional CISC microcontrollers. 1/5/2011 : ATmega128 Data Sheet, downloaded from http://www.atmel.com 34

Ports A - G Ports A - G are 8-bit bidirectional I/O ports with internal pull-up resistors (selected for each bit). The port output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port pins that are externally pulled low will source current if the pull-up resistors are activated. The Port pins are tri-stated when a reset condition becomes active, even if the clock is not running. 1/5/2011 : ATmega128 Data Sheet, downloaded from http://www.atmel.com 35

Other Pins Reset: A low level on this pin for longer than the minimum pulse length will generate a reset, even if the clock is not running. XTAL1: Input to the inverting Oscillator amplifier and input to the internal clock operating circuit. XTAL2: Output from the inverting Oscillator amplifier. 1/5/2011 : ATmega128 Data Sheet, downloaded from http://www.atmel.com 36

Other Pins AVCC: the supply voltage pin for Port F and the A/D Converter. It should be externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCC through a low-pass filter. AREF: the analog reference pin for the A/D Converter. 1/5/2011 : ATmega128 Data Sheet, downloaded from http://www.atmel.com 37

Other Pins PEN: a programming enable pin for the SPI Serial Programming mode, and is pulled high internally. By holding this pin low during a Power-on Reset, the device will enter the SPI Serial Programming mode. PEN has no function during normal operation. 1/5/2011 : ATmega128 Data Sheet, downloaded from http://www.atmel.com 38

Summary In this topic we: Examined the architecture of the AVR core Function of registers Interrupts ALU Status Register Memory map Stack and Stack Pointer Examined the block diagram of the ATmega128 Pin descriptions 1/5/2011 39