ATTINY13V_0701 ATMEL | Alldatasheet

Document overview

  • Manufacturer or author: Provided By ALLDATASHEET.COM(FREE DATASHEET DOWNLOAD SITE)
  • PDF pages: 177

Technical content

Features

 High Performance, Low Power AVR® 8-Bit Microcontroller  Advanced RISC Architecture – 120 Powerful Instructions – Most Single Clock Cycle Execution – 32 x 8 General Purpose Working Registers – Fully Static Operation – Up to 20 MIPS Througput at 20 MHz  Non-volatile Program and Data Memories – 1K Byte of In-System Progra mmable Program Memory Flash Endurance: 10,000 Write/Erase Cycles – 64 Bytes In-System Programmable EEPROM Endurance: 100,000 Write/Erase Cycles – 64 Bytes Internal SRAM – Programming Lock for Self-Programming Flash Program and EEPROM Data Security  Peripheral Features – One 8-bit Timer/Counter with Prescaler and Two PWM Channels – 4-channel, 10-bit ADC with Internal Voltage Reference – 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 – 8-pin PDIP/SOIC: Six Programmable I/O Lines – 20-pad MLF: Six Programmable I/O Lines  Operating Voltage: – 1.8 - 5.5V for ATtiny13V – 2.7 - 5.5V for ATtiny13  Speed Grade – ATtiny13V: 0 - 4 MHz @ 1.8 - 5.5V, 0 - 10 MHz @ 2.7 - 5.5V – ATtiny13: 0 - 10 MHz @ 2.7 - 5.5V, 0 - 20 MHz @ 4.5 - 5.5V  Industrial Temperature Range  Low Power Consumption – Active Mode: 1 MHz, 1.8V: 240µA – Power-down Mode: < 0.1µA at 1.8V 8-bit Microcontroller with 1K Bytes In-System Programmable Flash ATtiny13V ATtiny13 Rev. 2535G–AVR–01/07

2 ATtiny13

2535G–AVR–01/07 Pin Configurations Figure 1. Pinout ATtiny13 Overview The ATtiny13 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced RISC architecture. By executing powerful in structions in a single clock cycle, the ATtiny13 achieves throughputs approaching 1 MIPS per MHz allowing the system designer to optimize power consumption versus processing speed. (PCINT5/RESET/ADC0/dW) PB5 (PCINT3/CLKI/ADC3) PB3 (PCINT4/ADC2) PB4 GND VCC PB2 (SCK/ADC1/T0/PCINT2) PB1 (MISO/AIN1/OC0B/INT0/PCINT1) PB0 (MOSI/AIN0/OC0A/PCINT0) PDIP/SOIC QFN/MLF (PCINT5/RESET/ADC0/dW) PB5 (PCINT3/CLKI/ADC3) PB3 DNC DNC (PCINT4/ADC2) PB4 DNC DNC GND DNC DNC VCC PB2 (SCK/ADC1/T0/PCINT2) DNC PB1 (MISO/AIN1/OC0B/INT0/PCINT1) PB0 (MOSI/AIN0/OC0A/PCINT0) DNC DNC DNC DNC DNC NOTE: Bottom pad should be soldered to ground. DNC: Do Not Connect

2535G–AVR–01/07 Block Diagram Figure 2. Block Diagram PROGRAM COUNTER INTERNAL OSCILLATOR WATCHDOG TIMER STACK POINTER PROGRAM FLASH SRAM MCU CONTROL REGISTER GENERAL PURPOSE REGISTERS INSTRUCTION REGISTER TIMER/ COUNTER0 INSTRUCTION DECODER DATA DIR. REG.PORT B DATA REGISTER PORT B PROGRAMMING LOGIC TIMING AND CONTROL MCU STATUS REGISTER STATUS REGISTER ALU PORT B DRIVERS PB0-PB5 VCC GND CONTROL LINES 8-BIT DATABUS Z ADC / ANALOG COMPARATOR INTERRUPT UNIT CALIBRATED Y X RESET CLKI WATCHDOG OSCILLATOR DATA EEPROM

4 ATtiny13

2535G–AVR–01/07 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. The ATtiny13 provides the following featur es: 1K byte of In-System Programmable Flash, 64 bytes EEPROM, 64 bytes SRAM, 6 general purpose I/O lines, 32 general pur- pose working registers, one 8-bit Timer/C ounter with compare modes, 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 con- tents, 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’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 ATtiny13 AVR is supported with a full suite of program and system development tools including: C Compilers, Macro Assemblers, Program Debugger/Simulators, In-Cir- cuit Emulators, and Evaluation kits. Pin Descriptions VCC Digital supply voltage. GND Ground. 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 pi ns 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 ATtiny13 as listed on page 51. RESET Reset input. A low level on this pin for longer than the minimum pulse length will gener- ate a reset, even if the clock is not running. The minimum pulse length is given in Table 12 on page 31. Shorter pulses are not guaranteed to generate a reset. 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 defini- tions in the header files and interrupt handling in C is compiler dependent. Please confirm with the C compiler documentation for more details.

2535G–AVR–01/07 AVR CPU Core Introduction This section discusses the AVR core archit ecture in general. The main function of the CPU core is to ensure correct program execution. The CPU must therefore be able to access memories, perform calculations, control peripherals, and handle interrupts. Architectural Overview Figure 3. Block Diagram of the AVR Architecture 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 pipel ining. While one instruction is being exe- cuted, the next instruction is pre-fetched from the Program memory. This concept enables instructions to be executed in ever y 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, Flash Program Memory Instruction Register Instruction Decoder Program Counter Control Lines 32 x 8 General Purpose Registrers ALU Status and Control I/O Lines EEPROM Data Bus 8-bit Data SRAM Direct AddressingIndirect Addressing Interrupt Unit Watchdog Timer Analog Comparator I/O Module 2 I/O Module1 I/O Module n

6 ATtiny13

2535G–AVR–01/07 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 Pro- gram memory. These added function registers are the 16-bit X-, Y-, and Z-register, described later in this section. The ALU supports arithmetic and logic operations between registers or between a con- stant 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 s pace. Most AVR instructions have a single 16-bit word format. Every Program memory address contains a 16- or 32-bit instruction. 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 addresse s 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. 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-func- tions. Some implementations of the architecture also provide a powerful multiplier supporting both signed/unsigned multiplication and fractional format. See the “Instruc- tion Set” section for a detailed description.

2535G–AVR–01/07 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 Instructio n 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 – I: Global Interrupt Enable The Global Interrupt Enable bit must be set for the interrupts to be enabled. The individ- ual interrupt enable control is then performed in separate control registers. If the Global Interrupt Enable Register is cleared, n one 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 Comple- ment 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 arit hmetic or logic operation. See the “Instruc- tion Set Description” for detailed information. B i t 76543210 I T H S V N Z C SREG Read/Write R/W R/W R/W R/W R/W R/W R/W R/W Initial Value 0 0 0 0 0 0 0 0

8 ATtiny13

Figure 4 shows the structure of the 32 general purpose working registers in the CPU. Figure 4. AVR CPU General Purpose Working Registers and most of them are single cycle instructions. index any register in the file.

The registers R26..R31 have some added f unctions 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 5. Figure 5. The X-, Y -, and Z-registers PUSH command decreases the Stack Pointer. RET or return from interrupt RETI. case, the SPH Register will not be present.

15 XH XL 0

15 YH YL 0

15 ZH ZL 0

10 ATtiny13

source for the chip. No internal clock division is used. functions per cost, functions per clocks, and functions per power-unit. Figure 6. The Parallel Instruction Fetches and Instruction Executions to the destination register. Figure 7. Single Cycle ALU Operation with the Global Interrupt Enable bit in the Status Register in order to enable the interrupt. INT0 – the External Interrupt Request 0. automatically set when a Return from Interrupt instruction – RETI – is executed.

2535G–AVR–01/07 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. Interr upt 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 remem- bered 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 cor- responding 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 disap- pears 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 exe- cute one more instruction before any pending interrupt is served. Note that the Status Register is not automatically stored when entering an interrupt rou- tine, nor restored when returning from an interrupt routine. This must be handled by software. When using the CLI instruction to disable in terrupts, the interrupts will be immediately disabled. No interrupt will be executed after the CLI instruction, even if it occurs simulta- neously 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 ; store SREG value cli ; disable interrupts during timed sequence sbiEECR, EEMPE ; start EEPROM write sbiEECR, EEPE outSREG, r16 ; restore SREG value (I-bit) C Code Example char cSREG; cSREG = SREG;/* store SREG value */ /* disable interrupts during timed sequence */ __disable_interrupt(); EECR |= (1<<EEMPE); /* start EEPROM write */ EECR |= (1<<EEPE); SREG = cSREG; /* restore SREG value (I-bit) */

12 ATtiny13

2535G–AVR–01/07 When using the SEI instructio n to enable interrupts, the in struction following SEI will be executed before any pending interrupts, as shown in this example. Interrupt Response Time The interrupt execution response for all the enabled AVR interrupts is four clock cycles minimum. After four clock cycles the Progr am Vector address for the actual interrupt handling routine is executed. During this four clock cycle period, the Program Counter is pushed onto the Stack. The vector is normally a jump to the interrupt routine, and this jump takes three clock cycles. If an interr upt occurs during execution of a multi-cycle instruction, this instruction is completed before the interrupt is served. If an interrupt occurs when the MCU is in sleep mode, the interrupt execution response time is increased by four clock cycles. This increase comes in addition to the start-up time from the selected sleep mode. A return from an interrupt handling routine ta kes four clock cycles. During these four clock cycles, the Program Counter (two bytes) is popped back from the Stack, the Stack Pointer is incremented by two, and the I-bit in SREG is set. Assembly Code Example sei ; set Global Interrupt Enable sleep; enter sleep, waiting for interrupt ; note: will enter sleep before any pending ; interrupt(s) C Code Example __enable_interrupt(); /* set Global Interrupt Enable */ __sleep(); /* enter sleep, waiting for interrupt */ /* note: will enter sleep before any pending interrupt(s) */

spaces are linear and regular. on Flash data serial downloading using the SPI pins. the LPM – Load Program memory instruction description). Figure 8. Program Memory Map

14 ATtiny13

SRAM Data Memory Figure 9 shows how the ATtiny13 SRAM Memory is organized. the Register File, registers R26 to R31 feature the indirect addressing pointer registers. The direct addressing reaches the entire data space. address given by the Y- or Z-register. increment, the address registers X, Y, and Z are decremented or incremented. Register File is described in “General Purpose Register File” on page 8. Figure 9. Data Memory Map Data Memory Access Times This section describes the general access ti ming concepts for internal memory access. Figure 10. On-chip Data SRAM Access Cycles

32 Registers

64 I/O Registers

2535G–AVR–01/07 EEPROM Data Memory The ATtiny13 contains 64 bytes of data EEPROM memory. It is organized as a separate data space, in which single bytes can be read and written. The EEPROM has an endur- ance of at least 100,000 write/erase cycles. The access between the EEPROM and the CPU is described in the following, specifying the EEPROM Address Registers, the EEPROM Data Register, and the EEPROM Control Register. For a detailed description of Serial data downloading to the EEPROM, see page 107. EEPROM Read/Write Access The EEPROM Access Registers are accessible in the I/O space. The write access times for the EEPROM are given in Table 1. A self-timing function, however, lets the user software detect when the next byte can be written. If the user code contains instructions that write the EEPROM, some precautions must be taken. In heavily filtered power supplies, V CC is likely to rise or fall slowly on Power-up/down. This causes the device for some period of time to run at a voltage lower than specified as minimum for the clock frequency used. See “Preventing EEPROM Corruption” on page 19 for details on how to avoid problems in these situations. In order to prevent unintentional EEPROM writes, a specific write procedure must be fol- lowed. Refer to “Atomic Byte Programming” on page 17 and “Split Byte Programming” on page 17 for details on this. When the EEPROM is read, the CPU is halt ed for four clock cycles before the next instruction is executed. When the EEPROM is written, the CPU is halted for two clock cycles before the next instruction is executed. EEPROM Address Register – EEARL  Bits 7..6 – Res: Reserved Bits These bits are reserved bits in the ATtiny13 and will always read as zero.  Bits 5..0 – EEAR5..0: EEPROM Address The EEPROM Address Register – EEARL – specifies the EEPROM address in the 64 bytes EEPROM space. The EEPROM data bytes are addressed linearly between 0 and 63. The initial value of EEARL is undefined. A prop er value must be written before the EEPROM may be accessed. EEPROM Data Register – EEDR  Bits 7..0 – EEDR7..0: EEPROM Data For the EEPROM write operation the EEDR Register contains the data to be written to the EEPROM in the address given by the EEARL Register. For the EEPROM read oper- ation, the EEDR contains the data read out from the EEPROM at the address given by EEARL. B i t 76543210 – – EEAR5 EEAR4 EEAR3 EEAR2 EEAR1 EEAR0 EEARL Read/Write R R R/W R/W R/W R/W R/W R/W Initial Value 0 0 X X X X X X B i t 76543210 EEDR7 EEDR6 EEDR5 EEDR4 EEDR3 EEDR2 EEDR1 EEDR0 EEDR Read/Write R/W R/W R/W R/W R/W R/W R/W R/W Initial Value X X X X X X X X

16 ATtiny13

with future AVR devices, always write this bit to zero. After reading, mask out this bit. This bit is reserved in the ATtiny13 and will always read as zero. reset, the EEPMn bits will be reset to 0b00 unless the EEPROM is busy programming. Writing EERIE to one enables the EEPROM Ready Interrupt if the I-bit in SREG is set. constant interrupt when Non-volatile memory is ready for programming. The EEMPE bit determines whether writing EEPE to one will have effect or not. halted for two cycles before the next instruction is executed. Table 1. EEPROM Mode Bits

