AVR505: Migration between ATmega16/32 and ATmega164P/324P/644P Features • • • • • • • • • • General porting considerations Memories I/O Mapping and SRAM EEPROM Programming External 32 kHz Watch Crystal Changes To Register and Bit Names Fuse Settings Interrupt Vectors IEEE 1149.1 (JTAG) Boundary Scan Operational Range 8-bit Microcontrollers Application Note 1 Introduction The ATmega164P and the ATmega324P are new and enhanced versions of the ATmega16 and the ATmega32 respectively, and ATmega644P is a new 64kB device with the same features. An important improvement is the possibility for low voltage operation (1.8V) with ATmega164P/324P/644P and decreased power consumption. ATmega164P/324P/644P also features an extra USART and can run at frequencies up to 20 MHz. This application note summarizes the differences between ATmega16/32 and ATmega164P/324P/644P and is a guide to assist current ATmega16/32 users in converting existing designs to the ATmega164P/324P/644P. Note that electrical differences such as power consumption and I/O driving capabilities are not covered in this document. Refer to the datasheets for detailed information on the devices. Migration from ATmega644 is covered by AVR508: Migration from ATmega644 to ATmega644P. ATmega164P/324P/644P are pin compatible with ATmega163/323, and migration between these devices is possible but not within the scope of this application note. Refer to AVR083: Replacing ATmega163 by ATmega16 and AVR084: Replacing ATmega323 by ATmega32 for further details. Rev. 8001C-AVR-06/06 2 General porting considerations To make the porting process as easy as possible, we recommend to always refer to registers and bit positions using their defined names, as absolute addresses and values may change from device to device. When porting a design it is then often just necessary to include the correct definition file. Some examples are shown below. PORTE |= (1<<PORTE5); DDR &= ~(1<<PORTE5); // Set pin 5 on port E high // Set pin 5 on port E as input // Configure USI USICR = (1<<USISIE)|(0<<USIOIE)|(1<<USIWM1)|(0<<USIWM0)| (1<<USICS1)|(0<<USICS0)|(0<<USICLK)|(0<<USITC); To avoid conflicts with added features and register functionality, never access registers that are marked as reserved. Reserved bits should always be written to zero if accessed. This ensures forward compatibility, and that added features will stay in their default states if not used. 3 Memories The memory sizes are the same for the ATmega16 and the ATmega164P as well as for the ATmega32 and ATmega324P, hence this does not imply a considerable difference in migrating between them. Please note the different page size for 644P memories as shown in Table 3-2. Table 3-1. Memory Sizes. ATmega16/164P ATmega32/324P Atmega644P FLASH 16 kb 32 kb 64 kb SRAM 1 kb 2 kb 4 kb 512 b 1 kb 2 kb ATmega16/164P ATmega32/324P Atmega644P 64 words 64 words 128 words 4 bytes 4 bytes 8 bytes EEPROM Table 3-2. Page Sizes. FLASH EEPROM 4 I/O Mapping and SRAM The I/O memory space contains 64 addresses for CPU peripheral control registers. The ATmega164P/324P/644P I/O space and I/O range are changed and extended compared to ATmega16/32. The extended I/O space goes from 0x60 to 0xFF in data memory space where ST/STS/STD and LD/LDS/LDD instructions must be used. The memory map is slightly different between the ATmega16/32 and the ATmega164P/324P/644P due to extended I/O space. The ATmega164P/324P/644P internal data SRAM addressing starts at 0x100 as opposed to 0x60 in ATmega16/32. 2 AVR505 8001C-AVR-06/06 AVR505 5 EEPROM Programming In ATmega16/32 EEPROM data programming is done in one atomic operation, in ATmega164P/324P/644P it is also possible to split the erase and write operations in two different operations. The typical EEPROM programming times are also reduced in ATmega164P/324P/644P. Table 5-1. EEPROM Programming Time. ATmega16/32 EEPROM write from CPU ATmega164P/324P/644P Number of Calibrated RC Oscillator Cycles Typical Programming Time Number of Calibrated RC Oscillator Cycles Typical Programming Time 8448 8.5 ms 26368 3.3 ms 6 External 32 kHz Watch Crystal When operating the timer/counter from an external 32.768 kHz watch crystal or an external clock source, external capacitors might be needed to the TOSC1/2 pins when using ATmega164P/324P/644P, as opposed to ATmega16/32 where the crystal can be connected directly between the pins. The internal capacitance of ATmega164P/324P/644P low-frequency oscillator is typically 6pF, but the tracks to the crystal will add some additional capacitance. Refer to the datasheet for details on crystal connections. The low frequency crystal oscillator of the ATmega164P/324P/644P is optimized for very low power consumption and thus the crystal driver strength is reduced compared to the ATmega16/32. This means that when selecting a crystal, its load capacitance and Equivalent Series Resistance (ESR) must be taken into consideration. Both values are specified by the crystal vendor. Table 6-1 shows the ESR recommendations for ATmega164P/324P/644P. Table 6-1. ESR recommendation 32.768 kHz crystals with ATmega164P/324P/644P. Crystal CL [pF] Max ESR [kΩ]1 6.5 75 9 65 12.5 30 Note: 1. The values stated are for an oscillator allowance safety margin of 5. Since the oscillator’s transconductance is temperature compensated one can use a safety margin of 4, thus giving a max ESR of 90, 80 and 40 kΩ respectively. For examples of crystals that comply with the requirements see Appendix A. 3 8001C-AVR-06/06 The startup times are also increased as shown in Table 6-2. Table 6-2. Startup times with 32.768 kHz crystals. Crystal CL [pF] Startup time2 [ms] ATmega16/32 Startup time2 [ms] ATmega164P/324P/644P 6.5 - 600 9 300 700 12.5 400 1700 Note: 2. Crystals usually need ~3000ms before they are completely stable with any oscillator design. The time stated is before the crystal is running with a sufficient amplitude and frequency stability. 7 Changes To Register and Bit Names Several modifications have been done in register and bit naming conventions between ATmega16/32 and ATmega164P/324P/644P. The locations of the registers are changed considerably. 7.1 Registers Table 7-1. Changes to Register Names and Locations. 4 Address in ATmega16/32 Register Name in ATmega16/32 Address in ATmega164P/324P/ 644P Register Name in ATmega164P/324P/ 644P $3C ($5C) OCR0 $27 ($47) OCR0A $3B ($5B) GICR $1D ($3D) EIMSK $3A ($5A) GIFR $1C ($3C) EIFR $39 ($59) TIMSK ($6E) ($6F) ($70) TIMSK0 TIMSK1 TIMSK2 $38 ($58) TIFR $15 ($35) $16 ($36) $17 ($37) TIFR0 TIFR1 TIFR2 $37 ($57) SPMCR $37 ($57) SPMCSR $36 ($56) TWCR ($BC) TWCR $35 ($55) MCUCR $33 ($53) ($69) SMCR EICRA $34 ($54) MCUCSR $34 ($54) MCUSR(3) $33 ($53) TCCR0 $24 ($44) TCCR0A(3) $32 ($52) TCNT0 $26 ($46) TCNT0 $31 ($51) OSCCAL OCDR ($66) 31 ($51) OSCCAL OCDR $30 ($50) SFIOR ($7B) ADCSRB(3) $2F ($4F) TCCR1A ($80) TCCR1A(3) $2E ($4E) TCCR1B ($81) TCCR1B $2D ($4D) TCNT1H ($85) TCNT1H $2C ($4C) TCNT1L ($84) TCNT1L AVR505 8001C-AVR-06/06 AVR505 Address in ATmega16/32 Register Name in ATmega16/32 Address in ATmega164P/324P/ 644P Register Name in ATmega164P/324P/ 644P $2B ($4B) OCR1AH ($89) OCR1AH $2A ($4A) OCR1AL ($88) OCR1AL $29 ($49) OCR1BH ($8B) OCR1BH $28 ($48) OCR1BL ($8A) OCR1BL $27 ($47) ICR1H ($87) ICR1H $26 ($46) ICR1L ($86) ICR1L $25 ($45) TCCR2 ($B0) TCCR2A(3) $24 ($44) TCNT2 ($B2) TCNT2 $23 ($43) OCR2 ($B3) OCR2A $22 ($42) ASSR ($B6) ASSR(3) $21 ($41) WDTCR ($60) WDTCSR(3) $20 ($40) UBRRH UCSRC ($C5) ($C2) UBRR0H(3) (3) UCSR0C $1F ($3F) EEARH $22 ($42) EEARH $1E ($3E) EEARL $21 ($41) EEARL $1D ($3D) EEDR $20 ($40) EEDR $1C ($3C) EECR $1F ($3F) EECR $1B ($3B) PORTA $02 ($22) PORTA $1A ($3A) DDRA $01 ($21) DDRA $19 ($39) PINA $00 ($20) PINA $18 ($38) PORTB $05 ($25) PORTB $17 ($37) DDRB $04 ($24) DDRB $16 ($36) PINB $03 ($23) PINB $15 ($35) PORTC $08 ($28) PORTC $14 ($34) DDRC $07 ($27) DDRC $13 ($33) PINC $06 ($26) PINC $12 ($32) PORTD $0B ($2B) PORTD $11 ($31) DDRD $0A ($2A) DDRD $10 ($30) PIND $09 ($29) PIND $0F ($2F) SPDR $2E ($4E) SPDR $0E ($2E) SPSR $2D ($4D) SPSR $0D ($2D) SPCR $2C ($4C) SPCR $0C ($2C) UDR ($C6) UDR0 $0B ($2B) UCSRA ($C0) UCSR0A(3) $0A ($2A) UCSRB ($C1) UCSR0B(3) $09 ($29) UBRRL ($C4) UBRR0L $08 ($28) ACSR $30 ($50) ACSR $07 ($27) ADMUX ($7C) ADMUX $06 ($26) ADCSRA ($7A) ADCSRA 5 8001C-AVR-06/06 Address in ATmega16/32 Register Name in ATmega16/32 Address in ATmega164P/324P/ 644P Register Name in ATmega164P/324P/ 644P $05 ($25) ADCH ($79) ADCH $04 ($24) ADCL ($78) ADCL $03 ($23) TWDR ($BB) TWDR $02 ($22) TWAR ($BA) TWAR $01 ($21) TWSR ($B9) TWSR $00 ($20) TWBR ($B8) TWBR Note: 3. Some of the register bits may be located in another register or the bit names are changed, see Table 7-2. 7.2 Bit Definitions Some bits in ATmega164P/324P/644P have changed name and register location compared to ATmega16/32, other bits have changed location within the register. Table 7-2. Changes to Bit Names and Locations. 6 Register in ATmega16/32 Bit Name in ATmega16/32 Register in ATmega164P/324P/ 644P Bit Name in ATmega164P/324P/644 P GICR IVSEL, IVCE MCUCR IVSEL, IVCE TIMSK OCIE2 TICIE1 OCIE0 TIMSK2 TIMSK1 TIMSK0 OCIE2A ICIE1 OCIE0A TIFR TOV2 TOV1 TOV0 TIFR2 TIFR1 TIFR0 TOV2 TOV1 TOV0 TIFR OCF2 OCF0 TIFR2 TIFR0 OCF2A OCF0A MCUCSR JTD ISC2 MCUCR EICRA JTD ISC20 TCCR0 FOC0 COM01 COM00 CS02 CS01 CS00 TCCR0B TCCR0A TCCR0A TCCR0B TCCR0B TCCR0B FOC0A COM0A1 COM0A0 CS02 CS01 CS00 SFIOR PUD PSR2 PSR10 MCUCR GTCCR PUD PSRASY PSRSYNC TCCR1A FOC1A FOC1B TCCR1C FOC1A FOC1B TCCR2 FOC2 COM21 COM20 CS22 CS21 CS20 TCCR2B TCCR2A TCCR2A TCCR2B TCCR2B TCCR2B FOC2A COM2A1 COM2A0 CS22 CS21 CS20 AVR505 8001C-AVR-06/06 AVR505 Register in ATmega164P/324P/ 644P Bit Name in ATmega164P/324P/644 P OCR2UB TCR2UB WDTOE ASSR n/a(1) OCR2AUB TCR2AUB n/a(1) URSEL n/a(1) n/a(1) UCRSC URSEL UMSEL UPM1 UPM0 USBS UCSZ1 UCSZ2 UCPOL (1) n/a UCSR0C UCSR1C UCSR0C UCSR0C UCSR0C UCSR1C UCSR0C n/a UMSEL00 UPM10 UPM00 USBS0 UCSZ00 UCSZ10 UCPOL0 UCSRA RXC TXC UDRE FE DOR PE U2X MPCM UCSR0A RXC0 TXC0 UDRE0 FE0 DOR0 UPE0 U2X0 MPCM0 UCSRB RXCIE TXCIE UDRIE RXEN TXEN UCSZ2 RXB8 TXB8 UCSR0B RXCIE0 TXCIE0 UDRIE0 RXEN0 TXEN0 UCSZ02 RXB80 TXB80 Register in ATmega16/32 Bit Name in ATmega16/32 ASSR UBRRH Note: (1) 1. The function of this bit has a different ATmega164P/324P/644P. Refer to datasheet for details. implementation in 8 Fuse Settings ATmega164P/324P/644P has four fuse bytes instead of two in ATmega16/32. New features in ATmega164P/324P/644P imply other fuses and fuse settings. Fuse Low Byte Fuse High Byte Extended Fuse Byte Table 8-1. Comparing Fuses. ATmega16/32 Fuse ATmega16/32 Default Setting ATmega164P/324P/ 644P Fuse ATmega164P/324P/ 644P Default Setting - - BODLEVEL2 1 - - BODLEVEL1 1 - - BODLEVEL0 1 - - WDTON 1 CKOPT 1 - - - - CKDIV8 0 BODLEVEL 1 - - BODEN 1 - - 7 8001C-AVR-06/06 ATmega16/32 Fuse ATmega16/32 Default Setting ATmega164P/324P/ 644P Fuse ATmega164P/324P/ 644P Default Setting - - CKOUT 1 CKSEL1 0 CKSEL1 1 CKSEL0 1 CKSEL0 0 9 Interrupt Vectors The ATmega164P/324P/644P has 31 interrupt vectors, located at different addresses than the ATmega16/32, which has 21 interrupt vectors. The ATmega16 and the ATmega32 also have different interrupt tables as shown in Table 9-1. The additional interrupt vectors are due to extra peripherals not found on ATmega16/32 Table 9-1. Interrupt Table. Vector # 8 ATmega16 ATmega32 ATmega164P/324P/644P 1 RESET RESET RESET 2 INT0 INT0 INT0 3 INT1 INT1 INT1 4 TIMER2_COMP INT2 INT2 5 TIMER2_OVF TIMER2_COMP PCINT0 6 TIMER1_CAPT TIMER2_OVF PCINT1 7 TIMER1_COMPA TIMER1_CAPT PCINT2 8 TIMER1_COMPB TIMER1_COMPA PCINT3 9 TIMER1_OVF TIMER1_COMPB WDT 10 TIMER0_OVF TIMER1_OVF TIMER2_COMPA 11 SPI_STC TIMER0_COMP TIMER2_COMPB 12 USART_RXC TIMER0_OVF TIMER2_OVF 13 USART_UDRE SPI_STC TIMER1_CAPT 14 USART_TXC USART_RXC TIMER1_COMPA 15 ADC USART_UDRE TIMER1_COMPB 16 EE_RDY USART_TXC TIMER1_OVF 17 ANA_COMP ADC TIMER0_COMPA 18 TWI EE_RDY TIMER0_COMPB 19 INT2 ANA_COMP TIMER0_OVF 20 TIMER0_COMP TWI SPI_STC 21 SPM_RDY SPM_RDY USART0_RX 22 - - USART0_UDRE 23 - - USART0_TX 24 - - ANALOG_COMP 25 - - ADC 26 - - EE_READY 27 - - TWI AVR505 8001C-AVR-06/06 AVR505 Vector # ATmega16 ATmega32 ATmega164P/324P/644P 28 - - SPM_READY 29 - - USART1_RX 30 - - USART1_UDRE 31 - - USART1_TX 10 IEEE 1149.1 (JTAG) Boundary Scan The boundary scan has changed in ATmega164P/324P/644P where analog circuits no longer constitute a part of the scan chain. The order of the signal names in the boundary scan has also changed. Refer to datasheet for details. 11 Operational Range Table 11-1. Operating voltage and Speed grades. Operating Voltage Speed Grade ATmega16/32 4.5-5.5V 0-16 MHz ATmega16/32L 2.7-5.5V 0-8 MHz ATmega164P/324P/644P 2.7-5.5V 0-20 MHz ATmega164PV/324PV/644PV 1.8-5.5V 0-10 MHz 12 Appendix A Table 12-1 is a selection of crystals that meet the ESR requirements of the ATmega164P/324P/644P. The crystals are listed based on datasheet information and are not tested with the actual device. Any other crystal that complies with the ESR requirements can also be used. Availability and RoHS compliance has not been investigated. Table 12-1. Examples of crystals compliant with ATmega164P/324P/644P low-frequency Crystal Oscillator. Mounting (SMD/HOLE) Frequency Tolerance [±ppm] Load Capacitance [pF] Equivalent Series Resistance (ESR) [kΩ] Vendor Type C-MAC WATCH CRYSTALS HOLE 20 6 50 C-MAC 85SMX SMD 20 6 55 C-MAC 90SMX SMD 20 6 60 ECLIPTEK E4WC HOLE 20 6 50 ENDRICH 90SMX SMD 5 6 50 EPSON C-001R HOLE 20 6 -> 12.5 (specify) 35 EPSON C-002RX HOLE 20 6 -> 10 (specify) 50 EPSON C-004R HOLE 20 6 -> 10 (specify) 50 EPSON C-005R HOLE 20 6 -> 10 (specify) 50 EPSON MC-30A SMD 20 6 -> 10 (specify) 50 EPSON MC-306 SMD 20 6 -> 10 (specify) 50 EPSON MC-405 SMD 20 6 -> 10 (specify) 50 9 8001C-AVR-06/06 Mounting (SMD/HOLE) Frequency Tolerance [±ppm] Load Capacitance [pF] Equivalent Series Resistance (ESR) [kΩ] Vendor Type EPSON MC-406 SMD 20 6 -> 10 (specify) 50 GOLLEDGE GWX HOLE 5 6, 8 or 12.5 35 GOLLEDGE GSWX-26 SMD 10 6 , 8 or 12.5 35 GOLLEDGE GDX1 HOLE 10 6 42 GOLLEDGE GSX-200 SMD 5 6 50 IQD WATCH CRYSTALS HOLE 20 6 50 IQD 90SMX HOLE 10 6 60 IQD 91SMX HOLE 10 6 60 MICROCRYSTAL MS3V-T1R HOLE 20 7 or 9 65 MICROCRYSTAL MS2V-T1R HOLE 20 7 or 9 65 MICROCRYSTAL CC4V-T1A SMD 30 9 65 MICROCRYSTAL CC1V-T1A SMD 30 9 60 MICROCRYSTAL CC7V-T1A SMD 30 9 70 MMD WC26 HOLE 8 8 35 MMD WC38 HOLE 8 8 35 MMD WC155 HOLE 8 8 40 MMD WCSMC SMD 20 6 50 OSCILENT SERIES 111 HOLE 10 6 or 12.5 30 OSCILENT SERIES 112 HOLE 10 6 or 12.5 40 OSCILENT SERIES 113 HOLE 10 8 40 OSCILENT SERIES 223 SMD 20 6 50 RALTRON SERIES R38 HOLE 5 6 or 12.5 35 RALTRON SERIES R26 HOLE 5 6 or 12.5 35 RALTRON SERIES R145 HOLE 5 8 40 RALTRON SERIES RSE A, B, C, D SMD 20 6 50 SBTRON SBX-13 SMD 20 6 50 SBTRON SBX-20 SMD 20 6 50 SBTRON SBX-21 SMD 20 6 50 SBTRON SBX-24 SMD 20 6 50 SBTRON SBX-23 SMD 20 6 50 SBTRON SBX-22 SMD 20 6 50 SBTRON SBX-14 HOLE 20 6 50 SUNTSU SCT1 HOLE 20 6, 8, 10 or 12.5 40 SUNTSU SCT2 HOLE 20 6, 8, 10 50 SUNTSU SCT3 HOLE 20 6, 8, 10 50 SUNTSU SCP1 SMD 20 6 50 SUNTSU SCT2G SMD 20 6 or 10 50 10 AVR505 8001C-AVR-06/06 Disclaimer Atmel Corporation 2325 Orchard Parkway 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 East Kowloon Hong Kong 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 Atmel Operations Memory 2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 Microcontrollers 2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 La Chantrerie BP 70602 44306 Nantes Cedex 3, France Tel: (33) 2-40-18-18-18 Fax: (33) 2-40-18-19-60 ASIC/ASSP/Smart Cards Zone Industrielle 13106 Rousset Cedex, France Tel: (33) 4-42-53-60-00 Fax: (33) 4-42-53-60-01 RF/Automotive Theresienstrasse 2 Postfach 3535 74025 Heilbronn, Germany Tel: (49) 71-31-67-0 Fax: (49) 71-31-67-2340 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 Tel: (33) 4-76-58-30-00 Fax: (33) 4-76-58-34-80 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 Literature Requests www.atmel.com/literature Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMEL’S TERMS AND CONDITIONS OF SALE LOCATED ON ATMEL’S WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel’s products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. © 2006 Atmel Corporation. All rights reserved. Atmel®, logo and combinations thereof, Everywhere You Are®, AVR®, AVR Studio® and others, are the registered trademarks or trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others. 8001C-AVR-06/06