Module 2: Introduction to AVR ATmega 32 Architecture

Similar documents
FIFTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLOGY-MARCH 2014 EMBEDDED SYSTEMS (Common for CT,CM) [Time: 3 hours] (Maximum marks : 100)

2011 Pearson Higher Education, Mazidi, Naimi, and Naimi Pearson Higher Education, 2011 Pearson Higher Education,

COMP2121: Microprocessors and Interfacing. Instruction Set Architecture (ISA)

Lecture 14. Ali Karimpour Associate Professor Ferdowsi University of Mashhad

AVR MICROCONTROLLER ARCHITECTURTE

AVR Microcontrollers Architecture

Ali Karimpour Associate Professor Ferdowsi University of Mashhad

EE 308: Microcontrollers

Microprocessors And Microcontroller

Ali Karimpour Associate Professor Ferdowsi University of Mashhad

COMP3221: Microprocessors and. and Embedded Systems. Instruction Set Architecture (ISA) What makes an ISA? #1: Memory Models. What makes an ISA?

Lecture 2. Introduction to Microcontrollers

EE 308: Microcontrollers

Microcontrollers. Microcontroller

ATmega128. Introduction

Lecture Objectives. Introduction to Computing Chapter 0. Topics. Numbering Systems 04/09/2017

Embedded Systems. PIC16F84A Internal Architecture. Eng. Anis Nazer First Semester

ECED3204: Microprocessor Part I--Introduction

Microcomputer Architecture and Programming

Objectives. I/O Ports in AVR. Topics. ATmega16/mega32 pinout. AVR pin out The structure of I/O pins I/O programming Bit manipulating 22/09/2017

MICROPROCESSOR AND MICROCONTROLLER BASED SYSTEMS

CPU. Objectives. Introduction to Assembly Chapter 2. Topics. AVR s CPU 12/09/2017

Chapter 1. Microprocessor architecture ECE Dr. Mohamed Mahmoud.

Introduction to Assembly language

ELCT708 MicroLab Session #1 Introduction to Embedded Systems and Microcontrollers. Eng. Salma Hesham

EE 308: Microcontrollers

1 MALP ( ) Unit-1. (1) Draw and explain the internal architecture of 8085.


Review on Lecture-1. ICT 6641: Advanced Embedded System. Lecture 2 Branch, Call and Delay Loops, AVR I/O port programming

Programming Microcontroller Assembly and C

Computer Hardware Requirements for ERTSs: Microprocessors & Microcontrollers

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo

Microprocessors/Microcontrollers

Embedded programming, AVR intro

Microprocessors and Microcontrollers. Assignment 1:

Introduction to Microcontrollers

In this tutorial, we will discuss the architecture, pin diagram and other key concepts of microprocessors.

INTERFACING HARDWARE WITH MICROCONTROLLER

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo

Microprocessors I MICROCOMPUTERS AND MICROPROCESSORS

IAS0430 MICROPROCESSOR SYSTEMS

CPE 323 MSP430 INSTRUCTION SET ARCHITECTURE (ISA)

ELC4438: Embedded System Design Embedded Processor

Introduction to Microcontrollers

AVR ISA & AVR Programming (I)

An FPGA Implementation of 8-bit RISC Microcontroller

Chapter 1: Basics of Microprocessor [08 M]

Introduction to Microprocessor

COMP2121: Microprocessors and Interfacing. I/O Devices (I)

8-bit Microcontroller with 8K Bytes Programmable Flash AT90C8534. Preliminary

1. Internal Architecture of 8085 Microprocessor

UNIVERSITY OF MORATUWA CS2052 COMPUTER ARCHITECTURE. Time allowed: 2 Hours 10 min December 2018

8-bit Microcontroller with 2K Bytes of In-System Programmable Flash AT90S2323 AT90LS2323 AT90S2343 AT90S/LS2323. Features.

Dec Hex Bin ORG ; ZERO. Introduction To Computing