2535G–AVR–01/07 one to trigger the EEPROM read. The EEPROM read access takes one instruction, and the requested data is availabl e immediately. When the EE PROM is read, the CPU is halted for four cycles before the next instruction is executed. The user should poll the EEPE bit before starting the read operation. If a write operation is in progress, it is nei- ther possible to read the EEPROM, nor to change the EEARL Register. Atomic Byte Programming Using Atomic Byte Programming is the simp lest mode. When writing a byte to the EEPROM, the user must write the address into the EEARL Register and data into EEDR Register. If the EEPMn bits are zero, writi ng EEPE (within four cycles after EEMPE is written) will trigger the erase/write operation. Both the erase and write cycle are done in one operation and the total programming time is given in Table 1. The EEPE bit remains set until the erase and write operations are completed. While the device is busy with programming, it is not possible to do any other EEPROM operations. Split Byte Programming It is possible to split the erase and write cycle in two diff erent operations. This may be useful if the system requires short access time for some limited period of time (typically if the power supply voltage falls). In order to take advantage of this method, it is required that the locations to be written have been erased before the write operation. But since the erase and write operations are split, it is possible to do the erase operations when the system allows doing time-critical operations (typically after Power-up). Erase To erase a byte, the addres s must be written to EEARL. If the EEPMn bits are 0b01, writing the EEPE (within four cycles after EEMPE is written) will trigger the erase opera- tion only (progr amming time is given in Table 1). The EEPE bit remains set until the erase operation completes. While the device is busy programming, it is not possible to do any other EEPROM operations. Write To write a location, the user must write the address into EEARL and the data into EEDR. If the EEPMn bits are 0b10, writing the EEPE (within four cycles after EEMPE is written) will trigger the write operation only (programming time is given in Table 1). The EEPE bit remains set until the write operation completes. If the location to be written has not been erased before write, the data that is stored must be considered as lost. While the device is busy with programming, it is not possible to do any other EEPROM operations. The calibrated Oscillator is used to time the EEPROM accesses. Make sure the Oscilla- tor frequency is within the requirements desc ribed in “Oscillator Calibration Register – OSCCAL” on page 23.

18 ATtiny13

2535G–AVR–01/07 The following code examples show one assembly and one C function for erase, write, or atomic write of the EEPROM. The examples assume that interrupts are controlled (e.g., by disabling interrupts globally) so that no interrupts will occur during execution of these functions. Assembly Code Example EEPROM_write: ; Wait for completion of previous write sbic EECR,EEPE rjmp EEPROM_write ; Set Programming mode ldi r16, (0<<EEPM1)|(0<<EEPM0) out EECR, r16 ; Set up address (r17) in address register out EEARL, r17 ; Write data (r16) to data register out EEDR,r16 ; Write logical one to EEMPE sbi EECR,EEMPE ; Start eeprom write by setting EEPE sbi EECR,EEPE ret C Code Example void EEPROM_write(unsigned char ucAddress, unsigned char ucData) /* Wait for completion of previous write */ while(EECR & (1<<EEPE)) /* Set Programming mode */ EECR = (0<<EEPM1)|(0>>EEPM0) /* Set up address and data registers */ EEARL = ucAddress; EEDR = ucData; /* Write logical one to EEMPE */ EECR |= (1<<EEMPE); /* Start eeprom write by setting EEPE */ EECR |= (1<<EEPE);

2535G–AVR–01/07 The next code examples show assembly and C functions for reading the EEPROM. The examples assume that interr upts are controlled so that no interrupts will occur during execution of these functions. Preventing EEPROM Corruption During periods of low VCC, the EEPROM data can be corrupted because the supply volt- age is too low for the CPU and the EEPROM to operate properly. These issues are the same as for board level systems using EEPROM, and the same design solutions should be applied. An EEPROM data corruption can be caused by two situations when the voltage is too low. First, a regular write sequence to the EEPROM requires a minimum voltage to operate correctly. Secondly, the CPU itself ca n execute instructions incorrectly, if the supply voltage is too low. EEPROM data corruption can easily be avoided by following this design recommendation: Keep the AVR RESET active (low) during pe riods of insufficient power supply voltage. This can be done by enabling the internal Brown-out Detector (BOD). If the detection level of the internal BOD does not match the needed detection level, an external low V CC reset protection circuit can be used. If a reset occurs while a write operation is in progress, the write operation will be completed provided that the power supply voltage is sufficient. Assembly Code Example EEPROM_read: ; Wait for completion of previous write sbic EECR,EEPE rjmp EEPROM_read ; Set up address (r17) in address register out EEARL, r17 ; Start eeprom read by writing EERE sbi EECR,EERE ; Read data from data register in r16,EEDR ret C Code Example unsigned char EEPROM_read(unsigned char ucAddress) /* Wait for completion of previous write */ while(EECR & (1<<EEPE)) /* Set up address register */ EEARL = ucAddress; /* Start eeprom read by writing EERE */ EECR |= (1<<EERE); /* Return data from data register */ return EEDR;

20 ATtiny13

2535G–AVR–01/07 I/O Memory The I/O space definition of the ATtiny13 is shown in “Register Summary” on page 159. All ATtiny13 I/Os and peripherals are placed in the I/O space. All I/O locations may be accessed by the LD/LDS/LDD and ST/STS/STD instructions, transferring data between the 32 general purpose working registers and the I/O space. I/O Registers within the address range 0x00 - 0x1F are directly bit-accessible using the SBI and CBI instruc- tions. In these registers, the value of single bits can be checked by using the SBIS and SBIC instructions. Refer to the instruction set section for more details. When using the I/O specific commands IN and OUT, the I/O addresses 0x00 - 0x3F must be used. When addressing I/O Registers as data space using LD and ST instructions, 0x20 must be added to these addresses. For compatibility with future devices, reserved bits should be written to zero if accessed. Reserved I/O memory addresses should never be written. Some of the Status Flags are cleared by writing a logical one to them. Note that, unlike most other AVRs, the CBI and SBI instructions will only operate on the specified bit, and can therefore be used on registers containing such Status Flags. The CBI and SBI instructions work with registers 0x00 to 0x1F only. The I/O and Peripherals Control Registers are explained in later sections.

22 ATtiny13

and routed to the appropriate modules.Note: 1. For all fuses “1” means unprogrammed while “0” means programmed. time the start-up, ensuring stable Oscillator operation before instruction execution starts. used for each time-out is shown in Table 3. Table 2. Device Clocking Options Select

value, see the section “Calibration Byte” on page 106. Note: 1. The device is shipped with this option selected. Note: 1. The device is shipped with this option selected. This bit is reserved bit in the ATtiny13 and will always read as zero. Table 4. Internal Calibrated RC Oscillator Operating Modes Table 5. Start-up Times for the Internal Calibrated RC Oscillator Clock Selection

11 Reserved

24 ATtiny13

write may fail. Note that the Oscillator is intended for calibration to 9.6 MHz or 4.8 MHz. Tuning to other values is not guaranteed, as indicated in Table 6. OSCCAL-register should not exceed 0x20 for each calibration. Figure 12. To run the device on an extern al clock, the CKSEL Fuses must be pro- Figure 12. External Clock Drive Configuration Prescaler” on page 25 for details. Table 6. Internal RC Oscillator Frequency Range Table 7. Start-up Times for the External Clock Selection

The 128 kHz internal Oscillato r is a low power Oscillator pr oviding a clock of 128 kHz. by programming the CKSEL Fuses to “11”. clkCPU, and clkFLASH are divided by a factor as shown in Table 9. extend the time-out period, nor clear the CLKPCE bit. These bits are reserved bits in the ATtiny13 and will always read as zero. sion factors are given in Table 9.

  1. Write the Clock Prescaler Change Enable (CLKPCE) bit to one and all other bits
  2. Within four cycles, write the desire d value to CLKPS while writing a zero to

Table 8. Start-up Times for the 128 kHz Internal Oscillator

26 ATtiny13

tions. The device is shipped with the CKDIV8 Fuse programmed. quency corresponding to the new setting. takes to switch from one clock division to another cannot be exactly predicted. Table 9. Clock Prescaler Select

1001 R e s e r v e d

1010 R e s e r v e d

1011 R e s e r v e d

1100 R e s e r v e d

1101 R e s e r v e d

1110 R e s e r v e d

1111 R e s e r v e d

trollers an ideal choice for low power applications. power consumption to the application’s requirements. during sleep mode, the MCU wakes up and executes from the Reset Vector. tribution. The figure is helpful in selecting an appropriate sleep mode. The MCU Control Register contains control bits for power management. These bits select between the three available sleep modes as shown in Table 10. This bit is a reserved bit in the ATtiny13 and will always read as zero. Table 10. Sleep Mode Select

00 I d l e

11 R e s e r v e d

28 ATtiny13

CPU and clkFLASH, while allowing the other clocks to run. clkCPU, and clkFLASH, while allowing the other clocks to run. rupts” on page 54 for details. Note: 1. For INT0, only level interrupt. Table 11. Active Clock Domains and Wake-up Sources in the Different Sleep Modes

2535G–AVR–01/07 Minimizing Power Consumption There are several issues to consider when trying to minimize the power consumption in an AVR controlled system. In general, sleep modes should be used as much as possi- ble, and the sleep mode should be selected so that as few as pos sible of the device’s functions are operating. All functions not needed should be disabled. In particular, the following modules may need special consider ation when trying to achieve the lowest possible power consumption. Analog to Digital Converter If enabled, the ADC will be enabled in all sleep modes. To save power, the ADC should be disabled before entering any sleep mode. When the ADC is turned off and on again, the next conversion will be an extended conversion. Refer to “Analog to Digital Con- verter” on page 80 for details on ADC operation. Analog Comparator When entering Idle mode, the Analog Comparator should be disabled if not used. When entering ADC Noise Reduction mode, the Analog Comparator should be disabled. In the other sleep modes, the Analog Comparator is automatically disabled. However, if the Analog Comparator is set up to use the Internal Voltage Reference as input, the Analog Comparator should be disabled in all sleep modes. Otherwise, the Internal Voltage Ref- erence will be enabled, independent of sleep mode. Refer to “Analog Comparator” on page 77 for details on how to configure the Analog Comparator. Brown-out Detector If the Brown-out Detector is not needed in the application, this module should be turned off. If the Brown-out Detector is enabled by the BODLEVEL Fuses, it will be enabled in all sleep modes, and hence, always consume power. In the deeper sleep modes, this will contribute significantly to the total curr ent consumption. Refer to “Brown-out Detec- tion” on page 33 for details on how to configure the Brown-out Detector. Internal Voltage Reference The Internal Voltage Reference will be enabled when needed by the Brown-out Detec- tion, the Analog Comparator or the ADC. If these modules are disabled as described in the sections above, the internal voltage reference will be disabled and it will not be con- suming power. When turned on again, the user must allow the reference to start up before the output is used. If the reference is kept on in sleep mode, the output can be used immediately. Refer to “Internal Voltage Reference” on page 35 for details on the start-up time. Watchdog Timer If the Watchdog Timer is not needed in the application, this module should be turned off. If the Watchdog Timer is enabled, it will be enabled in all sleep modes, and hence, always consume power. In the deeper sleep modes, this will contribute significantly to the total current consumption. Refer to “Interrupts” on page 42 for details on how to con- figure the Watchdog Timer. Port Pins When entering a sleep mode, all port pins should be configured to use minimum power. The most important thing is then to ensure that no pins drive resistive loads. In sleep modes where both the I/O clock (clk I/O) and the ADC clock (clk ADC) are stopped, the input buffers of the device will be disabled. This ensure s that no power is consumed by the input logic when not needed. In some cases, the input logic is needed for detecting wake-up conditions, and it will then be enabled. Refer to the section “Digital Input Enable and Sleep Modes” on page 47 for details on which pins are enabled. If the input buffer is enabled and the input signal is left floating or has an analog signal level close to V CC/2, the input buffer will use excessive power. For analog input pins, the digital input buffe r should be disabled at all times. An analog signal level close to V CC/2 on an input pin can cause signi ficant current even in active mode. Digital input buffers can be disabled by writing to the Digital Input Disable Regis- ter (DIDR0). Refer to “Digital Input Disable Register 0 – DIDR0” on page 79 for details.

30 ATtiny13

2535G–AVR–01/07 System Control and Reset Resetting the AVR During reset, all I/O Registers are set to their initial values, and the program starts exe- cution from the Reset Vector. The instructio n placed at the Reset Vector must be a RJMP – Relative Jump – instruction to the reset handling routine. If the program never enables an interrupt source, the Interrupt Vectors are not used, and regular program code can be placed at these locations. The circuit diagram in Figure 13 shows the reset logic. Table 12 defines the electrical parameters of the reset circuitry. The I/O ports of the AVR are immediately reset to their initial state when a reset source goes active. This does not require any clock source to be running. After all reset sources have gone inactive, a delay counter is invoked, stretching the internal reset. This allows the power to reach a stable level before normal operation starts. The time-out period of the delay count er is defined by the user through the SUT and CKSEL Fuses. The different selections for the delay period are presented in “Clock Sources” on page 22. Reset Sources The ATtiny13 has four sources of reset:  Power-on Reset. The MCU is reset when the supply voltage is below the Power-on Reset threshold (V POT).  External Reset. The MCU is reset when a low level is present on the RESET pin for longer than the minimum pulse length.  Watchdog Reset. The MCU is reset when the Watchdog Timer period expires and the Watchdog is enabled.  Brown-out Reset. The MCU is reset when the supply voltage V CC is below the Brown-out Reset threshold (VBOT) and the Brown-out Detector is enabled.

Figure 13. Reset Logic Table 12. Reset Characteristics

32 ATtiny13

detect a failure in supply voltage. again, without any delay, when VCC decreases below the detection level. Figure 14. MCU Start-up, RESET Tied to VCC Figure 15. MCU Start-up, RESET Extended Externally

the delay counter starts the MCU after the Time-out period – t TOUT – has expired. Figure 16. External Reset During Operation BOT+ = VBOT + VHYST/2 and VBOT- = VBOT - VHYST/2. to a voltage where correct operation of the microcontroller is no longer guaranteed. out period tTOUT has expired. for longer than tBOD given in Table 14. Table 13. BODLEVEL Fuse Coding(1)

11 BOD Disabled

Table 14. Brown-out Characteristics

34 ATtiny13

Figure 17. Brown-out Reset During Operation TOUT. Refer to page 42 for details on operation of the Watchdog Timer. Figure 18. Watchdog Reset During Operation These bits are reserved bits in the ATtiny13 and will always read as zero. writing a logic zero to the flag. writing a logic zero to the flag.

