Understanding Atmega328P Microcontroller
(Lecture-9)
R S Ananda Murthy
Associate Professor and Head
Department of Electrical & Electronics Engineering,
Sri Jayachamarajendra College of Engineering,
Mysore 570 006
R S Ananda Murthy Understanding Atmega328P Microcontroller
AVR CPU General Purpose Registers – 32×8
R0
D0D1D2. . . . . . . . . . . .D7
R1
R2
...
R13
R14
R15
0x00
0x01
0x02
0x0D
0x0E
0x0F
Addr.
R16
R17
...
0x10
0x11
R26
R27
R28
0x1A
0x1B
0x1C
R29
R30
0x1D
0x1E
R31 0x1F
......
X Register Low-byte
X Register High-byte
Y Register Low-byte
Y Register High-byte
Z Register Low-byte
Z Register High-byte
Most instructions can access
any register and complete
operation in one CPU clock cycle.
There is also a 16-bit Stack Pointer.
Last three register pairs given below
can be used as three 16-bit index
registers to point at data memory.
R S Ananda Murthy Understanding Atmega328P Microcontroller
X, Y, and Z Registers – 16-bit Pointers to Data
D0D1D2. . . . . . . . . .D7
R26 (0x1A)R27 (0x1B)
D0D1D2. . . . . . . . . .D7
015 XH XL
X-Register
D0D1D2. . . . . . . . . .D7
R28 (0x1C)R29 (0x1D)
D0D1D2. . . . . . . . . .D7
015 YH YL
Y-Register
D0D1D2. . . . . . . . . .D7
R30 (0x1E)R31 (0x1F)
D0D1D2. . . . . . . . . .D7
015 ZH ZL
Z-Register
Register pairs R27 and R26, R29 and R28, R31 and R30
known as X, Y, and Z registers – can be used as 16-bit
address pointers for indirect addressing of the data space.
R S Ananda Murthy Understanding Atmega328P Microcontroller
Arithmetic Logic Unit (ALU) and Data Path
32 x 8 General
Purpose
Registers
ALU
8 8
Result
Status Register
H, S, V, N, Z, C
Flags
Carry Bit
Performs arithmetic, logical, or bit-function operations
between general purpose registers or between a register
and an immediate data within a single CPU clock cycle.
Can perform multiplication using on-chip 2-cycle multiplier.
Status Register is updated after all ALU operations, as
explained in the Instruction Set Reference.
R S Ananda Murthy Understanding Atmega328P Microcontroller
Status Register – for Conditional Branching
Bit 7 6 5 4 3 2 1 0
0x3F (0x5F) I T H S V N Z C SREG
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
I – Global Interrupt Enable bit. Explained later.
T – Bit Copy Storage. Explained later.
H – Half carry flag. Explained later.
S – Sign flag. S = N⊕V. Explained later.
V – Overflow flag. Explained later.
N – The negative flag. N = MSB of result.
Z – Zero flag. Z = 1 if result is 0. Z = 0 if result is 1.
C – Carry flag. C = 1 if there is carry from D7.
R S Ananda Murthy Understanding Atmega328P Microcontroller
Power On Reset (POR)
When Vcc is applied to the AVR microcontroller, it is
automatically reset.
This is known as Power On Reset (POR).
After POR, the Program Counter is loaded with the reset
address $0000 so that the instruction present in that
location is executed.
In Atmega328P, the user has to write a jump instruction
(JMP) at location $0000 to jump to the desired application.
Other events which can reset the MCU will be explained in
detail later.
R S Ananda Murthy Understanding Atmega328P Microcontroller
Clock Distribution in Atmega328P
R S Ananda Murthy Understanding Atmega328P Microcontroller
AVR Clock System
Clock Control Unit in side the chip generates clocks for
memory and IO devices.
Multiple clock signals are generated in side the chip.
All of the clocks need not be active at a given time.
In order to reduce power consumption, the clocks to
modules not being used can be halted by using different
sleep modes.
Default is internal 8 MHz R-C oscillator which is divided by
8 by prescaler to give a 1 MHz CPU clock.
Default CPU clock is only 5-10% accurate.
Option to use external crystal clock source (max 20 MHz)
is also available.
Selection of system clock by software will be explained later.
R S Ananda Murthy Understanding Atmega328P Microcontroller
Power Management Features in Atmega328P
Unused modules can be shut down to save power.
Six Sleep Modes – Idle, ADC Noise Reduction,
Power-save, Power-down, Standby, and Extended Standby.
From power down mode the device can be made to wake
up on external reset or when the watchdog timer reset
occurs.
From power save mode the device can be made to wake
up on timer events.
Power management by software will be explained later.
R S Ananda Murthy Understanding Atmega328P Microcontroller
Watchdog Timer
When MCU is hanging due to any reason, the watchdog
timer will timeout and produce an internal reset signal to
load the Program Counter with the reset address $0000.
During normal operation, the MCU regularly restarts the
watchdog timer to prevent it from elapsing, or timing out.
More details about watchdog timer will be given later.
R S Ananda Murthy Understanding Atmega328P Microcontroller
License
This work is licensed under a
Creative Commons Attribution 4.0 International License.
R S Ananda Murthy Understanding Atmega328P Microcontroller

