Professional Documents
Culture Documents
Lecture 6
Overview of the ATMega328
PC6
28
PC5
PCINT13
ADC5
A5
SCL
PCINT16
PD0
27
PC4
PCINT12
ADC4
A4
SDA
TXD
PCINT17
PD1
26
PC3
PCINT11
ADC3
A3
PC2
PCINT10
INT0
25
INT1
PCINT19
PD3
24
PC1
PCINT9
ADC1
A1
T0
XCK
PCINT20
PD4
23
PC0
PCINT8
ADC0
A0
XTAL1
OSC2
XTAL2
PD2
VCC
GND
PCINT6
T1
PCINT21
PD5
11
PWM
AIN0
PCINT22
PD6
AIN1
PCINT23
PD7
CLKO
PCINT0
PB0
AREF
VCC
19
PB5
PCINT5
SCK
13
18
PB4
PCINT4
MISO
12
12
17
PB3
PCINT3
OC2A
11
PWM
MOSI
13
16
PB2
PCINT2
OC1B
10
PWM
SS
14
15
PB1
PCINT1
OC1A
PWM
28 PC5
27 PC4
21 AREF
The
Not Connected
R3 Only
IOREF
RESET
PCINT14
1 PC6
3V3
input voltage to the Arduino board when
5V
it is running from external power.
GND
Not USB bus power.
GND
VIN
ADC0
ADC1
ADC2
ADC3
ADC4
ADC5
SDA
SCL
PCINT8
PCINT9
PCINT10
PCINT11
PCINT12
PCINT13
14
15
16
17
18
19
RESET
A0
A1
A2
A3
A4
A5
23
24
25
26
27
28
UNO
PINOUT DIAGRAM
5V
2.1mm
PC0
PC1
PC2
PC3
PC4
PC5
1 PC6
PCINT14
ARDUINO
USB
JACK
GND
VIN
USB JACK
TYPE B
POWER
JACK
7-12V Depending
on current drawn
21
20
SCK2
MISO2
10
PWM
GND
A2
MOSI2
PB7
OC0B
OC0A
ICP1
PCINT7
PB6
22
ADC2
19 PB5
18 PB4
13
12
17 PB3
11
19 A5
18 A4
PCINT13
PCINT12
19
18
17
16
15
14
PB5
PB4
PB3
PB2
PB1
PB0
GND
13
12
11
10
9
8
OC2A
OC1B
OC1A
CLKO
PCINT5
PCINT4
PCINT3
PCINT2
PCINT1
PCINT0
13
12
11
6
5
4
3
2
PD7
PD6
PD5
PD4
PD3
PD2
PD1
PD0
7
6
5
4
3
2
1
0
AIN1
AIN0
T1
T0
INT1
INT0
TXD
RXD
PCINT23
PCINT22
PCINT21
PCINT20
PCINT19
PCINT18
PCINT17
PCINT16
SCK
MISO
PCINT5
PCINT4
www.pighixxx.com
BY
ND
18 FEB 2013
GND
5V
OC2A
PCINT3
PWM
MOSI
ADC5
ADC4
AREF
PWM
PWM
PWM
SCL
SDA
SCK
MISO
MOSI
SS
ICP1
PWM
PWM
PWM
R3 Only
OC0A
XCK
OC2B
OSC1
PCINT18
ATMEGA328
2
PWM
THE
DEFINITIVE
RESET2
PCINT14
RXD
GND
OC2B
RESET
0
ATMEGA8U2/ATMEGA16U2 ICSP
Arduino Connections
TX
RX
GND
Power
Control
Physical Pin
Port Pin
Pin Function
Digital Pin
Analog Related Pin
PWM Pin
Serial Pin
IDE
Source Total 150mA
Arduino Connections
Arduino Connections
ATMEGA328 Internals
AREF
AVCC
GND
RESET
XTAL[1..2]
ADC
[6..7]
PORT C
8bit
T/C
2
PORT B
Internal
Bandgap
Analog
Comparator
8bit
T/C
0
SPI
Port B
[0..7]
PORT D
A/D Convertor
SRAM
PROGRAM
LOGIC
debugWIRE fuse
16bit
T/C
1
TWI
Port C
[0..6]
USART 0
VCC
Flash
CPU
Oscillator
Circuits/
Clock
Generation
EEPROM
Watchdog
Oscillator
Watchdog
Timer
GND
Power
Supervision
POR/BOD &
RESET
DATABUS
Port D
[0..7]
8
ATMega328 Features
High Performance, Low Power AVR 8bit Microcontroller!
Advanced RISC Architecture!
131 Powerful instructions (many single clock cycle)!
32x8 General Purpose Working Registers!
Fully Static Operation!
Up to 20MIPS Throughput at 20MHz!
On-chip 2-cycle Multiplier!
High Endurance Non-volatile Memory Segments!
32Kb of In-System, Self-Programmable Flash program
memory!
1Kb EEPROM!
2Kb Internal SRAM!
Write/Erase Cycles: 10,000 Flash/100,000 EEPROM!
Data Retention: 20 years at 85C/100 years at 25C!
Optional Boot Code Section with independent lock bits!
Programming lock for Software Security!
Special Microcontroller features!
Power-on Reset and programmable brown-out detection!
Internal Calibrated oscillator!
External and Internal Interrupt Sources!
Six Sleep Modes: Idle, ADC Noise Reduction, Powersave, Power-down, Standby, and Extended Standby!
!
Peripheral Features!
Two 8-bit Timer/Counters with Separate Prescaler and
Compare Mode!
One 16-bit Timer/Counter with separate prescaler,
compare mode, and capture mode.!
Real Time counter with separate oscillator!
Six PWM Channels!
Six-channel 10-bit ADC, temperature measurement!
Programmable Serial USART!
Master/Slave SPI Serial Interface!
Byte-oriented 2-wire Serial Interface (I2C compatible)!
Programmable Watchdog Timer with separate on-chip
oscillator!
On-chip Analog Comparator!
Interrupt and Wake-up on Pin Change!
I/O Lines: 23 Programmable I/O Lines!
Operating Voltage: 1.8-5.5v!
Temperature Range: -40C to 85C!
Power Consumption!
Active Mode: 0.2mA!
Power-down Mode: 0.1A!
Power-Save Mode: 0.75A (including 32kHz RTC)
ATMega328 Pinout
THE
DEFINITIVE
GND
Power
Control
Physical Pin
Port Pin
Pin Function
Digital Pin
Analog Related Pin
PWM Pin
Serial Pin
IDE
ATMEGA328
&Arduino
PINOUT DIAGRAM
PCINT14
PC6
28
PC5
PCINT13
ADC5
A5
19
SCL
RXD
PCINT16
PD0
27
PC4
PCINT12
ADC4
A4
18
SDA
TXD
PCINT17
PD1
26
PC3
PCINT11
ADC3
A3
17
INT0
PCINT18
PD2
25
PC2
PCINT10
ADC2
A2
16
OC2B
PWM
INT1
PCINT19
PD3
24
PC1
PCINT9
ADC1
A1
15
T0
XCK
PCINT20
PD4
23
PC0
PCINT8
ADC0
A0
14
VCC
GND
OSC1
XTAL1
PCINT6
PB6
OSC2
XTAL2
PCINT7
PB7
10
11
ATMEGA328
RESET
0
22
GND
21
AREF
20
VCC
19
PB5
PCINT5
SCK
18
PB4
PCINT4
PCINT3
OC2A
11
PWM
MOSI
SS
13
OC0B
PWM
T1
PCINT21
PD5
OC0A
PWM
AIN0
PCINT22
PD6
12
17
PB3
AIN1
PCINT23
PD7
13
16
PB2
PCINT2
OC1B
10
PWM
CLKO
PCINT0
PB0
14
15
PB1
PCINT1
OC1A
PWM
ICP1
www.pighixxx.com
BY
ND
18 FEB 2013
ver 2 rev 1 - 05.03.2013
MISO
12
DATABUS
ATMega328 Ports
Port D
PC6
PD0
PD1
PD2
PD3
PD4
VCC
GND
PB6
PB7
PD5
PD6
PD7
PB0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
28
27
26
25
24
23
22
21
20
19
18
17
16
15
PC5
PC4
PC3
PC2
PC1
PC0
GND
AREF
AVCC
PB5
PB4
PB3
PB2
PB1
Comp.
Port C
Port B
USART 0
SPI
TWI
PORT D (8)
PORT B (8)
PORT C (7)
RESET
XTAL[1..2]
PD[0..7]
PB[0..7]
PC[0..6]
bidirectional ports
EE 260 Lecture 6: Overview of the ATMega328
ADC[6..7]
RISC Processor
Reduced Instruction Set Computer!
As compared to Complex Instruction Set
Computers, i.e. x86!
Assumption: Simpler instructions execute faster!
Optimized most used instructions!
Other RISC machines: ARM, PowerPC, SPARC!
Became popular in mid 1990s
EE 260 Lecture 6: Overview of the ATMega328
Processor Layout
AVR Registers
32 8 Bit registers!
Mapped to address 0-31 in data space!
Most instructions can access any register and
complete in one cycle!
Last 3 register pairs can be used as 3 16 bit index
registers!
32 bit stack pointer
EE 260 Lecture 6: Overview of the ATMega328
Flash Memory
Non-volatile program space storage!
16 Bit width!
Some devices have separate lockable boot section!
At least 10,000 write/erase cycles
AVR SRAM
Data space storage!
8 Bit width
32 Registers
0x0000 0x001F
64 I/O Registers
0x0020 0x005F
0x00060 0x00FF
Internal SRAM
(512/1024/2048x8)
0x0100
0x04FF/0x6FF/0x8FF
External SRAM
AVR EEPROM
Electrically Erasable Programmable Read Only
Memory!
8 bit width!
Requires special write sequence!
Non-volatile storage for program specific data,
constants, etc.!
At least 100,000 write/erase cycles
EE 260 Lecture 6: Overview of the ATMega328
131 Instructions
Arithmetic & Logic!
Branch!
Bit set/clear/test!
Data transfer!
MCU control
Instruction Timing
Register register (1 cycle)!
Register memory (2 cycles)!
Branch instruction (1-2 cycles)!
Subroutine call & return (3-5 cycles)!
Some operations may take longer for external
memory
Clock Sources
Timer/
Counters
Timer/Counter
Oscillator
IO Modules
Crystal Oscillator
ADC
External Clock
Clock
Mux
System Clock
Prescaler
Calibrated RC
Oscillator
AVR
Clock
Control
CPU Core
8
RAM
FLASH &
EEPROM
Power Management
Multiple power down modes!
Power down mode!
Wake on external reset or watchdog reset!
Power save mode!
Wake on timer events!
Several standby modes!
Reset Sources
Power on reset!
External reset!
Watchdog system reset!
Brown out detect (BOD) reset
Interrupts
ATmega328 has 26 reset/interrupt sources!
1 Reset source!
2 External interrupt sources!
I/O Pin state change on all 24 GPIO pins!
Peripheral device events
Interrupt Vectors
Each vector is a 2 word jump instruction!
Vectors start at program memory address 0!
Reset vector is at address 0!
Sample vector table:
Address Labels
0x0000
0x0002
0x0004
0x0006
0x0008
Code
jmp RESET
jmp EXT_INT0
jmp EXT_INT1
jmp PCINT0
jmp PCINT1
...
Comments
; Reset Handler
; IRQ0 Handler
; IRQ1 Handler
; PCINT0 Handler
; PCINT1 Handler
Fuses
Fuses configure system parameters!
Clock selection and options!
Boot options!
Some IO pin configurations!
Reset options!
ATMega Peripherals
23 General Purpose IO
Bits!
6 or 8 ADC channels
(depends on package)!
Serial USART!
GPIO Ports
Three 8 Bit IO Ports!
Port B, Port C & Port D!
Pins identified as PBx, PCx or PDx (x=0..7)!
PC6
PD0
PD1
PD2
PD3
PD4
VCC
GND
(PCINT6/XTAL1/TOSC1) PB6
(PCINT7/XTAL2/TOSC2) PB7
(PCINT21/OC0B/T1) PD5
(PCINT22/OC0A/AIN0) PD6
(PCINT23/AIN1) PD7
(PCINT0/CLKO/ICP1) PB0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
28
27
26
25
24
23
22
21
20
19
18
17
16
15
PC5 (ADC5/SCL/PCIN13
PC4 (ADC4/SDA/PCIN12
PC3 (ADC3/PCINT11)
PC2 (ADC2/PCINT10)
PC1 (ADC1/PCINT9)
PC0 (ADC0/PCINT8)
GND
AREF
AVCC
PB5 (SCK/PCINT5)
PB4 (MISO/PCINT4)
PB3 (MOSI/OC2A/PCINT3
PB2 (SS/OC1B/PCINT2)
PB1 (OC1A/PCINT1)
(see Appendix A)
EE 260 Lecture 6: Overview of the ATMega328
Timers/Counters
8/16 Bit register!
Increments or decrements on every clock cycle!
Can be read on data bus!
Output feeds waveform generator!
Clock Sources!
Internal from clock prescaler!
External Tn Pin (Uses 1 port pin)
Timers/Counters
Multiple Operating modes!
Simple timer / counter!
Output Compare Function!
Waveform generator!
Clear/set/toggle on match!
Frequency control!
Pulse Width Modulation (PWM)
IRQ
Tn
TCCRnA
OCRnA
Clock
Select
TCNTn
Waveform
Generator
OCnA
IRQ
TCCRnB
OCRnB
DATA BUS
Waveform
Generator
OCnB
IRQ
T0
TCCR0A
OCR0A
Clock
Select
TCNT0
Waveform
Generator
OC0A
IRQ
TCCR0B
OCR0B
=
DATA BUS
Waveform
Generator
OC0B
OCnx
(toggle)
MAX
TOP
BOTTOM
Set on
BOTTOM
OCnx
Analog-To-Digital Convertor
10 Bit Successive Approximation ADC!
8 Channel multiplexer using port pins ADC0-7!
Max conversion time 260 "sec.
Analog Comparator
Compares voltage between pins AIN0 and AIN1!
Asserts AC0 when AIN0 > AIN1!
AC0 can trigger timer capture function!
Range finders indicate distance with pulse width!
Timer capture mode can compute pulse width
SCLK
MOSI
MISO
SS
Serial
Clock
Master
Out
Slave
In
Master
In
Slave
Out
Slave
Select
SCLK
MOSI
MISO
SS1
SS2
SS3
SCLK
MOSI
MISO
SS
SPI
Slave
SCLK
MOSI
MISO
SS
SPI
Slave
SCLK
MOSI
MISO
SS
SPI
Slave
Serial Data
SCL
Serial Clock
uC
Master
ADC
Slave
DAC
Slave
Vdd
SDA
SCL
uC
Slave
Compass!
IO Expanders!
Real Time Clocks!
Servo / Motor
Controller!
LED Display
Temperature sensors!
Ultrasonic range
finders!
EE 260 Lecture 6: Overview of the ATMega328
USART
Universal Synchronous and Asynchronous
(serial) Receiver and Transmitter!
Full Duplex Operation!
High Resolution Baud Rate Generator!
Can provide serial terminal interface