Atmel 8127 AVR 8 Bit Microcontroller ATtiny4 ATtiny5 ATtiny9 ATtiny10 Datasheet
Atmel 8127 AVR 8 Bit Microcontroller ATtiny4 ATtiny5 ATtiny9 ATtiny10 Datasheet
Features
High Performance, Low Power AVR 8-Bit Microcontroller
Advanced RISC Architecture
Rev. 8127FAVR02/2013
8127FAVR02/2013
1. Pin Configurations
Figure 1-1.
Pinout of ATtiny4/5/9/10
SOT-23
(PCINT0/TPIDATA/OC0A/ADC0/AIN0) PB0
GND
(PCINT1/TPICLK/CLKI/ICP0/OC0B/ADC1/AIN1) PB1
1
2
3
6
5
4
PB3 (RESET/PCINT3/ADC3)
VCC
PB2 (T0/CLKO/PCINT2/INT0/ADC2)
UDFN
(PCINT1/TPICLK/CLKI/ICP0/OC0B/ADC1/AIN1) PB1
NC
NC
GND
1
2
3
4
8
7
6
5
PB2 (T0/CLKO/PCINT2/INT0/ADC2)
VCC
PB3 (RESET/PCINT3/ADC3)
PB0 (AIN0/ADC0/OC0A/TPIDATA/PCINT0)
1.1
Pin Description
1.1.1
VCC
Supply voltage.
1.1.2
GND
Ground.
1.1.3
Port B (PB3..PB0)
This is a 4-bit, bi-directional I/O port with internal pull-up resistors, individually selectable for each bit. The output
buffers have symmetrical drive characteristics, with both high sink and source capability. As inputs, the port pins
that are externally pulled low will source current if pull-up resistors are activated. Port pins are tri-stated when a
reset condition becomes active, even if the clock is not running.
The port also serves the functions of various special features of the ATtiny4/5/9/10, as listed on page 36.
1.1.4
RESET
Reset input. A low level on this pin for longer than the minimum pulse length will generate a reset, even if the clock
is not running and provided the reset pin has not been disabled. The minimum pulse length is given in Table 16-4
on page 118. Shorter pulses are not guaranteed to generate a reset.
The reset pin can also be used as a (weak) I/O pin.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
2. Overview
ATtiny4/5/9/10 are low-power CMOS 8-bit microcontrollers based on the compact AVR enhanced RISC architecture. By executing powerful instructions in a single clock cycle, the ATtiny4/5/9/10 achieve throughputs
approaching 1 MIPS per MHz, allowing the system designer to optimize power consumption versus processing
speed.
Figure 2-1.
Block Diagram
VCC
RESET
PROGRAMMING
LOGIC
PROGRAM
COUNTER
INTERNAL
OSCILLATOR
CALIBRATED
OSCILLATOR
PROGRAM
FLASH
STACK
POINTER
WATCHDOG
TIMER
TIMING AND
CONTROL
INSTRUCTION
REGISTER
SRAM
RESET FLAG
REGISTER
INSTRUCTION
DECODER
MCU STATUS
REGISTER
GENERAL
PURPOSE
REGISTERS
CONTROL
LINES
TIMER/
COUNTER0
X
Y
Z
INTERRUPT
UNIT
ALU
STATUS
REGISTER
ISP
INTERFACE
ANALOG
COMPARATOR
DIRECTION
REG. PORT B
DATA REGISTER
PORT B
ADC
DRIVERS
PORT B
PB3:0
GND
The AVR core combines a rich instruction set with 16 general purpose working registers and system registers. All
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 compact and code efficient while achieving throughputs up to ten times faster than conventional CISC microcontrollers.
The ATtiny4/5/9/10 provide the following features: 512/1024 byte of In-System Programmable Flash, 32 bytes of
SRAM, four general purpose I/O lines, 16 general purpose working registers, a 16-bit timer/counter with two PWM
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
channels, internal and external interrupts, a programmable watchdog timer with internal oscillator, an internal calibrated oscillator, and four software selectable power saving modes. ATtiny5/10 are also equipped with a fourchannel, 8-bit Analog to Digital Converter (ADC).
Idle mode stops the CPU while allowing the SRAM, timer/counter, ADC (ATtiny5/10, only), analog comparator, and
interrupt system to continue functioning. ADC Noise Reduction mode minimizes switching noise during ADC conversions by stopping the CPU and all I/O modules except the ADC. In Power-down mode registers keep their
contents and all chip functions are disabled until the next interrupt or hardware reset. In Standby mode, the oscillator is running while the rest of the device is sleeping, allowing very fast start-up combined with low power
consumption.
The device is manufactured using Atmels high density non-volatile memory technology. The on-chip, in-system
programmable Flash allows program memory to be re-programmed in-system by a conventional, non-volatile
memory programmer.
The ATtiny4/5/9/10 AVR are supported by a suite of program and system development tools, including macro
assemblers and evaluation kits.
2.1
Device
Flash
ADC
Signature
ATtiny4
512 bytes
No
ATtiny5
512 bytes
Yes
ATtiny9
1024 bytes
No
ATtiny10
1024 bytes
Yes
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
3. General Information
3.1
Resources
A comprehensive set of drivers, application notes, data sheets and descriptions on development tools are available
for download at http://www.atmel.com/microcontroller/avr.
3.2
Code Examples
This documentation contains simple code examples that briefly show how to use various parts of the device. These
code examples assume that the part specific header file is included before compilation. Be aware that not all C
compiler vendors include bit definitions in the header files and interrupt handling in C is compiler dependent.
Please confirm with the C compiler documentation for more details.
3.3
3.4
Data Retention
Reliability Qualification results show that the projected data retention failure rate is much less than 1 PPM over 20
years at 85C or 100 years at 25C.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
4. CPU Core
This section discusses the AVR core architecture in general. 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.
Architectural Overview
Figure 4-1.
Flash
Program
Memory
Status
and Control
Program
Counter
16 x 8
General
Purpose
Registrers
Instruction
Decoder
Control Lines
Indirect Addressing
Instruction
Register
Direct Addressing
4.1
Interrupt
Unit
Watchdog
Timer
ALU
Analog
Comparator
ADC
Data
SRAM
Timer/Counter 0
I/O Lines
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.
The fast-access Register File contains 16 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.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
Six of the 16 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-, Y-, and Z-register,
described later in this section.
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.
Program flow is provided by conditional and unconditional jump and call instructions, capable of directly addressing
the whole address space. Most AVR instructions have a single 16-bit word format but 32-bit wide instructions also
exist. The actual instruction set varies, as some devices only implement a part of the instruction set.
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 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 four different addressing modes supported in the AVR architecture.
The memory spaces in the AVR architecture are all linear and regular memory maps.
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.
The I/O memory space contains 64 addresses for CPU peripheral functions as Control Registers, SPI, and other
I/O functions. The I/O memory can be accessed as the data space locations, 0x0000 - 0x003F.
4.2
4.3
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 document AVR Instruction Set and section Instruction Set Summary on page 150. 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.
4.4
Figure 4-2 below shows the structure of the 16 general purpose working registers in the CPU.
Figure 4-2.
0
R16
R17
Note:
General
R18
Purpose
Working
R26
Registers
R27
R28
R29
R30
R31
A typical implementation of the AVR register file includes 32 general prupose registers but ATtiny4/5/9/10 implement
only 16 registers. For reasons of compatibility the registers are numbered R16...R31, not R0...R15.
Most of the instructions operating on the Register File have direct access to all registers, and most of them are single cycle instructions.
4.4.1
X-register
XH
XL
0
R27
15
Y-register
YL
0
R29
15
Z-register
ZL
0
R31
R28
ZH
0
R26
YH
0
0
R30
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
In different addressing modes these address registers function as automatic increment and automatic decrement
(see document AVR Instruction Set and section Instruction Set Summary on page 150 for details).
4.5
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 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 0x40. 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.
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.
4.6
T2
T3
T4
clkCPU
1st Instruction Fetch
1st Instruction Execute
2nd Instruction Fetch
2nd Instruction Execute
3rd Instruction Fetch
3rd Instruction Execute
4th Instruction Fetch
Figure 4-4 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.
Figure 4-5 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.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
Figure 4-5.
T2
T3
T4
clkCPU
Total Execution Time
Register Operands Fetch
ALU Operation Execute
Result Write Back
4.7
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
10
When using the SEI instruction to enable interrupts, the instruction following SEI will be executed before any pending interrupts, as shown in the following example.
Assembly Code Example
sei
sleep
Note:
4.7.1
4.8
4.8.1
Register Description
CCP Configuration Change Protection Register
Bit
0x3C
CCP[7:0]
CCP
Read/Write
R/W
Initial Value
Signature
Group
Description
0xD8
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
11
4.8.2
4.8.3
15
14
13
12
11
10
0x3E
SP15
SP14
SP13
SP12
SP11
SP10
SP9
SP8
SPH
0x3D
SP7
SP6
SP5
SP4
SP3
SP2
SP1
SP0
SPL
Read/Write
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Read/Write
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Initial Value
RAMEND
RAMEND
RAMEND
RAMEND
RAMEND
RAMEND
RAMEND
RAMEND
Initial Value
RAMEND
RAMEND
RAMEND
RAMEND
RAMEND
RAMEND
RAMEND
RAMEND
0x3F
Read/Write
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Initial Value
SREG
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
12
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
13
5. Memories
This section describes the different memories in the ATtiny4/5/9/10. Devices have two main memory areas, the
program memory space and the data memory space.
5.1
5.2
Data Memory
Data memory locations include the I/O memory, the internal SRAM memory, the non-volatile memory lock bits, and
the Flash memory. See Figure 5-1 on page 15 for an illustration on how the ATtiny4/5/9/10 memory space is
organized.
The first 64 locations are reserved for I/O memory, while the following 32 data memory locations address the internal data SRAM.
The non-volatile memory lock bits and all the Flash memory sections are mapped to the data memory space.
These locations appear as read-only for device firmware.
The four different addressing modes for data memory are direct, indirect, indirect with pre-decrement, and indirect
with post-increment. In the register file, registers R26 to R31 function as pointer registers for indirect addressing.
The IN and OUT instructions can access all 64 locations of I/O memory. Direct addressing using the LDS and STS
instructions reaches the 128 locations between 0x0040 and 0x00BF.
The indirect addressing reaches the entire data memory space. When using indirect addressing modes with automatic pre-decrement and post-increment, the address registers X, Y, and Z are decremented or incremented.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
14
Figure 5-1.
I/O SPACE
(reserved)
(reserved)
CONFIGURATION BITS
(reserved)
CALIBRATION BITS
(reserved)
DEVICE ID BITS
(reserved)
T2
T3
clkCPU
Address
Compute Address
Address valid
Data
Write
Figure 5-2.
WR
Data
Read
5.2.1
RD
Next Instruction
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
15
5.3
I/O Memory
The I/O space definition of the ATtiny4/5/9/10 is shown in Register Summary on page 148.
All ATtiny4/5/9/10 I/Os and peripherals are placed in the I/O space. All I/O locations may be accessed using the LD
and ST instructions, enabling data transfer between the 16 general purpose working registers and the I/O space.
I/O Registers within the address range 0x00 - 0x1F are directly bit-accessible using the SBI and CBI instructions. In
these registers, the value of single bits can be checked by using the SBIS and SBIC instructions. See document
AVR Instruction Set and section Instruction Set Summary on page 150 for more details. When using the I/O
specific commands IN and OUT, the I/O addresses 0x00 - 0x3F must be used.
For compatibility with future devices, reserved bits should be written to zero if accessed. Reserved I/O memory
addresses should never be written.
Some of the status flags are cleared by writing a logical one to them. Note that CBI and SBI instructions will only
operate on the specified bit, and can therefore be used on registers containing such status flags. The CBI and SBI
instructions work on registers in the address range 0x00 to 0x1F, only.
The I/O and Peripherals Control Registers are explained in later sections.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
16
6. Clock System
Figure 6-1 presents the principal clock systems and their distribution in ATtiny4/5/9/10. 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 and power reduction register bits, as described in Power Management and
Sleep Modes on page 23. The clock systems is detailed below.
Figure 6-1.
Clock Distribution
ANALOG-TO-DIGITAL
CONVERTER
clk ADC
GENERAL
I/O MODULES
CPU
CORE
clk I/O
NVM
RAM
clk NVM
clk CPU
SOURCE CLOCK
RESET
LOGIC
WATCHDOG
CLOCK
CLOCK
PRESCALER
WATCHDOG
TIMER
CLOCK
SWITCH
EXTERNAL
CLOCK
6.1
WATCHDOG
OSCILLATOR
CALIBRATED
OSCILLATOR
Clock Subsystems
The clock subsystems are detailed in the sections below.
6.1.1
6.1.2
6.1.3
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
17
6.1.4
6.2
Clock Sources
All synchronous clock signals are derived from the main clock. The device has three alternative sources for the
main clock, as follows:
Calibrated Internal 8 MHz Oscillator (see page 18)
External Clock (see page 18)
Internal 128 kHz Oscillator (see page 19)
See Table 6-3 on page 21 on how to select and change the active clock source.
6.2.1
6.2.2
External Clock
To use the device with an external clock source, CLKI should be driven as shown in Figure 6-2. The external clock
is selected as the main clock by setting CLKMS[1:0] bits in CLKMSR to 0b10.
Figure 6-2.
CLKI
GND
When applying an external clock, it is required to avoid sudden changes in the applied clock frequency to ensure
stable operation of the MCU. A variation in frequency of more than 2% from one clock cycle to the next can lead to
unpredictable behavior. It is required to ensure that the MCU is kept in reset during such changes in the clock
frequency.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
18
6.2.3
6.2.4
6.2.5
6.3
6.3.1
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
19
6.4
Starting
6.4.1
Table 6-1.
Reset
Oscillator
Configuration
64 ms
6 cycles
21 cycles
Notes:
6.4.2
1. After powering up the device or after a reset the system clock is automatically set to calibrated internal 8 MHz oscillator, divided by 8
Notes:
6.4.3
6 cycles
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
20
6.5
Register Description
6.5.1
0x37
CLKMS1
CLKMS0
Read/Write
R/W
R/W
Initial Value
CLKMSR
CLKM1
CLKM0
External clock
Reserved
To avoid unintentional switching of main clock source, a protected change sequence must be followed to change
the CLKMS bits, as follows:
1. Write the signature for change enable of protected I/O register to register CCP
2. Within four instruction cycles, write the CLKMS bits with the desired value
6.5.2
Bit
CAL7
CAL6
CAL5
CAL4
CAL3
CAL2
CAL1
CAL0
Read/Write
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Initial Value
0x39
OSCCAL
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
21
6.5.3
0x36
CLKPS3
CLKPS2
CLKPS1
CLKPS0
Read/Write
R/W
R/W
R/W
R/W
Initial Value
CLKPSR
CLKPS3
CLKPS2
CLKPS1
CLKPS0
8 (default)
16
32
64
128
256
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
To avoid unintentional changes of clock frequency, a protected change sequence must be followed to change the
CLKPS bits:
1. Write the signature for change enable of protected I/O register to register CCP
2. Within four instruction cycles, write the desired value to CLKPS bits
At start-up, CLKPS bits are reset to 0b0011 to select the clock division factor of 8. If the selected clock source has
a frequency higher than the maximum allowed the application software must make sure a sufficient division factor
is used. To make sure the write procedure is not interrupted, interrupts must be disabled when changing prescaler
settings.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
22
7.1
Sleep Modes
Figure 6-1 on page 17 presents the different clock systems and their distribution in ATtiny4/5/9/10. The figure is
helpful in selecting an appropriate sleep mode. Table 7-1 shows the different sleep modes and their wake up
sources.
Table 7-1.
Main Clock
Source Enabled
INT0 and
Pin Change
ADC (1)
Other I/O
Watchdog
Interrupt
VLM Interrupt
Standby
Power-down
Note:
Wake-up Sources
clkADC (1)
Idle
Oscillators
clkIO
clkNVM
Sleep Mode
clkCPU
X
X
(2)
(2)
(2)
To enter any of the four sleep modes, the SE bits in SMCR must be written to logic one and a SLEEP instruction
must be executed. The SM2:0 bits in the SMCR register select which sleep mode (Idle, ADC Noise Reduction,
Standby or Power-down) will be activated by the SLEEP instruction. See Table 7-2 for a summary.
If an enabled interrupt occurs while the MCU is in a sleep mode, the MCU wakes up. The MCU is then halted for
four cycles in addition to the start-up time, executes the interrupt routine, and resumes execution from the instruction following SLEEP. The contents of the Register File and SRAM are unaltered when the device wakes up from
sleep. If a reset occurs during sleep mode, the MCU wakes up and executes from the Reset Vector.
Note that if a level triggered interrupt is used for wake-up the changed level must be held for some time to wake up
the MCU (and for the MCU to enter the interrupt service routine). See External Interrupts on page 36 for details.
7.1.1
Idle Mode
When bits SM2:0 are written to 000, the SLEEP instruction makes the MCU enter Idle mode, stopping the CPU but
allowing the analog comparator, timer/counter, watchdog, and the interrupt system to continue operating. This
sleep mode basically halts clkCPU and clkNVM, while allowing the other clocks to run.
Idle mode enables the MCU to wake up from external triggered interrupts as well as internal ones like the timer
overflow. If wake-up from the analog comparator interrupt is not required, the analog comparator can be powered
down by setting the ACD bit in ACSR Analog Comparator Control and Status Register on page 80. This will
reduce power consumption in idle mode. If the ADC is enabled (ATtiny5/10, only), a conversion starts automatically
when this mode is entered.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
23
7.1.2
7.1.3
Power-down Mode
When bits SM2:0 are written to 010, the SLEEP instruction makes the MCU enter Power-down mode. In this mode,
the oscillator is stopped, while the external interrupts, and the watchdog continue operating (if enabled). Only a
watchdog reset, an external level interrupt on INT0, or a pin change interrupt can wake up the MCU. This sleep
mode halts all generated clocks, allowing operation of asynchronous modules only.
7.1.4
Standby Mode
When bits SM2:0 are written to 100, the SLEEP instruction makes the MCU enter Standby mode. This mode is
identical to Power-down with the exception that the oscillator is kept running. This reduces wake-up time, because
the oscillator is already running and doesn't need to be started up.
7.2
The peripheral should in most cases be disabled before stopping the clock. Clearing the PRR bit wakes up the
peripheral and puts it in the same state as before shutdown.
Peripheral shutdown can be used in Idle mode and Active mode to significantly reduce the overall power consumption. See Supply Current of I/O Modules on page 121 for examples. In all other sleep modes, the clock is already
stopped.
7.3
7.3.1
Analog Comparator
When entering Idle mode, the analog comparator should be disabled if not used. In the power-down mode, the
analog comparator is automatically disabled. See Analog Comparator on page 80 for further details.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
24
7.3.2
7.3.3
Watchdog Timer
If the Watchdog Timer is not needed in the application, this module should be turned off. If the Watchdog Timer is
enabled, it will be enabled in all sleep modes, and hence, always consume power. In the deeper sleep modes, this
will contribute significantly to the total current consumption. Refer to Watchdog Timer on page 30 for details on
how to configure the Watchdog Timer.
7.3.4
Port Pins
When entering a sleep mode, all port pins should be configured to use minimum power. The most important thing
is then to ensure that no pins drive resistive loads. In sleep modes where the I/O clock (clkI/O) is stopped, the input
buffers of the device will be disabled. This ensures that no power is consumed by the input logic when not needed.
In some cases, the input logic is needed for detecting wake-up conditions, and it will then be enabled. Refer to the
section Digital Input Enable and Sleep Modes on page 44 for details on which pins are enabled. If the input buffer
is enabled and the input signal is left floating or has an analog signal level close to VCC/2, the input buffer will use
excessive power.
For analog input pins, the digital input buffer should be disabled at all times. An analog signal level close to VCC/2
on an input pin can cause significant current even in active mode. Digital input buffers can be disabled by writing to
the Digital Input Disable Register (DIDR0). Refer to DIDR0 Digital Input Disable Register 0 on page 81 for
details.
7.4
Register Description
7.4.1
0x3A
SM2
SM1
SM0
SE
Read/Write
R/W
R/W
R/W
R/W
Initial Value
SMCR
SM2
SM1
SM0
Sleep Mode
Idle
Power-down
Reserved
Standby
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
25
Table 7-2.
Note:
SM2
SM1
SM0
Sleep Mode
Reserved
Reserved
Reserved
1. This mode is available in all devices, although only ATtiny5/10 are equipped with an ADC
0x35
PRADC
PRTIM0
Read/Write
R/W
R/W
Initial Value
PRR
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
26
Reset Logic
DATA BUS
WDRF
PORF
Power-on Reset
Circuit
EXTRF
VLM
Pull-up Resistor
SPIKE
FILTER
Watchdog
Oscillator
Clock
Generator
CK
Delay Counters
TIMEOUT
The I/O ports of the AVR are immediately reset to their initial state when a reset source goes active. This does not
require any clock source to be running.
After all reset sources have gone inactive, a delay counter is invoked, stretching the internal reset. This allows the
power to reach a stable level before normal operation starts. The start up sequence is described in Starting from
Reset on page 20.
8.2
Reset Sources
The ATtiny4/5/9/10 have three sources of reset:
Power-on Reset. The MCU is reset when the supply voltage is below the Power-on Reset threshold (VPOT)
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
8.2.1
Power-on Reset
A Power-on Reset (POR) pulse is generated by an on-chip detection circuit. The detection level is defined in section System and Reset Characteristics on page 118. The POR is activated whenever VCC is below the detection
level. The POR circuit can be used to trigger the Start-up Reset, as well as to detect a failure in supply voltage.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
27
A Power-on Reset (POR) circuit ensures that the device is reset from Power-on. Reaching the Power-on Reset
threshold voltage invokes the delay counter, which determines how long the device is kept in reset after VCC rise.
The reset signal is activated again, without any delay, when VCC decreases below the detection level.
Figure 8-2.
V POT
RESET
V RST
TIME-OUT
t TOUT
INTERNAL
RESET
Figure 8-3.
V POT
> t TOUT
RESET
TIME-OUT
V RST
t TOUT
INTERNAL
RESET
8.2.2
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
28
When VLM is active and voltage at VCC is above the selected trigger level operation will be as normal and the VLM
can be shut down for a short period of time. If voltage at VCC drops below the selected threshold the VLM will either
flag an interrupt or generate a reset, depending on the configuration.
When the VLM has been configured to generate a reset at low supply voltage it will keep the device in reset as long
as VCC is below the reset level. See Table 8-4 on page 34 for reset level details. If supply voltage rises above the
reset level the condition is removed and the MCU will come out of reset, and initiate the power-up start-up
sequence.
If supply voltage drops enough to trigger the POR then PORF is set after supply voltage has been restored.
8.2.3
External Reset
An External Reset is generated by a low level on the RESET pin if enabled. Reset pulses longer than the minimum
pulse width (see section System and Reset Characteristics on page 118) will generate a reset, even if the clock is
not running. Shorter pulses are not guaranteed to generate a reset. When the applied signal reaches the Reset
Threshold Voltage VRST on its positive edge, the delay counter starts the MCU after the time-out period tTOUT
has expired. External reset is ignored during Power-on start-up count. After Power-on reset the internal reset is
extended only if RESET pin is low when the initial Power-on delay count is complete. See Figure 8-2 and Figure 83 on page 28.
Figure 8-4.
8.2.4
Watchdog Reset
When the Watchdog times out, it will generate a short reset pulse of one CK cycle duration. On the falling edge of
this pulse, the delay timer starts counting the time-out period tTOUT. See page 30 for details on operation of the
Watchdog Timer and Table 16-4 on page 118 for details on reset time-out.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
29
Figure 8-5.
CK
Watchdog Timer
The Watchdog Timer is clocked from an on-chip oscillator, which runs at 128 kHz. See Figure 8-6. By controlling
the Watchdog Timer prescaler, the Watchdog Reset interval can be adjusted as shown in Table 8-2 on page 32.
The WDR Watchdog Reset instruction resets the Watchdog Timer. The Watchdog Timer is also reset when it is
disabled and when a device reset occurs. Ten different clock cycle periods can be selected to determine the reset
period. If the reset period expires without another Watchdog Reset, the ATtiny4/5/9/10 resets and executes from
the Reset Vector. For timing details on the Watchdog Reset, refer to Table 8-3 on page 33.
Watchdog Timer
WDP0
WDP1
WDP2
WDP3
OSC/512K
OSC/1024K
OSC/256K
OSC/64K
OSC/128K
OSC/8K
OSC/4K
WATCHDOG
RESET
OSC/32K
WATCHDOG
PRESCALER
128 kHz
OSCILLATOR
OSC/16K
Figure 8-6.
OSC/2K
8.3
MUX
WDE
MCU RESET
The Wathdog Timer can also be configured to generate an interrupt instead of a reset. This can be very helpful
when using the Watchdog to wake-up from Power-down.
To prevent unintentional disabling of the Watchdog or unintentional change of time-out period, two different safety
levels are selected by the fuse WDTON as shown in Table 8-1 on page 31. See Procedure for Changing the
Watchdog Timer Configuration on page 31 for details.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
30
Table 8-1.
WDTON
WDT
Initial State
How to
Disable the WDT
How to
Change Time-out
Unprogrammed
Disabled
Protected change
sequence
No limitations
Programmed
Enabled
Always enabled
Protected change
sequence
8.3.1
8.3.1.1
Safety Level 1
In this mode, the Watchdog Timer is initially disabled, but can be enabled by writing the WDE bit to one without any
restriction. A special sequence is needed when disabling an enabled Watchdog Timer. To disable an enabled
Watchdog Timer, the following procedure must be followed:
1. Write the signature for change enable of protected I/O registers to register CCP
2. Within four instruction cycles, in the same operation, write WDE and WDP bits
8.3.1.2
Safety Level 2
In this mode, the Watchdog Timer is always enabled, and the WDE bit will always read as one. A protected change
is needed when changing the Watchdog Time-out period. To change the Watchdog Time-out, the following procedure must be followed:
1. Write the signature for change enable of protected I/O registers to register CCP
2. Within four instruction cycles, write the WDP bit. The value written to WDE is irrelevant
8.3.2
Code Examples
The following code example shows how to turn off the WDT. The example assumes that interrupts are controlled
(e.g., by disabling interrupts globally) so that no interrupts will occur during execution of these functions.
Assembly Code Example
WDT_off:
wdr
; Clear WDRF in RSTFLR
in
andi
out
r16, RSTFLR
r16, ~(1<<WDRF)
RSTFLR, r16
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
31
8.4
8.4.1
Register Description
WDTCSR Watchdog Timer Control and Status Register
Bit
WDIF
WDIE
WDP3
WDE
WDP2
WDP1
WDP0
Read/Write
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Initial Value
0x31
WDTCSR
Note:
(1)
WDIE
Mode
Action on Time-out
Stopped
None
Interrupt Mode
Interrupt
Reset
Interrupt, then go to
System Reset Mode
Reset
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
32
WDP3
WDP2
WDP1
WDP0
Number of WDT
Oscillator Cycles
Typical Time-out at
VCC = 5.0V
2K (2048) cycles
16 ms
4K (4096) cycles
32 ms
8K (8192) cycles
64 ms
0.125 s
0.25 s
0.5 s
1.0 s
2.0 s
4.0 s
8.0 s
Reserved
8.4.2
VLMF
VLMIE
VLM2
VLM1
VLM0
Read/Write
R/W
R/W
R/W
R/W
Initial Value
0x34
VLMCSR
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
33
Table 8-4.
VLM2:0
Label
Description
000
VLM0
001
VLM1L
010
VLM1H
011
VLM2
100
VLM3
101
110
Not allowed
111
0x3B
WDRF
EXTRF
PORF
Read/Write
R/W
R/W
R/W
Initial Value
RSTFLR
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
34
9. Interrupts
This section describes the specifics of the interrupt handling in ATtiny4/5/9/10. For a general explanation of the
AVR interrupt handling, see Reset and Interrupt Handling on page 10.
9.1
Interrupt Vectors
Interrupt vectors of ATtiny4/5/9/10 are described in Table 9-1 below.
Table 9-1.
Vector No.
Program Address
Note:
Label
Interrupt Source
0x0000
RESET
0x0001
INT0
0x0002
PCINT0
0x0003
TIM0_CAPT
0x0004
TIM0_OVF
Timer/Counter0 Overflow
0x0005
TIM0_COMPA
0x0006
TIM0_COMPB
0x0007
ANA_COMP
Analog Comparator
0x0008
WDT
Watchdog Time-out
10
0x0009
VLM
11
0x000A
ADC
In case the program never enables an interrupt source, the Interrupt Vectors will not be used and, consequently,
regular program code can be placed at these locations.
The most typical and general setup for interrupt vector addresses in ATtiny4/5/9/10 is shown in the program example below.
Comments
0x0000
rjmp
RESET
; Reset Handler
0x0001
rjmp
INT0
; IRQ0 Handler
0x0002
rjmp
PCINT0
; PCINT0 Handler
0x0003
rjmp
TIM0_CAPT
0x0004
rjmp
TIM0_OVF
0x0005
rjmp
TIM0_COMPA
0x0006
rjmp
TIM0_COMPB
0x0007
rjmp
ANA_COMP
0x0008
rjmp
WDT
0x0009
rjmp
VLM
0x000A
rjmp
ADC
<continues>
<continued>
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
35
9.2
0x000B
RESET: ldi
0x000C
out
SPH,r16
0x000D
ldi
0x000E
out
SPL,r16
0x000F
sei
0x0010
<instr>
...
...
; Enable interrupts
External Interrupts
External Interrupts are triggered by the INT0 pin or any of the PCINT3..0 pins. Observe that, if enabled, the interrupts will trigger even if the INT0 or PCINT3..0 pins are configured as outputs. This feature provides a way of
generating a software interrupt. Pin change 0 interrupts PCI0 will trigger if any enabled PCINT3..0 pin toggles. The
PCMSK Register controls which pins contribute to the pin change interrupts. Pin change interrupts on PCINT3..0
are detected asynchronously, which means that these interrupts can be used for waking the part also from sleep
modes other than Idle mode.
The INT0 interrupt can be triggered by a falling or rising edge or a low level. This is set up as shown in EICRA
External Interrupt Control Register A on page 37. When the INT0 interrupt is enabled and configured as level triggered, the interrupt will trigger as long as the pin is held low. Note that recognition of falling or rising edge interrupts
on INT0 requires the presence of an I/O clock, as described in Clock System on page 17.
9.2.1
9.2.2
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
36
Figure 9-1.
PCINT(0)
pcint_in_(0)
clk
pcint_syn
pcint_setflag
PCIF
pin_sync
LE
PCINT(0) in PCMSK(x)
clk
clk
PCINT(0)
pin_lat
pin_sync
pcint_in_(0)
pcint_syn
pcint_setflag
PCIF
9.3
Register Description
9.3.1
0x15
ISC01
ISC00
Read/Write
R/W
R/W
Initial Value
EICRA
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
37
low level interrupt is selected, the low level must be held until the completion of the currently executing instruction
to generate an interrupt.
Table 9-2.
9.3.2
ISC01
ISC00
Description
0x13
INTO
Read/Write
R/W
Initial Value
EIMSK
0x14
INTF0
Read/Write
R/W
Initial Value
EIFR
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
38
9.3.4
0x12
PCIE0
Read/Write
R/W
Initial Value
PCICR
0x11
PCIF0
Read/Write
R/W
Initial Value
PCIFR
0x10
PCINT3
PCINT2
PCINT1
PCINT0
Read/Write
R/W
R/W
R/W
R/W
Initial Value
PCMSK
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
39
Overview
All AVR ports have true Read-Modify-Write functionality when used as general digital I/O ports. This means that
the direction of one port pin can be changed without unintentionally changing the direction of any other pin with the
SBI and CBI instructions. The same applies when changing drive value (if configured as output) or enabling/disabling of pull-up resistors. Each output buffer has symmetrical drive characteristics with both high sink and source
capability. The pin driver is strong enough to drive LED displays directly. All port pins have individually selectable
pull-up resistors with a supply-voltage invariant resistance. All I/O pins have protection diodes to both VCC and
Ground as indicated in Figure 10-1 on page 40. See Electrical Characteristics on page 115 for a complete list of
parameters.
Figure 10-1. I/O Pin Equivalent Schematic
Rpu
Logic
Pxn
Cpin
See Figure
"General Digital I/O" for
Details
All registers and bit references in this section are written in general form. A lower case x represents the numbering letter for the port, and a lower case n represents the bit number. However, when using the register or bit
defines in a program, the precise form must be used. For example, PORTB3 for bit no. 3 in Port B, here documented generally as PORTxn. The physical I/O Registers and bit locations are listed in Register Description on
page 50.
Four I/O memory address locations are allocated for each port, one each for the Data Register PORTx, Data
Direction Register DDRx, Pull-up Enable Register PUEx, and the Port Input Pins PINx. The Port Input Pins
I/O location is read only, while the Data Register, the Data Direction Register, and the Pull-up Enable Register are
read/write. However, writing a logic one to a bit in the PINx Register, will result in a toggle in the corresponding bit
in the Data Register.
Using the I/O port as General Digital I/O is described in Ports as General Digital I/O on page 41. Most port pins
are multiplexed with alternate functions for the peripheral features on the device. How each alternate function interferes with the port pin is described in Alternate Port Functions on page 45. Refer to the individual module sections
for a full description of the alternate functions.
Note that enabling the alternate function of some of the port pins does not affect the use of the other pins in the port
as general digital I/O.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
40
10.2
REx
PUExn
Q CLR
RESET
WEx
DDxn
Q CLR
WDx
RESET
DATA BUS
RDx
1
Q
Pxn
PORTxn
Q CLR
RESET
WRx
SLEEP
WPx
RRx
SYNCHRONIZER
D
RPx
Q
PINxn
Q
clk I/O
SLEEP:
clk I/O :
Note:
10.2.1
SLEEP CONTROL
I/O CLOCK
WEx:
REx:
WDx:
RDx:
WRx:
RRx:
RPx:
WPx:
WRITE PUEx
READ PUEx
WRITE DDRx
READ DDRx
WRITE PORTx
READ PORTx REGISTER
READ PORTx PIN
WRITE PINx REGISTER
1. WEx, WRx, WPx, WDx, REx, RRx, RPx, and RDx are common to all pins within the same port. clkI/O, and SLEEP
are common to all ports.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
41
If PORTxn is written logic one when the pin is configured as an output pin, the port pin is driven high (one). If
PORTxn is written logic zero when the pin is configured as an output pin, the port pin is driven low (zero).
The pull-up resistor is activated, if the PUExn is written logic one. To switch the pull-up resistor off, PUExn has to
be written logic zero.
Table 10-1 summarizes the control signals for the pin value.
Table 10-1.
DDxn
PORTxn
PUExn
I/O
Pull-up
Comment
Input
No
Tri-state (hi-Z)
Input
Yes
Output
No
Output
Yes
NOT RECOMMENDED.
Output low (sink) and internal pull-up active.
Sources current through the internal pull-up
resistor and consumes power constantly
Output
No
Output
Yes
Port pins are tri-stated when a reset condition becomes active, even when no clocks are running.
10.2.2
10.2.3
Break-Before-Make Switching
In Break-Before-Make mode, switching the DDRxn bit from input to output introduces an immediate tri-state period
lasting one system clock cycle, as indicated in Figure 10-3. For example, if the system clock is 4 MHz and the
DDRxn is written to make an output, an immediate tri-state period of 250 ns is introduced before the value of
PORTxn is seen on the port pin.
To avoid glitches it is recommended that the maximum DDRxn toggle frequency is two system clock cycles. The
Break-Before-Make mode applies to the entire port and it is activated by the BBMx bit. For more details, see
PORTCR Port Control Register on page 50.
When switching the DDRxn bit from output to input no immediate tri-state period is introduced.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
42
0x02
r17
0x01
INSTRUCTIONS
nop
PORTx
DDRx
0x55
0x02
0x01
Px0
Px1
0x01
tri-state
tri-state
tri-state
intermediate tri-state cycle
10.2.4
SYSTEM CLK
INSTRUCTIONS
XXX
XXX
in r17, PINx
SYNC LATCH
PINxn
r17
0x00
0xFF
t pd, max
t pd, min
Consider the clock period starting shortly after the first falling edge of the system clock. The latch is closed when
the clock is low, and goes transparent when the clock is high, as indicated by the shaded region of the SYNC
LATCH signal. The signal value is latched when the system clock goes low. It is clocked into the PINxn Register at
the succeeding positive clock edge. As indicated by the two arrows tpd,max and tpd,min, a single signal transition
on the pin will be delayed between and 1 system clock period depending upon the time of assertion.
When reading back a software assigned pin value, a nop instruction must be inserted as indicated in Figure 10-5
on page 44. The out instruction sets the SYNC LATCH signal at the positive edge of the clock. In this case, the
delay tpd through the synchronizer is one system clock period.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
43
SYSTEM CLK
r16
INSTRUCTIONS
0xFF
out PORTx, r16
nop
in r17, PINx
SYNC LATCH
PINxn
r17
0x00
0xFF
t pd
10.2.5
10.2.6
Unconnected Pins
If some pins are unused, it is recommended to ensure that these pins have a defined level. Even though most of
the digital inputs are disabled in the deep sleep modes as described above, floating inputs should be avoided to
reduce current consumption in all other modes where the digital inputs are enabled (Reset, Active mode and Idle
mode).
The simplest method to ensure a defined level of an unused pin, is to enable the internal pull-up. In this case, the
pull-up will be disabled during reset. If low power consumption during reset is important, it is recommended to use
an external pull-up or pulldown. Connecting unused pins directly to VCC or GND is not recommended, since this
may cause excessive currents if the pin is accidentally configured as an output.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
44
10.2.7
Program Example
The following code example shows how to set port B pin 0 high, pin 1 low, and define the port pins from 2 to 3 as
input with a pull-up assigned to port pin 2. The resulting pin values are read back again, but as previously discussed, a nop instruction is included to be able to read back the value recently assigned to some of the pins.
Assembly Code Example
...
; Define pull-ups and set outputs high
; Define directions for port pins
ldi
r16,(1<<PUEB2)
ldi
r17,(1<<PB0)
ldi
r18,(1<<DDB1)|(1<<DDB0)
out
PUEB,r16
out
PORTB,r17
out
DDRB,r18
r16,PINB
...
Note:
10.3
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
45
PUOExn
REx
PUOVxn
1
Q
PUExn
Q CLR
DDOExn
RESET
WEx
DDOVxn
1
Q
D
DDxn
Q CLR
WDx
PVOExn
RESET
RDx
DATA BUS
PVOVxn
Pxn
Q
PORTxn
PTOExn
Q CLR
DIEOExn
WPx
DIEOVxn
RESET
WRx
1
0
RRx
SLEEP
SYNCHRONIZER
D
SET
RPx
PINxn
L
CLR
CLR
clk
I/O
DIxn
AIOxn
PUOExn:
PUOVxn:
DDOExn:
DDOVxn:
PVOExn:
PVOVxn:
DIEOExn:
DIEOVxn:
SLEEP:
PTOExn:
Note:
WEx:
REx:
WDx:
RDx:
RRx:
WRx:
RPx:
WPx:
clk I/O :
DIxn:
AIOxn:
WRITE PUEx
READ PUEx
WRITE DDRx
READ DDRx
READ PORTx REGISTER
WRITE PORTx
READ PORTx PIN
WRITE PINx
I/O CLOCK
DIGITAL INPUT PIN n ON PORTx
ANALOG INPUT/OUTPUT PIN n ON PORTx
1. WEx, WRx, WPx, WDx, REx, RRx, RPx, and RDx are common to all pins within the same port. clkI/O, and SLEEP
are common to all ports. All other signals are unique for each pin.
The illustration in the figure above serves as a generic description applicable to all port pins in the AVR microcontroller family. Some overriding signals may not be present in all port pins.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
46
Table 10-2 on page 47 summarizes the function of the overriding signals. The pin and port indexes from Figure 106 on page 46 are not shown in the succeeding tables. The overriding signals are generated internally in the modules having the alternate function.
Table 10-2.
Signal Name
Full Name
Description
PUOE
Pull-up Override
Enable
PUOV
Pull-up Override
Value
DDOE
Data Direction
Override Enable
DDOV
Data Direction
Override Value
PVOE
Port Value
Override Enable
If this signal is set and the Output Driver is enabled, the port
value is controlled by the PVOV signal. If PVOE is cleared, and
the Output Driver is enabled, the port Value is controlled by the
PORTxn Register bit.
PVOV
Port Value
Override Value
PTOE
Port Toggle
Override Enable
DIEOE
Digital Input
Enable Override
Enable
DIEOV
Digital Input
Enable Override
Value
DI
Digital Input
AIO
Analog
Input/Output
The following subsections shortly describe the alternate functions for each port, and relate the overriding signals to
the alternate function. Refer to the alternate function description for further details.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
47
10.3.1
Port Pin
Alternate Function
PB0
PB1
PB2
PB3
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
48
PCINT1: Pin Change Interrupt source 1. The PB1 pin can serve as an external interrupt source for pin change
interrupt 0.
TPICLK: Serial Programming Clock.
Port B, Bit 2 ADC2/CLKO/INT0/PCINT2/T0
ADC2: Analog to Digital Converter, Channel 2 (ATtiny5/10, only)
CLKO: System Clock Output. The system clock can be output on pin PB2. The system clock will be output if
CKOUT bit is programmed, regardless of the PORTB2 and DDB2 settings.
INT0: External Interrupt Request 0
PCINT2: Pin Change Interrupt source 2. The PB2 pin can serve as an external interrupt source for pin change
interrupt 0.
T0: Timer/Counter0 counter source.
Port B, Bit 3 ADC3/PCINT3/RESET
ADC3: Analog to Digital Converter, Channel 3 (ATtiny5/10, only)
PCINT3: Pin Change Interrupt source 3. The PB3 pin can serve as an external interrupt source for pin change
interrupt 0.
RESET:
Table 10-4 and Table 10-5 on page 50 relate the alternate functions of Port B to the overriding signals shown in
Figure 10-6 on page 46.
Table 10-4.
Signal
Name
PB3/ADC3/RESET/PCINT3
PUOE
RSTDISBL
PUOV
(1)
PB2/ADC2/INT0/T0/CLKO/PCINT2
CKOUT(2)
0
(1)
CKOUT(2)
DDOE
RSTDISBL
DDOV
PVOE
CKOUT(2)
PVOV
(system clock)
PTOE
DIEOE
DIEOV
DI
PCINT3 Input
INT0/T0/PCINT2 Input
AIO
ADC3 Input
ADC2 Input
Notes:
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
49
Table 10-5.
Signal
Name
PB1/ADC1/AIN1/OC0B/CLKI/ICP0/PCINT1
PUOE
EXT_CLOCK
PUOV
DDOE
EXT_CLOCK(1)
DDOV
EXT_CLOCK
(1)
+ OC0B Enable
OC0A Enable
PVOV
EXT_CLOCK
(1)
OC0B
OC0A
PTOE
0
(1)
+ (PCINT1 PCIE0) +
DIEOE
EXT_CLOCK
ADC1D
DIEOV
(EXT_CLOCK(1) PWR_DOWN) +
(EXT_CLOCK(1) PCINT1 PCIE0)
PCINT0 PCIE0
DI
CLOCK/ICP0/PCINT1 Input
PCINT0 Input
AIO
Notes:
10.4.1
PB0/ADC0/AIN0/OC0A/PCINT0
(1)
PVOE
10.4
Register Description
PORTCR Port Control Register
Bit
0x03
BBMB
Read/Write
R/W
Initial Value
PORTCR
0x03
PUEB3
PUEB2
PUEB1
PUEB0
Read/Write
R/W
R/W
R/W
R/W
Initial Value
PUEB
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
50
10.4.3
10.4.4
10.4.5
0x02
PORTB3
PORTB2
PORTB1
PORTB0
Read/Write
R/W
R/W
R/W
R/W
Initial Value
PORTB
0x01
DDB3
DDB2
DDB1
DDB0
Read/Write
R/W
R/W
R/W
R/W
Initial Value
DDRB
0x00
PINB3
PINB2
PINB1
PINB0
Read/Write
R/W
R/W
R/W
R/W
Initial Value
N/A
N/A
N/A
N/A
PINB
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
51
11.2
Overview
The 16-bit Timer/Counter unit allows accurate program execution timing (event management), wave generation,
and signal timing measurement.
Figure 11-1. 16-bit Timer/Counter Block Diagram
Count
Clear
Direction
TOVn
(Int.Req.)
Control Logic
clkTn
Clock Select
Edge
Detector
TOP
Tn
BOTTOM
( From Prescaler )
Timer/Counter
TCNTn
=0
OCnA
(Int.Req.)
Waveform
Generation
OCnA
OCRnA
DATA BUS
11.1
OCnB
(Int.Req.)
Fixed
TOP
Values
Waveform
Generation
=
OCRnB
OCnB
( From Analog
Comparator Ouput )
ICFn (Int.Req.)
Edge
Detector
ICRn
Noise
Canceler
ICPn
TCCRnA
TCCRnB
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
52
A simplified block diagram of the 16-bit Timer/Counter is shown in Figure 11-1 on page 52. For actual placement of
I/O pins, refer to Pinout of ATtiny4/5/9/10 on page 2. CPU accessible I/O Registers, including I/O bits and I/O
pins, are shown in bold. The device-specific I/O Register and bit locations are listed in the Register Description on
page 72.
Most register and bit references in this section are written in general form. A lower case n replaces the
Timer/Counter number, and a lower case x replaces the Output Compare unit channel. However, when using the
register or bit defines in a program, the precise form must be used, i.e., TCNT0 for accessing Timer/Counter0
counter value and so on.
11.2.1
Registers
The Timer/Counter (TCNT0), Output Compare Registers (OCR0A/B), and Input Capture Register (ICR0) are all
16-bit registers. Special procedures must be followed when accessing the 16-bit registers. These procedures are
described in the section Accessing 16-bit Registers on page 70. The Timer/Counter Control Registers
(TCCR0A/B) are 8-bit registers and have no CPU access restrictions. Interrupt requests (abbreviated to Int.Req. in
the figure) signals are all visible in the Timer Interrupt Flag Register (TIFR). All interrupts are individually masked
with the Timer Interrupt Mask Register (TIMSK). TIFR and TIMSK are not shown in the figure.
The Timer/Counter can be clocked internally, via the prescaler, or by an external clock source on the T0 pin. The
Clock Select logic block controls which clock source and edge the Timer/Counter uses to increment (or decrement)
its value. The Timer/Counter is inactive when no clock source is selected. The output from the Clock Select logic is
referred to as the timer clock (clkT0).
The double buffered Output Compare Registers (OCR0A/B) are compared with the Timer/Counter value at all time.
The result of the compare can be used by the Waveform Generator to generate a PWM or variable frequency output on the Output Compare pin (OC0A/B). See Output Compare Units on page 58. The compare match event will
also set the Compare Match Flag (OCF0A/B) which can be used to generate an Output Compare interrupt request.
The Input Capture Register can capture the Timer/Counter value at a given external (edge triggered) event on
either the Input Capture pin (ICP0) or on the Analog Comparator pins (See Analog Comparator on page 80). The
Input Capture unit includes a digital filtering unit (Noise Canceler) for reducing the chance of capturing noise
spikes.
The TOP value, or maximum Timer/Counter value, can in some modes of operation be defined by either the
OCR0A Register, the ICR0 Register, or by a set of fixed values. When using OCR0A as TOP value in a PWM
mode, the OCR0A Register can not be used for generating a PWM output. However, the TOP value will in this
case be double buffered allowing the TOP value to be changed in run time. If a fixed TOP value is required, the
ICR0 Register can be used as an alternative, freeing the OCR0A to be used as PWM output.
11.2.2
Definitions
The following definitions are used extensively throughout the section:
Table 11-1.
Definitions
Constant
Description
BOTTOM
MAX
The counter reaches its MAXimum when it becomes 0xFF (decimal 255)
TOP
The counter reaches the TOP when it becomes equal to the highest value in the count
sequence. The TOP value can be assigned to be the fixed value 0xFF (MAX) or the
value stored in the OCR0A Register. The assignment depends on the mode of operation
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
53
11.3
Clock Sources
The Timer/Counter can be clocked by an internal or an external clock source. The clock source is selected by the
Clock Select logic which is controlled by the Clock Select (CS02:0) bits located in the Timer/Counter control Register B (TCCR0B). For details on clock sources and prescaler, see section Prescaler.
11.3.1
Prescaler
The Timer/Counter can be clocked directly by the system clock (by setting the CS2:0 = 1). This provides the fastest
operation, with a maximum Timer/Counter clock frequency equal to system clock frequency (fCLK_I/O). Alternatively,
one of four taps from the prescaler can be used as a clock source.
See Figure 11-2 for an illustration of the prescaler unit.
Figure 11-2. Prescaler for Timer/Counter0
clk I/O
Clear
PSR10
T0
Synchronization
clkT0
Note:
1. The synchronization logic on the input pins (T0) is shown in Figure 11-3 on page 55.
The prescaled clock has a frequency of fCLK_I/O/8, fCLK_I/O/64, fCLK_I/O/256, or fCLK_I/O/1024. See Table 11-6 on page
75 for details.
11.3.1.1
Prescaler Reset
The prescaler is free running, i.e., operates independently of the Clock Select logic of the Timer/CounterCounter,
and it is shared by the Timer/Counter Tn. Since the prescaler is not affected by the Timer/Counters clock select,
the state of the prescaler will have implications for situations where a prescaled clock is used. One example of
prescaling artifacts occurs when the timer is enabled and clocked by the prescaler (CS2:0 = 2, 3, 4, or 5). The number of system clock cycles from when the timer is enabled to the first count occurs can be from 1 to N+1 system
clock cycles, where N equals the prescaler divisor (8, 64, 256, or 1024).
It is possible to use the Prescaler Reset for synchronizing the Timer/Counter to program execution.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
54
11.3.2
Tn
Tn_sync
(To Clock
Select Logic)
LE
clk I/O
Synchronization
Edge Detector
The synchronization and edge detector logic introduces a delay of 2.5 to 3.5 system clock cycles from an edge has
been applied to the T0 pin to the counter is updated.
Enabling and disabling of the clock input must be done when T0 has been stable for at least one system clock
cycle, otherwise it is a risk that a false Timer/Counter clock pulse is generated.
Each half period of the external clock applied must be longer than one system clock cycle to ensure correct sampling. The external clock must be guaranteed to have less than half the system clock frequency (fExtClk < fclk_I/O/2)
given a 50/50% duty cycle. Since the edge detector uses sampling, the maximum frequency of an external clock it
can detect is half the sampling frequency (Nyquist sampling theorem). However, due to variation of the system
clock frequency and duty cycle caused by oscillator source (crystal, resonator, and capacitors) tolerances, it is recommended that maximum frequency of an external clock source is less than fclk_I/O/2.5.
An external clock source can not be prescaled.
11.4
Counter Unit
The main part of the 16-bit Timer/Counter is the programmable 16-bit bi-directional counter unit. Figure 11-4 on
page 55 shows a block diagram of the counter and its surroundings.
Figure 11-4. Counter Unit Block Diagram
DATA BUS
(8-bit)
TOVn
(Int.Req.)
TEMP (8-bit)
Clock Select
Count
TCNTnH (8-bit)
TCNTnL (8-bit)
Clear
Direction
Control Logic
clkTn
Edge
Detector
Tn
( From Prescaler )
TOP
BOTTOM
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
55
Count
Direction
Clear
clkT0
TOP
BOTTOM
The 16-bit counter is mapped into two 8-bit I/O memory locations: Counter High (TCNT0H) containing the upper
eight bits of the counter, and Counter Low (TCNT0L) containing the lower eight bits. The TCNT0H Register can
only be indirectly accessed by the CPU. When the CPU does an access to the TCNT0H I/O location, the CPU
accesses the high byte temporary register (TEMP). The temporary register is updated with the TCNT0H value
when the TCNT0L is read, and TCNT0H is updated with the temporary register value when TCNT0L is written. This
allows the CPU to read or write the entire 16-bit counter value within one clock cycle via the 8-bit data bus. It is
important to notice that there are special cases of writing to the TCNT0 Register when the counter is counting that
will give unpredictable results. The special cases are described in the sections where they are of importance.
Depending on the mode of operation used, the counter is cleared, incremented, or decremented at each timer
clock (clkT0). The clkT0 can be generated from an external or internal clock source, selected by the Clock Select bits
(CS02:0). When no clock source is selected (CS02:0 = 0) the timer is stopped. However, the TCNT0 value can be
accessed by the CPU, independent of whether clkT0 is present or not. A CPU write overrides (has priority over) all
counter clear or count operations.
The counting sequence is determined by the setting of the Waveform Generation mode bits (WGM03:0) located in
the Timer/Counter Control Registers A and B (TCCR0A and TCCR0B). There are close connections between how
the counter behaves (counts) and how waveforms are generated on the Output Compare outputs OC0x. For more
details about advanced counting sequences and waveform generation, see Modes of Operation on page 61.
The Timer/Counter Overflow Flag (TOV0) is set according to the mode of operation selected by the WGM03:0 bits.
TOV0 can be used for generating a CPU interrupt.
11.5
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
56
DATA BUS
(8-bit)
TEMP (8-bit)
ICRnH (8-bit)
WRITE
ICRnL (8-bit)
TCNTnH (8-bit)
ACO*
Analog
Comparator
ACIC*
TCNTnL (8-bit)
ICNC
ICES
Noise
Canceler
Edge
Detector
ICFn (Int.Req.)
ICPn
When a change of the logic level (an event) occurs on the Input Capture pin (ICP0), alternatively on the Analog
Comparator output (ACO), and this change confirms to the setting of the edge detector, a capture will be triggered.
When a capture is triggered, the 16-bit value of the counter (TCNT0) is written to the Input Capture Register
(ICR0). The Input Capture Flag (ICF0) is set at the same system clock as the TCNT0 value is copied into ICR0
Register. If enabled (ICIE0 = 1), the Input Capture Flag generates an Input Capture interrupt. The ICF0 flag is automatically cleared when the interrupt is executed. Alternatively the ICF0 flag can be cleared by software by writing a
logical one to its I/O bit location.
Reading the 16-bit value in the Input Capture Register (ICR0) is done by first reading the low byte (ICR0L) and
then the high byte (ICR0H). When the low byte is read the high byte is copied into the high byte temporary register
(TEMP). When the CPU reads the ICR0H I/O location it will access the TEMP Register.
The ICR0 Register can only be written when using a Waveform Generation mode that utilizes the ICR0 Register for
defining the counters TOP value. In these cases the Waveform Generation mode (WGM03:0) bits must be set
before the TOP value can be written to the ICR0 Register. When writing the ICR0 Register the high byte must be
written to the ICR0H I/O location before the low byte is written to ICR0L.
For more information on how to access the 16-bit registers refer to Accessing 16-bit Registers on page 70.
11.5.1
57
clock cycles. Note that the input of the noise canceler and edge detector is always enabled unless the Timer/Counter is set in a Waveform Generation mode that uses ICR0 to define TOP.
An Input Capture can be triggered by software by controlling the port of the ICP0 pin.
11.5.2
Noise Canceler
The noise canceler improves noise immunity by using a simple digital filtering scheme. The noise canceler input is
monitored over four samples, and all four must be equal for changing the output that in turn is used by the edge
detector.
The noise canceler is enabled by setting the Input Capture Noise Canceler (ICNC0) bit in Timer/Counter Control
Register B (TCCR0B). When enabled the noise canceler introduces additional four system clock cycles of delay
from a change applied to the input, to the update of the ICR0 Register. The noise canceler uses the system clock
and is therefore not affected by the prescaler.
11.5.3
11.6
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
58
(8-bit)
TEMP (8-bit)
TCNTnH (8-bit)
OCRnxH (8-bit)
TCNTnL (8-bit)
OCRnxL (8-bit)
= (16-bit Comparator )
OCFnx (Int.Req.)
TOP
BOTTOM
Waveform Generator
WGMn3:0
OCnx
COMnx1:0
The OCR0x Register is double buffered when using any of the twelve Pulse Width Modulation (PWM) modes. For
the Normal and Clear Timer on Compare (CTC) modes of operation, the double buffering is disabled. The double
buffering synchronizes the update of the OCR0x Compare Register to either TOP or BOTTOM of the counting
sequence. The synchronization prevents the occurrence of odd-length, non-symmetrical PWM pulses, thereby
making the output glitch-free.
The OCR0x Register access may seem complex, but this is not case. When the double buffering is enabled, the
CPU has access to the OCR0x Buffer Register, and if double buffering is disabled the CPU will access the OCR0x
directly. The content of the OCR0x (Buffer or Compare) Register is only changed by a write operation (the
Timer/Counter does not update this register automatically as the TCNT0 and ICR0 Register). Therefore OCR0x is
not read via the high byte temporary register (TEMP). However, it is a good practice to read the low byte first as
when accessing other 16-bit registers. Writing the OCR0x Registers must be done via the TEMP Register since the
compare of all 16 bits is done continuously. The high byte (OCR0xH) has to be written first. When the high byte I/O
location is written by the CPU, the TEMP Register will be updated by the value written. Then when the low byte
(OCR0xL) is written to the lower eight bits, the high byte will be copied into the upper 8-bits of either the OCR0x
buffer or OCR0x Compare Register in the same system clock cycle.
For more information of how to access the 16-bit registers refer to Accessing 16-bit Registers on page 70.
11.6.1
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
59
11.6.2
11.6.3
11.7
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
60
COMnx1
COMnx0
FOCnx
Waveform
Generator
Q
1
OCnx
DATA BUS
OCnx
Pin
PORT
D
DDR
clk I/O
The general I/O port function is overridden by the Output Compare (OC0x) from the Waveform Generator if either
of the COM0x1:0 bits are set. However, the OC0x pin direction (input or output) is still controlled by the Data Direction Register (DDR) for the port pin. The Data Direction Register bit for the OC0x pin (DDR_OC0x) must be set as
output before the OC0x value is visible on the pin. The port override function is generally independent of the Waveform Generation mode, but there are some exceptions. See Table 11-2 on page 73, Table 11-3 on page 73 and
Table 11-4 on page 73 for details.
The design of the Output Compare pin logic allows initialization of the OC0x state before the output is enabled.
Note that some COM0x1:0 bit settings are reserved for certain modes of operation. See Register Description on
page 72
The COM0x1:0 bits have no effect on the Input Capture unit.
11.7.1
11.8
Modes of Operation
The mode of operation, i.e., the behavior of the Timer/Counter and the Output Compare pins, is defined by the
combination of the Waveform Generation mode (WGM03:0) and Compare Output mode (COM0x1:0) bits. The
Compare Output mode bits do not affect the counting sequence, while the Waveform Generation mode bits do.
The COM0x1:0 bits control whether the PWM output generated should be inverted or not (inverted or non-inverted
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
61
PWM). For non-PWM modes the COM0x1:0 bits control whether the output should be set, cleared or toggle at a
compare match (Compare Match Output Unit on page 60)
For detailed timing information refer to Timer/Counter Timing Diagrams on page 69.
11.8.1
Normal Mode
The simplest mode of operation is the Normal mode (WGM03:0 = 0). In this mode the counting direction is always
up (incrementing), and no counter clear is performed. The counter simply overruns when it passes its maximum
16-bit value (MAX = 0xFFFF) and then restarts from the BOTTOM (0x0000). In normal operation the Timer/Counter Overflow Flag (TOV0) will be set in the same timer clock cycle as the TCNT0 becomes zero. The TOV0 flag in
this case behaves like a 17th bit, except that it is only set, not cleared. However, combined with the timer overflow
interrupt that automatically clears the TOV0 flag, the timer resolution can be increased by software. There are no
special cases to consider in the Normal mode, a new counter value can be written anytime.
The Input Capture unit is easy to use in Normal mode. However, observe that the maximum interval between the
external events must not exceed the resolution of the counter. If the interval between events are too long, the timer
overflow interrupt or the prescaler must be used to extend the resolution for the capture unit.
The Output Compare units can be used to generate interrupts at some given time. Using the Output Compare to
generate waveforms in Normal mode is not recommended, since this will occupy too much of the CPU time.
11.8.2
TCNTn
OCnA
(Toggle)
Period
(COMnA1:0 = 1)
An interrupt can be generated at each time the counter value reaches the TOP value by either using the OCF0A or
ICF0 flag according to the register used to define the TOP value. If the interrupt is enabled, the interrupt handler
routine can be used for updating the TOP value. However, changing the TOP to a value close to BOTTOM when
the counter is running with none or a low prescaler value must be done with care since the CTC mode does not
have the double buffering feature. If the new value written to OCR0A or ICR0 is lower than the current value of
TCNT0, the counter will miss the compare match. The counter will then have to count to its maximum value
(0xFFFF) and wrap around starting at 0x0000 before the compare match can occur. In many cases this feature is
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
62
not desirable. An alternative will then be to use the fast PWM mode using OCR0A for defining TOP (WGM03:0 =
15) since the OCR0A then will be double buffered.
For generating a waveform output in CTC mode, the OC0A output can be set to toggle its logical level on each
compare match by setting the Compare Output mode bits to toggle mode (COM0A1:0 = 1). The OC0A value will
not be visible on the port pin unless the data direction for the pin is set to output (DDR_OC0A = 1). The waveform
generated will have a maximum frequency of 0A = fclk_I/O/2 when OCR0A is set to zero (0x0000). The waveform frequency is defined by the following equation:
f clk_I/O
f OCnA = --------------------------------------------------2 N 1 + OCRnA
The N variable represents the prescaler factor (1, 8, 64, 256, or 1024).
As for the Normal mode of operation, the TOV0 flag is set in the same timer clock cycle that the counter counts
from MAX to 0x0000.
11.8.3
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
63
TCNTn
OCnx
(COMnx1:0 = 2)
OCnx
(COMnx1:0 = 3)
Period
The Timer/Counter Overflow Flag (TOV0) is set each time the counter reaches TOP. In addition the OC0A or ICF0
flag is set at the same timer clock cycle as TOV0 is set when either OCR0A or ICR0 is used for defining the TOP
value. If one of the interrupts are enabled, the interrupt handler routine can be used for updating the TOP and compare values.
When changing the TOP value the program must ensure that the new TOP value is higher or equal to the value of
all of the Compare Registers. If the TOP value is lower than any of the Compare Registers, a compare match will
never occur between the TCNT0 and the OCR0x. Note that when using fixed TOP values the unused bits are
masked to zero when any of the OCR0x Registers are written.
The procedure for updating ICR0 differs from updating OCR0A when used for defining the TOP value. The ICR0
Register is not double buffered. This means that if ICR0 is changed to a low value when the counter is running with
none or a low prescaler value, there is a risk that the new ICR0 value written is lower than the current value of
TCNT0. The result will then be that the counter will miss the compare match at the TOP value. The counter will
then have to count to the MAX value (0xFFFF) and wrap around starting at 0x0000 before the compare match can
occur. The OCR0A Register however, is double buffered. This feature allows the OCR0A I/O location to be written
anytime. When the OCR0A I/O location is written the value written will be put into the OCR0A Buffer Register. The
OCR0A Compare Register will then be updated with the value in the Buffer Register at the next timer clock cycle
the TCNT0 matches TOP. The update is done at the same timer clock cycle as the TCNT0 is cleared and the
TOV0 flag is set.
Using the ICR0 Register for defining TOP works well when using fixed TOP values. By using ICR0, the OCR0A
Register is free to be used for generating a PWM output on OC0A. However, if the base PWM frequency is actively
changed (by changing the TOP value), using the OCR0A as TOP is clearly a better choice due to its double buffer
feature.
In fast PWM mode, the compare units allow generation of PWM waveforms on the OC0x pins. Setting the
COM0x1:0 bits to two will produce a non-inverted PWM and an inverted PWM output can be generated by setting
the COM0x1:0 to three (see Table 11-3 on page 73). The actual OC0x value will only be visible on the port pin if
the data direction for the port pin is set as output (DDR_OC0x). The PWM waveform is generated by setting (or
clearing) the OC0x Register at the compare match between OCR0x and TCNT0, and clearing (or setting) the
OC0x Register at the timer clock cycle the counter is cleared (changes from TOP to BOTTOM).
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
64
The PWM frequency for the output can be calculated by the following equation:
f clk_I/O
f OCnxPWM = ----------------------------------N 1 + TOP
The N variable represents the prescaler divider (1, 8, 64, 256, or 1024).
The extreme values for the OCR0x Register represents special cases when generating a PWM waveform output in
the fast PWM mode. If the OCR0x is set equal to BOTTOM (0x0000) the output will be a narrow spike for each
TOP+1 timer clock cycle. Setting the OCR0x equal to TOP will result in a constant high or low output (depending
on the polarity of the output set by the COM0x1:0 bits.)
A frequency (with 50% duty cycle) waveform output in fast PWM mode can be achieved by setting OC0A to toggle
its logical level on each compare match (COM0A1:0 = 1). The waveform generated will have a maximum frequency of f0A = fclk_I/O/2 when OCR0A is set to zero (0x0000). This feature is similar to the OC0A toggle in CTC
mode, except the double buffer feature of the Output Compare unit is enabled in the fast PWM mode.
11.8.4
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
65
TCNTn
OCnx
(COMnx1:0 = 2)
OCnx
(COMnx1:0 = 3)
Period
The Timer/Counter Overflow Flag (TOV0) is set each time the counter reaches BOTTOM. When either OCR0A or
ICR0 is used for defining the TOP value, the OC0A or ICF0 flag is set accordingly at the same timer clock cycle as
the OCR0x Registers are updated with the double buffer value (at TOP). The interrupt flags can be used to generate an interrupt each time the counter reaches the TOP or BOTTOM value.
When changing the TOP value the program must ensure that the new TOP value is higher or equal to the value of
all of the Compare Registers. If the TOP value is lower than any of the Compare Registers, a compare match will
never occur between the TCNT0 and the OCR0x. Note that when using fixed TOP values, the unused bits are
masked to zero when any of the OCR0x Registers are written. As the third period shown in Figure 11-10 on page
66 illustrates, changing the TOP actively while the Timer/Counter is running in the phase correct mode can result in
an unsymmetrical output. The reason for this can be found in the time of update of the OCR0x Register. Since the
OCR0x update occurs at TOP, the PWM period starts and ends at TOP. This implies that the length of the falling
slope is determined by the previous TOP value, while the length of the rising slope is determined by the new TOP
value. When these two values differ the two slopes of the period will differ in length. The difference in length gives
the unsymmetrical result on the output.
It is recommended to use the phase and frequency correct mode instead of the phase correct mode when changing the TOP value while the Timer/Counter is running. When using a static TOP value there are practically no
differences between the two modes of operation.
In phase correct PWM mode, the compare units allow generation of PWM waveforms on the OC0x pins. Setting
the COM0x1:0 bits to two will produce a non-inverted PWM and an inverted PWM output can be generated by setting the COM0x1:0 to three (See Table 11-4 on page 73). The actual OC0x value will only be visible on the port pin
if the data direction for the port pin is set as output (DDR_OC0x). The PWM waveform is generated by setting (or
clearing) the OC0x Register at the compare match between OCR0x and TCNT0 when the counter increments, and
clearing (or setting) the OC0x Register at compare match between OCR0x and TCNT0 when the counter decrements. The PWM frequency for the output when using phase correct PWM can be calculated by the following
equation:
f clk_I/O
f OCnxPCPWM = ----------------------------2 N TOP
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
66
The N variable represents the prescaler divider (1, 8, 64, 256, or 1024).
The extreme values for the OCR0x Register represent special cases when generating a PWM waveform output in
the phase correct PWM mode. If the OCR0x is set equal to BOTTOM the output will be continuously low and if set
equal to TOP the output will be continuously high for non-inverted PWM mode. For inverted PWM the output will
have the opposite logic values.
11.8.5
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
67
Figure 11-11. Phase and Frequency Correct PWM Mode, Timing Diagram
OCnA Interrupt Flag Set
or ICFn Interrupt Flag Set
(Interrupt on TOP)
OCRnx/TOP Updateand
TOVn Interrupt Flag Set
(Interrupt on Bottom)
TCNTn
OCnx
(COMnx1:0 = 2)
OCnx
(COMnx1:0 = 3)
Period
The Timer/Counter Overflow Flag (TOV0) is set at the same timer clock cycle as the OCR0x Registers are updated
with the double buffer value (at BOTTOM). When either OCR0A or ICR0 is used for defining the TOP value, the
OC0A or ICF0 flag set when TCNT0 has reached TOP. The interrupt flags can then be used to generate an interrupt each time the counter reaches the TOP or BOTTOM value.
When changing the TOP value the program must ensure that the new TOP value is higher or equal to the value of
all of the Compare Registers. If the TOP value is lower than any of the Compare Registers, a compare match will
never occur between the TCNT0 and the OCR0x.
As Figure 11-11 on page 68 shows the output generated is, in contrast to the phase correct mode, symmetrical in
all periods. Since the OCR0x Registers are updated at BOTTOM, the length of the rising and the falling slopes will
always be equal. This gives symmetrical output pulses and is therefore frequency correct.
Using the ICR0 Register for defining TOP works well when using fixed TOP values. By using ICR0, the OCR0A
Register is free to be used for generating a PWM output on OC0A. However, if the base PWM frequency is actively
changed by changing the TOP value, using the OCR0A as TOP is clearly a better choice due to its double buffer
feature.
In phase and frequency correct PWM mode, the compare units allow generation of PWM waveforms on the OC0x
pins. Setting the COM0x1:0 bits to two will produce a non-inverted PWM and an inverted PWM output can be generated by setting the COM0x1:0 to three (See Table 11-4 on page 73). The actual OC0x value will only be visible
on the port pin if the data direction for the port pin is set as output (DDR_OC0x). The PWM waveform is generated
by setting (or clearing) the OC0x Register at the compare match between OCR0x and TCNT0 when the counter
increments, and clearing (or setting) the OC0x Register at compare match between OCR0x and TCNT0 when the
counter decrements. The PWM frequency for the output when using phase and frequency correct PWM can be calculated by the following equation:
f clk_I/O
f OCnxPFCPWM = ----------------------------2 N TOP
The N variable represents the prescaler divider (1, 8, 64, 256, or 1024).
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
68
The extreme values for the OCR0x Register represents special cases when generating a PWM waveform output in
the phase correct PWM mode. If the OCR0x is set equal to BOTTOM the output will be continuously low and if set
equal to TOP the output will be set to high for non-inverted PWM mode. For inverted PWM the output will have the
opposite logic values.
11.9
clkI/O
clkTn
(clkI/O /1)
TCNTn
OCRnx - 1
OCRnx
OCRnx
OCRnx + 1
OCRnx + 2
OCRnx Value
OCFnx
Figure 11-13 on page 69 shows the same timing data, but with the prescaler enabled.
Figure 11-13. Timer/Counter Timing Diagram, Setting of OCF0x, with Prescaler (fclk_I/O/8)
clkI/O
clkTn
(clkI/O /8)
TCNTn
OCRnx
OCRnx - 1
OCRnx
OCRnx + 1
OCRnx + 2
OCRnx Value
OCFnx
Figure 11-14 on page 70 shows the count sequence close to TOP in various modes. When using phase and frequency correct PWM mode the OCR0x Register is updated at BOTTOM. The timing diagrams will be the same, but
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
69
TOP should be replaced by BOTTOM, TOP-1 by BOTTOM+1 and so on. The same renaming applies for modes
that set the TOV0 flag at BOTTOM.
Figure 11-14. Timer/Counter Timing Diagram, no Prescaling
clkI/O
clkTn
(clkI/O /1)
TCNTn
(CTC and FPWM)
TCNTn
(PC and PFC PWM)
TOP - 1
TOP
BOTTOM
BOTTOM + 1
TOP - 1
TOP
TOP - 1
TOP - 2
TOVn (FPWM)
and ICFn (if used
as TOP)
OCRnx
(Update at TOP)
Figure 11-15 on page 70 shows the same timing data, but with the prescaler enabled.
Figure 11-15. Timer/Counter Timing Diagram, with Prescaler (fclk_I/O/8)
clkI/O
clkTn
(clkI/O/8)
TCNTn
(CTC and FPWM)
TCNTn
(PC and PFC PWM)
TOP - 1
TOP
BOTTOM
BOTTOM + 1
TOP - 1
TOP
TOP - 1
TOP - 2
TOVn (FPWM)
and ICF n (if used
as TOP)
OCRnx
(Update at TOP)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
70
read by the CPU, the high byte of the 16-bit register is copied into the temporary register in the same clock cycle as
the low byte is read.
Not all 16-bit accesses uses the temporary register for the high byte. Reading the OCR0A/B 16-bit registers does
not involve using the temporary register.
To do a 16-bit write, the high byte must be written before the low byte. For a 16-bit read, the low byte must be read
before the high byte.
The following code example shows how to access the 16-bit timer registers assuming that no interrupts updates
the temporary register. The same principle can be used directly for accessing the OCR0A/B and ICR0 Registers.
Assembly Code Example
...
; Set TCNT0 to 0x01FF
ldi r17,0x01
ldi r16,0xFF
out TCNT0H,r17
out TCNT0L,r16
; Read TCNT0 into r17:r16
in r16,TCNT0L
in r17,TCNT0H
...
Note:
The code example returns the TCNT0 value in the r17:r16 register pair.
It is important to notice that accessing 16-bit registers are atomic operations. If an interrupt occurs between the two
instructions accessing the 16-bit register, and the interrupt code updates the temporary register by accessing the
same or any other of the 16-bit timer registers, then the result of the access outside the interrupt will be corrupted.
Therefore, when both the main code and the interrupt code update the temporary register, the main code must disable the interrupts during the 16-bit access.
The following code example shows how to do an atomic read of the TCNT0 Register contents. Reading any of the
OCR0A/B or ICR0 Registers can be done by using the same principle.
Assembly Code Example
TIM16_ReadTCNT0:
; Save global interrupt flag
in r18,SREG
; Disable interrupts
cli
; Read TCNT0 into r17:r16
in r16,TCNT0L
in r17,TCNT0H
; Restore global interrupt flag
out SREG,r18
ret
Note:
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
71
The code example returns the TCNT0 value in the r17:r16 register pair.
The following code example shows how to do an atomic write of the TCNT0 Register contents. Writing any of the
OCR0A/B or ICR0 Registers can be done by using the same principle.
Assembly Code Example
TIM16_WriteTCNT0:
; Save global interrupt flag
in r18,SREG
; Disable interrupts
cli
; Set TCNT0 to r17:r16
out TCNT0H,r17
out TCNT0L,r16
; Restore global interrupt flag
out SREG,r18
ret
Note:
The code example requires that the r17:r16 register pair contains the value to be written to TCNT0.
11.10.1
COM0A1
COM0A0
COM0B1
COM0B0
WGM01
WGM00
Read/Write
R/W
R/W
R/W
R/W
R/W
R/W
Initial Value
0x2E
TCCR0A
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
72
When OC0A or OC0B is connected to the pin, the function of COM0x1:0 bits depends on the WGM03:0 bits. Table
11-2 shows the COM0x1:0 bit functionality when the WGM03:0 bits are set to a Normal or CTC (non-PWM) Mode.
Table 11-2.
COM0A1/
COM0B1
Description
Table 11-3 shows the COM0x1:0 bit functionality when the WGM03:0 bits are set to one of the Fast PWM Modes.
Table 11-3.
COM0A1/
COM0B1
1 (1)
Note:
Description
1. A special case occurs when OCR0A/OCR0B equals TOP and COM0A1/COM0B1 is set. In this case the compare
match is ignored, but set or clear is done at BOTTOM. See Fast PWM Mode on page 63 for more details.
Table 11-4 shows the COM0x1:0 bit functionality when the WGM03:0 bits are set to the phase correct or the phase
and frequency correct, PWM mode.
Table 11-4.
COM0A1/
COM0B1
Compare Output in Phase Correct and Phase & Frequency Correct PWM Modes
COM0A0/
COM0B0
0
1 (1)
Note:
Description
1. A special case occurs when OCR0A/OCR0B equals TOP and COM0A1/COM0B1 is set. Phase Correct PWM
Mode on page 65 for more details.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
73
ported by the Timer/Counter unit are: Normal mode (counter), Clear Timer on Compare match (CTC) mode, and
three types of Pulse Width Modulation (PWM) modes. (Modes of Operation on page 61).
Table 11-5.
11.11.2
Mode
WGM0
3:0
Mode of Operation
TOP
Update of
OCR0x at
TOV0 Flag
Set on
0000
Normal
0xFFFF
Immediate
MAX
0001
0x00FF
TOP
BOTTOM
0010
0x01FF
TOP
BOTTOM
0011
0x03FF
TOP
BOTTOM
0100
OCR0A
Immediate
MAX
0101
0x00FF
TOP
TOP
0110
0x01FF
TOP
TOP
0111
0x03FF
TOP
TOP
1000
ICR0
BOTTOM
BOTTOM
1001
OCR0A
BOTTOM
BOTTOM
10
1010
ICR0
TOP
BOTTOM
11
1011
OCR0A
TOP
BOTTOM
12
1100
ICR0
Immediate
MAX
13
1101
(Reserved)
14
1110
Fast PWM
ICR0
TOP
TOP
15
1111
Fast PWM
OCR0A
TOP
TOP
ICNC0
ICES0
WGM03
WGM02
CS02
CS01
CS00
Read/Write
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Initial Value
0x2D
TCCR0B
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
74
When the ICR0 is used as TOP value (see description of the WGM03:0 bits located in the TCCR0A and the
TCCR0B Register), the ICP0 is disconnected and consequently the Input Capture function is disabled.
Bit 5 Reserved Bit
This bit is reserved for future use. For ensuring compatibility with future devices, this bit must be written to zero
when TCCR0B is written.
Bits 4:3 WGM03:2: Waveform Generation Mode
See TCCR0A Timer/Counter0 Control Register A on page 72.
Bits 2:0 CS02:0: Clock Select
The three Clock Select bits set the clock source to be used by the Timer/Counter, see Figure 11-12 and Figure 1113.
Table 11-6.
CS02
CS01
CS00
Description
If external pin modes are used for the Timer/Counter0, transitions on the T0 pin will clock the counter even if the
pin is configured as an output. This feature allows software control of the counting.
11.11.3
FOC0A
FOC0B
Read/Write
Initial Value
0x2C
0
TCCR0C
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
75
0x29
TCNT0[15:8]
0x28
TCNT0[7:0]
0
TCNT0H
TCNT0L
Read/Write
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Initial Value
The two Timer/Counter I/O locations (TCNT0H and TCNT0L, combined TCNT0) give direct access, both for read
and for write operations, to the Timer/Counter unit 16-bit counter. To ensure that both the high and low bytes are
read and written simultaneously when the CPU accesses these registers, the access is performed using an 8-bit
temporary high byte register (TEMP). This temporary register is shared by all the other 16-bit registers. See
Accessing 16-bit Registers on page 70.
Modifying the counter (TCNT0) while the counter is running introduces a risk of missing a compare match between
TCNT0 and one of the OCR0x Registers.
Writing to the TCNT0 Register blocks (removes) the compare match on the following timer clock for all compare
units.
11.11.5
11.11.6
0x27
OCR1A[15:8]
0x26
OCR1A[7:0]
0
OCR0AH
OCR0AL
Read/Write
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Initial Value
0x25
OCR0B[15:8]
0x24
OCR0B[7:0]
OCR0BH
OCR0BL
Read/Write
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Initial Value
The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value
(TCNT0). A match can be used to generate an Output Compare interrupt, or to generate a waveform output on the
OC0x pin.
The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary high byte register
(TEMP). This temporary register is shared by all the other 16-bit registers. See Accessing 16-bit Registers on
page 70.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
76
11.11.7
0x23
ICR0[15:8]
0x22
ICR0[7:0]
0
ICR0H
ICR0L
Read/Write
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Initial Value
The Input Capture is updated with the counter (TCNT0) value each time an event occurs on the ICP0 pin (or
optionally on the Analog Comparator output for Timer/Counter0). The Input Capture can be used for defining the
counter TOP value.
The Input Capture Register is 16-bit in size. To ensure that both the high and low bytes are read simultaneously
when the CPU accesses these registers, the access is performed using an 8-bit temporary high byte register
(TEMP). This temporary register is shared by all the other 16-bit registers. Accessing 16-bit Registers on page
70.
11.11.8
0x2B
ICIE0
OCIE0B
OCIE0A
TOIE0
Read/Write
R/W
R/W
R/W
R/W
Initial Value
TIMSK0
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
77
11.11.9
0x2A
ICF0
OCF0B
OCF0A
TOV0
Read/Write
R/W
R/W
R/W
R/W
Initial Value
TIFR0
0x2F
TSM
PSR
Read/Write
R/W
R/W
Initial Value
GTCCR
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
78
is halted and can be configured without the risk of advancing during configuration. When the TSM bit is written to
zero, the PSR bit is cleared by hardware, and the Timer/Counter start counting.
Bit 0 PSR: Prescaler 0 Reset Timer/Counter 0
When this bit is one, the Timer/Counter0 prescaler will be Reset. This bit is normally cleared immediately by hardware, except if the TSM bit is set.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
79
See Figure 1-1 on page 2 for pin use of analog comparator, and Table 10-4 on page 49 and Table 10-5 on page 50
for alternate pin usage.
12.1
12.1.1
Register Description
ACSR Analog Comparator Control and Status Register
Bit
0x1F
ACD
ACO
ACI
ACIE
ACIC
ACIS1
ACIS0
Read/Write
R/W
R/W
R/W
R/W
R/W
R/W
Initial Value
ACSR
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
80
ACIS1
ACIS0
Interrupt Mode
Reserved
When changing the ACIS1/ACIS0 bits, the analog comparator Interrupt must be disabled by clearing its Interrupt
Enable bit in ACSR Analog Comparator Control and Status Register. Otherwise an interrupt can occur when
the bits are changed.
12.1.2
0x17
ADC3D
ADC2D
ADC1D
ADC0D
Read/Write
R/W
R/W
R/W
R/W
Initial Value
DIDR0
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
81
Features
13.2
8-bit Resolution
0.5 LSB Integral Non-linearity
1 LSB Absolute Accuracy
65s Conversion Time
15 kSPS at Full Resolution
Four Multiplexed Single Ended Input Channels
Input Voltage Range: 0 VCC
Supply Voltage Range: 2.5V 5.5V
Free Running or Single Conversion Mode
ADC Start Conversion by Auto Triggering on Interrupt Sources
Interrupt on ADC Conversion Complete
Sleep Mode Noise Canceler
Overview
ATtiny5/10 feature an 8-bit, successive approximation ADC. The ADC is connected to a 4-channel analog multiplexer which allows four single-ended voltage inputs constructed from the pins of port B. The single-ended voltage
inputs refer to 0V (GND).
The ADC contains a Sample-and-Hold-circuit, which ensures that the input voltage to the ADC is held at a constant
level during conversion. A block diagram of the ADC is shown in Figure 13-1 on page 83.
Internal reference voltage of VCC is provided on-chip.
The ADC is not available in ATtiny4/9.
13.3
Operation
In order to be able to use the ADC the Power Reduction bit, PRADC, in the Power Reduction Register must be disabled. This is done by clearing the PRADC bit. See PRR Power Reduction Register on page 26 for more
details.
The ADC is enabled by setting the ADC Enable bit, ADEN in ADCSRA ADC Control and Status Register A.
Input channel selections will not go into effect until ADEN is set. The ADC does not consume power when ADEN is
cleared, so it is recommended to switch off the ADC before entering power saving sleep modes.
The ADC converts an analog input voltage to an 8-bit digital value using successive approximation. The minimum
value represents GND and the maximum value represents the voltage on VCC.
The analog input channel is selected by writing MUX1:0 bits. See ADMUX ADC Multiplexer Selection Register
on page 92. Any of the ADC input pins can be selected as single ended inputs to the ADC.
The ADC generates an 8-bit result which is presented in the ADC data register. See ADCL ADC Data Register
on page 94.
The ADC has its own interrupt request which can be triggered when a conversion completes.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
82
ADCSRB
ADCL
ADIE
ADEN
ADPS0
ADPS1
ADPS2
ADSC
ADATE
ADCSRA
ADTS2:0
ADC IRQ
TRIGGER
SELECT
PRESCALER
ADIF
CHANNEL
START
DECODER
ADC7:0
MUX1
MUX0
ADMUX
INTERRUPT FLAGS
CONVERSION LOGIC
VREF
VCC
8-BIT DAC
+
ADC3
ADC2
ADC1
INPUT
MUX
ADC0
13.4
Starting a Conversion
Make sure the ADC is powered by clearing the ADC Power Reduction bit, PRADC, in the Power Reduction Register, PRR (see PRR Power Reduction Register on page 26).
A single conversion is started by writing a logical one to the ADC Start Conversion bit, ADSC. This bit stays high as
long as the conversion is in progress and will be cleared by hardware when the conversion is completed. If a different data channel is selected while a conversion is in progress, the ADC will finish the current conversion before
performing the channel change.
Alternatively, a conversion can be triggered automatically by various sources. Auto Triggering is enabled by setting
the ADC Auto Trigger Enable bit, ADATE in ADCSRA. The trigger source is selected by setting the ADC Trigger
Select bits, ADTS in ADCSRB ADC Control and Status Register B. See Table 13-4 on page 93 for a list of the
trigger sources. When a positive edge occurs on the selected trigger signal, the ADC prescaler is reset and a conversion is started. This provides a method of starting conversions at fixed intervals. If the trigger signal still is set
when the conversion completes, a new conversion will not be started. If another positive edge occurs on the trigger
signal during conversion, the edge will be ignored. Note that an interrupt flag will be set even if the specific interrupt
is disabled. A conversion can thus be triggered without causing an interrupt. However, the interrupt flag must be
cleared in order to trigger a new conversion at the next interrupt event.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
83
PRESCALER
CLKADC
START
ADIF
ADATE
SOURCE 1
.
.
.
.
CONVERSION
LOGIC
EDGE
DETECTOR
SOURCE n
ADSC
Using the ADC interrupt flag as a trigger source makes the ADC start a new conversion as soon as the ongoing
conversion has finished. The ADC then operates in Free Running mode, constantly sampling and updating the
ADC data register. The first conversion must be started by writing a logical one to bit ADSC bit in ADCSRA. In this
mode the ADC will perform successive conversions independently of whether the ADC Interrupt Flag, ADIF is
cleared or not.
If Auto Triggering is enabled, single conversions can be started by writing ADSC in ADCSRA to one. ADSC can
also be used to determine if a conversion is in progress. The ADSC bit will be read as one during a conversion,
independently of how the conversion was started.
Reset
7-BIT ADC PRESCALER
CK/64
CK/128
CK/32
CK/8
CK/16
CK/4
CK
CK/2
13.5
ADPS0
ADPS1
ADPS2
The ADC module contains a prescaler, as illustrated in Figure 13-3 on page 84, which generates an acceptable
ADC clock frequency from any CPU frequency above 100 kHz. The prescaling is set by the ADPS bits in ADCSRA.
The prescaler starts counting from the moment the ADC is switched on by setting the ADEN bit in ADCSRA. The
prescaler keeps running for as long as the ADEN bit is set, and is continuously reset when ADEN is low.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
84
When initiating a single ended conversion by setting the ADSC bit in ADCSRA, the conversion starts at the following rising edge of the ADC clock cycle.
A normal conversion takes 13 ADC clock cycles, as summarised in Table 13-1 on page 86. The first conversion
after the ADC is switched on (ADEN in ADCSRA is set) takes 25 ADC clock cycles in order to initialize the analog
circuitry. See Figure 13-4.
Figure 13-4. ADC Timing Diagram, First Conversion (Single Conversion Mode)
Next
Conversion
First Conversion
Cycle Number
12
13
14
16
15
17
18
19
20
21
22
23
24
25
ADC Clock
ADEN
ADSC
ADIF
Conversion Result
ADCL
MUX
Update
Conversion MUX
Complete Update
The actual sample-and-hold takes place 3 ADC clock cycles after the start of a normal conversion and 16 ADC
clock cycles after the start of a first conversion. See Figure 13-5. When a conversion is complete, the result is written to the ADC Data Registers, and ADIF is set. In Single Conversion mode, ADSC is cleared simultaneously. The
software may then set ADSC again, and a new conversion will be initiated on the first rising ADC clock edge.
Figure 13-5. ADC Timing Diagram, Single Conversion
One Conversion
Cycle Number
Next Conversion
10
11
12
13
ADC Clock
ADSC
ADIF
ADCL
Conversion Result
MUX
Update
Conversion MUX
Complete Update
When Auto Triggering is used, the prescaler is reset when the trigger event occurs. See Figure 13-6. This assures
a fixed delay from the trigger event to the start of conversion. In this mode, the sample-and-hold takes place two
ADC clock cycles after the rising edge on the trigger source signal. Three additional CPU clock cycles are used for
synchronization logic.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
85
Cycle Number
Next Conversion
10
11
12
13
ADC Clock
Trigger
Source
ADATE
ADIF
ADCL
Conversion Result
Prescaler MUX
Reset Update
Conversion Prescaler
Reset
Complete
Sample &
Hold
In Free Running mode (see Figure 13-7), a new conversion will be started immediately after the conversion completes, while ADSC remains high.
Figure 13-7. ADC Timing Diagram, Free Running Conversion
One Conversion
Cycle Number
11
12
Next Conversion
13
ADC Clock
ADSC
ADIF
ADCL
Conversion Result
Conversion complete
MUX update
First conversion
16.5
25
Normal conversions
3.5
13
13.5
Condition
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
86
13.6
Changing Channel
The MUXn bits in the ADMUX Register are single buffered through a temporary register to which the CPU has random access. This ensures that the channel selection only takes place at a safe point during the conversion. The
channel is continuously updated until a conversion is started. Once the conversion starts, the channel selection is
locked to ensure a sufficient sampling time for the ADC. Continuous updating resumes in the last ADC clock cycle
before the conversion completes (ADIF in ADCSRA is set). Note that the conversion starts on the following rising
ADC clock edge after ADSC is written. The user is thus advised not to write new channel selection values to
ADMUX until one ADC clock cycle after ADSC is written.
If Auto Triggering is used, the exact time of the triggering event can be indeterministic. Special care must be taken
when updating the ADMUX Register, in order to control which conversion will be affected by the new settings.
If both ADATE and ADEN is written to one, an interrupt event can occur at any time. If the ADMUX Register is
changed in this period, the user cannot tell if the next conversion is based on the old or the new settings. ADMUX
can be safely updated in the following ways:
When ADATE or ADEN is cleared.
During conversion, minimum one ADC clock cycle after the trigger event.
After a conversion, before the Interrupt Flag used as trigger source is cleared.
When updating ADMUX in one of these conditions, the new settings will affect the next ADC conversion.
13.6.1
13.6.2
13.7
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
87
be generated when the ADC conversion completes. The CPU will remain in active mode until a new sleep
command is executed.
Note that the ADC will not be automatically turned off when entering other sleep modes than Idle mode and ADC
Noise Reduction mode. The user is advised to write zero to ADEN before entering such sleep modes to avoid
excessive power consumption.
13.8
IIH
ADCn
1..100 kohm
CS/H= 14 pF
IIL
VCC/2
The capacitor in Figure 13-8 depicts the total capacitance, including the sample/hold capacitor and any stray or
parasitic capacitance inside the device. The value given is worst case.
The ADC is optimized for analog signals with an output impedance of approximately 10 k, or less. With such
sources, the sampling time will be negligible. If a source with higher impedance is used, the sampling time will
depend on how long time the source needs to charge the S/H capacitor. This can vary widely. The user is recommended to only use low impedance sources with slowly varying signals, since this minimizes the required charge
transfer to the S/H capacitor.
Signal components higher than the Nyquist frequency (fADC/2) should not be present to avoid distortion from unpredictable signal convolution. The user is advised to remove high frequency components with a low-pass filter before
applying the signals as inputs to the ADC.
13.9
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
88
Where high ADC accuracy is required it is recommended to use ADC Noise Reduction Mode, as described in Section 13.7 on page 87. A good system design with properly placed, external bypass capacitors does reduce the
need for using ADC Noise Reduction Mode
Offset: The deviation of the first transition (0x00 to 0x01) compared to the ideal transition (at 0.5 LSB). Ideal
value: 0 LSB.
Figure 13-9. Offset Error
Output Code
Ideal ADC
Actual ADC
Offset
Error
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
89
Gain Error: After adjusting for offset, the Gain Error is found as the deviation of the last transition (0xFE to 0xFF)
compared to the ideal transition (at 1.5 LSB below maximum). Ideal value: 0 LSB
Figure 13-10. Gain Error
Gain
Error
Output Code
Ideal ADC
Actual ADC
Integral Non-linearity (INL): After adjusting for offset and gain error, the INL is the maximum deviation of an
actual transition compared to an ideal transition for any code. Ideal value: 0 LSB.
Figure 13-11. Integral Non-linearity (INL)
Output Code
INL
Ideal ADC
Actual ADC
VREF
Input Voltage
Differential Non-linearity (DNL): The maximum deviation of the actual code width (the interval between two
adjacent transitions) from the ideal code width (1 LSB). Ideal value: 0 LSB.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
90
Output Code
0xFF
1 LSB
DNL
0x00
0
VREF
Input Voltage
Quantization Error: Due to the quantization of the input voltage into a finite number of codes, a range of input
voltages (1 LSB wide) will code to the same value. Always 0.5 LSB.
Absolute Accuracy: The maximum deviation of an actual (unadjusted) transition compared to an ideal transition
for any code. This is the compound effect of offset, gain error, differential error, non-linearity, and quantization
error. Ideal value: 0.5 LSB.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
91
0x1B
MUX1
MUX0
Read/Write
R/W
R/W
Initial Value
ADMUX
MUX1
MUX0
Pin
ADC0
PB0
ADC1
PB1
ADC2
PB2
ADC3
PB3
If these bits are changed during a conversion, the change will not go in effect until the conversion is complete
(ADIF in ADCSRA is set)
13.12.2
ADEN
ADSC
ADATE
ADIF
ADIE
ADPS2
ADPS1
ADPS0
Read/Write
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Initial Value
0x1D
ADCSRA
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
92
13.12.3
ADPS2
ADPS1
ADPS0
Division Factor
16
32
64
128
0x1C
ADTS2
ADTS1
ADTS0
Read/Write
R/W
R/W
R/W
Initial Value
ADCSRB
ADTS2
ADTS1
ADTS0
Trigger Source
Analog Comparator
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
93
Table 13-4.
13.12.4
ADTS2
ADTS1
ADTS0
Trigger Source
Timer/Counter 0 Overflow
ADC7
ADC6
ADC5
ADC4
ADC3
ADC2
ADC1
ADC0
Read/Write
Initial Value
0x19
ADCL
When an ADC conversion is complete, the result is found in the ADC register.
Bits 7:0 ADC7:0: ADC Conversion Result
These bits represent the result from the conversion.
13.12.5
0x17
ADC3D
ADC2D
ADC1D
ADC0D
Read/Write
R/W
R/W
R/W
R/W
Initial Value
DIDR0
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
94
Features
Physical Layer:
Synchronous Data Transfer
Bi-directional, Half-duplex Receiver And Transmitter
Fixed Frame Format With One Start Bit, 8 Data Bits, One Parity Bit And 2 Stop Bits
Parity Error Detection, Frame Error Detection And Break Character Detection
Parity Generation And Collision Detection
Automatic Guard Time Insertion Between Data Reception And Transmission
Access Layer:
Communication Based On Messages
Automatic Exception Handling Mechanism
Compact Instruction Set
NVM Programming Access Control
Tiny Programming Interface Control And Status Space Access Control
Data Space Access Control
14.2
Overview
The Tiny Programming Interface (TPI) supports external programming of all Non-Volatile Memories (NVM). Memory programming is done via the NVM Controller, by executing NVM controller commands as described in Memory
Programming on page 106.
The Tiny Programming Interface (TPI) provides access to the programming facilities. The interface consists of two
layers: the access layer and the physical layer. The layers are illustrated in Figure 14-1.
Figure 14-1. The Tiny Programming Interface and Related Internal Interfaces
PHYSICAL
LAYER
ACCESS
LAYER
NVM
CONTROLLER
NON-VOLATILE
MEMORIES
DATA BUS
Programming is done via the physical interface. This is a 3-pin interface, which uses the RESET pin as enable, the
TPICLK pin as the clock input, and the TPIDATA pin as data input and output.
NVM can be programmed at 5V, only.
14.3
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
95
In addition, the VCC and GND pins must be connected between the external programmer and the device. See Figure 14-2.
Figure 14-2. Using an External Programmer for In-System Programming via TPI
+5V
ATtiny4/5/9/10
TPI
CONN
TPIDATA/PB0
PB3/RESET
GND
VCC
TPICLK/PB1
PB2
APPLICATION
NVM can be programmed at 5V, only. In some designs it may be necessary to protect components that can not tolerate 5V with, for example, series resistors.
14.3.1
Enabling
The following sequence enables the Tiny Programming Interface (see Figure 14-3 for guidance):
Apply 5V between VCC and GND
Depending on the method of reset to be used:
Either: wait tTOUT (see Table 16-4 on page 118) and then set the RESET pin low. This will reset the
device and enable the TPI physical layer. The RESET pin must then be kept low for the entire
programming session
Or: if the RSTDISBL configuration bit has been programmed, apply 12V to the RESET pin. The RESET
pin must be kept at 12V for the entire programming session
Wait tRST (see Table 16-4 on page 118)
Keep the TPIDATA pin high for 16 TPICLK cycles
RST
16 x TPICLK CYCLES
RESET
TPICLK
TPIDATA
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
96
14.3.2
Disabling
Provided that the NVM enable bit has been cleared, the TPI is automatically disabled if the RESET pin is released
to inactive high state or, alternatively, if VHV is no longer applied to the RESET pin.
If the NVM enable bit is not cleared a power down is required to exit TPI programming mode.
See NVMEN bit in TPISR Tiny Programming Interface Status Register on page 105.
14.3.3
Frame Format
The TPI physical layer supports a fixed frame format. A frame consists of one character, eight bits in length, and
one start bit, a parity bit and two stop bits. Data is transferred with the least significant bit first.
Figure 14-4. Serial frame format.
TPICLK
TPIDATA
IDLE
ST
D0
D1
D7
SP1
SP2
IDLE/ST
14.3.5
Supported Characters
The BREAK character is equal to a 12 bit long low level. It can be extended beyond a bit-length of 12.
Figure 14-5. Supported characters.
DATA CHARACTER
TPIDATA
IDLE
ST
D0
D1
D7
SP1
SP2
IDLE/ST
BREAK CHARACTER
TPIDATA
14.3.6
IDLE
IDLE/ST
Operation
The TPI physical layer operates synchronously on the TPICLK provided by the external programmer. The dependency between the clock edges and data sampling or data change is shown in Figure 14-6. Data is changed at
falling edges and sampled at rising edges.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
97
TPIDATA
SAMPLE
SETUP
The TPI physical layer supports two modes of operation: Transmit and Receive. By default, the layer is in Receive
mode, waiting for a start bit. The mode of operation is controlled by the access layer.
14.3.7
14.3.8
14.3.9
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
98
The collision detection is enabled in transmit mode, when the output driver has been disabled. The data line should
now be kept high by the internal pull-up and it is monitored to see, if it is driven low by the external programmer. If
the output is read low, a collision has been detected.
There are some potential pit-falls related to the way collision detection is performed. For example, collisions cannot
be detected when the TPI physical layer transmits a bit-stream of successive logical zeros, or bit-stream of alternating logical ones and zeros. This is because the output driver is active all the time, preventing polling of the
TPIDATA line. However, within a single frame the two stop bits should always be transmitted as logical ones,
enabling collision detection at least once per frame (as long as the frame format is not violated regarding the stop
bits).
The TPI physical layer will cease transmission when it detects a collision on the TPIDATA line. The collision is signalized to the TPI access layer, which immediately changes the physical layer to receive mode and goes to the
error state. The TPI access layer can be recovered from the error state only by sending a BREAK character.
14.3.10
Direction Change
In order to ensure correct timing of the half-duplex operation, a simple guard time mechanism has been added to
the physical layer. When the TPI physical layer changes from receive to transmit mode, a configurable number of
additional IDLE bits are inserted before the start bit is transmitted. The minimum transition time between receive
and transmit mode is two IDLE bits. The total IDLE time is the specified guard time plus two IDLE bits.
The guard time is configured by dedicated bits in the TPIPCR register. The default guard time value after the physical layer is initialized is 128 bits.
The external programmer looses control of the TPIDATA line when the TPI target changes from receive mode to
transmit. The guard time feature relaxes this critical phase of the communication. When the external programmer
changes from receive mode to transmit, a minimum of one IDLE bit should be inserted before the start bit is
transmitted.
14.4
14.4.1
Message format
Each message comprises an instruction followed by one or more byte operands. The instruction is always sent by
the external programmer. Depending on the instruction all the following operands are sent either by the external
programmer or by the TPI.
The messages can be categorized in two types based on the instruction, as follows:
Write messages. A write message is a request to write data. The write message is sent entirely by the external
programmer. This message type is used with the SSTCS, SST, STPR, SOUT and SKEY instructions.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
99
Read messages. A read message is a request to read data. The TPI reacts to the request by sending the byte
operands. This message type is used with the SLDCS, SLD and SIN instructions.
All the instructions except the SKEY instruction require the instruction to be followed by one byte operand. The
SKEY instruction requires 8 byte operands. For more information, see the TPI instruction set on page 100.
14.4.2
When the TPI physical layer is in transmit mode, the possible exceptions are:
The TPI physical layer detects a data collision.
All these exceptions are signalized to the TPI access layer. The access layer responds to an exception by aborting
any on-going operation and enters the error state. The access layer will stay in the error state until a BREAK character has been received, after which it is taken back to its default state. As a consequence, the external
programmer can always synchronize the protocol by simply transmitting two successive BREAK characters.
14.5
Instruction Set
The TPI has a compact instruction set that is used to access the TPI Control and Status Space (CSS) and the data
space. The instructions allow the external programmer to access the TPI, the NVM Controller and the NVM memories. All instructions except SKEY require one byte operand following the instruction. The SKEY instruction is
followed by 8 data bytes. All instructions are byte-sized.
The TPI instruction set is summarised in Table 14-1.
Table 14-1.
Mnemonic
Operand
Description
Operation
SLD
data, PR
data DS[PR]
SLD
data, PR+
data DS[PR]
PR PR+1
SST
PR, data
DS[PR] data
SST
PR+, data
DS[PR] data
PR PR+1
SSTPR
PR, a
PR[a] data
SIN
data, a
data I/O[a]
SOUT
a, data
I/O[a] data
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
100
Table 14-1.
14.5.1
Mnemonic
Operand
Description
Operation
SLDCS
data, a
data CSS[a]
SSTCS
a, data
CSS[a] data
SKEY
Key, {8{data}}
Serial KEY
Key {8{data}}
14.5.2
Operation
Opcode
Remarks
Register
data DS[PR]
0010 0000
PR PR
Unchanged
data DS[PR]
0010 0100
PR PR + 1
Post increment
14.5.3
Operation
Opcode
Remarks
Register
DS[PR] data
0110 0000
PR PR
Unchanged
DS[PR] data
0110 0100
PR PR + 1
Post increment
Operation
Opcode
Remarks
PR[a] data
0110 100a
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
101
14.5.4
14.5.5
Operation
Opcode
Remarks
data I/O[a]
0aa1 aaaa
14.5.6
Operation
Opcode
Remarks
I/O[a] data
1aa1 aaaa
SLDCS - Serial LoaD data from Control and Status space using direct addressing
The SLDCS instruction loads data byte from the TPI Control and Status Space to the TPI physical layer shift register for serial read-out. The SLDCS instruction uses direct addressing, the direct address consisting of the 4
address bits of the instruction, as shown in Table 14-7.
Table 14-7.
14.5.7
The Serial Load Data from Control and Status space (SLDCS) Instruction
Operation
Opcode
Remarks
data CSS[a]
1000 aaaa
SSTCS - Serial STore data to Control and Status space using direct addressing
The SSTCS instruction stores the data byte that is shifted into the TPI physical layer shift register to the TPI Control
and Status Space. The SSTCS instruction uses direct addressing, the direct address consisting of the 4 address
bits of the instruction, as shown in Table 14-8.
Table 14-8.
The Serial STore data to Control and Status space (SSTCS) Instruction
Operation
Opcode
Remarks
CSS[a] data
1100 aaaa
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
102
14.5.8
14.6
Operation
Opcode
Remarks
Key {8[data}}
1110 0000
Value
0x1289AB45CDD888FF
After the key has been given, the Non-Volatile Memory Enable (NVMEN) bit in the TPI Status Register (TPISR)
must be polled until the Non-Volatile memory has been enabled.
NVM programming is disabled by writing a logical zero to the NVMEN bit in TPISR.
14.7
Name
0x0F
TPIIR
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
0x0E
Reserved
0x02
TPIPCR
GT2
GT1
GT0
0x01
Reserved
0x00
TPISR
NVMEN
...
0x03
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
103
14.7.1
CSS: 0x0F
TPIIR
Read/Write
Initial Value
14.7.2
Code
Value
Interface Identification
0x80
CSS: 0x02
GT2
GT1
GT0
Read/Write
R/W
R/W
R/W
Initial Value
TPIPCR
GT1
GT0
+64
+32
+16
+8
+4
+2
+0
The default Guard Time is 128 IDLE bits. To speed up the communication, the Guard Time should be set to the
shortest safe value.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
104
14.7.3
CSS: 0x00
NVMEN
Read/Write
R/W
Initial Value
TPIPCR
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
105
Features
Two Embedded Non-Volatile Memories:
15.2
Overview
The Non-Volatile Memory (NVM) Controller manages all access to the Non-Volatile Memories. The NVM Controller
controls all NVM timing and access privileges, and holds the status of the NVM.
During normal execution the CPU will execute code from the code section of the Flash memory (program memory).
When entering sleep and no programming operations are active, the Flash memory is disabled to minimize power
consumption.
All NVM are mapped to the data memory. Application software can read the NVM from the mapped locations of
data memory using load instruction with indirect addressing.
The NVM has only one read port and, therefore, the next instruction and the data can not be read simultaneously.
When the application reads data from NVM locations mapped to the data space, the data is read first before the
next instruction is fetched. The CPU execution is here delayed by one system clock cycle.
Internal programming operations to NVM have been disabled and the NVM therefore appears to the application
software as read-only. Internal write or erase operations of the NVM will not be successful.
The method used by the external programmer for writing the Non-Volatile Memories is referred to as external programming. External programming can be done both in-system or in mass production. See Figure 14-2 on page 96.
The external programmer can read and program the NVM via the Tiny Programming Interface (TPI).
In the external programming mode all NVM can be read and programmed, except the signature and the calibration
sections which are read-only.
NVM can be programmed at 5V, only.
15.3
Non-Volatile Memories
The ATtiny4/5/9/10 have the following, embedded NVM:
Non-Volatile Memory Lock Bits
Flash memory with four separate sections
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
106
15.3.1
Lock Bit
Bit No
Description
Default Value
1 (unprogrammed)
1 (unprogrammed)
1 (unprogrammed)
1 (unprogrammed)
1 (unprogrammed)
1 (unprogrammed)
NVLB2
1 (unprogrammed)
NVLB1
1 (unprogrammed)
The Lock Bits can be left unprogrammed ("1") or can be programmed ("0") to obtain the additional security shown
in Table 15-2. Lock Bits can be erased to "1" with the Chip Erase command, only.
Table 15-2.
NVLB2 (2)
NVLB1 (2)
Notes:
Protection Type
1. Program the configuration section bits before programming NVLB1 and NVLB2.
2. "1" means unprogrammed, "0" means programmed
15.3.2
Flash Memory
The embedded Flash memory of ATtiny4/5/9/10 has four separate sections, as shown in Table 15-3 and Table 153.
Table 15-3.
Section
Code (program memory)
Configuration
Signature
(1)
Calibration
(1)
Size (Bytes)
Pages
WADDR
PADDR
1024
64
[3:1]
[9:4]
[3:1]
16
[3:1]
[4:4]
[3:1]
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
107
Notes:
Table 15-4.
Section
Size (Bytes)
Pages
WADDR
PADDR
512
32
[3:1]
[9:4]
[3:1]
16
[3:1]
[4:4]
[3:1]
(1)
Calibration (1)
Notes:
15.3.3
Configuration Section
ATtiny4/5/9/10 have one configuration byte, which resides in the configuration section. See Table 15-5.
Table 15-5.
Configuration bytes
Configuration word data
High byte
Low byte
0x00
Reserved
Configuration Byte 0
Reserved
Reserved
Table 15-6 briefly describes the functionality of all configuration bits and how they are mapped into the configuration byte.
Table 15-6.
Configuration Byte 0
Bit
Bit Name
Description
Default Value
7:3
Reserved
1 (unprogrammed)
CKOUT
1 (unprogrammed)
WDTON
1 (unprogrammed)
RSTDISBL
1 (unprogrammed)
Configuration bits are not affected by a chip erase but they can be cleared using the configuration section erase
command (see Erasing the Configuration Section on page 112). Note that configuration bits are locked if NonVolatile Lock Bit 1 (NVLB1) is programmed.
15.3.3.1
Latching of Configuration Bits
All configuration bits are latched either when the device is reset or when the device exits the external programming
mode. Changes to configuration bit values have no effect until the device leaves the external programming mode.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
108
15.3.4
Signature Section
The signature section is a dedicated memory area used for storing miscellaneous device information, such as the
device signature. Most of this memory section is reserved for internal use, as shown in Table 15-7.
Table 15-7.
Signature bytes
Signature word data
High byte
Low byte
0x00
Device ID 1
Manufacturer ID
0x01
Device ID 2
ATtiny4/5/9/10 have a three-byte signature code, which can be used to identify the device. The three bytes reside
in the signature section, as shown in Table 15-7. The signature data for ATtiny4/5/9/10 is given in Table 15-8.
Table 15-8.
Signature codes
Signature Bytes
Part
15.3.5
Manufacturer ID
Device ID 1
Device ID 2
ATtiny4
0x1E
0x8F
0x0A
ATtiny5
0x1E
0x8F
0x09
ATtiny9
0x1E
0x90
0x08
ATtiny10
0x1E
0x90
0x03
Calibration Section
ATtiny4/5/9/10 have one calibration byte. The calibration byte contains the calibration data for the internal oscillator
and resides in the calibration section, as shown in Table 15-9. During reset, the calibration byte is automatically
written into the OSCCAL register to ensure correct frequency of the calibrated internal oscillator.
Table 15-9.
Calibration byte
Calibration word data
High byte
Low byte
0x00
Reserved
Reserved
Reserved
15.3.5.1
Latching of Calibration Value
To ensure correct frequency of the calibrated internal oscillator the calibration value is automatically written into the
OSCCAL register during reset.
15.4
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
109
When the NVM Controller is busy performing an operation it will signal this via the NVM Busy Flag in the NVM Control and Status Register. See NVMCSR - Non-Volatile Memory Control and Status Register on page 114. The
NVM Command Register is blocked for write access as long as the busy flag is active. This is to ensure that the
current command is fully executed before a new command can start.
Programming any part of the NVM will automatically inhibit the following operations:
All programming to any other part of the NVM
All reading from any NVM location
ATtiny4/5/9/10 support only external programming. Internal programming operations to NVM have been disabled,
which means any internal attempt to write or erase NVM locations will fail.
15.4.1
PADDRMSB
WADDRMSB+1 WADDRMSB
PADDR
WADDR
0/1
ADDRESS POINTER
LOW/HIGH
BYTE SELECT
FLASH
SECTION
FLASH
PAGE
00
00
01
01
02
...
...
...
PAGE
PAGE ADDRESS
WITHIN A FLASH
SECTION
WORD
WORD ADDRESS
WITHIN A FLASH
PAGE
...
...
...
PAGEEND
SECTIONEND
15.4.2
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
110
15.4.3
15.4.3.1
Chip Erase
The Chip Erase command will erase the entire code section of the Flash memory and the NVM Lock Bits. For
security reasons, the NVM Lock Bits are not reset before the code section has been completely erased. Configuration, Signature and Calibration sections are not changed.
Before starting the Chip erase, the NVMCMD register must be loaded with the CHIP_ERASE command. To start
the erase operation a dummy byte must be written into the high byte of a word location that resides inside the Flash
code section. The NVMBSY bit remains set until erasing has been completed. While the Flash is being erased neither Flash buffer loading nor Flash reading can be performed.
The Chip Erase can be carried out as follows:
1. Write the CHIP_ERASE command to the NVMCMD register
2. Start the erase operation by writing a dummy byte to the high byte of any word location inside the code
section
3. Wait until the NVMBSY bit has been cleared
15.4.3.2
Erasing the Code Section
The algorithm for erasing all pages of the Flash code section is as follows:
1. Write the SECTION_ERASE command to the NVMCMD register
2. Start the erase operation by writing a dummy byte to the high byte of any word location inside the code
section
3. Wait until the NVMBSY bit has been cleared
15.4.3.3
Writing a Code Word
The algorithm for writing a word to the code section is as follows:
1. Write the WORD_WRITE command to the NVMCMD register
2. Write the low byte of the data into the low byte of a word location
3. Write the high byte of the data into the high byte of the same word location. This will start the Flash write
operation
4. Wait until the NVMBSY bit has been cleared
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
111
15.4.3.4
Erasing the Configuration Section
The algorithm for erasing the Configuration section is as follows:
1. Write the SECTION_ERASE command to the NVMCMD register
2. Start the erase operation by writing a dummy byte to the high byte of any word location inside the configuration section
3. Wait until the NVMBSY bit has been cleared
15.4.3.5
Writing a Configuration Word
The algorithm for writing a Configuration word is as follows.
1. Write the WORD_WRITE command to the NVMCMD register
2. Write the low byte of the data to the low byte of a configuration word location
3. Write the high byte of the data to the high byte of the same configuration word location. This will start the
Flash write operation.
4. Wait until the NVMBSY bit has been cleared
15.4.4
15.4.5
15.5
Self programming
The ATtiny4/5/9/10 don't support internal programming.
15.6
External Programming
The method for programming the Non-Volatile Memories by means of an external programmer is referred to as
external programming. External programming can be done both in-system or in mass production.
The Non-Volatile Memories can be externally programmed via the Tiny Programming Interface (TPI). For details
on the TPI, see Programming interface on page 95. Using the TPI, the external programmer can access the NVM
control and status registers mapped to I/O space and the NVM memory mapped to data memory space.
15.6.1
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
112
Refer to the Tiny Programming Interface description on page 95 for more detailed information of enabling the TPI
and programming the NVM.
15.6.2
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
113
15.7
15.7.1
Register Description
NVMBSY
Read/Write
R/W
Initial Value
0x32
0
NVMCSR
0x33
Read/Write
R/W
R/W
R/W
Initial Value
R/W
R/W
R/W
NVMCMD[5:0]
NVMCMD
Binary
Hex
Mnemonic
Description
0b000000
0x00
NO_OPERATION
No operation
0b010000
0x10
CHIP_ERASE
Chip erase
Section
0b010100
0x14
SECTION_ERASE
Section erase
Word
0b011101
0x1D
WORD_WRITE
Word write
General
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
114
*NOTICE:
16.2
DC Characteristics
Table 16-1.
Symbol
Parameter
Condition
Min.
VIL
Input High-voltage
Except RESET pin
Max.
Units
-0.5
0.2VCC
0.3VCC
0.7VCC(1)
0.6VCC(1)
VCC +0.5(2)
Input High-voltage
RESET pin
0.9VCC(1)
VCC +0.5(2)
VOL
0.6
0.5
VOH
Output High-voltage(4)
Except RESET pin(5)
ILIL
Input Leakage
Current I/O Pin
<0.05
ILIH
Input Leakage
Current I/O Pin
<0.05
RRST
30
60
RPU
20
50
IACLK
VCC = 5V
Vin = VCC/2
-50
50
nA
VIH
Typ.
4.3
2.5
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
115
Table 16-1.
Symbol
Condition
Power-down mode(7)
Notes:
Min.
Typ.
Max.
Units
0.2
0.5
mA
0.8
1.2
mA
2.7
mA
0.02
0.2
mA
0.13
0.5
mA
0.6
1.5
mA
4.5
10
0.15
1. Min means the lowest value where the pin is guaranteed to be read as high.
2. Max means the highest value where the pin is guaranteed to be read as low.
3. Although each I/O port can sink more than the test conditions (10 mA at VCC = 5V, 5 mA at VCC = 3V) under steady state
conditions (non-transient), the sum of all IOL (for all ports) should not exceed 60 mA. If IOL exceeds the test conditions, VOL
may exceed the related specification. Pins are not guaranteed to sink current greater than the listed test condition.
4. Although each I/O port can source more than the test conditions (10 mA at VCC = 5V, 5 mA at VCC = 3V) under steady state
conditions (non-transient), the sum of all IOH (for all ports) should not exceed 60 mA. If IOH exceeds the test condition, VOH
may exceed the related specification. Pins are not guaranteed to source current greater than the listed test condition.
5. The RESET pin must tolerate high voltages when entering and operating in programming modes and, as a consequence,
has a weak drive strength as compared to regular I/O pins. See Figure 17-25 on page 134, and Figure 17-26 on page 134.
6. Values are with external clock using methods described in Minimizing Power Consumption on page 24. Power Reduction
is enabled (PRR = 0xFF) and there is no I/O drive.
7. BOD Disabled.
16.3
Speed
The maximum operating frequency of the device depends on VCC . The relationship between supply voltage and
maximum operating frequency is piecewise linear, as shown in Figure 16-1.
Figure 16-1. Maximum Frequency vs. VCC
12 MHz
8 MHz
4 MHz
1.8V
2.7V
4.5V
5.5V
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
116
16.4
Clock Characteristics
16.4.1
Table 16-2.
Calibration
Method
Target Frequency
VCC
Temperature
Factory
Calibration
8.0 MHz
3V
25C
10%
User
Calibration
1%
Notes:
16.4.2
1. Accuracy of oscillator frequency at calibration point (fixed temperature and fixed voltage).
V IH1
V IL1
Table 16-3.
Symbol
Parameter
1/tCLCL
Clock Frequency
tCLCL
Clock Period
250
125
83
ns
tCHCX
High Time
100
50
33
ns
tCLCX
Low Time
100
50
33
ns
tCLCH
Rise Time
2.0
0.6
tCHCL
Fall Time
2.0
0.6
tCLCL
Min.
Max.
Min.
Max.
Min.
Max.
Units
12
MHz
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
117
16.5
Parameter
VRST
tRST
tTOUT
Note:
16.5.1
Min(1)
Typ(1)
0.2 VCC
VCC = 1.8V
VCC = 3V
VCC = 5V
Max(1)
Units
0.9VCC
2000
700
400
32
ns
64
128
ms
Power-On Reset
Table 16-5.
Symbol
VPOR
VPOA
SRON
Note:
(3)
Min(1)
Typ(1)
Max(1)
Units
1.1
1.4
1.6
0.6
1.3
1.6
0.01
V/ms
16.5.2
Parameter
Min
Typ (1)
Max
1.1
1.4
1.6
1.4
1.6
1.8
2.0
2.5
2.7
3.2
3.7
4.5
Units
5 (50)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
118
16.6
Table 16-7.
Symbol
Parameter
Condition
VAIO
ILAC
VCC = 2.7V
750
VCC = 4.0V
500
VCC = 2.7V
100
VCC = 4.0V
75
tAPD
tDPD
16.7
Min
Symbol
Units
< 10
40
mV
50
nA
-50
ns
CLK
Condition
Min
Typ
Resolution
Max
Units
Bits
1.0
LSB
1.0
LSB
1.0
LSB
Differential Non-linearity
(DNL)
0.5
LSB
Gain Error
1.0
LSB
Offset Error
1.0
LSB
Conversion Time
Absolute accuracy
(Including INL, DNL, and
Quantization, Gain and Offset
Errors)
Clock Frequency
RAIN
Max
Table 16-8.
VIN
Typ
Input Voltage
65
260
50
200
kHz
GND
VREF
Input Bandwidth
7.7
kHz
100
255
LSB
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
119
16.8
Transmit Mode
TPIDATA
tIVCH
tCHIX
tCLOV
TPICLK
tCLCH
tCHCL
tCLCL
Table 16-9.
Symbol
Parameter
1/tCLCL
Clock Frequency
Min
Typ
Max
Units
MHz
tCLCL
Clock Period
500
ns
tCLCH
200
ns
tCHCH
200
ns
tIVCH
50
ns
tCHIX
100
ns
tCLOV
200
ns
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
120
where VCC = operating voltage, CL = load capacitance and fSW = average switching frequency of I/O pin.
17.1
Additional Current Consumption for the different I/O modules (absolute values)
PRR bit
Typical numbers
VCC = 2V, f = 1MHz
6.6 uA
40.0 uA
153.0 uA
29.6 uA
88.3 uA
333.3 uA
PRTIM0
PRADC (1)
Note:
Table 17-2 below can be used for calculating typical current consumption for other supply voltages and frequencies
than those mentioned in the Table 17-1 above.
Table 17-2.
PRR bit
PRTIM0
2.3 %
10.4 %
PRADC (1)
6.7 %
28.8 %
Note:
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
121
0.7
5.5 V
0.6
5.0 V
0.5
4.5 V
ICC (mA)
4.0 V
0.4
3.3 V
0.3
2.7 V
0.2
1.8 V
0.1
0
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
Frequency (MHz)
5
4.5
5.5 V
4
5.0 V
3.5
4.5 V
ICC (mA)
17.2
2.5
4.0 V
2
1.5
3.3 V
2.7 V
0.5
1.8 V
0
0
10
12
Frequency (MHz)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
122
Figure 17-3. Active Supply Current vs. VCC (Internal Oscillator, 8 MHz)
ACTIVE SUPPLY CURRENT vs. VCC
INTERNAL OSCILLATOR, 8 MHz
3.5
-40 C
25 C
85 C
ICC (mA)
2.5
1.5
0.5
0
1.5
2.5
3.5
4.5
5.5
VCC (V)
Figure 17-4. Active Supply Current vs. VCC (Internal Oscillator, 1 MHz)
ACTIVE SUPPLY CURRENT vs. VCC
INTERNAL OSCILLATOR, 1 MHz
1
0.9
-40 C
25 C
85 C
0.8
0.7
ICC (mA)
0.6
0.5
0.4
0.3
0.2
0.1
0
1.5
2.5
3.5
4.5
5.5
VCC (V)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
123
Figure 17-5. Active Supply Current vs. VCC (Internal Oscillator, 128 kHz)
ACTIVE SUPPLY CURRENT vs. VCC
INTERNAL OSCILLATOR, 128 KHz
0.12
-40 C
25 C
85 C
0.1
ICC (mA)
0.08
0.06
0.04
0.02
0
1.5
2.5
3.5
4.5
5.5
VCC (V)
Figure 17-6. Active Supply Current vs. VCC (External Clock, 32 kHz)
ACTIVE SUPPLY CURRENT vs. VCC
INTERNAL OSCILLATOR, 32 KHz
0.04
-40 C
85 C
25 C
0.035
0.03
ICC (mA)
0.025
0.02
0.015
0.01
0.005
0
1.5
2.5
3.5
4.5
5.5
VCC (V)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
124
0,09
5.5 V
ICC (mA)
0,08
0,07
5.0 V
0,06
4.5 V
0,05
4.0 V
0,04
3.3 V
0,03
2.7 V
0,02
1.8 V
0,01
0
0,1
0,2
0,3
0,4
0,5
0,6
0,7
0,8
0,9
Frequency (MHz)
5.5 V
5.0 V
0,8
4.5 V
0,6
ICC (mA)
17.3
4.0 V
0,4
3.3 V
0,2
2.7 V
1.8 V
0
0
10
12
Frequency (MHz)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
125
Figure 17-9. Idle Supply Current vs. VCC (Internal Oscillator, 8 MHz)
IDLE SUPPLY CURRENT vs. VCC
INTERNAL RC OSCILLATOR, 8 MHz
0,7
85 C
25 C
-40 C
0,6
ICC (mA)
0,5
0,4
0,3
0,2
0,1
0
1,5
2,5
3,5
4,5
5,5
VCC (V)
Figure 17-10. Idle Supply Current vs. VCC (Internal Oscillator, 1 MHz)
IDLE SUPPLY CURRENT vs. VCC
INTERNAL RC OSCILLATOR, 1 MHz
0,7
0,6
ICC (mA)
0,5
0,4
0,3
85 C
25 C
-40 C
0,2
0,1
0
1,5
2,5
3,5
4,5
5,5
VCC (V)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
126
0.5
85 C
0.45
0.4
0.35
ICC (uA)
0.3
0.25
0.2
0.15
25 C
0.1
-40 C
0.05
0
1.5
2.5
3.5
4.5
5.5
VCC (V)
Figure 17-12. Power-down Supply Current vs. VCC (Watchdog Timer Enabled)
POWER-DOWN SUPPLY CURRENT vs. VCC
WATCHDOG TIMER ENABLED
9
-40 C
8
25 C
85 C
ICC (uA)
17.4
0
1,5
2,5
3,5
4,5
5,5
VCC (V)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
127
Pin Pull-up
Figure 17-13. I/O pin Pull-up Resistor Current vs. Input Voltage (VCC = 1.8V)
I/O PIN PULL-UP RESISTOR CURRENT vs. INPUT VOLTAGE
60
50
IOP (uA)
40
30
20
10
25 C
85 C
-40 C
0
0
0,2
0,4
0,6
0,8
1,2
1,4
1,6
1,8
VOP (V)
Figure 17-14. I/O Pin Pull-up Resistor Current vs. input Voltage (VCC = 2.7V)
I/O PIN PULL-UP RESISTOR CURRENT vs. INPUT VOLTAGE
80
70
60
50
IOP (uA)
17.5
40
30
20
10
25 C
85 C
-40 C
0
0
0,5
1,5
2,5
VOP (V)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
128
Figure 17-15. I/O pin Pull-up Resistor Current vs. Input Voltage (VCC = 5V)
I/O PIN PULL-UP RESISTOR CURRENT vs. INPUT VOLTAGE
160
140
120
IOP (uA)
100
80
60
40
20
25 C
85 C
-40 C
0
0
VOP (V)
Figure 17-16. Reset Pull-up Resistor Current vs. Reset Pin Voltage (VCC = 1.8V)
RESET PULL-UP RESISTOR CURRENT vs. RESET PIN VOLTAGE
40
35
30
IRESET (uA)
25
20
15
10
25 C
-40 C
85 C
0
0
0,2
0,4
0,6
0,8
1,2
1,4
1,6
1,8
VRESET (V)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
129
Figure 17-17. Reset Pull-up Resistor Current vs. Reset Pin Voltage (VCC = 2.7V)
RESET PULL-UP RESISTOR CURRENT vs. RESET PIN VOLTAGE
60
50
IRESET (uA)
40
30
20
10
25 C
-40 C
85 C
0
0
0,5
1 ,5
2,5
VRESET (V)
Figure 17-18. Reset Pull-up Resistor Current vs. Reset Pin Voltage (VCC = 5V)
RESET PULL-UP RESISTOR CURRENT vs. RESET PIN VOLTAGE
120
100
IRESET (uA)
80
60
40
20
25 C
-40 C
85 C
0
0
0,5
1,5
2,5
3,5
4,5
VRESET (V)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
130
0.8
0.7
85 C
0.6
VOL (V)
0.5
25 C
0.4
-40 C
0.3
0.2
0.1
0
0
0.5
1.5
2.5
3.5
4.5
IOL (mA)
Figure 17-20. I/O Pin Output Voltage vs. Sink Current (VCC = 3V)
I/O PIN OUTPUT VOLTAGE vs. SINK CURRENT
VCC = 3V
0.8
0.7
85 C
0.6
0.5
VOL (V)
17.6
25 C
-40 C
0.4
0.3
0.2
0.1
0
0
10
IOL (mA)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
131
Figure 17-21. I/O pin Output Voltage vs. Sink Current (VCC = 5V)
I/O PIN OUTPUT VOLTAGE vs. SINK CURRENT
VCC = 5V
85 C
0.8
-40 C
25 C
VOL (V)
0.6
0.4
0.2
0
0
10
12
14
16
18
20
IOL (mA)
Figure 17-22. I/O Pin Output Voltage vs. Source Current (VCC = 1.8V)
I/O PIN OUTPUT VOLTAGE vs. SOURCE CURRENT
VCC = 1.8V
2
1.8
1.6
VOH (V)
1.4
1.2
-40 C
25 C
0.8
85 C
0.6
0.4
0.2
0
0
0.5
1.5
2.5
3.5
4.5
IOH (mA)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
132
Figure 17-23. I/O Pin Output Voltage vs. Source Current (VCC = 3V)
I/O PIN OUTPUT VOLTAGE vs. SOURCE CURRENT
VCC = 3V
3.1
2.9
VOH (V)
2.7
2.5
-40 C
25 C
2.3
85 C
2.1
1.9
1.7
1.5
0
10
IOH (mA)
Figure 17-24. I/O Pin output Voltage vs. Source Current (VCC = 5V)
I/O PIN OUTPUT VOLTAGE vs. SOURCE CURRENT
VCC = 5V
5.2
VOH (V)
4.8
4.6
4.4
-40 C
25 C
4.2
85 C
4
0
10
12
14
16
18
20
IOH (mA)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
133
Figure 17-25. Reset Pin as I/O, Output Voltage vs. Sink Current
OUTPUT VOLTAGE vs. SINK CURRENT
RESET PIN AS I/O
1
3.0 V
1.8 V
0.9
0.8
0.7
5.0 V
VOL (V)
0.6
0.5
0.4
0.3
0.2
0.1
0
0
IOL (mA)
Figure 17-26. Reset Pin as I/O, Output Voltage vs. Source Current
OUTPUT VOLTAGE vs. SOURCE CURRENT
RESET PIN AS I/O
VOH (V)
3
5.0 V
3.0 V
1.8 V
0
0
0.2
0.4
0.6
0.8
1.2
1.4
1.6
1.8
IOH (mA)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
134
85 C
25 C
-40 C
Threshold (V)
2,5
1,5
0,5
0
1,5
2,5
3,5
4,5
5,5
VCC (V)
Figure 17-28. I/O Pin Input threshold Voltage vs. VCC (VIL, IO Pin Read as 0)
I/O PIN INPUT THRESHOLD VOLTAGE vs. VCC
VIL, IO PIN READ AS '0'
3
85 C
25 C
-40 C
2,5
Threshold (V)
17.7
1,5
0,5
0
1,5
2,5
3,5
4,5
5,5
VCC (V)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
135
0,9
0,8
0,7
0,6
-40 C
0,5
25 C
0,4
85 C
0,3
0,2
0,1
0
1,5
2,5
3,5
4,5
5,5
VCC (V)
Figure 17-30. Reset Pin as I/O, Input Threshold Voltage vs. VCC (VIH, I/O Pin Read as 1)
RESET PIN AS I/O THRESHOLD VOLTAGE vs. VCC
VIH, RESET READ AS '1'
3
-40 C
25 C
85 C
2,5
Threshold (V)
1,5
0,5
0
1,5
2,5
3,5
4,5
5,5
VCC (V)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
136
Figure 17-31. Reset Pin as I/O, Input Threshold Voltage vs. VCC (VIL, I/O pin Read as 0)
RESET PIN AS I/O THRESHOLD VOLTAGE vs. VCC
VIL, RESET READ AS '0'
2,5
85 C
25 C
-40 C
Threshold (V)
1,5
0,5
0
1,5
2,5
3,5
4,5
5,5
4,5
5,5
VCC (V)
Figure 17-32. Reset Input Hysteresis vs. VCC (Reset Pin Used as I/O)
RESET PIN AS I/O, INPUT HYSTERESIS vs. VCC
VIL, PIN READ AS "0"
1
0,9
0,8
0,7
-40 C
25 C
0,6
0,5
85 C
0,4
0,3
0,2
0,1
0
1,5
2,5
3,5
VCC (V)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
137
Figure 17-33. Reset Input Threshold Voltage vs. VCC (VIH, I/O Pin Read as 1)
RESET INPUT THRESHOLD VOLTAGE vs. VCC
VIH, IO PIN READ AS '1'
2,5
Threshold (V)
1,5
-40 C
25 C
1
85 C
0,5
0
1,5
2,5
3,5
4,5
5,5
VCC (V)
Figure 17-34. Reset Input Threshold Voltage vs. VCC (VIL, I/O pin Read as 0)
RESET INPUT THRESHOLD VOLTAGE vs. VCC
VIL, IO PIN READ AS '0'
2,5
85 C
25 C
-40 C
Threshold (V)
1,5
0,5
0
1,5
2,5
3,5
4,5
5,5
VCC (V)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
138
0,8
0,6
-40 C
0,4
25 C
85 C
0,2
0
1,5
2,5
3,5
4,5
5,5
VCC (V)
0.006
-40
0.004
Offset
17.8
25
0.002
85
0
0
VIN
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
139
110
109
108
Frequency (kHz)
107
-40 C
106
105
25 C
104
103
102
101
85 C
100
99
1.5
2.5
3.5
4.5
5.5
VCC (V)
110
109
108
107
Frequency (kHz)
17.9
106
105
104
1.8 V
103
2.7 V
102
3.3 V
101
4.0 V
5.5 V
100
-60
-40
-20
20
40
60
80
100
Temperature
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
140
8.4
-40 C
8.2
Frequency (MHz)
25 C
85 C
7.8
7.6
7.4
1.5
2.5
3.5
4.5
5.5
VCC (V)
8.3
8.2
Frequency (MHz)
8.1
7.9
5.0 V
7.8
3.0 V
7.7
1.8 V
7.6
-40
-20
20
40
60
80
100
Temperature
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
141
16
25 C
85 C
-40 C
14
Frequency (MHz)
12
10
8
6
4
2
0
0
16
32
48
64
80
96
1.42
1.41
Threshold (V)
1.4
1.39
1.38
1.37
1.36
1.35
1.34
-40
-20
20
40
60
80
100
Temperature (C)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
142
1.7
Threshold (V)
1.65
1.6
1.55
1.5
1.45
1.4
-40
-20
20
40
60
80
100
60
80
100
Temperature (C)
2.48
Threshold (V)
2.47
2.46
2.45
2.44
2.43
-40
-20
20
40
Temperature (C)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
143
3.9
Threshold (V)
3.8
3.7
3.6
3.5
3.4
-40
-20
20
40
60
80
100
Temperature (C)
700
600
ICC (uA)
500
400
300
200
100
0
1.5
2.5
3.5
4.5
5.5
VCC (V)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
144
120
ICC (uA)
100
25 C
80
60
40
20
0
1,5
2,5
3,5
4,5
5,5
VCC (V)
0.35
0.3
VLM2:0 = 001
VLM2:0 = 010
VLM2:0 = 011
0.25
ICC (mA)
VLM2:0 = 100
0.2
0.15
0.1
0.05
VLM2:0 = 000
1.5
2.5
3.5
4.5
5.5
VCC (V)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
145
350
-40 C
300
25 C
85 C
ICC (uA)
250
200
150
100
50
0
1.5
2.5
3.5
4.5
5.5
VCC (V)
-40 C
25 C
85 C
ICC (uA)
0
1,5
2,5
3,5
4,5
5,5
VCC (V)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
146
0,4
5.5 V
5.0 V
4.5 V
4.0 V
3.3 V
2.7 V
ICC (mA)
0,3
0,2
1.8 V
0,1
0
0
0,1
0,2
0,3
0,4
0,5
0,6
0,7
0,8
0,9
Frequency (MHz)
Note:
The default clock source for the device is always the internal 8 MHz oscillator. Hence, current consumption in reset
remains unaffected by external clock signals.
2500
Pulsewidth (ns)
2000
1500
1000
500
85 C
25 C
-40 C
0
1,5
2,5
3,5
4,5
5,5
VCC (V)
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
147
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Page
0x3F
SREG
Page 12
0x3E
SPH
Page 12
0x3D
SPL
Page 12
Note:
0x3C
CCP
0x3B
RSTFLR
0x3A
SMCR
0x39
OSCCAL
Page 11
WDRF
EXTRF
PORF
SM2
SM1
SM0
SE
Page 34
Page 25
Page 21
0x38
Reserved
0x37
CLKMSR
CLKMS1
CLKMS0
Page 21
0x36
CLKPSR
CLKPS3
CLKPS2
CLKPS1
CLKPS0
Page 22
0x35
PRR
PRADC
PRTIM0
Page 26
0x34
VLMCSR
VLMF
VLMIE
VLM2
VLM1
VLM0
Page 33
0x33
NVMCMD
0x32
NVMCSR
NVMBSY
Page 114
0x31
WDTCSR
WDIF
WDIE
WDP3
WDE
WDP2
WDP1
WDP0
Page 32
0x30
Reserved
NVM Comman
Page 114
0x2F
GTCCR
TSM
PSR
0x2E
TCCR0A
COM0A1
COM0A0
COM0B1
COM0B0
WGM01
WGM00
Page 78
Page 72
0x2D
TCCR0B
ICNC0
ICES0
WGM03
WGM02
CS02
CS01
CS00
Page 74
0x2C
TCCR0C
FOC0A
FOC0B
Page 75
0x2B
TIMSK0
ICIE0
OCIE0B
OCIE0A
TOIE0
Page 77
0x2A
TIFR0
ICF0
OCF0B
OCF0A
TOV0
0x29
TCNT0H
Page 78
Page 76
0x28
TCNT0L
Page 76
0x27
OCR0AH
Page 76
0x26
OCR0AL
Page 76
0x25
OCR0BH
Page 76
0x24
OCR0BL
Page 76
0x23
ICR0H
Page 77
0x22
ICR0L
Page 77
0x21
Reserved
0x20
Reserved
0x1F
ACSR
ACD
ACO
ACI
ACIE
ACIC
ACIS1
ACIS0
0x1E
Reserved
0x1D
ADCSRA
ADEN
ADSC
ADATE
ADIF
ADIE
ADPS2
ADPS1
ADPS0
Page 92
0x1C
ADCSRB
ADTS2
ADTS1
ADTS0
Page 93
0x1B
ADMUX
MUX1
MUX0
Page 92
0x1A
Reserved
Page 80
0x19
ADCL
0x18
Reserved
Page 94
0x17
DIDR0
ADC3D
ADC2D
ADC1D
ADC0D
0x16
Reserved
0x15
EICRA
ISC01
ISC00
0x14
EIFR
INTF0
Page 38
0x13
EIMSK
INT0
Page 38
0x12
PCICR
PCIE0
Page 39
0x11
PCIFR
PCIF0
Page 39
0x10
PCMSK
PCINT3
PCINT2
PCINT1
PCINT0
Page 39
0x0F
Reserved
0x0E
Reserved
0x0D
Reserved
0x0C
PORTCR
BBMB
0x0B
Reserved
0x0A
Reserved
0x09
Reserved
0x08
Reserved
0x07
Reserved
0x06
Reserved
0x05
Reserved
0x04
Reserved
0x03
PUEB
PUEB3
PUEB2
PUEB1
PUEB0
0x02
PORTB
PORTB3
PORTB2
PORTB1
PORTB0
Page 51
0x01
DDRB
DDRB3
DDRB2
DDRB1
DDRB0
Page 51
0x00
PINB
PINB3
PINB2
PINB1
PINB0
Page 51
Page 50
Page 50
1. For compatibility with future devices, reserved bits should be written to zero if accessed. Reserved I/O memory addresses
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
148
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
149
Operands
Description
Operation
Flags
#Clocks
Rd, Rr
Rd Rd + Rr
Z,C,N,V,S,H
ADC
Rd, Rr
Rd Rd + Rr + C
Z,C,N,V,S,H
SUB
Rd, Rr
Rd Rd - Rr
Z,C,N,V,S,H
SUBI
Rd, K
Subtract Immediate
Rd Rd - K
Z,C,N,V,S,H
SBC
Rd, Rr
Rd Rd - Rr - C
Z,C,N,V,S,H
SBCI
Rd, K
Rd Rd - K - C
Z,C,N,V,S,H
AND
Rd, Rr
Logical AND
Rd Rd Rr
Z,N,V,S
ANDI
Rd, K
Rd Rd K
Z,N,V,S
OR
Rd, Rr
Logical OR
Rd Rd v Rr
Z,N,V,S
ORI
Rd, K
Rd Rd v K
Z,N,V,S
EOR
Rd, Rr
Exclusive OR
Rd Rd Rr
Z,N,V,S
1
1
COM
Rd
Ones Complement
Rd $FF Rd
Z,C,N,V,S
NEG
Rd
Twos Complement
Rd $00 Rd
Z,C,N,V,S,H
SBR
Rd,K
Rd Rd v K
Z,N,V,S
1
1
CBR
Rd,K
Rd Rd ($FFh - K)
Z,N,V,S
INC
Rd
Increment
Rd Rd + 1
Z,N,V,S
DEC
Rd
Decrement
Rd Rd 1
Z,N,V,S
TST
Rd
Rd Rd Rd
Z,N,V,S
CLR
Rd
Clear Register
Rd Rd Rd
Z,N,V,S
SER
Rd
Set Register
Rd $FF
None
Relative Jump
PC PC + k + 1
None
PC(15:0) Z, PC(21:16) 0
None
BRANCH INSTRUCTIONS
RJMP
IJMP
PC PC + k + 1
None
3/4
ICALL
PC(15:0) Z, PC(21:16) 0
None
3/4
RET
Subroutine Return
PC STACK
None
4/5
RETI
Interrupt Return
PC STACK
if (Rd = Rr) PC PC + 2 or 3
None
RCALL
4/5
CPSE
Rd,Rr
1/2/3
CP
Rd,Rr
Compare
Rd Rr
Z, C,N,V,S,H
CPC
Rd,Rr
Rd Rr C
Z, C,N,V,S,H
CPI
Rd,K
Rd K
Z, C,N,V,S,H
SBRC
Rr, b
if (Rr(b)=0) PC PC + 2 or 3
None
1
1/2/3
SBRS
Rr, b
if (Rr(b)=1) PC PC + 2 or 3
None
1/2/3
SBIC
A, b
if (I/O(A,b)=0) PC PC + 2 or 3
None
1/2/3
SBIS
A, b
if (I/O(A,b)=1) PC PC + 2 or 3
None
1/2/3
BRBS
s, k
None
1/2
BRBC
s, k
None
1/2
BREQ
Branch if Equal
if (Z = 1) then PC PC + k + 1
None
1/2
BRNE
if (Z = 0) then PC PC + k + 1
None
1/2
BRCS
if (C = 1) then PC PC + k + 1
None
1/2
BRCC
if (C = 0) then PC PC + k + 1
None
1/2
BRSH
if (C = 0) then PC PC + k + 1
None
1/2
BRLO
Branch if Lower
if (C = 1) then PC PC + k + 1
None
1/2
BRMI
Branch if Minus
if (N = 1) then PC PC + k + 1
None
1/2
BRPL
Branch if Plus
if (N = 0) then PC PC + k + 1
None
1/2
BRGE
if (N V= 0) then PC PC + k + 1
None
1/2
BRLT
if (N V= 1) then PC PC + k + 1
None
1/2
BRHS
if (H = 1) then PC PC + k + 1
None
1/2
BRHC
if (H = 0) then PC PC + k + 1
None
1/2
BRTS
if (T = 1) then PC PC + k + 1
None
1/2
BRTC
if (T = 0) then PC PC + k + 1
None
1/2
BRVS
if (V = 1) then PC PC + k + 1
None
1/2
BRVC
if (V = 0) then PC PC + k + 1
None
1/2
BRIE
if ( I = 1) then PC PC + k + 1
None
1/2
BRID
if ( I = 0) then PC PC + k + 1
None
1/2
Rd
Z,C,N,V,H
LSR
Rd
Z,C,N,V
ROL
Rd
Rd(0)C,Rd(n+1) Rd(n),CRd(7)
Z,C,N,V,H
ROR
Rd
Rd(7)C,Rd(n) Rd(n+1),CRd(0)
Z,C,N,V
ASR
Rd
Z,C,N,V
SWAP
Rd
Swap Nibbles
Rd(3..0)Rd(7..4),Rd(7..4)Rd(3..0)
None
BSET
Flag Set
SREG(s) 1
SREG(s)
BCLR
Flag Clear
SREG(s) 0
SREG(s)
SBI
A, b
I/O(A, b) 1
None
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
150
Mnemonics
Operands
Description
Operation
Flags
#Clocks
CBI
A, b
I/O(A, b) 0
None
BST
Rr, b
T Rr(b)
BLD
Rd, b
Rd(b) T
None
1
1
SEC
Set Carry
C1
CLC
Clear Carry
C0
SEN
N1
CLN
N0
SEZ
Z1
CLZ
Z0
SEI
I1
CLI
I 0
1
1
SES
S1
CLS
S0
SEV
V1
CLV
V0
SET
Set T in SREG
T1
CLT
Clear T in SREG
T0
SEH
CLH
H1
H0
H
H
1
1
Rd, Rr
Copy Register
Rd Rr
None
LDI
Rd, K
Load Immediate
Rd K
None
1
1/2
LD
Rd, X
Load Indirect
Rd (X)
None
LD
Rd, X+
Rd (X), X X + 1
None
LD
Rd, - X
X X - 1, Rd (X)
None
2/3
1/2
LD
Rd, Y
Load Indirect
Rd (Y)
None
LD
Rd, Y+
Rd (Y), Y Y + 1
None
LD
Rd, - Y
Y Y - 1, Rd (Y)
None
2/3
1/2
LD
Rd, Z
Load Indirect
Rd (Z)
None
LD
Rd, Z+
Rd (Z), Z Z+1
None
LD
Rd, -Z
Z Z - 1, Rd (Z)
None
2/3
LDS
Rd, k
Rd k)
None
ST
X, Rr
Store Indirect
(X) Rr
None
ST
X+, Rr
(X) Rr, X X + 1
None
ST
- X, Rr
X X - 1, (X) Rr
None
ST
Y, Rr
Store Indirect
(Y) Rr
None
ST
Y+, Rr
(Y) Rr, Y Y + 1
None
ST
- Y, Rr
Y Y - 1, (Y) Rr
None
ST
Z, Rr
Store Indirect
(Z) Rr
None
ST
Z+, Rr
(Z) Rr, Z Z + 1
None
ST
-Z, Rr
Z Z - 1, (Z) Rr
None
STS
k, Rr
(k) Rr
None
IN
Rd, A
Rd I/O (A)
None
OUT
A, Rr
I/O (A) Rr
None
PUSH
Rr
STACK Rr
None
POP
Rd
Rd STACK
None
Break
None
NOP
No Operation
None
SLEEP
WDR
Sleep
Watchdog Reset
None
None
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
151
ATtiny4
Supply Voltage
Speed (1)
Temperature
Package (2)
Industrial
(-40C to 85C) (4)
6ST1
ATtiny4-TSHR(5)
12 MHz
8MA4
ATtiny4-MAHR (6)
6ST1
ATtiny4-TS8R (5)
1.8 5.5V
10 MHz
Notes:
Extended
(-40C to 125C) (6)
1. For speed vs. supply voltage, see section 16.3 Speed on page 116.
2. All packages are Pb-free, halide-free and fully green and they comply with the European directive for Restriction of Hazardous Substances (RoHS). NiPdAu finish.
3. Tape and reel.
4. Can also be supplied in wafer form. Contact your local Atmel sales office for ordering information and minimum quantities.
5. Top/bottomside markings:
Top: T4x, where x = die revision
Bottom: zHzzz or z8zzz, where H = (-40C to 85C), and 8 = (-40C to 125C)
6. For typical and Electrical characteristics for this device please consult Appendix A, ATtiny4/5/9/10 Specification at 125C.
Package Type
6ST1
8MA4
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
152
20.2
ATtiny5
Supply Voltage
Speed (1)
Temperature
Package (2)
Industrial
(-40C to 85C) (4)
6ST1
ATtiny5-TSHR (5)
12 MHz
8MA4
ATtiny5-MAHR (6)
6ST1
ATtiny5-TS8R (5)
1.8 5.5V
10 MHz
Notes:
Extended
(-40C to 125C) (6)
1. For speed vs. supply voltage, see section 16.3 Speed on page 116.
2. All packages are Pb-free, halide-free and fully green and they comply with the European directive for Restriction of Hazardous Substances (RoHS). NiPdAu finish.
3. Tape and reel.
4. Can also be supplied in wafer form. Contact your local Atmel sales office for ordering information and minimum quantities.
5. Top/bottomside markings:
Top: T5x, where x = die revision
Bottom: zHzzz or z8zzz, where H = (-40C to 85C), and 8 = (-40C to 125C)
6. For typical and Electrical characteristics for this device please consult Appendix A, ATtiny4/5/9/10 Specification at 125C.
Package Type
6ST1
8MA4
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
153
20.3
ATtiny9
Supply Voltage
Speed (1)
Temperature
Package (2)
Industrial
(-40C to 85C) (4)
6ST1
ATtiny9-TSHR (5)
12 MHz
8MA4
ATtiny9-MAHR (6)
6ST1
ATtiny9-TS8R (5)
1.8 5.5V
10 MHz
Notes:
Extended
(-40C to 125C) (6)
1. For speed vs. supply voltage, see section 16.3 Speed on page 116.
2. All packages are Pb-free, halide-free and fully green and they comply with the European directive for Restriction of Hazardous Substances (RoHS). NiPdAu finish.
3. Tape and reel.
4. Can also be supplied in wafer form. Contact your local Atmel sales office for ordering information and minimum quantities.
5. Top/bottomside markings:
Top: T9x, where x = die revision
Bottom: zHzzz or z8zzz, where H = (-40C to 85C), and 8 = (-40C to 125C)
6. For typical and Electrical characteristics for this device please consult Appendix A, ATtiny4/5/9/10 Specification at 125C.
Package Type
6ST1
8MA4
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
154
20.4
ATtiny10
Supply Voltage
Speed (1)
Temperature
Package (2)
Industrial
(-40C to 85C) (4)
6ST1
ATtiny10-TSHR (5)
12 MHz
8MA4
ATtiny10-MAHR (6)
6ST1
ATtiny10-TS8R (5)
1.8 5.5V
10 MHz
Notes:
Extended
(-40C to 125C) (6)
1. For speed vs. supply voltage, see section 16.3 Speed on page 116.
2. All packages are Pb-free, halide-free and fully green and they comply with the European directive for Restriction of Hazardous Substances (RoHS). NiPdAu finish.
3. Tape and reel.
4. Can also be supplied in wafer form. Contact your local Atmel sales office for ordering information and minimum quantities.
5. Top/bottomside markings:
Top: T10x, where x = die revision
Bottom: zHzzz or z8zzz, where H = (-40C to 85C), and 8 = (-40C to 125C)
6. For typical and Electrical characteristics for this device please consult Appendix A, ATtiny4/5/9/10 Specification at 125C.
Package Type
6ST1
8MA4
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
155
6ST1
D
5
E1
A2
Pin #1 ID
A1
0.10 C
SEATING PLANE
A
1
Side View
Top View
A2
0.10 C
SEATING PLANE
0.25
A1
View A-A
SEATING PLANE
SEE VIEW B
View B
COMMON DIMENSIONS
(Unit of Measure = mm)
SYMBOL MIN
MAX
NOM
1.45
A1
0.15
A2
0.90
1.30
2.80
2.90
3.00
2.60
2.80
3.00
E1
1.50
1.60
1.75
0.30
0.45
0.55
NOTE
0.95 BSC
0.30
0.50
0.09
0.20
6/30/08
TITLE
6ST1, 6-lead, 2.90 x 1.60 mm Plastic Small Outline
Package (SOT23)
GPC
TAQ
DRAWING NO.
REV.
6ST1
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
156
21.2
8MA4
8x
0.05 c
c
0.05 c
E
SIDE VIEW
Pin 1 ID
D
A1
TOP VIEW
D2
e
8
COMMON DIMENSIONS
(Unit of Measure = mm)
E2
SYMBOL
MIN
NOM
MAX
0.60
A1
0.00
0.05
0.20
0.30
1.95
2.00
2.05
D2
1.40
1.50
1.60
1.95
2.00
2.05
E2
C0.2
BOTTOM VIEW
0.80
0.90
1.00
0.50
0.20
0.30
0.40
0.20
NOTE
GPC
YAG
12/17/09
DRAWING NO. REV.
8MA4
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
157
22. Errata
The revision letters in this section refer to the revision of the corresponding ATtiny4/5/9/10 device.
22.1
ATtiny4
22.1.1
Rev. E
Programming Lock Bits
1. Programming Lock Bits
Programming Lock Bits to a lock mode equal or lower than the current causes one word of Flash to be corrupted. The location of the corruption is random.
Problem Fix / Workaround
When programming Lock Bits, make sure lock mode is not set to present, or lower levels.
22.1.2
Rev. D
ESD HBM (ESD STM 5.1) level 1000V
Programming Lock Bits
1. ESD HBM (ESD STM 5.1) level 1000V
The device meets ESD HBM (ESD STM 5.1) level 1000V.
Problem Fix / Workaround
Always use proper ESD protection measures (Class 1C) when handling integrated circuits before and during
assembly.
2. Programming Lock Bits
Programming Lock Bits to a lock mode equal or lower than the current causes one word of Flash to be corrupted. The location of the corruption is random.
Problem Fix / Workaround
When programming Lock Bits, make sure lock mode is not set to present, or lower levels.
22.1.3
Rev. A C
Not sampled.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
158
22.2
ATtiny5
22.2.1
Rev. E
Programming Lock Bits
1. Programming Lock Bits
Programming Lock Bits to a lock mode equal or lower than the current causes one word of Flash to be corrupted. The location of the corruption is random.
Problem Fix / Workaround
When programming Lock Bits, make sure lock mode is not set to present, or lower levels.
22.2.2
Rev. D
ESD HBM (ESD STM 5.1) level 1000V
Programming Lock Bits
1. ESD HBM (ESD STM 5.1) level 1000V
The device meets ESD HBM (ESD STM 5.1) level 1000V.
Problem Fix / Workaround
Always use proper ESD protection measures (Class 1C) when handling integrated circuits before and during
assembly.
2. Programming Lock Bits
Programming Lock Bits to a lock mode equal or lower than the current causes one word of Flash to be corrupted. The location of the corruption is random.
Problem Fix / Workaround
When programming Lock Bits, make sure lock mode is not set to present, or lower levels.
22.2.3
Rev. A C
Not sampled.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
159
22.3
ATtiny9
22.3.1
Rev. E
Programming Lock Bits
1. Programming Lock Bits
Programming Lock Bits to a lock mode equal or lower than the current causes one word of Flash to be corrupted. The location of the corruption is random.
Problem Fix / Workaround
When programming Lock Bits, make sure lock mode is not set to present, or lower levels.
22.3.2
Rev. D
ESD HBM (ESD STM 5.1) level 1000V
Programming Lock Bits
1. ESD HBM (ESD STM 5.1) level 1000V
The device meets ESD HBM (ESD STM 5.1) level 1000V.
Problem Fix / Workaround
Always use proper ESD protection measures (Class 1C) when handling integrated circuits before and during
assembly.
2. Programming Lock Bits
Programming Lock Bits to a lock mode equal or lower than the current causes one word of Flash to be corrupted. The location of the corruption is random.
Problem Fix / Workaround
When programming Lock Bits, make sure lock mode is not set to present, or lower levels.
22.3.3
Rev. A C
Not sampled.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
160
22.4
ATtiny10
22.4.1
Rev. E
Programming Lock Bits
1. Programming Lock Bits
Programming Lock Bits to a lock mode equal or lower than the current causes one word of Flash to be corrupted. The location of the corruption is random.
Problem Fix / Workaround
When programming Lock Bits, make sure lock mode is not set to present, or lower levels.
22.4.2
Rev. C D
ESD HBM (ESD STM 5.1) level 1000V
Programming Lock Bits
1. ESD HBM (ESD STM 5.1) level 1000V
The device meets ESD HBM (ESD STM 5.1) level 1000V.
Problem Fix / Workaround
Always use proper ESD protection measures (Class 1C) when handling integrated circuits before and during
assembly.
2. Programming Lock Bits
Programming Lock Bits to a lock mode equal or lower than the current causes one word of Flash to be corrupted. The location of the corruption is random.
Problem Fix / Workaround
When programming Lock Bits, make sure lock mode is not set to present, or lower levels.
22.4.3
Rev. A B
Not sampled.
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
161
23.2
23.3
23.4
23.5
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
162
23.6
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
163
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
164
Table of Contents
Features ..................................................................................................... 1
1
Overview ................................................................................................... 3
2.1
Resources .........................................................................................................5
3.2
3.3
3.4
4.2
4.3
4.4
4.5
4.6
4.7
4.8
Memories ................................................................................................. 14
5.1
5.2
5.3
6.2
6.3
6.4
Starting ............................................................................................................20
6.5
7.2
7.3
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
7.4
8.2
8.3
8.4
Interrupts ................................................................................................. 35
9.1
9.2
9.3
Overview ..........................................................................................................40
10.2
10.3
10.4
Features ..........................................................................................................52
11.2
Overview ..........................................................................................................52
11.3
11.4
11.5
11.6
11.7
11.8
11.9
11.10
11.11
Features ..........................................................................................................82
13.2
Overview ..........................................................................................................82
13.3
Operation .........................................................................................................82
13.4
13.5
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
13.6
13.7
13.8
13.9
13.10
13.11
13.12
Features ..........................................................................................................95
14.2
Overview ..........................................................................................................95
14.3
14.4
14.5
14.6
14.7
Features ........................................................................................................106
15.2
Overview ........................................................................................................106
15.3
15.4
15.5
15.6
15.7
16.2
DC Characteristics .........................................................................................115
16.3
Speed ............................................................................................................116
16.4
16.5
16.6
16.7
16.8
17.2
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
17.3
17.4
17.5
17.6
17.7
17.8
17.9
17.10
17.11
17.12
ATtiny4 ..........................................................................................................152
20.2
ATtiny5 ..........................................................................................................153
20.3
ATtiny9 ..........................................................................................................154
20.4
ATtiny10 ........................................................................................................155
6ST1 ..............................................................................................................156
21.2
8MA4 .............................................................................................................157
ATtiny4 ..........................................................................................................158
22.2
ATtiny5 ..........................................................................................................159
22.3
ATtiny9 ..........................................................................................................160
22.4
ATtiny10 ........................................................................................................161
23.2
23.3
23.4
23.5
23.6
ATtiny4/5/9/10 [DATASHEET]
8127FAVR02/2013
Atmel Corporation
1600 Technology Drive
Parkring 4
USA
Tokyo 141-0032
GERMANY
JAPAN
HONG KONG
www.atmel.com