MICROPROCESSOR BASED SYSTEM DESIGN

Introduction to 8051 microcontrollers

8-bit Microcontroller with 2K Bytes of In-System Programmable Flash AT90S2313

8051 microcontrollers

Lecture 1. Course Overview and The 8051 Architecture

Embedded Systems Design (630414) Lecture 1 Introduction to Embedded Systems Prof. Kasim M. Al-Aubidy Computer Eng. Dept.

8-bit Microcontroller with 2K Bytes of In-System Programmable Flash. ATtiny22 ATtiny22L. Preliminary. Features. Description

Automation Engineers AB Pvt Ltd, NOIDA Job-Oriented Course on Embedded Microcontrollers & Related Software Stack

COMPUTER STRUCTURE AND ORGANIZATION

INTRODUCTION TO MICROPROCESSORS

Microcontroller systems Lec 2 PIC18LF8722 Microcontroller s s core

INTEL Architectures GOPALAKRISHNAN IYER FALL 2009 ELEC : Computer Architecture and Design

ME 515 Mechatronics. A microprocessor

AVR. (AVR Assembly Language) Assembler . ก ก

Chapter 1 : Introduction

ECE2049 E17 Lecture 4 MSP430 Architecture & Intro to Digital I/O

ASSEMBLY LANGUAGE MACHINE ORGANIZATION

AVR. 2. (Assembler directives ) 3. ( Instruction field) 5. (Comment field) 1. (Label field) Assembler. 4. ก (Operands field) (AVR Assembly Language)

7/28/ Prentice-Hall, Inc Prentice-Hall, Inc Prentice-Hall, Inc Prentice-Hall, Inc Prentice-Hall, Inc.

Introduction to Embedded Systems

AT90S Bit Microcontroller with 1K bytes Downloadable Flash AT90S1200. Features. Description. Pin Configuration

CN310 Microprocessor Systems Design

ELEG3923 Microprocessor Ch.0 & Ch.1 Introduction to Microcontroller

8086 INTERNAL ARCHITECTURE

The Microcontroller. Lecture Set 3. Major Microcontroller Families. Example Microcontroller Families Cont. Example Microcontroller Families

Module 8: Atmega32 Stack & Subroutine. Stack Pointer Subroutine Call function

Module I. Microcontroller can be classified on the basis of their bits processed like 8bit MC, 16bit MC.

Diploma in Embedded Systems

8-bit Microcontroller with 2K Bytes of Flash. ATtiny28L ATtiny28V

CHAPTER 5 : Introduction to Intel 8085 Microprocessor Hardware BENG 2223 MICROPROCESSOR TECHNOLOGY

Chapter 2 Logic Gates and Introduction to Computer Architecture

Computer Organization

EE 354 Fall 2015 Lecture 1 Architecture and Introduction

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING

MICROCONTROLLERS 8051

COMP2121 Experiment 4

Question Bank Microprocessor and Microcontroller

Robosoft Systems in association with JNCE presents. Swarm Robotics

1. INTRODUCTION TO MICROPROCESSOR AND MICROCOMPUTER ARCHITECTURE:

8-bit Microcontroller with 1K Byte of In-System Programmable Flash AT90S1200

Lecture (01) Introducing Embedded Systems and the Microcontrollers By: Dr. Ahmed ElShafee

CREATED BY M BILAL & Arslan Ahmad Shaad Visit:

Midrange 8b PIC Microcontrollers. ECE Senior Design 14 February 2017

b. List different system buses of 8085 microprocessor and give function of each bus. (8) Answer:

