Features * High Performance, Low Power AVR(R) 8-Bit Microcontroller * Advanced RISC Architecture * * * * * * * * - 120 Powerful Instructions - Most Single Clock Cycle Execution - 32 x 8 General Purpose Working Registers - Fully Static Operation Non-volatile Program and Data Memories - 2/4/8K Byte of In-System Programmable Program Memory Flash (ATtiny25/45/85) * Endurance: 10,000 Write/Erase Cycles - 128/256/512 Bytes In-System Programmable EEPROM (ATtiny25/45/85) * Endurance: 100,000 Write/Erase Cycles - 128/256/512 Bytes Internal SRAM (ATtiny25/45/85) - Programming Lock for Self-Programming Flash Program and EEPROM Data Security Peripheral Features - 8-bit Timer/Counter with Prescaler and Two PWM Channels - 8-bit High Speed Timer/Counter with Separate Prescaler * 2 High Frequency PWM Outputs with Separate Output Compare Registers * Programmable Dead Time Generator - Universal Serial Interface with Start Condition Detector - 10-bit ADC * 4 Single Ended Channels * 2 Differential ADC Channel Pairs with Programmable Gain (1x, 20x) - Programmable Watchdog Timer with Separate On-chip Oscillator - On-chip Analog Comparator Special Microcontroller Features - debugWIRE On-chip Debug System - In-System Programmable via SPI Port - External and Internal Interrupt Sources - Low Power Idle, ADC Noise Reduction, and Power-down Modes - Enhanced Power-on Reset Circuit - Programmable Brown-out Detection Circuit - Internal Calibrated Oscillator I/O and Packages - Six Programmable I/O Lines - 8-pin SOIC - 20-pin QFN Operating Voltage - 2.7 - 5.5V for ATtiny25/45/85 Speed Grade - ATtiny25/45/85: 0 - 8 MHz @ 2.7 - 5.5V, 0 - 16 MHz @ 4.5 - 5.5V Automotive Temperature Range - -40C to +125C Low Power Consumption - Active Mode: * 1 MHz, 2.7V: 300A - Power-down Mode: * 0.2A at 2.7V 8-bit Microcontroller with 2/4/8K Bytes In-System Programmable Flash ATtiny25 ATtiny45 ATtiny85 Automotive 7598H-AVR-07/09 1. Pin Configurations Figure 1-1. Pinout ATtiny25/45/85 SOIC (PCINT5/RESET/ADC0/dW) PB5 (PCINT3/XTAL1/OC1B/ADC3) PB3 (PCINT4/XTAL2/CLKO/OC1B/ADC2) PB4 GND 1 2 3 4 8 7 6 5 VCC PB2 (SCK/USCK/SCL/ADC1/T0/INT0/PCINT2) PB1 (MISO/DO/AIN1/OC0B/OC1A/PCINT1) PB0 (MOSI/DI/SDA/AIN0/OC0A/OC1A/AREF/PCINT0) 2. Overview The ATtiny25/45/85 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced RISC architecture. By executing powerful instructions in a single clock cycle, the ATtiny25/45/85 achieves throughputs approaching 1 MIPS per MHz allowing the system designer to optimize power consumption versus processing speed. 2 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 2.1 Block Diagram Figure 2-1. Block Diagram 8-BIT DATABUS CALIBRATED INTERNAL OSCILLATOR PROGRAM COUNTER STACK POINTER PROGRAM FLASH SRAM WATCHDOG TIMER TIMING AND CONTROL VCC MCU CONTROL REGISTER MCU STATUS REGISTER GND INSTRUCTION REGISTER INSTRUCTION DECODER CONTROL LINES GENERAL PURPOSE REGISTERS TIMER/ COUNTER0 X Y Z TIMER/ COUNTER1 ALU UNIVERSAL SERIAL INTERFACE STATUS REGISTER INTERRUPT UNIT PROGRAMMING LOGIC DATA EEPROM DATA REGISTER PORT B DATA DIR. REG.PORT B OSCILLATORS ADC / ANALOG COMPARATOR PORT B DRIVERS RESET PB0-PB5 The AVR core combines a rich instruction set with 32 general purpose working registers. All the 32 registers are directly connected to the Arithmetic Logic Unit (ALU), allowing two independent registers to be accessed in one single instruction executed in one clock cycle. The resulting architecture is more code efficient while achieving throughputs up to ten times faster than conventional CISC microcontrollers. 3 7598H-AVR-07/09 The ATtiny25/45/85 provides the following features: 2/4/8K byte of In-System Programmable Flash, 128/256/512 bytes EEPROM, 128/256/256 bytes SRAM, 6 general purpose I/O lines, 32 general purpose working registers, one 8-bit Timer/Counter with compare modes, one 8-bit high speed Timer/Counter, Universal Serial Interface, Internal and External Interrupts, a 4-channel, 10-bit ADC, a programmable Watchdog Timer with internal Oscillator, and three software selectable power saving modes. The Idle mode stops the CPU while allowing the SRAM, Timer/Counter, ADC, Analog Comparator, and Interrupt system to continue functioning. The Power-down mode saves the register contents, disabling all chip functions until the next Interrupt or Hardware Reset. The ADC Noise Reduction mode stops the CPU and all I/O modules except ADC, to minimize switching noise during ADC conversions. The device is manufactured using Atmel(R)'s high density non-volatile memory technology. The On-chip ISP Flash allows the Program memory to be re-programmed In-System through an SPI serial interface, by a conventional non-volatile memory programmer or by an On-chip boot code running on the AVR core. The ATtiny25/45/85 AVR is supported with a full suite of program and system development tools including: C Compilers, Macro Assemblers, Program Debugger/Simulators, In-Circuit Emulators, and Evaluation kits. 2.2 Automotive Quality Grade The ATtiny25/45/85 have been developed and manufactured according to the most stringent requirements of the international standard ISO-TS-16949. This data sheet contains limit values extracted from the results of extensive characterization (Temperature and Voltage). The quality and reliability of the ATtiny25/45/85 have been verified during regular product qualification as per AEC-Q100 grade 1. As indicated in the ordering information paragraph, the products are available in three different temperature grades, but with equivalent quality and reliability objectives. Different temperature identifiers have been defined as listed in Table 2-1. Table 2-1. Temperature 4 Temperature Grade Identification for Automotive Products Temperature Identifier Comments -40 ; +85 T Similar to Industrial Temperature Grade but with Automotive Quality -40 ; +105 T1 Reduced Automotive Temperature Range -40 ; +125 Z Full AutomotiveTemperature Range ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 2.3 2.3.1 Pin Descriptions VCC Supply voltage. 2.3.2 GND Ground. 2.3.3 Port B (PB5..PB0) Port B is a 6-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port B output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port B pins that are externally pulled low will source current if the pull-up resistors are activated. The Port B pins are tri-stated when a reset condition becomes active, even if the clock is not running. Port B also serves the functions of various special features of the ATtiny25/45/85 as listed on page 54. 2.3.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. The minimum pulse length is given in Table 8-1 on page 37. Shorter pulses are not guaranteed to generate a reset. 3. About 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. 4. AVR CPU Core 4.1 Introduction 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. 5 7598H-AVR-07/09 4.2 Architectural Overview Figure 4-1. Block Diagram of the AVR Architecture Data Bus 8-bit Flash Program Memory Program Counter Status and Control 32 x 8 General Purpose Registrers Control Lines Direct Addressing Instruction Decoder Indirect Addressing Instruction Register Interrupt Unit Watchdog Timer ALU Analog Comparator I/O Module1 Data SRAM I/O Module 2 I/O Module n EEPROM 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 32 x 8-bit general purpose working registers with a single clock cycle access time. This allows single-cycle Arithmetic Logic Unit (ALU) operation. In a typical ALU operation, two operands are output from the Register File, the operation is executed, and the result is stored back in the Register File - in one clock cycle. Six of the 32 registers can be used as three 16-bit indirect address register pointers for Data Space addressing - enabling efficient address calculations. One of the these address pointers can also be used as an address pointer for look up tables in Flash Program memory. These added function registers are the 16-bit X-, Y-, and Z-register, described later in this section. 6 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 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, able to directly address the whole address space. Most AVR instructions are 16-bits wide. There are also 32-bit instructions. During interrupts and subroutine calls, the return address Program Counter (PC) is stored on the Stack. The Stack is effectively allocated in the general data SRAM, and consequently the Stack size is only limited by the total SRAM size and the usage of the SRAM. All user programs must initialize the SP in the Reset routine (before subroutines or interrupts are executed). The Stack Pointer (SP) is read/write accessible in the I/O space. The data SRAM can easily be accessed through the five different addressing modes supported in the AVR architecture. 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 directly, or as the Data Space locations following those of the Register File, 0x20 - 0x5F. 4.3 ALU - Arithmetic Logic Unit The high-performance AVR ALU operates in direct connection with all the 32 general purpose working registers. Within a single clock cycle, arithmetic operations between general purpose registers or between a register and an immediate are executed. The ALU operations are divided into three main categories - arithmetic, logical, and bit-functions. Some implementations of the architecture also provide a powerful multiplier supporting both signed/unsigned multiplication and fractional format. See the "Instruction Set" section for a detailed description. 4.4 Status Register The Status Register contains information about the result of the most recently executed arithmetic instruction. This information can be used for altering program flow in order to perform conditional operations. Note that the Status Register is updated after all ALU operations, as specified in the Instruction Set Reference. This will in many cases remove the need for using the dedicated compare instructions, resulting in faster and more compact code. The Status Register is not automatically stored when entering an interrupt routine and restored when returning from an interrupt. This must be handled by software. The AVR Status Register - SREG - is defined as: Bit 7 6 5 4 3 2 1 0 I T H S V N Z C Read/Write R/W R/W R/W R/W R/W R/W R/W R/W Initial Value 0 0 0 0 0 0 0 0 SREG 7 7598H-AVR-07/09 * Bit 7 - I: Global Interrupt Enable The Global Interrupt Enable bit must be set for the interrupts to be enabled. The individual interrupt enable control is then performed in separate control registers. If the Global Interrupt Enable Register is cleared, none of the interrupts are enabled independent of the individual interrupt enable settings. The I-bit is cleared by hardware after an interrupt has occurred, and is set by the RETI instruction to enable subsequent interrupts. The I-bit can also be set and cleared by the application with the SEI and CLI instructions, as described in the instruction set reference. * Bit 6 - T: Bit Copy Storage The Bit Copy instructions BLD (Bit LoaD) and BST (Bit STore) use the T-bit as source or destination for the operated bit. A bit from a register in the Register File can be copied into T by the BST instruction, and a bit in T can be copied into a bit in a register in the Register File by the BLD instruction. * Bit 5 - H: Half Carry Flag The Half Carry Flag H indicates a Half Carry in some arithmetic operations. Half Carry is useful in BCD arithmetic. See the "Instruction Set Description" for detailed information. * Bit 4 - S: Sign Bit, S = N V The S-bit is always an exclusive or between the Negative Flag N and the Two's Complement Overflow Flag V. See the "Instruction Set Description" for detailed information. * Bit 3 - V: Two's Complement Overflow Flag The Two's Complement Overflow Flag V supports two's complement arithmetics. See the "Instruction Set Description" for detailed information. * Bit 2 - N: Negative Flag The Negative Flag N indicates a negative result in an arithmetic or logic operation. See the "Instruction Set Description" for detailed information. * Bit 1 - Z: Zero Flag The Zero Flag Z indicates a zero result in an arithmetic or logic operation. See the "Instruction Set Description" for detailed information. * Bit 0 - C: Carry Flag The Carry Flag C indicates a carry in an arithmetic or logic operation. See the "Instruction Set Description" for detailed information. 8 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 4.5 General Purpose Register File The Register File is optimized for the AVR Enhanced RISC instruction set. In order to achieve the required performance and flexibility, the following input/output schemes are supported by the Register File: * One 8-bit output operand and one 8-bit result input * Two 8-bit output operands and one 8-bit result input * Two 8-bit output operands and one 16-bit result input * One 16-bit output operand and one 16-bit result input Figure 4-2 shows the structure of the 32 general purpose working registers in the CPU. Figure 4-2. AVR CPU General Purpose Working Registers 7 0 Addr. R0 0x00 R1 0x01 R2 0x02 ... R13 0x0D General R14 0x0E Purpose R15 0x0F Working R16 0x10 Registers R17 0x11 ... R26 0x1A X-register Low Byte R27 0x1B X-register High Byte R28 0x1C Y-register Low Byte R29 0x1D Y-register High Byte R30 0x1E Z-register Low Byte R31 0x1F Z-register High Byte Most of the instructions operating on the Register File have direct access to all registers, and most of them are single cycle instructions. As shown in Figure 4-2, each register is also assigned a Data memory address, mapping them directly into the first 32 locations of the user Data Space. Although not being physically implemented as SRAM locations, this memory organization provides great flexibility in access of the registers, as the X-, Y- and Z-pointer registers can be set to index any register in the file. 9 7598H-AVR-07/09 4.5.1 The X-register, Y-register, and Z-register The registers R26..R31 have some added functions to their general purpose usage. These registers are 16-bit address pointers for indirect addressing of the data space. The three indirect address registers X, Y, and Z are defined as described in Figure 4-3. Figure 4-3. The X-, Y-, and Z-registers 15 X-register XH XL 7 0 R27 (0x1B) 15 Y-register 0 R26 (0x1A) YH YL 7 0 R29 (0x1D) Z-register 0 7 0 7 0 R28 (0x1C) 15 ZH 7 0 ZL 7 R31 (0x1F) 0 0 R30 (0x1E) In the different addressing modes these address registers have functions as fixed displacement, automatic increment, and automatic decrement (see the instruction set reference for details). 4.6 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 0x60. 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. Bit Read/Write Initial Value 10 15 14 13 12 11 10 9 8 SP15 SP14 SP13 SP12 SP11 SP10 SP9 SP8 SPH SP7 SP6 SP5 SP4 SP3 SP2 SP1 SP0 SPL 7 6 5 4 3 2 1 0 R/W R/W R/W R/W R/W R/W R/W R/W R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 1 0 0 1 1 1 1 1 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 4.7 Instruction Execution Timing This section describes the general access timing concepts for instruction execution. The AVR CPU is driven by the CPU clock clkCPU, directly generated from the selected clock source for the chip. No internal clock division is used. 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-4. The Parallel Instruction Fetches and Instruction Executions T1 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-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. Figure 4-5. Single Cycle ALU Operation T1 T2 T3 T4 clkCPU Total Execution Time Register Operands Fetch ALU Operation Execute Result Write Back 4.8 Reset and Interrupt Handling The AVR provides several different interrupt sources. These interrupts and the separate Reset Vector each have a separate Program Vector in the Program memory space. All interrupts are assigned individual enable bits which must be written logic one together with the Global Interrupt Enable bit in the Status Register in order to enable the interrupt. The lowest addresses in the Program memory space are by default defined as the Reset and Interrupt Vectors. The complete list of vectors is shown in "Interrupts" on page 45. The list also determines the priority levels of the different interrupts. The lower the address the higher is the priority level. RESET has the highest priority, and next is INT0 - the External Interrupt Request 0. 11 7598H-AVR-07/09 When an interrupt occurs, the Global Interrupt Enable I-bit is cleared and all interrupts are disabled. The user software can write logic one to the I-bit to enable nested interrupts. All enabled interrupts can then interrupt the current interrupt routine. The I-bit is automatically set when a Return from Interrupt instruction - RETI - is executed. There are basically two types of interrupts. The first type is triggered by an event that sets the Interrupt Flag. For these interrupts, the Program Counter is vectored to the actual Interrupt Vector in order to execute the interrupt handling routine, and hardware clears the corresponding Interrupt Flag. Interrupt Flags can also be cleared by writing a logic one to the flag bit position(s) to be cleared. If an interrupt condition occurs while the corresponding interrupt enable bit is cleared, the Interrupt Flag will be set and remembered until the interrupt is enabled, or the flag is cleared by software. Similarly, if one or more interrupt conditions occur while the Global Interrupt Enable bit is cleared, the corresponding Interrupt Flag(s) will be set and remembered until the Global Interrupt Enable bit is set, and will then be executed by order of priority. The second type of interrupts will trigger as long as the interrupt condition is present. These interrupts do not necessarily have Interrupt Flags. If the interrupt condition disappears before the interrupt is enabled, the interrupt will not be triggered. When the AVR exits from an interrupt, it will always return to the main program and execute one more instruction before any pending interrupt is served. Note that the Status Register is not automatically stored when entering an interrupt routine, nor restored when returning from an interrupt routine. This must be handled by software. When using the CLI instruction to disable interrupts, the interrupts will be immediately disabled. No interrupt will be executed after the CLI instruction, even if it occurs simultaneously with the CLI instruction. The following example shows how this can be used to avoid interrupts during the timed EEPROM write sequence.. Assembly Code Example in r16, SREG cli ; store SREG value ; disable interrupts during timed sequence sbi EECR, EEMWE ; start EEPROM write sbi EECR, EEWE out SREG, r16 ; restore SREG value (I-bit) C Code Example char cSREG; cSREG = SREG; /* store SREG value */ /* disable interrupts during timed sequence */ _CLI(); EECR |= (1<>EEPM0) /* Set up address and data registers */ EEARL = ucAddress; EEDR = ucData; /* Write logical one to EEMWE */ EECR |= (1< ... ; Enable interrupts xxx ... ... 10. I/O Ports 10.1 Introduction 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 (if configured as input). 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. Refer to "Electrical Characteristics" on page 150 for a complete list of parameters. 46 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 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 for I/O-Ports" on page 58. Three I/O memory address locations are allocated for each port, one each for the Data Register - PORTx, Data Direction Register - DDRx, and the Port Input Pins - PINx. The Port Input Pins I/O location is read only, while the Data Register and the Data Direction 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. In addition, the Pull-up Disable - PUD bit in MCUCR disables the pull-up function for all pins in all ports when set. Using the I/O port as General Digital I/O is described in "Ports as General Digital I/O" on page 47. 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 52. 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. 10.2 Ports as General Digital I/O The ports are bi-directional I/O ports with optional internal pull-ups. Figure 10-2 shows a functional description of one I/O-port pin, here generically called Pxn. 47 7598H-AVR-07/09 Figure 10-2. General Digital I/O(1) PUD Q D DDxn Q CLR WDx RESET DATA BUS RDx 1 Q Pxn D 0 PORTxn Q CLR RESET WRx WPx RRx SLEEP SYNCHRONIZER D Q L Q D RPx Q PINxn Q clk I/O PUD: SLEEP: clkI/O: Note: 10.2.1 PULLUP DISABLE SLEEP CONTROL I/O CLOCK WDx: RDx: WRx: RRx: RPx: WPx: WRITE DDRx READ DDRx WRITE PORTx READ PORTx REGISTER READ PORTx PIN WRITE PINx REGISTER 1. WRx, WPx, WDx, RRx, RPx, and RDx are common to all pins within the same port. clkI/O, SLEEP, and PUD are common to all ports. Configuring the Pin Each port pin consists of three register bits: DDxn, PORTxn, and PINxn. As shown in "Register Description for I/O-Ports" on page 58, the DDxn bits are accessed at the DDRx I/O address, the PORTxn bits at the PORTx I/O address, and the PINxn bits at the PINx I/O address. The DDxn bit in the DDRx Register selects the direction of this pin. If DDxn is written logic one, Pxn is configured as an output pin. If DDxn is written logic zero, Pxn is configured as an input pin. If PORTxn is written logic one when the pin is configured as an input pin, the pull-up resistor is activated. To switch the pull-up resistor off, PORTxn has to be written logic zero or the pin has to be configured as an output pin. The port pins are tri-stated when reset condition becomes active, even if no clocks are running. 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). 10.2.2 48 Toggling the Pin Writing a logic one to PINxn toggles the value of PORTxn, independent on the value of DDRxn. Note that the SBI instruction can be used to toggle one single bit in a port. ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 10.2.3 Switching Between Input and Output When switching between tri-state ({DDxn, PORTxn} = 0b00) and output high ({DDxn, PORTxn} = 0b11), an intermediate state with either pull-up enabled {DDxn, PORTxn} = 0b01) or output low ({DDxn, PORTxn} = 0b10) must occur. Normally, the pull-up enabled state is fully acceptable, as a high-impedant environment will not notice the difference between a strong high driver and a pull-up. If this is not the case, the PUD bit in the MCUCR Register can be set to disable all pull-ups in all ports. Switching between input with pull-up and output low generates the same problem. The user must use either the tri-state ({DDxn, PORTxn} = 0b00) or the output high state ({DDxn, PORTxn} = 0b10) as an intermediate step. Table 10-1 summarizes the control signals for the pin value. Table 10-1. 10.2.4 Port Pin Configurations DDxn PORTxn PUD (in MCUCR) I/O Pull-up 0 0 X Input No Tri-state (Hi-Z) 0 1 0 Input Yes Pxn will source current if ext. pulled low. 0 1 1 Input No Tri-state (Hi-Z) 1 0 X Output No Output Low (Sink) 1 1 X Output No Output High (Source) Comment Reading the Pin Value Independent of the setting of Data Direction bit DDxn, the port pin can be read through the PINxn Register bit. As shown in Figure 10-2, the PINxn Register bit and the preceding latch constitute a synchronizer. This is needed to avoid metastability if the physical pin changes value near the edge of the internal clock, but it also introduces a delay. Figure 10-3 shows a timing diagram of the synchronization when reading an externally applied pin value. The maximum and minimum propagation delays are denoted tpd,max and tpd,min respectively. Figure 10-3. Synchronization when Reading an Externally Applied Pin value SYSTEM CLK INSTRUCTIONS XXX XXX in r17, PINx SYNC LATCH PINxn r17 0x00 0xFF t pd, max t pd, min 49 7598H-AVR-07/09 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 1/2 and 11/2 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-4. 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. Figure 10-4. Synchronization when Reading a Software Assigned Pin Value SYSTEM CLK r16 INSTRUCTIONS 0xFF out PORTx, r16 nop in r17, PINx SYNC LATCH PINxn r17 0x00 0xFF t pd The following code example shows how to set port B pins 0 and 1 high, 2 and 3 low, and define the port pins from 4 to 5 as input with a pull-up assigned to port pin 4. 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. 50 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 Assembly Code Example(1) ... ; Define pull-ups and set outputs high ; Define directions for port pins ldi r16,(1< CSn2:0 > 1). 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. 78 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 13.2 External Clock Source An external clock source applied to the T0 pin can be used as Timer/Counter clock (clkT0). The T0 pin is sampled once every system clock cycle by the pin synchronization logic. The synchronized (sampled) signal is then passed through the edge detector. Figure 13-1 shows a functional equivalent block diagram of the T0 synchronization and edge detector logic. The registers are clocked at the positive edge of the internal system clock (clkI/O). The latch is transparent in the high period of the internal system clock. The edge detector generates one clkT0 pulse for each positive (CSn2:0 = 7) or negative (CSn2:0 = 6) edge it detects. Figure 13-1. T0 Pin Sampling Tn D Q D Q D Tn_sync (To Clock Select Logic) Q 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. 79 7598H-AVR-07/09 Figure 13-2. Prescaler for Timer/Counter0 clk I/O Clear PSR10 T0 Synchronization clkT0 Note: 13.2.1 1. The synchronization logic on the input pins (T0) is shown in Figure 13-1. General Timer/Counter Control Register - GTCCR Bit 7 6 5 4 3 2 1 0 TSM PWM1B COM1B1 COM1B0 FOC1B FOC1A PSR1 PSR0 Read/Write R/W R R R R R R R/W Initial Value 0 0 0 0 0 0 0 0 GTCCR * Bit 7 - TSM: Timer/Counter Synchronization Mode Writing the TSM bit to one activates the Timer/Counter Synchronization mode. In this mode, the value that is written to the PSR0 bit is kept, hence keeping the Prescaler Reset signal asserted. This ensures that the Timer/Counter is halted and can be configured without the risk of advancing during configuration. When the TSM bit is written to zero, the PSR0 bit is cleared by hardware, and the Timer/Counter start counting. * Bit 0 - PSR0: Prescaler Reset Timer/Counter0 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. 80 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 14. Counter and Compare Units Figure 14-1 shows the Timer/Counter1 prescaler that supports two clocking modes, a synchronous clocking mode and an asynchronous clocking mode. The synchronous clocking mode uses the system clock (CK) as the clock timebase and asynchronous mode uses the fast peripheral clock (PCK) as the clock time base. The PCKE bit from the PLLCSR register enables the asynchronous mode when it is set (`1'). Figure 14-1. Timer/Counter1 Prescaler PSR1 T1CK T1CK/16384 T1CK/8192 T1CK/4096 T1CK/2048 T1CK/1024 T1CK/512 T1CK/256 T1CK/128 T1CK/64 T1CK/32 T1CK/16 T1CK/8 0 T1CK/4 14-BIT T/C PRESCALER T1CK/2 CK S PCK 64/32 MHz A T1CK PCKE CS10 CS11 CS12 CS13 TIMER/COUNTER1 COUNT ENABLE In the asynchronous clocking mode the clock selections are from PCK to PCK/16384 and stop, and in the synchronous clocking mode the clock selections are from CK to CK/16384 and stop. The clock options are described in Table 14-2 on page 84 and the Timer/Counter1 Control Register, TCCR1. Setting the PSR1 bit in GTCCR register resets the prescaler. The PCKE bit in the PLLCSR register enables the asynchronous mode. The frequency of the fast peripheral clock is 64 MHz (or 32 MHz in Low Speed Mode). 14.1 Timer/Counter1 The Timer/Counter1 general operation is described in the asynchronous mode and the operation in the synchronous mode is mentioned only if there are differences between these two modes. Figure 14-2 shows Timer/Counter 1 synchronization register block diagram and synchronization delays in between registers. Note that all clock gating details are not shown in the figure. The Timer/Counter1 register values go through the internal synchronization registers, which cause the input synchronization delay, before affecting the counter operation. The registers TCCR1, GTCCR, OCR1A, OCR1B, and OCR1C can be read back right after writing the register. The read back values are delayed for the Timer/Counter1 (TCNT1) register and flags (OCF1A, OCF1B, and TOV1), because of the input and output synchronization. The Timer/Counter1 features a high resolution and a high accuracy usage with the lower prescaling opportunities. It can also support two accurate, high speed, 8-bit Pulse Width Modulators using clock speeds up to 64 MHz ( or 32 MHz in Low Speed Mode). In this mode, Timer/Counter1 and the output compare registers serve as dual stand-alone PWMs with non-overlapping non-inverted and inverted outputs. Refer to page 90 for a detailed description on this function. Similarly, the high prescaling opportunities make this unit useful for lower speed functions or exact timing functions with infrequent actions. 81 7598H-AVR-07/09 Figure 14-2. Timer/Counter 1 Synchronization Register Block Diagram. 8-BIT DATABUS IO-registers Input synchronization registers OCR1A OCR1A_SI OCR1B OCR1B_SI OCR1C OCR1C_SI TCCR1 TCCR1_SI GTCCR GTCCR_SI TCNT1 TCNT1_SI Timer/Counter1 Output synchronization registers TCNT1 TCNT_SO OCF1A OCF1A_SO TCNT1 OCF1B OCF1B_SO OCF1A OCF1A_SI OCF1B OCF1B_SI TOV1 TOV1_SI TOV1 TOV1_SO PCKE CK S A S PCK A SYNC MODE 1/2 CK Delay 1 CK Delay 1 CK Delay 1/2 CK Delay ASYNC MODE 1 - 2 PCK Delay 1 PCK Delay ~1 CK Delay No Delay Timer/Counter1 and the prescaler allow running the CPU from any clock source while the prescaler is operating on the fast 64 MHz (or 32 MHz in Low Speed Mode) PCK clock in the asynchronous mode. Note that the system clock frequency must be lower than one third of the PCK frequency. The synchronization mechanism of the asynchronous Timer/Counter1 needs at least two edges of the PCK when the system clock is high. If the frequency of the system clock is too high, it is a risk that data or control values are lost. The following Figure 14-3 shows the block diagram for Timer/Counter1. 82 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 Figure 14-3. Timer/Counter1 Block Diagram T/C1 OVER- T/C1 COMPARE T/C1 COMPARE FLOW IRQ MATCH A IRQ MATCH B IRQ OC1A (PB1) OC1B (PB4) OC1A (PB0) DEAD TIME GENERATOR PSR1 FOC1B FOC1A COM1B0 PWM1B GLOBAL T/C CONTROL REGISTER (GTCCR) COM1B1 CS10 CS11 CS12 CS13 COM1A0 COM1A1 CTC1 TOV1 T/C CONTROL REGISTER 1 (TCCR1) PWM1A TOV1 TOV0 OCF1B OCF1A OCF1A TIMER INT. FLAG REGISTER (TIFR) OCF1B TOIE1 TOIE0 OCIE1B OCIE1A DEAD TIME GENERATOR TIMER INT. MASK REGISTER (TIMSK) OC1B (PB3) TIMER/COUNTER1 TIMER/COUNTER1 (TCNT1) T/C CLEAR T/C1 CONTROL LOGIC 8-BIT COMPARATOR 8-BIT COMPARATOR 8-BIT COMPARATOR T/C1 OUTPUT COMPARE REGISTER (OCR1A) T/C1 OUTPUT COMPARE REGISTER (OCR1B) T/C1 OUTPUT COMPARE REGISTER (OCR1C) CK PCK 8-BIT DATABUS Three status flags (overflow and compare matches) are found in the Timer/Counter Interrupt Flag Register - TIFR. Control signals are found in the Timer/Counter Control Registers TCCR1 and GTCCR. The interrupt enable/disable settings are found in the Timer/Counter Interrupt Mask Register - TIMSK. The Timer/Counter1 contains three Output Compare Registers, OCR1A, OCR1B, and OCR1C as the data source to be compared with the Timer/Counter1 contents. In normal mode the Output Compare functions are operational with all three output compare registers. OCR1A determines action on the OC1A pin (PB1), and it can generate Timer1 OC1A interrupt in normal mode and in PWM mode. Likewise, OCR1B determines action on the OC1B pin (PB3) and it can generate Timer1 OC1B interrupt in normal mode and in PWM mode. OCR1C holds the Timer/Counter maximum value, i.e. the clear on compare match value. In the normal mode an overflow interrupt (TOV1) is generated when Timer/Counter1 counts from $FF to $00, while in the PWM mode the overflow interrupt is generated when Timer/Counter1 counts either from $FF to $00 or from OCR1C to $00. The inverted PWM outputs OC1A and OC1B are not connected in normal mode. In PWM mode, OCR1A and OCR1B provide the data values against which the Timer Counter value is compared. Upon compare match the PWM outputs (OC1A, OC1A, OC1B, OC1B) are generated. In PWM mode, the Timer Counter counts up to the value specified in the output compare register OCR1C and starts again from $00. This feature allows limiting the counter "full" value to a specified value, lower than $FF. Together with the many prescaler options, flexible PWM frequency selection is provided. Table 14-6 lists clock selection and OCR1C values to obtain PWM frequencies from 20 kHz to 250 kHz in 10 kHz steps and from 250 kHz to 500 kHz in 50 kHz steps. Higher PWM frequencies can be obtained at the expense of resolution. 83 7598H-AVR-07/09 14.1.1 Timer/Counter1 Control Register - TCCR1 Bit 7 6 5 4 3 2 1 0 $30 ($50) CTC1 PWM1A COM1A1 COM1A0 CS13 CS12 CS11 CS10 Read/Write R/W R/W R/W R/W R/W R/W R/W R/W Initial value 0 0 0 0 0 0 0 0 TCCR1 * Bit 7- CTC1 : Clear Timer/Counter on Compare Match When the CTC1 control bit is set (one), Timer/Counter1 is reset to $00 in the CPU clock cycle after a compare match with OCR1C register value. If the control bit is cleared, Timer/Counter1 continues counting and is unaffected by a compare match. * Bit 6- PWM1A: Pulse Width Modulator A Enable When set (one) this bit enables PWM mode based on comparator OCR1A in Timer/Counter1 and the counter value is reset to $00 in the CPU clock cycle after a compare match with OCR1C register value. * Bits 5,4 - COM1A1, COM1A0: Comparator A Output Mode, Bits 1 and 0 The COM1A1 and COM1A0 control bits determine any output pin action following a compare match with compare register A in Timer/Counter1. Output pin actions affect pin PB1 (OC1A). Since this is an alternative function to an I/O port, the corresponding direction control bit must be set (one) in order to control an output pin. Note that OC1A is not connected in normal mode. Table 14-1. Comparator A Mode Select COM1A1 COM1A0 Description 0 0 Timer/Counter Comparator A disconnected from output pin OC1A. 0 1 Toggle the OC1A output line. 1 0 Clear the OC1A output line. 1 1 Set the OC1A output line In PWM mode, these bits have different functions. Refer to Table 14-4 on page 90 for a detailed description. * Bits 3 .. 0 - CS13, CS12, CS11, CS10: Clock Select Bits 3, 2, 1, and 0 The Clock Select bits 3, 2, 1, and 0 define the prescaling source of Timer/Counter1. Table 14-2. 84 Timer/Counter1 Prescale Select Asynchronous Clocking Mode Synchronous Clocking Mode 0 T/C1 stopped T/C1 stopped 0 1 PCK CK 0 1 0 PCK/2 CK/2 0 0 1 1 PCK/4 CK/4 0 1 0 0 PCK/8 CK/8 0 1 0 1 PCK/16 CK/16 0 1 1 0 PCK/32 CK/32 CS13 CS12 CS11 CS10 0 0 0 0 0 0 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 Table 14-2. Timer/Counter1 Prescale Select (Continued) Asynchronous Clocking Mode Synchronous Clocking Mode 1 PCK/64 CK/64 0 0 PCK/128 CK/128 0 0 1 PCK/256 CK/256 1 0 1 0 PCK/512 CK/512 1 0 1 1 PCK/1024 CK/1024 1 1 0 0 PCK/2048 CK/2048 1 1 0 1 PCK/4096 CK/4096 1 1 1 0 PCK/8192 CK/8192 1 1 1 1 PCK/16384 CK/16384 CS13 CS12 CS11 CS10 0 1 1 1 0 1 The Stop condition provides a Timer Enable/Disable function. 14.1.2 General Timer/Counter1 Control Register - GTCCR Bit 7 6 5 4 3 2 1 0 $2C ($4C) TSM PWM1B COM1B1 COM1B0 FOC1B FOC1A PSR1 PSR0 Read/Write R/W R/W R/W R/W W W R/W R/W Initial value 0 0 0 0 0 0 0 0 GTCCR * Bit 6- PWM1B: Pulse Width Modulator B Enable When set (one) this bit enables PWM mode based on comparator OCR1B in Timer/Counter1 and the counter value is reset to $00 in the CPU clock cycle after a compare match with OCR1C register value. * Bits 5,4 - COM1B1, COM1B0: Comparator B Output Mode, Bits 1 and 0 The COM1B1 and COM1B0 control bits determine any output pin action following a compare match with compare register B in Timer/Counter1. Output pin actions affect pin PB3 (OC1B). Since this is an alternative function to an I/O port, the corresponding direction control bit must be set (one) in order to control an output pin. Note that OC1B is not connected in normal mode. Table 14-3. Comparator B Mode Select COM1B1 COM1B0 Description 0 0 Timer/Counter Comparator B disconnected from output pin OC1B. 0 1 Toggle the OC1B output line. 1 0 Clear the OC1B output line. 1 1 Set the OC1B output line In PWM mode, these bits have different functions. Refer to Table 14-4 on page 90 for a detailed description. 85 7598H-AVR-07/09 * Bit 3- FOC1B: Force Output Compare Match 1B Writing a logical one to this bit forces a change in the compare match output pin PB3 (OC1B) according to the values already set in COM1B1 and COM1B0. If COM1B1 and COM1B0 written in the same cycle as FOC1B, the new settings will be used. The Force Output Compare bit can be used to change the output pin value regardless of the timer value. The automatic action programmed in COM1B1 and COM1B0 takes place as if a compare match had occurred, but no interrupt is generated. The FOC1B bit always reads as zero. FOC1B is not in use if PWM1B bit is set. * Bit 2- FOC1A: Force Output Compare Match 1A Writing a logical one to this bit forces a change in the compare match output pin PB1 (OC1A) according to the values already set in COM1A1 and COM1A0. If COM1A1 and COM1A0 written in the same cycle as FOC1A, the new settings will be used. The Force Output Compare bit can be used to change the output pin value regardless of the timer value. The automatic action programmed in COM1A1 and COM1A0 takes place as if a compare match had occurred, but no interrupt is generated. The FOC1A bit always reads as zero. FOC1A is not in use if PWM1A bit is set. * Bit 1- PSR1 : Prescaler Reset Timer/Counter1 When this bit is set (one), the Timer/Counter prescaler (TCNT1 is unaffected) will be reset. The bit will be cleared by hardware after the operation is performed. Writing a zero to this bit will have no effect. This bit will always read as zero. 14.1.3 Timer/Counter1 - TCNT1 Bit 7 6 5 4 3 2 1 0 $2F ($4F) MSB LSB Read/Write R/W R/W R/W R/W R/W R/W R/W R/W Initial value 0 0 0 0 0 0 0 0 TCNT1 This 8-bit register contains the value of Timer/Counter1. Timer/Counter1 is realized as an up counter with read and write access. Due to synchronization of the CPU, Timer/Counter1 data written into Timer/Counter1 is delayed by one and half CPU clock cycles in synchronous mode and at most one CPU clock cycles for asynchronous mode. 14.1.4 Timer/Counter1 Output Compare RegisterA - OCR1A Bit 7 6 5 4 3 2 1 0 $2E ($4E) MSB LSB Read/Write R/W R/W R/W R/W R/W R/W R/W R/W Initial value 0 0 0 0 0 0 0 0 OCR1A The output compare register A is an 8-bit read/write register. The Timer/Counter Output Compare Register A contains data to be continuously compared with Timer/Counter1. Actions on compare matches are specified in TCCR1. A compare match does only occur if Timer/Counter1 counts to the OCR1A value. A software write that sets TCNT1 and OCR1A to the same value does not generate a compare match. A compare match will set the compare interrupt flag OCF1A after a synchronization delay following the compare event. 86 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 14.1.5 Timer/Counter1 Output Compare RegisterB - OCR1B Bit 7 6 5 4 3 2 1 0 $2D ($4D) MSB LSB Read/Write R/W R/W R/W R/W R/W R/W R/W R/W Initial value 0 0 0 0 0 0 0 0 OCR1B The output compare register B is an 8-bit read/write register. The Timer/Counter Output Compare Register B contains data to be continuously compared with Timer/Counter1. Actions on compare matches are specified in TCCR1. A compare match does only occur if Timer/Counter1 counts to the OCR1B value. A software write that sets TCNT1 and OCR1B to the same value does not generate a compare match. A compare match will set the compare interrupt flag OCF1B after a synchronization delay following the compare event. 14.1.6 Timer/Counter1 Output Compare RegisterC - OCR1C Bit 7 6 5 4 3 2 1 0 $2B ($4B) MSB LSB Read/Write R/W R/W R/W R/W R/W R/W R/W R/W Initial value 1 1 1 1 1 1 1 1 OCR1C The output compare register C is an 8-bit read/write register. The Timer/Counter Output Compare Register C contains data to be continuously compared with Timer/Counter1. A compare match does only occur if Timer/Counter1 counts to the OCR1C value. A software write that sets TCNT1 and OCR1C to the same value does not generate a compare match. If the CTC1 bit in TCCR1 is set, a compare match will clear TCNT1. This register has the same function in normal mode and PWM mode. 14.1.7 Timer/Counter Interrupt Mask Register - TIMSK Bit 7 6 5 4 3 2 1 $39 ($59) - OCIE1A OCIE1B OCIE0A OCIE0B TOIE1 TOIE0 0 - Read/Write R R/W R/W R/W R/W R/W R/W R Initial value 0 0 0 0 0 0 0 0 TIMSK * Bit 7 - Res: Reserved Bit This bit is a reserved bit in the ATtiny25/45/85 and always reads as zero. * Bit 6 - OCIE1A: Timer/Counter1 Output Compare Interrupt Enable When the OCIE1A bit is set (one) and the I-bit in the Status Register is set (one), the Timer/Counter1 Compare MatchA, interrupt is enabled. The corresponding interrupt at vector $003 is executed if a compare matchA occurs. The Compare Flag in Timer/Counter1 is set (one) in the Timer/Counter Interrupt Flag Register. * Bit 5 - OCIE1B: Timer/Counter1 Output Compare Interrupt Enable When the OCIE1B bit is set (one) and the I-bit in the Status Register is set (one), the Timer/Counter1 Compare MatchB, interrupt is enabled. The corresponding interrupt at vector $009 is executed if a compare matchB occurs. The Compare Flag in Timer/Counter1 is set (one) in the Timer/Counter Interrupt Flag Register. 87 7598H-AVR-07/09 * Bit 4- OCIE0A: Timer/Counter Output Compare Match A Interrupt Enable When the OCIE0A bit is written to one, and the I-bit in the Status Register is set, the Timer/Counter Compare Match A interrupt is enabled. The corresponding interrupt is executed if a Compare Match in Timer/Counter occurs, i.e., when the OCF0A bit is set in the Timer/Counter Interrupt Flag Register - TIFR0. * Bit 3 - OCIE0B: Timer/Counter Output Compare Match B Interrupt Enable When the OCIE0B bit is written to one, and the I-bit in the Status Register is set, the Timer/Counter Compare Match B interrupt is enabled. The corresponding interrupt is executed if a Compare Match in Timer/Counter occurs, i.e., when the OCF0B bit is set in the Timer/Counte Interrupt Flag Register - TIFR0. * Bit 2 - TOIE1: Timer/Counter1 Overflow Interrupt Enable When the TOIE1 bit is set (one) and the I-bit in the Status Register is set (one), the Timer/Counter1 Overflow interrupt is enabled. The corresponding interrupt (at vector $004) is executed if an overflow in Timer/Counter1 occurs. The Overflow Flag (Timer1) is set (one) in the Timer/Counter Interrupt Flag Register - TIFR. * Bit 0 - Res: Reserved Bit This bit is a reserved bit in the ATtiny25/45/85 and always reads as zero. 14.1.8 Timer/Counter Interrupt Flag Register - TIFR Bit 7 6 5 4 3 2 1 $38 ($58) - OCF1A OCF1B OCF0A OCF0B TOV1 TOV0 0 - Read/Write R R/W R/W R R R/W R/W R Initial value 0 0 0 0 0 0 0 0 TIFR * Bit 7 - Res: Reserved Bit This bit is a reserved bit in the ATtiny25/45/85 and always reads as zero. * Bit 6 - OCF1A: Output Compare Flag 1A The OCF1A bit is set (one) when compare match occurs between Timer/Counter1 and the data value in OCR1A - Output Compare Register 1A. OCF1A is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, OCF1A is cleared, after synchronization clock cycle, by writing a logic one to the flag. When the I-bit in SREG, OCIE1A, and OCF1A are set (one), the Timer/Counter1 A compare match interrupt is executed. * Bit 5 - OCF1B: Output Compare Flag 1B The OCF1B bit is set (one) when compare match occurs between Timer/Counter1 and the data value in OCR1B - Output Compare Register 1A. OCF1B is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, OCF1B is cleared, after synchronization clock cycle, by writing a logic one to the flag. When the I-bit in SREG, OCIE1B, and OCF1B are set (one), the Timer/Counter1 B compare match interrupt is executed. * Bit 2 - TOV1: Timer/Counter1 Overflow Flag In normal mode (PWM1A=0 and PWM1B=0) the bit TOV1 is set (one) when an overflow occurs in Timer/Counter1. The bit TOV1 is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, TOV1 is cleared, after synchronization clock cycle, by writing a logical one to the flag. 88 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 In PWM mode (either PWM1A=1 or PWM1B=1) the bit TOV1 is set (one) when compare match occurs between Timer/Counter1 and data value in OCR1C - Output Compare Register 1C. Clearing the Timer/Counter1 with the bit CTC1 does not generate an overflow. When the SREG I-bit, and TOIE1 (Timer/Counter1 Overflow Interrupt Enable), and TOV1 are set (one), the Timer/Counter1 Overflow interrupt is executed. * Bit 0 - Res: Reserved Bit This bit is a reserved bit in the ATtiny25/45/85 and always reads as zero. 14.1.9 PLL Control and Status Register - PLLCSR Bit 7 6 5 4 3 2 1 0 $27 ($27) LSM - - - - PCKE PLLE PLOCK Read/Write R/W R R R R R/W R/W R Initial value 0 0 0 0 0 0 0/1 0 PLLCSR * Bit 7- LSM: Low Speed Mode The high speed mode is enabled as default and the fast peripheral clock is 64 MHz, but the low speed mode can be set by writing the LSM bit to one. Then the fast peripheral clock is scaled down to 32 MHz. The low speed mode must be set, if the supply voltage is below 2.7 volts, because the Timer/Counter1 is not running fast enough on low voltage levels. It is highly recommended that Timer/Counter1 is stopped whenever the LSM bit is changed. * Bit 6.. 3- Res : Reserved Bits These bits are reserved bits in the ATtiny25/45/85 and always read as zero. * Bit 2- PCKE: PCK Enable The PCKE bit change the Timer/Counter1 clock source. When it is set, the asynchronous clock mode is enabled and fast 64 MHz (or 32 MHz in Low Speed Mode) PCK clock is used as Timer/Counter1 clock source. If this bit is cleared, the synchronous clock mode is enabled, and system clock CK is used as Timer/Counter1 clock source. This bit can be set only if PLLE bit is set. It is safe to set this bit only when the PLL is locked i.e the PLOCK bit is 1. The bit PCKE can only be set, if the PLL has been enabled earlier. * Bit 1- PLLE: PLL Enable When the PLLE is set, the PLL is started and if needed internal RC-oscillator is started as a PLL reference clock. If PLL is selected as a system clock source the value for this bit is always 1. * Bit 0- PLOCK: PLL Lock Detector When the PLOCK bit is set, the PLL is locked to the reference clock, and it is safe to enable PCK for Timer/Counter1. After the PLL is enabled, it takes about 100 micro seconds for the PLL to lock. 14.1.10 Timer/Counter1 Initialization for Asynchronous Mode To change Timer/Counter1 to the asynchronous mode, first enable PLL, wait 100 s before polling the PLOCK bit until it is set, and then set the PCKE bit. 89 7598H-AVR-07/09 14.1.11 Timer/Counter1 in PWM Mode When the PWM mode is selected, Timer/Counter1 and the Output Compare Register C OCR1C form a dual 8-bit, free-running and glitch-free PWM generator with outputs on the PB1(OC1A) and PB3(OC1B) pins and inverted outputs on pins PB0(OC1A) and PB2(OC1B). As default non-overlapping times for complementary output pairs are zero, but they can be inserted using a Dead Time Generator (see description on page 100). Figure 14-4. The PWM Output Pair PWM1x PWM1x t non-overlap =0 t non-overlap =0 x = A or B When the counter value match the contents of OCR1A or OCR1B, the OC1A and OC1B outputs are set or cleared according to the COM1A1/COM1A0 or COM1B1/COM1B0 bits in the Timer/Counter1 Control Register A - TCCR1, as shown in Table 14-4. Timer/Counter1 acts as an up-counter, counting from $00 up to the value specified in the output compare register OCR1C, and starting from $00 up again. A compare match with OC1C will set an overflow interrupt flag (TOV1) after a synchronization delay following the compare event. Table 14-4. Compare Mode Select in PWM Mode COM11 COM10 Effect on Output Compare Pins 0 0 OC1x not connected. OC1x not connected. 0 1 OC1x cleared on compare match. Set whenTCNT1 = $01. OC1x set on compare match. Cleared when TCNT1 = $00. 1 0 OC1x cleared on compare match. Set when TCNT1 = $01. OC1x not connected. 1 1 OC1x Set on compare match. Cleared when TCNT1= $01. OC1x not connected. Note that in PWM mode, writing to the Output Compare Registers OCR1A or OCR1B, the data value is first transferred to a temporary location. The value is latched into OCR1A or OCR1B when the Timer/Counter reaches OCR1C. This prevents the occurrence of odd-length PWM pulses (glitches) in the event of an unsynchronized OCR1A or OCR1B. See Figure 14-5 for an example. 90 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 Figure 14-5. Effects of Unsynchronized OCR Latching Compare Value changes Counter Value Compare Value PWM Output OC1x Synchronized OC1x Latch Compare Value changes Counter Value Compare Value PWM Output OC1x Glitch Unsynchronized OC1x Latch During the time between the write and the latch operation, a read from OCR1A or OCR1B will read the contents of the temporary location. This means that the most recently written value always will read out of OCR1A or OCR1B. When OCR1A or OCR1B contain $00 or the top value, as specified in OCR1C register, the output PB1(OC1A) or PB3(OC1B) is held low or high according to the settings of COM1A1/COM1A0. This is shown in Table 14-5. Table 14-5. PWM Outputs OCR1x = $00 or OCR1C, x = A or B COM1x1 COM1x0 OCR1x Output OC1x Output OC1x 0 1 $00 L H 0 1 OCR1C H L 1 0 $00 L Not connected. 1 0 OCR1C H Not connected. 1 1 $00 H Not connected. 1 1 OCR1C L Not connected. In PWM mode, the Timer Overflow Flag - TOV1 is set when the TCNT1 counts to the OCR1C value and the TCNT1 is reset to $00. The Timer Overflow Interrupt1 is executed when TOV1 is set provided that Timer Overflow Interrupt and global interrupts are enabled. This also applies to the Timer Output Compare flags and interrupts. The frequency of the PWM will be Timer Clock 1 Frequency divided by (OCR1C value + 1). See the following equation: f TCK1 f PWM = ----------------------------------( OCR1C + 1 ) 91 7598H-AVR-07/09 Resolution shows how many bit is required to express the value in the OCR1C register. It is calculated by following equation ResolutionPWM = log2(OCR1C + 1). Table 14-6. 92 Timer/Counter1 Clock Prescale Select in the Asynchronous Mode PWM Frequency Clock Selection CS13..CS10 OCR1C RESOLUTION 20 kHz PCK/16 0101 199 7.6 30 kHz PCK/16 0101 132 7.1 40 kHz PCK/8 0100 199 7.6 50 kHz PCK/8 0100 159 7.3 60 kHz PCK/8 0100 132 7.1 70 kHz PCK/4 0011 228 7.8 80 kHz PCK/4 0011 199 7.6 90 kHz PCK/4 0011 177 7.5 100 kHz PCK/4 0011 159 7.3 110 kHz PCK/4 0011 144 7.2 120 kHz PCK/4 0011 132 7.1 130 kHz PCK/2 0010 245 7.9 140 kHz PCK/2 0010 228 7.8 150 kHz PCK/2 0010 212 7.7 160 kHz PCK/2 0010 199 7.6 170 kHz PCK/2 0010 187 7.6 180 kHz PCK/2 0010 177 7.5 190 kHz PCK/2 0010 167 7.4 200 kHz PCK/2 0010 159 7.3 250 kHz PCK 0001 255 8.0 300 kHz PCK 0001 212 7.7 350 kHz PCK 0001 182 7.5 400 kHz PCK 0001 159 7.3 450 kHz PCK 0001 141 7.1 500 kHz PCK 0001 127 7.0 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 15. Dead Time Generator The Dead Time Generator is provided for the Timer/Counter1 PWM output pairs to allow driving external power control switches safely. The Dead Time Generator is a separate block that can be connected to Timer/Counter1 and it is used to insert dead times (non-overlapping times) for the Timer/Counter1 complementary output pairs (OC1A-OC1A and OC1B-OC1B). The sharing of tasks is as follows: the timer/counter generates the PWM output and the Dead Time Generator generates the non-overlapping PWM output pair from the timer/counter PWM signal. Two Dead Time Generators are provided, one for each PWM output. The non-overlap time is adjustable and the PWM output and it's complementary output are adjusted separately, and independently for both PWM outputs. Figure 15-1. Timer/Counter1 & Dead Time Generators PCKE TIMER/COUNTER1 T15M CK PWM GENERATOR PWM1A PWM1B PCK DT1AH DT1BH DEAD TIME GENERATOR DEAD TIME GENERATOR DT1AL DT1BL OC1A OC1B OC1A OC1B The dead time generation is based on the 4-bit down counters that count the dead time, as shown in Figure 46. There is a dedicated prescaler in front of the Dead Time Generator that can divide the Timer/Counter1 clock (PCK or CK) by 1, 2, 4 or 8. This provides for large range of dead times that can be generated. The prescaler is controlled by two control bits DTPS11..10 from the I/O register at address 0x23. The block has also a rising and falling edge detector that is used to start the dead time counting period. Depending on the edge, one of the transitions on the rising edges, OC1x or OC1x is delayed until the counter has counted to zero. The comparator is used to compare the counter with zero and stop the dead time insertion when zero has been reached. The counter is loaded with a 4-bit DT1xH or DT1xL value from DT1x I/O register, depending on the edge of the PWM generator output when the dead time insertion is started. Figure 15-2. Dead Time Generator T/C1 CLOCK DTPS11..10 COMPARATOR OC1x DEAD TIME PRESCALER CLOCK CONTROL 4-BIT COUNTER DT1xL DT1xH OC1x DT1x I/O REGISTER PWM1x 93 7598H-AVR-07/09 The length of the counting period is user adjustable by selecting the dead time prescaler setting in 0x23 register, and selecting then the dead time value in I/O register DT1x. The DT1x register consists of two 4-bit fields, DT1xH and DT1xL that control the dead time periods of the PWM output and its' complementary output separately. Thus the rising edge of OC1x and OC1x can have different dead time periods. The dead time is adjusted as the number of prescaled dead time generator clock cycles. Figure 15-3. The Complementary Output Pair PWM1x OC1x OC1x x = A or B t non-overlap / rising edge 15.1 t non-overlap / falling edge Timer/Counter1 Dead Time Prescaler register 1 - DTPS1 Bit 7 6 5 4 3 2 $23 ($43) 1 0 DTPS11 DTPS10 Read/Write R R R R R R R/W R/W Initial value 0 0 0 0 0 0 0 0 DTPS1 The dead time prescaler register, DTPS1 is a 2-bit read/write register. Bits 1 - 0 - DTPS1: Timer/Counter1 Dead Time Prescaler register 1 The dedicated Dead Time prescaler in front of the Dead Time Generator can divide the Timer/Counter1 clock (PCK or CK) by 1, 2, 4 or 8 providing a large range of dead times that can be generated. The Dead Time prescaler is controlled by two bits DTPS11..10 from the Dead Time Prescaler register. These bits define the division factor of the Dead Time prescaler. The division factors are given in table 46.. Table 15-1. 94 Division factors of the Dead Time prescaler DTPS11 DTPS10 Prescaler divides the T/C1 clock by 0 0 1x (no division) 0 1 2x 1 0 4x 1 1 8x ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 15.2 Timer/Counter1 Dead Time A - DT1A Bit 7 6 5 4 3 2 1 0 DT1AH3 DT1AH2 DT1AH1 DT1AH0 DT1AL3 DT1AL2 DT1AL1 DT1AL0 Read/Write R/W R/W R/W R/W R/W R/W R/W R/W Initial value 0 0 0 0 0 0 0 0 $25 ($45) DT1A The dead time value register A is an 8-bit read/write register. The dead time delay of is adjusted by the dead time value register, DT1A. The register consists of two fields, DT1AH3..0 and DT1AL3..0, one for each complementary output. Therefore a different dead time delay can be adjusted for the rising edge of OC1A and the rising edge of OC1A. * Bits 7..4- DT1AH3..DT1AH0: Dead Time Value for OC1A Output The dead time value for the OC1A output. The dead time delay is set as a number of the prescaled timer/counter clocks. The minimum dead time is zero and the maximum dead time is the prescaled time/counter clock period multiplied by 15. * Bits 3..0- DT1AL3..DT1AL0: Dead Time Value for OC1A Output The dead time value for the OC1A output. The dead time delay is set as a number of the prescaled timer/counter clocks. The minimum dead time is zero and the maximum dead time is the prescaled time/counter clock period multiplied by 15. 15.3 Timer/Counter1 Dead Time B - DT1B Bit 7 6 5 4 3 2 1 0 DT1BH3 DT1BH2 DT1BH1 DT1BH0 DT1BL3 DT1BL2 DT1BL1 DT1BL0 Read/Write R/W R/W R/W R/W R/W R/W R/W R/W Initial value 0 0 0 0 0 0 0 0 $25 ($45) DT1B The dead time value register Bis an 8-bit read/write register. The dead time delay of is adjusted by the dead time value register, DT1B. The register consists of two fields, DT1BH3..0 and DT1BL3..0, one for each complementary output. Therefore a different dead time delay can be adjusted for the rising edge of OC1A and the rising edge of OC1A. * Bits 7..4- DT1BH3..DT1BH0: Dead Time Value for OC1B Output The dead time value for the OC1B output. The dead time delay is set as a number of the prescaled timer/counter clocks. The minimum dead time is zero and the maximum dead time is the prescaled time/counter clock period multiplied by 15. * Bits 3..0- DT1BL3..DT1BL0: Dead Time Value for OC1B Output The dead time value for the OC1B output. The dead time delay is set as a number of the prescaled timer/counter clocks. The minimum dead time is zero and the maximum dead time is the prescaled time/counter clock period multiplied by 15. 95 7598H-AVR-07/09 16. Universal Serial Interface - USI The Universal Serial Interface, or USI, provides the basic hardware resources needed for serial communication. Combined with a minimum of control software, the USI allows significantly higher transfer rates and uses less code space than solutions based on software only. Interrupts are included to minimize the processor load. The main features of the USI are: * * * * * * 16.1 Two-wire Synchronous Data Transfer (Master or Slave, fSCLmax = fCK/16) Three-wire Synchronous Data Transfer (Master or Slave fSCKmax = fCK/4) Data Received Interrupt Wakeup from Idle Mode In Two-wire Mode: Wake-up from All Sleep Modes, Including Power-down Mode Two-wire Start Condition Detector with Interrupt Capability Overview A simplified block diagram of the USI is shown on Figure 16-1. For the actual placement of I/O pins, refer to "Pinout ATtiny25/45/85" 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 "USI Register Descriptions" on page 103. Figure 16-1. Universal Serial Interface, Block Diagram Bit7 Bit0 D Q LE DO (Output only) DI/SDA (Input/Open Drain) USCK/SCL (Input/Open Drain) 3 2 USIDR 1 0 TIM0 COMP USIPF 4-bit Counter USIDC USISIF USIOIF DATA BUS USIDB 3 2 0 1 1 0 CLOCK HOLD [1] Two-wire Clock Control Unit USISR USITC USICLK USICS0 USICS1 USIWM0 USIWM1 USISIE USIOIE 2 USICR The 8-bit Shift Register is directly accessible via the data bus and contains the incoming and outgoing data. The register has no buffering so the data must be read as quickly as possible to ensure that no data is lost. The most significant bit is connected to one of two output pins depending of the wire mode configuration. A transparent latch is inserted between the Serial Register Output and output pin, which delays the change of data output to the opposite clock edge of the data input sampling. The serial input is always sampled from the Data Input (DI) pin independent of the configuration. The 4-bit counter can be both read and written via the data bus, and can generate an overflow interrupt. Both the Serial Register and the counter are clocked simultaneously by the same clock source. 96 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 This allows the counter to count the number of bits received or transmitted and generate an interrupt when the transfer is complete. Note that when an external clock source is selected the counter counts both clock edges. In this case the counter counts the number of edges, and not the number of bits. The clock can be selected from three different sources: The USCK pin, Timer/Counter0 Compare Match or from software. The Two-wire clock control unit can generate an interrupt when a start condition is detected on the Two-wire bus. It can also generate wait states by holding the clock pin low after a start condition is detected, or after the counter overflows. 16.2 16.2.1 Functional Descriptions Three-wire Mode The USI Three-wire mode is compliant to the Serial Peripheral Interface (SPI) mode 0 and 1, but does not have the slave select (SS) pin functionality. However, this feature can be implemented in software if necessary. Pin names used by this mode are: DI, DO, and USCK. Figure 16-2. Three-wire Mode Operation, Simplified Diagram DO Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 DI Bit0 USCK SLAVE DO Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 DI Bit0 USCK PORTxn MASTER Figure 16-2 shows two USI units operating in Three-wire mode, one as Master and one as Slave. The two Shift Registers are interconnected in such way that after eight USCK clocks, the data in each register are interchanged. The same clock also increments the USI's 4-bit counter. The Counter Overflow (interrupt) Flag, or USIOIF, can therefore be used to determine when a transfer is completed. The clock is generated by the Master device software by toggling the USCK pin via the PORT Register or by writing a one to the USITC bit in USICR. 97 7598H-AVR-07/09 Figure 16-3. Three-wire Mode, Timing Diagram CYCLE ( Reference ) 1 2 3 4 5 6 7 8 USCK USCK DO MSB DI MSB A B C 6 5 4 3 2 1 LSB 6 5 4 3 2 1 LSB D E The Three-wire mode timing is shown in Figure 16-3. At the top of the figure is a USCK cycle reference. One bit is shifted into the USI Shift Register (USIDR) for each of these cycles. The USCK timing is shown for both external clock modes. In External Clock mode 0 (USICS0 = 0), DI is sampled at positive edges, and DO is changed (Data Register is shifted by one) at negative edges. External Clock mode 1 (USICS0 = 1) uses the opposite edges versus mode 0, i.e., samples data at negative and changes the output at positive edges. The USI clock modes corresponds to the SPI data mode 0 and 1. Referring to the timing diagram (Figure 16-3.), a bus transfer involves the following steps: 1. The Slave device and Master device sets up its data output and, depending on the protocol used, enables its output driver (mark A and B). The output is set up by writing the data to be transmitted to the Serial Data Register. Enabling of the output is done by setting the corresponding bit in the port Data Direction Register. Note that point A and B does not have any specific order, but both must be at least one half USCK cycle before point C where the data is sampled. This must be done to ensure that the data setup requirement is satisfied. The 4-bit counter is reset to zero. 2. The Master generates a clock pulse by software toggling the USCK line twice (C and D). The bit value on the slave and master's data input (DI) pin is sampled by the USI on the first edge (C), and the data output is changed on the opposite edge (D). The 4-bit counter will count both edges. 3. Step 2. is repeated eight times for a complete register (byte) transfer. 4. After eight clock pulses (i.e., 16 clock edges) the counter will overflow and indicate that the transfer is completed. The data bytes transferred must now be processed before a new transfer can be initiated. The overflow interrupt will wake up the processor if it is set to Idle mode. Depending of the protocol used the slave device can now set its output to high impedance. 16.2.2 SPI Master Operation Example The following code demonstrates how to use the USI module as a SPI Master: SPITransfer: sts USIDR,r16 ldi r16,(1< 2 CPU clock cycles for fck < 12 MHz, 3 CPU clock cycles for fck >= 12 MHz High: > 2 CPU clock cycles for fck < 12 MHz, 3 CPU clock cycles for fck >= 12 MHz 21.6.1 Serial Programming Algorithm When writing serial data to the ATtiny25/45/85, data is clocked on the rising edge of SCK. When reading data from the ATtiny25/45/85, data is clocked on the falling edge of SCK. See Figure 21-2 and Figure 21-3 for timing details. 138 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 To program and verify the ATtiny25/45/85 in the Serial Programming mode, the following sequence is recommended (see four byte instruction formats in Table 21-10): 1. Power-up sequence: Apply power between VCC and GND while RESET and SCK are set to "0". In some systems, the programmer can not guarantee that SCK is held low during power-up. In this case, RESET must be given a positive pulse of at least two CPU clock cycles duration after SCK has been set to "0". 2. Wait for at least 20 ms and enable serial programming by sending the Programming Enable serial instruction to pin MOSI. 3. The serial programming instructions will not work if the communication is out of synchronization. When in sync. the second byte (0x53), will echo back when issuing the third byte of the Programming Enable instruction. Whether the echo is correct or not, all four bytes of the instruction must be transmitted. If the 0x53 did not echo back, give RESET a positive pulse and issue a new Programming Enable command. 4. The Flash is programmed one page at a time. The memory page is loaded one byte at a time by supplying the 5 LSB of the address and data together with the Load Program memory Page instruction. To ensure correct loading of the page, the data low byte must be loaded before data high byte is applied for a given address. The Program memory Page is stored by loading the Write Program memory Page instruction with the 6 MSB of the address. If polling (RDY/BSY) is not used, the user must wait at least tWD_FLASH before issuing the next page. (See Table 21-9.) Accessing the serial programming interface before the Flash write operation completes can result in incorrect programming. 5. A: The EEPROM array is programmed one byte at a time by supplying the address and data together with the appropriate Write instruction. An EEPROM memory location is first automatically erased before new data is written. If polling (RDY/BSY) is not used, the user must wait at least tWD_EEPROM before issuing the next byte. (See Table 21-9.) In a chip erased device, no 0xFFs in the data file(s) need to be programmed. B: The EEPROM array is programmed one page at a time. The Memory page is loaded one byte at a time by supplying the 2 LSB of the address and data together with the Load EEPROM Memory Page instruction. The EEPROM Memory Page is stored by loading the Write EEPROM Memory Page Instruction with the 6 MSB of the address. When using EEPROM page access only byte locations loaded with the Load EEPROM Memory Page instruction is altered. The remaining locations remain unchanged. If polling (RDY/BSY) is not used, the used must wait at least tWD_EEPROM before issuing the next page (See Table 21-7). In a chip erased device, no 0xFF in the data file(s) need to be programmed. 6. Any memory location can be verified by using the Read instruction which returns the content at the selected address at serial output MISO. 7. At the end of the programming session, RESET can be set high to commence normal operation. 8. Power-off sequence (if needed): Set RESET to "1". Turn VCC power off. 139 7598H-AVR-07/09 Table 21-9. Minimum Wait Delay Before Writing the Next Flash or EEPROM Location Symbol Minimum Wait Delay tWD_FLASH 4.5 ms tWD_EEPROM 4.0 ms tWD_ERASE 4.0 ms tWD_FUSE 4.5 ms Figure 21-2. Serial Programming Waveforms SERIAL DATA INPUT (MOSI) MSB LSB SERIAL DATA OUTPUT (MISO) MSB LSB SERIAL CLOCK INPUT (SCK) SAMPLE Table 21-10. Serial Programming Instruction Set Instruction Format Instruction Byte 1 Byte 2 Byte 3 Byte4 Operation Programming Enable 1010 1100 0101 0011 xxxx xxxx xxxx xxxx Enable Serial Programming after RESET goes low. Chip Erase 1010 1100 100x xxxx xxxx xxxx xxxx xxxx Chip Erase EEPROM and Flash. 0010 H000 0000 000a bbbb bbbb oooo oooo Read H (high or low) data o from Program memory at word address a:b. 0100 H000 000x xxxx xxxb bbbb iiii iiii Write H (high or low) data i to Program memory page at word address b. Data low byte must be loaded before Data high byte is applied within the same address. Write Program Memory Page 0100 1100 0000 000a bbxx xxxx xxxx xxxx Write Program memory Page at address a:b. Read EEPROM Memory 1010 0000 000x xxxx xxbb bbbb oooo oooo Read data o from EEPROM memory at address b. Write EEPROM Memory 1100 0000 000x xxxx xxbb bbbb iiii iiii Write data i to EEPROM memory at address b. Read Program Memory Load Program Memory Page 140 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 Table 21-10. Serial Programming Instruction Set Instruction Format Instruction Byte 1 Byte 2 Byte 3 Byte4 Operation 1100 0001 0000 0000 0000 00bb iiii iiii Load data i to EEPROM memory page buffer. After data is loaded, program EEPROM page. 1100 0010 00xx xxxx xxbb bb00 xxxx xxxx 0101 1000 0000 0000 xxxx xxxx xxoo oooo Read Lock bits. "0" = programmed, "1" = unprogrammed. See Table 21-1 on page 134 for details. 1010 1100 111x xxxx xxxx xxxx 11ii iiii Write Lock bits. Set bits = "0" to program Lock bits. See Table 21-1 on page 134 for details. 0011 0000 000x xxxx xxxx xxbb oooo oooo Read Signature Byte o at address b. Write Fuse bits 1010 1100 1010 0000 xxxx xxxx iiii iiii Set bits = "0" to program, "1" to unprogram. See Table 21-5 on page 136 for details. Write Fuse High bits 1010 1100 1010 1000 xxxx xxxx iiii iiii Set bits = "0" to program, "1" to unprogram. See Table 21-4 on page 135 for details. 1010 1100 1010 0100 xxxx xxxx xxxx xxxi Set bits = "0" to program, "1" to unprogram. See Table 21-3 on page 135 for details. 0101 0000 0000 0000 xxxx xxxx oooo oooo Read Fuse bits. "0" = programmed, "1" = unprogrammed. See Table 21-5 on page 136 for details. 0101 1000 0000 1000 xxxx xxxx oooo oooo Read Fuse High bits. "0" = pro-grammed, "1" = unprogrammed. See Table 21-4 on page 135 for details. 0101 0000 0000 1000 xxxx xxxx oooo oooo Read Extended Fuse bits. "0" = pro-grammed, "1" = unprogrammed. See Table 21-3 on page 135 for details. 0011 1000 000x xxxx 0000 0000 oooo oooo 1111 0000 0000 0000 xxxx xxxx xxxx xxxo Load EEPROM Memory Page (page access) Write EEPROM Memory Page (page access) Read Lock bits Write Lock bits Read Signature Byte Write Extended Fuse Bits Read Fuse bits Read Fuse High bits Read Extended Fuse Bits Read Calibration Byte Poll RDY/BSY Note: Write EEPROM page at address b. Read Calibration Byte If o = "1", a programming operation is still busy. Wait until this bit returns to "0" before applying another command. a = address high bits, b = address low bits, H = 0 - Low byte, 1 - High Byte, o = data out, i = data in, x = don't care 141 7598H-AVR-07/09 21.6.2 Serial Programming Characteristics Figure 21-3. Serial Programming Timing MOSI tSHOX tOVSH SCK tSLSH tSHSL MISO tSLIV Table 21-11. Serial Programming Characteristics, TA = -40C to 125C, VCC = 2.7 - 5.5V (Unless Otherwise Noted) Symbol Parameter 1/tCLCL Oscillator Frequency (ATtiny25/45/85V) Oscillator Period (ATtiny25/45/85V) tCLCL 1/tCLCL Oscillator Period (ATtiny25/45/85L, VCC = 2.7 5.5V) tCLCL 0 Typ Max Units 4 MHz 250 0 ns 10 100 MHz ns Oscillator Frequency (ATtiny25/45/85, VCC = 4.5V 5.5V) 0 tCLCL Oscillator Period (ATtiny25/45/85, VCC = 4.5V - 5.5V) 50 ns tSHSL SCK Pulse Width High 2 tCLCL* ns tSLSH SCK Pulse Width Low 2 tCLCL* ns tOVSH MOSI Setup to SCK High tCLCL ns tSHOX MOSI Hold after SCK High 2 tCLCL ns 1/tCLCL Note: 21.7 Oscillator Frequency (ATtiny25/45/85L, VCC = 2.7 5.5V) Min 20 MHz 1. 2 tCLCL for fck < 12 MHz, 3 tCLCL for fck >= 12 MHz High-voltage Serial Programming This section describes how to program and verify Flash Program memory, EEPROM Data memory, Lock bits and Fuse bits in the ATtiny25/45/85. 142 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 Figure 21-4. High-voltage Serial Programming Table 21-12. Pin Name Mapping Signal Name in High-voltage Serial Programming Mode Pin Name I/O Function SDI PB0 I Serial Data Input SII PB1 I Serial Instruction Input SDO PB2 O Serial Data Output SCI PB3 I Serial Clock Input (min. 220ns period) Table 21-13. High-voltage Serial Programming Characteristics TA = 25C 10%, VCC = 5.0V 10% (Unless otherwise noted) Symbol Parameter Min Typ Max Units tSHSL SCI (PB3) Pulse Width High 125 ns tSLSH SCI (PB3) Pulse Width Low 125 ns tIVSH SDI (PB0), SII (PB1) Valid to SCI (PB3) High 50 ns tSHIX SDI (PB0), SII (PB1) Hold after SCI (PB3) High 50 ns tSHOV SCI (PB3) High to SDO (PB2) Valid 16 ns tWLWH_PFB Wait after Instr. 3 for Write Fuse Bits 2.5 ms Table 21-14. Pin Values Used to Enter Programming Mode Pin Symbol Value SDI Prog_enable[0] 0 SII Prog_enable[1] 0 SDO Prog_enable[2] 0 143 7598H-AVR-07/09 21.8 High-voltage Serial Programming Algorithm Sequence To program and verify the ATtiny25/45/85 in the High-voltage Serial Programming mode, the following sequence is recommended (See instruction formats in Table 21-16): 21.8.1 Enter High-voltage Serial Programming Mode The following algorithm puts the device in High-voltage Serial Programming mode: 1. Apply 4.5 - 5.5V between VCC and GND. 2. Set RESET pin to "0" and toggle SCI at least six times. 3. Set the Prog_enable pins listed in Table 21-14 to "000" and wait at least 100 ns. 4. Apply VHVRST - 5.5V to RESET. Keep the Prog_enable pins unchanged for at least tHVRST after the High-voltage has been applied to ensure the Prog_enable signature has been latched. 5. Shortly after latching the Prog_enable signature, the device will activly output data on the Prog_enable[2]/SDO pin, and the resulting drive contention may increase the power consumption. To minimize this drive contention, release the Prog_enable[2] pin after tHVRST has elapsed. 6. Wait at least 50 s before giving any serial instructions on SDI/SII. Table 21-15. High-voltage Reset Characteristics RESET Pin High-voltage Threshold Minimum High-voltage Period for Latching Prog_enable VCC VHVRST tHVRST 4.5V 11.5V 100 ns 5.5V 11.5V 100 ns Supply Voltage 21.8.2 Considerations for Efficient Programming The loaded command and address are retained in the device during programming. For efficient programming, the following should be considered. * The command needs only be loaded once when writing or reading multiple memory locations. * Skip writing the data value 0xFF that is the contents of the entire EEPROM (unless the EESAVE Fuse is programmed) and Flash after a Chip Erase. * Address High byte needs only be loaded before programming or reading a new 256 word window in Flash or 256 byte EEPROM. This consideration also applies to Signature bytes reading. 21.8.3 Chip Erase The Chip Erase will erase the Flash and EEPROM(1) memories plus Lock bits. The Lock bits are not reset until the Program memory has been completely erased. The Fuse bits are not changed. A Chip Erase must be performed before the Flash and/or EEPROM are re-programmed. Note: 1. The EEPROM memory is preserved during Chip Erase if the EESAVE Fuse is programmed. 1. Load command "Chip Erase" (see Table 21-16). 2. Wait after Instr. 3 until SDO goes high for the "Chip Erase" cycle to finish. 3. Load Command "No Operation". 144 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 21.8.4 Programming the Flash The Flash is organized in pages, see Table 21-10 on page 140. When programming the Flash, the program data is latched into a page buffer. This allows one page of program data to be programmed simultaneously. The following procedure describes how to program the entire Flash memory: 1. Load Command "Write Flash" (see Table 21-16). 2. Load Flash Page Buffer. 3. Load Flash High Address and Program Page. Wait after Instr. 3 until SDO goes high for the "Page Programming" cycle to finish. 4. Repeat 2 through 3 until the entire Flash is programmed or until all data has been programmed. 5. End Page Programming by Loading Command "No Operation". When writing or reading serial data to the ATtiny25/45/85, data is clocked on the rising edge of the serial clock, see Figure 21-6, Figure 21-7 and Table 21-17 for details. Figure 21-5. Addressing the Flash which is Organized in Pages PCMSB PROGRAM COUNTER PAGEMSB PCPAGE PCWORD PAGE ADDRESS WITHIN THE FLASH WORD ADDRESS WITHIN A PAGE PROGRAM MEMORY PAGE PAGE PCWORD[PAGEMSB:0]: INSTRUCTION WORD 00 01 02 PAGEEND Figure 21-6. High-voltage Serial Programming Waveforms SDI PB0 MSB LSB SII PB1 MSB LSB SDO PB2 SCI PB3 MSB 0 LSB 1 2 3 4 5 6 7 8 9 10 145 7598H-AVR-07/09 21.8.5 Programming the EEPROM The EEPROM is organized in pages, see Table 21-11 on page 142. When programming the EEPROM, the data is latched into a page buffer. This allows one page of data to be programmed simultaneously. The programming algorithm for the EEPROM Data memory is as follows (refer to Table 21-16): 1. Load Command "Write EEPROM". 2. Load EEPROM Page Buffer. 3. Program EEPROM Page. Wait after Instr. 2 until SDO goes high for the "Page Programming" cycle to finish. 4. Repeat 2 through 3 until the entire EEPROM is programmed or until all data has been programmed. 5. End Page Programming by Loading Command "No Operation". 21.8.6 Reading the Flash The algorithm for reading the Flash memory is as follows (refer to Table 21-16): 1. Load Command "Read Flash". 2. Read Flash Low and High Bytes. The contents at the selected address are available at serial output SDO. 21.8.7 Reading the EEPROM The algorithm for reading the EEPROM memory is as follows (refer to Table 21-16): 1. Load Command "Read EEPROM". 2. Read EEPROM Byte. The contents at the selected address are available at serial output SDO. 21.8.8 Programming and Reading the Fuse and Lock Bits The algorithms for programming and reading the Fuse Low/High bits and Lock bits are shown in Table 21-16. 21.8.9 Reading the Signature Bytes and Calibration Byte The algorithms for reading the Signature bytes and Calibration byte are shown in Table 21-16. 21.8.10 Power-off sequence Set SCI to "0". Set RESET to "1". Turn VCC power off. 146 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 Table 21-16. High-voltage Serial Programming Instruction Set for ATtiny25/45/85 Instruction Format Instruction Chip Erase Load "Write Flash" Command Load Flash Page Buffer Instr.1/5 Instr.2/6 Instr.3 SDI 0_1000_0000_00 0_0000_0000_00 0_0000_0000_00 SII 0_0100_1100_00 0_0110_0100_00 0_0110_1100_00 SDO x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx SDI 0_0001_0000_00 SII 0_0100_1100_00 SDI 0_ bbbb_bbbb _00 0_eeee_eeee_00 0_dddd_dddd_00 0_0000_0000_00 SII 0_0000_1100_00 0_0010_1100_00 0_0011_1100_00 0_0111_1101_00 SDO x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx SDI 0_0000_0000_00 SII 0_0111_1100_00 Load EEPROM Page Buffer Program EEPROM Page Write EEPROM Byte Load "Read EEPROM" Command Instr 5. 0_0000_000a_00 0_0000_0000_00 0_0000_0000_00 0_0001_1100_00 0_0110_0100_00 0_0110_1100_00 x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx 0_0000_0010_00 SII 0_0100_1100_00 Wait after Instr 3 until SDO goes high. Repeat Instr. 2 - 3 for each loaded Flash Page until the entire Flash or all data is programmed. Repeat Instr. 1 for a new 256 byte page. See Note 1. Enter Flash Read mode. SDO x_xxxx_xxxx_xx SDI 0_bbbb_bbbb_00 0_0000_000a_00 0_0000_0000_00 0_0000_0000_00 SII 0_0000_1100_00 0_0001_1100_00 0_0110_1000_00 0_0110_1100_00 x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx q_qqqq_qqqx_xx 0_0000_0000_00 0_0000_0000_00 SII 0_0111_1000_00 0_0111_1100_00 SDO x_xxxx_xxxx_xx p_pppp_pppx_xx SDI 0_0001_0001_00 SII 0_0100_1100_00 Enter EEPROM Programming mode. x_xxxx_xxxx_xx SDI 0_00bb_bbbb_00 0_eeee_eeee_00 0_0000_0000_00 0_0000_0000_00 SII 0_0000_1100_00 0_0010_1100_00 0_0110_1101_00 0_0110_1100_00 SDO x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx SDI 0_0000_0000_00 0_0000_0000_00 SII 0_0110_0100_00 0_0110_1100_00 x_xxxx_xxxx_xx x_xxxx_xxxx_xx SDI 0_00bb_bbbb_00 0_eeee_eeee_00 0_0000_0000_00 0_0000_0000_00 SII 0_0000_1100_00 0_0010_1100_00 0_0110_1101_00 0_0110_0100_00 SDO x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx SDI 0_0000_0000_00 SII 0_0110_1100_00 x_xxxx_xxxx_xx SDI 0_0000_0011_00 SII 0_0100_1100_00 Repeat Instr. 1 - 4 until the entire page buffer is filled or until all data within the page is filled. See Note 2. Wait after Instr. 2 until SDO goes high. Repeat Instr. 1 - 2 for each loaded EEPROM page until the entire EEPROM or all data is programmed. SDO SDO Repeat Instr. 1, 3 - 6 for each new address. Repeat Instr. 2 for a new 256 byte page. Instr 5 - 6. SDO SDO Repeat after Instr. 1 - 5 until the entire page buffer is filled or until all data within the page is filled. See Note 1. x_xxxx_xxxx_xx SDI Read Flash Low SDO and High Bytes SDI Load "Write EEPROM" Command Enter Flash Programming code. x_xxxx_xxxx_xx Load Flash High SDI Address and SII Program Page SDO Operation Remarks Wait after Instr.3 until SDO goes high for the Chip Erase cycle to finish. SDO SDO Load "Read Flash" Command Instr.4 Repeat Instr. 1 - 5 for each new address. Wait after Instr. 5 until SDO goes high. See Note 3. Instr. 5 Enter EEPROM Read mode. x_xxxx_xxxx_xx 147 7598H-AVR-07/09 Table 21-16. High-voltage Serial Programming Instruction Set for ATtiny25/45/85 (Continued) Instruction Format Instruction SDI Read EEPROM SII Byte SDO Write Fuse Low Bits 0_bbbb_bbbb_00 0_aaaa_aaaa_00 0_0000_0000_00 0_0000_0000_00 0_0000_1100_00 0_0001_1100_00 0_0110_1000_00 0_0110_1100_00 x_xxxx_xxxx_xx x_xxxx_xxxx_xx q_qqqq_qqq0_00 0_A987_6543_00 0_0000_0000_00 0_0000_0000_00 SII 0_0100_1100_00 0_0010_1100_00 0_0110_0100_00 0_0110_1100_00 x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx 0_0100_0000_00 0_000F_EDCB_00 0_0000_0000_00 0_0000_0000_00 0_0100_1100_00 0_0010_1100_00 0_0111_0100_00 0_0111_1100_00 SDO x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx SDI 0_0010_0000_00 0_0000_0021_00 0_0000_0000_00 0_0000_0000_00 SII 0_0100_1100_00 0_0010_1100_00 0_0110_0100_00 0_0110_1100_00 x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx 0_0000_0100_00 0_0000_0000_00 0_0000_0000_00 0_0100_1100_00 0_0110_1000_00 0_0110_1100_00 x_xxxx_xxxx_xx x_xxxx_xxxx_xx A_9876_543x_xx 0_0000_0100_00 0_0000_0000_00 0_0000_0000_00 0_0100_1100_00 0_0111_1010_00 0_0111_1110_00 x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxFE_DCBx_xx SDI 0_0000_0100_00 0_0000_0000_00 0_0000_0000_00 SII 0_0100_1100_00 0_0111_1000_00 0_0111_1100_00 SDI Read Fuse High SII Bits SDO x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_x21x_xx 0_0000_00bb_00 0_0000_0000_00 0_0000_0000_00 SII 0_0100_1100_00 0_0000_1100_00 0_0110_1000_00 0_0110_1100_00 x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx q_qqqq_qqqx_xx 0_0000_1000_00 0_0000_0000_00 0_0000_0000_00 0_0000_0000_00 0_0100_1100_00 0_0000_1100_00 0_0111_1000_00 0_0111_1100_00 x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx p_pppp_pppx_xx 0_0000_0000_00 SII 0_0100_1100_00 SDO Wait after Instr. 4 until SDO goes high. Write A - 3 = "0" to program the Fuse bit. Wait after Instr. 4 until SDO goes high. Write F - B = "0" to program the Fuse bit. Wait after Instr. 4 until SDO goes high. Write 2 - 1 = "0" to program the Lock Bit. Reading 2, 1 = "0" means the Lock bit is programmed. 0_0000_1000_00 SDI Repeat Instr. 1, 3 - 4 for each new address. Repeat Instr. 2 for a new 256 byte page. Reading F - B = "0" means the Fuse bit is programmed. SDO SDO Operation Remarks Reading A - 3 = "0" means the Fuse bit is programmed. SDI SDI Read Calibration SII Byte SDO Load "No Operation" Command Instr.4 x_xxxx_xxxx_xx SDI Read Fuse Low SII Bits SDO Read Signature Bytes Instr.3 0_0100_0100_00 SDO Read Lock Bits Instr.2/6 SDI SDI Write Fuse High SII Bits SDO Write Lock Bits Instr.1/5 Repeats Instr 2 4 for each signature byte address. x_xxxx_xxxx_xx Note: a = address high bits, b = address low bits, d = data in high bits, e = data in low bits, p = data out high bits, q = data out low bits, x = don't care, 1 = Lock Bit1, 2 = Lock Bit2, 3 = CKSEL0 Fuse, 4 = CKSEL1 Fuse, 5 = SUT0 Fuse, 6 = SUT1 Fuse, 7 = CKDIV8, Fuse, 8 = WDTON Fuse, 9 = EESAVE Fuse, A = SPIEN Fuse, B = RSTDISBL Fuse, C = BODLEVEL0 Fuse, D= BODLEVEL1 Fuse, E = MONEN Fuse, F = SPMEN Fuse Notes: 1. For page sizes less than 256 words, parts of the address (bbbb_bbbb) will be parts of the page address. 2. For page sizes less than 256 bytes, parts of the address (bbbb_bbbb) will be parts of the page address. 3. The EEPROM is written page-wise. But only the bytes that are loaded into the page are actually written to the EEPROM. Page-wise EEPROM access is more efficient when multiple bytes are to be written to the same page. Note that auto-erase of EEPROM is not available in High-voltage Serial Programming, only in SPI Programming. 148 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 21.9 High-voltage Serial Programming Characteristics Figure 21-7. High-voltage Serial Programming Timing CC CK Table 21-17. High-voltage Serial Programming Characteristics TA = 25C 10%, VCC = 5.0V 10% (Unless otherwise noted) Symbol Parameter Min tSHSL SCI (PB3) Pulse Width High 110 ns tSLSH SCI (PB3) Pulse Width Low 110 ns tIVSH SDI (PB0), SII (PB1) Valid to SCI (PB3) High 50 ns tSHIX SDI (PB0), SII (PB1) Hold after SCI (PB3) High 50 ns tSHOV SCI (PB3) High to SDO (PB2) Valid 16 ns Wait after Instr. 3 for Write Fuse Bits 2.5 ms tWLWH_PFB Typ Max Units 149 7598H-AVR-07/09 22. Electrical Characteristics 22.1 Absolute Maximum Ratings* Operating Temperature.................................. -40C to +125C *NOTICE: Storage Temperature ..................................... -65C to +150C Voltage on any Pin except RESET with respect to Ground ................................-0.5V to VCC+0.5V Voltage on RESET with respect to Ground......-0.5V to +13.0V Stresses beyond those listed under "Absolute Maximum Ratings" may cause permanent damage to the device. This is a stress rating only and functional operation of the device at these or other conditions beyond those indicated in the operational sections of this specification is not implied. Exposure to absolute maximum rating conditions for extended periods may affect device reliability. Maximum Operating Voltage ............................................ 6.0V DC Current per I/O Pin ............................................... 40.0 mA DC Current VCC and GND Pins................................ 200.0 mA Table 22-1. DC Characteristics TA = -40C to 125C, VCC = 2.7V to 5.5V (unless otherwise noted)(1) . Max.(3) Units -0.5 0.3VCC V XTAL pin -0.5 0.1VCC V Input Low Voltage RESET pin -0.5 0.1VCC V VIH Input High-voltage Except RESET and XTAL pins 0.6VCC(3) VCC +0.5 V VIH1 Input High-voltage XTAL pin 0.9VCC(3) VCC +0.5 V VIH2 Input High-voltage RESET pin 0.9VCC(3) VCC +0.5 V 0.6 0.5 V V Symbol Parameter Condition VIL Input Low Voltage Except RESET and XTAL pins VIL1 Input Low Voltage VIL2 (4) Min.(2) Typ. VOL Output Low Voltage (Port B) except PB5 IOL = 8 mA, VCC = 5V IOL = 5 mA, VCC = 3V VOH Output High-voltage(5) (Port B) except PB5 IOH = -8 mA, VCC = 5V IOH = -5 mA, VCC = 3V VOL1 Output Low Voltage(4) PB5 IOL = 1 mA VOH1 Output High-voltage(5) PB5 IOH = -200A, VCC = 5V IIL Input Leakage Current I/O Pin except RESET Vcc = 5.5V, pin low (absolute value) 50 nA IIH Input Leakage Current I/O Pin except RESET Vcc = 5.5V, pin high (absolute value) 50 nA RRST Reset Pull-up Resistor 30 60 k Rpu I/O Pin Pull-up Resistor 20 50 k 150 4.1 2.3 V V 0.6 3.2 V V ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 DC Characteristics TA = -40C to 125C, VCC = 2.7V to 5.5V (unless otherwise noted)(1) . Table 22-1. Symbol Parameter Power Supply Current ICC(6) Power-down mode(7) Notes: Typ. Max.(3) Units Active 4MHz, VCC = 3V 1.25 3 mA Active 8MHz, VCC = 5V 5 10 mA Active 16MHz, VCC = 5V 10 15 mA Idle 4MHz, VCC = 3V 0.4 0.5 mA Idle 8MHz, VCC = 5V 1.2 2 mA Idle 16MHz, VCC = 5V 2.5 5 mA WDT enabled, VCC = 3V 5 30 A WDT disabled, VCC = 3V 2 24 A WDT enabled, VCC = 5V 9 50 A WDT disabled, VCC = 5V 3 36 A Condition Min.(2) 1. All DC Characteristics contained in this data sheet result from actual silicon characterization. 2. "Max" means the highest value where the pin is guaranteed to be read as low. 3. "Min" means the lowest value where the pin is guaranteed to be read as high. 4. Although each I/O port can sink more than the test conditions (8 mA at VCC = 5V, 5 mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed: 1] The sum of all IOL, for all ports, should not exceed 60 mA. If IOL exceeds the test condition, VOL may exceed the related specification. Pins are not guaranteed to sink current greater than the listed test condition. 5. Although each I/O port can source more than the test conditions (8 mA at VCC = 5V, 5 mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed: 1] 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. 6. All I/O modules are turned off (PRR = 0xFF) for all ICC values. 7. Brown-Out Detection (BOD) disabled. 22.2 External Clock Drive Waveforms Figure 22-1. External Clock Drive Waveforms V IH1 V IL1 151 7598H-AVR-07/09 22.3 External Clock Drive Table 22-2. External Clock Drive(1). PRELIMINARY VCC = 4.5 5.5V VCC = 2.7 - 5.5V Min. Max. Min. Max. Units 0 8 0 16 MHz Symbol Parameter 1/tCLCL Clock Frequency tCLCL Clock Period 100 50 ns tCHCX High Time 40 20 ns tCLCX Low Time 40 20 ns tCLCH Rise Time 1.6 0.5 s tCHCL Fall Time 1.6 0.5 s tCLCL Change in period from one clock cycle to the next 2 2 % Note: 1. All DC Characteristics contained in this data sheet result from actual silicon characterization. Figure 22-2. Maximum Frequency vs. VCC 16 MHz 8 MHz Safe Operating Area 2.7V 152 4.5V 5.5V ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 22.4 ADC Characteristics - Preliminary Data ADC Characteristics, Single Ended Channels. -40C - 125C. (1). PRELIMINARY Table 22-3. Symbol Parameter Resolution Single Ended Conversion Max(1) Units 10 Bits LSB Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 1 MHz 3 LSB Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 200 kHz Noise Reduction Mode 1.5 LSB Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 1 MHz Noise Reduction Mode 2.5 LSB Integral Non-linearity (INL) Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 200 kHz 1 LSB Differential Non-linearity (DNL) Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 200 kHz 0.5 LSB Gain Error Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 200 kHz 2.5 LSB Offset Error Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 200 kHz 1.5 LSB Conversion Time Free Running Conversion Analog Supply Voltage Input Voltage 13 VINT Internal Voltage Reference RAIN Analog Input Resistance 260 50 VCC - 0.3 1.1 100 kHz (3) VCC + 0.3 V VREF-50mV V 38.5 1.0 s 1000 (2) GND Input Bandwidth Note: Typ(1) 2 Clock Frequency VIN Min(1) Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 200 kHz Absolute accuracy (Including INL, DNL, quantization error, gain and offset error) AVCC Condition kHz 1.2 V M 1. All DC Characteristics contained in this data sheet result from actual silicon characterization. 2. Minimum for AVCC is 2.7V. 3. Maximum for AVCC is 5.5V. 153 7598H-AVR-07/09 22.5 Calibrated RC Oscillator Accuracy Table 22-4. Calibration Accuracy of Internal RC Oscillator Factory Calibration User Calibration Frequency Vcc Temperature Calibration Accuracy 8.0 MHz 3V 25C 1% 7.3 - 8.1 MHz 2.7V - 5.5V -40C - +125C 14% 23. Typical Characteristics The data contained in this section is extracted from preliminary silicon characterization and will be updated upon final characterization. The following charts show typical behavior. These figures are not tested during manufacturing. All current consumption measurements are performed with all I/O pins configured as inputs and with internal pull-ups enabled. A sine wave generator with railtorail output is used as clock source. The power consumption in Power-down mode is independent of clock selection. The current consumption is a function of several factors such as: operating voltage, operating frequency, loading of I/O pins, switching rate of I/O pins, code executed and ambient temperature. The dominating factors are operating voltage and frequency. The current drawn from capacitive loaded pins may be estimated (for one pin) as CL*VCC*f where CL = load capacitance, VCC = operating voltage and f = average switching frequency of I/O pin. The parts are characterized at frequencies higher than test limits. Parts are not guaranteed to function properly at frequencies higher than the ordering code indicates. The difference between current consumption in Power-down mode with Watchdog Timer enabled and Power-down mode with Watchdog Timer disabled represents the differential current drawn by the Watchdog Timer. 154 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 23.1 Active Supply Current Figure 23-1. Active Supply Current vs. Frequency (0.1 - 1.0 MHz) 0.040 5.5 V 0.035 5.0 V 0.030 4.5 V 4.0 V 0.025 0.020 3.3 V 2.7 V 0.015 0.010 0.005 0.000 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Fre que nc y (MHz ) Figure 23-2. Active Supply Current vs. Frequency (1 - 20 MHz) ACTIVE S UP P LY CURRENT vs . FREQUENCY 1 - 20MHz 14 5.5 V 12 5.0 V ICC (mA) 10 4.5 V 8 4.0 V 6 3.3 V 4 2.7 V 2 0 0 2 4 6 8 10 12 14 16 18 20 Frequency (MHz) 155 7598H-AVR-07/09 Figure 23-3. Active Supply Current vs. VCC (Internal RC Oscillator, 128 kHz) ACTIVE S UP P LY CURRENT vs . VC C INTERNAL RC OSCILLATOR, 128 KHz 0.25 125 85 25 -40 ICC(mA) 0.2 C C C C 0.15 0.1 0.05 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 V CC (V) Figure 23-4. Active Supply Current vs. VCC (Internal RC Oscillator, 1 MHz) ACTIVE S UP P LY CURRENT vs . VC C INTERNAL RC OSCILLATOR, 1 MHz 1.8 1.6 125 85 25 -40 1.4 ICC (mA) 1.2 C C C C 1 0.8 0.6 0.4 0.2 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 V CC (V) 156 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 Figure 23-5. Active Supply Current vs. VCC (Internal RC Oscillator, 8 MHz) ACTIVE S UP P LY CURRENT vs . V CC INTERNAL RC OSCILLATOR, 8 MHz 8 7 125 85 25 -40 ICC (mA) 6 C C C C 5 4 3 2 1 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 V CC (V) 23.2 Idle Supply Current Figure 23-6. Idle Supply Current vs. Frequency (0.1 - 1.0 MHz) IDLE S UP P LY CURRENT vs . LOW FREQUENCY 0.1 - 1.0 MHz 0.25 5.5 V 0.2 5.0 V Idle (mA) 4.5 V 4.0 V 0.15 3.3 V 2.7 V 0.1 1.8 V 0.05 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Frequency (MHz) 157 7598H-AVR-07/09 Figure 23-7. Idle Supply Current vs. Frequency (1 - 20 MHz) IDLE S UP P LY CURRENT vs . FREQUENCY 1 - 20MHz Idle (mA) 4 3.5 5.5 V 3 5.0 V 2.5 4.5 V 2 4.0 V 1.5 3.3 V 1 2.7 V 0.5 1.8 V 0 0 2 4 6 8 10 12 14 16 18 20 Frequency (MHz) Figure 23-8. Idle Supply Current vs. VCC (Internal RC Oscillator, 128 kHz) IDLE S UP P LY CURRENT vs . VC C INTERNAL RC OSCILLATOR, 128 KHz 0.25 125 85 25 -40 0.2 C C C C ICC 0.15 0.1 0.05 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 V CC (V) 158 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 Figure 23-9. Idle Supply Current vs. VCC (Internal RC Oscillator, 1 MHz) IDLE S UP P LY CURRENT vs . VC C INTERNAL RC OSCILLATOR, 1 MHz 0.6 0.5 Idle (mA) 0.4 125 85 25 -40 C C C C 125 85 25 -40 C C C C 0.3 0.2 0.1 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 V CC (V) Figure 23-10. Idle Supply Current vs. VCC (Internal RC Oscillator, 8 MHz) IDLE S UP P LY CURRENT vs . VC C INTERNAL RC OSCILLATOR, 8 MHz 2 1.8 Idle (mA) 1.6 1.4 1.2 1 0.8 0.6 0.4 0.2 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 V CC (V) 159 7598H-AVR-07/09 23.2.1 Using the Power Reduction Register The tables and formulas below can be used to calculate the additional current consumption for the different I/O modules in Active and Idle mode. The enabling or disabling of the I/O modules are controlled by the Power Reduction Register. See "Power Reduction Register" on page 33 for details. Table 23-1. PRR bit Additional Current Consumption for the different I/O modules (absolute values) Typical numbers VCC = 2V, F = 1MHz VCC = 3V, F = 4MHz VCC = 5V, F = 8MHz PRTIM1 43 uA 270 uA 1090 uA PRTIM0 5.0 uA 28 uA 116 uA PRUSI 4.0 uA 25 uA 102 uA PRADC 13 uA 84 uA 351 uA Table 23-2. Additional Current Consumption (percentage) in Active and Idle mode PRR bit Additional Current consumption compared to Active with external clock (see Figure 23-1 and Figure 23-2) Additional Current consumption compared to Idle with external clock (see Figure 23-6 and Figure 23-7) PRTIM1 17.3% 68.4 % PRTIM0 1.8 % 7.3 % PRUSI 1.6 % 6.4 % PRADC 5.4 % 21.4 % It is possible to calculate the typical current consumption based on the numbers from Table 2 for other VCC and frequency settings than listed in Table 1. 23.2.1.1 Example 1 Calculate the expected current consumption in idle mode with USI, TIMER0, and ADC enabled at VCC = 2.0V and F = 1MHz. From Table 23-2, third column, we see that we need to add 6.4% for the USI, 7.3% for the TIMER0 module, and 21.4% for the ADC module. Reading from Figure 23-9, we find that the idle current consumption is ~0,25mA at VCC = 3.0V and F = 1MHz. The total current consumption in idle mode with USI, TIMER0, and ADC enabled, gives: I CC total ( 0,25 )mA * ( 1 + 0,064 + 0,073 + 0,214 ) 0,337mA 160 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 23.3 Power-Down Supply Current Figure 23-11. Power-Down Supply Current vs. VCC (Watchdog Timer Disabled) P OWER-DOWN S UP P LY CURRENT vs . VC C WATCHDOG TIMER DISABLED 4 125 C 3.5 3 ICC (uA) 2.5 2 1.5 1 85 C 0.5 -40 C 25 C 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 V CC (V) Figure 23-12. Power-Down Supply Current vs. VCC (Watchdog Timer Enabled) P OWER-DOWN S UP P LY CURRENT vs . VC C WATCHDOG TIMER ENABLED 12 10 125 C -40 C 25 C 85 C ICC (uA) 8 6 4 2 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 V CC (V) 161 7598H-AVR-07/09 23.4 Pin Pull-up Figure 23-13. I/O Pin Pull-Up Resistor Current vs. Input Voltage (VCC = 1.8V) I/O P IN P ULL-UP RES IS TOR CURRENT vs . INP UT VOLTAGE Vcc = 1.8V 60 50 IOP (uA) 40 30 20 10 0 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 -40 25 85 2 125 C C C C V OP (V) Figure 23-14. I/O Pin Pull-Up Resistor Current vs. Input Voltage (VCC = 2.7V) I/O P IN P ULL-UP RES IS TOR CURRENT vs . INP UT VOLTAGE Vcc = 2.7V 90 80 70 IOP (uA) 60 50 40 30 20 10 0 0 0.5 1 1.5 2 2.5 125 85 25 3 -40 C C C C V OP (V) 162 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 Figure 23-15. I/O Pin Pull-Up Resistor Current vs. Input Voltage (VCC = 5.0V) I/O P IN P ULL-UP RES IS TOR CURRENT vs . INP UT VOLTAGE Vcc = 5.0V 160 140 120 IOP (uA) 100 80 60 40 20 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 125 C 85 C 25 C 5 -40 C V OP (V) Figure 23-16. Reset Pull-Up Resistor Current vs. Reset Pin Voltage (VCC = 1.8V) RES ET P ULL-UP RES IS TOR CURRENT vs . RES ET P IN VOLTAGE Vcc = 1.8V 40 35 IRE S E T (uA) 30 25 20 15 10 5 0 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 125 85 25 2 -40 C C C C V RES ET (V) 163 7598H-AVR-07/09 Figure 23-17. Reset Pull-Up Resistor Current vs. Reset Pin Voltage (VCC = 2.7V) RES ET P ULL-UP RES IS TOR CURRENT vs . RES ET P IN VOLTAGE Vcc = 2.7V 70 60 IRE S E T (uA) 50 40 30 20 10 0 0 0.5 1 1.5 2 2.5 3 125 85 25 -40 C C C C V RES ET (V) Figure 23-18. Reset Pull-Up Resistor Current vs. Reset Pin Voltage (VCC = 5.0V) RES ET P ULL-UP RES IS TOR CURRENT vs . RES ET P IN VOLTAGE Vcc = 5.0V 140 120 IRE S E T (uA) 100 80 60 40 20 0 0 1 2 3 4 5 125 85 25 6 -40 C C C C V RES ET (V) 164 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 23.5 Pin Driver Strength Figure 23-19. I/O Pin Source Current vs. Output Voltage (VCC = 1.8V) I/O P IN S INK CURRENT vs . OUTP UT VOLTAGE V CC = 1.8V 12 -40 C 10 25 C 85 C 125 C IOL (mA) 8 6 4 2 0 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 V OL (V) Figure 23-20. I/O Pin Source Current vs. Output Voltage (VCC = 3V) I/O P IN OUTP UT VOLTAGE vs . S INK CURRENT Vc c = 3.0V 1.2 125 1 85 V OL (V) 0.8 25 0.6 -40 0.4 0.2 0 0 5 10 15 20 25 IOL (V) 165 7598H-AVR-07/09 Figure 23-21. I/O Pin Source Current vs. Output Voltage (VCC = 5V) I/O P IN OUTP UT VOLTAGE vs . S INK CURRENT Vc c = 5.0V 0.7 125 0.6 85 V OL (V) 0.5 25 -40 0.4 0.3 0.2 0.1 0 0 5 10 15 20 25 IOL (V) Figure 23-22. I/O Pin Sink Current vs. Output Voltage (VCC = 1.8V) I/O P IN S OURCE CURRENT vs . OUTP UT VOLTAGE V CC = 1.8V 9 8 25 C 7 IOH (mA) 6 -40 C 85 C 5 125 C 4 3 2 1 0 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 V OH (V) 166 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 Figure 23-23. I/O Pin Sink Current vs. Output Voltage (VCC = 3V) I/O P IN OUTP UT VOLTAGE vs . S OURCE CURRENT Vc c = 3V 3.5 3 V OH (V 2.5 -40 25 85 125 2 1.5 1 0.5 0 0 5 10 15 20 25 IOH (mA) Figure 23-24. I/O Pin Sink Current vs. Output Voltage (VCC = 5.0V) I/O P IN OUTP UT VOLTAGE vs . S OURCE CURRENT Vc c = 5.0V 5.1 5 4.9 V OH (V) 4.8 4.7 4.6 -40 4.5 25 85 125 4.4 4.3 0 5 10 15 20 25 IOH (mA) 167 7598H-AVR-07/09 23.6 Pin Thresholds and Hysteresis Figure 23-25. I/O Pin Input Threshold Voltage vs. VCC (VIH, I/O Pin Read As '1') I/O P IN INP UT THRES HOLD VOLTAGE vs . V CC VIH, IO PIN READ AS '1' -40 25 85 125 3 2.5 C C C C Thre s hold 2 1.5 1 0.5 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 V CC (V) Figure 23-26. I/O Pin Input Threshold Voltage vs. VCC (VIL, I/O Pin Read As '0') I/O P IN INP UT THRES HOLD VOLTAGE vs . VC C VIL, IO PIN READ AS '0' 125 85 25 -40 2.5 C C C C Thre s hold 2 1.5 1 0.5 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 V CC (V) 168 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 Figure 23-27. I/O Pin Input Hysteresis vs. VCC I/O P IN INP UT HYS TERES IS 0.8 0.7 Thre s hold 0.6 0.5 0.4 -40 25 85 125 0.3 0.2 C C C C 0.1 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 V CC (V) Figure 23-28. Reset Input Threshold Voltage vs. VCC (VIH, Reset Pin Read As '1') RES ET INP UT THRES HOLD VOLTAGE vs . V C C VIH, IO PIN READ AS '1' 125 85 25 -40 2.5 C C C C Thre s hold 2 1.5 1 0.5 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 V CC (V) 169 7598H-AVR-07/09 Figure 23-29. Reset Input Threshold Voltage vs. VCC (VIL, Reset Pin Read As '0') RES ET INP UT THRES HOLD VOLTAGE vs . CVC VIL, IO PIN READ AS '0' 125 85 25 -40 C C C C 125 85 25 5.5 -40 C C C C 2.5 Thre s hold 2 1.5 0.5 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 V CC (V) Figure 23-30. Reset Input Pin Hysteresis vs. VCC RES ET INP UT THRES HOLD VOLTAGE vs . CC V VIH, IO PIN READ AS '1' 0.25 Thre s hold 0.2 0.15 0.1 0.05 0 1.5 2 2.5 3 3.5 4 4.5 5 V CC (V) 170 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 23.7 BOD Thresholds and Analog Comparator Offset Figure 23-31. BOD Thresholds vs. Temperature (BODLEVEL Is 4.3V) BOD THRES HOLDS vs . TEMP ERATURE BODLEVEL = 4.3V 4.4 4.35 Ris ing Thre s hold (V) 4.3 Falling 4.25 4.2 4.15 4.1 4.05 4 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 Temperature (C) Figure 23-32. BOD Thresholds vs. Temperature (BODLEVEL Is 2.7V) BOD THRES HOLDS vs . TEMP ERATURE BODLEVEL = 2.7V 2.8 Ris ing Thre s hold (V) 2.75 2.7 Falling 2.65 2.6 2.55 2.5 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 Temperature (C) 171 7598H-AVR-07/09 Figure 23-33. BOD Thresholds vs. Temperature (BODLEVEL Is 1.8V) BOD THRES HOLDS vs . TEMP ERATURE BODLEVEL at 1.8V 1.9 1.85 Thre s hold (V) Ris ing Vcc 1.8 Falling Vcc 1.75 1.7 1.65 1.6 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 Temperature (C) 23.8 Internal Oscillator Speed Figure 23-34. Watchdog Oscillator Frequency vs. VCC) WATCHDOC OS CILLATOR FREQUENCY vs . V CC 0.118 0.116 -40 C 0.114 25 C FRC (MHz ) 0.112 0.11 0.108 85 C 0.106 0.104 125 C 0.102 0.1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 V CC (V) 172 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 Figure 23-35. Watchdog Oscillator Frequency vs. Temperature WATCHDOG OS CILLATOR FREQUENCY vs . TEMP ERATURE 0.118 0.116 0.114 FRC (MHz ) 0.112 0.11 0.108 1.8 V 0.106 2.7 3.6 4.0 5.5 0.104 0.102 0.1 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 V V V V 100 110 120 Temperature Figure 23-36. Calibrated 8 MHz RC Oscillator Frequency vs. Temperature CALIBRATED 8MHz RC OS CILLATOR FREQUENCY vs . TEMP ERATURE 8.4 5.0 V 3.0 V 8.3 8.2 FRC (MHz ) 8.1 8 7.9 7.8 7.7 7.6 7.5 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 Temperature 173 7598H-AVR-07/09 Figure 23-37. Calibrated 8 MHz RC Oscillator Frequency vs. VCC CALIBRATED 8MHz RC OS CILLATOR FREQUENCY vs . OP ERATING VOLTAGE 8.4 125 C 8.3 85 C 8.2 FRC (MHz ) 8.1 25 C 8 7.9 7.8 -40 C 7.7 7.6 7.5 1.5 2 2.5 3 3.5 4 4.5 5 5.5 V CC (V) Figure 23-38. Calibrated 8 MHz RC Oscillator Frequency vs. Osccal Value CALIBRATED 8MHz RC OS CILLATOR FREQUENCY vs . OS CCAL VALUE 14 125 85 25 -40 12 C C C C FRC (MHz ) 10 8 6 4 2 0 16 32 48 64 80 96 112 128 144 160 176 192 208 224 240 OSCCAL (X1) 174 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 23.9 Current Consumption of Peripheral Units Figure 23-39. Brownout Detector Current vs. VCC BROWNOUT DETECTOR CURRENT vs . CVC 35 125 85 25 -40 30 ICC (uA) 25 C C C C 20 15 10 5 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 V CC (V) Figure 23-40. Analog Comparator Current vs. VCC ANALOG COMP ARATOR CURRENT vs . V CC AREF = AVcc 350 150 C 300 125 C 85 C ICC (uA) 250 200 25 C 150 100 50 -40 C 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 V CC (V) 175 7598H-AVR-07/09 23.10 Current Consumption in Reset and Reset Pulse width Figure 23-41. Reset Supply Current vs. VCC (0.1 - 1.0 MHz, Excluding Current through the Reset Pull-up) RES ET S UP P LY CURRENT vs . CVC 0.1 - 1.0 MHz, EXCLUDING CURRENT THROUGH THE RESET PULLUP 0.14 5.5 V 0.12 5.0 V ICC (mA) 0.1 4.5 V 4.0 V 0.08 3.3 V 0.06 2.7 V 0.04 1.8 V 0.02 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Frequency (MHz) Figure 23-42. Reset Supply Current vs. VCC (1 - 24 MHz, Excluding Current through the Reset Pull-up) RES ET S UP P LY CURRENT vs . V C C 1 - 20 MHz , EXCLUDING CURRENT THROUGH THE RESET PULLUP 2.5 5.5 V 5.0 V 2 ICC (mA) 4.5 V 1.5 4.0 V 1 3.3 V 0.5 2.7 V 1.8 V 0 0 2 4 6 8 10 12 14 16 18 20 Frequency (MHz) 176 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 Figure 23-43. Reset Pulse Width vs. VCC MINIMUM RES ET P ULS E WIDTH vs . VC C 2500 Puls e width (ns ) 2000 1500 1000 125 85 25 -40 500 C C C C 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 V CC (V) 23.11 Analog to Digital Converter Figure 23-44. Analog to Digital Converter Differential mode OFFSET vs. VCC Analog to Digital Converter - OFFS ET Diffe re ntia l Inputs , Vc c = 4V, Vre f = 4V 2 1.5 1 0.5 Diff x1 0 -0.5 -1 -1.5 Diff x20 -2 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 Te mpe ra ture 177 7598H-AVR-07/09 Figure 23-45. Analog to Digital Converter Single Endded mode OFFSET vs. VCC Analog to Digital Converter - OFFS ET Single Ended, Vcc = 4V, Vref = 4V 2.5 2 LSB 1.5 1 0.5 0 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 Temperature Figure 23-46. Analog to Digital Converter Differential mode GAIN vs. VCC Analog to Digital Converter - GAIN Differential Inputs , Vcc = 5V, Vref = 4V -1 -1.2 -1.4 -1.6 Diff x20 LSB -1.8 -2 -2.2 -2.4 -2.6 Diff x1 -2.8 -3 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 Temperature 178 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 Figure 23-47. Analog to Digital Converter Single Endded mode GAIN vs. VCC Analog to Digital Converter - GAIN Single Ended, Vcc = 4V, Vref = 4V 0 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 -0.5 LSB -1 -1.5 -2 -2.5 Temperature Figure 23-48. Analog to Digital Converter Differential mode DNL vs. VCC Analog to Digital Converter - Differential Non Linearity DNL Differential Inputs , Vcc = 4V, Vref = 4V 1.2 Diff x20 1 LSB 0.8 0.6 0.4 Diff x1 0.2 0 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 Temperature 179 7598H-AVR-07/09 Figure 23-49. Analog to Digital Converter Single Endded mode DNL vs. VCC Analog to Digital Converter - Differential Non Linearity DNL Single Ended, Vcc = 4V, Vref = 4V 0.57 0.56 0.55 0.54 LSB 0.53 0.52 0.51 0.5 0.49 0.48 0.47 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 Temperature Figure 23-50. Analog to Digital Converter differential mode INL vs. VCC Analog to Digital Converter - Integral Non Linearity INL Differential Inputs , Vcc = 4V, Vref = 4V 1.8 1.6 Diff x20 1.4 LSB 1.2 1 0.8 0.6 Diff x1 0.4 0.2 0 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 Temperature 180 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 Figure 23-51. Analog to Digital Converter Single Endded mode INL vs. VCC Analog to Digital Converter - Integral Non Linearity INL Single Ended, Vcc = 4V, Vref = 4V 0.72 0.7 LSB 0.68 0.66 0.64 0.62 0.6 0.58 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 Temperature 181 7598H-AVR-07/09 24. Register Summary Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 0x3F SREG I T H S V N Z C Page page 7 0x3E SPH - - - - - - - SP8 page 10 0x3D SPL SP7 SP6 SP5 SP4 SP3 SP2 SP1 SP0 page 10 0x3C Reserved 0x3B GIMSK - INT0 PCIE - - - - - page 59 0x3A GIFR - INTF0 PCIF - - - - - page 60 0x39 TIMSK - OCIE1A OCIE1B OCIE0A OCIE0B TOIE1 TOIE0 - page 77 0x38 TIFR - OCF1A OCF1B OCF0A OCF0B TOV1 TOV0 - page 77 0x37 SPMCSR - - - CTPB RFLB PGWRT PGERS SPMEN page 132 0x36 Reserved 0x35 MCUCR BODS PUD SE SM1 SM0 BODSE ISC01 ISC00 page 31, page 54, page 59 0x34 MCUSR - - - - WDRF BORF EXTRF PORF page 40 0x33 TCCR0B FOC0A FOC0B - - WGM02 CS02 CS01 CS00 page 75 0x32 TCNT0 Timer/Counter0 0x31 OSCCAL Oscillator Calibration Register 0x30 TCCR1 0x2F TCNT1 Timer/Counter1 page 86 0x2E OCR1A Timer/Counter1 Output Compare Register A page 86 0x2D OCR1C Timer/Counter1 Output Compare Register C 0x2C GTCCR - - CTC1 PWM1A COM1A1 TSM PWM1B COM1B1 COM0A1 COM0A0 COM0B1 COM1A0 CS13 COM1B0 FOC1B page 76 page 26 CS12 CS11 CS10 page 84 page 87 FOC1A PSR1 PSR0 WGM01 WGM00 Timer/Counter1 Output Compare Register B page 80, page 85 0x2B OCR1B 0x2A TCCR0A 0x29 OCR0A Timer/Counter0 - Output Compare Register A 0x28 OCR0B Timer/Counter0 - Output Compare Register B 0x27 PLLCSR SM - - - - PCKE PLLE PLOCK page 89 0x26 CLKPR CLKPCE - - - CLKPS3 CLKPS2 CLKPS1 CLKPS0 page 29 0x25 DT1A DT1AH3 DT1AH2 DT1AH1 DT1AH0 DT1AL3 DT1AL2 DT1AL1 DT1AL0 page 95 0x24 DT1B DT1BH3 DT1BH2 DT1BH1 DT1BH0 DT1BL3 DT1BL2 DT1BL1 DT1BL0 page 95 0x23 DTPS1 - - - - - - DTPS11 DTPS10 page 94 WDTIE WDP3 WDCE WDE WDP2 WDP1 WDP0 page 42 PRTIM1 PRTIM0 PRUSI PRADC page 33 EEAR8 page 16 page 16 COM0B0 page 87 - 0x22 DWDR 0x21 WDTCR WDTIF 0x20 PRR - 0x1F EEARH 0x1E EEARL 0x1D EEDR 0x1C EECR 0x1B Reserved - 0x1A Reserved - 0x19 Reserved 0x18 PORTB - - PORTB5 0x17 DDRB - - 0x16 PINB - 0x15 PCMSK 0x14 DIDR0 page 76 page 77 DWDR[7:0] EEAR7 EEAR6 EEAR5 EEAR4 EEAR3 page 72 page 129 EEAR2 EEAR1 EEAR0 EERIE EEMWE EEWE EERE page 16 PORTB4 PORTB3 PORTB2 PORTB1 PORTB0 page 58 DDB5 DDB4 DDB3 DDB2 DDB1 DDB0 page 58 - PINB5 PINB4 PINB3 PINB2 PINB1 PINB0 page 58 - - PCINT5 PCINT4 PCINT3 PCINT2 PCINT1 PCINT0 page 60 - - ADC0D ADC2D ADC3D ADC1D EIN1D AIN0D page 110, page 127 EEPROM Data Register - - EEPM1 EEPM0 page 16 - 0x13 GPIOR2 General Purpose I/O Register 2 0x12 GPIOR1 General Purpose I/O Register 1 0x11 GPIOR0 General Purpose I/O Register 0 0x10 USIBR USI Buffer Register 0x0F USIDR USI Data Register 0x0E USISR USICIF USIOIF USIPF USIDC USICNT3 USICNT2 USICNT1 USICNT0 page 104 0x0D USICR USISIE USIOIE USIWM1 USIWM0 USICS1 USICS0 USICLK USITC page 105 0x0C Reserved - 0x0B Reserved - 0x0A Reserved - 0x09 Reserved - Notes: page 104 page 103 1. For compatibility with future devices, reserved bits should be written to zero if accessed. Reserved I/O memory addresses should never be written. 2. 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. 3. Some of the Status Flags are cleared by writing a logical one to them. Note that, unlike most other AVRs, the CBI and SBI instructions will only operation the specified bit, and can therefore be used on registers containing such Status Flags. The CBI and SBI instructions work with registers 0x00 to 0x1F only. 182 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page 0x08 ACSR ACD ACBG ACO ACI ACIE - ACIS1 ACIS0 page 108 0x07 ADMUX REFS1 REFS0 ADLAR REFS2 MUX3 MUX2 MUX1 MUX0 page 123 0x06 ADCSRA ADEN ADSC ADATE ADIF ADIE ADPS2 ADPS1 ADPS0 page 124 0x05 ADCH ADC Data Register High Byte 0x04 ADCL ADC Data Register Low Byte 0x03 ADCSRB 0x02 Reserved - 0x01 Reserved - 0x00 Reserved - Notes: BIN ACME IPR - - page 126 page 126 ADTS2 ADTS1 ADTS0 page 108, page 126 1. For compatibility with future devices, reserved bits should be written to zero if accessed. Reserved I/O memory addresses should never be written. 2. 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. 3. Some of the Status Flags are cleared by writing a logical one to them. Note that, unlike most other AVRs, the CBI and SBI instructions will only operation the specified bit, and can therefore be used on registers containing such Status Flags. The CBI and SBI instructions work with registers 0x00 to 0x1F only. 183 7598H-AVR-07/09 25. Instruction Set Summary Mnemonics Operands Description Operation Flags #Clocks ARITHMETIC AND LOGIC INSTRUCTIONS ADD Rd, Rr Add two Registers Rd Rd + Rr Z,C,N,V,H ADC Rd, Rr Add with Carry two Registers Rd Rd + Rr + C Z,C,N,V,H 1 ADIW Rdl,K Add Immediate to Word Rdh:Rdl Rdh:Rdl + K Z,C,N,V,S 2 SUB Rd, Rr Subtract two Registers Rd Rd - Rr Z,C,N,V,H 1 SUBI Rd, K Subtract Constant from Register Rd Rd - K Z,C,N,V,H 1 SBC Rd, Rr Subtract with Carry two Registers Rd Rd - Rr - C Z,C,N,V,H 1 SBCI Rd, K Subtract with Carry Constant from Reg. Rd Rd - K - C Z,C,N,V,H 1 SBIW Rdl,K Subtract Immediate from Word Rdh:Rdl Rdh:Rdl - K Z,C,N,V,S 2 AND Rd, Rr Logical AND Registers Rd Rd * Rr Z,N,V 1 ANDI Rd, K Logical AND Register and Constant Rd Rd * K Z,N,V 1 OR Rd, Rr Logical OR Registers Rd Rd v Rr Z,N,V 1 ORI Rd, K Logical OR Register and Constant Rd Rd v K Z,N,V 1 1 EOR Rd, Rr Exclusive OR Registers Rd Rd Rr Z,N,V 1 COM Rd One's Complement Rd 0xFF -Rd Z,C,N,V 1 NEG Rd Two's Complement Rd 0x00 -Rd Z,C,N,V,H 1 SBR Rd,K Set Bit(s) in Register Rd Rd v K Z,N,V 1 CBR Rd,K Clear Bit(s) in Register Rd Rd * (0xFF - K) Z,N,V 1 INC Rd Increment Rd Rd + 1 Z,N,V 1 DEC Rd Decrement Rd Rd -1 Z,N,V 1 TST Rd Test for Zero or Minus Rd Rd * Rd Z,N,V 1 CLR Rd Clear Register Rd Rd Rd Z,N,V 1 SER Rd Set Register Rd 0xFF None 1 BRANCH INSTRUCTIONS RJMP k IJMP Relative Jump PC PC + k + 1 None 2 Indirect Jump to (Z) PC Z None 2 Relative Subroutine Call PC PC + k + 1 None 3 ICALL Indirect Call to (Z) PC Z None 3 RET Subroutine Return PC STACK None 4 RETI Interrupt Return PC STACK I 4 RCALL k CPSE Rd,Rr Compare, Skip if Equal if (Rd = Rr) PC PC + 2 or 3 None CP Rd,Rr Compare Rd -Rr Z, N,V,C,H 1 CPC Rd,Rr Compare with Carry Rd -Rr -C Z, N,V,C,H 1 CPI Rd,K Compare Register with Immediate Rd -K Z, N,V,C,H SBRC Rr, b Skip if Bit in Register Cleared if (Rr(b)=0) PC PC + 2 or 3 None 1/2/3 1 1/2/3 SBRS Rr, b Skip if Bit in Register is Set if (Rr(b)=1) PC PC + 2 or 3 None 1/2/3 SBIC P, b Skip if Bit in I/O Register Cleared if (P(b)=0) PC PC + 2 or 3 None 1/2/3 SBIS P, b Skip if Bit in I/O Register is Set if (P(b)=1) PC PC + 2 or 3 None 1/2/3 BRBS s, k Branch if Status Flag Set if (SREG(s) = 1) then PCPC+k + 1 None 1/2 BRBC s, k Branch if Status Flag Cleared if (SREG(s) = 0) then PCPC+k + 1 None 1/2 BREQ k Branch if Equal if (Z = 1) then PC PC + k + 1 None 1/2 BRNE k Branch if Not Equal if (Z = 0) then PC PC + k + 1 None 1/2 BRCS k Branch if Carry Set if (C = 1) then PC PC + k + 1 None 1/2 BRCC k Branch if Carry Cleared if (C = 0) then PC PC + k + 1 None 1/2 BRSH k Branch if Same or Higher if (C = 0) then PC PC + k + 1 None 1/2 BRLO k Branch if Lower if (C = 1) then PC PC + k + 1 None 1/2 BRMI k Branch if Minus if (N = 1) then PC PC + k + 1 None 1/2 BRPL k Branch if Plus if (N = 0) then PC PC + k + 1 None 1/2 BRGE k Branch if Greater or Equal, Signed if (N V= 0) then PC PC + k + 1 None 1/2 BRLT k Branch if Less Than Zero, Signed if (N V= 1) then PC PC + k + 1 None 1/2 BRHS k Branch if Half Carry Flag Set if (H = 1) then PC PC + k + 1 None 1/2 BRHC k Branch if Half Carry Flag Cleared if (H = 0) then PC PC + k + 1 None 1/2 BRTS k Branch if T Flag Set if (T = 1) then PC PC + k + 1 None 1/2 BRTC k Branch if T Flag Cleared if (T = 0) then PC PC + k + 1 None 1/2 BRVS k Branch if Overflow Flag is Set if (V = 1) then PC PC + k + 1 None 1/2 BRVC k Branch if Overflow Flag is Cleared if (V = 0) then PC PC + k + 1 None 1/2 BRIE k Branch if Interrupt Enabled if ( I = 1) then PC PC + k + 1 None 1/2 BRID k Branch if Interrupt Disabled if ( I = 0) then PC PC + k + 1 None 1/2 BIT AND BIT-TEST INSTRUCTIONS SBI P,b Set Bit in I/O Register I/O(P,b) 1 None 2 CBI P,b Clear Bit in I/O Register I/O(P,b) 0 None 2 LSL Rd Logical Shift Left Rd(n+1) Rd(n), Rd(0) 0 Z,C,N,V 1 LSR Rd Logical Shift Right Rd(n) Rd(n+1), Rd(7) 0 Z,C,N,V 1 ROL Rd Rotate Left Through Carry Rd(0)C,Rd(n+1)Rd(n),CRd(7) Z,C,N,V 1 184 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 Mnemonics Operands Description Operation Flags #Clocks ROR Rd Rotate Right Through Carry Rd(7)C,Rd(n)Rd(n+1),CRd(0) Z,C,N,V ASR Rd Arithmetic Shift Right Rd(n) Rd(n+1), n=0..6 Z,C,N,V 1 1 SWAP Rd Swap Nibbles Rd(3..0)Rd(7..4),Rd(7..4)Rd(3..0) None 1 BSET s Flag Set SREG(s) 1 SREG(s) 1 BCLR s Flag Clear SREG(s) 0 SREG(s) 1 BST Rr, b Bit Store from Register to T T Rr(b) T 1 BLD Rd, b Bit load from T to Register Rd(b) T None 1 SEC Set Carry C 1 C 1 CLC Clear Carry C 0 C 1 SEN Set Negative Flag N 1 N 1 CLN Clear Negative Flag N 0 N 1 SEZ Set Zero Flag Z 1 Z 1 CLZ Clear Zero Flag Z 0 Z 1 SEI Global Interrupt Enable I 1 I 1 CLI Global Interrupt Disable I 0 I 1 SES Set Signed Test Flag S 1 S 1 CLS Clear Signed Test Flag S 0 S 1 SEV Set Twos Complement Overflow. V 1 V 1 1 CLV Clear Twos Complement Overflow V 0 V SET Set T in SREG T 1 T 1 CLT Clear T in SREG T 0 T 1 SEH CLH Set Half Carry Flag in SREG Clear Half Carry Flag in SREG H 1 H 0 H H 1 Rd Rr Rd+1:Rd Rr+1:Rr None 1 None 1 1 1 DATA TRANSFER INSTRUCTIONS MOV Rd, Rr Move Between Registers MOVW Rd, Rr Copy Register Word LDI Rd, K Load Immediate Rd K None LD Rd, X Load Indirect Rd (X) None 2 LD Rd, X+ Load Indirect and Post-Inc. Rd (X), X X + 1 None 2 LD Rd, - X Load Indirect and Pre-Dec. X X - 1, Rd (X) None 2 LD Rd, Y Load Indirect Rd (Y) None 2 LD Rd, Y+ Load Indirect and Post-Inc. Rd (Y), Y Y + 1 None 2 LD Rd, - Y Load Indirect and Pre-Dec. Y Y - 1, Rd (Y) None 2 LDD Rd,Y+q Load Indirect with Displacement Rd (Y + q) None 2 LD Rd, Z Load Indirect Rd (Z) None 2 LD Rd, Z+ Load Indirect and Post-Inc. Rd (Z), Z Z+1 None 2 LD Rd, -Z Load Indirect and Pre-Dec. Z Z - 1, Rd (Z) None 2 LDD Rd, Z+q Load Indirect with Displacement Rd (Z + q) None 2 LDS Rd, k Load Direct from SRAM Rd (k) None 2 ST X, Rr Store Indirect (X) Rr None 2 ST X+, Rr Store Indirect and Post-Inc. (X) Rr, X X + 1 None 2 ST - X, Rr Store Indirect and Pre-Dec. X X - 1, (X) Rr None 2 ST Y, Rr Store Indirect (Y) Rr None 2 ST Y+, Rr Store Indirect and Post-Inc. (Y) Rr, Y Y + 1 None 2 ST - Y, Rr Store Indirect and Pre-Dec. Y Y - 1, (Y) Rr None 2 STD Y+q,Rr Store Indirect with Displacement (Y + q) Rr None 2 ST Z, Rr Store Indirect (Z) Rr None 2 ST Z+, Rr Store Indirect and Post-Inc. (Z) Rr, Z Z + 1 None 2 ST -Z, Rr Store Indirect and Pre-Dec. Z Z - 1, (Z) Rr None 2 STD Z+q,Rr Store Indirect with Displacement (Z + q) Rr None 2 STS k, Rr Store Direct to SRAM (k) Rr None 2 Load Program Memory R0 (Z) None 3 LPM Rd, Z Load Program Memory Rd (Z) None 3 LPM Rd, Z+ Load Program Memory and Post-Inc Rd (Z), Z Z+1 None 3 Store Program Memory (z) R1:R0 None LPM SPM IN Rd, P In Port Rd P None 1 OUT P, Rr Out Port P Rr None 1 PUSH Rr Push Register on Stack STACK Rr None 2 POP Rd Pop Register from Stack Rd STACK None 2 MCU CONTROL INSTRUCTIONS NOP No Operation None 1 SLEEP Sleep (see specific descr. for Sleep function) None 1 WDR BREAK Watchdog Reset Break (see specific descr. for WDR/Timer) For On-chip Debug Only None None 1 N/A 185 7598H-AVR-07/09 26. Ordering Information Power Supply Notes: Speed (MHz) Ordering Code Package Operation Range 2.7 - 5.5V (3) 8 - 16 ATtiny25/45/85-15ST ATtiny25/45/85-15ST1 ATtiny25/45/85-15SZ T5 Automotive (-40C to +85C) Automotive (-40C to +105C) Automotive (-40C to 125C) 2.7 - 5.5V 8 - 16(3) ATtiny25/45/85-15MT ATtiny25/45/85-15MT1 ATtiny25/45/85-15MZ PC Automotive (-40C to 85C) Automotive (-40C to +105C) Automotive (-40C to +125C) 1. Green and ROHS packaging 2. Tape and Reel with Dry-pack delivery. 3. For Speed vs. VCC,see Figure 22-2 on page 152. Package Type T5 T5 - 8-lead, 0.208" Body Width Plastic Gull Wing Small Outline Package PC PC - 20-lead, 4.0x4.0 mm Body, 0.50 mm Pitch Quad Flat No Lead Package (QFN) 186 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 27. Packaging Information 27.1 T5 187 7598H-AVR-07/09 27.2 188 PC ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 28. Document Revision History 28.1 Revision 7598H - 07/09 1. Absolute Maximum Ratings updated 28.2 Revision 7598G - 03/08 1. Modified See "Power Management and Sleep Modes" on page 31. 2. Modified See "MCU Control Register - MCUCR" on page 31. 3. Modified Active Clock Domains and Wake-up Sources in the Different Sleep Modes33. 4. Added "Limitations" on page 33. 5. Modified "Power Reduction Register" on page 33. 28.3 Revision 7598F - 11/07 1. Correction to ICC Active, Table 22-1 on page 150. 28.4 Revision 7598E - 03/07 1. POR updated, see Section 8.3 on page 36. 28.5 Revision 7598D - 02/07 1. Clarification of Power On Reset Specifications table, Table 8-1 on page 37. 2. Errata list updated. 3. Added QFN packages. 28.6 Revision 7598C - 09/06 1. Correction of package codification and drawings. 28.7 Revision 7598B - 08/06 1. Clarification of several TBD values 2. Addition of the Power On Reset specification 3. DC characteristics Limits completed after corner run characterization 4. Typical Characteristic curves produced 28.8 Changes from Revision 2535A-09/01 to Revision 7598A-04/06 1. Automotive grade created: Features: - Change voltage and temperature range (2.7V - 5.5V), (-40C, +125C) - Adapt Stand-by current to automotive temperature range Packages: - PDIP removed - Ordering info limited to Automotive versions (green only, dry pack) DC & AC parameters - Only PRELIMINARY values are produced. 189 7598H-AVR-07/09 29. Errata The revision letter in this section refers to the revision of the ATtiny25/45/85 device. 29.1 ATtiny25, Revision E 1. No known errata. Flash security improvements. 29.2 ATtiny45, Revision G 1. No known errata. Flash security improvements. 29.3 ATtiny85, Revision C 1. No known errata. Flash security improvements. 190 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 30. Table of Contents Features ..................................................................................................... 1 1 Pin Configurations ................................................................................... 2 2 Overview ................................................................................................... 2 2.1 Block Diagram ...................................................................................................3 2.2 Automotive Quality Grade .................................................................................4 2.3 Pin Descriptions .................................................................................................5 3 About Code Examples ............................................................................. 5 4 AVR CPU Core .......................................................................................... 5 5 6 4.1 Introduction ........................................................................................................5 4.2 Architectural Overview .......................................................................................6 4.3 ALU - Arithmetic Logic Unit ...............................................................................7 4.4 Status Register ..................................................................................................7 4.5 General Purpose Register File ..........................................................................9 4.6 Stack Pointer ...................................................................................................10 4.7 Instruction Execution Timing ...........................................................................11 4.8 Reset and Interrupt Handling ...........................................................................11 AVR ATtiny25/45/85 Memories ............................................................. 13 5.1 In-System Re-programmable Flash Program Memory ....................................13 5.2 SRAM Data Memory ........................................................................................14 5.3 EEPROM Data Memory ..................................................................................15 5.4 I/O Memory ......................................................................................................21 System Clock and Clock Options ......................................................... 21 6.1 Clock Systems and their Distribution ...............................................................21 6.2 Clock Sources .................................................................................................23 6.3 Default Clock Source .......................................................................................24 6.4 Crystal Oscillator .............................................................................................24 6.5 Low-frequency Crystal Oscillator .....................................................................25 6.6 Calibrated Internal RC Oscillator .....................................................................26 6.7 External Clock .................................................................................................27 6.8 128 kHz Internal Oscillator ..............................................................................28 6.9 Clock Output Buffer .........................................................................................29 6.10 System Clock Prescaler ..................................................................................29 191 7598H-AVR-07/09 7 8 9 Power Management and Sleep Modes ................................................. 31 7.1 MCU Control Register - MCUCR ....................................................................31 7.2 Idle Mode .........................................................................................................32 7.3 ADC Noise Reduction Mode ............................................................................32 7.4 Power-down Mode ...........................................................................................32 7.5 Limitations .......................................................................................................33 7.6 Power Reduction Register ...............................................................................33 7.7 Minimizing Power Consumption ......................................................................34 System Control and Reset .................................................................... 35 8.1 Resetting the AVR ...........................................................................................35 8.2 Reset Sources .................................................................................................35 8.3 Power-on Reset ...............................................................................................36 8.4 External Reset .................................................................................................37 8.5 Brown-out Detection ........................................................................................38 8.6 Watchdog Reset ..............................................................................................39 8.7 MCU Status Register - MCUSR ......................................................................40 8.8 Internal Voltage Reference ..............................................................................40 8.9 Watchdog Timer ..............................................................................................41 8.10 Timed Sequences for Changing the Configuration of the Watchdog Timer ....44 Interrupts ................................................................................................ 45 9.1 Interrupt Vectors in ATtiny25/45/85 .................................................................45 10 I/O Ports .................................................................................................. 46 10.1 Introduction ......................................................................................................46 10.2 Ports as General Digital I/O .............................................................................47 10.3 Alternate Port Functions ..................................................................................52 10.4 Register Description for I/O-Ports ....................................................................58 11 External Interrupts ................................................................................. 58 11.1 MCU Control Register - MCUCR ....................................................................59 11.2 General Interrupt Mask Register - GIMSK ......................................................59 11.3 General Interrupt Flag Register - GIFR ..........................................................60 11.4 Pin Change Mask Register - PCMSK .............................................................60 12 8-bit Timer/Counter0 with PWM ............................................................ 61 192 12.1 Overview ..........................................................................................................61 12.2 Timer/Counter Clock Sources .........................................................................62 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 12.3 Counter Unit ....................................................................................................62 12.4 Output Compare Unit .......................................................................................63 12.5 Compare Match Output Unit ............................................................................65 12.6 Modes of Operation .........................................................................................66 12.7 Timer/Counter Timing Diagrams .....................................................................70 12.8 8-bit Timer/Counter Register Description ........................................................72 13 Timer/Counter Prescaler ....................................................................... 78 13.1 Prescaler Reset ...............................................................................................78 13.2 External Clock Source .....................................................................................79 14 Counter and Compare Units ................................................................. 81 14.1 Timer/Counter1 ................................................................................................81 15 Dead Time Generator ............................................................................. 93 15.1 Timer/Counter1 Dead Time Prescaler register 1 - DTPS1 ..............................94 15.2 Timer/Counter1 Dead Time A - DT1A .............................................................95 15.3 Timer/Counter1 Dead Time B - DT1B .............................................................95 16 Universal Serial Interface - USI ............................................................ 96 16.1 Overview ..........................................................................................................96 16.2 Functional Descriptions ...................................................................................97 16.3 Alternative USI Usage ...................................................................................103 16.4 USI Register Descriptions .............................................................................103 17 Analog Comparator ............................................................................. 108 17.1 ADC Control and Status Register B - ADCSRB ...........................................108 17.2 Analog Comparator Control and Status Register - ACSR ............................108 17.3 Analog Comparator Multiplexed Input ...........................................................110 18 Analog to Digital Converter ................................................................ 111 18.1 Features ........................................................................................................111 18.2 Operation .......................................................................................................112 18.3 Starting a Conversion ....................................................................................113 18.4 Prescaling and Conversion Timing ................................................................114 18.5 Changing Channel or Reference Selection ...................................................117 18.6 ADC Noise Canceler .....................................................................................118 18.7 ADC Conversion Result .................................................................................121 19 debugWIRE On-chip Debug System .................................................. 128 19.1 Features ........................................................................................................128 193 7598H-AVR-07/09 19.2 Overview ........................................................................................................128 19.3 Physical Interface ..........................................................................................128 19.4 Software Break Points ...................................................................................129 19.5 Limitations of debugWIRE .............................................................................129 19.6 debugWIRE Related Register in I/O Memory ................................................129 20 Self-Programming the Flash ............................................................... 130 20.1 Performing Page Erase by SPM ....................................................................130 20.2 Filling the Temporary Buffer (Page Loading) .................................................130 20.3 Performing a Page Write ...............................................................................131 20.4 Addressing the Flash During Self-Programming ...........................................131 21 Memory Programming ......................................................................... 134 21.1 Program And Data Memory Lock Bits ...........................................................134 21.2 Fuse Bytes .....................................................................................................135 21.3 Signature Bytes .............................................................................................137 21.4 Calibration Byte .............................................................................................137 21.5 Page Size ......................................................................................................137 21.6 Serial Downloading ........................................................................................138 21.7 High-voltage Serial Programming ..................................................................142 21.8 High-voltage Serial Programming Algorithm Sequence ................................144 21.9 High-voltage Serial Programming Characteristics .........................................149 22 Electrical Characteristics .................................................................... 150 22.1 Absolute Maximum Ratings* .........................................................................150 22.2 External Clock Drive Waveforms ...................................................................151 22.3 External Clock Drive ......................................................................................152 22.4 ADC Characteristics - Preliminary Data ........................................................153 22.5 Calibrated RC Oscillator Accuracy ................................................................154 23 Typical Characteristics ........................................................................ 154 194 23.1 Active Supply Current ....................................................................................155 23.2 Idle Supply Current ........................................................................................157 23.3 Power-Down Supply Current .........................................................................161 23.4 Pin Pull-up .....................................................................................................162 23.5 Pin Driver Strength ........................................................................................165 23.6 Pin Thresholds and Hysteresis ......................................................................168 23.7 BOD Thresholds and Analog Comparator Offset ..........................................171 23.8 Internal Oscillator Speed ...............................................................................172 ATtiny25/45/85 7598H-AVR-07/09 ATtiny25/45/85 23.9 Current Consumption of Peripheral Units ......................................................175 23.10 Current Consumption in Reset and Reset Pulse width .................................176 23.11 Analog to Digital Converter ............................................................................177 24 Register Summary .............................................................................. 182 25 Instruction Set Summary .................................................................... 184 26 Ordering Information ........................................................................... 186 27 Packaging Information ........................................................................ 187 27.1 T5 ..................................................................................................................187 27.2 PC ..................................................................................................................188 28 Document Revision History ................................................................ 189 28.1 Revision 7598H - 07/09 .................................................................................189 28.2 Revision 7598G - 03/08 .................................................................................189 28.3 Revision 7598F - 11/07 .................................................................................189 28.4 Revision 7598E - 03/07 .................................................................................189 28.5 Revision 7598D - 02/07 .................................................................................189 28.6 Revision 7598C - 09/06 .................................................................................189 28.7 Revision 7598B - 08/06 .................................................................................189 28.8 Changes from Revision 2535A-09/01 to Revision 7598A-04/06 ...................189 29 Errata ..................................................................................................... 190 29.1 ATtiny25, Revision E .....................................................................................190 29.2 ATtiny45, Revision G .....................................................................................190 29.3 ATtiny85, Revision C .....................................................................................190 30 Table of Contents ................................................................................. 191 195 7598H-AVR-07/09 Headquarters International Atmel Corporation 2325 Orchard Parkway San Jose, CA 95131 USA Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Atmel Asia Unit 1-5 & 16, 19/F BEA Tower, Millennium City 5 418 Kwun Tong Road Kwun Tong, Kowloon Hong Kong Tel: (852) 2245-6100 Fax: (852) 2722-1369 Atmel Europe Le Krebs 8, Rue Jean-Pierre Timbaud BP 309 78054 Saint-Quentin-en-Yvelines Cedex France Tel: (33) 1-30-60-70-00 Fax: (33) 1-30-60-71-11 Atmel Japan 9F, Tonetsu Shinkawa Bldg. 1-24-8 Shinkawa Chuo-ku, Tokyo 104-0033 Japan Tel: (81) 3-3523-3551 Fax: (81) 3-3523-7581 Technical Support avr@atmel.com Sales Contact www.atmel.com/contacts Product Contact Web Site www.atmel.com Literature Requests www.atmel.com/literature Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMEL'S TERMS AND CONDITIONS OF SALE LOCATED ON ATMEL'S WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel's products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. (c) 2009 Atmel Corporation. All rights reserved. Atmel(R), logo and combinations thereof, AVR (R), AVR Studio (R) and others are registered trademarks or trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others. 7598H-AVR-07/09