writing a logic zero to the flag. Detection, and it can be used as an input to the Analog Comparator or the ADC. The voltage reference has a start-up time that may influence the way it should be used.

  1. When the BOD is enabled (by pr ogramming the BODLEVEL [1..0] Fuse).
  2. When the bandgap reference is connected to the Analog Comparator (by setting

Table 15. Internal Voltage Reference Characteristics

36 ATtiny13

Figure 19. Watchdog Timer

  1. In the same operation, write a logic one to the Watchdog change enable bit
  2. Within the next four clock cycles, write the WDE and Watchdog prescaler bits

2535G–AVR–01/07 The following code example shows one assembly and one C function for turning off the Watchdog Timer. The example assumes that interrupts are controlled (e.g. by disabling interrupts globally) so that no interrupts wi ll occur during the execution of these functions. Note: 1. The example code assumes that the pa rt specific header file is included. Note: If the Watchdog is accidentally enabled, for example by a runaway pointer or brown-out condition, the device will be reset and the Watchdog Timer will stay enabled. If the code is not set up to handle the Watchdog, this might lead to an eternal loop of time-out resets. To avoid this situation, the application software should always clear the Assembly Code Example (1) WDT_off: ; Turn off global interrupt cli ; Reset Watchdog Timer wdr ; Clear WDRF in MCUSR in r16, MCUSR andi r16, (0xff & (0<<WDRF)) out MCUSR, r16 ; Write logical one to WDCE and WDE ; Keep old prescaler setting to prevent unintentional time-out in r16, WDTCR ori r16, (1<<WDCE) | (1<<WDE) out WDTCR, r16 ; Turn off WDT ldi r16, (0<<WDE) out WDTCR, r16 ; Turn on global interrupt sei ret C Code Example(1) void WDT_off(void) __disable_interrupt(); __watchdog_reset(); /* Clear WDRF in MCUSR */ MCUSR &= ~(1<<WDRF); /* Write logical one to WDCE and WDE */ /* Keep old prescaler setting to prevent unintentional time-out WDTCR |= (1<<WDCE) | (1<<WDE); /* Turn off WDT */ WDTCR = 0x00; __enable_interrupt();

38 ATtiny13

2535G–AVR–01/07 Watchdog System Reset Flag (WDRF) and the WDE control bit in the initialisation rou- tine, even if the Watchdog is not in use. The following code example shows one assembly and one C function for changing the time-out value of the Watchdog Timer. Note: 1. The example code assumes that the pa rt specific header file is included. Note: The Watchdog Timer should be reset before any change of the WDP bits, since a change in the WDP bits can result in a time -out when switching to a shorter time-out period. Assembly Code Example(1) WDT_Prescaler_Change: ; Turn off global interrupt cli ; Reset Watchdog Timer wdr ; Start timed sequence in r16, WDTCR ori r16, (1<<WDCE) | (1<<WDE) out WDTCR, r16 ; -- Got four cycles to set the new values from here - ; Set new prescaler(time-out) value = 64K cycles (~0.5 s) ldi r16, (1<<WDE) | (1<<WDP2) | (1<<WDP0) out WDTCR, r16 ; -- Finished setting new values, used 2 cycles - ; Turn on global interrupt sei ret C Code Example(1) void WDT_Prescaler_Change(void) __disable_interrupt(); __watchdog_reset(); /* Start timed sequence */ WDTCR |= (1<<WDCE) | (1<<WDE); /* Set new prescaler(time-out) value = 64K cycles (~0.5 s) */ WDTCR = (1<<WDE) | (1<<WDP2) | (1<<WDP0); __enable_interrupt();

Note: 1. WDTON Fuse set to “0“ means programmed and “1“ means unprogrammed. WDE bit, and/or change the prescaler bits, WDCE must be set. Once written to one, hardware will clear WDCE after four clock cycles. resets during conditions causing failure, and a safe start-up after the failure. Table 16. Watchdog Timer Configuration

100 S t o p p e d N o n e

111 Interrupt and System

40 ATtiny13

2535G–AVR–01/07 The WDP3..0 bits determine the Watchdog Timer prescaling when the Watchdog Timer is running. The different prescaling values and their corresponding time-out periods are shown in Table 17 on page 41.

Table 17. Watchdog Timer Prescale Select

42 ATtiny13

Interrupts This section describes the specifics of t he interrupt handling as performed in ATtiny13. Table 18. Reset and Interrupt Vectors

120 for a complete list of parameters. Figure 20. I/O Pin Equivalent Schematic tion for I/O-Ports” on page 53. full description of the alternate functions.

44 ATtiny13

of the other pins in the port as general digital I/O. functional description of one I/O-port pin, here generically called Pxn. Figure 21. General Digital I/O(1) Note: 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. reset condition becomes active, even if no clocks are running. put pin, the port pin is driven low (zero).

DDRxn. Note that the SBI instruction can be used to toggle one single bit in a port. the MCUCR Register can be set to disable all pull-ups in all ports. ({DDxn, PORTxn} = 0b10) as an intermediate step. Table 19 summarizes the control signals for the pin value. Figure 22. Synchronization when Reading an Externally Applied Pin value Table 19. Port Pin Configurations

46 ATtiny13

Consider the clock period starting shortly afte r the first falling edge of the system clock. period depending upon the time of assertion. Figure 23. Synchronization when Reading a Software Assigned Pin Value

2535G–AVR–01/07 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 result- ing 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. Note: 1. For the assembly program, two tempor ary registers are used to minimize the time from pull-ups are set on pins 0, 1 and 4, until the direction bits are correctly set, defin- ing bit 2 and 3 as low and redefining bits 0 and 1 as strong high drivers. Digital Input Enable and Sleep Modes As shown in Figure 21, the digital input si gnal can be clamped to ground at the input of the schmitt-trigger. The signal denoted SLEEP in the figure, is set by the MCU Sleep Controller in Power-down mode, Power-save mode, and Standby mode to avoid high power consumption if some input signals are left floating, or have an analog signal level close to V CC/2. SLEEP is overridden for port pins enabled as external interrupt pins. If the external inter- rupt request is not enabled, SLEEP is active also for these pins. SLEEP is also overridden by various other alternate functions as described in “Alternate Port Func- tions” on page 48. If a logic high level (“one”) is present on an asynchronous external interrupt pin config- ured as “Interrupt on Rising Edge, Falling Edge, or Any Logic Change on Pin” while the external interrupt is not enabled, the corresponding Exte rnal Interrupt Flag will be set Assembly Code Example (1) ... ; Define pull-ups and set outputs high ; Define directions for port pins out PORTB,r16 out DDRB,r17 ; Insert nop for synchronization nop ; Read port pins in r16,PINB ... C Code Example unsigned char i; ... /* Define pull-ups and set outputs high */ /* Define directions for port pins */ /* Insert nop for synchronization*/ __no_operation(); /* Read port pins */ i = PINB; ...

48 ATtiny13

2535G–AVR–01/07 when resuming from the above mentioned Sle ep mode, as the clamping in these sleep mode produces the requested logic change. Unconnected Pins If some pins are unused, it is recommended to ensure that these pins have a defined level. Even though most of the digital inputs are disabled in the deep sleep modes as described above, floating inputs should be av oided to reduce current consumption in all other modes where the digital inputs are enabled (Reset, Active mode and Idle mode). The simplest method to ensure a defined level of an unused pin, is to enable the internal pull-up. In this case, the pull-up will be disabled during reset. If low power consumption during reset is important, it is recommended to use an external pull-up or pull-down. Connecting unused pins directly to V CC or GND is not recommended, since this may cause excessive currents if the pin is accidentally configured as an output. Alternate Port Functions Most port pins have alternate functions in addition to being general digital I/Os. Figure 24 shows how the port pin control signals fr om the simplified Figure 21 can be overrid- den by alternate functions. The overriding signals may not be present in all port pins, but the figure serves as a generic description app licable to all port pins in the AVR micro- controller family.

Figure 24. Alternate Port Functions(1) Note: 1. WRx, WPx, WDx, RRx, RPx, and RDx are common to all pins within the same port.

50 ATtiny13

erated internally in the modules having the alternate function. description for further details. Table 20. Generic Description of Overriding Signals for Alternate Functions enabled when {DDxn, PORTxn, PUD} = 0b010. DDxn, PORTxn, and PUD Register bits. driver is enabled by the DDxn Register bit. is controlled by the PORTxn Register bit. of the setting of the PORTxn Register bit. If PTOE is set, the PORTxn Register bit is inverted. the alternate function will use its own synchronizer. can be used bi-directionally.

These bits are reserved bits in the ATtiny13 and will always read as zero. and PORTxn Registers are configured to enable the pull-ups ({DDxn, PORTxn} = 0b01). See “Configuring the Pin” on page 44 for more details about this feature. Alternate Functions of Port B The Port B pins with alternate function are shown in Table 21. Notes: 1. Reset pin, debugWire I/O, ADC Input channel, or Pin Change Interrupt.

  1. ADC Input channel or Pin Change Interrupt.
  2. ADC Input channel, Clock Input, or Pin Change Interrupt.
  3. Serial Clock Input, Timer/Counter Clock Input, ADC Input Channel 0, or Pin Change
  4. Serial Data Input, Analog Comparator Negative Input, Output Compare and PWM

Output B for Timer/Counter, External Interrupt 0 or Pin Change Interrupt.

  1. Serial Data Output, Analog Comparator Positive Input, Output Compare and PWM

Output A for Timer/Counter, or Pin Change Interrupt. ing signals shown in Figure 24 on page 49. Table 21. Port B Pins Alternate Functions

52 ATtiny13

Note: 1. 1 when the Fuse is “0” (Programmed). Table 22. Overriding Signals for Alternate Functions in PB5..PB3 Table 23. Overriding Signals for Alternate Functions in PB2..PB0

2535G–AVR–01/07 Register Description for I/O-Ports Port B Data Register – PORTB Port B Data Direction Register – DDRB Port B Input Pins Address – PINB B i t 76543210 – – PORTB5 PORTB4 PORTB3 PORTB2 PORTB1 PORTB0 PORTB Read/Write R R R/W R/W R/W R/W R/W R/W I n i t i a l V a l u e 00000000 B i t 76543210 –– DDB5 DDB4 DDB3 DDB2 DDB1 DDB0 DDRB Read/Write R R R/W R/W R/W R/W R/W R/W I n i t i a l V a l u e 00000000 B i t 76543210 –– PINB5 PINB4 PINB3 PI NB2 PINB1 PINB0 PINB Read/Write R R R/W R/W R/W R/W R/W R/W Initial Value 0 0 N/A N/A N/A N/A N/A N/A

54 ATtiny13

External Interrupts The External Interrupts are triggered by the INT0 pin or any of the PCINT5..0 pins. configured as outputs. This feature provides a way of generating a software interrupt. used for waking the part also from sleep modes other than Idle mode. mode. The I/O clock is halted in all sleep modes except Idle mode. SUT and CKSEL Fuses as described in “System Clock and Clock Options” on page 21. An example of timing of a pin change interrupt is shown in Figure 25. Figure 25. Timing of pin change interrupts

the completion of the currently executing instruction to generate an interrupt. Table 24. Interrupt 0 Sense Control 0 0 The low level of INT0 generates an interrupt request. 0 1 Any logical change on INT0 generates an interrupt request. 1 0 The falling edge of INT0 generates an interrupt request. 1 1 The rising edge of INT0 generates an interrupt request.

56 ATtiny13

2535G–AVR–01/07 General Interrupt Mask Register – GIMSK  Bits 7, 4..0 – Res: Reserved Bits These bits are reserved bits in the ATtiny13 and will always read as zero.  Bit 6 – INT0: External Interrupt Request 0 Enable When the INT0 bit is set (one) and the I-bit in the Status Register (SREG) is set (one), the external pin interrupt is enabled. The Interrupt Sense Control0 bits 1/0 (ISC01 and ISC00) in the MCU Control Register (MCUCR) define whether the external interrupt is activated on rising and/or falling edge of the INT0 pin or level sensed. Activity on the pin will cause an interrupt request even if INT0 is configured as an output. The correspond- ing interrupt of External Interrupt Request 0 is executed from the INT0 Interrupt Vector.  Bit 5 – PCIE: Pin Change Interrupt Enable When the PCIE bit is set (one) and the I-bit in the Status Register (SREG) is set (one), pin change interrupt is enabled. Any change on any enabled PCINT5..0 pin will cause an interrupt. The corresponding interrupt of Pin Change Interrupt Request is executed from the PCI Interrupt Vector. PCINT5..0 pins are enabled individually by the PCMSK0 Register. General Interrupt Flag Register – GIFR  Bits 7, 4..0 – Res: Reserved Bits These bits are reserved bits in the ATtiny13 and will always read as zero.  Bit 6 – INTF0: External Interrupt Flag 0 When an edge or logic change on the INT0 pin triggers an interrupt request, INTF0 becomes set (one). If the I-bit in SREG and the INT0 bit in GIMSK are set (one), the MCU will jump to the corresponding Interrupt Vector. The flag is cleared when the inter- rupt routine is executed. Alternatively, the flag can be cleared by writing a logical one to it. This flag is always cleared when INT0 is configured as a level interrupt.  Bit 5 – PCIF: Pin Change Interrupt Flag When a logic change on any PCINT5..0 pin triggers an interrupt request, PCIF becomes set (one). If the I-bit in SREG and the PCIE bit in GIMSK are set (one), the MCU will jump to the corresponding Interrupt Vector. The flag is cleared when the interrupt routine is executed. Alternatively, the flag can be cleared by writing a logical one to it. B i t 76543210 Read/Write R R/W R/W R R R R R Initial Value 0 0 0 0 0 0 0 0 B i t 76543210 – I N T F 0 P C I F ––––– G I F R Read/Write R R/W R/W R R R R R Initial Value 0 0 0 0 0 0 0 0

2535G–AVR–01/07 Pin Change Mask Register – PCMSK  Bits 7, 6 – Res: Reserved Bits These bits are reserved bits in the ATtiny13 and will always read as zero. Each PCINT5..0 bit selects whether pin change interrupt is enabled on the correspond- ing I/O pin. If PCINT5..0 is set and the PCIE bit in GIMSK is set, pin change interrupt is enabled on the corresponding I/O pin. If PCINT5..0 is cleared, pin change interrupt on the corresponding I/O pin is disabled. B i t 76543210 – – PCINT5 PCINT4 PCINT3 PCINT2 PCINT1 PCINT0 PCMSK Read/Write R R R/W R/W R/W R/W R/W R/W Initial Value 0 0 0 0 0 0 0 0

58 ATtiny13

Figure 26. 8-bit Timer/Counter Block Diagram

60 ATtiny13

priority over) all counter clear or count operations. waveform generation, see “Modes of Operation” on page 63. selected by the WGM01:0 bits. TOV0 can be used for generating a CPU interrupt. values in some modes of operation (See “Modes of Operation” on page 63.). Figure 28 shows a block diagram of the Output Compare unit. Figure 28. Output Compare Unit, Block Diagram