acret Ameya Centre for Robotics & Embedded Technology Syllabus for Diploma in Embedded Systems (Total Eight Modules-4 Months -320 Hrs.

Segment 1A. Introduction to Microcomputer and Microprocessor

Transcription:

Module 2: Introduction to AVR ATmega 32 Architecture Definition of computer architecture processor operation CISC vs RISC von Neumann vs Harvard architecture AVR introduction AVR architecture

Architecture & Organization Definition

Definition of Architecture & Organization What is architecture? o Architecture is how a computer system is designed and what technologies it is compatible with. o The attributes of a system are visible to a programmer. o These attributes have a direct impact on the logical execution of a program (i.e. instruction set, number of bits used for data representation, I/O mechanisms, addressing techniques). o There two type of computer architecture. o Von Neumann architecture: a computer architecture with physically single storage and signal pathways for instructions and data. o Harvard architecture: a computer architecture with physically separate storage and signal pathways for instructions and data.

Von Neumann Architecture o The computer has single storage system(memory) for storing data as well as program to be executed. o Processor needs two clock cycles to complete an instruction. Pipelining the instructions is not possible with this architecture. o In the first clock cycle the processor gets the instruction from memory and decodes it. In the next clock cycle the required data is taken from memory. For each instruction this cycle repeats and hence needs two cycles to complete an instruction. o This is a relatively older architecture and was replaced by Harvard architecture.

Harvard Architecture o The computer has two separate memories for storing data and program. o Processor can complete an instruction in one cycle if appropriate pipelining strategies are implemented. o In the first stage of pipeline the instruction to be executed can be taken from program memory. In the second stage of pipeline data is taken from the data memory using the decoded instruction or address. o Most of the modern computing architectures are based on Harvard architecture. But the number of stages in the pipeline varies from system to system.

Definition of Architecture & Organization What is organization? o Computer Organization is typically refers to the operational units of the system together with their interconnection how features are implemented. o It consists of hardware details that are transparent to the programmers.

Processor Architecture & Organization Many computer manufacturers offer a family of computer models, all with the same architecture but with differences in organization. This gives code compatibility (at least backwards) o All Intel x86 family share the same basic architecture o The IBM System/370 family share the same basic architecture An architecture may survive many years, but its organization changes with the changing technology. o E.g. the IBM Systems/370 architecture, with few enhancements, has survived to this day as the architecture of IBM's mainframe product line.

Processor ISA (Industry Standard Architecture): CISC vs RISC CISC RISC Emphasis on hardware Emphasis on software Include multi-clock complex instructions Include single-clock reduce instruction only Memory-to-memory: Load and Store incorporated in instructions Small code sizes, high cycles per second Transistors used for storing complex instructions RISC vs. CISC is a topic quite popular on the Net. Every time Intel (CISC) or Apple (RISC) introduces a new CPU, the topic pops up again. Most PC's use CPU based on CISC architecture. For instance Intel and AMD CPU's are based on CISC architectures. Many claim that RICS is the architecture of the future. Register-to-register: Load and Store are independent instructions Low cycles per second, large code sizes Spends more transistors on memory registers But even though RISC has been in the market since 1980, it hasn t managed to kick CISC out of the picture, some argue that if it is really the architecture of the future it should have been able to do this by now.

Introduction to AVR

Introduction to AVR The AVR architecture was designed by two students Alf-Egil Bogen and Vegard Wollan in Norway and then was bought and developed by Atmel in 1996. There are many kind of AVR microcontroller with different properties. Except for AVR32 (32-bit microcontroller), AVRs are all 8-bit microprocessors the CPU can work only 8 bits of data at a time. Data larger that 8 bits has to be broken into 8-bit pieces to be processed by the CPU. The AVR is a modified Harvard architecture machine where program and data is stored in separate physical memory systems that appear in different address spaces, but having the ability to read data items from program memory using special instructions.

AVR Family Overview AVRs are generally classified into four groups: o Classic AVR (AT90Sxxxx) o This is the original AVR chip o i.e. AT90S2313, AT90S4433

o Mega AVR (ATmegaxxxx) AVR Family Overview o These are powerful microcontrollers with more than 120 instructions o Has lots of different peripheral capabilities, which can be used in different designs. o i.e. ATmega8, ATmega32, ATmega128

o Tiny AVR (ATtinyxxxx) AVR Family Overview o Has less instructions and smaller packages compared to mega family. o Can design systems with low cost and power consumption using Tiny AVRs. o i.e. ATtiny13, ATtiny25

o Special purpose AVR AVR Family Overview o The ICs of this group can be considered as a subset of other groups. o But their special capabilities are made for designing specific applications such USB controller, CAN controller, LCD controller, Zigbee, Ethernet controller, FPGA. o i.e. AT90PWM216,AT90USB1287

Let s get familiar with AVR part number ATmega128 Atmel mega group ROM =128K ATtiny44 AT90S4433 Atmel Tiny group ROM =4K Atmel Classic group ROM =4K

ATmega32 Pin Out

Atmega32 Pin Out Port B Clears all the Provides registers supply and voltage restart the to the chip. These execution It pins should of are be used connected program to connect to +5 external crystal for clock source Port A Reference voltage Supply for voltage ADC for ADC and porta. Connect it to VCC Port D Port C 20112012-I

I/O Port Pins & Their Function o The number of ports in the AVR family varies depending on the number of pins on the chip. o 8-pin AVR has port B only. o 64-pin version has ports A through F. o 100-pin AVR has ports A through L. o 40-pin AVR (ATmega32), has four ports: PORTA, PORTB, PORTC and PORTD. o It must be programmed first before we use any of these ports as an input or output. o Each port has three I/O registers associated with it; o PORTx: Data Register for send/out data. (Write) o DDRx: Data Direction Register. (Read/Write) o PINx: Dara Register for in/receive data. (Read only)

I/O Port Pins & Their Function o Each of the I/O registers are 8 bits wide, and each port has a maximum of 8 pins. o Therefore each bit of the I/O registers affects one of the pins.

DDRx Register o Each of the ports A-D in the ATmega32 can be used for input and output. o The DDRx I/O register is used solely for the purpose of making a given port an input or output port. o To make a port an output, write 1s to the DDRx register. o Example: Make port B as output, thus write 0b11111111 into DDRB register to make all of the pins output. o To make a port an input, write 0s to the DDRx register. o Example: Make port B as output, thus write 0b00000000 into DDRB register to make all of the pins input. 0x00 0x00 0b00000000 (0000 0000)

DDRx Register o Example: Define what happen to the pins when, 0b01110101 is write into DDRA register, as instructions below: LDI R20,0x75 ;R20 = 0b01110101 (binary) LDI R17, 0x0F ;R17 = ob00001111 OUT DDRA,R20 ;DDRA = R20 OUT PORTA,R17 ;PORTA =??? IN R18,PINA ;R18 =??? Lets input at PINA = 11111111

PINx Register o PINx register is used to read the data at the pins. o In which to bring the data into CPU from pins, we read the contents of the PINx register.

PORTx Register o PORTx register is used to send the data out to the pins. o However, PORTx register also can demonstrate for inputting data by putting 1s to activate the pull-up resistor.

AVR Architecture

AVR Architecture o AVR uses Harvard architecture, that has separate buses for the code and data memory. o Two kind of busses in AVR; o Program Bus provide access to Program Flash ROM. o Data Bus to bring data to the CPU.

o Two kinds of memory space in AVR: o Code memory space where program is stored. o Data memory space stores data. o The data memory is composed of three parts: o General register. o I/O register o Internal data SRAM AVR Data Memory purpose

General Purpose Registers (GPRs) in AVR o AVR microcontrollers have many registers for arithmetic and logic operations. o In the CPU, registers are used to store information temporarily. o That information could be; o A byte of data to be processed o And address pointing to the data to be fetched. o The majority of AVR registers are 8-bit registers because in AVR only one data type: 8-bit. MSB LSB o With an 8-bit data type, any data larger than 8 bits must be broken into 8-bit chunks before it is processed.

General Purpose Registers (GPRs) in AVR o In AVR there are 32 general purpose registers. o They are R01-R31 and are located in the lowest location of memory address. o To understand of the purpose of general purpose registers, two simple instructions LDI and ADD is used as example.

GPRs: LDI Instruction o LDI copies 8-bit data into general purpose registers. o K is an 8-bit value that can be 0-255 (decimal), or 00-FF (hex). o Rd is R16 to R31. (Note: cannot load values into registers R0-R15 using LDI, because its not valid). o Example: Loads the R20 register with a value of 0x25 (25 in hex).

GPRs: ADD Instruction o ADD to add the value of Rr to Rd and put the result back into Rd register. o Example: To add two numbers such as 0x25 and 0x34, one can do the following: o Executing the above line results in R16 = 0x59 (0x25 + 0x34 = 0x59).

I/O Memory o The I/O memory is dedicated to specific function such as status register, timers, serial communication, I/O ports, ADC and etc. o The function of each I/O memory location is fixed by the CPU designer. o The number of locations in the data memory set aside for I/O memory depends on the pin numbers and peripheral functions supported by that chip. o But, all off the AVRs have at least 64 bytes of locations called standard I/O memory. I/O memory

Internal Data SRAM o Internal data SRAM widely used for storing data and parameters by AVR programmers and C compilers. o Each location of the SRAM can be accessed directly by its address. o Each location is 8 bits wide and can be used to store any data we want. o The size of SRAM can be vary from chip to chip.

Using Instruction With Data Memory o Earlier we saw a simple example of using LDI and ADD that uses immediate (constant) value of K and the GPRs. o Meanwhile, the AVR also allows direct access to other location in the data memory. o In this section, we will learn the instructions accessing various locations of the data memory.

Data Memory: LDS instruction o LDS (LoaD direct from data Space) instruction tells CPU to load (copy) one byte from an address in the data memory to GPR. o After the instruction is executed, the GPR will have the same values as the location in the data memory. o Example: Loads the R5 with the contents of location 0x200. o Example: Adds the contents of location 0x300 to location 0x302.

Data Memory: LDS instruction

Data Memory: STS instruction o STS (STore direct to data Space) instruction tells CPU to store (copy) the contents of the GPR to an address location in the data memory. o After the instruction is executed, the location in the data space will have the same value as GPR. o Example: Stores the contents of R25 to location 0x230. o Example: Loads the R16 register with value 0x55, then moves this value around to I/O registers of ports B (0x38), C (0x35) and D (0x32).

Data Memory: IN instruction o IN (IN from I/O location) instruction tells CPU to load one byte from an I/O register to GPR. o After the instruction is executed, the GPR will have the same value as I/O register. o Each location in I/O memory has two address: o Data memory address o I/O address address of each I/O register in comparison in comparison of the beginning of the I/O memory o IN instruction, the I/O registers are referred by the I/O address. o Example: Load R19 with the contents of location 0x10 of the I/O memory.

Data Memory: IN instruction

Data Memory: IN instruction o To work with the I/O registers more easily, we can use their names instead of their I/O addresses. o Example: Load R19 with the contents of PIND.

Data Memory: OUT instruction o OUT (OUT to I/O location) instruction tells CPU to store GPR to the I/O register. o After the instruction is executed, the I/O register will have the same value as GPR. o OUT instruction, the I/O registers are referred by the I/O address. o Example: Copy 0xE6 to SPL register. Note: cannot copy an immediate value to an I/O register nor to an SRAM location.

Data Memory: OUT instruction o Example: Copies PIND to PORTA.

Data Memory: MOV instruction o MOV instruction is used to copy data among the GPR registers (R0-R31). o Example: Copies the contents of R20 to R10.

More ALU instructions involving GPRs

ALU Instruction: INC o INC instruction increments the contents of Rd (register) by 1. o Example: Adds 1 to the contents of R2. o Example: Increase the contents of data memory location 0x430 by 1.

ALU Instruction: DEC o DEC instruction decrements the contents of Rd (register) by 1. o Example: Subtracts 1 to the contents of R10. o Example: Put the value 3 into R30, then the value of R30 is decremented three times.

ALU Instruction: SUB o SUB instruction tells the CPU to subtract the value of Rr from Rd and put the result back into the Rd register. o Example: Subtract 0x25 from 0x34 values. o Example: Subtracts 5 from the contents of location 0x300 and stores the result in location 0x3200.

ALU Instruction: Others

ALU Instruction: Others

AVR Status Register

AVR Status Register o Like other μps, the AVR has a flag register to indicate arithmetic condition such as the carry bit. o The flag register in the AVR is called status register (SReg) o The status register is an 8-bit register that contains of C, Z, N, V, S and H that are called conditional flags (to indicate some conditions that result after an instruction is executed).

o C, the carry flag AVR Status Register o The flag is set whenever there is a carry out from D7 bit, in which after an 8-bit addition or subtraction. o Z, the zero flag o The flag reflects the result of an arithmetic or logic operation. o If the result is zero, then Z=1. if the result is not zero, then Z=0. o N, the negative flag o Binary representation of signed numbers uses D7 as the sign bit. o The flag reflects the result of an arithmetic operation. o If the D7 bit is zero, then N=0 and the result is positive. But, if the D7 bit is one, then N=1 and the result is negative. o V, the overflow flag o The flag is set whenever the result of a signed number operation is too large, causing the high-order bit to overflow in the sign bit.

o S, the Sign flag AVR Status Register o The flag is the result of Exclusive-Oring of N and V flags. o H, Half carry flag o If there is a carry from D3 to D4 during and ADD or SUB operation, this bit is set, otherwise, it is cleared.

AVR Status Register: Example

AVR Status Register: Example D7 D4 D3 D0 1

AVR Status Register: Example D7 D4 D3 D0 1 1

AVR Status Register: Example D7 D4 D3 D0 1

AVR Status Register: Example SREG: I T H S V N Z C Interrupt ALU Temporary Sign Negative Half carry N+V Example: Show the status of the C, H, and Z flags after the addition subtraction of 0x9C 0x38 of 0x23 0x9C 0x73 and 0x64 0x2F from in 0xA5 0x9C 0x52 the following the following instructions: instructions: LDI R16, LDI 0x38 R20, R0 0xA5 0x9C 0x52 ;R16 = 0x38 R1 LDI R17, LDI 0x2F R21, 0x64 0x23 0x9C 0x73 ;R17 = 0x2F R2 ADD ADD R16, SUB R17 R20, R21 ;add R17 ;add ;subtract to R16 R21 to R21 R20 from R20 SREG: I T H S V N C Solution: Solution: CPU Solution: 1 R15 R16 R17 PC Z overflow 1 because R21 is bigger than R20 and there is a borrow from D8 bit. C = 1 0 because there R21 is is not a carry bigger R30beyond than R20 the D7 and bit. there is no borrow from D8 bit. Instruction C 0 because decoder there R20 is no has carry a value beyond other the than D7 zero bit. after the subtraction. Z = 1 because there R20 is has is carry zero carry R31 value from after other D3 subtraction. than to the 0 after D4 bit. the subtraction. because there is a borrow from from the D4 D3 to D3. the D4 bit. Instruction Z H = 1 0 because Register the there R20 is (the no borrow result) has from a D4 value to D3. 0 in it after the addition. = 0 because the R16 (the result) has value other than 0 after the addition. registers Zero Carry $A5 $9C $52 0101 $38 0011 1010 10010010 1000 0101 1100 + - + $64 $23 $9C $73 0111 $2F 0110 10010011 0100 1111 0011 1100 $DF $100 $67 $82 $00 1101 1 0000110 1000 00001111 0010 R20 R20 = 00 R16 R20 = $DF 0x67 $82 $00