More Related Content

PPTX
Presentation on 8086 Microprocessor
PPT
STM32 MCU Family
PPTX
Architecture of 8051
PPTX
Pic 18 microcontroller
PPTX
latches
PDF
8086 labmanual
PPTX
PIC 16F877 micro controller by Gaurav raikar
PPTX
I o ports.ppt
Presentation on 8086 Microprocessor
STM32 MCU Family
Architecture of 8051
Pic 18 microcontroller
latches
8086 labmanual
PIC 16F877 micro controller by Gaurav raikar
I o ports.ppt

What's hot (20)

PPTX
Verilog operators
PDF
L8 understanding-atmega328 p-1
PPTX
Full custom digital ic design of priority encoder
PPTX
Instruction set of 8085 microprocessor
PPT
8051 Inturrpt
PPT
Embedded System Presentation
PPTX
SRAM DRAM
PDF
8085 branching instruction
PDF
PAI Unit 3 Multitasking in 80386
PPTX
Introduction to arm processor
PPTX
PIC Microcontrollers
PPTX
I/O Ports
PPT
PPT
PIC 16F877A by PARTHIBAN. S.
PPTX
RISC - Reduced Instruction Set Computing
PPTX
PIC Microcontroller | ADC Interfacing
PPT
Microprocessor 80386
PDF
Unit II Arm 7 Introduction
Verilog operators
L8 understanding-atmega328 p-1
Full custom digital ic design of priority encoder
Instruction set of 8085 microprocessor
8051 Inturrpt
Embedded System Presentation
SRAM DRAM
8085 branching instruction
PAI Unit 3 Multitasking in 80386
Introduction to arm processor
PIC Microcontrollers
I/O Ports
PIC 16F877A by PARTHIBAN. S.
RISC - Reduced Instruction Set Computing
PIC Microcontroller | ADC Interfacing
Microprocessor 80386
Unit II Arm 7 Introduction
Ad

Viewers also liked (20)

PDF
L16 usart-atmega328 p
PDF
L7 starting-to-use-mcu
PDF
L3 instruction-execution-steps
PDF
L14 kb-lcd-interfacing-with-atmega328 p
PDF
L12 c-language-programming-of-atmega328 p
PDF
L11 assembly-language-programming-of-atmega328 p
PDF
Arduino atmega328
PDF
Introduction to-Tex-and-LaTeX
PDF
L10 assembly-language-programming-of-atmega328 p
PDF
L15 timers-counters-in-atmega328 p
PDF
Lecture-1 : Introduction to Power Electronics
PDF
Trends in-power-electronics
PDF
L6 primary-memory
PDF
L5 data-parallel-computers
PDF
L1 intro-to-mpu-mcu
PDF
Transformers
PDF
L4 speeding-up-execution
PDF
Lecture-5 : Semiconductor Power Switching Devices-2
PDF
L13 interrupts-in-atmega328 p
PDF
Lecture-3 : More Applications of Power Electronics
L16 usart-atmega328 p
L7 starting-to-use-mcu
L3 instruction-execution-steps
L14 kb-lcd-interfacing-with-atmega328 p
L12 c-language-programming-of-atmega328 p
L11 assembly-language-programming-of-atmega328 p
Arduino atmega328
Introduction to-Tex-and-LaTeX
L10 assembly-language-programming-of-atmega328 p
L15 timers-counters-in-atmega328 p
Lecture-1 : Introduction to Power Electronics
Trends in-power-electronics
L6 primary-memory
L5 data-parallel-computers
L1 intro-to-mpu-mcu
Transformers
L4 speeding-up-execution
Lecture-5 : Semiconductor Power Switching Devices-2
L13 interrupts-in-atmega328 p
Lecture-3 : More Applications of Power Electronics
Ad

Similar to L9 understanding-atmega328 p-2 (20)