2535G–AVR–01/07 The OCR0x Registers are double buffered when using any of the Pulse Width Modula- tion (PWM) modes. For the normal and Clear Timer on Compare (CTC) modes of operation, the double buffering is disabled. The double buffering synchronizes the update of the OCR0x Compare Registers to either top or bottom of the counting sequence. The synchronization prevents the occurrence of odd-length, non-symmetrical PWM pulses, thereby making the output glitch-free. The OCR0x Register access may seem comple x, but this is not case. When the double buffering is enabled, the CPU has access to the OCR0x Buffer Register, and if double buffering is disabled the CPU will access the OCR0x directly. Force Output Compare In non-PWM waveform generation modes, the match output of the comparator can be forced by writing a one to the Force Output Compare (FOC0x) bit. Forcing Compare Match will not set the OCF0x Flag or reload /clear the timer, but the OC0x pin will be updated as if a real Compare Match had occurred (the COM0x1:0 bits settings define whether the OC0x pin is set, cleared or toggled). Compare Match Blocking by TCNT0 Write All CPU write operations to the TCNT0 Register will block any Compare Match that occur in the next timer clock cycle, even w hen the timer is stopped. This feature allows OCR0x to be initialized to the same value as TCNT0 without triggering an interrupt when the Timer/Counter clock is enabled. Using the Output Compare Unit Since writing TCNT0 in any mode of operation will block all Compare Matches for one timer clock cycle, there are risks involved when changing TCNT0 when using the Output Compare Unit, independently of whether the Timer/Counter is running or not. If the value written to TCNT0 equals the OCR0x value, the Compare Match will be missed, resulting in incorrect waveform generation . Similarly, do not write the TCNT0 value equal to BOTTOM when the counter is down-counting. The setup of the OC0x should be performed before setting the Data Direction Register for the port pin to output. The easiest way of setting the OC0x value is to use the Force Output Compare (FOC0x) strobe bits in Normal mode. The OC0x Registers keep their values even when changing between Waveform Generation modes. Be aware that the COM0x1:0 bits are not double buffered together with the compare value. Changing the COM0x1:0 bits will take effect immediately.

62 ATtiny13

Register, not the OC0x pin. If a system reset occur, the OC0x Register is reset to “0”. Figure 29. Compare Match Output Unit, Schematic dent of the Waveform Generation mode. modes of operation. See “8-bit Timer/Counter Register Description” on page 69. effect by using the FOC0x strobe bits.

“Timer/Counter Timing Diagrams” on page 67. TOV0 Flag in this case behaves like a ninth bit, except that it is only set, not cleared. consider in the Normal mode, a new counter value can be written anytime. since this will occupy too much of the CPU time. Match output frequency. It also simplifies the operation of counting external events. then counter (TCNT0) is cleared. Figure 30. CTC Mode, Timing Diagram

64 ATtiny13

2535G–AVR–01/07 to OCR0A is lower than the current value of TCNT0, the counter will miss the Compare Match. The counter will then have to count to its maxi mum value (0xFF) and wrap around starting at 0x00 before the Compare Match can occur. For generating a waveform output in CTC mode, the OC0A output can be set to toggle its logical level on each Compare Match by setting the Compare Output mode bits to toggle mode (COM0A1:0 = 1). The OC0A value will not be visible on the port pin unless the data direction for the pin is set to output. The waveform generated will have a maxi- mum frequency of f OC0 = fclk_I/O /2 when OCR0A is set to zero (0x00). The waveform frequency is defined by the following equation: The N variable represents the prescale factor (1, 8, 64, 256, or 1024). As for the Normal mode of operation, the TOV0 Flag is set in the same timer clock cycle that the counter counts from MAX to 0x00. Fast PWM Mode The fast Pulse Width Modulation or fast PWM mode (WGM02:0 = 3 or 7) provides a high frequency PWM waveform generation option. The fast PWM differs from the other PWM option by its single-slope operation. The counter counts from BOTTOM to TOP then restarts from BOTTOM. TOP is defined as 0xFF when WGM2:0 = 3, and OCR0A when WGM2:0 = 7. In non-inverting Compare Output mode, the Output Compare (OC0x) is cleared on the Compare Match between TCNT0 and OCR0x, and set at BOTTOM. In inverting Compare Output mode, the output is set on Compare Match and cleared at BOTTOM. Due to the single-slope operation, the operating frequency of the fast PWM mode can be twice as high as the phase co rrect PWM mode that use dual-slope opera- tion. This high frequency makes the fast PWM mode well suited for power regulation, rectification, and DAC applications. High fr equency allows physicall y small sized exter- nal components (coils, capacitors), and therefore reduces total system cost. In fast PWM mode, the counter is incremented until the counter value matches the TOP value. The counter is then cleared at the following timer clock cycle. The timing diagram for the fast PWM mode is shown in Figure 31. The TCNT0 value is in the timing diagram shown as a histogram for illustrating the single-slope operation. The diagram includes non-inverted and inverted PWM outputs. The small horizontal line marks on the TCNT0 slopes represent Compare Matches between OCR0x and TCNT0. f OCnx fclk_I/O

Figure 31. Fast PWM Mode, Timing Diagram The N variable represents the prescale factor (1, 8, 64, 256, or 1024). buffer feature of the Output Compare unit is enabled in the fast PWM mode.

66 ATtiny13

PWM modes, these modes are preferred for motor control applications. sent Compare Matches between OCR0x and TCNT0. Figure 32. Phase Correct PWM Mode, Timing Diagram

68 ATtiny13

Figure 34. Timer/Counter Timing Diagram, with Prescaler (fclk_I/O/8) CTC mode and PWM mode, where OCR0A is TOP. Figure 35. Timer/Counter Timing Diagram, Setting of OCF0x, with Prescaler (fclk_I/O/8) PWM mode where OCR0A is TOP. Figure 36. Timer/Counter Timing Diagram, Clear Timer on Compare Match mode, with

responding to the OC0A pin must be set in order to enable the output driver. WGM02:0 bits are set to a normal or CTC mode (non-PWM). Mode” on page 64 for more details. Table 26. Compare Output Mode, non-PWM Mode 0 0 Normal port operation, OC0A disconnected. Table 27. Compare Output Mode, Fast PWM Mode(1) 0 0 Normal port operation, OC0A disconnected. 0 1 WGM02 = 0: Normal Port Operation, OC0A Disconnected. WGM02 = 1: Toggle OC0A on Compare Match.

70 ATtiny13

rect PWM Mode” on page 66 for more details. responding to the OC0B pin must be set in order to enable the output driver. WGM02:0 bits are set to a normal or CTC mode (non-PWM). Mode” on page 64 for more details. Table 28. Compare Output Mode, Phase Correct PWM Mode(1) 0 0 Normal port operation, OC0A disconnected. 0 1 WGM02 = 0: Normal Port Operation, OC0A Disconnected. WGM02 = 1: Toggle OC0A on Compare Match. Compare Match when down-counting. Compare Match when down-counting. Table 29. Compare Output Mode, non-PWM Mode 0 0 Normal port operation, OC0B disconnected. Table 30. Compare Output Mode, Fast PWM Mode(1) 0 0 Normal port operation, OC0B disconnected.

01 R e s e r v e d

rect PWM Mode” on page 66 for more details. These bits are reserved bits in the ATtiny13 and will always read as zero. “Modes of Operation” on page 63). Table 31. Compare Output Mode, Phase Correct PWM Mode(1) 0 0 Normal port operation, OC0B disconnected. Compare Match when down-counting. Compare Match when down-counting. Table 32. Waveform Generation Mode Bit Description

72 ATtiny13

The FOC0A bit is only active when the WGM bits specify a non-PWM mode. FOC0A bit, an immediate Compare Match is forced on the Waveform Generation unit. COM0A1:0 bits that determines the effect of the forced compare. The FOC0A bit is always read as zero. The FOC0B bit is only active when the WGM bits specify a non-PWM mode. FOC0B bit, an immediate Compare Match is forced on the Waveform Generation unit. COM0B1:0 bits that determines the effect of the forced compare. The FOC0B bit is always read as zero. These bits are reserved bits in the ATtiny13 and will always read as zero. See the description in the “Timer/Counter Control Register A – TCCR0A” on page 69. The three Clock Select bits select the clock source to be used by the Timer/Counter. Table 33. Clock Select Bit Description

interrupt, or to generate a waveform output on the OC0A pin. interrupt, or to generate a waveform output on the OC0B pin. These bits are reserved bits in the ATtiny13 and will always read as zero. 1 1 0 External clock source on T0 pin. Clock on falling edge. 1 1 1 External clock source on T0 pin. Clock on rising edge. Table 33. Clock Select Bit Description (Continued)

74 ATtiny13

2535G–AVR–01/07 executed if a Compare Match in Timer/Counter occurs, i.e., when the OCF0B bit is set in the Timer/Counter Interrupt Flag Register – TIFR0.  Bit 2 – OCIE0A: Timer/Counter0 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/Counter0 Compare Match A interrupt is enabled. The corresponding interrupt is executed if a Compare Match in Timer/Counter0 occurs, i.e., when the OCF0A bit is set in the Timer/Counter 0 Interrupt Flag Register – TIFR0.  Bit 1 – TOIE0: Timer/Counter0 Overflow Interrupt Enable When the TOIE0 bit is written to one, and the I-bit in the Status Register is set, the Timer/Counter0 Overflow interrupt is enabled. The corresponding interrupt is executed if an overflow in Timer/Counter0 occurs, i.e., when the TOV0 bit is set in the Timer/Counter 0 Interrupt Flag Register – TIFR0. Timer/Counter 0 Interrupt Flag Register – TIFR0  Bits 7..4, 0 – Res: Reserved Bits These bits are reserved bits in the ATtiny13 and will always read as zero.  Bit 3 – OCF0B: Output Compare Flag 0 B The OCF0B bit is set when a Compare Match occurs between the Timer/Counter and the data in OCR0B – Output Compare Register0 B. OCF0B is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, OCF0B is cleared by writing a logic one to the flag. When the I-bit in SREG, OCIE0B (Timer/Counter Compare B Match Interrupt Enable), and OCF0B are set, the Timer/Counter Compare Match Interrupt is executed.  Bit 2 – OCF0A: Output Compare Flag 0 A The OCF0A bit is set when a Compare Match occurs between the Timer/Counter0 and the data in OCR0A – Output Compare Register0. OCF0A is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, OCF0A is cleared by writing a logic one to the flag. When t he I-bit in SREG, OCIE0A (Timer/Counter0 Compare Match Interrupt Enable), and OCF0A are set, the Timer/Counter0 Compare Match Interrupt is executed.  Bit 1 – TOV0: Timer/Counter0 Overflow Flag The bit TOV0 is set when an overflow occu rs in Timer/Counter0. TOV0 is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, TOV0 is cleared by writing a logic one to the flag. When the SREG I-bit, TOIE0 (Timer/Counter0 Overflow Interrupt Enable), and TOV0 are set, the Timer/Counter0 Overflow interrupt is executed. The setting of this flag is dependent of the WGM02:0 bit setting. Refer to Table 32, “Waveform Generation Mode Bit Description” on page 71. B i t 76543210 –––– O C F 0 B O C F 0 A TOV0 –T I F R 0 Read/Write R R R R R/W R/W R/W R I n i t i a l V a l u e 00000000

CLK_I/O/8, fCLK_I/O/64, fCLK_I/O/256, or fCLK_I/O/1024. cycles, where N equals the prescaler divisor (8, 64, 256, or 1024). clkI/O). The latch is transparent in the high period of the internal system clock. (CSn2:0 = 6) edge it detects. Figure 37. T0 Pin Sampling clock cycles from an edge has been applied to the T0 pin to the counter is updated. An external clock source can not be prescaled.

76 ATtiny13

Figure 38. Prescaler for Timer/Counter0 Note: 1. The synchronization logic on the input pins ( T0) is shown in Figure 37. zero, the PSR10 bit is cleared by hardware, and the Timer/Counter start counting. cleared immediately by hardware, except if the TSM bit is set.

parator and its surrounding logic is shown in Figure 39. Figure 39. Analog Comparator Block Diagram Notes: 1. See Table 35 on page 79.

  1. Refer to Figure 1 on page 2 and Table 23 on page 52 for Analog Comparator pin

When this bit is written logic one, the power to the Analog Comparator is switched off. can occur when the bit is changed.

78 ATtiny13

ACO. The synchronization introduces a delay of 1 - 2 clock cycles. log Comparator interrupt is activated. When written logic zero, the interrupt is disabled. This bit is a reserved bit in the ATtiny13 and will always read as zero. rupt. The different settings are shown in Table 34. can occur when the bits are changed. Table 34. ACIS1/ACIS0 Settings 0 0 Comparator Interrupt on Output Toggle. 1 0 Comparator Interrupt on Falling Output Edge. 1 1 Comparator Interrupt on Rising Output Edge.

applied to the negative input to the Analog Comparator. When this bit is written logic one, the digital input buffer on the AIN1/0 pin is disabled. Table 35. Analog Comparator Multiplexed Input

80 ATtiny13

