ATMEGA169PA-MNR Atmel, ATMEGA169PA-MNR Datasheet
![no-image](/images/manufacturer_photos/0/0/78/atmel_sml.jpg)
ATMEGA169PA-MNR
Specifications of ATMEGA169PA-MNR
Related parts for ATMEGA169PA-MNR
ATMEGA169PA-MNR Summary of contents
Page 1
... MIPS Throughput at 20 MHz (ATmega329A/329PA/3290A/3290PA/6490A/6490P) – On-Chip 2-cycle Multiplier • High Endurance Non-volatile Memory segments – In-System Self-programmable Flash Program Memory • 16K Bytes (ATmega169A/ATmega169PA) • 32K Bytes (ATmega329A/ATmega329PA/ATmega3290A/ATmega3290PA) • 64K Bytes (ATmega649A/ATmega649P/ATmega6490A/ATmega6490P) – EEPROM • 512bytes (ATmega169A/ATmega169PA) • 1K bytes (ATmega329A/ATmega329PA/ATmega3290A/ATmega3290PA) • ...
Page 2
... ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 1. Pin Configurations 1.1 Pinout - 64A (TQFP) and 64M1 (QFN/MLF) Figure 1-1. Pinout ATmega169A/ATmega169PA/ATmega329A/ATmega329PA/ATmega649A/ATmega649P LCDCAP 1 (RXD/PCINT0) PE0 2 (TXD/PCINT1) PE1 3 (XCK/AIN0/PCINT2) PE2 4 (AIN1/PCINT3) PE3 5 (USCK/SCL/PCINT4) PE4 6 (DI/SDA/PCINT5) PE5 7 (DO/PCINT6) PE6 8 (CLKO/PCINT7) PE7 9 (SS/PCINT8) PB0 10 (SCK/PCINT9) PB1 11 (MOSI/PCINT10) PB2 12 (MISO/PCINT11) PB3 13 (OC0A/PCINT12) PB4 ...
Page 3
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 1.2 Pinout - 100A (TQFP) Figure 1-2. Pinout ATmega3290A/ATmega3290PA/ATmega6490A/ATmega6490P 1 LCDCAP 2 (RXD/PCINT0) PE0 3 (TXD/PCINT1) PE1 4 (XCK/AIN0/PCINT2) PE2 5 (AIN1/PCINT3) PE3 (USCK/SCL/PCINT4) PE4 6 (DI/SDA/PCINT5) PE5 7 8 (DO/PCINT6) PE6 9 (CLKO/PCINT7) PE7 10 VCC 11 GND ...
Page 4
... A8 PB4 A16 B15 A17 8284A–AVR–10/10 Pinout ATmega169A/ATmega169PA Top view DRQFN-64 Pinout ATmega169A/ATmega169PA PB7 A18 PB6 B16 PG3 A19 PG4 B17 RESET A20 VCC B18 GND A21 XTAL2 (TOSC2) B19 XTAL1 (TOSC1) A22 PD0 (SEG22) B20 PD1 (SEG21) A23 PD2 (SEG20) ...
Page 5
... ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 2. Overview The ATmega169A/169PA/329A/329PA/3290A/3290PA/649A/649P/6490A/6490P is a low-power CMOS 8-bit microcon- troller based on the Atmel AVR ® ® the ATmega169A/169PA/329A/329PA/3290A/3290PA/649A/649P/6490A/6490P achieves throughputs approaching 1 MIPS per MHz allowing the system designer to optimize power consumption versus processing speed. 2.1 Block Diagram Figure 2-1. Block Diagram ...
Page 6
... Suppression QTouch Suite toolchain allows you to explore, develop and debug your own touch applications. The device is manufactured using Atmel’s high density non-volatile memory technology. The On-chip In-System re-Programmable (ISP) Flash allows the program memory to be repro- grammed In-System through an SPI serial interface conventional non-volatile memory programmer On-chip Boot program running on the AVR core ...
Page 7
... ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 2.2 Comparison Between ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 2-1. Differences between: ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Device Flash ATmega169A 16 Kbyte ATmega169PA 16 Kbyte ATmega329A 32 Kbyte ATmega329PA 32 Kbyte ATmega3290A 32K bytes ATmega3290PA 32 Kbyte ATmega649A 64 Kbyte ATmega649P 64 Kbyte ATmega6490A 64 Kbyte ATmega6490P 64 Kbyte 8284A–AVR–10/10 EEPROM RAM 512 Bytes 1 Kbyte ...
Page 8
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 2.3 Pin Descriptions The following section describes the I/O-pin special functions. 2.3 Digital supply voltage. 2.3.2 GND Ground. 2.3.3 Port A (PA7...PA0) Port 8-bit bi-directional I/O port with internal pull-up resistors (selected for each ...
Page 9
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Port D also serves the functions of various special features of the ATmega169A/169PA/329A/329PA/3290A/3290PA/649A/649P/6490A/6490P as listed on 79. 2.3.7 Port E (PE7...PE0) Port 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port ...
Page 10
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P bility. As inputs, Port J pins that are externally pulled low will source current if the pull-up resistors are activated. The Port J pins are tri-stated when a reset condition becomes active, even if the clock is not running. ...
Page 11
... ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 3. Resources A comprehensive set of development tools, application notes and datasheets are available for download on http://www.atmel.com/avr. Note: 4. Data Retention Reliability Qualification results show that the projected data retention failure rate is much less than 1 PPM over 20 years at 85°C or 100 years at 25°C. ...
Page 12
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 6. AVR CPU Core 6.1 Overview This section discusses the AVR core architecture in general. The main function of the CPU core is to ensure correct program execution. The CPU must therefore be able to access memories, perform calculations, ...
Page 13
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P ical ALU operation, two operands are output from the Register File, the operation is executed, and the result is stored back in the Register File – in one clock cycle. Six of the 32 registers can be used as ...
Page 14
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P conditional operations. Note that the Status Register is updated after all ALU operations, as specified in the Instruction Set Reference. This will in many cases remove the need for using the dedicated compare instructions, resulting in faster and more ...
Page 15
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P • Bit 0 – C: Carry Flag The Carry Flag C indicates a carry in an arithmetic or logic operation. See the “Instruction Set Description” for detailed information. 6.5 General Purpose Register File The Register File is optimized for ...
Page 16
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 6.5.1 The X-register, Y-register, and Z-register The registers R26...R31 have some added functions to their general purpose usage. These reg- isters are 16-bit address pointers for indirect addressing of the data space. The three indirect address registers X, Y, ...
Page 17
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 6.6.1 SPH and SPL – Stack pointer High and Stack Pointer Low Bit 0x3E (0x5E) 0x3D (0x5D) Read/Write Initial Value Note: 6.7 Instruction Execution Timing This section describes the general access timing concepts for instruction execution. The AVR CPU ...
Page 18
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 6.8 Reset and Interrupt Handling The AVR provides several different interrupt sources. These interrupts and the separate Reset Vector each have a separate program vector in the program memory space. All interrupts are assigned individual enable bits which must ...
Page 19
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P CLI instruction. The following example shows how this can be used to avoid interrupts during the timed EEPROM write sequence. Assembly Code Example in r16, SREG cli sbi EECR, EEMWE sbi EECR, EEWE out SREG, r16 C Code Example ...
Page 20
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 7. AVR Memories ATmega169A/169PA/329A/329PA/3290A/3290PA/649A/649P/6490A/6490P. The AVR archi- tecture has two main memory spaces, the Data Memory and the Program Memory space. In addition, the ATmega169A/169PA/329A/329PA/3290A/3290PA/649A/649P/6490A/6490P fea- tures an EEPROM Memory for data storage. All three ...
Page 21
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 7.2 SRAM Data Memory Figure 7-2 The ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P is a complex microcontroller with more peripheral units than can be supported within the 64 locations reserved in the Opcode for the IN and OUT instructions. For the Extended I/O space ...
Page 22
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Figure 7-3. 7.3 EEPROM Data Memory The ATmega169A/169PA/329A/329PA/3290A/3290PA/649A/649P/6490A/6490P contains 512/1K/2K bytes of data EEPROM memory organized as a separate data space, in which single bytes can be read and written. The EEPROM has an endurance of at ...
Page 23
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 1. Wait until EEWE becomes zero. 2. Wait until SPMEN in SPMCSR becomes zero. 3. Write new EEPROM address to EEAR (optional). 4. Write new EEPROM data to EEDR (optional). 5. Write a logical one to the EEMWE bit ...
Page 24
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Assembly Code Example EEPROM_write: C Code Example void EEPROM_write(unsigned int uiAddress, unsigned char ucData The next code examples show assembly and C functions for reading the EEPROM. The exam- ples assume that interrupts are controlled so that ...
Page 25
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Assembly Code Example EEPROM_read: C Code Example unsigned char EEPROM_read(unsigned int uiAddress 7.3.2 EEPROM Write During Power-down Sleep Mode When entering Power-down sleep mode while an EEPROM write operation is active, the EEPROM write operation will continue, ...
Page 26
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Keep the AVR RESET active (low) during periods 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, ...
Page 27
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 7.6 Register Description 7.6.1 EEARH and EEARL – EEPROM Address Register ATmega169A/169PA Bit 0x22 (0x42) 0x21 (0x41) Read/Write Initial Value • Bits 15:9 – Reserved These bits are reserved and will always be read as zero. • Bits 8:0 ...
Page 28
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 7.6.3 EEDR – EEPROM Data Register Bit 0x20 (0x40) Read/Write Initial Value • 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 ...
Page 29
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 7.6.6 GPIOR1 – General Purpose I/O Register 1 Bit 0x2A (0x4A) Read/Write Initial Value 7.6.7 GPIOR0 – General Purpose I/O Register 0 Bit 0x1E (0x3E) Read/Write Initial Value 8284A–AVR–10/ MSB R/W R/W R/W R/W 0 ...
Page 30
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 8. System Clock and Clock Options 8.1 Clock Systems and their Distribution Figure 8-1 need not be active at a given time. In order to reduce power consumption, the clocks to modules not being used can be halted by ...
Page 31
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 8.1.4 Asynchronous Timer Clock – clk The Asynchronous Timer clock allows the Asynchronous Timer/Counter and the LCD controller to be clocked directly from an external clock or an external 32 kHz clock crystal. The dedicated clock domain allows using ...
Page 32
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 8.4 Calibrated Internal RC Oscillator By default, the Internal RC Oscillator provides an approximate 8 MHz clock. Though voltage and temperature dependent, this clock can be very accurately calibrated by the user. The device is shipped with the CKDIV8 ...
Page 33
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P electromagnetic noise of the environment. Some initial guidelines for choosing capacitors for use with crystals are given in the manufacturer should be used. Figure 8-2. The Oscillator can operate in three different modes, each optimized for a specific frequency ...
Page 34
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 8-6. CKSEL0 Notes: 8.6 Low-frequency Crystal Oscillator The Low-frequency Crystal Oscillator is optimized for use with a 32.768 kHz watch crystal. When selecting crystals, load capacitance and crystal’s Equivalent Series Resistance, ESR must be taken ...
Page 35
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P The Low-frequency Crystal Oscillator provides an internal load capacitance, each TOSC pin. Table 8-9. ATmega169A/169PA/329A/329PA/3290A /3290PA/649A/649P/6490A/6490P The capacitance (Ce + Ci) needed at each TOSC pin can be calculated by using: where optional external capacitors as ...
Page 36
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Figure 8-3. When this clock source is selected, start-up times are determined by the SUT Fuses as shown in Table 8-13. Table 8-12. ATmega169A/169PA/649A/649P ATmega329A/329PA/3290A/3290PA/6490A/6490P Table 8-13. SUT1.. When applying an external clock ...
Page 37
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 8.9 Timer/Counter Oscillator ATmega169A/169PA/329A/329PA/3290A/3290PA/649A/649P/6490A/6490P uses the same crystal oscillator for Low-frequency Oscillator and Timer/Counter Oscillator. See Crystal Oscillator” on page 34 ATmega169A/169PA/329A/329PA/3290A/3290PA/649A/649P/6490A/6490P share the Timer/Counter Oscillator Pins (TOSC1 and TOSC2) with XTAL1 and XTAL2. When using the Timer/Counter Oscillator, ...
Page 38
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 8.11 Register Description 8.11.1 OSCCAL – Oscillator Calibration Register Bit (0x66) Read/Write Initial Value • Bits 7:0 – CAL7:0: Oscillator Calibration Value The Oscillator Calibration Register is used to trim the Calibrated Internal RC Oscillator to remove process variations ...
Page 39
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 1. Write the Clock Prescaler Change Enable (CLKPCE) bit to one and all other bits in CLKPR to zero. 2. Within four cycles, write the desired value to CLKPS while writing a zero to CLKPCE. Interrupts must be disabled ...
Page 40
... When the Brown-out Detector (BOD) is enabled by BODLEVEL fuses - see 313 and onwards, the BOD is actively monitoring the power supply voltage during a sleep period. To save power possible to disable the BOD by software for some of the sleep- modes, see 8284A–AVR–10/ BOD disable is only available for ATmega169PA/329PA/3290PA/6490P. Oscillators ( ...
Page 41
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P level as when BOD is globally disabled by fuses. If BOD is disabled in software, the BOD func- tion is turned off immediately after entering the sleep mode. Upon wake-up from sleep, BOD is automatically enabled again. This ensures ...
Page 42
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P interrupt on INT0 pin change interrupt can wake up the MCU. This sleep mode basically halts all generated clocks, allowing operation of asynchronous modules only. Note that if a level triggered interrupt is used for wake-up from ...
Page 43
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 9.10 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 possible, and the sleep mode should be ...
Page 44
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 9.10.6 Port Pins When entering a sleep mode, all port pins should be configured to use minimum power. The most important is then to ensure that no pins drive resistive loads. In sleep modes where both the I/O clock ...
Page 45
... Standby mode is only recommended for use with external crystals or resonators (1) (1) JTD BODS BODSE R/W R/W R Only available in the picoPower devices ATmega169PA/329PA/3290PA/649P/6490P. 40. Writing to the BODS bit is controlled by a timed sequence and an enable bit – SM2 SM1 SM0 R R/W R/W R Table 9-2. ...
Page 46
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P The BODS bit is active three clock cycles after it is set. A sleep instruction must be executed while BODS is active in order to turn off the BOD for the actual sleep mode. The BODS bit is automatically ...
Page 47
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 10. System Control and Reset 10.1 Resetting the AVR During reset, all I/O Registers are set to their initial values, and the program starts execution from the Reset Vector. The instruction placed at the Reset Vector must be a ...
Page 48
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Figure 10-1. Reset Logic BODLEVEL [2..0] 10.2.1 Power-on Reset A Power-on Reset (POR) pulse is generated by an On-chip detection circuit. The detection level is defined below the detection level. The POR circuit can be used ...
Page 49
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Figure 10-2. MCU Start-up, RESET Tied to V TIME-OUT INTERNAL Figure 10-3. MCU Start-up, RESET Extended Externally TIME-OUT INTERNAL 10.2.2 External Reset An External Reset is generated by a low level on the RESET pin. Reset pulses longer than ...
Page 50
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 10.2.3 Brown-out Detection ATmega169A/169PA/329A/329PA/3290A/3290PA/649A/649P/6490A/6490P has an On-chip Brown-out Detection (BOD) circuit for monitoring the fixed trigger level. The trigger level for the BOD can be selected by the BODLEVEL Fuses. The trigger level has a hysteresis ...
Page 51
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 10.3 Internal Voltage Reference ATmega169A/169PA/329A/329PA/3290A/3290PA/649A/649P/6490A/6490P features an inter- nal bandgap reference. This reference is used for Brown-out Detection, and it can be used as an input to the Analog Comparator or the ADC. 10.3.1 Voltage Reference Enable Signals and ...
Page 52
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Figure 10-7. Watchdog Timer 10.4.1 Timed Sequences for Changing the Configuration of the Watchdog Timer The sequence for changing configuration differs slightly between the two safety levels. Separate procedures are described for each level. 10.4.2 Safety Level 1 In ...
Page 53
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 10.5 Register Description 10.5.1 MCUSR – MCU Status Register The MCU Status Register provides information on which reset source caused an MCU reset. Bit 0x35 (0x55) Read/Write Initial Value • Bit 4 – JTRF: JTAG Reset Flag This bit ...
Page 54
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P • Bit 3 – WDE: Watchdog Enable When the WDE is written to logic one, the Watchdog Timer is enabled, and if the WDE is written to logic zero, the Watchdog Timer function is disabled. WDE can only be ...
Page 55
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P The following code example shows one assembly and one C function for turning off the WDT. The example assumes that interrupts are controlled (e.g. by disabling interrupts globally) so that no interrupts will occur during execution of these functions. ...
Page 56
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 11. Interrupts 11.1 Overview ...
Page 57
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 11-2 BOOTRST and IVSEL settings. If the program never enables an interrupt source, the Interrupt Vectors are not used, and regular program code can be placed at these locations. This is also the case if the Reset Vector ...
Page 58
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 0x0036 0x0037 When the BOOTRST Fuse is unprogrammed, the Boot section size set to 4K bytes and the IVSEL bit in the MCUCR Register is set before any interrupts are enabled, the most typical and general program setup for ...
Page 59
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 0x382C/0x782C ; 0x382E/0x782ERESET:ldir16,high(RAMEND); Main program start 0x382F/0x782F 0x3830/0x7830 0x3831/0x7831 0x3832/0x7832 0x3833/0x7833 11.2.1 Moving Interrupts Between Application and Boot Space he General Interrupt Control Register controls the placement of the Interrupt Vector table, see ”MCUCR – MCU Control Register” on ...
Page 60
... IVSEL is written. Setting the IVCE bit will disable interrupts, as explained in the description in Space” on page 8284A–AVR–10/ (1) (1) JTD BODS BODSE R Only available in the picoPower devices ATmega169PA/329PA/3290PA/649P/6490P. for details. 59. See Code Example PUD – – IVSEL R R ” ...
Page 61
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 12. External Interrupts 12.1 Overview The External Interrupts are triggered by the INT0 pin or any of the PCINT30:0 pins that, if enabled, the interrupts will trigger even if the INT0 or PCINT30:0 pins are configured as outputs. This ...
Page 62
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 12.2 Pin Change Interrupt Timing An example of timing of a pin change interrupt is shown in Figure 12-1. Pin Change Interrupt 12.3 Register Description 12.3.1 EICRA – External Interrupt Control Register A The External Interrupt Control Register A ...
Page 63
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 12-1. ISC01 12.3.2 EIMSK – External Interrupt Mask Register Bit 0x1D (0x3D) Read/Write Initial Value • Bit 7 – PCIE3: Pin Change Interrupt Enable 3 When the PCIE3 bit is set (one) and the ...
Page 64
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P interrupt request even if INT0 is configured as an output. The corresponding interrupt of External Interrupt Request 0 is executed from the INT0 Interrupt Vector. 12.3.3 EIFR – External Interrupt Flag Register Bit 0x1C (0x3C) Read/Write Initial Value • ...
Page 65
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 12.3.4 PCMSK3 – Pin Change Mask Register 3 Bit (0x73) Read/Write Initial Value • Bit 6:0 – PCINT30:24: Pin Change Enable Mask 30...24 Each PCINT30:24-bit selects whether pin change interrupt is enabled on the corresponding I/O pin. If PCINT30:24 ...
Page 66
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 13. I/O-Ports 13.1 Overview All AVR ports have true Read-Modify-Write functionality when used as general digital I/O ports. This means that the direction of one port pin can be changed without unintentionally changing the direction of any other pin ...
Page 67
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Functions” on page nate functions. Note that enabling the alternate function of some of the port pins does not affect the use of the other pins in the port as general digital I/O. 13.2 Ports as General Digital I/O ...
Page 68
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P be configured as an output pin. The port pins are tri-stated when reset condition becomes active, even if no clocks are running. If PORTxn is written logic one when the pin is configured as an output pin, the port ...
Page 69
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Figure 13-3. Synchronization when Reading an Externally Applied Pin value INSTRUCTIONS Consider the clock period starting shortly after the first falling edge of the system clock. The latch is closed when the clock is low, and goes transparent when ...
Page 70
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Assembly Code Example C Code Example unsigned char i; Note: 13.2.5 Digital Input Enable and Sleep Modes As shown in input of the Schmitt-trigger. The signal denoted SLEEP in the figure, is set by the MCU Sleep Controller in ...
Page 71
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 13.2.6 Unconnected Pins If some pins are unused 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, float- ing ...
Page 72
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 13.3 Alternate Port Functions Most port pins have alternate functions in addition to being general digital I/Os. shows how the port pin control signals from the simplified ridden by alternate functions. The overriding signals may not be present in ...
Page 73
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 13-2. Signal Name PUOE PUOV DDOE DDOV PVOE PVOV PTOE DIEOE DIEOV DI AIO The following subsections shortly describe the alternate functions for each port, and relate the overriding signals to the alternate function. Refer to the alternate ...
Page 74
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 13.3.1 Alternate Functions of Port A The Port A has an alternate function as COM0:3 and SEG0:3 for the LCD Controller. Table 13-3. Port Pin PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0 Table 13-4 shown in Table 13-4. ...
Page 75
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 13-5. Signal Name PUOE PUOV DDOE DDOV PVOE PVOV PTOE DIEOE DIEOV DI AIO 13.3.2 Alternate Functions of Port B The Port B pins with alternate functions are shown in Table 13-6. Port Pin PB7 PB6 PB5 PB4 ...
Page 76
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P • OC1B/PCINT14, Bit 6 OC1B, Output Compare Match B output: The PB6 pin can serve as an external output for the Timer/Counter1 Output Compare B. The pin has to be configured as an output (DDB6 set (one)) to serve ...
Page 77
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P low. When the SPI is enabled as a Master, the data direction of this pin is controlled by DDB0. When the pin is forced input, the pull-up can still be controlled by the PORTB0 bit PCINT8, ...
Page 78
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 13.3.3 Alternate Functions of Port C The Port C has an alternate function as SEG for the LCD Controller. Table 13-9. Port Pin PC7 PC6 PC5 PC4 PC3 PC2 PC1 PC0 The alternate pin configuration is as follows: • ...
Page 79
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 13-11. Overriding Signals for Alternate Functions in PC3:PC0 Signal Name PUOE PUOV DDOE DDOV PVOE PVOV PTOE DIEOE DIEOV DI AIO 13.3.4 Alternate Functions of Port D The Port D pins with alternate functions are shown in Table ...
Page 80
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 13-13 shown in Table 13-13. Overriding Signals for Alternate Functions PD7:PD4 Signal Name PUOE PUOV DDOE DDOV PVOE PVOV PTOE DIEOE DIEOV DI (1) AIO (2) AIO 1. 2. Table 13-14. Overriding Signals for Alternate Functions in PD3:PD0 ...
Page 81
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 13.3.5 Alternate Functions of Port E The Port E pins with alternate functions are shown in Table 13-15. Port E Pins Alternate Functions Port Pin PE7 PE6 PE5 PE4 PE3 PE2 PE1 PE0 • PCINT7 – Port E, Bit ...
Page 82
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P • XCK/AIN0/PCINT2 – Port E, Bit 2 XCK, USART0 External Clock. The Data Direction Register (DDE2) controls whether the clock is output (DDE2 set) or input (DDE2 cleared). The XCK pin is active only when the USART0 oper- ates ...
Page 83
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 13-17. Overriding Signals for Alternate Functions in PE3:PE0 Signal Name PUOE PUOV DDOE DDOV PVOE PVOV PTOE DIEOE DIEOV DI AIO Note: 13.3.6 Alternate Functions of Port F The Port F has an alternate function as analog input ...
Page 84
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P • TDO, ADC6 – Port F, Bit 6 ADC6, Analog to Digital Converter, Channel 6 TDO, JTAG Test Data Out: Serial output data from Instruction Register or Data Register. When the JTAG interface is enabled, this pin can not ...
Page 85
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 13-20. Overriding Signals for Alternate Functions in PF3:PF0 Signal Name PUOE PUOV DDOE DDOV PVOE PVOV PTOE DIEOE DIEOV DI AIO 13.3.7 Alternate Functions of Port G The alternate pin configuration is as follows: Table 13-21. Port G ...
Page 86
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P • SEG – Port G, Bit 2 SEG, LCD front plane 4/4. • SEG – Port G, Bit 1 SEG, Segment driver 17/13. • SEG – Port G, Bit 0 SEG, LCD front plane 18/14. Table 13-21 shown in ...
Page 87
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 13-23. Overriding Signals for Alternate Functions in PG3:0 Signal Name PUOE PUOV DDOE DDOV PVOE PVOV PTOE DIEOE DIEOV DI (1) AIO (2) AIO 1. 2. 13.3.8 Alternate Functions of Port H Port H is only present in ...
Page 88
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P • PCINT22/SEG – Port H, Bit 6 PCINT22, Pin Change Interrupt Source 22: The PH6 pin can serve as an external interrupt source. SEG, LCD front plane 37. • PCINT21/SEG – Port H, Bit 5 PCINT21, Pin Change Interrupt ...
Page 89
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 13-25 shown in Table 13-25. Overriding Signals for Alternate Functions in PH7:4 Signal Name PUOE PUOV DDOE DDOV PVOE PVOV PTOE DIEOE DIEOV DI (1) AIO (2) AIO 1. 2. Table 13-26. Overriding Signals for Alternate Functions in ...
Page 90
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 13.3.9 Alternate Functions of Port J Port J is only present in ATmega3290A/3290PA/6490A/6490P. The alternate pin configuration is as follows: Table 13-27. Port J Pins Alternate Functions Port Pin PJ6 PJ5 PJ4 PJ3 PJ2 PJ1 PJ0 The alternate pin ...
Page 91
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P • PCINT28/SEG – Port J, Bit 4 PCINT28, Pin Change Interrupt Source 28: The PE28 pin can serve as an external interrupt source. SEG, LCD front plane 29. • PCINT27/SEG – Port J, Bit 3 PCINT27, Pin Change Interrupt ...
Page 92
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 13-28 on page 92 the overriding signals shown in Table 13-28. Overriding Signals for Alternate Functions in PJ7:4 Signal Name PUOE PUOV DDOE DDOV PVOE PVOV PTOE DIEOE DIEOV DI AIO Table 13-29. Overriding Signals for Alternate Functions ...
Page 93
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 13.4 Register Description 13.4.1 MCUCR – MCU Control Register Bit 0x35 (0x55) Read/Write Initial Value • Bit 4 – PUD: Pull-up Disable When this bit is written to one, the pull-ups in the I/O ports are disabled even if ...
Page 94
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 13.4.8 PORTC – Port C Data Register Bit 0x08 (0x28) Read/Write Initial Value 13.4.9 DDRC – Port C Data Direction Register Bit 0x07 (0x27) Read/Write Initial Value 13.4.10 PINC – Port C Input Pins Address Bit 0x06 (0x26) Read/Write ...
Page 95
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 13.4.16 PINE – Port E Input Pins Address Bit 0x0C (0x2C) Read/Write Initial Value 13.4.17 PORTF – Port F Data Register Bit 0x11 (0x31) Read/Write Initial Value 13.4.18 DDRF – Port F Data Direction Register Bit 0x10 (0x30) Read/Write ...
Page 96
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 13.4.24 DDRH – Port H Data Direction Register Bit (0xD9) Read/Write Initial Value 13.4.25 PINH – Port H Input Pins Address Bit (0xD8) Read/Write Initial Value 13.4.26 PORTJ – Port J Data Register Bit (0xDD) Read/Write Initial Value 13.4.27 ...
Page 97
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 14. 8-bit Timer/Counter0 with PWM 14.1 Features • Single Compare Unit Counter • Clear Timer on Compare Match (Auto Reload) • Glitch-free, Phase Correct Pulse Width Modulator (PWM) • Frequency Generator • External Event Counter • 10-bit Clock Prescaler ...
Page 98
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P The double buffered Output Compare Register (OCR0A) is compared with the Timer/Counter value at all times. The result of the compare can be used by the Waveform Generator to gener- ate a PWM or variable frequency output on the ...
Page 99
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P clk top bottom Depending of the mode of operation used, the counter is cleared, incremented, or decremented at each timer clock (clk selected by the Clock Select bits (CS02:0). When no clock source is selected (CS02 the ...
Page 100
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 14.5 Output Compare Unit The 8-bit comparator continuously compares TCNT0 with the Output Compare Register (OCR0A). Whenever TCNT0 equals OCR0A, the comparator signals a match. A match will set the Output Compare Flag (OCF0A) at the next timer clock ...
Page 101
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 14.5.1 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 (FOC0A) bit. Forcing compare match will not set the OCF0A Flag or ...
Page 102
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Figure 14-4. Compare Match Output Unit, Schematic The general I/O port function is overridden by the Output Compare (OC0A) from the Waveform Generator if either of the COM0A1:0 bits are set. However, the OC0A pin direction (input or out- ...
Page 103
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 14.7.1 Normal Mode The simplest mode of operation is the Normal mode (WGM01:0 = 0). In this mode the counting direction is always up (incrementing), and no counter clear is performed. The counter simply overruns when it passes its ...
Page 104
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P the pin is set to output. The waveform generated will have a maximum frequency when OCR0A is set to zero (0x00). The waveform frequency is defined by the following clk_I/O equation: The N variable represents ...
Page 105
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P In fast PWM mode, the compare unit allows generation of PWM waveforms on the OC0A pin. Setting the COM0A1:0 bits to two will produce a non-inverted PWM and an inverted PWM output can be generated by setting the COM0A1:0 ...
Page 106
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Figure 14-7. Phase Correct PWM Mode, Timing Diagram TCNTn OCn OCn Period The Timer/Counter Overflow Flag (TOV0) is set each time the counter reaches BOTTOM. The Interrupt Flag can be used to generate an interrupt each time the counter ...
Page 107
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P symmetry around BOTTOM the OCn value at MAX must correspond to the result of an up- counting Compare Match. • The timer starts counting from a value higher than the one in OCR0A, and for that reason misses the ...
Page 108
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Figure 14-10. Timer/Counter Timing Diagram, Setting of OCF0A, with Prescaler (f clk clk (clk TCNTn OCRnx OCFnx Figure 14-11 Figure 14-11. Timer/Counter Timing Diagram, Clear Timer on Compare Match mode, with Pres- clk clk (clk TCNTn (CTC) OCRnx OCFnx ...
Page 109
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P • Bit 6, 3 – WGM01:0: Waveform Generation Mode These bits control the counting sequence of the counter, the source for the maximum (TOP) counter value, and what type of waveform generation to be used. Modes of operation supported ...
Page 110
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Note: Table 14-5 rect PWM mode. Table 14-5. COM0A1 Note: • Bit 2:0 – CS02:0: Clock Select The three Clock Select bits select the clock source to be used by the Timer/Counter. Table 14-6. CS02 ...
Page 111
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 14.9.3 OCR0A – Output Compare Register A Bit 0x27 (0x47) Read/Write Initial Value The Output Compare Register A contains an 8-bit value that is continuously compared with the counter value (TCNT0). A match can be used to generate an ...
Page 112
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 15. 16-bit Timer/Counter1 15.1 Features • True 16-bit Design (i.e., Allows 16-bit PWM) • Two independent Output Compare Units • Double Buffered Output Compare Registers • One Input Capture Unit • Input Capture Noise Canceler • Clear Timer on ...
Page 113
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Figure 15-1. 16-bit Timer/Counter Block Diagram Note: 15.2.1 Registers The Timer/Counter (TCNT1), Output Compare Registers (OCR1A/B), and Input Capture Regis- ter (ICR1) are all 16-bit registers. Special procedures must be followed when accessing the 16- bit registers. These procedures ...
Page 114
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P tion “15.7” on page 121. Match Flag (OCF1A/B) which can be used to generate an Output Compare interrupt request. The Input Capture Register can capture the Timer/Counter value at a given external (edge trig- gered) event on either the ...
Page 115
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 15.3 Accessing 16-bit Registers The TCNT1, OCR1A/B, and ICR1 are 16-bit registers that can be accessed by the AVR CPU via the 8-bit data bus. The 16-bit register must be byte accessed using two read or write operations. Each ...
Page 116
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P the main code and the interrupt code update the temporary register, the main code must disable the interrupts during the 16-bit access. The following code examples show how atomic read of the TCNT1 Register contents. Reading ...
Page 117
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P The following code examples show how atomic write of the TCNT1 Register contents. Writing any of the OCR1A/B or ICR1 Registers can be done by using the same principle. Assembly Code Example TIM16_WriteTCNT1: C Code Example ...
Page 118
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 15.5 Counter Unit The main part of the 16-bit Timer/Counter is the programmable 16-bit bi-directional counter unit. Figure 15-2 Figure 15-2. Counter Unit Block Diagram Signal description (internal signals): Count Direction Clear clk TOP BOTTOM The 16-bit counter is ...
Page 119
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P The Timer/Counter Overflow Flag (TOV1) is set according to the mode of operation selected by the WGM13:0 bits. TOV1 can be used for generating a CPU interrupt. 15.6 Input Capture Unit The Timer/Counter incorporates an Input Capture unit that ...
Page 120
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P tion mode (WGM13:0) bits must be set before the TOP value can be written to the ICR1 Register. When writing the ICR1 Register the high byte must be written to the ICR1H I/O location before the low byte is ...
Page 121
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P cleared by software (writing a logical one to the I/O bit location). For measuring frequency only, the clearing of the ICF1 Flag is not required (if an interrupt handler is used). 15.7 Output Compare Units The 16-bit comparator continuously ...
Page 122
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P prevents the occurrence of odd-length, non-symmetrical PWM pulses, thereby making the out- put glitch-free. The OCR1x Register access may seem complex, but this is not case. When the double buffering is enabled, the CPU has access to the OCR1x ...
Page 123
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 15.8 Compare Match Output Unit The Compare Output mode (COM1x1:0) bits have two functions. The Waveform Generator uses the COM1x1:0 bits for defining the Output Compare (OC1x) state at the next compare match. Secondly the COM1x1:0 bits control the ...
Page 124
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P OC1x Register performed on the next compare match. For compare output actions in the non-PWM modes refer to page 134, and for phase correct and phase and frequency correct PWM refer to page 134. A change ...
Page 125
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Figure 15-6. CTC Mode, Timing Diagram TCNTn OCnA (Toggle) Period An interrupt can be generated at each time the counter value reaches the TOP value by either using the OCF1A or ICF1 Flag according to the register used to ...
Page 126
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P The PWM resolution for fast PWM can be fixed to 8-, 9-, or 10-bit, or defined by either ICR1 or OCR1A. The minimum resolution allowed is 2-bit (ICR1 or OCR1A set to 0x0003), and the max- imum resolution is ...
Page 127
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P to be written anytime. When the OCR1A I/O location is written the value written will be put into the OCR1A Buffer Register. The OCR1A Compare Register will then be updated with the value in the Buffer Register at the ...
Page 128
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 0x0003), and the maximum resolution is 16-bit (ICR1 or OCR1A set to MAX). The PWM resolu- tion in bits can be calculated by using the following equation: In phase correct PWM mode the counter is incremented until the counter ...
Page 129
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P ister. Since the OCR1x update occurs at TOP, the PWM period starts and ends at TOP. This implies that the length of the falling slope is determined by the previous TOP value, while the length of the rising slope ...
Page 130
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P In phase and frequency correct PWM mode the counter is incremented until the counter value matches either the value in ICR1 (WGM13:0 = 8), or the value in OCR1A (WGM13:0 = 9). The counter has then reached the TOP ...
Page 131
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P if the base PWM frequency is actively changed by changing the TOP value, using the OCR1A as TOP is clearly a better choice due to its double buffer feature. In phase and frequency correct PWM mode, the compare units ...
Page 132
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Figure 15-11. Timer/Counter Timing Diagram, Setting of OCF1x, with Prescaler (f Figure 15-12 frequency correct PWM mode the OCR1x Register is updated at BOTTOM. The timing diagrams will be the same, but TOP should be replaced by BOTTOM, TOP-1 ...
Page 133
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Figure 15-13. Timer/Counter Timing Diagram, with Prescaler (f and ICF n 15.11 Register Description 15.11.1 TCCR1A – Timer/Counter1 Control Register A Bit (0x80) Read/Write Initial Value • Bit 7:6 – COM1A1:0: Compare Output Mode for Unit A • Bit ...
Page 134
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 15-3 PWM mode. Table 15-3. COM1A1/COM1B1 Note: Table 15-4 correct or the phase and frequency correct, PWM mode. Table 15-4. COM1A1/COM1B1 Note: • Bit 1:0 – WGM11:0: Waveform Generation Mode Combined with the WGM13:2 bits found in the ...
Page 135
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 15-5. Waveform Generation Mode Bit Description WGM12 Mode WGM13 (CTC1) (PWM11 ...
Page 136
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P When the ICR1 is used as TOP value (see description of the WGM13:0 bits located in the TCCR1A and the TCCR1B Register), the ICP1 is disconnected and consequently the Input Cap- ture function is disabled. • Bit 5 – ...
Page 137
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P A FOC1A/FOC1B strobe will not generate any interrupt nor will it clear the timer in Clear Timer on Compare match (CTC) mode using OCR1A as TOP. The FOC1A/FOC1B bits are always read as zero. 15.11.4 TCNT1H and TCNT1L – ...
Page 138
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 15.11.7 ICR1H and ICR1L – Input Capture Register 1 Bit (0x87) (0x86) Read/Write Initial Value The Input Capture is updated with the counter (TCNT1) value each time an event occurs on the ICP1 pin (or optionally on the Analog ...
Page 139
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 15.11.9 TIFR1 – Timer/Counter1 Interrupt Flag Register Bit 0x16 (0x36) Read/Write Initial Value • Bit 5 – ICF1: Timer/Counter1, Input Capture Flag This flag is set when a capture event occurs on the ICP1 pin. When the Input Capture ...
Page 140
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 16. Timer/Counter0 and Timer/Counter1 Prescalers Timer/Counter1 and Timer/Counter0 share the same prescaler module, but the Timer/Counters can have different prescaler settings. The description below applies to both Timer/Counter1 and Timer/Counter0. 16.1 Internal Clock Source The Timer/Counter can be clocked ...
Page 141
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Enabling and disabling of the clock input must be done when T1/T0 has been stable for at least one system clock cycle, otherwise risk that a false Timer/Counter clock pulse is generated. Each half period of ...
Page 142
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 16.4 Register Description 16.4.1 TCCR0A – Timer/Counter Control Register A Bit 0x24 (0x44) Read/Write Initial Value • Bit 7 – FOC0A: Force Output Compare A The FOC0A bit is only active when the WGM00 bit specifies a non-PWM mode. ...
Page 143
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 16-2. COM0A1 Table 16-3 mode. Table 16-3. COM0A1 Note: Table 16-4 rect PWM mode. Table 16-4. COM0A1 Note: 8284A–AVR–10/10 Compare Output Mode, non-PWM Mode COM0A0 Description ...
Page 144
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P • Bit 2:0 – CS02:0: Clock Select The three Clock Select bits select the clock source to be used by the Timer/Counter. Table 16-5. CS02 external pin modes are used ...
Page 145
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 16.4.4 TIMSK0 – Timer/Counter 0 Interrupt Mask Register Bit (0x6E) Read/Write Initial Value • Bit 1 – OCIE0A: Timer/Counter0 Output Compare Match A Interrupt Enable When the OCIE0A bit is written to one, and the I-bit in the Status ...
Page 146
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 16.4.6 GTCCR – General Timer/Counter Control Register Bit 0x23 (0x43) Read/Write Initial Value • Bit 7 – TSM: Timer/Counter Synchronization Mode Writing the TSM bit to one activates the Timer/Counter Synchronization mode. In this mode, the value that is ...
Page 147
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 17. 8-bit Timer/Counter2 with PWM and Asynchronous Operation 17.1 Features • Single Compare Unit Counter • Clear Timer on Compare Match (Auto Reload) • Glitch-free, Phase Correct Pulse Width Modulator (PWM) • Frequency Generator • 10-bit Clock Prescaler • ...
Page 148
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P (TIFR2). All interrupts are individually masked with the Timer Interrupt Mask Register (TIMSK2). TIFR2 and TIMSK2 are not shown in the figure. The Timer/Counter can be clocked internally, via the prescaler, or asynchronously clocked from the TOSC1/2 pins, as ...
Page 149
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 17.4 Counter Unit The main part of the 8-bit Timer/Counter is the programmable bi-directional counter unit. 17-2 shows a block diagram of the counter and its surrounding environment. Figure 17-2. Counter Unit Block Diagram Signal description (internal signals): count ...
Page 150
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Generator for handling the special cases of the extreme values in some modes of operation (”Modes of Operation” on page Figure 17-3 Figure 17-3. Output Compare Unit, Block Diagram The OCR2A Register is double buffered when using any of ...
Page 151
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 17.5.3 Using the Output Compare Unit Since writing TCNT2 in any mode of operation will block all compare matches for one timer clock cycle, there are risks involved when changing TCNT2 when using the Output Compare unit, independently of ...
Page 152
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P tion Register bit for the OC2A pin (DDR_OC2A) must be set as output before the OC2A value is visible on the pin. The port override function is independent of the Waveform Generation mode. The design of the Output Compare ...
Page 153
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P The timing diagram for the CTC mode is shown in increases until a compare match occurs between TCNT2 and OCR2A, and then counter (TCNT2) is cleared. Figure 17-5. CTC Mode, Timing Diagram TCNTn OCnx (Toggle) Period An interrupt can ...
Page 154
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P for power regulation, rectification, and DAC applications. High frequency allows physically small sized external components (coils, capacitors), and therefore reduces total system cost. In fast PWM mode, the counter is incremented until the counter value matches the MAX value. ...
Page 155
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P A frequency (with 50% duty cycle) waveform output in fast PWM mode can be achieved by set- ting OC2A to toggle its logical level on each compare match (COM2A[1:0] = 1). The waveform generated will have a maximum frequency ...
Page 156
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P In phase correct PWM mode, the compare unit allows generation of PWM waveforms on the OC2A pin. Setting the COM2A[1:0] bits to two will produce a non-inverted PWM. An inverted PWM output can be generated by setting the COM2A[1:0] ...
Page 157
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Figure 17-9 Figure 17-9. Timer/Counter Timing Diagram, with Prescaler (f Figure 17-10 Figure 17-10. Timer/Counter Timing Diagram, Setting of OCF2A, with Prescaler (f Figure 17-11 on page 158 8284A–AVR–10/10 shows the same timing data, but with the prescaler enabled. ...
Page 158
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Figure 17-11. Timer/Counter Timing Diagram, Clear Timer on Compare Match mode, with Pres- 17.9 Asynchronous Operation of Timer/Counter2 When Timer/Counter2 operates asynchronously, some considerations must be taken. • Warning: When switching between asynchronous and synchronous clocking of Timer/Counter2, the ...
Page 159
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P user is in doubt whether the time before re-entering Power-save or ADC Noise Reduction mode is sufficient, the following algorithm can be used to ensure that one TOSC1 cycle has elapsed: 1. Write a value to TCCR2A, TCNT2, or ...
Page 160
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 17.9.1 Timer/Counter Prescaler Figure 17-12. Prescaler for Timer/Counter2 TOSC1 The clock source for Timer/Counter2 is named clk system I/O clock clk clocked from the TOSC1 pin. This enables use of Timer/Counter2 as a Real Time Counter (RTC). When AS2 ...
Page 161
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 17.10 Register Description 17.10.1 TCCR2A – Timer/Counter Control Register A Bit (0xB0) Read/Write Initial Value • Bit 7 – FOC2A: Force Output Compare A The FOC2A bit is only active when the WGM bits specify a non-PWM mode. However, ...
Page 162
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P When OC2A is connected to the pin, the function of the COM2A[1:0] bits depends on the WGM2[1:0] bit setting. bits are set to a normal or CTC mode (non-PWM). Table 17-3. COM2A1 Table 17-4 PWM mode. Table 17-4. COM2A1 ...
Page 163
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 17-6. CS22 17.10.2 TCNT2 – Timer/Counter Register Bit (0xB2) Read/Write Initial Value The Timer/Counter Register gives direct access, both for read and write operations, to the Timer/Counter unit 8-bit counter. ...
Page 164
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P • Bit 3 – AS2: Asynchronous Timer/Counter2 When AS2 is written to zero, Timer/Counter2 is clocked from the I/O clock, clk written to one, Timer/Counter2 is clocked from a crystal Oscillator connected to the Timer Oscil- lator 1 (TOSC1) ...
Page 165
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 17.10.6 TIFR2 – Timer/Counter2 Interrupt Flag Register Bit 0x17 (0x37) Read/Write Initial Value • Bit 1 – OCF2A: Output Compare Flag 2 A The OCF2A bit is set (one) when a compare match occurs between the Timer/Counter2 and the ...
Page 166
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 18. SPI – Serial Peripheral Interface 18.1 Features • Full-duplex, Three-wire Synchronous Data Transfer • Master or Slave Operation • LSB First or MSB First Data Transfer • Seven Programmable Bit Rates • End of Transmission Interrupt Flag • ...
Page 167
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Figure 18-1. SPI Block Diagram Note: The interconnection between Master and Slave CPUs with SPI is shown in 168. The system consists of two shift Registers, and a Master clock generator. The SPI Master initiates the communication cycle when ...
Page 168
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Flag, SPIF is set. If the SPI Interrupt Enable bit, SPIE, in the SPCR Register is set, an interrupt is requested. The Slave may continue to place new data to be sent into SPDR before reading the incoming data. ...
Page 169
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P The following code examples show how to initialize the SPI as a Master and how to perform a simple transmission. DDR_SPI in the examples must be replaced by the actual Data Direction Register controlling the SPI pins. DD_MOSI, DD_MISO ...
Page 170
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P The following code examples show how to initialize the SPI as a Slave and how to perform a simple reception. Assembly Code Example SPI_SlaveInit: SPI_SlaveReceive: C Code Example void SPI_SlaveInit(void char SPI_SlaveReceive(void Note: 8284A–AVR–10/10 (1) ...
Page 171
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 18.3 SS Pin Functionality 18.3.1 Slave Mode When the SPI is configured as a Slave, the Slave Select (SS) pin is always input. When SS is held low, the SPI is activated, and MISO becomes an output if configured ...
Page 172
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Figure 18-3. SPI Transfer Format with CPHA = 0 Figure 18-4. SPI Transfer Format with CPHA = 1 8284A–AVR–10/10 SCK (CPOL = 0) mode 0 SCK (CPOL = 1) mode 2 SAMPLE I MOSI/MISO CHANGE 0 MOSI PIN CHANGE ...
Page 173
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 18.5 Register Description 18.5.1 SPCR – SPI Control Register Bit 0x2C (0x4C) Read/Write Initial Value • Bit 7 – SPIE: SPI Interrupt Enable This bit causes the SPI interrupt to be executed if SPIF bit in the SPSR Register ...
Page 174
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P • Bits 1, 0 – SPR1, SPR0: SPI Clock Rate Select 1 and 0 These two bits control the SCK rate of the device configured as a Master. SPR1 and SPR0 have no effect on the Slave. The relationship ...
Page 175
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P program memory and EEPROM downloading or uploading. See serial programming and verification. 18.5.3 SPDR – SPI Data Register Bit 0x2E (0x4E) Read/Write Initial Value The SPI Data Register is a read/write register used for data transfer between the Register ...
Page 176
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 19. USART0 19.1 Features • Full Duplex Operation (Independent Serial Receive and Transmit Registers) • Asynchronous or Synchronous Operation • Master or Slave Clocked Synchronous Operation • High Resolution Baud Rate Generator • Supports Serial Frames with 5, 6, ...
Page 177
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Figure 19-1. USART Block Diagram Note: The dashed boxes in the block diagram separate the three main parts of the USART (listed from the top): Clock Generator, Transmitter and Receiver. Control Registers are shared by all units. The Clock ...
Page 178
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 19.2.1 AVR USART vs. AVR UART – Compatibility The USART is fully compatible with the AVR UART regarding: • Bit locations inside all USART Registers. • Baud Rate Generation. • Transmitter Operation. • Transmit Buffer Functionality. • Receiver Operation. ...
Page 179
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Figure 19-2. .Clock Generation Logic, Block Diagram Signal description: txclk rxclk xcki xcko fosc 19.3.1 Internal Clock Generation – The Baud Rate Generator Internal clock generation is used for the asynchronous and the synchronous master modes of operation. The ...
Page 180
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 19-1. Operating Mode Asynchronous Normal mode (U2Xn = 0) Asynchronous Double Speed mode (U2Xn = 1) Synchronous Master mode Note: BAUD f OSC UBRRn Some examples of UBRRn values for some system clock frequencies are found in page ...
Page 181
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 19.3.4 Synchronous Clock Operation When synchronous mode is used (UMSELn = 1), the XCK pin will be used as either clock input (Slave) or clock output (Master). The dependency between the clock edges and data sampling or data change ...
Page 182
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P St ( IDLE The frame format used by the USART is set by the UCSZn2:0, UPMn1:0 and USBSn bits in UCSRnB and UCSRnC. The Receiver and Transmitter use the same setting. Note that changing the setting of ...
Page 183
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P For the assembly code, the baud rate parameter is assumed to be stored in the r17:r16 Registers. Assembly Code Example USART_Init: C Code Example #define FOSC 1843200 // Clock Speed #define BAUD 9600 #define MYUBRR FOSC/16/BAUD-1 void main( void ...
Page 184
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 19.6 Data Transmission – The USART Transmitter The USART Transmitter is enabled by setting the Transmit Enable (TXENn) bit in the UCSRnB Register. When the Transmitter is enabled, the normal port operation of the TxD pin is overrid- den ...
Page 185
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 19.6.2 Sending Frames with 9 Data Bit If 9-bit characters are used (UCSZ = 7), the ninth bit must be written to the TXB8n bit in UCSRnB before the low byte of the character is written to UDRn. The ...
Page 186
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P contains data to be transmitted that has not yet been moved into the Shift Register. For compat- ibility with future devices, always write this bit to zero when writing the UCSRnA Register. When the Data Register Empty Interrupt Enable ...
Page 187
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P bits of the data read from the UDRn will be masked to zero. The USART has to be initialized before the function can be used. Assembly Code Example USART_Receive: C Code Example unsigned char USART_Receive( void ) { } ...
Page 188
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P The following code example shows a simple USART receive function that handles both nine bit characters and the status bits. Assembly Code Example USART_Receive: USART_ReceiveNoError: C Code Example unsigned int USART_Receive( void ) { } Note: The receive function ...
Page 189
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 19.7.3 Receive Compete Flag and Interrupt The USART Receiver has one flag that indicates the Receiver state. The Receive Complete (RXCn) Flag indicates if there are unread data present in the receive buf- fer. This flag is one when ...
Page 190
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P with the received data and stop bits. The Parity Error (UPEn) Flag can then be read by software to check if the frame had a Parity Error. The UPEn bit is set if the next character that can be ...
Page 191
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P operation. Samples denoted zero are samples done when the RxD line is idle (i.e., no communi- cation activity). Figure 19-5. Start Bit Sampling When the clock recovery logic detects a high (idle) to low (start) transition on the RxD ...
Page 192
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Figure 19-7. Stop Bit Sampling and Next Start Bit Sampling The same majority voting is done to the stop bit as done for the other bits in the frame. If the stop bit is registered to have a logic ...
Page 193
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 19-2. # (Data+Parity Bit) Table 19-3. # (Data+Parity Bit) The recommendations of the maximum receiver baud rate error was made under the assump- tion that the Receiver and Transmitter equally divides the maximum total error. There are two ...
Page 194
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P nine data bits, then the ninth bit (RXB8n) is used for identifying address and data frames. When the frame type bit (the first stop or the ninth bit) is one, the frame contains an address. When the frame type ...
Page 195
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 19.10 Examples of Baud Rate Setting For standard crystal and resonator frequencies, the most commonly used baud rates for asyn- chronous operation can be generated by using the UBRRn settings in UBRRn values which yield an actual baud rate ...
Page 196
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 19-5. Examples of UBRRn Settings for Commonly Used Oscillator Frequencies (Continued 3.6864 MHz osc Baud U2Xn = 0 U2Xn = 1 Rate (bps) UBRRn Error UBRRn 2400 95 0.0% 191 4800 47 0.0% 95 9600 23 ...
Page 197
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 19-6. Examples of UBRRn Settings for Commonly Used Oscillator Frequencies (Continued 8.0000 MHz osc Baud U2Xn = 0 U2Xn = 1 Rate (bps) UBRRn Error UBRRn 2400 207 0.2% 416 4800 103 0.2% 207 9600 51 ...
Page 198
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P Table 19-7. Examples of UBRRn Settings for Commonly Used Oscillator Frequencies (Continued 16.0000 MHz osc Baud U2Xn = 0 U2Xn = 1 Rate (bps) UBRRn Error UBRRn 2400 416 -0.1% 832 4800 207 0.2% 416 9600 103 ...
Page 199
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P 19.11 Register Description 19.11.1 UDRn – USART I/O Data Register n Bit Read/Write Initial Value The USART Transmit Data Buffer Register and USART Receive Data Buffer Registers share the same I/O address referred to as USART Data Register or ...
Page 200
ATmega169A/169PA/329A/329PA/649A/649P/3290A/3290PA/6490A/6490P • Bit 5 – UDREn: USART Data Register Empty The UDREn Flag indicates if the transmit buffer (UDRn) is ready to receive new data. If UDREn is one, the buffer is empty, and therefore ready to be written. The ...