PPT
8085 (1)
PDF
Microprocessor based lecture slide M1L2.pdf
PDF
Atmel 42735-8-bit-avr-microcontroller-a tmega328-328-p_summary
PDF
Z80 microprocessor architecture1
PPT
Embedded System
PPTX
8051 microcontroller
PDF
pic_1.pdf
PPT
AVR Fundamentals
PDF
Atemega saya
PDF
Atmega8u2 mur
PPTX
Arduino and its hw architecture
PDF
Atmel 2486-8-bit-avr-microcontroller-atmega8 l-datasheet
PDF
Atmega 8
PDF
A tmega16A Microcontroller Data Sheet
PPT
8085 intro
PPTX
Introduction to PIC.pptx
PPTX
Visitor counter
PDF
Introduction to 8085_by_adi_ppt
PDF
Introduction to 8085 Microprocessor
8085 (1)
Microprocessor based lecture slide M1L2.pdf
Atmel 42735-8-bit-avr-microcontroller-a tmega328-328-p_summary
Z80 microprocessor architecture1
Embedded System
8051 microcontroller
pic_1.pdf
AVR Fundamentals
Atemega saya
Atmega8u2 mur
Arduino and its hw architecture
Atmel 2486-8-bit-avr-microcontroller-atmega8 l-datasheet
Atmega 8
A tmega16A Microcontroller Data Sheet
8085 intro
Introduction to PIC.pptx
Visitor counter
Introduction to 8085_by_adi_ppt
Introduction to 8085 Microprocessor

More from rsamurti (7)

PDF
EE110-elementary-circuit-and-network-theory-(a)
PDF
Synchronous generators
PDF
Three phase-circuits
PDF
L2 types-of-computers
PDF
Lecture-7 : Semiconductor Power Switching Devices-4
PDF
Lecture-4 : Semiconductor Power Switching Devices-1
PDF
Lecture-2 : Applications of Power Electronics
EE110-elementary-circuit-and-network-theory-(a)
Synchronous generators
Three phase-circuits
L2 types-of-computers
Lecture-7 : Semiconductor Power Switching Devices-4
Lecture-4 : Semiconductor Power Switching Devices-1
Lecture-2 : Applications of Power Electronics

Recently uploaded (20)

PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PDF
Abrasive, erosive and cavitation wear.pdf
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PPTX
"Array and Linked List in Data Structures with Types, Operations, Implementat...
PPTX
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PDF
Improvement effect of pyrolyzed agro-food biochar on the properties of.pdf
PPTX
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
PPTX
Software Engineering and software moduleing
PPTX
Module 8- Technological and Communication Skills.pptx
PPTX
Fundamentals of Mechanical Engineering.pptx
PDF
Design Guidelines and solutions for Plastics parts
PPTX
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
PPTX
communication and presentation skills 01
PPTX
Management Information system : MIS-e-Business Systems.pptx
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PPT
Total quality management ppt for engineering students
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PDF
ChapteR012372321DFGDSFGDFGDFSGDFGDFGDFGSDFGDFGFD
PDF
737-MAX_SRG.pdf student reference guides
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
Abrasive, erosive and cavitation wear.pdf
Exploratory_Data_Analysis_Fundamentals.pdf
"Array and Linked List in Data Structures with Types, Operations, Implementat...
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
Improvement effect of pyrolyzed agro-food biochar on the properties of.pdf
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
Software Engineering and software moduleing
Module 8- Technological and Communication Skills.pptx
Fundamentals of Mechanical Engineering.pptx
Design Guidelines and solutions for Plastics parts
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
communication and presentation skills 01
Management Information system : MIS-e-Business Systems.pptx
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Total quality management ppt for engineering students
Fundamentals of safety and accident prevention -final (1).pptx
ChapteR012372321DFGDSFGDFGDFSGDFGDFGDFGSDFGDFGFD
737-MAX_SRG.pdf student reference guides