2535G–AVR–01/07 Analog to Digital Converter Features  10-bit Resolution  0.5 LSB Integral Non-linearity  ± 2 LSB Absolute Accuracy  13 - 260 µs Conversion Time  Up to 15 kSPS at Maximum Resolution  Four Multiplexed Single Ended Input Channels  Optional Left Adjustment for ADC Result Readout  0 - VCC ADC Input Voltage Range  Selectable 1.1V ADC Reference Voltage  Free Running or Single Conversion Mode  ADC Start Conversion by Auto Triggering on Interrupt Sources  Interrupt on ADC Conversion Complete  Sleep Mode Noise Canceler The ATtiny13 features a 10-bit successive approximation ADC. The ADC is connected to a 4-channel Analog Multiplexer which allo ws four single-ended voltage inputs con- structed from the pins of Port B. The single-ended voltage inputs refer to 0V (GND). The ADC contains a Sample and Hold circuit which ensures that the input voltage to the ADC is held at a constant level during conversion. A block diagram of the ADC is shown in Figure 40. Internal reference voltages of nominally 1.1V or VCC are provided On-chip.

Figure 40. Analog to Digital Converter Block Schematic CC or an internal 1.1V reference voltage. ADC input pins, can be selected as single ended inputs to the ADC. ADC before entering power saving sleep modes. be presented left adjusted by setting the ADLAR bit in ADMUX.

82 ATtiny13

The ADC has its own interrupt which can be triggered when a conversion completes. ADCL, the interrupt will trigger even if the result is lost. ger a new conversion at the next interrupt event. Figure 41. ADC Auto Trigger Logic Interrupt Flag, ADIF is cleared or not. ADCSRA to one. ADSC can also be used to determine if a conversion is in progress.

Figure 42. ADC Prescaler bit is set, and is continuously reset when ADEN is low. version starts at the following rising edge of the ADC clock cycle. ADSC again, and a new conversion will be initiated on the first rising ADC clock edge. source signal. Three additional CPU clock cycles are used for synchronization logic.

84 ATtiny13

Figure 43. ADC Timing Diagram, First Conversion (Single Conversion Mode) Figure 44. ADC Timing Diagram, Single Conversion Figure 45. ADC Timing Diagram, Auto Triggered Conversion

Figure 46. ADC Timing Diagram, Free Running Conversion Table 36. ADC Conversion Time

86 ATtiny13

2535G–AVR–01/07 Changing Channel or Reference Selection The MUXn and REFS1:0 bits in the ADMUX Register are single buffered through a tem- porary register to which the CPU has random access. This ensures that the channels and reference selection only takes place at a safe point during the conversion. The channel and reference selection is continuously updated until a conversion is started. Once the conversion starts, the channel and reference selection is locked to ensure a sufficient sampling time for the ADC. C ontinuous updating resumes in the last ADC clock cycle before the conversion completes (A DIF in ADCSRA is set). Note that the conversion starts on the following rising ADC clock edge after ADSC is written. The user is thus advised not to write new channel or reference selection values to ADMUX until one ADC clock cycle after ADSC is written. If Auto Triggering is used, the exact time of the triggering event can be indeterministic. Special care must be taken when updating the ADMUX Register, in order to control which conversion will be affected by the new settings. If both ADATE and ADEN is written to one, an interrupt event can occur at any time. If the ADMUX Register is changed in this period, the user cannot tell if the next conversion is based on the old or the new settings. ADMUX can be safely updated in the following ways: 1. When ADATE or ADEN is cleared. 2. During conversion, minimum one ADC clock cycle after the trigger event. 3. After a conversion, before the Interrupt Flag used as trigger source is cleared. When updating ADMUX in one of these conditions, the new settings will affect the next ADC conversion. ADC Input Channels When changing channel selections, the user should observe the following guidelines to ensure that the correct channel is selected: In Single Conversion mode, always select the channel before starting the conversion. The channel selection may be changed one ADC clock cycle after writing one to ADSC. However, the simplest method is to wait for the conversion to complete before changing the channel selection. In Free Running mode, always select the channel before starting the first conversion. The channel selection may be changed one ADC clock cycle after writing one to ADSC. However, the simplest method is to wait for the first conversion to complete, and then change the channel selection. Since the next conversion has already started automati- cally, the next result will reflect the previous channel selection. Subsequent conversions will reflect the new channel selection.

2535G–AVR–01/07 ADC Voltage Reference The reference voltage for the ADC (V REF) indicates the conversion range for the ADC. Single ended channels that exceed VREF will result in codes close to 0x3FF. VREF can be selected as either V CC, or internal 1.1V reference, or external AREF pin. The first ADC conversion result after switching referenc e voltage source may be inaccurate, and the user is advised to discard this result. ADC Noise Canceler The ADC features a noise canceler that enables conversion during sleep mode to reduce noise induced from the CPU core and other I/O peripherals. The noise canceler can be used with ADC Noise Reduction and Idle mode. To make use of this feature, the following procedure should be used: 1. Make sure that the ADC is enabled and is not busy converting. Single Con- version mode must be selected and the ADC conversion complete interrupt must be enabled. 2. Enter ADC Noise Reduction mode (or Idle mode). The ADC will start a con- version once the CPU has been halted. 3. If no other interrupts occur before the ADC conversion completes, the ADC interrupt will wake up the CPU and ex ecute the ADC Conversion Complete interrupt routine. If another interrupt wakes up the CPU before the ADC con- version is complete, that interrupt will be executed, and an ADC Conversion Complete interrupt request will be ge nerated when the ADC conversion completes. The CPU will remain in ac tive mode until a new sleep command is executed. Note that the ADC will not be automatically tu rned off when entering other sleep modes than Idle mode and ADC Nois e Reduction mode. The user is advised to write zero to ADEN before entering such sleep modes to avoid excessive power consumption.

88 ATtiny13

(combined resistance in the input path). minimizes the required charge transfer to the S/H capacitor. Figure 47. Analog Input Circuitry

  1. Keep analog signal paths as short as possible. Make sure analog tracks run
  2. Use the ADC noise canceler function to reduce induced noise from the CPU.
  3. If any port pins are used as digital outputs, it is essential that these do not

switch while a conversion is in progress. steps (LSBs). The lowest code is read as 0, and the highest code is read as 2n-1. transition (at 0.5 LSB). Ideal value: 0 LSB. Figure 48. Offset Error

90 ATtiny13

Figure 49. Gain Error Figure 50. Integral Non-linearity (INL) (the interval between two adjacent transitions) from the ideal code width (1 LSB).

Figure 51. Differential Non-linearity (DNL) the ADC Result Registers (ADCL, ADCH). ground, and 0x3FF represents the selected reference voltage minus one LSB. This bit is reserved bit in the ATtiny13 and will always read as zero.

0 VREF Input Voltage

1 LSB

92 ATtiny13

complete (ADIF in ADCSRA is set). ADC Data Register – ADCL and ADCH” on page 93. These bits are reserved bits in the ATtiny13 and will always read as zero. ADC. See Table 38 for details. change will not go in effect until this conversion is complete (ADIF in ADCSRA is set). ing the ADC off while a conversion is in progress, will terminate this conversion.

  1. This first conversion performs initialization of the ADC.

complete, it returns to zero. Writing zero to this bit has no effect. Table 37. Voltage Reference Selections for ADC 0V CC used as analog reference. 1 Internal Voltage Reference. Table 38. Input Channel Selections

00 ADC0 (PB5)

01 ADC1 (PB2)

10 ADC2 (PB4)

11 ADC3 (PB3)

selected by setting the ADC Trigger Select bits, ADTS in ADCSRB. This bit is set when an ADC conversion completes and the data registers are updated. handling vector. Alternatively, ADIF is cleared by writing a logical one to the flag. abled. This also applies if the SBI and CBI instructions are used. plete Interrupt is activated. Table 39. ADC Prescaler Selections

94 ATtiny13

When an ADC conversion is complete, the result is found in these two registers. sufficient to read ADCH. Otherwise, ADCL must be read first, then ADCH. (default), the result is right adjusted. These bits are reserved bits in the ATtiny13 and will always read as zero. effect. A conversion will be triggered by the rising edge of the selected Interrupt Flag. Table 40. ADC Auto Trigger Source Selections

2535G–AVR–01/07 When this bit is written logic one, the digital input buffer on the corresponding ADC pin is disabled. The corresponding PIN register bit will always read as zero when this bit is set. When an analog signal is applied to the ADC3..0 pin and the digital input from this pin is not needed, this bit should be written logic one to reduce power consumption in the dig- ital input buffer.

96 ATtiny13

and becomes the communication gateway between target and emulator. Figure 52. The debugWIRE Setup the clock source selected by the CKSEL Fuses.  Pull-Up resistor on the dW/(RESET) line must be in the range of 10k to 20 k Ω. However, the pull-up resistor is optional.

2535G–AVR–01/07  Capacitors inserted on the RESET pin must be disconnected when using debugWire.  All external reset sources must be disconnected. Software Break Points debugWIRE supports Program memory Break Points by the AVR Break instruction. Set- ting a Break Point in AVR Studio ® will insert a BREAK inst ruction in the Program memory. The instruction replaced by the BR EAK instruction will be stored. When pro- gram execution is continued, the stored in struction will be executed before continuing from the Program memory. A break can be inserted manually by putting the BREAK instruction in the program. The Flash must be re-programmed each time a Break Point is changed. This is auto- matically handled by AVR Studio through the debugWIRE interface. The use of Break Points will therefore reduce the Flash Data retention. Devices used for debugging pur- poses should not be shipped to end customers. Limitations of debugWIRE The debugWIRE communication pin (dW) is physically located on the same pin as External Reset (RESET). An External Reset source is therefore not supported when the debugWIRE is enabled. The debugWIRE system accurately emulates all I/O functions when running at full speed, i.e., when the program in the CPU is running. When the CPU is stopped, care must be taken while accessing some of the I/O Registers via the debugger (AVR Stu- dio). See the debugWIRE documentation for detailed description of the limitations. A programmed DWEN Fuse enables some parts of the clock system to be running in all sleep modes. This will increase the power consumption while in sleep. Thus, the DWEN Fuse should be disabled when debugWire is not used. debugWIRE Related Register in I/O Memory The following section describes the registers used with the debugWire. debugWire Data Register – DWDR The DWDR Register provides a communica tion channel from the running program in the MCU to the debugger. This register is only accessible by the debugWIRE and can therefore not be used as a general purpose register in the normal operations. B i t 76543210 DWDR[7:0] DWDR Read/Write R/W R/W R/W R/W R/W R/W R/W R/W I n i t i a l V a l u e 00000000

98 ATtiny13

2535G–AVR–01/07 Self-Programming the Flash The device provides a Self-Programming mechanism for downloading and uploading program code by the MCU itself. The Self -Programming can use any available data interface and associated protocol to read code and write (program) that code into the Program memory. The Program memory is updated in a page by page fashion. Before programming a page with the data stored in the temporary page buffer, the page must be erased. The temporary page buffer is filled one word at a time using SPM and the buffer can be filled either before the Page Erase command or between a Page Erase and a Page Write operation: Alternative 1, fill the buffer before a Page Erase  Fill temporary page buffer  Perform a Page Erase  Perform a Page Write Alternative 2, fill the buffer after Page Erase  Perform a Page Erase  Fill temporary page buffer  Perform a Page Write If only a part of the page needs to be changed, the rest of the page must be stored (for example in the temporary page buffer) before the erase, and then be re-written. When using alternative 1, the Boot Loader provi des an effective Read-Modify-Write feature which allows the user software to first read the page, do the necessary changes, and then write back the modified data. If alternativ e 2 is used, it is not possible to read the old data while loading since the page is already erased. The temporary page buffer can be accessed in a random sequence. It is essential that the page address used in both the Page Erase and Page Write operation is addressing the same page. Performing Page Erase by SPM To execute Page Erase, set up the address in the Z-pointer, write “00000011” to SPMCSR and execute SPM within four clock cycles after writing SPMCSR. The data in R1 and R0 is ignored. The page address must be written to PCPAGE in the Z-register. Other bits in the Z-pointer will be ignored during this operation.  The CPU is halted during the Page Erase operation. Filling the Temporary Buffer (Page Loading) To write an instruction word, set up the address in the Z-pointer and data in R1:R0, write “00000001” to SPMCSR and execute SPM within four clock cycles after writing SPMCSR. The content of PCWORD in the Z-register is used to address the data in the temporary buffer. The temporary buffer will auto-erase after a Page Write operation or by writing the CTPB bit in SPMCSR. It is also erased after a system reset. Note that it is not possible to write more than one time to each address without erasing the temporary buffer. If the EEPROM is written in the middle of an SPM Page Load operation, all data loaded will be lost. Performing a Page Write To execute Page Write, set up the address in the Z-pointer, write “00000101” to SPMCSR and execute SPM within four clock cycles after writing SPMCSR. The data in R1 and R0 is ignored. The page address must be written to PCPAGE. Other bits in the Z-pointer must be written to zero during this operation.  The CPU is halted during the Page Write operation.

The Z-pointer is used to address the SPM commands. addresses the Flash byte-by-byte, also the LSB (bit Z0) of the Z-pointer is used. Figure 53. Addressing the Flash During SPM Note: 1. The different variables used in Figure 53 are listed in Table 46 on page 106.

100 ATtiny13

2535G–AVR–01/07 Store Program Memory Control and Status Register – SPMCSR The Store Program Memory Control and Status Register contains the control bits needed to control the Program memory operations.  Bits 7..5 – Res: Reserved Bits These bits are reserved bits in the ATtiny13 and always read as zero.  Bit 4 – CTPB: Clear Temporary Page Buffer If the CTPB bit is written while filling the temporary page buffer, the temporary page buffer will be cleared and the data will be lost.  Bit 3 – RFLB: Read Fuse and Lock Bits An LPM instruction within three cycles after RFLB and SELFPRGEN are set in the SPMCSR Register, will read either the Lock bits or the Fuse bits (depending on Z0 in the Z-pointer) into the destination register. See “EEPROM Write Prevents Writing to SPMCSR” on page 101 for details.  Bit 2 – PGWRT: Page Write If this bit is written to one at the same time as SELFPRGEN, the next SPM instruction within four clock cycles executes Page Writ e, with the data stored in the temporary buffer. The page address is taken from the high part of the Z-pointer. The data in R1 and R0 are ignored. The PGWRT bit will auto-clear upon completion of a Page Write, or if no SPM instruction is executed within four clock cycles. The CPU is halted during the entire Page Write operation.  Bit 1 – PGERS: Page Erase If this bit is written to one at the same time as SELFPRGEN, the next SPM instruction within four clock cycles executes Page Eras e. The page address is taken from the high part of the Z-pointer. The data in R1 and R0 are ignored. The PGERS bit will auto-clear upon completion of a Page Erase, or if no SPM instruction is executed within four clock cycles. The CPU is halted during the entire Page Write operation.  Bit 0 – SELFPRGEN: Self Programming Enable This bit enables the SPM instruction for the next four clock cycles. If written to one together with either CTPB, RFLB, PGWRT, or PGERS, the follo wing SPM instruction will have a special meaning, see description above. If only SELFPRGEN is written, the following SPM instruction will store the value in R1:R0 in the temporary page buffer addressed by the Z-pointer. The LSB of the Z-pointer is ignored. The SELFPRGEN bit will auto-clear upon completion of an SPM instru ction, or if no SPM instruction is exe- cuted within four clock cycles. During Page Erase and Page Write, the SELFPRGEN bit remains high until the operation is completed. Writing any other combination than “10001”, “01001”, “00101”, “00011” or “00001” in the lower five bits will have no effect. B i t 7654321 0 – – – CTPB RFLB PGWRT PGERS SELFPRGEN SPMCSR Read/Write R R R R/W R/W R/W R/W R/W I n i t i a l V a l u e 0000000 0

2535G–AVR–01/07 EEPROM Write Prevents Writing to SPMCSR Note that an EEPROM write operation will block all software programming to Flash. Reading the Fuses and Lock bits from software will al so be prevented during the EEPROM write operation. It is recommended that the user checks the status bit (EEPE) in the EECR Register and verifies that the bit is cleared before writing to the SPMCSR Register. Reading the Fuse and Lock Bits from Software It is possible to read both the Fuse and Lock bits from software. To read the Lock bits, load the Z-pointer with 0x0001 and set the RFLB and SELFPRGEN bits in SPMCSR. When an LPM instruction is executed within three CPU cycles after the RFLB and SELFPRGEN bits are set in SPMCSR, the value of the Lock bits will be loaded in the destination register. The RFLB and SELFPRGEN bits will auto-clear upon completion of reading the Lock bits or if no LPM instruct ion is executed within three CPU cycles or no SPM instruction is executed within four CPU cycles. When RFLB and SELFPRGEN are cleared, LPM will work as described in the Instruction set Manual. The algorithm for reading the Fuse Low byte is similar to the one described above for reading the Lock bits. To read the Fuse Low byte, load the Z-pointer with 0x0000 and set the RFLB and SELFPRGEN bits in SPMCSR. When an LPM instruction is executed within three cycles after the RFLB and SEL FPRGEN bits are set in the SPMCSR, the value of the Fuse Low byte (FLB) will be loaded in the destination register as shown below. Refer to Table 45 on page 104 for a detailed description and mapping of the Fuse Low byte. Similarly, when reading the Fuse High byte, load 0x0003 in the Z-pointer. When an LPM instruction is executed within three cycles after the RFLB and SELFPRGEN bits are set in the SPMCSR, the value of the Fuse High byte (FHB) will be loaded in the destination register as shown below. Refer to Table 44 on page 104 for detailed description and mapping of the Fuse High byte. Fuse and Lock bits that are programmed, will be read as zero. Fuse and Lock bits that are unprogrammed, will be read as one. B i t 76543210 B i t 76543210 Rd FLB7 FLB6 FLB5 FLB4 FLB3 FLB2 FLB1 FLB0 B i t 76543210 Rd FHB7 FHB6 FHB5 FHB4 FHB3 FHB2 FHB1 FHB0

102 ATtiny13

A Flash program corruption can be caused by two situations when the voltage is too low. for executing instructions is too low.

  1. Keep the AVR RESET active (low) duri ng periods of insufficient power supply
  2. Keep the AVR core in Power-down sleep mode during periods of low V CC. This

programming time for Flash accesses from the CPU. Table 41. SPM Programming Time

This section describes the different methods for Programming the ATtiny13 memories. only be erased to “1” with the Chip Erase command. should always debugWIRE be disabled by clearing the DWEN fuse. Notes: 1. Program the Fuse bits before programming the LB1 and LB2.

  1. “1” means unprogrammed, “0” means programmed

Table 42. Lock Bit Byte(1) Table 43. Lock Bit Protection Modes(1)(2) 1 1 1 No memory lock features enabled. disabled in High-voltage and Serial Programming mode.

104 ATtiny13

read as logical zero, “0”, if they are programmed. Notes: 1. See Table 13 on page 33 for BODLEVEL Fuse decoding.

  1. See “Alternate Functions of Port B” on page 51 for description of RSTDISBL and
  2. DWEN must be unprogrammed when Lock Bi t security is required. See “Program

And Data Memory Lock Bits” on page 103.

  1. When programming the RSTDISBL Fuse, High-voltage Serial programming has to be

used to change fuses to perform further programming. Notes: 1. The SPIEN Fuse is not accessible in SPI Programming mode.

  1. See “Watchdog Timer Control Register - WDTCR” on page 39 for details. Program-

ming this fues will disable the Watchdog Timer Interrupt.

  1. The default value of SUT1..0 results in ma ximum start-up time for the default clock

source. See Table 5 on page 23 for details. Table 4 on page 23 for details.

  1. See “System Clock Prescaler” on page 25 for details.

Table 44. Fuse High Byte Table 45. Fuse Low Byte

2535G–AVR–01/07 The status of the Fuse bits is not affected by Chip Erase. Note that the Fuse bits are locked if Lock bit1 (LB1) is programmed. Program the Fuse bits before programming the Lock bits.

106 ATtiny13

are also latched on Power-up in Normal mode. Signature Bytes All Atmel microcontrollers have a three-byte signature code which identifies the device. the device is locked. The three bytes reside in a separate address space.

  1. 0x000: 0x1E (indicates manufactured by Atmel).
  2. 0x001: 0x90 (indicates 1 KB Flash memory).
  3. 0x002: 0x07 (indicates ATtiny13 device when 0x001 is 0x90).

Table 46. No. of Words in a Page and No. of Pages in the Flash Table 47. No. of Words in a Page and No. of Pages in the EEPROM

the SPI pins dedicated for the internal SPI interface. Figure 54. Serial Programming and Verify location in both the Program and EEPROM arrays into 0xFF. Table 48. Pin Mapping Serial Programming

108 ATtiny13

2535G–AVR–01/07 Serial Programming Algorithm When writing serial data to the ATtiny13, data is clocked on the rising edge of SCK. When reading data from the ATtiny13, data is clocked on the falling edge of SCK. See Figure 55 and Figure 56 for timing details. To program and verify the ATtiny13 in the Serial Programming mode, the following sequence is recommended (see four byte instruction formats in Table 50): 1. Power-up sequence: Apply power between V CC 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 Program- ming 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 4 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 5 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 49.) 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 to gether with the appr opriate 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 t WD_EEPROM before issuing the next byte. (See Table 49.) 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 Mem- ory Page is stored by loading the Wr ite EEPROM Memory Page Instruction with the 4 MSB of the address. When usin g EEPROM page access only byte loca- tions 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 t WD_EEPROM before issuing the next page (See Table 47). 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”. Tur n VCC power off.

Figure 55. Serial Programming Waveforms Table 49. Minimum Wait Delay Before Writing the Next Flash or EEPROM Location

110 ATtiny13

Table 50. Serial Programming Instruction Set Chip Erase 1010 1100 100x xxxx xxxx xxxx xxxx xxxx Chip Erase EEPROM and Flash. Program memory at word address a:b. Write EEPROM page at address b. Read Signature Byte 0011 0000 000x xxxx xxxx xx bb oooo oooo Read Signature Byte o at address b. Table 36 on page 85 for details. “0” before applying another command.

Figure 56. Serial Programming Timing Table 51. Serial Programming Characteristics, T A = -40 °C to 85 °C, VCC = 1.8 - 5.5V

112 ATtiny13

Data memory, Lock bits and Fuse bits in the ATtiny13. Figure 57. High-voltage Serial Programming Table 52. Pin Name Mapping Table 53. Pin Values Used to Enter Programming Mode

  1. Apply 4.5 - 5.5V between V CC and GND.
  2. Set RESET pin to “0” and toggle SCI at least six times.
  3. Set the Prog_enable pins listed in Table 53 to “000” and wait at least 100 ns.
  4. Shortly after latching the Prog_enable signature, the device will actively output
  5. Wait at least 50 µs before giving any serial instructions on SDI/SII.
  6. Set Prog_enable pins listed in Table 53 to “000”.
  7. Re-program the fuses to ensure that Exte rnal Clock is selected as clock source
  8. Exit Programming mode by power the device down or by bringing RESET
  9. Enter Programming mode with the original algorithm, as described above.

efficient programming, the following should be considered. the EESAVE Fuse is programmed) and Flash after a Chip Erase. Table 54. High-voltage Reset Characteristics

114 ATtiny13

2535G–AVR–01/07 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 55). 2. Wait after Instr. 3 until SDO goes high for the “Chip Erase” cycle to finish. 3. Load Command “No Operation”.

116 ATtiny13

2535G–AVR–01/07 Programming the EEPROM The EEPROM is organized in pages, see Table 51 on page 111. 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 mem- ory is as follows (refer to Table 55): 1. Load Command “Write EEPROM”. 2. Load EEPROM Page Buffer. 3. Program EEPROM Page. Wait after Instr. 2 until SD O 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”. Reading the Flash The algorithm for reading the Flash memory is as follows (refer to Table 55): 1. Load Command "Read Flash". 2. Read Flash Low and High Bytes. The contents at the selected address are avail- able at serial output SDO. Reading the EEPROM The algorithm for reading the EEPROM memory is as follows (refer to Table 55): 1. Load Command “Read EEPROM”. 2. Read EEPROM Byte. The contents at the selected address are available at serial output SDO. 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 55. Reading the Signature Bytes and Calibration Byte The algorithms for reading the Signature bytes and Calibration byte are shown in Table 55. Power-off sequence Set SCI to “0”. Set RESET to “1”. Turn V CC power off.

Table 55. High-voltage Serial Programming Instruction Set for ATtiny13 Enter Flash Programming code. Flash or all data is programmed.

118 ATtiny13

Notes: 1. For page sizes less than 256 words, parts of the address (bbbb_bbbb) will be parts of the page address.

  1. For page sizes less than 256 bytes, parts of the address (bbbb_bbbb) will be parts of the page address.
  2. The EEPROM is written page-wise. But only the bytes that are loaded into the page are actually written to the EEPROM.

of EEPROM is not available in High-voltage Serial Programming, only in SPI Programming. Table 55. High-voltage Serial Programming Instruction Set for ATtiny13 (Continued)