L9 understanding-atmega328 p-2

  • 1. Understanding Atmega328P Microcontroller (Lecture-9) R S Ananda Murthy Associate Professor and Head Department of Electrical & Electronics Engineering, Sri Jayachamarajendra College of Engineering, Mysore 570 006 R S Ananda Murthy Understanding Atmega328P Microcontroller
  • 2. AVR CPU General Purpose Registers – 32×8 R0 D0D1D2. . . . . . . . . . . .D7 R1 R2 ... R13 R14 R15 0x00 0x01 0x02 0x0D 0x0E 0x0F Addr. R16 R17 ... 0x10 0x11 R26 R27 R28 0x1A 0x1B 0x1C R29 R30 0x1D 0x1E R31 0x1F ...... X Register Low-byte X Register High-byte Y Register Low-byte Y Register High-byte Z Register Low-byte Z Register High-byte Most instructions can access any register and complete operation in one CPU clock cycle. There is also a 16-bit Stack Pointer. Last three register pairs given below can be used as three 16-bit index registers to point at data memory. R S Ananda Murthy Understanding Atmega328P Microcontroller
  • 3. X, Y, and Z Registers – 16-bit Pointers to Data D0D1D2. . . . . . . . . .D7 R26 (0x1A)R27 (0x1B) D0D1D2. . . . . . . . . .D7 015 XH XL X-Register D0D1D2. . . . . . . . . .D7 R28 (0x1C)R29 (0x1D) D0D1D2. . . . . . . . . .D7 015 YH YL Y-Register D0D1D2. . . . . . . . . .D7 R30 (0x1E)R31 (0x1F) D0D1D2. . . . . . . . . .D7 015 ZH ZL Z-Register Register pairs R27 and R26, R29 and R28, R31 and R30 known as X, Y, and Z registers – can be used as 16-bit address pointers for indirect addressing of the data space. R S Ananda Murthy Understanding Atmega328P Microcontroller
  • 4. Arithmetic Logic Unit (ALU) and Data Path 32 x 8 General Purpose Registers ALU 8 8 Result Status Register H, S, V, N, Z, C Flags Carry Bit Performs arithmetic, logical, or bit-function operations between general purpose registers or between a register and an immediate data within a single CPU clock cycle. Can perform multiplication using on-chip 2-cycle multiplier. Status Register is updated after all ALU operations, as explained in the Instruction Set Reference. R S Ananda Murthy Understanding Atmega328P Microcontroller
  • 5. Status Register – for Conditional Branching Bit 7 6 5 4 3 2 1 0 0x3F (0x5F) I T H S V N Z C SREG Read/Write R/W R/W R/W R/W R/W R/W R/W R/W Initial Value 0 0 0 0 0 0 0 0 I – Global Interrupt Enable bit. Explained later. T – Bit Copy Storage. Explained later. H – Half carry flag. Explained later. S – Sign flag. S = N⊕V. Explained later. V – Overflow flag. Explained later. N – The negative flag. N = MSB of result. Z – Zero flag. Z = 1 if result is 0. Z = 0 if result is 1. C – Carry flag. C = 1 if there is carry from D7. R S Ananda Murthy Understanding Atmega328P Microcontroller
  • 6. Power On Reset (POR) When Vcc is applied to the AVR microcontroller, it is automatically reset. This is known as Power On Reset (POR). After POR, the Program Counter is loaded with the reset address $0000 so that the instruction present in that location is executed. In Atmega328P, the user has to write a jump instruction (JMP) at location $0000 to jump to the desired application. Other events which can reset the MCU will be explained in detail later. R S Ananda Murthy Understanding Atmega328P Microcontroller
  • 7. Clock Distribution in Atmega328P R S Ananda Murthy Understanding Atmega328P Microcontroller
  • 8. AVR Clock System Clock Control Unit in side the chip generates clocks for memory and IO devices. Multiple clock signals are generated in side the chip. All of the clocks need not be active at a given time. In order to reduce power consumption, the clocks to modules not being used can be halted by using different sleep modes. Default is internal 8 MHz R-C oscillator which is divided by 8 by prescaler to give a 1 MHz CPU clock. Default CPU clock is only 5-10% accurate. Option to use external crystal clock source (max 20 MHz) is also available. Selection of system clock by software will be explained later. R S Ananda Murthy Understanding Atmega328P Microcontroller
  • 9. Power Management Features in Atmega328P Unused modules can be shut down to save power. Six Sleep Modes – Idle, ADC Noise Reduction, Power-save, Power-down, Standby, and Extended Standby. From power down mode the device can be made to wake up on external reset or when the watchdog timer reset occurs. From power save mode the device can be made to wake up on timer events. Power management by software will be explained later. R S Ananda Murthy Understanding Atmega328P Microcontroller
  • 10. Watchdog Timer When MCU is hanging due to any reason, the watchdog timer will timeout and produce an internal reset signal to load the Program Counter with the reset address $0000. During normal operation, the MCU regularly restarts the watchdog timer to prevent it from elapsing, or timing out. More details about watchdog timer will be given later. R S Ananda Murthy Understanding Atmega328P Microcontroller
  • 11. License This work is licensed under a Creative Commons Attribution 4.0 International License. R S Ananda Murthy Understanding Atmega328P Microcontroller