Figure 60. High-voltage Serial Programming Timing Table 56. High-voltage Serial Programming Characteristics V CC = 5.0V ± 10% (Unless

120 ATtiny13

2535G–AVR–01/07

Electrical Characteristics

Absolute Maximum Ratings* DC Characteristics Maximum Ratings” may cause permanent dam- age 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. Voltage on any Pin except RESET DC Current TA = -40°C to 85°C, VCC = 1.8V to 5.5V (unless otherwise noted)(1) Symbol Parameter Condition Min. Typ. Max. Units VIL Input Low Voltage except RESET pin VCC = 1.8V - 2.4V VCC = 2.4V - 5.5V -0.5 0.2VCC 0.3VCC V VIH Input High-voltage except RESET pin VCC = 1.8V - 2.4V VCC = 2.4V - 5.5V 0.7VCC (3) 0.6VCC (3) VCC +0.5 V VIL1 Input Low-voltage CLKI pin VCC = 1.8V - 5.5 -0.5 0.1V CC V VIH1 Input High-voltage CLKI pin VCC = 1.8V - 2.4V VCC = 2.4V - 5.5V 0.8VCC (3) 0.7VCC (3) VCC +0.5 V VIL2 Input Low-voltage RESET pin VCC = 1.8V - 5.5 -0.5 0.2V CC V VIH2 Input High-voltage RESET pin VCC = 1.8V - 5.5 0.9V CC (3) VCC +0.5 V VIL3 Input Low-voltage RESET pin VCC = 1.8V - 2.4V VCC = 2.4V - 5.5V -0.5 0.2V CC V VIH3 Input High-voltage RESET pin VCC = 1.8V - 2.4V VCC = 2.4V - 5.5V 0.7VCC (3) 0.6VCC (3) VCC +0.5 V VOL Output Low Voltage(4) (PB1 and PB0) IOL = 20 mA, VCC = 5V IOL = 10 mA, VCC = 3V 0.7 0.5 V V VOL1 Output Low Voltage(4) (PB5, PB4, PB3 and PB2) IOL = 10 mA, VCC = 5V IOL = 5 mA, VCC = 3V 0.7 0.5 V V VOL2 Output Low Voltage(4) (PB5, Reset used as I/O) IOL =TBD mA, VCC = TBDV IOL =TBD mA, VCC = TBDV V V VOH Output High-voltage(5) ( PB1 and PB0) IOH = -20 mA, VCC = 5V IOH = -10 mA, VCC = 3V 4.2 2.5 V V

2535G–AVR–01/07 Notes: 1. All DC Characteristics contained in this data sheet ar e based on simulation and characterization of other AVR microcontrol- lers manufactured in the same process technology. These values are representing design targets, and will be updated after characterization of actual silicon. 2. “Max” means the highest value where the pin is guaranteed to be read as low. 3. “Min” means the lowest value where t he pin is guaranteed to be read as high. 4. Although each I/O port can sink more than the test conditions (20 mA at V CC = 5V, 10 mA at VCC = 3V for PB5, PB1:0, 10 mA at VCC = 5V, 5 mA at VCC = 3V for PB4:2) 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 (20 mA at V CC = 5V, 10 mA at VCC = 3V for PB5, PB1:0, 10 mA at VCC = 5V, 5 mA at VCC = 3V for PB4:2) 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 rela ted specification. Pins are not guaranteed to source current greater than the listed test condition. VOH1 Output High-voltage(5) (PB4, PB3 and PB2) IOH = -10 mA, VCC = 5V IOH = -5 mA, VCC = 3V 4.2 2.5 V V VOH2 Output High-voltage(5) (PB5, Reset used as I/O) IOH = - TBD mA, VCC = TBDV IOH = - TBD mA, VCC = TBDV V V IIL Input Leakage Current I/O Pin Vcc = 5.5V, pin low (absolute value) 1µ A IIH Input Leakage Current I/O Pin Vcc = 5.5V, pin high (absolute value) 1µ A RRST Reset Pull-up Resistor 30 80 k Ω Rpu I/O Pin Pull-up Resistor 20 50 k Ω ICC Power Supply Current Active 1MHz, VCC = 2V 0.35 mA Active 4MHz, VCC = 3V 1.8 mA Active 8MHz, VCC = 5V 6 mA Idle 1MHz, VCC = 2V 0.08 0.2 mA Idle 4MHz, VCC = 3V 0.41 1 mA Idle 8MHz, VCC = 5V 1.6 3 mA Power-down mode WDT enabled, VCC = 3V < 5 10 µA WDT disabled, VCC = 3V < 0.5 2 µA VACIO Analog Comparator Input Offset Voltage VCC = 5V Vin = VCC/2 < 10 40 mV IACLK Analog Comparator Input Leakage Current VCC = 5V Vin = VCC/2 -50 50 nA tACPD Analog Comparator Propagation Delay VCC = 2.7V VCC = 4.0V 750 500 ns TA = -40°C to 85°C, VCC = 1.8V to 5.5V (unless otherwise noted)(1) (Continued) Symbol Parameter Condition Min. Typ. Max. Units

122 ATtiny13

Figure 61. External Clock Drive Waveforms Table 57. External Clock Drive

Figure 62. Maximum Frequency vs. VCC, ATtiny13V Figure 63. Maximum Frequency vs. VCC, ATtiny13

10 MHz

4 MHz

20 MHz

124 ATtiny13

Table 58. ADC Characteristics, Single Ended Channels. -40°C - 85°C

1.5 LSB

2.5 LSB

0.5 LSB

2535G–AVR–01/07 Typical Characteristics The following charts show typical behavior. These figures are not tested during manu- facturing. 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 rail- to-rail 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 C L*VCC*f where CL = load capacitance, V CC = operating voltage and f = average switch- ing frequency of I/O pin. The parts are characterized at frequencies higher than test limits. Parts are not guaran- teed 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 dif- ferential current drawn by the Watchdog Timer. Active Supply Current Figure 64. Active Supply Current vs. Frequency (0.1 - 1.0 MHz) ACTIVE SUPPLY CURRENT vs. LOW FREQUENCY 0.1 - 1.0 MHz 5.5 V 5.0 V 4.5 V 4.0 V 3.3 V 2.7 V 1.8 V 0.2 0.4 0.6 0.8 1.2 Frequency (MHz) ICC (mA)

126 ATtiny13

Figure 65. Active Supply Current vs. Frequency (1 - 20 MHz) Figure 66. Active Supply Current vs. VCC (Internal RC Oscillator, 9.6 MHz)

128 ATtiny13

Figure 69. Active Supply Current vs. VCC (32 kHz External Clock)

130 ATtiny13

Figure 73. Idle Supply Current vs. VCC (Internal RC Oscillator, 4.8 MHz) Figure 74. Idle Supply Current vs. VCC (Internal RC Oscillator, 128 kHz)

132 ATtiny13

Figure 77. Power-Down Supply Current vs. VCC (Watchdog Timer Enabled)

134 ATtiny13

Figure 81. Reset Pull-up Resistor Current vs. Reset Pin Voltage (VCC = 2.7V)

136 ATtiny13

Figure 85. I/O Pin Sink Current vs. Output Voltage (Low Power Ports, VCC = 5V) Figure 86. I/O Pin Sink Current vs. Output Voltage (Low Power Ports, VCC = 2.7V)

138 ATtiny13

Figure 89. I/O Pin Source Current vs. Output Voltage (VCC = 2.7V) Figure 90. I/O Pin Source Current vs. Output Voltage (VCC = 1.8V)

140 ATtiny13

Figure 93. I/O Pin Sink Current vs. Output Voltage (VCC = 1.8V) Figure 94. Reset Pin as I/O - Source Current vs. Output Voltage (VCC = 5V)

142 ATtiny13

Figure 97. Reset Pin as I/O - Sink Current vs. Output Voltage (VCC = 5V) Figure 98. Reset Pin as I/O - Sink Current vs. Output Voltage (VCC = 2.7V)

144 ATtiny13

Figure 101. I/O Pin Input Threshold Voltage vs. VCC (VIL, I/O Pin Read as '0') Figure 102. I/O Pin Input Hysteresis vs. VCC

146 ATtiny13

Figure 105. Reset Pin as I/O - Pin Hysteresis vs. VCC Figure 106. Reset Input Threshold Voltage vs. VCC (VIH, Reset Pin Read as '1')

148 ATtiny13

Figure 109. BOD Thresholds vs. Temperature (BODLEVEL is 4.3V) Figure 110. BOD Thresholds vs. Temperature (BODLEVEL is 2.7V)

150 ATtiny13

Figure 113. Analog Comparator Offset Voltage vs. Common Mode Voltage (VCC = 5V) Figure 114. Analog Comparator Offset Voltage vs. Common Mode Voltage (VCC= 2.7V)

Figure 116. Calibrated 9.6 MHz RC Oscillator Frequency vs. VCC

152 ATtiny13

Figure 117. Calibrated 9.6 MHz RC Oscillator Frequency vs. Osccal Value Figure 118. Calibrated 4.8 MHz RC Oscillator Frequency vs. Temperature

154 ATtiny13

Figure 121. 128 kHz Watchdog Oscillator Frequency vs. VCC Figure 122. 128 kHz Watchdog Oscillator Frequency vs. Temperature

156 ATtiny13

Figure 125. Analog Comparator Current vs. VCC Figure 126. Programming Current vs. VCC

158 ATtiny13

Figure 129. Reset Pulse Width vs. VCC

2535G–AVR–01/07 Register Summary Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page 0x3F SREG I T H S V N Z C page 7 0x3D SPL SP[7:0] page 9 0x3C Reserved – 0x3B GIMSK – INT0 PCIE – – – – – page 56 0x3A GIFR – INTF0 PCIF – – – – – page 56 0x39 TIMSK0 – – – – OCIE0B OCIE0A TOIE0 – page 73 0x38 TIFR0 – – – – OCF0B OCF0A TOV0 – page 74 0x37 SPMCSR – – – CTPB RFLB PGWRT PGERS SELFPRGEN page 100 0x36 OCR0A Timer/Counter – Output Compare Register A page 73 0x35 MCUCR –P U D S E S M 1 S M 0 – ISC01 ISC00 page 51 0x34 MCUSR – – – – WDRF BORF EXTRF PORF page 34 0x33 TCCR0B FOC0A FOC0B – – WGM02 CS02 CS01 CS00 page 69 0x32 TCNT0 Timer/Counter (8-bit) page 73 0x31 OSCCAL Oscillator Calibration Register page 23 0x30 Reserved – 0x2F TCCR0A COM0A1 COM0A0 COM0B1 COM0B0 – – WGM01 WGM00 page 72 0x2E DWDR DWDR[7:0] page 97 0x2D Reserved – 0x2C Reserved – 0x2B Reserved – 0x2A Reserved – 0x29 OCR0B Timer/Counter – Output Compare Register B page 73 0x28 GTCCR TSM – – – – – – PSR10 page 76 0x27 Reserved – 0x26 CLKPR CLKPCE – – – CLKPS3 CLKPS2 CLKPS1 CLKPS0 page 25 0x25 Reserved – 0x24 Reserved – 0x23 Reserved – 0x22 Reserved – 0x21 WDTCR WDTIF WDTIE WDP3 WDCE WDE WDP2 WDP1 WDP0 page 39 0x20 Reserved – 0x1F Reserved – 0x1E EEARL – – EEPROM Address Register page 15 0x1D EEDR EEPROM Data Register page 15 0x1C EECR – – EEPM1 EEPM0 EERIE EEMPE EEPE EERE page 16 0x1B Reserved – 0x1A Reserved – 0x19 Reserved – 0x18 PORTB – – PORTB5 PORTB4 PORTB3 PORTB2 PORTB1 PORTB0 page 53 0x17 DDRB – – DDB5 DDB4 DDB3 DDB 2 DDB1 DDB0 page 53 0x16 PINB – – PINB5 PINB4 PINB3 PINB2 PINB1 PINB0 page 53 0x15 PCMSK – – PCINT5 PCINT4 PCINT3 PCINT2 PCINT1 PCINT0 page 57 0x14 DIDR0 – – ADC0D ADC2D ADC3D ADC1D AIN1D AIN0D page 79, page 94 0x13 Reserved – 0x12 Reserved – 0x11 Reserved – 0x10 Reserved – 0x0F Reserved – 0x0E Reserved – 0x0D Reserved – 0x0C Reserved – 0x0B Reserved – 0x0A Reserved – 0x09 Reserved – 0x08 ACSR ACD ACBG ACO ACI ACIE – ACIS1 ACIS0 page 77 0x07 ADMUX – REFS0 ADLAR – – – MUX1 MUX0 page 91 0x06 ADCSRA ADEN ADSC ADATE ADIF ADIE ADPS2 ADPS1 ADPS0 page 92 0x05 ADCH ADC Data Register High Byte page 93 0x04 ADCL ADC Data Register Low Byte page 93 0x03 ADCSRB –A C M E – – – ADTS2 ADTS1 ADTS0 page 94 0x02 Reserved – 0x01 Reserved – 0x00 Reserved –

160 ATtiny13

2535G–AVR–01/07 Note: 1. For compatibility with future devices, reserved bits shoul d be written to zero if accessed. Reserved I/O memory addresse s should never be written. 2. I/O Registers within the address range 0x00 - 0x1F are direct ly 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 specif ied bit, and can therefore be used on registers containing such Status Flags. The CBI and SBI instructions work with registers 0x00 to 0x1F only.

2535G–AVR–01/07 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 1 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 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 Relative Jump PC ← PC + k + 1 None 2 IJMP Indirect Jump to (Z) PC ← Z None 2 RCALL k Relative Subroutine Call PC ← PC + k + 1 None 3 ICALL Indirect Call to (Z) PC ← ZN o n e 3 RET Subroutine Return PC ← STACK None 4 RETI Interrupt Return PC ← STACK I 4 CPSE Rd,Rr Compare, Skip if Equal if (Rd = Rr) PC ← PC + 2 or 3 None 1/2/3 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 1 SBRC Rr, b Skip if Bit in Register Cleared if (Rr(b)=0) PC ← PC + 2 or 3 None 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 PC ←PC+k + 1 None 1/2 BRBC s, k Branch if Status Flag Cleared if (SREG(s) = 0) then PC ←PC+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) ← 1N o n e 2 CBI P,b Clear Bit in I/O Register I/O(P,b) ← 0N o n e 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),C←Rd(7) Z,C,N,V 1

162 ATtiny13

2535G–AVR–01/07 ROR Rd Rotate Right Through Carry Rd(7) ←C,Rd(n)← Rd(n+1),C←Rd(0) Z,C,N,V 1 ASR Rd Arithmetic Shift Right Rd(n) ← Rd(n+1), n=0..6 Z,C,N,V 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) ← TN o n e 1 SEC Set Carry C ← 1C 1 CLC Clear Carry C ← 0 C 1 SEN Set Negative Flag N ← 1N 1 CLN Clear Negative Flag N ← 0 N 1 SEZ Set Zero Flag Z ← 1Z 1 CLZ Clear Ze ro Flag Z ← 0 Z 1 SEI Global Interrupt Enable I ← 1I 1 CLI Global Interrupt Disable I ← 0 I 1 SES Set Signed Test Flag S ← 1S 1 CLS Clear Signed Test Flag S ← 0 S 1 SEV Set Twos Complement Overflow. V ← 1V 1 CLV Clear Twos Complement Overflow V ← 0 V 1 SET Set T in SREG T ← 1T 1 CLT Clear T in SREG T ← 0 T 1 SEH Set Half Carry Flag in SREG H ← 1H 1 CLH Clear Half Carry Flag in SREG H ← 0 H 1 DATA TRANSFER INSTRUCTIONS MOV Rd, Rr Move Between Registers Rd ← Rr None 1 MOVW Rd, Rr Copy Register Word Rd+1:Rd ← Rr+1:Rr None 1 LDI Rd, K Load Immediate Rd ← KN o n e 1 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 LPM 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 SPM Store Program Memory (z) ← R1:R0 None IN Rd, P In Port Rd ← PN o n e 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 Watchdog Reset (see specific descr. for WDR/Timer) None 1 BREAK Break For On-chip Debug Only None N/A Mnemonics Operands Description Operation Flags #Clocks

2535G–AVR–01/07

Ordering Information

Notes: 1. This device can also be supplied in wafer form. Please contact your local Atmel sales office for detailed ordering information and minimum quantities. 2. Pb-free packaging alternative, complies to the European Dire ctive for Restriction of Hazardous Substances (RoHS direc- tive). Also Halide free and fully Green 3. For Speed vs. V CC, see “Maximum Speed vs. VCC” on page 123. Speed (MHz)(3) Power Supply Ordering Code Package (1) Operation Range 10 1.8 - 5.5 ATtiny13V-10PI ATtiny13V-10PU(2) ATtiny13V-10SI ATtiny13V-10SU(2) ATtiny13V-10SSI ATtiny13V-10SSU (2)I ATtiny13V-10MU(2) 8P3 8P3 8S2 8S2 S8S1 S8S1 20M1 Industrial (-40°C to 85°C) 20 2.7 - 5.5 ATtiny13-20PI ATtiny13-20PU (2) ATtiny13-20SI ATtiny13-20SU (2) ATtiny13-20SSI ATtiny13-20SSU(2) ATtiny13-20MU(2) 8P3 8P3 8S2 8S2 S8S1 S8S1 20M1 Industrial (-40°C to 85°C) Package Type 8P3 8-lead, 0.300" Wide, Plastic Dual Inline Package (PDIP) 8S2 8-lead, 0.209" Wide, Plastic Small Outline Package (EIAJ SOIC) S8S1 8-lead, 0.150" Wide, Plastic Gull-Wing Small Outline (JEDEC SOIC) 20M1 20-pad, 4 x 4 x 0.8 mm Body, Lead Pitch 0.50 mm, Micro Lead Frame Package (MLF)

164 ATtiny13

2535G–AVR–01/07 Packaging Information 8P3

2325 Orchard Parkway

San Jose, CA 95131 TITLE DRAWING NO. R REV. 8P3, 8-lead, 0.300" Wide Body, Plastic Dual In-line Package (PDIP) 01/09/02 8P3 B D E e Lb2 b A2 A N eA c

4 PLCS

(Unit of Measure = inches) SYMBOL MIN NOM MAX NOTE Notes: 1. This drawing is for general information only; refer to JEDEC Drawing MS-001, Variation BA for additional information. 2. Dimensions A and L are measured with the package seated in JEDEC seating plane Gauge GS-3. 3. D, D1 and E1 dimensions do not include mold Flash or protrusions. Mold Flash or protrusions shall not exceed 0.010 inch. 4. E and eA measured with the leads constrained to be perpendicular to datum. 5. Pointed or rounded lead tips are preferred to ease insertion. A 0.210 2 A2 0.115 0.130 0.195 b 0.014 0.018 0.022 5 b2 0.045 0.060 0.070 6 b3 0.030 0.039 0.045 6 c 0.008 0.010 0.014 D 0.355 0.365 0.400 3 D1 0.005 3 E 0.300 0.310 0.325 4 E1 0.240 0.250 0.280 3 e 0.100 BSC eA 0.300 BSC 4 L 0.115 0.130 0.150 2

2535G–AVR–01/07 8S2 San Jose, CA 95131 TITLE DRAWING NO. R REV. 8S2, 8-lead, 0.209" Body, Plastic Small Outline Package (EIAJ) 4/7/06 8S2D COMMON DIMENSIONS (Unit of Measure = mm) SYMBOL MIN NOM MAX NOTE Notes: 1. Thi s drawing is for general information only; refer to EIAJ Drawing EDR-7320 for additional information. 2. Mi smatch of the upper and lower dies and resin burrs are not included. 3. It is recommended that upper and lower cavities be equal. If they are different, the larger dimension shall be regarded. 4. Determine s the true geometric position. A 1.70 2.16 A1 0.05 0.25 b 0. 35 0.4 8 5 C 0.15 0. 35 5 D 5.1 3 5. 35 E1 5.1 8 5.40 2, 3 E 7.70 8.26 L 0.51 0. 85 θ 0° 8° e 1.27 B SC 4 θθ NN EE TOP VIEWTOP VIEW CC E1E1 END VIEWEND VIEW AA bb LL A1A1 ee DD SIDE VIEWSIDE VIEW

166 ATtiny13

2535G–AVR–01/07 S8S1 San Jose, CA 95131 TITLE DRAWING NO. R REV. Note: 10/10/01 8S1, 8-lead (0.150" Wide Body), Plastic Gull Wing Small Outline (JEDEC SOIC) 8S1 A H N Top View C E End View A B L e D Side View COMMON DIMENSIONS (Unit of Measure = mm) SYMBOL MIN NOM MAX NOTE This drawing is for general information only. Refer to JEDEC Drawing MS-012 for proper dimensions, tolerances, datums, etc. A – – 1.75 B – – 0.51 C – – 0.25 D – – 5.00 E – – 4.00 e 1.27 BSC H – – 6.20 L – – 1.27

2535G–AVR–01/07 20M1 San Jose, CA 95131 TITLE DRAWING NO. R REV. 20M1, 20-pad, 4 x 4 x 0.8 mm Body, Lead Pitch 0.50 mm, A20M1 10/27/04 2.6 mm Exposed Pad, Micro Lead Frame Package (MLF) A 0.70 0.75 0.80 A1 – 0.01 0.05 A2 0.20 REF b 0.18 0.23 0.30 D 4.00 BSC D2 2.45 2.60 2.75 E 4.00 BSC E2 2.45 2.60 2.75 e 0.50 BSC L 0.35 0.40 0.55 SIDE VIEW Pin 1 ID Pin #1 Notch (0.20 R) BOTTOM VIEW TOP VIEW Note: Reference JEDEC Standard MO-220, Fig. 1 (SAW Singulation) WGGD-5. COMMON DIMENSIONS (Unit of Measure = mm) SYMBOL MIN NOM MAX NOTE D E e A 0.08 C L b

168 ATtiny13

2535G–AVR–01/07 Errata The revision letter in this section refers to the revision of the ATtiny13 device. ATtiny13 Rev. D  EEPROM can not be written below 1.9 Volt 1. EEPROM can not be written below 1.9 Volt Writing the EEPROM at VCC below 1.9 volts might fail. Problem Fix/Workaround Do not write the EEPROM when V CC is below 1.9 volts. ATtiny13 Rev. B  Wrong values read after Erase Only operation  High Voltage Serial Programming Flash, EEPROM, Fuse and Lock Bits may fail  Device may lock for further programming  debugWIRE communication not blocked by lock-bits  Watchdog Timer Interrupt disabled  EEPROM can not be written below 1.9 Volt 1. Wrong values read after Erase Only operation At supply voltages below 2.7 V, an EEPROM location that is erased by the Erase Only operation may read as programmed (0x00). Problem Fix/Workaround If it is necessary to read an EEPROM location after Erase Only, use an Atomic Write operation with 0xFF as data in order to erase a location. In any case, the Write Only operation can be used as intended. Thus no special considerations are needed as long as the erased location is not read before it is programmed. 2. High Voltage Serial Programming Fl ash, EEPROM, Fuse and Lock Bits may fail Writing to any of these locations and bits may in some occasions fail. Problem Fix/Workaround After a writing has been initiated, always observe the RDY/BSY signal. If the writing should fail, rewrite until the RDY/BSY verifies a correct writing. This will be fixed in revision D. 3. Device may lock for further programming Special combinations of fuse bits will lock the device for further programming effec- tively turning it into an OTP device. The following combinations of settings/fuse bits will cause this effect: – 128 kHz internal oscillator (CKSEL[1 ..0] = 11), shortest start-up time (SUT[1..0] = 00), Debugwire enabled (DWEN = 0) or Reset disabled RSTDISBL = 0. – 9.6 MHz internal oscillator (CKSEL[1 ..0] = 10), shortest start-up time (SUT[1..0] = 00), Debugwire enabled (DWEN = 0) or Reset disabled RSTDISBL = 0. – 4.8 MHz internal oscillator (CKSEL[1 ..0] = 01), shortest start-up time (SUT[1..0] = 00), Debugwire enabled (DWEN = 0) or Reset disabled RSTDISBL = 0. Problem fix/ Workaround Avoid the above fuse combinations. Selecting longer start-up time will eliminate the problem.

2535G–AVR–01/07 4. debugWIRE communication not blocked by lock-bits When debugWIRE on-chip debug is enabled (DWEN = 0), the contents of program memory and EEPROM data memory can be read even if the lock-bits are set to block further reading of the device. Problem fix/ Workaround Do not ship products with on-chip debug of the tiny13 enabled. 5. Watchdog Timer Interrupt disabled If the watchdog timer interrupt flag is not cleared before a new timeout occurs, the watchdog will be disabled, and the interrupt flag will automatically be cleared. This is only applicable in interrupt only mode. If the Watchdog is configured to reset the device in the watchdog time-out following an interrupt, the device works correctly. Problem fix / Workaround Make sure there is enough time to always service the first timeout event before a new watchdog timeout occurs. This is done by selecting a long enough time-out period. 6. EEPROM can not be written below 1.9 Volt Writing the EEPROM at V CC below 1.9 volts might fail. Problem Fix/Workaround Do not write the EEPROM when V CC is below 1.9 volts. ATtiny13 Rev. A Revision A has not been sampled.

170 ATtiny13

2535G–AVR–01/07 Datasheet Revision History Please note that the referring page numbers in this section are referring to this docu- ment. The referring revision in this section are referring to the document revision. Changes from Rev. 2535F-04/06 to Rev. 2535G-01/07 Changes from Rev. 2535E-10/04 to Rev. 2535F-04/06 Changes from Rev. 2535D-04/04 to Rev. 2535E-10/04 Changes from Rev. 2535C-02/04 to Rev. 2535D-04/04 Changes from Rev. 2535B-01/04 to Rev. 2535C-02/04 1. Removed Preliminary. 2. Updated Table 12 on page 31, Table 16 on page 39,Table 51 on page 111. 3. Removed Note from Table 15 on page 35. 4. Updated “Bit 6 – ACBG: Analog Comparator Bandgap Select” on page 78. 5. Updated “Prescaling and Conversion Timing” on page 83. 6. Updated Figure 56 on page 111. 7. Updated “DC Characteristics” on page 120. 8. Updated “Ordering Information” on page 163. 9. Updated “Packaging Information” on page 164. 1. Revision not published. 1. Bits EEMWE/EEWE changed to EEMPE/EEPE in document. 2. Updated “Pinout ATtiny13” on page 2. 3. Updated “Write Fuse Low Bits” in Table 55 on page 117, Table 57 on page 122. 2. Added “Pin Change Interrupt Timing” on page 54. 4. Updated “General Interrupt Mask Register – GIMSK” on page 56. 5. Updated “Pin Change Mask Register – PCMSK” on page 57. 6. Updated item 4 in “Serial Programming Algorithm” on page 108. 7. Updated “Enter High-voltage Serial Programming Mode” on page 113. 8. Updated “DC Characteristics” on page 120. 9. Updated “Typical Characteristics” on page 125. 10. Updated “Ordering Information” on page 163. 11. Updated “Packaging Information” on page 164. 12. Updated “Errata” on page 168. 1. Maximum Speed Grades changed - 12MHz to 10MHz - 24MHz to 20MHz 2. Updated “Serial Programming Instruction Set” on page 110. 3. Updated “Maximum Speed vs. VCC” on page 123 4. Updated “Ordering Information” on page 163 1. C-code examples updated to use legal IAR syntax. 2. Replaced occurrences of WDIF with WDTIF and WDIE with WDTIE. 3. Updated “Stack Pointer” on page 9.

2535G–AVR–01/07 Changes from Rev. 2535A-06/03 to Rev. 2535B-01/04 4. Updated “Calibrated Internal RC Oscillator” on page 23. 5. Updated “Oscillator Calibration Register – OSCCAL” on page 23. 6. Updated typo in introduction on “Watchdog Timer” on page 36. 7. Updated “ADC Conversion Time” on page 85. 8. Updated “Serial Downloading” on page 107. 9. Updated “Electrical Characteristics” on page 120. 10. Updated “Ordering Information” on page 163. 11. Removed rev. C from “Errata” on page 168. 1. Updated Figure 2 on page 3. 2. Updated Table 12 on page 31, Table 17 on page 41, Table 37 on page 92 and Table 57 on page 122. 3. Updated “Calibrated Internal RC Oscillator” on page 23. 4. Updated the whole “Watchdog Timer” on page 36. 5. Updated Figure 54 on page 107 and Figure 57 on page 112. 6. Updated registers “MCU Control Register – MCUCR” on page 51, “Timer/Counter Control Register B – TCCR0B” on page 72 and “Digital Input Disable Register 0 – DIDR0” on page 79. 7. Updated Absolute Maximum Ratings and DC Characteristics in “Electrical Characteristics” on page 120. 8. Added “Maximum Speed vs. VCC” on page 123 9. Updated “ADC Characteristics” on page 124. 10. Updated “Typical Characteristics” on page 125. 11. Updated “Ordering Information” on page 163. 12. Updated “Packaging Information” on page 164. 13. Updated “Errata” on page 168. 14. Changed instances of EEAR to EEARL.

172 ATtiny13

2535G–AVR–01/07

i ATtiny13 2535G–AVR–01/07

2535G–AVR–01/07

2535G–AVR–01/07 Maximum Speed vs. V

2535G–AVR–01/07

2535G–AVR–01/07 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 CONDI- TIONS OF SALE LOCATED ON ATMEL ’S WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTOR Y WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO , THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICU LAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR I NCIDEN- TAL 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 AT MEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or co mpleteness of the contents of this document and reserves the rig ht to make changes to specifications and product descriptions at any time without notice. Atmel does not make any commitment to update the information contained her ein. Atmel’s products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. Atmel Corporation Atmel Operations San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Regional Headquarters Europe Atmel Sarl Route des Arsenaux 41 Case Postale 80 CH-1705 Fribourg Switzerland Tel: (41) 26-426-5555 Fax: (41) 26-426-5500 Asia Room 1219 Chinachem Golden Plaza

77 Mody Road Tsimshatsui

Tel: (852) 2721-9778 Fax: (852) 2722-1369 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 Memory San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 Microcontrollers San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 La Chantrerie BP 70602

44306 Nantes Cedex 3, France

13106 Rousset Cedex, France

1150 East Cheyenne Mtn. Blvd. Colorado Springs, CO 80906, USA Tel: 1(719) 576-3300 Fax: 1(719) 540-1759 Scottish Enterprise Technology Park Maxwell Building East Kilbride G75 0QR, Scotland Tel: (44) 1355-803-000 Fax: (44) 1355-242-743 RF/Automotive Theresienstrasse 2 Postfach 3535

74025 Heilbronn, Germany

1150 East Cheyenne Mtn. Blvd. Colorado Springs, CO 80906, USA Tel: 1(719) 576-3300 Fax: 1(719) 540-1759 Biometrics/Imaging/Hi-Rel MPU/ High Speed Converters/RF Datacom Avenue de Rochepleine BP 123

38521 Saint-Egreve Cedex, France

www.atmel.com/literature © 2007 Atmel Corporation . All rights reserved. Atmel ®, logo and combinations thereof, AVR ®, AVR Studio ®, and Everywhere Y ou Are ® are registered trademarks of Atmel Corporation or its subsidia ries. Other terms and product names may be trademarks of others.