ATA6612C/ATA6613C 8K/16K Flash Microcontroller with LIN Transceiver, 5V Regulator and Watchdog DATASHEET General Features Single-package fully-integrated Atmel(R) AVR(R) 8-bit microcontroller with LIN transceiver, 5V regulator (85mA current capability) and watchdog Very low current consumption in sleep mode 8Kbytes/16Kbytes flash memory for application program (Atmel ATA6612C/ATA6613C) Supply voltage up to 40V Operating voltage: 5V to 27V Temperature range: Tcase -40C to +125C QFN48, 7mm x 7mm package Description Atmel ATA6612C/ATA6613C is a system-in-package (SiP) product, which is particularly suited for complete LIN-bus slave-node applications. I consists of two ICs in one package supporting highly integrated solutions for in-vehicle LIN networks. The first chip is the LIN-system-basis-chip (LIN-SBC) Atmel ATA6624, which has an integrated LIN transceiver, a 5V regulator and a window watchdog. The second chip is an automotive microcontroller from Atmel series of Atmel AVR 8-bit microcontroller with advanced RISC architecture. The Atmel ATA6612C consists of the LIN-SBC Atmel ATA6624 and the Atmel ATmega88 with 8Kbytes flash. The Atmel ATA6613C consists of the LIN-SBC Atmel ATA6624 and the Atmel ATmega168 with 16Kbytes flash. All pins of the LIN system basis chip as well as all pins of the Atmel AVR microcontroller are bonded out to provide customers the same flexibility for their applications as they have when using discrete parts. In section 2 you will find the pin configuration for the complete SiP. In sections 3 to 5 the LIN SBC is described, and in sections 6 to 7 the Atmel AVR is described in detail. 9111L-AUTO-11/14 Figure 1. Application Diagram LIN Bus Atmel ATA6612C/ATA6613C MCU Atmel ATmega88 or ATmega168 2 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 LIN-SBC Atmel ATA6624 Pin Configuration PB4 PB3 PB2 PB1 PB0 PD7 PD6 PD5 PB7 PB6 MCUVCC GND2 Figure 1-1. Pinning QFN48, 7mm x 7mm 48 47 46 45 44 43 42 41 40 39 38 37 PB5 MCUAVCC ADC6 AREF 1 2 36 3 34 GND4 ADC7 PC0 PC1 PC2 PC3 PC4 PC5 5 35 4 6 7 8 33 Atmel ATA6612C/ ATA6613C 32 31 30 29 9 28 10 27 11 26 12 25 MCUVCC GND1 PD4 PD3 LIN GND WAKE NTRIG EN VS VCC PVCC 13 14 15 16 17 18 19 20 21 22 23 24 PC6 PD0 PD1 PD2 RXD INH TXD NRES WD_OSC TM MODE KL_15 1. Table 1-1. Pin Description Pin Symbol Function 1 PB5 2 MCUAVCC 3 ADC6 ADC input channel 6 4 AREF Analog reference voltage input 5 GND4 Ground 6 ADC7 ADC input channel 7 7 PC0 Port C 0 I/O line (ADC0/PCINT8) 8 PC1 Port C 1 I/O line (ADC1/PCINT9) 9 PC2 Port C 2 I/O line (ADC2/PCINT10) 10 PC3 Port C 3 I/O line (ADC3/PCINT11) 11 PC4 Port C 4 I/O line (ADC4/SDA/PCINT12) 12 PC5 Port C 5 I/O line (ADC5/SCL/PCINT13) 13 PC6 Port C 6 I/O line (RESET/PCINT14) 14 PD0 Port D 0 I/O line (RXD/PCINT16) 15 PD1 Port D 1 I/O line (TXD/PCINT17) Port B 5 I/O line (SCK / PCINT5) Microcontroller ADC-unit supply voltage (referred to as AVCC pin in Section 5. "Microcontroller Block" on page 27 and Section 6. "2-wire Serial Interface Characteristics" on page 276) 16 PD2 Port D 2 I/O line (INT0/PCINT18) 17(1) RXD Receive data output 18 (1) INH High side switch output for controlling an external voltage regulator 19 Note: (1) 1. TXD Transmit data input / active low output after a local wake up request This identifies the pins of the LIN SBC Atmel ATA6624 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 3 Table 1-1. Pin 20 Pin Description (Continued) Symbol (1) 21(1) NRES Watchdog and under voltage reset output (open drain) WD_OSC External resistor for adjustable watchdog timing 22(1) TM Tie to ground - for factory use only 23 (1) MODE Connect to GND for normal watchdog operation or connect to VCC for debug mode 24 (1) KL_15 Ignition detection (edge sensitive) 25(1) PVCC Voltage regulator sense input 26 (1) VCC 27 (1) VS Battery connection 28 (1) EN LIN-transceiver enable input Voltage regulator output 29(1) NTRIG Watchdog trigger input (negative edge) 30 (1) WAKE System-basis-chip external wake-up input 31 (1) GND Analog system GND 32 (1) LIN LIN-bus input/output 33 PD3 Port D 3 I/O line (INT1 OC2B/PCINT19) 34 PD4 Port D 4 I/O line (T0/XCK/PCINT20) 35 GND1 36 MCUVCC 37 GND2 38 MCUVCC 39 PB6 Port B 6 I/O line (TOSC1/XTAL1/PCINT6) 40 PB7 Port B 7 I/O line (TOSC2/XTAL2/PCINT7) 41 PD5 Port D 5 I/O line (T1/OC0B/PCINT21) 42 PD6 Port D 6 I/O line (AIN0/OC0A PCINT22) 43 PD7 Port D 7 I/O line (AIN1/PCINT23) 44 PB0 Port B 0 I/O line (ICP1/CLKO/PCINT0) 45 PB1 Port B 1 I/O line (OC1A/PCINT1) 46 PB2 Port B 2 I/O line (OC1B/SS/PCINT2) 47 PB3 Port B 3 I/O line (MOSI/OC2A/PCINT3) 48 PB4 Port B 4 I/O line (MISO/PCINT4) Backside Note: 1. 4 Function Ground Microcontroller supply voltage (referred to as VCC pin in Section 5. "Microcontroller Block" on page 27 and Section 6. "2-wire Serial Interface Characteristics" on page 276) Ground Microcontroller supply voltage (referred to as VCC pin in Section 5. "Microcontroller Block" on page 27 and Section 6. "2-wire Serial Interface Characteristics" on page 276) Heat slug is connected to GND This identifies the pins of the LIN SBC Atmel ATA6624 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 2. Absolute Maximum Ratings Table 2-1. Maximum Ratings of the SiP Stresses beyond those listed under "Absolute Maximum Ratings" may cause permanent damage to the device. This is a stress rating only and functional operation of the device at these or any 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. Parameters Symbol HBM ESD ANSI/ESD -STM5.1 JESD22 -A114 AEC-Q100 (002) Min. Typ. Max. Unit 2 KV CDM ESD STM 5.3.1 Corner pins (1, 12, 13, 24, 25, 36, 37, 48) All other pins 750 500 V V Machine model ESD AEC-Q100-Rev.F (003) 100 V ESD according to IBEE LIN EMC Test Spec. 1.0 following IEC 61000-4-2 - Pin VS, LIN, KL_15 (47k/100nF) to GND - Pin WAKE (33 k serial resistor) to GND 6 5 KV KV 6 KV ESD HBM following STM5.1 with 1.5k 100pF - Pin VS, LIN, KL_15, WAKE to GND Storage temperature Operating temperature (1) Ts -55 +150 C Tcase -40 +125 C Thermal resistance junction to heat slug Rthjc 5 K/W Thermal resistance junctiion to ambient Rthja 25 K/W Thermal shutdown of VCC regulator 150 165 170 C Thermal shutdown of LIN output 150 165 170 C Thermal shutdown hysteresis 10 C Note: 1. Tcase means the temperature of the heat slug (backside). It is mandatory that this backside temperature is 125C in the application. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 5 Table 2-2. Maximum Ratings of the LIN-SBC Stresses beyond those listed under "Absolute Maximum Ratings" may cause permanent damage to the device. This is a stress rating only and functional operation of the device at these or any 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. Parameters Symbol Min. Supply voltage VS VS -0.3 Pulse time 500ms; Ta = 25C Output current IVCC 85mA Pulse time 2min; Ta = 25C Output current IVCC 85mA Max. Unit +40 V VS +40 V VS 27 V -1 -150 +40 +100 V V INH - DC voltage -0.3 VS + 0.3 V LIN - DC voltage -27 +40 V Logic pins (RxD, TxD, EN, NRES, NTRIG, WD_OSC, MODE, TM) -0.3 +5.5 WAKE (with 33k serial resistor) KL_15 (with 47k/100nF) DC voltage Transient voltage due to ISO7637 (coupling 1nF) Output current NRES INRES PVCC DC voltage VCC DC voltage Table 2-3. Typ. -0.3 -0.3 V +2 mA +5.5 +6.5 V V Maximum Ratings of the Microcontroller Stresses beyond those listed under "Absolute Maximum Ratings" may cause permanent damage to the device. This is a stress rating only and functional operation of the device at these or any 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. Parameters 6 Symbol Min. Typ. Max. Unit Voltage on any pin except RESET with respect to ground -0.5 MCUVCC + 0.5 V Voltage on RESET with respect to ground -0.5 13.0 V Maximum operating voltage 6.0 V DC current per I/O pin 40.0 mA DC current MCUVCC and GND pins 200.0 mA Injection current at MCUVCC = 0V(1) 5.0 mA Injection current at MCUVCC = 5V Note: 1. Maximum current per port = 30mA 1.0 mA ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 3. LIN System-basis-chip Block 3.1 Features Master and slave operation possible Supply voltage up to 40V Operating voltage VS = 5V to 27V Typically 10A supply current during sleep mode Typically 57A supply current in silent mode Linear low-drop voltage regulator, 85mA current capability: Normal, fail-safe, and silent mode In sleep mode VCC is switched off VCC = 5.0V 2% VCC - undervoltage detection (4ms reset time) and watchdog reset logical combined at open drain output NRES Negative trigger input for watchdog Boosting the voltage regulator possible with an external NPN transistor LIN physical layer according to LIN 2.0, 2.1 specification and SAEJ2602-2 Wake-up capability via LIN-bus, wake pin, or Kl_15 pin INH output to control an external voltage regulator or to switch off the master pull Up resistor TXD time-out timer Bus pin is over temperature and short circuit protected versus GND and battery Adjustable watchdog time via external resistor Advanced EMC and ESD performance Fulfills the OEM "hardware requirements for LIN in automotive applications Rev.1.0" Interference and damage protection according ISO7637 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 7 3.2 Description The LIN-SBC ATA6624 is a fully integrated LIN transceiver, which complies with the LIN 2.0, 2.1 and SAEJ2602-2 specifications. It has a low-drop voltage regulator for 5V/85mA output and a window watchdog. The voltage regulator is able to source up to 85mA, but the output current can be boosted by using an external NPN transistor. The LIN-SBC is designed to handle the low-speed data communication in vehicles, e.g., in convenience electronics. Improved slope control at the LIN-driver ensures secure data communication up to 20kBaud. Sleep mode and silent mode guarantee very low current consumption. Figure 3-1. Block Diagram VS Normal and Fail-safe Mode INH PVCC Normal Mode Receiver RXD + RF Filter LIN WAKE KL_15 PVCC TXD Edge Detection Wake-up Bus Timer Slew Rate Control TXD Time-out Timer Control Unit EN Short Circuit and Overtemperature Protection Debounce Time Normal/Silent/ Fail-safe Mode 5V Undervoltage Reset OUT Watchdog GND PVCC 8 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 PVCC Mode Select Internal Testing Unit MODE VCC TM NTRIG NRES Adjustable Watchdog Oscillator WD_OSC 3.3 Functional Description 3.3.1 Physical Layer Compatibility Since the LIN physical layer is independent from higher LIN layers (e.g., the LIN protocol layer), all nodes with a LIN physical layer according to revision 2.x can be mixed with LIN physical layer nodes, which are according to older versions (i.e., LIN 1.0, LIN 1.1, LIN 1.2, LIN 1.3), without any restrictions. 3.3.2 Supply Pin (VS) The LIN operating voltage is VS = 5V to 27V. An under voltage detection is implemented to disable data transmission if VS falls below VSth < 4V in order to avoid false bus messages. After switching on VS, the IC starts in fail-safe mode, and the voltage regulator is switched on (i.e., output capability). The supply current is typically 10A in sleep mode and 57A in silent mode. 3.3.3 Ground Pin (GND) The IC does not affect the LIN bus in the event of GND disconnection. It is able to handle a ground shift up to 11.5% of versus The mandatory system ground is pin 5. 3.3.4 Voltage Regulator Output Pin (VCC) The internal voltage regulator is capable of driving loads with up to 85mA. It is able to supply the microcontroller and other ICs on the PCB and is protected against overloads by means of current limitation and over temperature shut-down. Furthermore, the output voltage is monitored and will cause a reset signal at the NRES output pin if it drops below a defined threshold Vthun. To boost up the maximum load current, an external NPN transistor may be used, with its base connected to the VCC pin and its emitter connected to PVCC. 3.3.5 Voltage Regulator Sense Pin (PVCC) The PVCC is the sense input pin of the voltage regulator. For normal applications (i.e., when only using the internal output transistor), this pin is connected to the VCC pin. If an external boosting transistor is used, the PVCC pin must be connected to the output of this transistor, i.e., its emitter terminal. 3.3.6 Bus Pin (LIN) A low-side driver with internal current limitation and thermal shutdown and an internal pull-up resistor compliant with the LIN 2.x specification are implemented. The allowed voltage range is between -27V and +40V. Reverse currents from the LIN bus to VS are suppressed, even in the event of GND shifts or battery disconnection. LIN receiver thresholds are compatible with the LIN protocol specification. The fall time from recessive to dominant bus state and the rise time from dominant to recessive bus state are slope controlled. 3.3.7 Input/Output Pin (TXD) In normal mode the TXD pin is the microcontroller interface used to control the state of the LIN output. TXD must be pulled to ground in order to have a low LIN-bus. If TXD is high or unconnected (internal pull-up resistor), the LIN output transistor is turned off, and the bus is in recessive state. During fail-safe mode, this pin is used as output. It is current-limited to < 8mA. and is latched to low if the last wake-up event was from pin WAKE or KL_15. 3.3.8 TXD Dominant Time-out Function The TXD input has an internal pull-up resistor. An internal timer prevents the bus line from being driven permanently in dominant state. If TXD is forced to low for longer than tDOM > 6ms, the LIN-bus driver is switched to recessive state. To reactivate the LIN bus driver, switch TXD to high (>10s). 3.3.9 Output Pin (RXD) The output pin reports the state of the LIN-bus to the microcontroller. LIN high (recessive state) is reported by a high level at RXD; LIN low (dominant state) is reported by a low level at RXD. The output has an internal pull-up resistor with typically 5k to VCC. The AC characteristics can be defined with an external load capacitor of 20pF. The output is short-circuit protected. RXD is switched off in Unpowered mode (i.e., VS = 0V). ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 9 3.3.10 Enable Input Pin (EN) The enable Input pin controls the operation mode of the device. If EN is high, the circuit is in normal mode, with transmission paths from TXD to LIN and from LIN to RXD both active. The VCC voltage regulator operates with 5V/85mA output capability. If EN is switched to low while TXD is still high, the device is forced to silent mode. No data transmission is then possible, and the current consumption is reduced to IVS typ. 57A. The VCC regulator has its full functionality. If EN is switched to low while TXD is low, the device is forced to sleep mode. No data transmission is possible, and the voltage regulator is switched off. 3.3.11 Wake Input Pin (WAKE) The wake input pin is a high-voltage input used to wake up the device from sleep mode or silent mode. It is usually connected to an external switch in the application to generate a local wake-up. A pull-up current source, typically 10A, is implemented. If a local wake-up is not needed for the application, connect the Wake pin directly to the VS pin. 3.3.12 Mode Input Pin (MODE) Connect the MODE pin directly or via an external resistor to GND for normal watchdog operation. To debug the software of the connected microcontroller, connect the MODE pin to VCC and the watchdog is switched off. 3.3.13 TM Input Pin The TM pin is used for final production measurements at Atmel(R). In normal application, it has to be always connected to GND. 3.3.14 KL_15 Pin The KL_15 pin is a high-voltage input used to wake up the device from sleep or silent mode. It is an edge sensitive pin (low-to-high transition). It is usually connected to ignition to generate a local wake-up in the application when the ignition is switched on. Although KL_15 pin is at high voltage (VBatt), it is possible to switch the IC into sleep or silent mode. Connect the KL_15 pin directly to GND if you do not need it. A debounce timer with a typical TdbKl_15 of 160s is implemented. The input voltage threshold can be adjusted by varying the external resistor due to the input current IKL_15. To protect this pin against voltage transients, a serial resistor of 47k and a ceramic capacitor of 100nF are recommended. With this RC combination you can increase the wake-up time TwKL_15 and, therefore, the sensitivity against transients on the ignition Kl.15. The wake-up time can also be increased by using external capacitors with higher values. 3.3.15 INH Output Pin The INH Output pin is used to switch on an external voltage regulator during normal or fail-safe mode. The INH pin is switched off in sleep or silent mode. It is possible to switch off the external 1k master resistor via the INH pin for master node applications. The INH pin is switched off during VCC under voltage reset. 3.3.16 Reset Output Pin (NRES) The reset output pin, an open drain output, switches to low during VCC under voltage or a watchdog failure. 3.3.17 WD_OSC Output Pin The WD_OSC output pin provides a typical voltage of 1.2V, which supplies an external resistor with values between 34k and 120k to adjust the watchdog oscillator time. 3.3.18 NTRIG Input Pin The NTRIG input pin is the trigger input for the window watchdog. A pull-up resistor is implemented. A negative edge triggers the watchdog. The trigger signal (low) must exceed a minimum time ttrigmin to generate a watchdog trigger. 10 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 3.3.19 Wake-up Events from Sleep or Silent Mode LIN-bus WAKE pin EN pin KL_15 3.3.20 Modes of Operation Figure 3-2. Modes of Operation a: VS > 5V Unpowered Mode VBatt = 0V b b: VS < 4V c: Bus wake-up event d: Wake up from WAKE or KL_15 pin a e: NRES switches to low b Fail-safe Mode VCC: 5V/85mA With undervoltage monitoring Communication: OFF Watchdog: ON b e EN = 1 b c+d+e EN = 1 c+d Go to silent command EN = 0 Silent Mode TXD = 1 VCC: 5V/85mA With undervoltage monitoring Communication: OFF Watchdog: OFF Local wake-up event Normal Mode EN = 1 VCC: 5V/85mA With undervoltage monitoring Go to sleep command EN = 0 Communication: ON Watchdog: ON Table 3-1. Sleep Mode TXD = 0 VCC: switched off Communication: OFF Watchdog: OFF Table of Modes Mode of Operation Transceiver VCC Watchdog WD_OSC INH RXD LIN Fail-safe Off 5V On 1.23V On High, except after wake-up Recessive Normal On 5V On 1.23V On LIN depending TXD depending Silent Off 5V Off 0V Off High Recessive Sleep Off 0V Off 0V Off 0V Recessive 3.3.20.1 Normal Mode This is the normal transmitting and receiving mode at the LIN interface in accordance with the LIN specification LIN 2.x. The voltage regulator is active and can source up to 85mA. The under voltage detection is activated. The watchdog needs a trigger signal from NTRIG to avoid resets at NRES. If NRES is switched to low, the IC changes its state to fail-safe mode. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 11 3.3.20.2 Silent Mode A falling edge at EN when TXD is high switches the IC into silent mode. The TXD signal has to be logic high during the mode select window (see Figure 3-3). The transmission path is disabled in silent mode. The overall supply current from VBatt is a combination of the IVSsi 57A plus the VCC regulator output current IVCC. The internal slave termination between the LIN pin and the VS pin is disabled in silent mode, only a weak pull-up current (typically 10A) between the LIN pin and the VS pin is present. silent mode can be activated independently from the actual level on the LIN, WAKE, or KL_15 pins. If an under voltage condition occurs, NRES is switched to low, and the IC changes its state to fail-safe mode. A voltage lower than the LIN pre_wake detection VLINL at the LIN pin activates the internal LIN receiver and switches on the internal slave termination between the LIN pin and the VS pin. Figure 3-3. Switch to Silent Mode Normal Mode Silent Mode EN TXD Mode select window td = 3.2s NRES VCC Delay time silent mode td_sleep = maximum 20s LIN LIN switches directly to recessive mode 12 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 A falling edge at the LIN pin followed by a dominant bus level maintained for a certain time period (> tbus) and followed by a rising edge at the LIN pin (see Figure 3-4) result in a remote wake-up request. The device switches from silent mode to fail-safe mode. The remote wake-up request is indicated by a low level at the RXD pin to interrupt the microcontroller (see Figure 3-4). EN high can be used to switch directly to normal mode. Figure 3-4. LIN Wake-up from Silent Mode Bus wake-up filtering time tbus Fail-safe mode Normal mode LIN Bus Node in silent mode RXD High Low High TXD Watchdog VCC Voltage Regulator Watchdog off Start watchdog lead time td Silent mode 5V Fail safe mode 5V Normal mode EN High EN NRES Undervoltage detection active ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 13 3.3.20.3 Sleep Mode A falling edge at EN when TXD is low switches the IC into sleep mode. The TXD signal has to be logic low during the mode select window (Figure 3-5). In order to avoid any influence to the LIN-pin during switching into sleep mode it is possible to switch the EN up to 3.2s earlier to LOW than the TXD. Therefore, the best and easiest way are two falling edges at TXD and EN at the same time.The transmission path is disabled in sleep mode. The supply current IVSsleep from VBatt is typically 10A. The VCC regulator and the INH output are switched off. NRES and RXD are low. The internal slave termination between the LIN pin and VS pin is disabled, only a weak pull-up current (typically 10A) between the LIN pin and the VS pin is present. sleep mode can be activated independently from the current level on the LIN, WAKE, or KL_15 pin. A voltage lower than the LIN pre_wake detection VLINL at the LIN pin activates the internal LIN receiver and switches on the internal slave termination between the LIN pin and the VS pin. A falling edge at the LIN pin followed by a dominant bus level maintained for a certain time period (> tbus) and followed by a rising edge at pin LIN results in a remote wake-up request. The device switches from sleep mode to fail-safe mode. The VCC regulator is activated, and the remote wake-up request is indicated by a low level at the RXD pin to interrupt the microcontroller (see Figure 3-6 on page 15). EN high can be used to switch directly from sleep/silent to fail-safe mode. If EN is still high after VCC ramp up and under voltage reset time, the IC switches to the normal mode. Figure 3-5. Switch to Sleep Mode Normal Mode Sleep Mode EN Mode select window TXD td = 3.2s NRES VCC Delay time sleep mode td_sleep = maximum 20s LIN LIN switches directly to recessive mode 3.3.20.4 Fail-safe Mode The device automatically switches to fail-safe mode at system power-up and the voltage regulator is switched on (see Figure 3-7 on page 17). The NRES output switches to low for tres = 4ms and gives a reset to the microcontroller. LIN communication is switched off. The IC stays in this mode until EN is switched to high. The IC then changes to normal mode. A power down of VBatt (VS < 4V) during silent or sleep mode switches the IC into fail-safe mode. A low at NRES switches into fail-safe mode directly. During fail-safe mode the TXD pin is an output and signals the last wake-up source. 14 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 3.3.20.5 Unpowered Mode If you connect battery voltage to the application circuit, the voltage at the VS pin increases according to the block capacitor (see Figure 3-7 on page 17). After VS is higher than the VS undervoltage threshold VSth, the IC mode changes from unpowered mode to fail-safe mode. The VCC output voltage reaches its nominal value after tVCC. This time, tVCC, depends on the VCC capacitor and the load. The NRES is low for the reset time delay treset. During this time, treset, no mode change is possible. Figure 3-6. LIN Wake-up from Sleep Mode Bus wake-up filtering time tbus Fail-safe Mode Normal Mode LIN Bus RXD Low TXD VCC Voltage Regulator On state Off state Regulator wake-up time EN High EN Reset time NRES Microcontroller start-up time delay Watchdog Watchdog off Start watchdog lead time td 3.3.21 Wake-up Scenarios from Silent to Sleep Mode 3.3.21.1 Remote Wake-up via Dominant Bus State A voltage lower than the LIN pre_wake detection VLINL at the LIN pin activates the internal LIN receiver. A falling edge at the LIN pin followed by a dominant bus level VBUSdom maintained for a certain time period (> tBUS) and followed by a rising edge at pin LIN result in a remote wake-up request. The device switches from silent or sleep mode to fail-safe mode. The VCC voltage regulator is/remains activated, the INH pin is switched to high, and remote wake-up request is indicated by a low level at the RXD pin to generate an interrupt for the microcontroller. A low level at the LIN pin in the normal mode starts the bus wake-up filtering time, and if the IC is switched to silent or sleep mode, it will receive a wake-up after a positive edge at the LIN pin. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 15 3.3.21.2 Local Wake-up via Pin Wake A falling edge at the WAKE pin followed by a low level maintained for a certain time period (> tWAKE) results in a local wake-up request. The device switches to fail-safe mode. The local wake-up request is indicated by a low level at the RXD pin to generate an interrupt in the microcontroller and a strong pull down at TXD. When the wake pin is low, it is possible to switch to silent or sleep mode via pin EN. In this case, the wake-up signal has to be switched to high >10s before the negative edge at WAKE starts a new local wake-up request. 3.3.21.3 Local Wake-up via Pin KL_15 A positive edge at pin KL_15 followed by a high voltage level for a certain time period (>tKL_15) results in a local wake-up request. The device switches into the fail-safe mode. The extra long wake-up time ensures that no transients at KL_15 create a wake up. The local wake-up request is indicated by a low level at the RXD pin to generate an interrupt for the microcontroller and a strong pull down at TXD. During high-level voltage at pin KL_15, it is possible to switch to silent or sleep mode via pin EN. In this case, the wake-up signal has to be switched to low >250s before the positive edge at KL_15 starts a new local wake-up request. With external RC combination, the time is even longer. 3.3.21.4 Wake-up Source Recognition The device can distinguish between a local wake-up request (Wake or KL_15 pins) and a remote wake-up request (via LIN bus). The wake-up source can be read on the TXD pin in fail-safe mode. A high level indicates a remote wake-up request (weak pull up at the TXD pin); a low level indicates a local wake-up request (strong pull down at the TXD pin). The wake-up request flag (signalled on the RXD pin), as well as the wake-up source flag (signalled on the TXD pin), is immediately reset if the microcontroller sets the EN pin to high (see Figure 3-3 on page 12 and Figure 3-4 on page 13) and the IC is in normal mode. The last wake-up source flag is stored and signalled in fail-safe mode at the TXD pin. 3.3.22 Fail-safe Features 16 During a short-circuit at LIN to VBattery, the output limits the output current to IBUS_LIM. Due to the power dissipation, the chip temperature exceeds TLINoff, and the LIN output is switched off. The chip cools down and after a hysteresis of Thys, switches the output on again. RXD stays on high because LIN is high. During LIN over temperature switch-off, the VCC regulator works independently. During a short-circuit from LIN to GND the IC can be switched into sleep or silent mode. If the short-circuit disappears, the IC starts with a remote wake-up. The reverse current is very low <15A at the LIN pin during loss of VBatt or GND. This is optimal behavior for bus systems where some slave nodes are supplied from battery or ignition. During a short circuit at VCC, the output limits the output current to IVCCn. Because of under voltage, NRES switches to low and sends a reset to the microcontroller. The IC switches into fail-safe mode. If the chip temperature exceeds the value TVCCoff, the VCC output switches off. The chip cools down and after a hysteresis of Thys, switches the output on again. Because of the fail-safe mode, the VCC voltage will switch on again although EN is switched off from the microcontroller. The microcontroller can start with its normal operation. EN pin provides a pull-down resistor to force the transceiver into recessive mode if EN is disconnected. If the resistor at WO_OSC pin is disconnected, the watchdog runs with an internal oscillator and guarantees a reset after the second NTRIG signal at the latest. RXD pin is set floating if VBatt is disconnected. TXD pin provides a pull-up resistor to force the transceiver into recessive mode if TXD is disconnected. If TXD is short-circuited to GND, it is possible to switch to sleep mode via ENABLE after tdom >20ms. If the WD_OSC pin has a short-circuit to GND and the NTRIG signal has a period time >27ms, the watchdog runs with an internal oscillator and guarantees a reset after the second NTRIG signal at the latest. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 3.3.23 Voltage Regulator The voltage regulator needs an external capacitor for compensation and for smoothing the disturbances from the microcontroller. It is recommended to use an electrolytic capacitor with C 1.8F and a ceramic capacitor with C = 100nF. The values of these capacitors can be varied by the customer, depending on the application. The main power dissipation of the IC is created from the VCC output current IVCC, which is needed for the application. In Figure 3-8 the safe operating area is shown. Figure 3-7. VCC Voltage Regulator: Ramp Up and Undervoltage Detection VS 12V 5.5V t VCC 5V Vthun tVCC tres_f tReset t NRES 5V t Figure 3-8. Power Dissipation: Safe Operating Area VCC Output Current versus Supply Voltage VS at Different Ambient Temperatures 90 80 Tamb = 100C IVCC (mA) 70 60 Tamb = 105C 50 Tamb = 110C 40 30 Tamb = 115C 20 10 0 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 VS (V) For programming purposes of the microcontroller it is potentially necessary to supply the VCC output via an external power supply while the VS pin of the system basis chip is disconnected. This will not affect the system basis chip. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 17 3.3.24 Watchdog The watchdog anticipates a trigger signal from the microcontroller at the NTRIG (negative edge) input within a time window of Twd. The trigger signal must exceed a minimum time ttrigmin > 200ns. If a triggering signal is not received, a reset signal will be generated at output NRES. After a watchdog reset the IC starts with the lead time. The timing basis of the watchdog is provided by the internal oscillator. Its time period, Tosc, is adjustable via the external resistor Rwd_osc (34k to 120k). During silent or sleep mode the watchdog is switched off to reduce current consumption. The minimum time for the first watchdog pulse is required after the under voltage reset at NRES disappears. It is defined as lead time td. After wake up from sleep or silent mode, the lead time td starts with the negative edge of the RXD output. 3.3.24.1 Typical Timing Sequence with RWD_OSC = 51k The trigger signal Twd is adjustable between 20ms and 64ms using the external resistor RWD_OSC. For example, with an external resistor of RWD_OSC = 51k 1%, the typical parameters of the watchdog are as follows: tosc = 0.405 x RWD_OSC - 0.0004 x (RWD_OSC)2 (RWD_OSC in k; tosc in s) tOSC = 19.6s due to 51k td = 7895 x 19.6s = 155ms t1 = 1053 x 19.6s = 20.6ms t2 = 1105 x 19.6s = 21.6ms tnres = constant = 4ms After ramping up the battery voltage, the 5V regulator is switched on. The reset output NRES stays low for the time treset (typically 4ms), then it switches to high, and the watchdog waits for the trigger sequence from the microcontroller. The lead time, td, follows the reset and is td = 155ms. In this time, the first watchdog pulse from the microcontroller is required. If the trigger pulse NTRIG occurs during this time, the time t1 starts immediately. If no trigger signal occurs during the time td, a watchdog reset with tNRES = 4ms will reset the microcontroller after td = 155ms. The times t1 and t2 have a fixed relationship between each other. A triggering signal from the microcontroller is anticipated within the time frame of t2 = 21.6ms. To avoid false triggering from glitches, the trigger pulse must be longer than tTRIG,min > 200ns. This slope serves to restart the watchdog sequence. If the triggering signal fails in this open window t2, the NRES output will be drawn to ground. A triggering signal during the closed window t1 immediately switches NRES to low. Figure 3-9. Timing Sequence with RWD_OSC = 51k VCC Undervoltage Reset NRES Watchdog Reset tnres = 4ms treset = 4ms td = 155ms t1 t1 = 20.6ms t2 = 21ms twd NTRIG ttrig > 200ns 18 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 t2 3.3.24.2 Worst Case Calculation with RWO_OSC = 51k The internal oscillator has a tolerance of 20%. This means that t1 and t2 can also vary by 20%. The worst case calculation for the watchdog period twd is calculated as follows. The ideal watchdog time twd is between the maximum t1 and the minimum t1 plus the minimum t2. t1,min = 0.8 x t1 = 16.5ms, t1,max = 1.2 x t1 = 24.8ms t2,min = 0.8 x t2 = 17.3ms, t2,max = 1.2 x t2 = 26ms twdmax = t1min + t2min = 16.5ms + 17.3ms = 33.8ms twdmin = t1max = 24.8ms twd = 29.3ms 4.5ms (15%) A microcontroller with an oscillator tolerance of 15% is sufficient to supply the trigger inputs correctly. Table 3-2. Typical Watchdog Timings RWD_OSC k Oscillator Period tosc/s Lead Time td/ms Closed Window t1/ms Open Window t2/ms Trigger Period from Microcontroller twd/ms Reset Time tnres/ms 34 13.3 105 14.0 14.7 19.9 4 51 19.61 154.8 20.64 21.67 29.32 4 91 33.54 264.80 35.32 37.06 50.14 4 120 42.84 338.22 45.11 47.34 64.05 4 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 19 4. Electrical Characteristics 5V < VS < 27V, -40C < Tcase < 125C, -40C < Tj < 150C, unless otherwise specified. All values refer to GND pins No. 1 1.1 1.2 1.3 Parameters Test Conditions Pin Symbol Min. VS VS 5 Sleep mode VLIN > VS - 0.5V VS < 14V (Tj = 25C) VS IVSsleep 3 Sleep mode VLIN > VS - 0.5V VS < 14V (Tj = 125C) VS IVSsleep Bus recessive VS < 14V (Tj = 25C) Without load at VCC VS Bus recessive VS < 14V (Tj = 125C) Without load at VCC Typ. Max. Unit Type* 27 V A 10 14 A B 5 11 16 A A IVSsi 47 57 67 A B VS IVSsi 56 66 76 A A VS Pin Nominal DC voltage range Supply current in sleep mode Supply current in silent mode 1.4 Bus recessive Supply current in normal VS < 14V mode Without load at VCC VS IVSrec 0.3 0.8 mA A 1.5 Bus dominant Supply current in normal VS < 14V mode VCC load current 50mA VS IVSdom 50 53 mA A 1.6 Supply current in fail-safe mode VS IVSfail 250 550 A A 1.7 VS undervoltage threshold VS VSth 3.7 5 V A 1.8 VS undervoltage threshold hysteresis VS VSth_hys V A RXD IRXD 8 mA A 0.4 V A 7 k A 2 Bus recessive VS < 14V Without load at VCC 4.4 0.2 RXD Output Pin Normal mode VLIN = 0V VRXD = 0.4V 2.1 Low-level output sink current 2.2 Low-level output voltage IRXD = 1mA RXD VRXDL 2.3 Internal resistor to VCC RXD RRXD 3 3 TXD Input/Output Pin TXD VTXDL -0.3 +0.8 V A VCC + 0.3V V A 400 k A +3 A A 8 mA A 3.1 Low-level voltage input 3.2 High-level voltage input 3.3 Pull-up resistor 3.4 High-level leakage current 3.5 Fail-safe mode Low-level output sink V = VS current at local wake-up LIN VWAKE = 0V request VTXD = 0.4V 1.3 TXD VTXDH 2 VTXD = 0V TXD RTXD 125 VTXD = VCC TXD ITXD -3 TXD ITXDwake 2 2.5 5 250 2.5 *) Type means: A = 100% tested, B = 100% correlation tested, C = Characterized on samples, D = Design parameter 20 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 4. Electrical Characteristics (Continued) 5V < VS < 27V, -40C < Tcase < 125C, -40C < Tj < 150C, unless otherwise specified. All values refer to GND pins No. Parameters 4 EN Input Pin 4.1 Low-level voltage input 4.2 High-level voltage input 4.3 Pull-down resistor 4.4 Low-level input current 5 Test Conditions Pin Symbol Min. EN VENL Typ. Max. Unit Type* -0.3 +0.8 V A VCC + 0.3V V A 200 k A EN VENH 2 VEN = VCC EN REN 50 VEN = 0V EN IEN -3 +3 A A 125 NTRIG Watchdog Input Pin 5.1 Low-level voltage input NTRIG VNTRIGL -0.3 +0.8 V A 5.2 High-level voltage input NTRIG VNTRIGH 2 VCC + 0.3V V A 5.3 Pull-up resistor VNTRIG = 0V NTRIG RNTRIG 125 400 k A 5.4 High-level leakage current VNTRIG = VCC NTRIG INTRIG -3 +3 A A 6 250 Mode Input Pin 6.1 Low-level voltage input MODE VMODEL -0.3 +0.8 V A 6.2 High-level voltage input MODE VMODEH 2 VCC + 0.3V V A 6.3 High-level leakage current MODE IMODE -3 +3 A A INH VINHH VS - 0.75 VS V A INH RINH 50 A INH IINHL +3 A A VS V A 7 INH Output Pin 7.1 High-level voltage 7.2 Switch-on resistance between VS and INH 7.3 Leakage current 8 VMODE = VCC or VMODE = 0V IINH = -15mA Sleep mode VINH = 0V/27V, VS = 27V 30 -3 LIN Bus Driver: Bus Load Conditions: Load 1 (small): 1nF, 1k; Load 2 (large): 10nF, 500; Internal pull-up RRXD = 5k; CRXD = 20pF Load 3 (medium): 6.8nF, 660, characterized on samples 10.6 and 10.7 specifies the timing parameters for proper operation at 20kBit/s and 10.8 and 10.9 at 10.4kBit/s 8.1 Driver recessive output Load1/load2 voltage LIN VBUSrec 8.2 Driver dominant voltage VVS = 7V Rload = 500 LIN V_LoSUP 1.2 V A 8.3 Driver dominant voltage VVS = 18V Rload = 500 LIN V_HiSUP 2 V A 8.4 Driver dominant voltage VVS = 7.0V Rload = 1000 LIN V_LoSUP_1k 0.6 V A 8.5 Driver dominant voltage VVS = 18V Rload = 1000 LIN V_HiSUP_1k 0.8 V A 8.6 Pull-up resistor to VS The serial diode is mandatory LIN RLIN 20 60 k A 8.7 Voltage drop at the serial diodes In pull-up path with Rslave ISerDiode = 10mA LIN VSerDiode 0.4 1.0 V D 0.9 x VS 30 *) Type means: A = 100% tested, B = 100% correlation tested, C = Characterized on samples, D = Design parameter ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 21 4. Electrical Characteristics (Continued) 5V < VS < 27V, -40C < Tcase < 125C, -40C < Tj < 150C, unless otherwise specified. All values refer to GND pins No. Parameters 8.8 LIN current limitation VBUS = VBatt_max 8.9 Input leakage current at the receiver including pull-up resistor as specified 8.10 8.11 8.12 Test Conditions Pin Symbol Min. Typ. Max. Unit Type* LIN IBUS_LIM 40 120 200 mA A Input leakage current Driver off VBUS = 0V VBatt = 12V LIN IBUS_PAS_do -1 -0.35 mA A Leakage current LIN recessive Driver off 8V < VBatt < 18V 8V < VBUS < 18V VBUS VBatt LIN Leakage current when control unit disconnected from ground. Loss of local ground must not affect communication in the residual network. GNDDevice = VS VBatt = 12V 0V < VBUS < 18V LIN Leakage current at a disconnected battery. Node has to sustain the VBatt disconnected current that can flow VSUP_Device = GND under this condition. 0V < VBUS < 18V Bus must remain operational under this condition. m IBUS_PAS_re 10 20 A A +0.5 +10 A A 0.1 2 A A 0.5 x VS 0.525 x VS V A 0.4 x VS V A V A 0.175 x VS V A c IBUS_NO_gn -10 d LIN IBUS_NO_bat LIN VBUS_CNT 9 LIN Bus Receiver 9.1 Center of receiver threshold 9.2 Receiver dominant state VEN = 5V LIN VBUSdom 9.3 Receiver recessive state VEN = 5V LIN VBUSrec 0.6 x VS 9.4 Receiver input hysteresis Vhys = Vth_rec - Vth_dom LIN VBUShys 0.028 x VS 9.5 Pre_Wake detection LIN High-level input voltage LIN VLINH VS - 2V VS + 0.3V V A 9.6 Pre_Wake detection LIN Activates the LIN receiver Low-level input voltage LIN VLINL -27 VS - 3.3V V A VBUS_CNT = (Vth_dom + Vth_rec)/2 0.475 x VS 0.1 x VS *) Type means: A = 100% tested, B = 100% correlation tested, C = Characterized on samples, D = Design parameter 22 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 4. Electrical Characteristics (Continued) 5V < VS < 27V, -40C < Tcase < 125C, -40C < Tj < 150C, unless otherwise specified. All values refer to GND pins No. Parameters 10 Internal Timers Test Conditions Pin Symbol Min. Typ. Max. Unit Type* 10.1 Dominant time for wakeVLIN = 0V up via LIN bus LIN tbus 30 90 150 s A 10.2 Time delay for mode change from fail-safe into normal mode via EN pin VEN = 5V EN tnorm 5 15 20 s A 10.3 Time delay for mode change from normal V = 0V mode to sleep mode via EN EN pin EN tsleep 2 7 12 s A 10.4 TXD dominant time-out VTXD = 0V time TXD tdom 6 13 20 ms A 10.5 Time delay for mode change from silent V = 5V mode into normal mode EN via EN EN ts_n 5 15 40 s A Duty cycle 1 THRec(max) = 0.744 x VS THDom(max) = 0.581 x VS VS = 7.0V to 18V tBit = 50s D1 = tbus_rec(min)/(2 x tBit) LIN D1 0.396 Duty cycle 2 THRec(min) = 0.422 x VS THDom(min) = 0.284 x VS VS = 7.6V to 18V tBit = 50s D2 = tbus_rec(max)/(2 x tBit) LIN D2 Duty cycle 3 THRec(max) = 0.778 x VS THDom(max) = 0.616 x VS VS = 7.0V to 18V tBit = 96s D3 = tbus_rec(min)/(2 x tBit) LIN D3 10.9 Duty cycle 4 THRec(min) = 0.389 x VS THDom(min) = 0.251 x VS VS = 7.6V to 18V tBit = 96s D4 = tbus_rec(max)/(2 x tBit) LIN D4 10.10 Slope time falling and rising edge at LIN VS = 7.0V to 18V LIN tSLOPE_fall tSLOPE_rise 10.6 10.7 10.8 11 A 0.581 A 0.417 A 0.590 3.5 A 22.5 s A 6 s A +2 s A Receiver Electrical AC Parameters of the LIN Physical Layer LIN Receiver, RXD Load Conditions (CRXD): 20pF 11.1 Propagation delay of receiver (Figure 4-1 on page 26) 11.2 Symmetry of receiver V = 7.0V to 18V propagation delay rising S =t -t t edge minus falling edge rx_sym rx_pdr rx_pdf VS = 7.0V to 18V trx_pd = max(trx_pdr, trx_pdf) RXD trx_pd RXD trx_sym -2 *) Type means: A = 100% tested, B = 100% correlation tested, C = Characterized on samples, D = Design parameter ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 23 4. Electrical Characteristics (Continued) 5V < VS < 27V, -40C < Tcase < 125C, -40C < Tj < 150C, unless otherwise specified. All values refer to GND pins No. Parameters Test Conditions 12 NRES Open Drain Output Pin Pin Symbol Min. Typ. Max. Unit Type* 12.1 Low-level output voltage VS 5.5V INRES = 1mA NRES VNRESL 0.14 V A 12.2 Low-level output low 10k to 5V VCC = 0V NRES VNRESLL 0.14 V A 12.3 Undervoltage reset time VS 5.5V CNRES = 20pF NRES treset 2 6 ms A 12.4 Reset debounce time for falling edge VS 5.5V CNRES = 20pF NRES tres_f 1.5 10 s A 13 Watchdog Oscillator 1.33 V A 120 k A 13.1 Voltage at WD_OSC in normal mode 13.2 Possible values of resistor 13.3 Oscillator period 13.4 IWD_OSC = -200A VVS 4V WD_OSC VWD_OSC 1.23 ROSC 34 ROSC = 34k tOSC 10.65 13.3 15.97 s A Oscillator period ROSC = 51k tOSC 15.68 19.6 23.52 s A 13.5 Oscillator period ROSC = 91k tOSC 26.83 33.5 40.24 s A 13.6 Oscillator period ROSC = 120k tOSC 34.2 42.8 51.4 s A 14 WD_OSC 1.13 4 Watchdog Timing Relative to tOSC 14.1 Watchdog lead time after reset td 7895 cycles A 14.2 Watchdog closed window t1 1053 cycles A 14.3 Watchdog open window t2 1105 cycles A 14.4 Watchdog reset time NRES 4.8 ms A 15 NRES tnres 3.2 4 KL_15 Pin 15.1 High-level input voltage Positive edge initializes a RV = 47 k wake-up KL_15 VKL_15H 4 VS + 0.3V V A 15.2 Low-level input voltage RV = 47 k KL_15 VKL_15L -1 +2 V A 15.3 KL_15 pull-down current VS < 27V VKL_15 = 27V KL_15 IKL_15 50 65 A A 15.4 Internal debounce time Without external capacitor KL_15 TdbKL_15 80 160 250 s A 15.5 KL_15 wake-up time RV = 47k, C = 100nF KL_15 TwKL_15 0.4 2 4.5 ms C WAKE VWAKEH VS - 1V VS + 0.3V V A VS - 3.3V V A A A A A 16 WAKE Pin 16.1 High-level input voltage 16.2 Low-level input voltage Initializes a wake-up signal WAKE VWAKEL -1 16.3 WAKE pull-up current VS < 27V VWAKE = 0V WAKE IWAKE -30 16.4 High-level leakage current VS = 27V VWAKE = 27V WAKE IWAKEL -5 -10 +5 *) Type means: A = 100% tested, B = 100% correlation tested, C = Characterized on samples, D = Design parameter 24 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 4. Electrical Characteristics (Continued) 5V < VS < 27V, -40C < Tcase < 125C, -40C < Tj < 150C, unless otherwise specified. All values refer to GND pins No. Parameters Test Conditions 16.5 Time of low pulse for wake-up via WAKE pin VWAKE = 0V 17 17.1 Pin Symbol Min. Typ. Max. Unit Type* WAKE IWAKEL 30 70 150 s A 5.5V < VS < 18V (0mA to 50mA) VCC VCCnor 4.9 5.1 V A 6V < VS < 18V (0mA to 85mA) VCC VCCnor 4.9 5.1 V C VCC VCClow VS - VD 5.1 V A 250 mV A 600 mV A 200 mV A VCC Voltage Regulator, PVCC = VCC Output voltage VCC 17.2 Output voltage VCC at low VS 4V < VS < 5.5V 17.3 Regulator drop voltage VS > 4V IVCC = -20mA VS, VCC VD1 17.4 Regulator drop voltage VS > 4V IVCC = -50mA VS, VCC VD2 17.5 Regulator drop voltage VS > 3.3V IVCC = -15mA VS, VCC VD3 17.6 Line regulation 5.5V < VS < 18V VCC VCCline 0.1 0.2 % A 17.7 Load regulation 5mA < IVCC < 50mA VCC VCCload 0.1 0.5 % A 17.8 Power supply ripple rejection 10Hz to 100kHz CVCC = 10F VS = 14V, IVCC = -15mA VCC dB D 17.9 Output current limitation VS > 5.5V mA A F D V A mV A s A 17.10 External load capacity 0.2 < ESR < 5 at 100kHz for phase margin 60 400 50 VCC IVCClim -240 -130 VCC Cload 1.8 10 4.2 -85 ESR < 0.2 at 100kHz for phase margin 30 17.11 VCC undervoltage threshold Referred to VCC VS > 5.5V VCC VthunN 17.12 Hysteresis of undervoltage threshold Referred to VCC VS > 5.5V VCC Vhysthun 250 17.13 Ramp-up time VS > 5.5V to VCC = 5V CVCC = 2.2F Iload = -5mA at VCC VCC tVCC 130 4.8 300 *) Type means: A = 100% tested, B = 100% correlation tested, C = Characterized on samples, D = Design parameter ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 25 Figure 4-1. Definition of Bus Timing Parameters tBit tBit tBit TXD (Input to transmitting node) tBus_dom(max) tBus_rec(min) Thresholds of THRec(max) VS (Transceiver supply of transmitting node) receiving node1 THDom(max) LIN Bus Signal Thresholds of THRec(min) receiving node2 THDom(min) tBus_dom(min) tBus_rec(max) RXD (Output of receiving node1) trx_pdf(1) trx_pdr(1) RXD (Output of receiving node2) trx_pdr(2) 26 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 trx_pdf(2) 5. Microcontroller Block 5.1 Features High performance, low power Atmel(R) AVR(R) 8-bit microcontroller Advanced RISC architecture 131 powerful instructions - most single clock cycle execution 32 x 8 general purpose working register Fully static operation Up to 16MIPS throughput at 16MHz On-chip 2-cycle multiplier Non-volatile program and data memories 8/16Kbytes of in-system self-programmable flash (Atmel ATA6612C/ATA6613C) Endurance: 75,000 write/erase cycles Optional boot code section with independent lock bits In-system programming by on-chip boot program True read-while-write operation 512bytes EEPROM Endurance: 100,000 write/erase cycles 1Kbyte internal SRAM Programming lock for software security Peripheral features Two 8-bit Timer/Counters with separate prescaler and compare mode One 16-bit Timer/Counter with separate prescaler, compare mode, and capture mode Real time counter with separate oscillator Six PWM channels 8-channel 10-bit ADC Programmable serial USART Master/slave SPI serial interface Byte-oriented 2-wire serial interface Programmable watchdog timer with separate on-chip oscillator On-chip analog comparator Interrupt and wake-up on pin change Special microcontroller features Power-on reset and programmable brown-out detection Internal calibrated oscillator External and internal interrupt sources Five sleep modes: idle, ADC noise reduction, power-save, power-down, and standby I/O Operating voltage Speed grade Low power consumption 23 programmable I/O lines 2.7V to 5.5V 0 to 8MHz at 2.7V to 5.5V, 0 to 16MHz at 4.5V to 5.5V Active mode: 4MHz, 3.0V: 1.8mA Power-down mode: 5A at 3.0V ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 27 5.2 Overview The Atmel(R) ATA6612C/ATA6613C uses a low-power CMOS 8-bit microcontroller based on the Atmel AVR(R) enhanced RISC architecture. By executing powerful instructions in a single clock cycle, the Atmel ATA6612C/ATA6613C achieves throughputs approaching 1MIPS per MHz allowing the system designer to optimize power consumption versus processing speed. 5.2.1 Block Diagram Figure 5-1. Block Diagram GND Watchdog Timer Watchdog Oscillator Oscillator Circuits/ Clock Generation VCC Power Supervision POR/BOD and RESET debugWIRE Flash SRAM Program Logic AVR CPU EEPROM AVCC AREF DATA BUS GND 8-bit T/C 0 16-bit T/C 1 A/D Converter 8-bit T/C 2 Analog Compensation Internal Bandgap USART 0 SPI TWI PORT D (8) PORT B (8) PORT C (7) 2 6 RESET XTAL[1..2] PD[0..7] 28 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 PB[0..7] PC[0..6] ADC[6..7] The Atmel(R) AVR(R) 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 Atmel ATA6612C/ATA6613C provides the following features: 8K/16K bytes of in-system programmable flash with read-while-write capabilities, 512 bytes EEPROM, 1Kbyte SRAM, 23 general purpose I/O lines, 32 general purpose working registers, three flexible Timer/Counters with compare modes, internal and external interrupts, a serial programmable USART, a byte-oriented 2-wire serial interface, an SPI serial port, a 6-channel 10-bit ADC (8 channels in TQFP and QFN packages), a programmable watchdog timer with internal oscillator, and five software selectable power saving modes. The idle mode stops the CPU while allowing the SRAM, Timer/Counters, USART, 2-wire serial interface, SPI port, and interrupt system to continue functioning. The power-down mode saves the register contents but freezes the oscillator, disabling all other chip functions until the next interrupt or hardware reset. In power-save mode, the asynchronous timer continues to run, allowing the user to maintain a timer base while the rest of the device is sleeping. The ADC noise reduction mode stops the CPU and all I/O modules except asynchronous timer and ADC, to minimize switching noise during ADC conversions. In standby mode, the crystal/resonator oscillator is running while the rest of the device is sleeping. This allows very fast start-up combined with low power consumption. The device is manufactured using Atmel's high density non-volatile memory technology. The on-chip ISP flash allows the program memory to be reprogrammed in-system through an SPI serial interface, by a conventional non-volatile memory programmer, or by an on-chip boot program running on the Atmel AVR core. The boot program can use any interface to download the application program in the Application Flash memory. Software in the Boot Flash section will continue to run while the application flash section is updated, providing true read-while-write operation. By combining an 8-bit RISC CPU with in-system self-programmable flash on a monolithic chip, the Atmel ATA6612C/ATA6613C uses a powerful microcontroller that provides a highly flexible and cost effective solution to many embedded control applications. The Atmel ATA6612C/ATA6613C Atmel AVR is supported with a full suite of program and system development tools including: C compilers, macro assemblers, program debugger/simulators, in-circuit emulator, and evaluation kits. 5.2.2 Automotive Quality Grade The Atmel ATA6612C and Atmel ATA6613C have been developed and manufactured according to the most stringent requirements of the international standard ISO-TS-16949 grade 1. This data sheet contains limit values extracted from the results of extensive characterization (temperature and voltage). The quality and reliability of the ATA6612C and ATA6613C have been verified during regular product qualification as per AEC-Q100. 5.2.3 Comparison Between Atmel ATA6612C/ATA6613C The Atmel ATA6612C and ATA6613C differ only in memory sizes, boot loader support, and interrupt vector sizes. Table 5-1 summarizes the different memory and interrupt vector sizes for the two devices. Table 5-1. Memory Size Summary Device Flash EEPROM RAM Interrupt Vector Size ATA6612C 8Kbytes 512Bytes 1Kbyte 1 instruction word/vector ATA6613C 16Kbytes 512Bytes 1Kbyte 2 instruction words/vector Atmel ATA6612C and ATA6613C support a real read-while-write self-programming mechanism. There is a separate boot loader section, and the SPM instruction can only execute from there. 5.2.4 Pin Descriptions 5.2.4.1 VCC Digital supply voltage. 5.2.4.2 GND Ground. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 29 5.2.4.3 Port B (PB7:0) XTAL1/XTAL2/TOSC1/TOSC2 Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The port B output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port B pins that are externally pulled low will source current if the pull-up resistors are activated. The port B pins are tri-stated when a reset condition becomes active, even if the clock is not running. Depending on the clock selection fuse settings, PB6 can be used as input to the inverting oscillator amplifier. Depending on the clock selection fuse settings, PB7 can be used as input to the inverting oscillator amplifier. If the internal calibrated RC oscillator is used as chip clock source, PB7..6 is used as TOSC2..1 input for the asynchronous Timer/Counter2 if the AS2 bit in ASSR is set. The various special features of port B are elaborated in Section 5.10.3.2 "Alternate Functions of Port B" on page 84 and Section 5.6 "System Clock and Clock Options" on page 46. 5.2.4.4 Port C (PC5:0) Port C is a 7-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The PC5..0 output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, port C pins that are externally pulled low will source current if the pull-up resistors are activated. The port C pins are tri-stated when a reset condition becomes active, even if the clock is not running. 5.2.4.5 PC6/RESET If the RSTDISBL fuse is unprogrammed, PC6 is used as a reset input. A low level on this pin for longer than the minimum pulse length will generate a reset, even if the clock is not running. The minimum pulse length is given in Table 5-3 on page 43. Shorter pulses are not guaranteed to generate a reset. The various special features of port C are elaborated in Section 5.10.3.3 "Alternate Functions of Port C" on page 87. 5.2.4.6 Port D (PD7:0) Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port D output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port D pins that are externally pulled low will source current if the pull-up resistors are activated. The port D pins are tri-stated when a reset condition becomes active, even if the clock is not running. The various special features of Port D are elaborated in Section 5.10.3.4 "Alternate Functions of Port D" on page 89. 5.2.4.7 AVCC AVCC is the supply voltage pin for the A/D converter, PC3:0, and ADC7:6. I should be externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCC through a low-pass filter. Note that PC6..4 use digital supply voltage, VCC. 5.2.4.8 AREF AREF is the analog reference pin for the A/D converter. 5.2.4.9 ADC7:6 (TQFP and QFN Package Only) In the TQFP and QFN package, ADC7:6 serve as analog inputs to the A/D converter. These pins are powered from the analog supply and serve as 10-bit ADC channels. 30 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 5.3 About Code Examples This documentation contains simple code examples that briefly show how to use various parts of the device. These code examples assume that the part specific header file is included before compilation. Be aware that not all C compiler vendors include bit definitions in the header file and interrupt handling in C is compiler dependent. Please confirm with the C compiler documentation for more details. 5.4 AVR CPU Core 5.4.1 Introduction This section discusses the Atmel AVR(R) core architecture in general. The main function of the CPU core is to ensure correct program execution. The CPU must therefore be able to access memories, perform calculations, control peripherals, and handle interrupts. Architectural Overview Figure 5-2. Block Diagram of the Atmel AVR Architecture Data Bus 8 Bit Flash Program Memory Program Counter Status and Control 32 x 8 General Purpose Registers Instruction Decoder Control Lines Indirect Addressing Instruction Register Direct Addressing 5.4.2 ALU Interrupt Unit SPI Unit Watchdog Timer Analog Comparator I/O Module 1 Data SRAM I/O Module 2 I/O Module n EEPROM I/O Lines ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 31 In order to maximize performance and parallelism, the Atmel AVR(R) uses a harvard architecture - with separate memories and buses for program and data. Instructions in the program memory are executed with a single level pipelining. While one instruction is being executed, the next instruction is pre-fetched from the program memory. This concept enables instructions to be executed in every clock cycle. The program memory is in-system reprogrammable flash memory. The fast-access register file contains 32 x 8-bit general purpose working registers with a single clock cycle access time. This allows single-cycle arithmetic logic unit (ALU) operation. In a typical ALU operation, two operands are output from the register file, the operation is executed, and the result is stored back in the register file - in one clock cycle. Six of the 32 registers can be used as three 16-bit indirect address register pointers for data space addressing - enabling efficient address calculations. One of the these address pointers can also be used as an address pointer for look up tables in flash program memory. These added function registers are the 16-bit X-, Y-, and Z-register, described later in this section. The ALU supports arithmetic and logic operations between registers or between a constant and a register. Single register operations can also be executed in the ALU. After an arithmetic operation, the status register is updated to reflect information about the result of the operation. Program flow is provided by conditional and unconditional jump and call instructions, able to directly address the whole address space. Most AVR instructions have a single 16-bit word format. Every program memory address contains a 16- or 32-bit instruction. Program flash memory space is divided in two sections, the boot program section and the application program section. Both sections have dedicated lock bits for write and read/write protection. The SPM instruction that writes into the application flash memory section must reside in the boot program section. During interrupts and subroutine calls, the return address program counter (PC) is stored on the stack. The stack is effectively allocated in the general data SRAM, and consequently the stack size is only limited by the total SRAM size and the usage of the SRAM. All user programs must initialize the SP in the reset routine (before subroutines or interrupts are executed). The stack pointer (SP) is read/write accessible in the I/O space. The data SRAM can easily be accessed through the five different addressing modes supported in the AVR architecture. The memory spaces in the AVR architecture are all linear and regular memory maps. A flexible interrupt module has its control registers in the I/O space with an additional global interrupt enable bit in the status register. All interrupts have a separate interrupt vector in the interrupt vector table. The interrupts have priority in accordance with their interrupt vector position. The lower the interrupt vector address, the higher the priority. The I/O memory space contains 64 addresses for CPU peripheral functions as control registers, SPI, and other I/O functions. The I/O memory can be accessed directly, or as the data space locations following those of the register file, 0x20 - 0x5F. In addition, the Atmel(R) ATA6612C/ATA6613C has extended I/O space from 0x60 - 0xFF in SRAM where only the ST/STS/STD and LD/LDS/LDD instructions can be used. 5.4.3 ALU - Arithmetic Logic Unit The high-performance AVR ALU operates in direct connection with all the 32 general purpose working registers. Within a single clock cycle, arithmetic operations between general purpose registers or between a register and an immediate are executed. The ALU operations are divided into three main categories - arithmetic, logical, and bit-functions. Some implementations of the architecture also provide a powerful multiplier supporting both signed/unsigned multiplication and fractional format. See the "instruction set" section for a detailed description. 32 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 5.4.4 Status Register The status register contains information about the result of the most recently executed arithmetic instruction. This information can be used for altering program flow in order to perform conditional operations. Note that the status register is updated after all ALU operations, as specified in the instruction set reference. This will in many cases remove the need for using the dedicated compare instructions, resulting in faster and more compact code. The status register is not automatically stored when entering an interrupt routine and restored when returning from an interrupt. This must be handled by software. The AVR(R) status register - SREG - is defined as: Bit 7 6 5 4 3 2 1 0 I T H S V N Z C Read/Write R/W R/W R/W R/W R/W R/W R/W R/W Initial Value 0 0 0 0 0 0 0 0 SREG * Bit 7 - I: Global Interrupt Enable The global interrupt enable bit must be set for the interrupts to be enabled. The individual interrupt enable control is then performed in separate control registers. If the global interrupt enable register is cleared, none of the interrupts are enabled independent of the individual interrupt enable settings. The I-bit is cleared by hardware after an interrupt has occurred, and is set by the RETI instruction to enable subsequent interrupts. The I-bit can also be set and cleared by the application with the SEI and CLI instructions, as described in the instruction set reference. * Bit 6 - T: Bit Copy Storage The bit copy instructions BLD (Bit LoaD) and BST (Bit STore) use the T-bit as source or destination for the operated bit. A bit from a register in the register file can be copied into T by the BST instruction, and a bit in T can be copied into a bit in a register in the register file by the BLD instruction. * Bit 5 - H: Half Carry Flag The half carry flag H indicates a half carry in some arithmetic operations. Half carry is useful in BCD arithmetic. See the "Instruction Set Description" for detailed information. * Bit 4 - S: Sign Bit, S = N V The S-bit is always an exclusive or between the negative flag N and the two's complement overflow flag V. See the "Instruction Set Description" for detailed information. * Bit 3 - V: Two's Complement Overflow Flag The two's complement overflow flag V supports two's complement arithmetics. See the "Instruction Set Description" for detailed information. * Bit 2 - N: Negative Flag The negative flag N indicates a negative result in an arithmetic or logic operation. See the "Instruction Set Description" for detailed information. * Bit 1 - Z: Zero Flag The zero flag Z indicates a zero result in an arithmetic or logic operation. See the "Instruction Set Description" for detailed information. * Bit 0 - C: Carry Flag The carry flag C indicates a carry in an arithmetic or logic operation. See the "Instruction Set Description" for detailed information. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 33 5.4.5 General Purpose Register File The register file is optimized for the AVR(R) enhanced RISC instruction set. In order to achieve the required performance and flexibility, the following input/output schemes are supported by the register file: One 8-bit output operand and one 8-bit result input Two 8-bit output operands and one 8-bit result input Two 8-bit output operands and one 16-bit result input One 16-bit output operand and one 16-bit result input Figure 5-3 shows the structure of the 32 general purpose working registers in the CPU. Figure 5-3. AVR CPU General Purpose Working Registers 7 0 Address R0 0x00 R1 0x01 R2 0x02 ... General Purpose Working Registers R13 0x0D R14 0x0E R15 0x0F R16 0x10 R17 0x11 ... R26 0x1A X-register Low Byte R27 0x1B X-register High Byte R28 0x1C Y-register Low Byte R29 0x1D Y-register High Byte R30 0x1E Z-register Low Byte R31 0x1F Z-register High Byte Most of the instructions operating on the register file have direct access to all registers, and most of them are single cycle instructions. As shown in Figure 5-3, each register is also assigned a data memory address, mapping them directly into the first 32 locations of the user data space. Although not being physically implemented as SRAM locations, this memory organization provides great flexibility in access of the registers, as the X-, Y- and Z-pointer registers can be set to index any register in the file. 34 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 5.4.5.1 The X-register, Y-register, and Z-register The registers R26..R31 have some added functions to their general purpose usage. These registers are 16-bit address pointers for indirect addressing of the data space. The three indirect address registers X, Y, and Z are defined as described in Figure 5-4. Figure 5-4. The X-, Y-, and Z-registers 15 XH XL 0 7 0 7 0 X-register R27 (0x1B) R26 (0x1A) 15 YH YL 0 7 0 7 0 Y-register R29 (0x1D) R28 (0x1C) 15 ZH ZL 0 7 0 7 0 Z-register R31 (0x1F) R30 (0x1E) In the different addressing modes these address registers have functions as fixed displacement, automatic increment, and automatic decrement (see the instruction set reference for details). 5.4.6 Stack Pointer The stack is mainly used for storing temporary data, for storing local variables and for storing return addresses after interrupts and subroutine calls. The stack pointer register always points to the top of the stack. Note that the stack is implemented as growing from higher memory locations to lower memory locations. This implies that a stack PUSH command decreases the stack pointer. The stack pointer points to the data SRAM Stack area where the subroutine and interrupt stacks are located. This stack space in the data SRAM must be defined by the program before any subroutine calls are executed or interrupts are enabled. The stack pointer must be set to point above 0x0100, preferably RAMEND. The stack pointer is decremented by one when data is pushed onto the stack with the PUSH instruction, and it is decremented by two when the return address is pushed onto the stack with subroutine call or interrupt. The stack pointer is incremented by one when data is popped from the stack with the POP instruction, and it is incremented by two when data is popped from the stack with return from subroutine RET or return from interrupt RETI. The AVR(R) stack pointer is implemented as two 8-bit registers in the I/O space. The number of bits actually used is implementation dependent. Note that the data space in some implementations of the AVR architecture is so small that only SPL is needed. In this case, the SPH register will not be present. Bit Read/Write 15 14 13 12 11 10 9 8 SP15 SP14 SP13 SP12 SP11 SP10 SP9 SP8 SPH SP7 SP6 SP5 SP4 SP3 SP2 SP1 SP0 SPL 7 6 5 4 3 2 1 0 R/W R/W R/W R/W R/W R/W R/W R/W R/W R/W R/W R/W R/W R/W R/W R/W Initial Value RAMEND RAMEND RAMEND RAMEND RAMEND RAMEND RAMEND RAMEND RAMEND RAMEND RAMEND RAMEND RAMEND RAMEND RAMEND RAMEND ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 35 5.4.7 Instruction Execution Timing This section describes the general access timing concepts for instruction execution. The AVR(R) CPU is driven by the CPU clock clkCPU, directly generated from the selected clock source for the chip. No internal clock division is used. Figure 5-5 shows the parallel instruction fetches and instruction executions enabled by the harvard architecture and the fast-access register file concept. This is the basic pipelining concept to obtain up to 1MIPS per MHz with the corresponding unique results for functions per cost, functions per clocks, and functions per power-unit. Figure 5-5. The Parallel Instruction Fetches and Instruction Executions T1 T2 T3 T4 clkCPU 1st Instruction Fetch 1st Instruction Execute 2nd Instruction Fetch 2nd Instruction Execute 3rd Instruction Fetch 3rd Instruction Execute 4th Instruction Fetch Figure 5-6 shows the internal timing concept for the register file. In a single clock cycle an ALU operation using two register operands is executed, and the result is stored back to the destination register. Figure 5-6. Single Cycle ALU Operation T1 T2 T3 T4 clkCPU Total Execution Time Register Operands Fetch ALU Operation Execute Result Write Back 5.4.8 Reset and Interrupt Handling The AVR provides several different interrupt sources. These interrupts and the separate reset vector each have a separate program vector in the program memory space. All interrupts are assigned individual enable bits which must be written logic one together with the global interrupt enable bit in the status register in order to enable the interrupt. Depending on the program counter value, interrupts may be automatically disabled when boot lock bits BLB02 or BLB12 are programmed. This feature improves software security. See Section 5.24 "Memory Programming" on page 253 for details. The lowest addresses in the program memory space are by default defined as the reset and Interrupt vectors. The complete list of vectors is shown in Section 5.9 "Interrupts" on page 70. The list also determines the priority levels of the different interrupts. The lower the address the higher is the priority level. RESET has the highest priority, and next is INT0 - the external interrupt request 0. The interrupt vectors can be moved to the start of the boot flash section by setting the IVSEL bit in the MCU control register (MCUCR). Refer to Section 5.9 "Interrupts" on page 70 for more information. The reset vector can also be moved to the start of the boot flash section by programming the BOOTRST fuse (see Section 5.23 "Boot Loader Support - Read-While-Write Self-Programming, Atmel ATA6612C and ATA6613C" on page 240). When an interrupt occurs, the global interrupt enable I-bit is cleared and all interrupts are disabled. The user software can write logic one to the I-bit to enable nested interrupts. All enabled interrupts can then interrupt the current interrupt routine. The I-bit is automatically set when a return from interrupt instruction - RETI - is executed. 36 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 There are basically two types of interrupts. The first type is triggered by an event that sets the interrupt flag. For these interrupts, the program counter is vectored to the actual interrupt vector in order to execute the interrupt handling routine, and hardware clears the corresponding interrupt flag. Interrupt flags can also be cleared by writing a logic one to the flag bit position(s) to be cleared. If an interrupt condition occurs while the corresponding interrupt enable bit is cleared, the interrupt flag will be set and remembered until the interrupt is enabled, or the flag is cleared by software. Similarly, if one or more interrupt conditions occur while the global interrupt enable bit is cleared, the corresponding interrupt flag(s) will be set and remembered until the global interrupt enable bit is set, and will then be executed by order of priority. The second type of interrupts will trigger as long as the interrupt condition is present. These interrupts do not necessarily have interrupt flags. If the interrupt condition disappears before the interrupt is enabled, the interrupt will not be triggered. When the AVR(R) exits from an interrupt, it will always return to the main program and execute one more instruction before any pending interrupt is served. Note that the status register is not automatically stored when entering an interrupt routine, nor restored when returning from an interrupt routine. This must be handled by software. When using the CLI instruction to disable interrupts, the interrupts will be immediately disabled. No interrupt will be executed after the CLI instruction, even if it occurs simultaneously with the CLI instruction. The following example shows how this can be used to avoid interrupts during the timed EEPROM write sequence. Assembly Code Example in r16, SREG ; store SREG value cli ; disable interrupts during timed sequence sbi EECR, EEMPE ; start EEPROM write sbi EECR, EEPE out SREG, r16 ; restore SREG value (I-bit) C Code Example char cSREG; cSREG = SREG; /* store SREG value */ /* disable interrupts during timed sequence */ _CLI(); EECR |= (1< xxx ... ... ... ... ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 71 When the BOOTRST Fuse is unprogrammed, the boot section size set to 2Kbytes and the IVSEL bit in the MCUCR register is set before any interrupts are enabled, the most typical and general program setup for the reset and interrupt vector addresses in Atmel(R) ATA6612C is: Address Labels Code Comments 0x000 RESET: ldi r16,high(RAMEND); Main program start 0x001 out SPH,r16 ; Set Stack Pointer to top of RAM 0x002 ldi r16,low(RAMEND) 0x003 out SPL,r16 0x004 sei ; Enable interrupts 0x005 xxx ; .org 0xC01 0xC01 rjmp EXT_INT0 ; IRQ0 Handler 0xC02 rjmp EXT_INT1 ; IRQ1 Handler ... ... ... ; 0xC19 rjmp SPM_RDY ; Store Program Memory Ready Handler When the BOOTRST fuse is programmed and the boot section size set to 2Kbytes, the most typical and general program setup for the reset and Interrupt vector Aadresses in Atmel ATA6612C is: Address Labels Code Comments .org 0x001 0x001 rjmp EXT_INT0 ; IRQ0 Handler 0x002 rjmp EXT_INT1 ; IRQ1 Handler ... ... ... ; 0x019 rjmp SPM_RDY ; Store Program Memory Ready Handler ; .org 0xC00 0xC00 RESET: ldi r16,high(RAMEND); Main program start 0xC01 out SPH,r16; Set Stack Pointer to top of RAM 0xC02 ldi r16,low(RAMEND) 0xC03 out SPL,r16 0xC04 sei ; Enable interrupts 0xC05 xxx When the BOOTRST fuse is programmed, the boot section size set to 2Kbytes and the IVSEL bit in the MCUCR register is set before any interrupts are enabled, the most typical and general program setup for the reset and interrupt vector addresses in Atmel ATA6612C is: Address ; .org 0xC00 0xC00 0xC01 0xC02 ... 0xC19 ; 0xC1A 0xC1B 0xC1C 0xC1D 0xC1E 0xC1F 72 Labels Code rjmp rjmp rjmp ... rjmp ... RESET; Reset handler EXT_INT0; IRQ0 Handler EXT_INT1; IRQ1 Handler ; SPM_RDY; Store Program Memory Ready Handler RESET: ldi r16,high(RAMEND); Main program start out SPH,r16 ; Set Stack Pointer to top of RAM ldi r16,low(RAMEND) out SPL,r16 sei ; Enable interrupts xxx ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 Comments 5.9.2 Interrupt Vectors in ATA6613C Table 5-28. Reset and Interrupt Vectors in ATA6613C Vector No. Program Address(2) Source Interrupt Definition 1 0x0000(1) RESET External pin, power-on reset, brown-out reset and watchdog system reset 2 0x0002 INT0 External interrupt request 0 3 0x0004 INT1 External interrupt request 1 4 0x0006 PCINT0 Pin change interrupt request 0 5 0x0008 PCINT1 Pin change interrupt request 1 6 0x000A PCINT2 Pin change interrupt request 2 7 0x000C WDT Watchdog time-out interrupt 8 0x000E TIMER2 COMPA Timer/Counter2 compare match A 9 0x0010 TIMER2 COMPB Timer/Counter2 compare match B 10 0x0012 TIMER2 OVF Timer/Counter2 overflow 11 0x0014 TIMER1 CAPT Timer/Counter1 capture event 12 0x0016 TIMER1 COMPA Timer/Counter1 compare match A 13 0x0018 TIMER1 COMPB Timer/coutner1 compare match B 14 0x001A TIMER1 OVF Timer/Counter1 overflow 15 0x001C TIMER0 COMPA Timer/Counter0 compare match A 16 0x001E TIMER0 COMPB Timer/Counter0 compare match B 17 0x0020 TIMER0 OVF Timer/Counter0 overflow 18 0x0022 SPI, STC SPI serial transfer complete 19 0x0024 USART, RX USART Rx complete 20 0x0026 USART, UDRE USART, data register empty 21 0x0028 USART, TX USART, Tx complete 22 0x002A ADC ADC conversion complete 23 0x002C EE READY EEPROM ready 24 0x002E ANALOG COMP Analog comparator 25 0x0030 TWI 2-wire serial interface 26 Notes: 1. 0x0032 SPM READY Store program memory ready When the BOOTRST Fuse is programmed, the device will jump to the boot loader address at reset (see Section 5.23 "Boot Loader Support - Read-While-Write Self-Programming, Atmel ATA6612C and ATA6613C" on page 240). 2. When the IVSEL bit in MCUCR is set, interrupt vectors will be moved to the start of the boot flash section. The address of each interrupt vector will then be the address in this table added to the start address of the boot flash section. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 73 Table 5-29 shows reset and interrupt vectors placement for the various combinations of 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 is in the application section while the interrupt vectors are in the boot section or vice versa. Table 5-29. Reset and Interrupt Vectors Placement in ATA6613C(1) BOOTRST IVSEL Reset Address Interrupt Vectors Start Address 1 0 0x000 0x001 1 1 0x000 Boot reset address + 0x0002 0 0 Boot reset address 0x001 Note: 0 1. 1 Boot reset address Boot reset address + 0x0002 The Boot Reset Address is shown in Table 5-108 on page 251. For the BOOTRST fuse "1" means unprogrammed while "0" means programmed. The most typical and general program setup for the reset and interrupt vector addresses in ATA6613C is: Address Labels Code Comments 0x0000 rjmp RESET ; Reset Handler 0x0002 rjmp EXT_INT0 ; IRQ0 Handler 0x0004 rjmp EXT_INT1 ; IRQ1 Handler 0x0006 rjmp PCINT0 ; PCINT0 Handler 0x0008 rjmp PCINT1 ; PCINT1 Handler 0x000A rjmp PCINT2 ; PCINT2 Handler 0x000C rjmp WDT ; Watchdog Timer Handler 0x000E rjmp TIM2_COMPA ; Timer2 Compare A Handler 0x0010 rjmp TIM2_COMPB ; Timer2 Compare B Handler 0x0012 rjmp TIM2_OVF ; Timer2 Overflow Handler 0x0014 rjmp TIM1_CAPT ; Timer1 Capture Handler 0x0016 rjmp TIM1_COMPA ; Timer1 Compare A Handler 0x0018 rjmp TIM1_COMPB ; Timer1 Compare B Handler 0x001A rjmp TIM1_OVF ; Timer1 Overflow Handler 0x001C rjmp TIM0_COMPA ; Timer0 Compare A Handler 0x001E rjmp TIM0_COMPB ; Timer0 Compare B Handler 0x0020 rjmp TIM0_OVF ; Timer0 Overflow Handler 0x0022 rjmp SPI_STC ; SPI Transfer Complete Handler 0x0024 rjmp USART_RXC ; USART, RX Complete Handler 0x0026 rjmp USART_UDRE ; USART, UDR Empty Handler 0x0028 rjmp USART_TXC ; USART, TX Complete Handler 0x002A rjmp ADC ; ADC Conversion Complete Handler 0x002C rjmp EE_RDY ; EEPROM Ready Handler 0x002E rjmp ANA_COMP ; Analog Comparator Handler 0x0030 rjmp TWI ; 2-wire Serial Interface Handler 0x0032 rjmp SPM_RDY ; Store Program Memory Ready Handler ; 0x0033 RESET: ldi r16, high(RAMEND); Main program start 0x0034 out SPH,r16 ; Set Stack Pointer to top of RAM 0x0035 ldi r16, low(RAMEND) 0x0036 out SPL,r16 0x0037 sei ; Enable interrupts 0x0038 xxx ... ... ... ... 74 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 When the BOOTRST Fuse is unprogrammed, the boot section size set to 2K bytes and the IVSEL bit in the MCUCR register is set before any interrupts are enabled, the most typical and general program setup for the reset and interrupt vector addresses in ATA6613C is: Address Labels Code Comments 0x0000 RESET: ldi r16,high(RAMEND); Main program start 0x0001 out SPH,r16 ; Set Stack Pointer to top of RAM 0x0002 ldi r16,low(RAMEND) 0x0003 out SPL,r16 0x0004 sei ; Enable interrupts 0x0005 xxx ; .org 0xC02 0x1C02 rjmp EXT_INT0 ; IRQ0 Handler 0x1C04 rjmp EXT_INT1 ; IRQ1 Handler ... ... ... ; 0x1C32 rjmp SPM_RDY ; Store Program Memory Ready Handler When the BOOTRST fuse is programmed and the boot section size set to 2Kbytes, the most typical and general program setup for the reset and interrupt vector addresses in ATA6613C is: Address Labels Code Comments .org 0x0002 0x0002 rjmp EXT_INT0 ; IRQ0 Handler 0x0004 rjmp EXT_INT1 ; IRQ1 Handler ... ... ... ; 0x0032 rjmp SPM_RDY ; Store Program Memory Ready Handler ; .org 0x1C00 0x1C00 RESET: ldi r16,high(RAMEND); Main program start 0x1C01 out SPH,r16 ; Set Stack Pointer to top of RAM 0x1C02 ldi r16,low(RAMEND) 0x1C03 out SPL,r16 0x1C04 sei ; Enable interrupts 0x1C05 xxx When the BOOTRST fuse is programmed, the boot section size set to 2Kbytes and the IVSEL bit in the MCUCR register is set before any interrupts are enabled, the most typical and general program setup for the reset and interrupt vector addresses in ATA6613C is: Address Labels Code Comments ; .org 0x1C00 0x1C00 rjmp RESET ; Reset handler 0x1C02 rjmp EXT_INT0 ; IRQ0 Handler 0x1C04 rjmp EXT_INT1 ; IRQ1 Handler ... ... ... ; 0x1C32 rjmp SPM_RDY ; Store Program Memory Ready Handler ; 0x1C33 RESET: ldi r16,high(RAMEND); Main program start 0x1C34 out SPH,r16 ; Set Stack Pointer to top of RAM 0x1C35 ldi r16,low(RAMEND) 0x1C36 out SPL,r16 0x1C37 sei ; Enable interrupts 0x1C38 xxx ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 75 5.9.2.1 Moving Interrupts Between Application and Boot Space, Atmel ATA6612C and ATA6613C The MCU control register controls the placement of the interrupt vector table. 5.9.2.2 MCU Control Register - MCUCR Bit 7 6 5 4 3 2 1 0 - - - PUD - - IVSEL IVCE Read/Write R R R R/W R R R/W R/W Initial Value 0 0 0 0 0 0 0 0 MCUCR * Bit 1 - IVSEL: Interrupt Vector Select When the IVSEL bit is cleared (zero), the interrupt vectors are placed at the start of the flash memory. When this bit is set (one), the interrupt vectors are moved to the beginning of the boot loader section of the flash. The actual address of the start of the boot flash section is determined by the BOOTSZ fuses. Refer to section Section 5.23 "Boot Loader Support - ReadWhile-Write Self-Programming, Atmel ATA6612C and ATA6613C" on page 240 for details. To avoid unintentional changes of interrupt vector tables, a special write procedure must be followed to change the IVSEL bit: a. Write the interrupt vector change enable (IVCE) bit to one. b. Within four cycles, write the desired value to IVSEL while writing a zero to IVCE. Interrupts will automatically be disabled while this sequence is executed. Interrupts are disabled in the cycle IVCE is set, and they remain disabled until after the instruction following the write to IVSEL. If IVSEL is not written, interrupts remain disabled for four cycles. The I-bit in the status register is unaffected by the automatic disabling. Note: If interrupt vectors are placed in the boot loader section and boot lock bit BLB02 is programmed, interrupts are disabled while executing from the application section. If interrupt vectors are placed in the application section and boot lock bit BLB12 is programed, interrupts are disabled while executing from the boot loader section. Refer to Section 5.23 "Boot Loader Support - Read-While-Write Self-Programming, Atmel ATA6612C and ATA6613C" on page 240 for details on boot lock bits. * Bit 0 - IVCE: Interrupt Vector Change Enable The IVCE bit must be written to logic one to enable change of the IVSEL bit. IVCE is cleared by hardware four cycles after it is written or when IVSEL is written. Setting the IVCE bit will disable interrupts, as explained in the IVSEL description above. See code example below. Assembly Code Example Move_interrupts: ; Enable change of Interrupt Vectors ldi r16, (1< CSn2:0 > 1). The number of system clock cycles from when the timer is enabled to the first count occurs can be from 1 to N+1 system clock cycles, where N equals the prescaler divisor (8, 64, 256, or 1024). It is possible to use the prescaler reset for synchronizing the Timer/Counter to program execution. However, care must be taken if the other Timer/Counter that shares the same prescaler also uses prescaling. A prescaler reset will affect the prescaler period for all Timer/Counters it is connected to. 5.13.3 External Clock Source An external clock source applied to the T1/T0 pin can be used as Timer/Counter clock (clkT1/clkT0). The T1/T0 pin is sampled once every system clock cycle by the pin synchronization logic. The synchronized (sampled) signal is then passed through the edge detector. Figure 5-38 shows a functional equivalent block diagram of the T1/T0 synchronization and edge detector logic. The registers are clocked at the positive edge of the internal system clock (clkI/O). The latch is transparent in the high period of the internal system clock. The edge detector generates one clkT1/clkT0 pulse for each positive (CSn2:0 = 7) or negative (CSn2:0 = 6) edge it detects. Figure 5-38. T1/T0 Pin Sampling Tn D Q D Q D Tn_sync (To Clock Select Logic) Q LE clkI/O Synchronization Edge Detector The synchronization and edge detector logic introduces a delay of 2.5 to 3.5 system clock cycles from an edge has been applied to the T1/T0 pin to the counter is updated. Enabling and disabling of the clock input must be done when T1/T0 has been stable for at least one system clock cycle, otherwise it is a risk that a false Timer/Counter clock pulse is generated. Each half period of the external clock applied must be longer than one system clock cycle to ensure correct sampling. The external clock must be guaranteed to have less than half the system clock frequency (fExtClk < fclk_I/O/2) given a 50/50% duty cycle. Since the edge detector uses sampling, the maximum frequency of an external clock it can detect is half the sampling frequency (nyquist sampling theorem). However, due to variation of the system clock frequency and duty cycle caused by oscillator source (crystal, resonator, and capacitors) tolerances, it is recommended that maximum frequency of an external clock source is less than fclk_I/O/2.5. An external clock source can not be prescaled. 112 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 Figure 5-39. Prescaler for Timer/Counter0 and Timer/Counter1(1) CK/256 CK/8 PSRSYNC Note: T0 Synchronization T1 Synchronization 1. 0 CK/1024 10-bit T/C Prescaler Clear CK/64 clkI/O 0 CS10 CS00 CS11 CS01 CS12 CS02 Timer/Counter1 Clock Source Timer/Counter0 Clock Source clkT1 clkT0 The synchronization logic on the input pins (T1/T0) is shown in Figure 5-38 on page 112. 5.13.4 General Timer/Counter Control Register - GTCCR Bit 7 6 5 4 3 2 1 0 TSM - - - - - PSRASY PSRSYNC Read/Write R/W R R R R R R/W R/W Initial Value 0 0 0 0 0 0 0 0 GTCCR * Bit 7 - TSM: Timer/Counter Synchronization Mode Writing the TSM bit to one activates the Timer/Counter synchronization mode. In this mode, the value that is written to the PSRASY and PSRSYNC bits is kept, hence keeping the corresponding prescaler reset signals asserted. This ensures that the corresponding Timer/Counters are halted and can be configured to the same value without the risk of one of them advancing during configuration. When the TSM bit is written to zero, the PSRASY and PSRSYNC bits are cleared by hardware, and the Timer/Counters start counting simultaneously. * Bit 0 - PSRSYNC: Prescaler Reset When this bit is one, Timer/Counter1 and Timer/Counter0 prescaler will be reset. This bit is normally cleared immediately by hardware, except if the TSM bit is set. Note that Timer/Counter1 and Timer/Counter0 share the same prescaler and a reset of this prescaler will affect both timers. 5.14 16-bit Timer/Counter1 with PWM The 16-bit Timer/Counter unit allows accurate program execution timing (event management), wave generation, and signal timing measurement. The main features are: 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 compare match (auto reload) Glitch-free, phase correct pulse width modulator (PWM) ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 113 Variable PWM period Frequency generator External event counter Four independent interrupt sources (TOV1, OCF1A, OCF1B, and ICF1) 5.14.1 Overview Most register and bit references in this section are written in general form. A lower case "n" replaces the Timer/Counter number, and a lower case "x" replaces the output compare unit channel. However, when using the register or bit defines in a program, the precise form must be used, i.e., TCNT1 for accessing Timer/Counter1 counter value and so on. A simplified block diagram of the 16-bit Timer/Counter is shown in Figure 5-40 on page 114. The device-specific I/O register and bit locations are listed in the Section 5.14.10 "16-bit Timer/Counter Register Description" on page 132. The PRTIM1 bit in Section 5.7.7.1 "Power Reduction Register - PRR" on page 58 must be written to zero to enable Timer/Counter1 module. Figure 5-40. 16-bit Timer/Counter Block Diagram(1) TOVn (Int. Req.) Count Clear Direction Clock Select Control Logic clkTn TOP BOTTOM = = Edge Detector Tn (from Prescaler) Timer/Counter TCNTn 0 OCnA (Int. Req.) Waveform Generation = OCnA OCRnA DATA BUS Fixed TOP Value OCnB (Int. Req.) Waveform Generation = OCnB (From Analog Comparator Output) OCRnB ICFn (Int. Req.) Edge Detector ICRn TCCRnA Note: 114 1. Noise Canceler ICPn TCCRnB Refer to Table 5-32 on page 84 and Table 5-38 on page 89 for Timer/Counter1 pin placement and description. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 5.14.1.1 Registers The Timer/Counter (TCNT1), output compare registers (OCR1A/B), and input capture register (ICR1) are all 16-bit registers. Special procedures must be followed when accessing the 16-bit registers. These procedures are described in the Section 5.14.2 "Accessing 16-bit Registers" on page 115. The Timer/Counter control registers (TCCR1A/B) are 8-bit registers and have no CPU access restrictions. Interrupt requests (abbreviated to Int.Req. in the figure) signals are all visible in the timer interrupt flag register (TIFR1). All interrupts are individually masked with the timer interrupt mask register (TIMSK1). TIFR1 and TIMSK1 are not shown in the figure. The Timer/Counter can be clocked internally, via the prescaler, or by an external clock source on the T1 pin. The clock select logic block controls which clock source and edge the Timer/Counter uses to increment (or decrement) its value. The Timer/Counter is inactive when no clock source is selected. The output from the clock select logic is referred to as the timer clock (clkT1). The double buffered output compare registers (OCR1A/B) are compared with the Timer/Counter value at all time. The result of the compare can be used by the waveform generator to generate a PWM or variable frequency output on the output compare pin (OC1A/B), see Section 5.14.6 "Output Compare Units" on page 121. The compare match event will also set the compare 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 triggered) event on either the input capture pin (ICP1) or on the analog comparator pins (see Section 5.20 "Analog Comparator" on page 221). The input capture unit includes a digital filtering unit (noise canceler) for reducing the chance of capturing noise spikes. The TOP value, or maximum Timer/Counter value, can in some modes of operation be defined by either the OCR1A register, the ICR1 register, or by a set of fixed values. When using OCR1A as TOP value in a PWM mode, the OCR1A register can not be used for generating a PWM output. However, the TOP value will in this case be double buffered allowing the TOP value to be changed in run time. If a fixed TOP value is required, the ICR1 register can be used as an alternative, freeing the OCR1A to be used as PWM output. 5.14.1.2 Definitions The following definitions are used extensively throughout the section: Table 5-52. General Counter Definitions Parameter Definition BOTTOM The counter reaches the BOTTOM when it becomes 0x0000. MAX The counter reaches its MAXimum when it becomes 0xFFFF (decimal 65535). TOP The counter reaches the TOP when it becomes equal to the highest value in the count sequence. The TOP value can be assigned to be one of the fixed values: 0x00FF, 0x01FF, or 0x03FF, or to the value stored in the OCR1A or ICR1 register. The assignment is dependent of the mode of operation. 5.14.2 Accessing 16-bit Registers The TCNT1, OCR1A/B, and ICR1 are 16-bit registers that can be accessed by the AVR(R) CPU via the 8-bit data bus. The 16-bit register must be byte accessed using two read or write operations. Each 16-bit timer has a single 8-bit register for temporary storing of the high byte of the 16-bit access. The same temporary register is shared between all 16-bit registers within each 16-bit timer. Accessing the low byte triggers the 16-bit read or write operation. When the low byte of a 16-bit register is written by the CPU, the high byte stored in the temporary register, and the low byte written are both copied into the 16-bit register in the same clock cycle. When the low byte of a 16-bit register is read by the CPU, the high byte of the 16-bit register is copied into the temporary register in the same clock cycle as the low byte is read. Not all 16-bit accesses uses the temporary register for the high byte. Reading the OCR1A/B 16-bit registers does not involve using the temporary register. To do a 16-bit write, the high byte must be written before the low byte. For a 16-bit read, the low byte must be read before the high byte. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 115 The following code examples show how to access the 16-bit timer registers assuming that no interrupts updates the temporary register. The same principle can be used directly for accessing the OCR1A/B and ICR1 registers. Note that when using "C", the compiler handles the 16-bit access. Assembly Code Examples(1) ... ; Set TCNT1 to 0x01FF ldi r17,0x01 ldi r16,0xFF out TCNT1H,r17 out TCNT1L,r16 ; Read TCNT1 into r17:r16 in r16,TCNT1L in r17,TCNT1H ... C Code Examples(1) unsigned int i; ... /* Set TCNT1 to 0x01FF */ TCNT1 = 0x1FF; /* Read TCNT1 into i */ i = TCNT1; ... Note: 1. The example code assumes that the part specific header file is included. For I/O registers located in extended I/O map, "IN", "OUT", "SBIS", "SBIC", "CBI", and "SBI" instructions must be replaced with instructions that allow access to extended I/O. Typically "LDS" and "STS" combined with "SBRS", "SBRC", "SBR", and "CBR". The assembly code example returns the TCNT1 value in the r17:r16 register pair. It is important to notice that accessing 16-bit registers are atomic operations. If an interrupt occurs between the two instructions accessing the 16-bit register, and the interrupt code updates the temporary register by accessing the same or any other of the 16-bit timer registers, then the result of the access outside the interrupt will be corrupted. Therefore, when both the main code and the interrupt code update the temporary register, the main code must disable the interrupts during the 16-bit access. 116 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 The following code examples show how to do an atomic read of the TCNT1 register contents. Reading any of the OCR1A/B or ICR1 registers can be done by using the same principle. Assembly Code Example(1) TIM16_ReadTCNT1: ; Save global interrupt flag in r18,SREG ; Disable interrupts cli ; Read TCNT1 into r17:r16 in r16,TCNT1L in r17,TCNT1H ; Restore global interrupt flag out SREG,r18 ret C Code Example(1) unsigned int TIM16_ReadTCNT1( void ) { unsigned char sreg; unsigned int i; /* Save global interrupt flag */ sreg = SREG; /* Disable interrupts */ _CLI(); /* Read TCNT1 into i */ i = TCNT1; /* Restore global interrupt flag */ SREG = sreg; return i; } Note: 1. The example code assumes that the part specific header file is included. For I/O registers located in extended I/O map, "IN", "OUT", "SBIS", "SBIC", "CBI", and "SBI" instructions must be replaced with instructions that allow access to extended I/O. Typically "LDS" and "STS" combined with "SBRS", "SBRC", "SBR", and "CBR". The assembly code example returns the TCNT1 value in the r17:r16 register pair. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 117 The following code examples show how to do an 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(1) TIM16_WriteTCNT1: ; Save global interrupt flag in r18,SREG ; Disable interrupts cli ; Set TCNT1 to r17:r16 out TCNT1H,r17 out TCNT1L,r16 ; Restore global interrupt flag out SREG,r18 ret C Code Example(1) void TIM16_WriteTCNT1(unsigned int i) { unsigned char sreg; unsigned int i; /* Save global interrupt flag */ sreg = SREG; /* Disable interrupts */ _CLI(); /* Set TCNT1 to i */ TCNT1 = i; /* Restore global interrupt flag */ SREG = sreg; } Note: 1. The example code assumes that the part specific header file is included. For I/O registers located in extended I/O map, "IN", "OUT", "SBIS", "SBIC", "CBI", and "SBI" instructions must be replaced with instructions that allow access to extended I/O. Typically "LDS" and "STS" combined with "SBRS", "SBRC", "SBR", and "CBR". The assembly code example requires that the r17:r16 register pair contains the value to be written to TCNT1. 5.14.2.1 Reusing the Temporary High Byte Register If writing to more than one 16-bit register where the high byte is the same for all registers written, then the high byte only needs to be written once. However, note that the same rule of atomic operation described previously also applies in this case. 5.14.3 Timer/Counter Clock Sources The Timer/Counter can be clocked by an internal or an external clock source. The clock source is selected by the clock select logic which is controlled by the clock select (CS12:0) bits located in the Timer/Counter control register B (TCCR1B). For details on clock sources and prescaler (see Section 5.13 "Timer/Counter0 and Timer/Counter1 Prescalers" on page 112). 118 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 5.14.4 Counter Unit The main part of the 16-bit Timer/Counter is the programmable 16-bit bi-directional counter unit. Figure 5-41 shows a block diagram of the counter and its surroundings. Figure 5-41. Counter Unit Block Diagram DATA BUS (8-bit) TOVn (Int. Req.) TEMP (8-bit) Clock Select Count TCNTnH (8-bit) TCNTnL (8-bit) TCNTnH (16-bit Counter) Clear Control Logic clkTn Edge Detector Tn Direction (From Prescaler) TOP BOTTOM Signal description (internal signals): Count Increment or decrement TCNT1 by 1. Direction Select between increment and decrement. Clear Clear TCNT1 (set all bits to zero). clkT1 Timer/Counter clock. TOP Signalize that TCNT1 has reached maximum value. BOTTOM Signalize that TCNT1 has reached minimum value (zero). The 16-bit counter is mapped into two 8-bit I/O memory locations: Counter High (TCNT1H) containing the upper eight bits of the counter, and counter low (TCNT1L) containing the lower eight bits. The TCNT1H register can only be indirectly accessed by the CPU. When the CPU does an access to the TCNT1H I/O location, the CPU accesses the high byte temporary register (TEMP). The temporary register is updated with the TCNT1H value when the TCNT1L is read, and TCNT1H is updated with the temporary register value when TCNT1L is written. This allows the CPU to read or write the entire 16-bit counter value within one clock cycle via the 8-bit data bus. It is important to notice that there are special cases of writing to the TCNT1 register when the counter is counting that will give unpredictable results. The special cases are described in the sections where they are of importance. Depending on the mode of operation used, the counter is cleared, incremented, or decremented at each timer clock (clkT1). The clkT1 can be generated from an external or internal clock source, selected by the clock select bits (CS12:0). When no clock source is selected (CS12:0 = 0) the timer is stopped. However, the TCNT1 value can be accessed by the CPU, independent of whether clkT1 is present or not. A CPU write overrides (has priority over) all counter clear or count operations. The counting sequence is determined by the setting of the waveform generation mode bits (WGM13:0) located in the Timer/Counter control registers A and B (TCCR1A and TCCR1B). There are close connections between how the counter behaves (counts) and how waveforms are generated on the output compare outputs OC1x. For more details about advanced counting sequences and waveform generation (see Section 5.14.8 "Modes of Operation" on page 124). 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. 5.14.5 Input Capture Unit The Timer/Counter incorporates an input capture unit that can capture external events and give them a time-stamp indicating time of occurrence. The external signal indicating an event, or multiple events, can be applied via the ICP1 pin or alternatively, via the analog-comparator unit. The time-stamps can then be used to calculate frequency, duty-cycle, and other features of the signal applied. Alternatively the time-stamps can be used for creating a log of the events. The input capture unit is illustrated by the block diagram shown in Figure 5-42 on page 120. The elements of the block diagram that are not directly a part of the input capture unit are gray shaded. The small "n" in register and bit names indicates the Timer/Counter number. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 119 Figure 5-42. Input Capture Unit Block Diagram DATA BUS (8-bit) TEMP (8-bit) ICRnH (8-bit) ICRnL (8-bit) TCNTnH (8-bit) ICRn (16-bit Register) WRITE + - ACO* Analog Comparator TCNTnL (8-bit) TCNTn (16-bit Counter) ACIC* ICNCn ICESn Noise Canceler Edge Detector ICFn (Int. Req.) ICPn When a change of the logic level (an event) occurs on the input capture pin (ICP1), alternatively on the analog comparator output (ACO), and this change confirms to the setting of the edge detector, a capture will be triggered. When a capture is triggered, the 16-bit value of the counter (TCNT1) is written to the input capture register (ICR1). The input capture flag (ICF1) is set at the same system clock as the TCNT1 value is copied into ICR1 register. If enabled (ICIE1 = 1), the input capture flag generates an input capture interrupt. The ICF1 flag is automatically cleared when the interrupt is executed. Alternatively the ICF1 flag can be cleared by software by writing a logical one to its I/O bit location. Reading the 16-bit value in the input capture register (ICR1) is done by first reading the low byte (ICR1L) and then the high byte (ICR1H). When the low byte is read the high byte is copied into the high byte temporary register (TEMP). When the CPU reads the ICR1H I/O location it will access the TEMP register. The ICR1 register can only be written when using a waveform generation mode that utilizes the ICR1 register for defining the counter's TOP value. In these cases the waveform generation 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 written to ICR1L. For more information on how to access the 16-bit registers refer to Section 5.14.2 "Accessing 16-bit Registers" on page 115. 5.14.5.1 Input Capture Trigger Source The main trigger source for the input capture unit is the input capture pin (ICP1). Timer/Counter1 can alternatively use the analog comparator output as trigger source for the input capture unit. The analog comparator is selected as trigger source by setting the analog comparator input capture (ACIC) bit in the analog comparator control and status register (ACSR). Be aware that changing trigger source can trigger a capture. The input capture flag must therefore be cleared after the change. Both the input capture pin (ICP1) and the analog comparator output (ACO) inputs are sampled using the same technique as for the T1 pin (see Figure 5-38 on page 112). The edge detector is also identical. However, when the noise canceler is enabled, additional logic is inserted before the edge detector, which increases the delay by four system clock cycles. Note that the input of the noise canceler and edge detector is always enabled unless the Timer/Counter is set in a waveform generation mode that uses ICR1 to define TOP. An input capture can be triggered by software by controlling the port of the ICP1 pin. 120 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 5.14.5.2 Noise Canceler The noise canceler improves noise immunity by using a simple digital filtering scheme. The noise canceler input is monitored over four samples, and all four must be equal for changing the output that in turn is used by the edge detector. The noise canceler is enabled by setting the input capture noise canceler (ICNC1) bit in Timer/Counter control register B (TCCR1B). When enabled the noise canceler introduces additional four system clock cycles of delay from a change applied to the input, to the update of the ICR1 register. The noise canceler uses the system clock and is therefore not affected by the prescaler. 5.14.5.3 Using the Input Capture Unit The main challenge when using the input capture unit is to assign enough processor capacity for handling the incoming events. The time between two events is critical. If the processor has not read the captured value in the ICR1 register before the next event occurs, the ICR1 will be overwritten with a new value. In this case the result of the capture will be incorrect. When using the input capture interrupt, the ICR1 register should be read as early in the interrupt handler routine as possible. Even though the input capture interrupt has relatively high priority, the maximum interrupt response time is dependent on the maximum number of clock cycles it takes to handle any of the other interrupt requests. Using the input capture unit in any mode of operation when the TOP value (resolution) is actively changed during operation, is not recommended. Measurement of an external signal's duty cycle requires that the trigger edge is changed after each capture. Changing the edge sensing must be done as early as possible after the ICR1 register has been read. After a change of the edge, the input capture flag (ICF1) must be 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). 5.14.6 Output Compare Units The 16-bit comparator continuously compares TCNT1 with the output compare register (OCR1x). If TCNT equals OCR1x the comparator signals a match. A match will set the output compare flag (OCF1x) at the next timer clock cycle. If enabled (OCIE1x = 1), the output compare flag generates an output compare interrupt. The OCF1x flag is automatically cleared when the interrupt is executed. Alternatively the OCF1x flag can be cleared by software by writing a logical one to its I/O bit location. The waveform generator uses the match signal to generate an output according to operating mode set by the waveform generation mode (WGM13:0) bits and compare output mode (COM1x1:0) bits. The TOP and BOTTOM signals are used by the waveform generator for handling the special cases of the extreme values in some modes of operation (see Section 5.14.8 "Modes of Operation" on page 124). A special feature of output compare unit A allows it to define the Timer/Counter TOP value (i.e., counter resolution). In addition to the counter resolution, the TOP value defines the period time for waveforms generated by the waveform generator. Figure 5-43 on page 122 shows a block diagram of the output compare unit. The small "n" in the register and bit names indicates the device number (n = 1 for Timer/Counter 1), and the "x" indicates output compare unit (A/B). The elements of the block diagram that are not directly a part of the output compare unit are gray shaded. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 121 Figure 5-43. Output Compare Unit, Block Diagram DATA BUS (8-bit) TEMP (8-bit) OCRnxH Buf. (8-bit) OCRnxL Buf. (8-bit) TCNTnH (8-bit) OCRnx Buffer (16-bit Register) OCRnxH (8-bit) TCNTnL (8-bit) TCNTn (16-bit Counter) OCRnxL (8-bit) OCRnx (16-bit Register) = (16-bit Comparator) OCFnx (Int. Req.) TOP Waveform Generator OCnx BOTTOM WGMn3:0 COMnx1:0 The OCR1x register is double buffered when using any of the twelve pulse width modulation (PWM) modes. For the normal and clear timer on compare (CTC) modes of operation, the double buffering is disabled. The double buffering synchronizes the update of the OCR1x compare register to either TOP or BOTTOM of the counting sequence. The synchronization prevents the occurrence of odd-length, non-symmetrical PWM pulses, thereby making the output glitch-free. The OCR1x register access may seem complex, but this is not case. When the double buffering is enabled, the CPU has access to the OCR1x buffer register, and if double buffering is disabled the CPU will access the OCR1x directly. The content of the OCR1x (buffer or compare) register is only changed by a write operation (the Timer/Counter does not update this register automatically as the TCNT1 and ICR1 register). Therefore OCR1x is not read via the high byte temporary register (TEMP). However, it is a good practice to read the low byte first as when accessing other 16-bit registers. Writing the OCR1x registers must be done via the TEMP register since the compare of all 16 bits is done continuously. The high byte (OCR1xH) has to be written first. When the high byte I/O location is written by the CPU, the TEMP register will be updated by the value written. Then when the low byte (OCR1xL) is written to the lower eight bits, the high byte will be copied into the upper 8-bits of either the OCR1x buffer or OCR1x compare register in the same system clock cycle. For more information of how to access the 16-bit registers refer to Section 5.14.2 "Accessing 16-bit Registers" on page 115. 5.14.6.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 (FOC1x) bit. Forcing compare match will not set the OCF1x flag or reload/clear the timer, but the OC1x pin will be updated as if a real compare match had occurred (the COM11:0 bits settings define whether the OC1x pin is set, cleared or toggled). 5.14.6.2 Compare Match Blocking by TCNT1 Write All CPU writes to the TCNT1 register will block any compare match that occurs in the next timer clock cycle, even when the timer is stopped. This feature allows OCR1x to be initialized to the same value as TCNT1 without triggering an interrupt when the Timer/Counter clock is enabled. 122 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 5.14.6.3 Using the Output Compare Unit Since writing TCNT1 in any mode of operation will block all compare matches for one timer clock cycle, there are risks involved when changing TCNT1 when using any of the output compare channels, independent of whether the Timer/Counter is running or not. If the value written to TCNT1 equals the OCR1x value, the compare match will be missed, resulting in incorrect waveform generation. Do not write the TCNT1 equal to TOP in PWM modes with variable TOP values. The compare match for the TOP will be ignored and the counter will continue to 0xFFFF. Similarly, do not write the TCNT1 value equal to BOTTOM when the counter is downcounting. The setup of the OC1x should be performed before setting the data direction register for the port pin to output. The easiest way of setting the OC1x value is to use the force output compare (FOC1x) strobe bits in normal mode. The OC1x register keeps its value even when changing between waveform generation modes. Be aware that the COM1x1:0 bits are not double buffered together with the compare value. Changing the COM1x1:0 bits will take effect immediately. 5.14.7 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 OC1x pin output source. Figure 5-44 shows a simplified schematic of the logic affected by the COM1x1:0 bit setting. The I/O registers, I/O bits, and I/O pins in the figure are shown in bold. Only the parts of the general I/O port control registers (DDR and PORT) that are affected by the COM1x1:0 bits are shown. When referring to the OC1x state, the reference is for the internal OC1x register, not the OC1x pin. If a system reset occur, the OC1x register is reset to "0". Figure 5-44. Compare Match Output Unit, Schematic COMnx1 COMnx0 FOCnx Waveform Generator D Q 1 OCnx Pin OCnx 0 DATA BUS D Q PORT D clkI/O Q DDR The general I/O port function is overridden by the output compare (OC1x) from the waveform generator if either of the COM1x1:0 bits are set. However, the OC1x pin direction (input or output) is still controlled by the data direction register (DDR) for the port pin. The data direction register bit for the OC1x pin (DDR_OC1x) must be set as output before the OC1x value is visible on the pin. The port override function is generally independent of the waveform generation mode, but there are some exceptions. Refer to Table 5-53 on page 132, Table 5-54 on page 132 and Table 5-55 on page 133 for details. The design of the output compare pin logic allows initialization of the OC1x state before the output is enabled. Note that some COM1x1:0 bit settings are reserved for certain modes of operation (see Section 5.14.10 "16-bit Timer/Counter Register Description" on page 132). The COM1x1:0 bits have no effect on the input capture unit. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 123 5.14.7.1 Compare Output Mode and Waveform Generation The waveform generator uses the COM1x1:0 bits differently in normal, CTC, and PWM modes. For all modes, setting the COM1x1:0 = 0 tells the waveform generator that no action on the OC1x register is to be performed on the next compare match. For compare output actions in the non-PWM modes refer to Table 5-53 on page 132. For fast PWM mode refer to Table 5-54 on page 132, and for phase correct and phase and frequency correct PWM refer to Table 5-55 on page 133. A change of the COM1x1:0 bits state will have effect at the first compare match after the bits are written. For non-PWM modes, the action can be forced to have immediate effect by using the FOC1x strobe bits. 5.14.8 Modes of Operation The mode of operation, i.e., the behavior of the Timer/Counter and the output compare pins, is defined by the combination of the waveform generation mode (WGM13:0) and compare output mode (COM1x1:0) bits. The compare output mode bits do not affect the counting sequence, while the waveform generation mode bits do. The COM1x1:0 bits control whether the PWM output generated should be inverted or not (inverted or non-inverted PWM). For non-PWM modes the COM1x1:0 bits control whether the output should be set, cleared or toggle at a compare match (see Section 5.14.7 "Compare Match Output Unit" on page 123). For detailed timing information refer to Section 5.14.9 "Timer/Counter Timing Diagrams" on page 130. 5.14.8.1 Normal Mode The simplest mode of operation is the normal mode (WGM13:0 = 0). In this mode the counting direction is always up (incrementing), and no counter clear is performed. The counter simply overruns when it passes its maximum 16-bit value (MAX = 0xFFFF) and then restarts from the BOTTOM (0x0000). In normal operation the Timer/Counter overflow flag (TOV1) will be set in the same timer clock cycle as the TCNT1 becomes zero. The TOV1 flag in this case behaves like a 17th bit, except that it is only set, not cleared. However, combined with the timer overflow interrupt that automatically clears the TOV1 flag, the timer resolution can be increased by software. There are no special cases to consider in the normal mode, a new counter value can be written anytime. The input capture unit is easy to use in normal mode. However, observe that the maximum interval between the external events must not exceed the resolution of the counter. If the interval between events are too long, the timer overflow interrupt or the prescaler must be used to extend the resolution for the capture unit. The output compare units can be used to generate interrupts at some given time. Using the output compare to generate waveforms in normal mode is not recommended, since this will occupy too much of the CPU time. 5.14.8.2 Clear Timer on Compare Match (CTC) Mode In clear timer on compare or CTC mode (WGM13:0 = 4 or 12), the OCR1A or ICR1 register are used to manipulate the counter resolution. In CTC mode the counter is cleared to zero when the counter value (TCNT1) matches either the OCR1A (WGM13:0 = 4) or the ICR1 (WGM13:0 = 12). The OCR1A or ICR1 define the top value for the counter, hence also its resolution. This mode allows greater control of the compare match output frequency. It also simplifies the operation of counting external events. The timing diagram for the CTC mode is shown in Figure 5-45. The counter value (TCNT1) increases until a compare match occurs with either OCR1A or ICR1, and then counter (TCNT1) is cleared. Figure 5-45. CTC Mode, Timing Diagram OCnA Interrupt Flag Set or ICFn Interrupt Flag Set (Interrupt on TOP) TCNTn OCnA (Toggle) Period 124 (COMnA1:0 = 1) 1 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 2 3 4 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 define the TOP value. If the interrupt is enabled, the interrupt handler routine can be used for updating the TOP value. However, changing the TOP to a value close to BOTTOM when the counter is running with none or a low prescaler value must be done with care since the CTC mode does not have the double buffering feature. If the new value written to OCR1A or ICR1 is lower than the current value of TCNT1, the counter will miss the compare match. The counter will then have to count to its maximum value (0xFFFF) and wrap around starting at 0x0000 before the compare match can occur. In many cases this feature is not desirable. An alternative will then be to use the fast PWM mode using OCR1A for defining TOP (WGM13:0 = 15) since the OCR1A then will be double buffered. For generating a waveform output in CTC mode, the OC1A output can be set to toggle its logical level on each compare match by setting the compare output mode bits to toggle mode (COM1A1:0 = 1). The OC1A value will not be visible on the port pin unless the data direction for the pin is set to output (DDR_OC1A = 1). The waveform generated will have a maximum frequency of fOC1A = fclk_I/O/2 when OCR1A is set to zero (0x0000). The waveform frequency is defined by the following equation: f clk_I/O f OCnA = ----------------------------------------------------2 x N x ( 1 + OCRnA ) The N variable represents the prescaler factor (1, 8, 64, 256, or 1024). As for the normal mode of operation, the TOV1 flag is set in the same timer clock cycle that the counter counts from MAX to 0x0000. 5.14.8.3 Fast PWM Mode The fast pulse width modulation or fast PWM mode (WGM13:0 = 5, 6, 7, 14, or 15) provides a high frequency PWM waveform generation option. The fast PWM differs from the other PWM options by its single-slope operation. The counter counts from BOTTOM to TOP then restarts from BOTTOM. In non-inverting compare output mode, the output compare (OC1x) is set on the compare match between TCNT1 and OCR1x, and cleared at TOP. In inverting compare output mode output is cleared on compare match and set at TOP. Due to the single-slope operation, the operating frequency of the fast PWM mode can be twice as high as the phase correct and phase and frequency correct PWM modes that use dual-slope operation. This high frequency makes the fast PWM mode well suited for power regulation, rectification, and DAC applications. High frequency allows physically small sized external components (coils, capacitors), hence reduces total system cost. 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 maximum resolution is 16-bit (ICR1 or OCR1A set to MAX). The PWM resolution in bits can be calculated by using the following equation: log ( TOP + 1 ) R FPWM = --------------------------------log ( 2 ) In fast PWM mode the counter is incremented until the counter value matches either one of the fixed values 0x00FF, 0x01FF, or 0x03FF (WGM13:0 = 5, 6, or 7), the value in ICR1 (WGM13:0 = 14), or the value in OCR1A (WGM13:0 = 15). The counter is then cleared at the following timer clock cycle. The timing diagram for the fast PWM mode is shown in Figure 5-46 on page 126. The figure shows fast PWM mode when OCR1A or ICR1 is used to define TOP. The TCNT1 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 TCNT1 slopes represent compare matches between OCR1x and TCNT1. The OC1x interrupt flag will be set when a compare match occurs. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 125 Figure 5-46. Fast PWM Mode, Timing Diagram OCRnx/TOP Update and TOVn Interrupt Flag Set and OCnA Interrupt Flag Set or ICFn Interrupt Flag Set (Interrupt on TOP) TCNTn OCnx (COMnx1:0 = 2) OCnx (COMnx1:0 = 3) Period 1 2 3 4 5 6 7 8 The Timer/Counter overflow flag (TOV1) is set each time the counter reaches TOP. In addition the OC1A or ICF1 flag is set at the same timer clock cycle as TOV1 is set when either OCR1A or ICR1 is used for defining the TOP value. If one of the interrupts are enabled, the interrupt handler routine can be used for updating the TOP and compare values. When changing the TOP value the program must ensure that the new TOP value is higher or equal to the value of all of the compare registers. If the TOP value is lower than any of the compare registers, a compare match will never occur between the TCNT1 and the OCR1x. Note that when using fixed TOP values the unused bits are masked to zero when any of the OCR1x registers are written. The procedure for updating ICR1 differs from updating OCR1A when used for defining the TOP value. The ICR1 register is not double buffered. This means that if ICR1 is changed to a low value when the counter is running with none or a low prescaler value, there is a risk that the new ICR1 value written is lower than the current value of TCNT1. The result will then be that the counter will miss the compare match at the TOP value. The counter will then have to count to the MAX value (0xFFFF) and wrap around starting at 0x0000 before the compare match can occur. The OCR1A register however, is double buffered. This feature allows the OCR1A I/O location 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 next timer clock cycle the TCNT1 matches TOP. The update is done at the same timer clock cycle as the TCNT1 is cleared and the TOV1 flag is set. Using the ICR1 register for defining TOP works well when using fixed TOP values. By using ICR1, the OCR1A register is free to be used for generating a PWM output on OC1A. However, 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 fast PWM mode, the compare units allow generation of PWM waveforms on the OC1x pins. Setting the COM1x1:0 bits to two will produce a non-inverted PWM and an inverted PWM output can be generated by setting the COM1x1:0 to three (see Table 5-53 on page 132). The actual OC1x value will only be visible on the port pin if the data direction for the port pin is set as output (DDR_OC1x). The PWM waveform is generated by setting (or clearing) the OC1x register at the compare match between OCR1x and TCNT1, and clearing (or setting) the OC1x register at the timer clock cycle the counter is cleared (changes from TOP to BOTTOM). The PWM frequency for the output can be calculated by the following equation: f clk_I/O f OCnxPWM = -----------------------------------N x ( 1 + TOP ) The N variable represents the prescaler divider (1, 8, 64, 256, or 1024). The extreme values for the OCR1x register represents special cases when generating a PWM waveform output in the fast PWM mode. If the OCR1x is set equal to BOTTOM (0x0000) the output will be a narrow spike for each TOP+1 timer clock cycle. Setting the OCR1x equal to TOP will result in a constant high or low output (depending on the polarity of the output set by the COM1x1:0 bits). 126 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 A frequency (with 50% duty cycle) waveform output in fast PWM mode can be achieved by setting OC1A to toggle its logical level on each compare match (COM1A1:0 = 1). This applies only if OCR1A is used to define the TOP value (WGM13:0 = 15). The waveform generated will have a maximum frequency of fOC1A = fclk_I/O/2 when OCR1A is set to zero (0x0000). This feature is similar to the OC1A toggle in CTC mode, except the double buffer feature of the output compare unit is enabled in the fast PWM mode. 5.14.8.4 Phase Correct PWM Mode The phase correct pulse width modulation or phase correct PWM mode (WGM13:0 = 1, 2, 3, 10, or 11) provides a high resolution phase correct PWM waveform generation option. The phase correct PWM mode is, like the phase and frequency correct PWM mode, based on a dual-slope operation. The counter counts repeatedly from BOTTOM (0x0000) to TOP and then from TOP to BOTTOM. In non-inverting compare output mode, the output compare (OC1x) is cleared on the compare match between TCNT1 and OCR1x while upcounting, and set on the compare match while downcounting. In inverting output compare mode, the operation is inverted. The dual-slope operation has lower maximum operation frequency than single slope operation. However, due to the symmetric feature of the dual-slope PWM modes, these modes are preferred for motor control applications. The PWM resolution for the phase correct PWM mode 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 maximum resolution is 16-bit (ICR1 or OCR1A set to MAX). The PWM resolution in bits can be calculated by using the following equation: log ( TOP + 1 ) R PCPWM = --------------------------------log ( 2 ) In phase correct PWM mode the counter is incremented until the counter value matches either one of the fixed values 0x00FF, 0x01FF, or 0x03FF (WGM13:0 = 1, 2, or 3), the value in ICR1 (WGM13:0 = 10), or the value in OCR1A (WGM13:0 = 11). The counter has then reached the TOP and changes the count direction. The TCNT1 value will be equal to TOP for one timer clock cycle. The timing diagram for the phase correct PWM mode is shown on Figure 5-47. The figure shows phase correct PWM mode when OCR1A or ICR1 is used to define TOP. The TCNT1 value is in the timing diagram shown as a histogram for illustrating the dual-slope operation. The diagram includes non-inverted and inverted PWM outputs. The small horizontal line marks on the TCNT1 slopes represent compare matches between OCR1x and TCNT1. The OC1x interrupt flag will be set when a compare match occurs. Figure 5-47. Phase Correct PWM Mode, Timing Diagram OCRnx/TOP Update and OCnA Interrupt Flag Set or ICFn Interrupt Flag Set (Interrupt on TOP) TOVn Interrupt Flag Set (Interrupt on Bottom) TCNTn OCnx (COMnx1:0 = 2) OCnx (COMnx1:0 = 3) Period 1 2 3 4 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 127 The Timer/Counter overflow flag (TOV1) is set each time the counter reaches BOTTOM. When either OCR1A or ICR1 is used for defining the TOP value, the OC1A or ICF1 flag is set accordingly at the same timer clock cycle as the OCR1x registers are updated with the double buffer value (at TOP). The interrupt flags can be used to generate an interrupt each time the counter reaches the TOP or BOTTOM value. When changing the TOP value the program must ensure that the new TOP value is higher or equal to the value of all of the compare registers. If the TOP value is lower than any of the compare registers, a compare match will never occur between the TCNT1 and the OCR1x. Note that when using fixed TOP values, the unused bits are masked to zero when any of the OCR1x registers are written. As the third period shown in Figure 5-47 on page 127 illustrates, changing the TOP actively while the Timer/Counter is running in the phase correct mode can result in an unsymmetrical output. The reason for this can be found in the time of update of the OCR1x register. 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 is determined by the new TOP value. When these two values differ the two slopes of the period will differ in length. The difference in length gives the unsymmetrical result on the output. It is recommended to use the phase and frequency correct mode instead of the phase correct mode when changing the TOP value while the Timer/Counter is running. When using a static TOP value there are practically no differences between the two modes of operation. In phase correct PWM mode, the compare units allow generation of PWM waveforms on the OC1x pins. Setting the COM1x1:0 bits to two will produce a non-inverted PWM and an inverted PWM output can be generated by setting the COM1x1:0 to three. The actual OC1x value will only be visible on the port pin if the data direction for the port pin is set as output (DDR_OC1x). The PWM waveform is generated by setting (or clearing) the OC1x register at the compare match between OCR1x and TCNT1 when the counter increments, and clearing (or setting) the OC1x register at compare match between OCR1x and TCNT1 when the counter decrements. The PWM frequency for the output when using phase correct PWM can be calculated by the following equation: f clk_I/O f OCnxPCPWM = ------------------------------2 x N x TOP The N variable represents the prescaler divider (1, 8, 64, 256, or 1024). The extreme values for the OCR1x register represent special cases when generating a PWM waveform output in the phase correct PWM mode. If the OCR1x is set equal to BOTTOM the output will be continuously low and if set equal to TOP the output will be continuously high for non-inverted PWM mode. For inverted PWM the output will have the opposite logic values. If OCR1A is used to define the TOP value (WGM13:0 = 11) and COM1A1:0 = 1, the OC1A output will toggle with a 50% duty cycle. 5.14.8.5 Phase and Frequency Correct PWM Mode The phase and frequency correct pulse width modulation, or phase and frequency correct PWM mode (WGM13:0 = 8 or 9) provides a high resolution phase and frequency correct PWM waveform generation option. The phase and frequency correct PWM mode is, like the phase correct PWM mode, based on a dual-slope operation. The counter counts repeatedly from BOTTOM (0x0000) to TOP and then from TOP to BOTTOM. In non-inverting compare output mode, the output compare (OC1x) is cleared on the compare match between TCNT1 and OCR1x while upcounting, and set on the compare match while downcounting. In inverting compare output mode, the operation is inverted. The dual-slope operation gives a lower maximum operation frequency compared to the single-slope operation. However, due to the symmetric feature of the dual-slope PWM modes, these modes are preferred for motor control applications. The main difference between the phase correct, and the phase and frequency correct PWM mode is the time the OCR1x register is updated by the OCR1x buffer register (see Figure 5-47 on page 127 and Figure 5-48 on page 129). The PWM resolution for the phase and frequency correct PWM mode can be defined by either ICR1 or OCR1A. The minimum resolution allowed is 2-bit (ICR1 or OCR1A set to 0x0003), and the maximum resolution is 16-bit (ICR1 or OCR1A set to MAX). The PWM resolution in bits can be calculated using the following equation: log ( TOP + 1 ) R PFCPWM = --------------------------------log ( 2 ) 128 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 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 and changes the count direction. The TCNT1 value will be equal to TOP for one timer clock cycle. The timing diagram for the phase correct and frequency correct PWM mode is shown on Figure 5-48. The figure shows phase and frequency correct PWM mode when OCR1A or ICR1 is used to define TOP. The TCNT1 value is in the timing diagram shown as a histogram for illustrating the dual-slope operation. The diagram includes non-inverted and inverted PWM outputs. The small horizontal line marks on the TCNT1 slopes represent compare matches between OCR1x and TCNT1. The OC1x interrupt flag will be set when a compare match occurs. Figure 5-48. Phase and Frequency Correct PWM Mode, Timing Diagram OCnA Interrupt Flag Set or ICFn Interrupt Flag Set (Interrupt on TOP) OCRnx/ TOP Update and TOVn Interrupt Flag Set (Interrupt on Bottom) TCNTn OCnx (COMnx1:0 = 2) OCnx (COMnx1:0 = 3) Period 1 2 3 4 The Timer/Counter overflow flag (TOV1) is set at the same timer clock cycle as the OCR1x registers are updated with the double buffer value (at BOTTOM). When either OCR1A or ICR1 is used for defining the TOP value, the OC1A or ICF1 flag set when TCNT1 has reached TOP. The interrupt flags can then be used to generate an interrupt each time the counter reaches the TOP or BOTTOM value. When changing the TOP value the program must ensure that the new TOP value is higher or equal to the value of all of the compare registers. If the TOP value is lower than any of the compare registers, a compare match will never occur between the TCNT1 and the OCR1x. As Figure 5-48 shows the output generated is, in contrast to the phase correct mode, symmetrical in all periods. Since the OCR1x registers are updated at BOTTOM, the length of the rising and the falling slopes will always be equal. This gives symmetrical output pulses and is therefore frequency correct. Using the ICR1 register for defining TOP works well when using fixed TOP values. By using ICR1, the OCR1A register is free to be used for generating a PWM output on OC1A. However, 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 allow generation of PWM waveforms on the OC1x pins. Setting the COM1x1:0 bits to two will produce a non-inverted PWM and an inverted PWM output can be generated by setting the COM1x1:0 to three (see Table 5-55 on page 133). The actual OC1x value will only be visible on the port pin if the data direction for the port pin is set as output (DDR_OC1x). The PWM waveform is generated by setting (or clearing) the OC1x register at the compare match between OCR1x and TCNT1 when the counter increments, and clearing (or setting) the OC1x register at compare match between OCR1x and TCNT1 when the counter decrements. The PWM frequency for the output when using phase and frequency correct PWM can be calculated by the following equation: f clk_I/O f OCnxPFCPWM = ------------------------------2 x N x TOP The N variable represents the prescaler divider (1, 8, 64, 256, or 1024). ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 129 The extreme values for the OCR1x register represents special cases when generating a PWM waveform output in the phase correct PWM mode. If the OCR1x is set equal to BOTTOM the output will be continuously low and if set equal to TOP the output will be set to high for non-inverted PWM mode. For inverted PWM the output will have the opposite logic values. If OCR1A is used to define the TOP value (WGM13:0 = 9) and COM1A1:0 = 1, the OC1A output will toggle with a 50% duty cycle. 5.14.9 Timer/Counter Timing Diagrams The Timer/Counter is a synchronous design and the timer clock (clkT1) is therefore shown as a clock enable signal in the following figures. The figures include information on when interrupt flags are set, and when the OCR1x register is updated with the OCR1x buffer value (only for modes utilizing double buffering). Figure 5-49 shows a timing diagram for the setting of OCF1x. Figure 5-49. Timer/Counter Timing Diagram, Setting of OCF1x, no Prescaling clkI/O clkTn (clkI/O/1) TCNTn OCRnx - 1 OCRnx OCRnx + 1 OCRnx + 2 OCRnx Value OCRnx OCFnx Figure 5-50 shows the same timing data, but with the prescaler enabled. Figure 5-50. Timer/Counter Timing Diagram, Setting of OCF1x, with Prescaler (fclk_I/O/8) clkI/O clkTn (clkI/O/8) TCNTn OCRnx - 1 OCRnx OCFnx 130 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 OCRnx OCRnx + 1 OCRnx Value OCRnx + 2 Figure 5-51 shows the count sequence close to TOP in various modes. When using phase and 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 by BOTTOM+1 and so on. The same renaming applies for modes that set the TOV1 flag at BOTTOM. Figure 5-51. Timer/Counter Timing Diagram, no Prescaling clkI/O clkTn (clkI/O/1) TCNTn (CTC and FPWM) TOP - 1 TOP BOTTOM BOTTOM + 1 TCNTn (PC and PFC PWM) TOP - 1 TOP TOP - 1 TOP - 2 TOVn (FPWM) and ICFn (if used as TOP) OCRnx (Update at TOP) Old OCRnx Value New OCRnx Value Figure 5-52 shows the same timing data, but with the prescaler enabled. Figure 5-52. Timer/Counter Timing Diagram, with Prescaler (fclk_I/O/8) clkI/O clkTn (clkI/O/8) TCNTn (CTC and FPWM) TOP - 1 TOP BOTTOM BOTTOM + 1 TCNTn (PC and PFC PWM) TOP - 1 TOP TOP - 1 TOP - 2 TOVn (FPWM) and ICFn (if used as TOP) OCRnx (Update at TOP) Old OCRnx Value New OCRnx Value ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 131 5.14.10 16-bit Timer/Counter Register Description 5.14.10.1 Timer/Counter1 Control Register A - TCCR1A Bit 7 6 5 4 3 2 1 0 COM1A1 COM1A0 COM1B1 COM1B0 - - WGM11 WGM10 Read/Write R/W R/W R/W R/W R R R/W R/W Initial Value 0 0 0 0 0 0 0 0 TCCR1A * Bit 7:6 - COM1A1:0: Compare Output Mode for Channel A * Bit 5:4 - COM1B1:0: Compare Output Mode for Channel B The COM1A1:0 and COM1B1:0 control the output compare pins (OC1A and OC1B respectively) behavior. If one or both of the COM1A1:0 bits are written to one, the OC1A output overrides the normal port functionality of the I/O pin it is connected to. If one or both of the COM1B1:0 bit are written to one, the OC1B output overrides the normal port functionality of the I/O pin it is connected to. However, note that the data direction register (DDR) bit corresponding to the OC1A or OC1B pin must be set in order to enable the output driver. When the OC1A or OC1B is connected to the pin, the function of the COM1x1:0 bits is dependent of the WGM13:0 bits setting. Table 5-53 shows the COM1x1:0 bit functionality when the WGM13:0 bits are set to a Normal or a CTC mode (non-PWM). Table 5-53. Compare Output Mode, non-PWM COM1A1/COM1B1 COM1A0/COM1B0 Description 0 0 Normal port operation, OC1A/OC1B disconnected. 0 1 Toggle OC1A/OC1B on compare match. 1 0 Clear OC1A/OC1B on compare match (set output to low level). 1 1 Set OC1A/OC1B on compare match (set output to high level). Table 5-54 shows the COM1x1:0 bit functionality when the WGM13:0 bits are set to the fast PWM mode. Table 5-54. Compare Output Mode, Fast PWM(1) COM1A1/COM1B1 COM1A0/COM1B0 0 0 Normal port operation, OC1A/OC1B disconnected. 0 1 WGM13:0 = 14 or 15: Toggle OC1A on compare match, OC1B disconnected (normal port operation). For all other WGM1 settings, normal port operation, OC1A/OC1B disconnected. 1 0 Clear OC1A/OC1B on compare match, set OC1A/OC1B at TOP Note: 132 Description 1 1 Set OC1A/OC1B on compare match, clear OC1A/OC1B at TOP 1. A special case occurs when OCR1A/OCR1B equals TOP and COM1A1/COM1B1 is set. In this case the compare match is ignored, but the set or clear is done at TOP. See Section 5.14.8.3 "Fast PWM Mode" on page 125 for more details. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 Table 5-55 shows the COM1x1:0 bit functionality when the WGM13:0 bits are set to the phase correct or the phase and frequency correct, PWM mode. Table 5-55. Compare Output Mode, Phase Correct and Phase and Frequency Correct PWM(1) COM1A1/COM1B1 COM1A0/COM1B0 0 0 Normal port operation, OC1A/OC1B disconnected. 0 1 WGM13:0 = 8, 9, 10 or 11: Toggle OC1A on compare match, OC1B disconnected (normal port operation). For all other WGM1 settings, normal port operation, OC1A/OC1B disconnected. 1 0 Clear OC1A/OC1B on compare match when up-counting. Set OC1A/OC1B on compare match when downcounting. Set OC1A/OC1B on compare match when up-counting. Clear OC1A/OC1B on compare match when downcounting. A special case occurs when OCR1A/OCR1B equals TOP and COM1A1/COM1B1 is set. See Section 5.14.8.4 "Phase Correct PWM Mode" on page 127 for more details. 1 Note: 1. Description 1 * Bit 1:0 - WGM11:0: Waveform Generation Mode Combined with the WGM13:2 bits found in the TCCR1B register, these bits control the counting sequence of the counter, the source for maximum (TOP) counter value, and what type of waveform generation to be used (see Table 5-56 on page 133). Modes of operation supported by the Timer/Counter unit are: Normal mode (counter), clear timer on compare match (CTC) mode, and three types of pulse width modulation (PWM) modes (see Section 5.14.8 "Modes of Operation" on page 124). Table 5-56. Waveform Generation Mode Bit Description(1) Mode WGM13 WGM12 (CTC1) WGM11 WGM10 Timer/Counter Mode of (PWM11) (PWM10) Operation TOP Update of OCR1x at TOV1 Flag Set on 0 0 0 0 0 Normal 0xFFFF Immediate MAX 1 0 0 0 1 PWM, phase correct, 8-bit 0x00FF TOP BOTTOM 2 0 0 1 0 PWM, phase correct, 9-bit 0x01FF TOP BOTTOM 3 0 4 0 0 1 1 PWM, phase correct, 10-bit 0x03FF TOP BOTTOM 1 0 0 CTC OCR1A Immediate MAX 5 0 1 0 1 Fast PWM, 8-bit 0x00FF TOP TOP 6 0 1 1 0 Fast PWM, 9-bit 0x01FF TOP TOP 7 0 1 1 1 Fast PWM, 10-bit 0x03FF TOP TOP BOTTOM BOTTOM 8 1 0 0 0 PWM, phase and frequency ICR1 correct 9 1 0 0 1 PWM, phase and frequency OCR1A correct BOTTOM BOTTOM 10 1 0 1 0 PWM, phase correct ICR1 TOP BOTTOM 11 1 0 1 1 PWM, phase correct OCR1A TOP BOTTOM 12 1 1 0 0 CTC ICR1 Immediate MAX 13 1 1 0 1 (Reserved) - - - 14 1 1 1 0 Fast PWM ICR1 TOP TOP 15 Note: 1. 1 1 1 1 Fast PWM OCR1A TOP TOP The CTC1 and PWM11:0 bit definition names are obsolete. Use the WGM12:0 definitions. However, the functionality and location of these bits are compatible with previous versions of the timer. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 133 5.14.10.2 Timer/Counter1 Control Register B - TCCR1B Bit 7 6 5 4 3 2 1 0 ICNC1 ICES1 - WGM13 WGM12 CS12 CS11 CS10 Read/Write R/W R/W R R/W R/W R/W R/W R/W Initial Value 0 0 0 0 0 0 0 0 TCCR1B * Bit 7 - ICNC1: Input Capture Noise Canceler Setting this bit (to one) activates the input capture noise canceler. When the noise canceler is activated, the input from the input capture pin (ICP1) is filtered. The filter function requires four successive equal valued samples of the ICP1 pin for changing its output. The input capture is therefore delayed by four oscillator cycles when the noise canceler is enabled. * Bit 6 - ICES1: Input Capture Edge Select This bit selects which edge on the Input Capture pin (ICP1) that is used to trigger a capture event. When the ICES1 bit is written to zero, a falling (negative) edge is used as trigger, and when the ICES1 bit is written to one, a rising (positive) edge will trigger the capture. When a capture is triggered according to the ICES1 setting, the counter value is copied into the input capture register (ICR1). The event will also set the input capture flag (ICF1), and this can be used to cause an input capture interrupt, if this interrupt is enabled. 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 capture function is disabled. * Bit 5 - Reserved Bit This bit is reserved for future use. For ensuring compatibility with future devices, this bit must be written to zero when TCCR1B is written. * Bit 4:3 - WGM13:2: Waveform Generation Mode See TCCR1A register description. * Bit 2:0 - CS12:0: Clock Select The three clock select bits select the clock source to be used by the Timer/Counter, see Figure 5-49 on page 130 and Figure 5-50 on page 130. Table 5-57. Clock Select Bit Description CS12 CS11 CS10 Description 0 0 0 No clock source (Timer/Counter stopped). 0 0 1 clkI/O/1 (no prescaling) 0 1 0 clkI/O/8 (from prescaler) 0 1 1 clkI/O/64 (from prescaler) 1 0 0 clkI/O/256 (from prescaler) 1 0 1 clkI/O/1024 (from prescaler) 1 1 0 External clock source on T1 pin. Clock on falling edge. 1 1 1 External clock source on T1 pin. Clock on rising edge. If external pin modes are used for the Timer/Counter1, transitions on the T1 pin will clock the counter even if the pin is configured as an output. This feature allows software control of the counting. 134 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 5.14.10.3 Timer/Counter1 Control Register C - TCCR1C Bit 7 6 5 4 3 2 1 0 FOC1A FOC1B - - - - - - Read/Write R/W R/W R R R R R R Initial Value 0 0 0 0 0 0 0 0 TCCR1C * Bit 7 - FOC1A: Force Output Compare for Channel A * Bit 6 - FOC1B: Force Output Compare for Channel B The FOC1A/FOC1B bits are only active when the WGM13:0 bits specifies a non-PWM mode. However, for ensuring compatibility with future devices, these bits must be set to zero when TCCR1A is written when operating in a PWM mode. When writing a logical one to the FOC1A/FOC1B bit, an immediate compare match is forced on the Waveform Generation unit. The OC1A/OC1B output is changed according to its COM1x1:0 bits setting. Note that the FOC1A/FOC1B bits are implemented as strobes. Therefore it is the value present in the COM1x1:0 bits that determine the effect of the forced compare. 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. 5.14.10.4 Timer/Counter1 - TCNT1H and TCNT1L Bit 7 6 5 4 3 2 1 0 TCNT1[15:8] TCNT1H TCNT1[7:0] TCNT1L 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 The two Timer/Counter I/O locations (TCNT1H and TCNT1L, combined TCNT1) give direct access, both for read and for write operations, to the Timer/Counter unit 16-bit counter. To ensure that both the high and low bytes are read and written simultaneously when the CPU accesses these registers, the access is performed using an 8-bit temporary high byte register (TEMP). This temporary register is shared by all the other 16-bit registers see Section 5.14.2 "Accessing 16-bit Registers" on page 115. Modifying the counter (TCNT1) while the counter is running introduces a risk of missing a compare match between TCNT1 and one of the OCR1x registers. Writing to the TCNT1 register blocks (removes) the compare match on the following timer clock for all compare units. 5.14.10.5 Output Compare Register 1 A - OCR1AH and OCR1AL Bit 7 6 5 4 3 2 1 0 OCR1A[15:8] OCR1AH OCR1A[7:0] OCR1AL 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 2 1 0 5.14.10.6 Output Compare Register 1 B - OCR1BH and OCR1BL Bit 7 6 5 4 3 OCR1B[15:8] OCR1BH OCR1B[7:0] OCR1BL 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 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 135 The output compare registers contain a 16-bit value that is continuously compared with the counter value (TCNT1). A match can be used to generate an output compare interrupt, or to generate a waveform output on the OC1x pin. The output compare registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary high byte register (TEMP). This temporary register is shared by all the other 16-bit registers (see Section 5.14.2 "Accessing 16-bit Registers" on page 115). 5.14.10.7 Input Capture Register 1 - ICR1H and ICR1L Bit 7 6 5 4 3 2 1 0 ICR1[15:8] ICR1H ICR1[7:0] ICR1L 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 The input capture is updated with the counter (TCNT1) value each time an event occurs on the ICP1 pin (or optionally on the analog comparator output for Timer/Counter1). The input capture can be used for defining the counter TOP value. The input capture register is 16-bit in size. To ensure that both the high and low bytes are read simultaneously when the CPU accesses these registers, the access is performed using an 8-bit temporary high byte register (TEMP). This temporary register is shared by all the other 16-bit registers (see Section 5.14.2 "Accessing 16-bit Registers" on page 115). 5.14.10.8 Timer/Counter1 Interrupt Mask Register - TIMSK1 Bit 7 6 5 Read/Write Initial Value 0 4 3 2 1 0 - - ICIE1 R R R/W - - OCIE1B OCIE1A TOIE1 R R R/W R/W R/W 0 0 0 0 0 0 0 TIMSK1 * Bit 7, 6 - Res: Reserved Bits These bits are unused bits in the Atmel(R) ATA6612C/ATA6613C, and will always read as zero. * Bit 5 - ICIE1: Timer/Counter1, Input Capture Interrupt Enable When this bit is written to one, and the I-flag in the status register is set (interrupts globally enabled), the Timer/Counter1 input capture interrupt is enabled. The corresponding interrupt vector (see Section 5.9 "Interrupts" on page 70) is executed when the ICF1 flag, located in TIFR1, is set. * Bit 4, 3 - Res: Reserved Bits These bits are unused bits in the Atmel ATA6612C/ATA6613C, and will always read as zero. * Bit 2 - OCIE1B: Timer/Counter1, Output Compare B Match Interrupt Enable When this bit is written to one, and the I-flag in the status register is set (interrupts globally enabled), the Timer/Counter1 output compare B match interrupt is enabled. The corresponding interrupt vector (see Section 5.9 "Interrupts" on page 70) is executed when the OCF1B flag, located in TIFR1, is set. * Bit 1 - OCIE1A: Timer/Counter1, Output Compare A Match Interrupt Enable When this bit is written to one, and the I-flag in the status register is set (interrupts globally enabled), the Timer/Counter1 output compare A match interrupt is enabled. The corresponding interrupt vector (see Section 5.9 "Interrupts" on page 70) is executed when the OCF1A flag, located in TIFR1, is set. * Bit 0 - TOIE1: Timer/Counter1, Overflow Interrupt Enable When this bit is written to one, and the I-flag in the status register is set (interrupts globally enabled), the Timer/Counter1 overflow interrupt is enabled. The corresponding interrupt vector (see Section 5.8.9 "Watchdog Timer" on page 66) is executed when the TOV1 flag, located in TIFR1, is set. 136 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 5.14.10.9 Timer/Counter1 Interrupt Flag Register - TIFR1 Bit 7 6 5 4 3 2 1 0 - - ICF1 - - OCF1B OCF1A TOV1 Read/Write R R R/W R R R/W R/W R/W Initial Value 0 0 0 0 0 0 0 0 TIFR1 * Bit 7, 6 - Res: Reserved Bits These bits are unused bits in the Atmel(R) ATA6612C/ATA6613C, and will always read as zero. * 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 register (ICR1) is set by the WGM13:0 to be used as the TOP value, the ICF1 flag is set when the counter reaches the TOP value. ICF1 is automatically cleared when the input capture interrupt vector is executed. Alternatively, ICF1 can be cleared by writing a logic one to its bit location. * Bit 4, 3 - Res: Reserved Bits These bits are unused bits in the Atmel ATA6612C/ATA6613C, and will always read as zero. * Bit 2 - OCF1B: Timer/Counter1, Output Compare B Match Flag This flag is set in the timer clock cycle after the counter (TCNT1) value matches the output compare register B (OCR1B). Note that a forced output compare (FOC1B) strobe will not set the OCF1B flag. OCF1B is automatically cleared when the output compare match B interrupt vector is executed. Alternatively, OCF1B can be cleared by writing a logic one to its bit location. * Bit 1 - OCF1A: Timer/Counter1, Output Compare A Match Flag This flag is set in the timer clock cycle after the counter (TCNT1) value matches the output compare register A (OCR1A). Note that a forced output compare (FOC1A) strobe will not set the OCF1A flag. OCF1A is automatically cleared when the output compare match A interrupt vector is executed. Alternatively, OCF1A can be cleared by writing a logic one to its bit location. * Bit 0 - TOV1: Timer/Counter1, Overflow Flag The setting of this flag is dependent of the WGM13:0 bits setting. In normal and CTC modes, the TOV1 flag is set when the timer overflows. Refer to Table 5-56 on page 133 for the TOV1 flag behavior when using another WGM13:0 bit setting. TOV1 is automatically cleared when the Timer/Counter1 overflow interrupt vector is executed. Alternatively, TOV1 can be cleared by writing a logic one to its bit location. 5.15 8-bit Timer/Counter2 with PWM and Asynchronous Operation Timer/Counter2 is a general purpose, single channel, 8-bit Timer/Counter module. The main features are: Single channel counter Clear timer on compare match (auto reload) Glitch-free, phase correct pulse width modulator (PWM) Frequency generator 10-bit clock prescaler Overflow and compare match interrupt sources (TOV2, OCF2A and OCF2B) Allows clocking from external 32kHz watch crystal independent of the I/O clock ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 137 5.15.1 Overview A simplified block diagram of the 8-bit Timer/Counter is shown in Figure 5-53. The device-specific I/O register and bit locations are listed in the Section 5.15.8 "8-bit Timer/Counter Register Description" on page 148. The PRTIM2 bit in Section 5.7.7.1 "Power Reduction Register - PRR" on page 58 must be written to zero to enable Timer/Counter2 module. Figure 5-53. 8-bit Timer/Counter Block Diagram Count Clear Direction TOVn (Int. Req.) Control Logic clkTn TOSC1 T/C Oscillator Prescaler TOP TOSC2 BOTTOM clkI/O Timer/Counter TCNTn = = 0 OCnA (Int. Req.) Waveform Generation = OCnA DATA BUS OCRnA Fixed TOP Value Waveform Generation = OCRnB TCCRnA 138 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 OCnB (Int. Req.) TCCRnB OCnB 5.15.1.1 Registers The Timer/Counter (TCNT2) and output compare register (OCR2A and OCR2B) are 8-bit registers. Interrupt request (shorten as Int.Req.) signals are all visible in the timer interrupt flag register (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 detailed later in this section. The asynchronous operation is controlled by the asynchronous status register (ASSR). The clock select logic block controls which clock source he Timer/Counter uses to increment (or decrement) its value. The Timer/Counter is inactive when no clock source is selected. The output from the clock select logic is referred to as the timer clock (clkT2). The double buffered output compare register (OCR2A and OCR2B) are compared with the Timer/Counter value at all times. The result of the compare can be used by the waveform generator to generate a PWM or variable frequency output on the output compare pins (OC2A and OC2B). See Section 5.15.4 "Output Compare Unit" on page 140 for details. The compare match event will also set the compare flag (OCF2A or OCF2B) which can be used to generate an output compare interrupt request. 5.15.1.2 Definitions Many register and bit references in this document are written in general form. A lower case "n" replaces the Timer/Counter number, in this case 2. However, when using the register or bit defines in a program, the precise form must be used, i.e., TCNT2 for accessing Timer/Counter2 counter value and so on. The definitions below are also used extensively throughout the section. Table 5-58. Definitions Parameter Definition BOTTOM The counter reaches the BOTTOM when it becomes zero (0x00). MAX The counter reaches its MAXimum when it becomes 0xFF (decimal 255). TOP The counter reaches the TOP when it becomes equal to the highest value in the count sequence. The TOP value can be assigned to be the fixed value 0xFF (MAX) or the value stored in the OCR2A register. The assignment is dependent on the mode of operation. 5.15.2 Timer/Counter Clock Sources The Timer/Counter can be clocked by an internal synchronous or an external asynchronous clock source. The clock source clkT2 is by default equal to the MCU clock, clkI/O. When the AS2 bit in the ASSR register is written to logic one, the clock source is taken from the Timer/Counter oscillator connected to TOSC1 and TOSC2. For details on asynchronous operation (see Section 5.15.9.2 "Asynchronous Status Register - ASSR" on page 154). For details on clock sources and prescaler, see Section 5.15.10 "Timer/Counter Prescaler" on page 155. 5.15.3 Counter Unit The main part of the 8-bit Timer/Counter is the programmable bi-directional counter unit. Figure 5-54 shows a block diagram of the counter and its surrounding environment. Figure 5-54. Counter Unit Block Diagram TOVn (Int. Req.) DATA BUS TOSC1 T/C Oscillator Count TCNTn Clear Control Logic clkTn Prescaler TOSC2 Direction clkI/O Bottom Top ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 139 Signal description (internal signals): count Increment or decrement TCNT2 by 1. direction Selects between increment and decrement. clear Clear TCNT2 (set all bits to zero). clkTn Timer/Counter clock, referred to as clkT2 in the following. top Signalizes that TCNT2 has reached maximum value. bottom Signalizes that TCNT2 has reached minimum value (zero). Depending on the mode of operation used, the counter is cleared, incremented, or decremented at each timer clock (clkT2). clkT2 can be generated from an external or internal clock source, selected by the clock select bits (CS22:0). When no clock source is selected (CS22:0 = 0) the timer is stopped. However, the TCNT2 value can be accessed by the CPU, regardless of whether clkT2 is present or not. A CPU write overrides (has priority over) all counter clear or count operations. The counting sequence is determined by the setting of the WGM21 and WGM20 bits located in the Timer/Counter control register (TCCR2A) and the WGM22 located in the Timer/Counter control register B (TCCR2B). There are close connections between how the counter behaves (counts) and how waveforms are generated on the output compare outputs OC2A and OC2B. For more details about advanced counting sequences and waveform generation (see Section 5.15.6 "Modes of Operation" on page 142). The Timer/Counter overflow flag (TOV2) is set according to the mode of operation selected by the WGM22:0 bits. TOV2 can be used for generating a CPU interrupt. 5.15.4 Output Compare Unit The 8-bit comparator continuously compares TCNT2 with the output compare register (OCR2A and OCR2B). Whenever TCNT2 equals OCR2A or OCR2B, the comparator signals a match. A match will set the output compare flag (OCF2A or OCF2B) at the next timer clock cycle. If the corresponding interrupt is enabled, the output compare flag generates an output compare interrupt. The output compare flag is automatically cleared when the interrupt is executed. Alternatively, the output compare flag can be cleared by software by writing a logical one to its I/O bit location. The waveform generator uses the match signal to generate an output according to operating mode set by the WGM22:0 bits and compare output mode (COM2x1:0) bits. The max and bottom signals are used by the waveform generator for handling the special cases of the extreme values in some modes of operation (see Section 5.15.6 "Modes of Operation" on page 142). Figure 5-55 shows a block diagram of the output compare unit. Figure 5-55. Output Compare Unit, Block Diagram DATA BUS OCRnx TCNTn = (8-bit Comparator) OCFnx (Int. Req.) Top Bottom Waveform Generator FOCn WGMn1:0 140 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 COMnX1:0 OCnx The OCR2x register is double buffered when using any of the pulse width modulation (PWM) modes. For the normal and clear timer on compare (CTC) modes of operation, the double buffering is disabled. The double buffering synchronizes the update of the OCR2x compare register to either top or bottom of the counting sequence. The synchronization prevents the occurrence of odd-length, non-symmetrical PWM pulses, thereby making the output glitch-free. The OCR2x register access may seem complex, but this is not case. When the double buffering is enabled, the CPU has access to the OCR2x buffer register, and if double buffering is disabled the CPU will access the OCR2x directly. 5.15.4.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 (FOC2x) bit. Forcing compare match will not set the OCF2x flag or reload/clear the timer, but the OC2x pin will be updated as if a real compare match had occurred (the COM2x1:0 bits settings define whether the OC2x pin is set, cleared or toggled). 5.15.4.2 Compare Match Blocking by TCNT2 Write All CPU write operations to the TCNT2 register will block any compare match that occurs in the next timer clock cycle, even when the timer is stopped. This feature allows OCR2x to be initialized to the same value as TCNT2 without triggering an interrupt when the Timer/Counter clock is enabled. 5.15.4.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 channel, independently of whether the Timer/Counter is running or not. If the value written to TCNT2 equals the OCR2x value, the compare match will be missed, resulting in incorrect waveform generation. Similarly, do not write the TCNT2 value equal to BOTTOM when the counter is downcounting. The setup of the OC2x should be performed before setting the data direction register for the port pin to output. The easiest way of setting the OC2x value is to use the force output compare (FOC2x) strobe bit in normal mode. The OC2x register keeps its value even when changing between waveform generation modes. Be aware that the COM2x1:0 bits are not double buffered together with the compare value. Changing the COM2x1:0 bits will take effect immediately. 5.15.5 Compare Match Output Unit The compare output mode (COM2x1:0) bits have two functions. The waveform generator uses the COM2x1:0 bits for defining the output compare (OC2x) state at the next compare match. Also, the COM2x1:0 bits control the OC2x pin output source. Figure 5-56 on page 142 shows a simplified schematic of the logic affected by the COM2x1:0 bit setting. The I/O registers, I/O bits, and I/O pins in the figure are shown in bold. Only the parts of the general I/O port control registers (DDR and PORT) that are affected by the COM2x1:0 bits are shown. When referring to the OC2x state, the reference is for the internal OC2x register, not the OC2x pin. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 141 Figure 5-56. Compare Match Output Unit, Schematic COMnx1 COMnx0 FOCnx Waveform Generator D Q 1 OCnx Pin OCnx 0 DATA BUS D Q PORT D clkI/O Q DDR The general I/O port function is overridden by the output compare (OC2x) from the waveform generator if either of the COM2x1:0 bits are set. However, the OC2x pin direction (input or output) is still controlled by the data direction register (DDR) for the port pin. The data direction register bit for the OC2x pin (DDR_OC2x) must be set as output before the OC2x value is visible on the pin. The port override function is independent of the waveform generation mode. The design of the output compare pin logic allows initialization of the OC2x state before the output is enabled. Note that some COM2x1:0 bit settings are reserved for certain modes of operation (see Section 5.15.8 "8-bit Timer/Counter Register Description" on page 148). 5.15.5.1 Compare Output Mode and Waveform Generation The waveform generator uses the COM2x1:0 bits differently in normal, CTC, and PWM modes. For all modes, setting the COM2x1:0 = 0 tells the waveform generator that no action on the OC2x register is to be performed on the next compare match. For compare output actions in the non-PWM modes refer to Table 5-62 on page 149. For fast PWM mode, refer to Table 5-63 on page 149, and for phase correct PWM refer to Table 5-64 on page 149. A change of the COM2x1:0 bits state will have effect at the first compare match after the bits are written. For non-PWM modes, the action can be forced to have immediate effect by using the FOC2x strobe bits. 5.15.6 Modes of Operation The mode of operation, i.e., the behavior of the Timer/Counter and the output compare pins, is defined by the combination of the waveform generation mode (WGM22:0) and compare output mode (COM2x1:0) bits. The compare output mode bits do not affect the counting sequence, while the waveform generation mode bits do. The COM2x1:0 bits control whether the PWM output generated should be inverted or not (inverted or non-inverted PWM). For non-PWM modes the COM2x1:0 bits control whether the output should be set, cleared, or toggled at a compare match (see Section 5.15.5 "Compare Match Output Unit" on page 141). For detailed timing information refer to Section 5.15.7 "Timer/Counter Timing Diagrams" on page 146. 142 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 5.15.6.1 Normal Mode The simplest mode of operation is the normal mode (WGM22:0 = 0). In this mode the counting direction is always up (incrementing), and no counter clear is performed. The counter simply overruns when it passes its maximum 8-bit value (TOP = 0xFF) and then restarts from the bottom (0x00). In normal operation the Timer/Counter overflow flag (TOV2) will be set in the same timer clock cycle as the TCNT2 becomes zero. The TOV2 flag in this case behaves like a ninth bit, except that it is only set, not cleared. However, combined with the timer overflow interrupt that automatically clears the TOV2 flag, the timer resolution can be increased by software. There are no special cases to consider in the normal mode, a new counter value can be written anytime. The output compare unit can be used to generate interrupts at some given time. Using the output compare to generate waveforms in normal mode is not recommended, since this will occupy too much of the CPU time. 5.15.6.2 Clear Timer on Compare Match (CTC) Mode In clear timer on compare or CTC mode (WGM22:0 = 2), the OCR2A register is used to manipulate the counter resolution. In CTC mode the counter is cleared to zero when the counter value (TCNT2) matches the OCR2A. The OCR2A defines the top value for the counter, hence also its resolution. This mode allows greater control of the compare match output frequency. It also simplifies the operation of counting external events. The timing diagram for the CTC mode is shown in Figure 5-57. The counter value (TCNT2) increases until a compare match occurs between TCNT2 and OCR2A, and then counter (TCNT2) is cleared. Figure 5-57. CTC Mode, Timing Diagram OCnx Interrupt Flag Set TCNTn OCnx (Toggle) Period (COMnx1:0 = 1) 1 2 3 4 An interrupt can be generated each time the counter value reaches the TOP value by using the OCF2A flag. If the interrupt is enabled, the interrupt handler routine can be used for updating the TOP value. However, changing TOP to a value close to BOTTOM when the counter is running with none or a low prescaler value must be done with care since the CTC mode does not have the double buffering feature. If the new value written to OCR2A is lower than the current value of TCNT2, the counter will miss the compare match. The counter will then have to count to its maximum value (0xFF) and wrap around starting at 0x00 before the compare match can occur. For generating a waveform output in CTC mode, the OC2A output can be set to toggle its logical level on each compare match by setting the compare output mode bits to toggle mode (COM2A1:0 = 1). The OC2A 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 maximum frequency of fOC2A = fclk_I/O/2 when OCR2A is set to zero (0x00). The waveform frequency is defined by the following equation: f clk_I/O f OCnx = ---------------------------------------------------2 x N x ( 1 + OCRnx ) The N variable represents the prescale factor (1, 8, 32, 64, 128, 256, or 1024). As for the normal mode of operation, the TOV2 flag is set in the same timer clock cycle that the counter counts from MAX to 0x00. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 143 5.15.6.3 Fast PWM Mode The fast pulse width modulation or fast PWM mode (WGM22: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 OCR2A when MGM2:0 = 7. In non-inverting compare output mode, the output compare (OC2x) is cleared on the compare match between TCNT2 and OCR2x, 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 correct PWM mode that uses dual-slope operation. This high frequency makes the fast PWM mode well suited 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 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 5-58 on page 144. The TCNT2 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 TCNT2 slopes represent compare matches between OCR2x and TCNT2. Figure 5-58. Fast PWM Mode, Timing Diagram OCRnx Interrupt Flag Set OCRnx Update and TOVn Interrupt Flag Set TCNTn OCn (COMnx1:0 = 2) OCn (COMnx1:0 = 3) Period 1 2 3 4 5 6 7 The Timer/Counter overflow flag (TOV2) is set each time the counter reaches TOP. If the interrupt is enabled, the interrupt handler routine can be used for updating the compare value. In fast PWM mode, the compare unit allows generation of PWM waveforms on the OC2x pin. Setting the COM2x1:0 bits to two will produce a non-inverted PWM and an inverted PWM output can be generated by setting the COM2x1:0 to three. TOP is defined as 0xFF when WGM2:0 = 3, and OCR2A when MGM2:0 = 7 (see Table 5-60 on page 148). The actual OC2x value will only be visible on the port pin if the data direction for the port pin is set as output. The PWM waveform is generated by setting (or clearing) the OC2x register at the compare match between OCR2x and TCNT2, and clearing (or setting) the OC2x register at the timer clock cycle the counter is cleared (changes from TOP to BOTTOM). The PWM frequency for the output can be calculated by the following equation: f clk_I/O f OCnxPWM = ------------------N x 256 The N variable represents the prescale factor (1, 8, 32, 64, 128, 256, or 1024). The extreme values for the OCR2A register represent special cases when generating a PWM waveform output in the fast PWM mode. If the OCR2A is set equal to BOTTOM, the output will be a narrow spike for each MAX+1 timer clock cycle. Setting the OCR2A equal to MAX will result in a constantly high or low output (depending on the polarity of the output set by the COM2A1:0 bits.) 144 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 A frequency (with 50% duty cycle) waveform output in fast PWM mode can be achieved by setting OC2x to toggle its logical level on each compare match (COM2x1:0 = 1). The waveform generated will have a maximum frequency of foc2 = fclk_I/O/2 when OCR2A is set to zero. This feature is similar to the OC2A toggle in CTC mode, except the double buffer feature of the output compare unit is enabled in the fast PWM mode. 5.15.6.4 Phase Correct PWM Mode The phase correct PWM mode (WGM22:0 = 1 or 5) provides a high resolution phase correct PWM waveform generation option. The phase correct PWM mode is based on a dual-slope operation. The counter counts repeatedly from BOTTOM to TOP and then from TOP to BOTTOM. TOP is defined as 0xFF when WGM2:0 = 3, and OCR2A when MGM2:0 = 7. In non-inverting compare output mode, the output compare (OC2x) is cleared on the compare match between TCNT2 and OCR2x while upcounting, and set on the compare match while downcounting. In inverting output compare mode, the operation is inverted. The dual-slope operation has lower maximum operation frequency than single slope operation. However, due to the symmetric feature of the dual-slope PWM modes, these modes are preferred for motor control applications. In phase correct PWM mode the counter is incremented until the counter value matches TOP. When the counter reaches TOP, it changes the count direction. The TCNT2 value will be equal to TOP for one timer clock cycle. The timing diagram for the phase correct PWM mode is shown on Figure 5-59. The TCNT2 value is in the timing diagram shown as a histogram for illustrating the dual-slope operation. The diagram includes non-inverted and inverted PWM outputs. The small horizontal line marks on the TCNT2 slopes represent compare matches between OCR2x and TCNT2. Figure 5-59. Phase Correct PWM Mode, Timing Diagram OCnx Interrupt Flag Set OCRnx Update TOVn Interrupt Flag Set TCNTn OCn (COMnx1:0 = 2) OCn (COMnx1:0 = 3) Period 1 2 3 The Timer/Counter overflow flag (TOV2) is set each time the counter reaches BOTTOM. The interrupt flag can be used to generate an interrupt each time the counter reaches the BOTTOM value. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 145 In phase correct PWM mode, the compare unit allows generation of PWM waveforms on the OC2x pin. Setting the COM2x1:0 bits to two will produce a non-inverted PWM. An inverted PWM output can be generated by setting the COM2x1:0 to three. TOP is defined as 0xFF when WGM2:0 = 3, and OCR2A when MGM2:0 = 7 (see Table 5-61 on page 148). The actual OC2x value will only be visible on the port pin if the data direction for the port pin is set as output. The PWM waveform is generated by clearing (or setting) the OC2x register at the compare match between OCR2x and TCNT2 when the counter increments, and setting (or clearing) the OC2x register at compare match between OCR2x and TCNT2 when the counter decrements. The PWM frequency for the output when using phase correct PWM can be calculated by the following equation: f clk_I/O f OCnxPCPWM = ------------------N x 510 The N variable represents the prescale factor (1, 8, 32, 64, 128, 256, or 1024). The extreme values for the OCR2A register represent special cases when generating a PWM waveform output in the phase correct PWM mode. If the OCR2A is set equal to BOTTOM, the output will be continuously low and if set equal to MAX the output will be continuously high for non-inverted PWM mode. For inverted PWM the output will have the opposite logic values. At the very start of period 2 in Figure 5-59 on page 145 OCnx has a transition from high to low even though there is no compare match. The point of this transition is to guarantee symmetry around BOTTOM. There are two cases that give a transition without compare match. OCR2A changes its value from MAX, like in Figure 5-59 on page 145. When the OCR2A value is MAX the OCn pin value is the same as the result of a down-counting compare match. To ensure 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 OCR2A, and for that reason misses the compare match and hence the OCn change that would have happened on the way up. 5.15.7 Timer/Counter Timing Diagrams The following figures show the Timer/Counter in synchronous mode, and the timer clock (clkT2) is therefore shown as a clock enable signal. In asynchronous mode, clkI/O should be replaced by the Timer/Counter oscillator clock. The figures include information on when interrupt flags are set. Figure 5-60 contains timing data for basic Timer/Counter operation. The figure shows the count sequence close to the MAX value in all modes other than phase correct PWM mode. Figure 5-60. Timer/Counter Timing Diagram, no Prescaling clkI/O clkTn (clkI/O/1) TCNTn MAX - 1 TOVn 146 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 MAX BOTTOM BOTTOM + 1 Figure 5-61 shows the same timing data, but with the prescaler enabled. Figure 5-61. Timer/Counter Timing Diagram, with Prescaler (fclk_I/O/8) clkI/O clkTn (clkI/O/8) TCNTn MAX - 1 MAX BOTTOM BOTTOM + 1 TOVn Figure 5-62 shows the setting of OCF2A in all modes except CTC mode. Figure 5-62. Timer/Counter Timing Diagram, Setting of OCF2A, with Prescaler (fclk_I/O/8) clkI/O clkTn (clkI/O/8) TCNTn OCRnx - 1 OCRnx OCRnx OCRnx + 1 OCRnx + 2 OCRnx Value OCFnx Figure 5-63 shows the setting of OCF2A and the clearing of TCNT2 in CTC mode. Figure 5-63. Timer/Counter Timing Diagram, Clear Timer on Compare Match mode, with Prescaler (fclk_I/O/8) clkI/O clkTn (clkI/O/8) TCNTn (CTC) OCRnx TOP - 1 TOP BOTTOM BOTTOM + 1 TOP OCFnx ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 147 5.15.8 8-bit Timer/Counter Register Description 5.15.8.1 Timer/Counter Control Register A - TCCR2A Bit 7 6 5 4 COM2A1 COM2A0 COM2B1 COM2B0 3 2 1 0 - - WGM21 WGM20 Read/Write R/W R/W R/W R/W R R R/W R/W Initial Value 0 0 0 0 0 0 0 0 TCCR2A * Bits 7:6 - COM2A1:0: Compare Match Output A Mode These bits control the output compare pin (OC2A) behavior. If one or both of the COM2A1:0 bits are set, the OC2A output overrides the normal port functionality of the I/O pin it is connected to. However, note that the data direction register (DDR) bit corresponding to the OC2A pin must be set in order to enable the output driver. When OC2A is connected to the pin, the function of the COM2A1:0 bits depends on the WGM22:0 bit setting. Table 5-59 shows the COM2A1:0 bit functionality when the WGM22:0 bits are set to a normal or CTC mode (non-PWM). Table 5-59. Compare Output Mode, non-PWM Mode COM2A1 COM2A0 Description 0 0 Normal port operation, OC0A disconnected. 0 1 Toggle OC2A on compare match 1 0 Clear OC2A on compare match 1 1 Set OC2A on compare match Table 5-60 shows the COM2A1:0 bit functionality when the WGM21:0 bits are set to fast PWM mode. Table 5-60. Compare Output Mode, Fast PWM Mode(1) COM2A1 COM2A0 0 0 Normal port operation, OC2A disconnected. 0 1 WGM22 = 0: Normal port operation, OC0A disconnected. WGM22 = 1: Toggle OC2A on compare match. 1 0 Clear OC2A on compare match, set OC2A at TOP Note: 1 1. Description 1 Set OC2A on compare match, clear OC2A at TOP A special case occurs when OCR2A equals TOP and COM2A1 is set. In this case, the compare match is ignored, but the set or clear is done at TOP. See Section 5.15.6.3 "Fast PWM Mode" on page 144 for more details. Table 5-61 shows the COM2A1:0 bit functionality when the WGM22:0 bits are set to phase correct PWM mode. Table 5-61. Compare Output Mode, Phase Correct PWM Mode() COM2A1 COM2A0 0 0 Normal port operation, OC2A disconnected. 0 1 WGM22 = 0: Normal port operation, OC2A disconnected. WGM22 = 1: Toggle OC2A on compare match. 1 0 Clear OC2A on compare match when up-counting. Set OC2A on compare match when down-counting. 1 Note: 148 1. Description Set OC2A on compare match when up-counting. Clear OC2A on compare match when down-counting. A special case occurs when OCR2A equals TOP and COM2A1 is set. In this case, the compare match is ignored, but the set or clear is done at TOP. See Section 5.15.6.4 "Phase Correct PWM Mode" on page 145 for more details. 1 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 * Bits 5:4 - COM2B1:0: Compare Match Output B Mode These bits control the output compare pin (OC2B) behavior. If one or both of the COM2B1:0 bits are set, the OC2B output overrides the normal port functionality of the I/O pin it is connected to. However, note that the data direction register (DDR) bit corresponding to the OC2B pin must be set in order to enable the output driver. When OC2B is connected to the pin, the function of the COM2B1:0 bits depends on the WGM22:0 bit setting. Table 5-62 shows the COM2B1:0 bit functionality when the WGM22:0 bits are set to a normal or CTC mode (non-PWM). Table 5-62. Compare Output Mode, non-PWM Mode COM2B1 COM2B0 0 0 Description Normal port operation, OC2B disconnected. 0 1 Toggle OC2B on compare match 1 0 Clear OC2B on compare match 1 1 Set OC2B on compare match Table 5-63 shows the COM2B1:0 bit functionality when the WGM22:0 bits are set to fast PWM mode. Table 5-63. Compare Output Mode, Fast PWM Mode(1) COM2B1 COM2B0 0 0 Normal port operation, OC2B disconnected. 0 1 Reserved 1 0 Clear OC2B on compare match, set OC2B at TOP Note: 1 1. Description 1 Set OC2B on compare match, clear OC2B at TOP A special case occurs when OCR2B equals TOP and COM2B1 is set. In this case, the compare match is ignored, but the set or clear is done at TOP. See Section 5.15.6.4 "Phase Correct PWM Mode" on page 145 for more details. Table 5-64 shows the COM2B1:0 bit functionality when the WGM22:0 bits are set to phase correct PWM mode. Table 5-64. Compare Output Mode, Phase Correct PWM Mode(1) COM2B1 COM2B0 0 0 Normal port operation, OC2B disconnected. 0 1 Reserved 1 0 Clear OC2B on compare match when up-counting. Set OC2B on compare match when down-counting. 1 Note: 1. Description Set OC2B on compare match when up-counting. Clear OC2B on compare match when down-counting. A special case occurs when OCR2B equals TOP and COM2B1 is set. In this case, the compare match is ignored, but the set or clear is done at TOP. See Section 5.15.6.4 "Phase Correct PWM Mode" on page 145 for more details. 1 * Bits 3, 2 - Res: Reserved Bits These bits are reserved bits in the Atmel(R) ATA6612C/ATA6613C and will always read as zero. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 149 * Bits 1:0 - WGM21:0: Waveform Generation Mode Combined with the WGM22 bit found in the TCCR2B register, these bits control the counting sequence of the counter, the source for maximum (TOP) counter value, and what type of waveform generation to be used, see Table 5-65. Modes of operation supported by the Timer/Counter unit are: Normal mode (counter), clear timer on compare match (CTC) mode, and two types of pulse width modulation (PWM) modes (see Section 5.15.6 "Modes of Operation" on page 142). Table 5-65. Waveform Generation Mode Bit Description Timer/Counter Mode of Operation TOP Update of OCRx at TOV Flag Set on(1)(2) 0 Normal 0xFF Immediate MAX 0 1 PWM, phase correct 0xFF TOP BOTTOM 0 1 0 CTC OCRA Immediate MAX 3 0 1 1 Fast PWM 0xFF TOP MAX 4 1 0 0 Reserved - - - 5 1 0 1 PWM, phase correct OCRA TOP BOTTOM 6 1 1 0 Reserved - - - 1 1 Fast PWM OCRA TOP TOP Mode WGM2 WGM1 WGM0 0 0 0 1 0 2 7 Notes: 1. 1 MAX = 0xFF 2. BOTTOM = 0x00 5.15.8.2 Timer/Counter Control Register B - TCCR2B Bit 7 6 5 4 3 2 1 0 FOC2A FOC2B - - WGM22 CS22 CS21 CS20 Read/Write W W R R R R R/W R/W Initial Value 0 0 0 0 0 0 0 0 TCCR2B * Bit 7 - FOC2A: Force Output Compare A The FOC2A bit is only active when the WGM bits specify a non-PWM mode. However, for ensuring compatibility with future devices, this bit must be set to zero when TCCR2B is written when operating in PWM mode. When writing a logical one to the FOC2A bit, an immediate compare match is forced on the waveform generation unit. The OC2A output is changed according to its COM2A1:0 bits setting. Note that the FOC2A bit is implemented as a strobe. Therefore it is the value present in the COM2A1:0 bits that determines the effect of the forced compare. A FOC2A strobe will not generate any interrupt, nor will it clear the timer in CTC mode using OCR2A as TOP. The FOC2A bit is always read as zero. * Bit 6 - FOC2B: Force Output Compare B The FOC2B bit is only active when the WGM bits specify a non-PWM mode. However, for ensuring compatibility with future devices, this bit must be set to zero when TCCR2B is written when operating in PWM mode. When writing a logical one to the FOC2B bit, an immediate compare match is forced on the waveform generation unit. The OC2B output is changed according to its COM2B1:0 bits setting. Note that the FOC2B bit is implemented as a strobe. Therefore it is the value present in the COM2B1:0 bits that determines the effect of the forced compare. A FOC2B strobe will not generate any interrupt, nor will it clear the timer in CTC mode using OCR2B as TOP. The FOC2B bit is always read as zero. 150 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 * Bits 5:4 - Res: Reserved Bits These bits are reserved bits in the Atmel(R) ATA6612C/ATA6613C and will always read as zero. * Bit 3 - WGM22: Waveform Generation Mode See the description in Section 5.15.8.1 "Timer/Counter Control Register A - TCCR2A" on page 148. * Bit 2:0 - CS22:0: Clock Select The three clock select bits select the clock source to be used by the Timer/Counter (see Table 5-66). Table 5-66. Clock Select Bit Description CS22 CS21 CS20 Description 0 0 0 No clock source (Timer/Counter stopped). 0 0 1 clkT2S/(no prescaling) 0 1 0 clkT2S/8 (from prescaler) 0 1 1 clkT2S/32 (from prescaler) 1 0 0 clkT2S/64 (from prescaler) 1 0 1 clkT2S/128 (from prescaler) 1 1 0 clkT2S/256 (from prescaler) 1 1 1 clkT2S/1024 (from prescaler) If external pin modes are used for the Timer/Counter0, transitions on the T0 pin will clock the counter even if the pin is configured as an output. This feature allows software control of the counting. 5.15.8.3 Timer/Counter Register - TCNT2 Bit 7 6 5 4 3 2 1 0 TCNT2[7:0] TCNT2 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 The Timer/Counter register gives direct access, both for read and write operations, to the Timer/Counter unit 8-bit counter. Writing to the TCNT2 register blocks (removes) the compare match on the following timer clock. Modifying the counter (TCNT2) while the counter is running, introduces a risk of missing a compare match between TCNT2 and the OCR2x registers. 5.15.8.4 Output Compare Register A - OCR2A Bit 7 6 5 4 3 2 1 0 OCR2A[7:0] OCR2A 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 The output compare register A contains an 8-bit value that is continuously compared with the counter value (TCNT2). A match can be used to generate an output compare interrupt, or to generate a waveform output on the OC2A pin. 5.15.8.5 Output Compare Register B - OCR2B Bit 7 6 5 4 3 2 1 0 OCR2B[7:0] OCR2B 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 The output compare register B contains an 8-bit value that is continuously compared with the counter value (TCNT2). A match can be used to generate an output compare interrupt, or to generate a waveform output on the OC2B pin. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 151 5.15.8.6 Timer/Counter2 Interrupt Mask Register - TIMSK2 Bit 7 6 5 4 3 2 1 0 - - - - - OCIE2B OCIE2A TOIE2 Read/Write R R R R R R/W R/W R/W Initial Value 0 0 0 0 0 0 0 0 TIMSK2 * Bit 2 - OCIE2B: Timer/Counter2 Output Compare Match B Interrupt Enable When the OCIE2B bit is written to one and the I-bit in the status register is set (one), the Timer/Counter2 compare match B interrupt is enabled. The corresponding interrupt is executed if a compare match in Timer/Counter2 occurs, i.e., when the OCF2B bit is set in the Timer/Counter 2 interrupt flag register - TIFR2. * Bit 1 - OCIE2A: Timer/Counter2 Output Compare Match A Interrupt Enable When the OCIE2A bit is written to one and the I-bit in the status register is set (one), the Timer/Counter2 compare match A interrupt is enabled. The corresponding interrupt is executed if a compare match in Timer/Counter2 occurs, i.e., when the OCF2A bit is set in the Timer/Counter 2 interrupt flag register - TIFR2. * Bit 0 - TOIE2: Timer/Counter2 Overflow Interrupt Enable When the TOIE2 bit is written to one and the I-bit in the status register is set (one), the Timer/Counter2 overflow interrupt is enabled. The corresponding interrupt is executed if an overflow in Timer/Counter2 occurs, i.e., when the TOV2 bit is set in the Timer/Counter2 interrupt flag register - TIFR2. 5.15.8.7 Timer/Counter2 Interrupt Flag Register - TIFR2 Bit 7 6 5 4 3 2 1 0 - - - Read/Write R R R - - OCF2B OCF2A TOV2 R R R/W R/W R/W Initial Value 0 0 0 0 0 0 0 0 TIFR2 * Bit 2 - OCF2B: Output Compare Flag 2 B The OCF2B bit is set (one) when a compare match occurs between the Timer/Counter2 and the data in OCR2B - Output compare register2. OCF2B is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, OCF2B is cleared by writing a logic one to the flag. When the I-bit in SREG, OCIE2B (Timer/Counter2 compare match interrupt enable), and OCF2B are set (one), the Timer/Counter2 compare match interrupt is executed. * 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 data in OCR2A - Output compare register2. OCF2A is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, OCF2A is cleared by writing a logic one to the flag. When the I-bit in SREG, OCIE2A (Timer/Counter2 compare match interrupt enable), and OCF2A are set (one), the Timer/Counter2 compare match interrupt is executed. * Bit 0 - TOV2: Timer/Counter2 Overflow Flag The TOV2 bit is set (one) when an overflow occurs in Timer/Counter2. TOV2 is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, TOV2 is cleared by writing a logic one to the flag. When the SREG I-bit, TOIE2A (Timer/Counter2 overflow interrupt enable), and TOV2 are set (one), the Timer/Counter2 overflow interrupt is executed. In PWM mode, this bit is set when Timer/Counter2 changes counting direction at 0x00. 152 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 5.15.9 Asynchronous Operation of the Timer/Counter 5.15.9.1 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 timer registers TCNT2, OCR2x, and TCCR2x might be corrupted. A safe procedure for switching clock source is: a. Disable the Timer/Counter2 interrupts by clearing OCIE2x and TOIE2. b. Select clock source by setting AS2 as appropriate. c. Write new values to TCNT2, OCR2x, and TCCR2x. d. To switch to asynchronous operation: Wait for TCN2xUB, OCR2xUB, and TCR2xUB. e. Clear the Timer/Counter2 interrupt flags. f. Enable interrupts, if needed. The CPU main clock frequency must be more than four times the oscillator frequency. When writing to one of the registers TCNT2, OCR2x, or TCCR2x, the value is transferred to a temporary register, and latched after two positive edges on TOSC1. The user should not write a new value before the contents of the temporary register have been transferred to its destination. Each of the five mentioned registers have their individual temporary register, which means that e.g. writing to TCNT2 does not disturb an OCR2x write in progress. To detect that a transfer to the destination register has taken place, the asynchronous status register - ASSR has been implemented. When entering power-save or ADC noise reduction mode after having written to TCNT2, OCR2x, or TCCR2x, the user must wait until the written register has been updated if Timer/Counter2 is used to wake up the device. Otherwise, the MCU will enter sleep mode before the changes are effective. This is particularly important if any of the output compare2 interrupt is used to wake up the device, since the output compare function is disabled during writing to OCR2x or TCNT2. If the write cycle is not finished, and the MCU enters sleep mode before the corresponding OCR2xUB bit returns to zero, the device will never receive a compare match interrupt, and the MCU will not wake up. If Timer/Counter2 is used to wake the device up from power-save or ADC noise reduction mode, precautions must be taken if the user wants to re-enter one of these modes: The interrupt logic needs one TOSC1 cycle to be reset. If the time between wake-up and re-entering sleep mode is less than one TOSC1 cycle, the interrupt will not occur, and the device will fail to wake up. If the 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: a. Write a value to TCCR2x, TCNT2, or OCR2x. b. Wait until the corresponding update busy flag in ASSR returns to zero. c. Enter power-save or ADC noise reduction mode. When the asynchronous operation is selected, the 32.768kHz oscillator for Timer/Counter2 is always running, except in power-down and standby modes. After a power-up reset or wake-up from power-down or standby mode, the user should be aware of the fact that this oscillator might take as long as one second to stabilize. The user is advised to wait for at least one second before using Timer/Counter2 after power-up or wake-up from power-down or standby mode. The contents of all Timer/Counter2 registers must be considered lost after a wake-up from power-down or standby mode due to unstable clock signal upon start-up, no matter whether the oscillator is in use or a clock signal is applied to the TOSC1 pin. Description of wake up from power-save or ADC noise reduction mode when the timer is clocked asynchronously: When the interrupt condition is met, the wake up process is started on the following cycle of the timer clock, that is, the timer is always advanced by at least one before the processor can read the counter value. After wake-up, the MCU is halted for four cycles, it executes the interrupt routine, and resumes execution from the instruction following SLEEP. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 153 Reading of the TCNT2 register shortly after wake-up from power-save may give an incorrect result. Since TCNT2 is clocked on the asynchronous TOSC clock, reading TCNT2 must be done through a register synchronized to the internal I/O clock domain. Synchronization takes place for every rising TOSC1 edge. When waking up from power-save mode, and the I/O clock (clkI/O) again becomes active, TCNT2 will read as the previous value (before entering sleep) until the next rising TOSC1 edge. The phase of the TOSC clock after waking up from power-save mode is essentially unpredictable, as it depends on the wake-up time. The recommended procedure for reading TCNT2 is thus as follows: a. Write any value to either of the registers OCR2x or TCCR2x. b. Wait for the corresponding update busy flag to be cleared. c. Read TCNT2. During asynchronous operation, the synchronization of the interrupt flags for the asynchronous timer takes 3 processor cycles plus one timer cycle. The timer is therefore advanced by at least one before the processor can read the timer value causing the setting of the interrupt flag. The output compare pin is changed on the timer clock and is not synchronized to the processor clock. 5.15.9.2 Asynchronous Status Register - ASSR Bit 7 6 5 4 3 2 1 0 - EXCLK AS2 TCN2UB OCR2AUB OCR2BUB TCR2AUB TCR2BUB Read/Write R R/W R/W R R R R R Initial Value 0 0 0 0 0 0 0 0 ASSR * Bit 6 - EXCLK: Enable External Clock Input When EXCLK is written to one, and asynchronous clock is selected, the external clock input buffer is enabled and an external clock can be input on timer oscillator 1 (TOSC1) pin instead of a 32kHz crystal. Writing to EXCLK should be done before asynchronous operation is selected. Note that the crystal oscillator will only run when this bit is zero. * Bit 5 - AS2: Asynchronous Timer/Counter2 When AS2 is written to zero, Timer/Counter2 is clocked from the I/O clock, clkI/O. When AS2 is written to one, Timer/Counter2 is clocked from a crystal oscillator connected to the timer oscillator 1 (TOSC1) pin. When the value of AS2 is changed, the contents of TCNT2, OCR2A, OCR2B, TCCR2A and TCCR2B might be corrupted. * Bit 4 - TCN2UB: Timer/Counter2 Update Busy When Timer/Counter2 operates asynchronously and TCNT2 is written, this bit becomes set. When TCNT2 has been updated from the temporary storage register, this bit is cleared by hardware. A logical zero in this bit indicates that TCNT2 is ready to be updated with a new value. * Bit 3 - OCR2AUB: Output Compare Register2 Update Busy When Timer/Counter2 operates asynchronously and OCR2A is written, this bit becomes set. When OCR2A has been updated from the temporary storage register, this bit is cleared by hardware. A logical zero in this bit indicates that OCR2A is ready to be updated with a new value. * Bit 2 - OCR2BUB: Output Compare Register2 Update Busy When Timer/Counter2 operates asynchronously and OCR2B is written, this bit becomes set. When OCR2B has been updated from the temporary storage register, this bit is cleared by hardware. A logical zero in this bit indicates that OCR2B is ready to be updated with a new value. * Bit 1 - TCR2AUB: Timer/Counter Control Register2 Update Busy When Timer/Counter2 operates asynchronously and TCCR2A is written, this bit becomes set. When TCCR2A has been updated from the temporary storage register, this bit is cleared by hardware. A logical zero in this bit indicates that TCCR2A is ready to be updated with a new value. 154 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 * Bit 0 - TCR2BUB: Timer/Counter Control Register2 Update Busy When Timer/Counter2 operates asynchronously and TCCR2B is written, this bit becomes set. When TCCR2B has been updated from the temporary storage register, this bit is cleared by hardware. A logical zero in this bit indicates that TCCR2B is ready to be updated with a new value. If a write is performed to any of the five Timer/Counter2 registers while its update busy flag is set, the updated value might get corrupted and cause an unintentional interrupt to occur. The mechanisms for reading TCNT2, OCR2A, OCR2B, TCCR2A and TCCR2B are different. When reading TCNT2, the actual timer value is read. When reading OCR2A, OCR2B, TCCR2A and TCCR2B the value in the temporary storage register is read. 5.15.10 Timer/Counter Prescaler Figure 5-64. Prescaler for Timer/Counter2 clkT2S/1024 clkT2S/256 clkT2S/128 clkT2S/64 AS2 10-bit T/C Prescaler Clear clkT2S/32 TOSC1 clkT2S clkT2S/8 clkI/O PSRASY 0 CS20 CS21 CS22 Timer/Counter2 Clock Source clkT2 The clock source for Timer/Counter2 is named clkT2S. clkT2S is by default connected to the main system I/O clock clkIO. By setting the AS2 bit in ASSR, Timer/Counter2 is asynchronously clocked from the TOSC1 pin. This enables use of Timer/Counter2 as a real time counter (RTC). When AS2 is set, pins TOSC1 and TOSC2 are disconnected from port C. A crystal can then be connected between the TOSC1 and TOSC2 pins to serve as an independent clock source for Timer/Counter2. The oscillator is optimized for use with a 32.768kHz crystal. Applying an external clock source to TOSC1 is not recommended. For Timer/Counter2, the possible prescaled selections are: clkT2S/8, clkT2S/32, clkT2S/64, clkT2S/128, clkT2S/256, and clkT2S/1024. Additionally, clkT2S as well as 0 (stop) may be selected. Setting the PSRASY bit in GTCCR resets the prescaler. This allows the user to operate with a predictable prescaler. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 155 5.15.10.1 General Timer/Counter Control Register - GTCCR Bit 7 6 5 4 3 2 TSM - - - - - 1 0 Read/Write R/W R R R R R R/W R/W Initial Value 0 0 0 0 0 0 0 0 PSRASY PSRSYNC GTCCR * Bit 1 - PSRASY: Prescaler Reset Timer/Counter2 When this bit is one, the Timer/Counter2 prescaler will be reset. This bit is normally cleared immediately by hardware. If the bit is written when Timer/Counter2 is operating in asynchronous mode, the bit will remain one until the prescaler has been reset. The bit will not be cleared by hardware if the TSM bit is set. Refer to the description of the "Bit 7 - TSM: Timer/Counter Synchronization Mode" for a description of the Timer/Counter synchronization mode. 5.16 Serial Peripheral Interface - SPI The serial peripheral interface (SPI) allows high-speed synchronous data transfer between the Atmel(R) ATA6612C/ATA6613C and peripheral devices or between several AVR(R) devices. The Atmel ATA6612C/ATA6613C SPI includes the following 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 Write collision flag protection Wake-up from idle mode Double speed (CK/2) master SPI mode The USART can also be used in master SPI mode (see Section 5.18 "USART in SPI Mode" on page 186). The PRSPI bit in Section 5.7.7.1 "Power Reduction Register - PRR" on page 58 must be written to zero to enable SPI module. 156 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 Figure 5-65. SPI Block Diagram(1) MISO S clkI/O MSB M M LSB 8-Bit Shift Register Read Data Buffer Pin Control Logic Divider /2/4/8/16/32/64/128 Clock SPI Clock (Master) SPR0 DORD SPR0 SPR1 CPHA CPOL SPI Control Register 8 SPI Interrupt Request MSTR SPIE SPI Status Register DORD SPI2X 8 SPE MSTR SPE WCOL SPIF SPE MSTR SPR1 SPI2X M SS SPI Control 1. SCK S Clock Logic Select Note: MOSI S 8 Internal Data Bus Refer to Table 5-32 on page 84 for SPI pin placement. The interconnection between master and slave CPUs with SPI is shown in Figure 5-66 on page 158. The system consists of two shift registers, and a master clock generator. The SPI master initiates the communication cycle when pulling low the slave select SS pin of the desired slave. master and slave prepare the data to be sent in their respective shift registers, and the master generates the required clock pulses on the SCK line to interchange data. Data is always shifted from master to slave on the master out - slave In, MOSI, line, and from slave to master on the master in - slave out, MISO, line. After each data packet, the master will synchronize the slave by pulling high the slave select, SS, line. When configured as a master, the SPI interface has no automatic control of the SS line. This must be handled by user software before communication can start. When this is done, writing a byte to the SPI data register starts the SPI clock generator, and the hardware shifts the eight bits into the slave. After shifting one byte, the SPI clock generator stops, setting the end of transmission flag (SPIF). If the SPI interrupt enable bit (SPIE) in the SPCR register is set, an interrupt is requested. The master may continue to shift the next byte by writing it into SPDR, or signal the end of packet by pulling high the slave select, SS line. The last incoming byte will be kept in the buffer register for later use. When configured as a slave, the SPI interface will remain sleeping with MISO tri-stated as long as the SS pin is driven high. In this state, software may update the contents of the SPI data register, SPDR, but the data will not be shifted out by incoming clock pulses on the SCK pin until the SS pin is driven low. As one byte has been completely shifted, the end of transmission 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. The last incoming byte will be kept in the buffer register for later use. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 157 Figure 5-66. SPI Master-slave Interconnection MSB MASTER LSB MISO MISO 8 Bit Shift Register SPI Clock Generator MSB SLAVE LSB 8 Bit Shift Register MOSI MOSI SCK SCK SS Shift Enable SS The system is single buffered in the transmit direction and double buffered in the receive direction. This means that bytes to be transmitted cannot be written to the SPI data register before the entire shift cycle is completed. When receiving data, however, a received character must be read from the SPI data register before the next character has been completely shifted in. Otherwise, the first byte is lost. In SPI slave mode, the control logic will sample the incoming signal of the SCK pin. To ensure correct sampling of the clock signal, the frequency of the SPI clock should never exceed fosc/4. When the SPI is enabled, the data direction of the MOSI, MISO, SCK, and SS pins is overridden according to Table 5-67. For more details on automatic port overrides, refer to Section 5.10.3 "Alternate Port Functions" on page 81. Table 5-67. SPI Pin Overrides(1) Pin Direction, Master SPI Direction, Slave SPI MOSI User defined Input MISO Input User defined SCK User defined Input SS Note: 1. 158 User defined Input See Section 5.10.3.2 "Alternate Functions of Port B" on page 84 for a detailed description of how to define the direction of the user defined SPI pins. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 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 and DD_SCK must be replaced by the actual data direction bits for these pins. E.g. if MOSI is placed on pin PB5, replace DD_MOSI with DDB5 and DDR_SPI with DDRB. Assembly Code Example(1) SPI_MasterInit: ; Set MOSI and SCK output, all others input ldi r17,(1<>8); UBRRnL = (unsigned char)baud; /* Enable receiver and transmitter */ UCSRnB = (1<> 1) & 0x01; return ((resh << 8) | resl); } Note: 1. The example code assumes that the part specific header file is included. For I/O registers located in extended I/O map, "IN", "OUT", "SBIS", "SBIC", "CBI", and "SBI" instructions must be replaced with instructions that allow access to extended I/O. Typically "LDS" and "STS" combined with "SBRS", "SBRC", "SBR", and "CBR". The receive function example reads all the I/O registers into the register file before any computation is done. This gives an optimal receive buffer utilization since the buffer location read will be free to accept new data as early as possible. 174 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 5.17.6.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 buffer. This flag is one when unread data exist in the receive buffer, and zero when the receive buffer is empty (i.e., does not contain any unread data). If the receiver is disabled (RXENn = 0), the receive buffer will be flushed and consequently the RXCn bit will become zero. When the receive complete Interrupt enable (RXCIEn) in UCSRnB is set, the USART receive complete interrupt will be executed as long as the RXCn flag is set (provided that global interrupts are enabled). When interrupt-driven data reception is used, the receive complete routine must read the received data from UDRn in order to clear the RXCn flag, otherwise a new interrupt will occur once the interrupt routine terminates. 5.17.6.4 Receiver Error Flags The USART receiver has three error flags: Frame error (FEn), data overrun (DORn) and parity error (UPEn). All can be accessed by reading UCSRnA. Common for the error flags is that they are located in the receive buffer together with the frame for which they indicate the error status. Due to the buffering of the error flags, the UCSRnA must be read before the receive buffer (UDRn), since reading the UDRn I/O location changes the buffer read location. Another equality for the error flags is that they can not be altered by software doing a write to the flag location. However, all flags must be set to zero when the UCSRnA is written for upward compatibility of future USART implementations. None of the error flags can generate interrupts. The frame error (FEn) flag indicates the state of the first stop bit of the next readable frame stored in the receive buffer. The FEn flag is zero when the stop bit was correctly read (as one), and the FEn flag will be one when the stop bit was incorrect (zero). This flag can be used for detecting out-of-sync conditions, detecting break conditions and protocol handling. The FEn flag is not affected by the setting of the USBSn bit in UCSRnC since the receiver ignores all, except for the first, stop bits. For compatibility with future devices, always set this bit to zero when writing to UCSRnA. The data overrun (DORn) flag indicates data loss due to a receiver buffer full condition. A data overrun occurs when the receive buffer is full (two characters), it is a new character waiting in the receive shift register, and a new start bit is detected. If the DORn flag is set there was one or more serial frame lost between the frame last read from UDRn, and the next frame read from UDRn. For compatibility with future devices, always write this bit to zero when writing to UCSRnA. The DORn flag is cleared when the frame received was successfully moved from the shift register to the receive buffer. The parity error (UPEn) flag indicates that the next frame in the receive buffer had a parity error when received. If parity check is not enabled the UPEn bit will always be read zero. For compatibility with future devices, always set this bit to zero when writing to UCSRnA. For more details see Section 5.17.3.1 "Parity Bit Calculation" on page 169 and Section 5.17.6.5 "Parity Checker" on page 175. 5.17.6.5 Parity Checker The parity checker is active when the high USART parity mode (UPMn1) bit is set. Type of parity check to be performed (odd or even) is selected by the UPMn0 bit. When enabled, the parity checker calculates the parity of the data bits in incoming frames and compares the result with the parity bit from the serial frame. The result of the check is stored in the receive buffer together 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 read from the receive buffer had a parity error when received and the parity checking was enabled at that point (UPMn1 = 1). This bit is valid until the receive buffer (UDRn) is read. 5.17.6.6 Disabling the Receiver In contrast to the transmitter, disabling of the receiver will be immediate. Data from ongoing receptions will therefore be lost. When disabled (i.e., the RXENn is set to zero) the receiver will no longer override the normal function of the RxDn port pin. The receiver buffer FIFO will be flushed when the receiver is disabled. Remaining data in the buffer will be lost. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 175 5.17.6.7 Flushing the Receive Buffer The receiver buffer FIFO will be flushed when the receiver is disabled, i.e., the buffer will be emptied of its contents. Unread data will be lost. If the buffer has to be flushed during normal operation, due to for instance an error condition, read the UDRn I/O location until the RXCn flag is cleared. The following code example shows how to flush the receive buffer. Assembly Code Example(1) USART_Flush: sbis UCSRnA, RXCn ret in r16, UDRn rjmp USART_Flush C Code Example(1) void USART_Flush (void) { unsigned char dummy; while (UCSRnA & (1< 2 CPU clock cycles for fck < 12MHz, 3 CPU clock cycles for fck 12MHz High: > 2 CPU clock cycles for fck < 12MHz, 3 CPU clock cycles for fck 12MHz 5.24.8.1 Serial Programming Algorithm When writing serial data to the Atmel(R) ATA6612C/ATA6613C, data is clocked on the rising edge of SCK. When reading data from the Atmel ATA6612C/ATA6613C, data is clocked on the falling edge of SCK. See Figure 5-127 on page 269 for timing details. To program and verify the Atmel ATA6612C/ATA6613C in the serial programming mode, the following sequence is recommended (see four byte instruction formats in Table 5-129 on page 269): 1. Power-up sequence: Apply power between VCC and GND while RESET and SCK are set to "0". In some systems, the programmer can not guarantee that SCK is held low during power-up. In this case, RESET must be given a positive pulse of at least two CPU clock cycles duration after SCK has been set to "0". 2. Wait for at least 20ms and enable serial programming by sending the programming enable serial instruction to pin MOSI. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 267 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 6 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 8 MSB of the address. If polling is not used, the user must wait at least tWD_FLASH before issuing the next page (see Table 5-128 on page 268). Accessing the serial programming interface before the flash write operation completes can result in incorrect programming. 5. The EEPROM array is programmed one byte at a time by supplying the address and data together with the appropriate write instruction. An EEPROM memory location is first automatically erased before new data is written. If polling is not used, the user must wait at least tWD_EEPROM before issuing the next byte (see Table 5-128 on page 268). In a chip erased device, no 0xFFs in the data file(s) need to be programmed. 6. Any memory location can be verified by using the read instruction which returns the content at the selected address at serial output MISO. 7. At the end of the programming session, RESET can be set high to commence normal operation. 8. Power-off sequence (if needed): Set RESET to "1". Turn VCC power off. 5.24.8.2 Data Polling Flash When a page is being programmed into the flash, reading an address location within the page being programmed will give the value 0xFF. At the time the device is ready for a new page, the programmed value will read correctly. This is used to determine when the next page can be written. Note that the entire page is written simultaneously and any address within the page can be used for polling. Data polling of the flash will not work for the value 0xFF, so when programming this value, the user will have to wait for at least tWD_FLASH before programming the next page. As a chip-erased device contains 0xFF in all locations, programming of addresses that are meant to contain 0xFF, can be skipped. See Table 5-128 on page 268 for tWD_FLASH value. 5.24.8.3 Data Polling EEPROM When a new byte has been written and is being programmed into EEPROM, reading the address location being programmed will give the value 0xFF. At the time the device is ready for a new byte, the programmed value will read correctly. This is used to determine when the next byte can be written. This will not work for the value 0xFF, but the user should have the following in mind: As a chip-erased device contains 0xFF in all locations, programming of addresses that are meant to contain 0xFF, can be skipped. This does not apply if the EEPROM is re-programmed without chip erasing the device. In this case, data polling cannot be used for the value 0xFF, and the user will have to wait at least tWD_EEPROM before programming the next byte. See Table 5-128 for tWD_EEPROM value. Table 5-128. Minimum Wait Delay Before Writing the Next Flash or EEPROM Location 268 Symbol Minimum Wait Delay tWD_FLASH 4.5ms tWD_EEPROM 3.6ms tWD_ERASE 9.0ms ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 Figure 5-127. Serial Programming Waveforms SERIAL DATA INPUT (MOSI) MSB LSB SERIAL DATA OUTPUT (MISO) MSB LSB SERIAL CLOCK INPUT (SCK) SAMPLE Table 5-129. Serial Programming Instruction Set Instruction Format Instruction Byte 1 Byte 2 Byte 3 Byte4 Programming enable 1010 1100 0101 0011 xxxx xxxx xxxx xxxx Enable serial programming after RESET goes low. Chip erase 1010 1100 100x xxxx xxxx xxxx xxxx xxxx Chip erase EEPROM and flash. Read program memory 0010 H000 000a aaaa Read H (high or low) data o from bbbb bbbb oooo oooo Program memory at word address a:b. Load program memory page 0100 H000 000x xxxx xxbb bbbb iiii iiii Write H (high or low) data i to program memory page at word address b. Data low byte must be loaded before data high byte is applied within the same address. Write program memory page 0100 1100 000a aaaa bbxx xxxx xxxx xxxx Read EEPROM memory 1010 0000 000x xxaa bbbb bbbb oooo oooo Read data o from EEPROM memory at address a:b. Write EEPROM memory 1100 0000 000x xxaa bbbb bbbb iiii iiii Write data i to EEPROM memory at address a:b. Load EEPROM memory Page (page access) 1100 0001 0000 0000 0000 00bb iiii iiii Load data i to EEPROM memory page buffer. After data is loaded, program EEPROM page. Write EEPROM memory Page (page access) 1100 0010 00xx xxaa bbbb bb00 xxxx xxxx Read lock bits 0101 1000 0000 0000 xxxx xxxx Write lock bits 1010 1100 111x xxxx xxxx xxxx Read signature byte 0011 0000 000x xxxx xxxx xxbb Write fuse bits 1010 1100 1010 0000 xxxx xxxx Write program memory page at address a:b. Write EEPROM page at address a:b. Read Lock bits. "0" = programmed, xxoo oooo "1" = unprogrammed. See Table 5114 on page 253 for details. 11ii iiii Write lock bits. Set bits = "0" to program lock bits. See Table 5-114 on page 253 for details. oooo oooo Read signature byte o at address b. iiii iiii Set bits = "0" to program, "1" to unprogram. See Table XXX on page XXX for details. Set bits = "0" to program, "1" to unprogram. See Table 5-98 on page 229 for details. a = address high bits, b = address low bits, H = 0 - Low byte, 1 - High Byte, o = data out, i = data in, x = do not care Write fuse high bits Note: Operation 1010 1100 1010 1000 xxxx xxxx iiii iiii ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 269 Table 5-129. Serial Programming Instruction Set (Continued) Instruction Format Instruction Byte 1 Byte 2 Byte 3 Byte4 Write extended fuse bits 1010 1100 1010 0100 xxxx xxxx xxxx xxii Read fuse bits 0101 0000 0000 0000 xxxx xxxx Read fuse bits. "0" = programmed, "1" oooo oooo = unprogrammed. See Table XXX on page XXX for details. xxxx xxxx Read fuse high bits. "0"=programmed, oooo oooo "1" = unprogrammed. See Table 5-98 on page 229 for details. Read fuse high bits 0101 1000 0000 1000 Operation Set bits = "0" to program, "1" to unprogram. See Table 5-117 on page 254 for details. Read extended fuse bits 0101 0000 0000 1000 xxxx xxxx Read extended fuse bits. "0" = programmed, "1" = unprogrammed. oooo oooo See Table 5-117 on page 254 for details. Read calibration byte 0011 1000 000x xxxx 0000 0000 oooo oooo Read calibration byte If o = "1", a programming operation is still busy. Wait until this bit returns to Poll RDY/BSY 1111 0000 0000 0000 xxxx xxxx xxxx xxxo "0" before applying another command. Note: a = address high bits, b = address low bits, H = 0 - Low byte, 1 - High Byte, o = data out, i = data in, x = do not care 5.24.8.4 SPI Serial Programming Characteristics For characteristics of the SPI module see Section 6.1 "SPI Timing Characteristics" on page 278. 270 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 5.25 Electrical Characteristics 5.25.1 DC Characteristics Tcase = -40C to +125C, VCC = 2.7V to 5.5V (unless otherwise noted) Symbol Min.(5) Max.(5) Units VCC = 2.7V to 5.5V VIL -0.5 0.3VCC(1) V Input low voltage, XTAL1 pin VCC = 2.7V to 5.5V VIL1 -0.5 0.1VCC(1) V Input low voltage, RESET pin VCC = 2.7V to 5.5V VIL2 -0.5 0.1VCC(1) V Input high voltage, except XTAL1 and RESET pins VCC = 2.7V to 5.5V VIH 0.6VCC(2) VCC + 0.5 V Input high voltage, XTAL1 pin VCC = 2.7V to 5.5V VIH1 0.7VCC(2) VCC + 0.5 V Input high voltage, RESET VCC = 2.7V to 5.5V pin VIH2 0.9VCC(2) VCC + 0.5 V 0.8 0.5 V Parameter Condition Input low voltage, except XTAL1 and reset pin Typ. Output low voltage(3) IOL = 20mA, VCC = 5V IOL = 5mA, VCC = 3V VOL Output high voltage(4) IOH = -20mA, VCC = 5V IOH = -10mA, VCC = 3V VOH Input leakage Current I/O pin VCC = 5.5V, pin low (absolute value) IIL 50 nA Input leakage Current I/O pin VCC = 5.5V, pin high (absolute value) IIH 50 nA Reset pull-up resistor VCC = 5.0V, VIN = 0V RRST 60 k 50 k 4.1 2.3 V 30 I/O pin pull-up resistor RPU 20 Notes: 1. "Max" means the highest value where the pin is guaranteed to be read as low 2. "Min" means the lowest value where the pin is guaranteed to be read as high 3. Although each I/O port can sink more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed: Atmel ATA6612C/ATA6613C: 1] The sum of all IOL, for ports C0 - C5, should not exceed 100mA. 2] The sum of all IOL, for ports C6, D0 - D4, should not exceed 100mA. 3] The sum of all IOL, for ports B0 - B7, D5 - D7, should not exceed 100mA. 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. 4. Although each I/O port can source more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed: Atmel ATA6612C/ATA6613C: 1] The sum of all IOH, for ports C0 - C5, should not exceed 100mA. 2] The sum of all IOH, for ports C6, D0 - D4, should not exceed 100mA. 3] The sum of all IOH, for ports B0 - B7, D5 - D7, should not exceed 100mA. If IOH exceeds the test condition, VOH may exceed the related specification. Pins are not guaranteed to source current greater than the listed test condition. 5. All DC Characteristics contained in this datasheet are based on actual Atmel ATA6612C microcontrollers characterization. 6. Values with "Power Reduction REgister - PRR" enabled (0xEF). ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 271 5.25.1 DC Characteristics (Continued) Tcase = -40C to +125C, VCC = 2.7V to 5.5V (unless otherwise noted) Parameter Typ. Max.(5) Units Active 4MHz, VCC = 3V (ATA6612C/ATA6613CL) 1.8 3.0 mA Active 8MHz, VCC = 5V (ATA6612C/ATA6613C) 6.0 10 mA Active 15MHz, VCC = 5V (ATA6612C/ATA6613C) 10.0 16 mA Idle 4MHz, VCC = 3V (ATA6612C/ATA6613CV) 0.4 1 mA 1.4 2.4 mA 2.8 4 mA WDT enabled, VCC = 3V 8 30 A WDT enabled, VCC = 5V 12.6 50 A WDT disabled, VCC = 3V 5 24 A WDT disabled, VCC = 5V 6.6 36 A 10 40 mV 50 nA Condition Power supply current (2) Idle 8MHz, VCC = 5V (ATA6612C/ATA6613CL) Symbol Min.(5) ICC Idle 15MHz, VCC = 5V (ATA6612C/ATA6613C) Power-down mode Analog comparator Input offset voltage VCC = 5V Vin = VCC/2 VACIO Analog comparator Input leakage current VCC = 5V Vin = VCC/2 IACLK -50 Analog comparator VCC = 4.5V tACID 140 propagation delay Notes: 1. "Max" means the highest value where the pin is guaranteed to be read as low 272 ns 2. "Min" means the lowest value where the pin is guaranteed to be read as high 3. Although each I/O port can sink more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed: Atmel ATA6612C/ATA6613C: 1] The sum of all IOL, for ports C0 - C5, should not exceed 100mA. 2] The sum of all IOL, for ports C6, D0 - D4, should not exceed 100mA. 3] The sum of all IOL, for ports B0 - B7, D5 - D7, should not exceed 100mA. 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. 4. Although each I/O port can source more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed: Atmel ATA6612C/ATA6613C: 1] The sum of all IOH, for ports C0 - C5, should not exceed 100mA. 2] The sum of all IOH, for ports C6, D0 - D4, should not exceed 100mA. 3] The sum of all IOH, for ports B0 - B7, D5 - D7, should not exceed 100mA. If IOH exceeds the test condition, VOH may exceed the related specification. Pins are not guaranteed to source current greater than the listed test condition. 5. All DC Characteristics contained in this datasheet are based on actual Atmel ATA6612C microcontrollers characterization. 6. Values with "Power Reduction REgister - PRR" enabled (0xEF). ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 5.25.2 External Clock Drive Waveforms Figure 5-128. External Clock Drive Waveforms tCHCX tCLCH tCHCX tCHCL VIH1 VIL1 tCLCX tCLCL 5.25.3 External Clock Drive Table 5-130. External Clock Drive VCC = 2.7V to 5.5V VCC = 4.5V to 5.5V Symbol Min. Max. Min. Max. Units 1/tCLCL 0 8 0 16 MHz Clock period tCLCL 125 62.5 ns High time tCHCX 50 25 ns Low time tCLCX 50 Rise time tCLCH 1.6 0.5 s Fall time tCHCL 1.6 0.5 s Change in period from one clock cycle to the next tCLCL 2 2 % Parameter Oscillator frequency 25 ns 5.25.4 Maximum Speed versus VCC Maximum frequency is dependent on VCC. As shown in Figure 5-129, the maximum frequency versus VCC curve is linear between 2.7V < VCC < 4.5V. Figure 5-129. Maximum Frequency versus VCC, Atmel ATA6612C/ATA6613C 16MHz 8MHz Safe Operating Area 2.7V 4.5V 5.5V ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 273 5.26 LIN Re-synchronization Algorithm 5.26.1 Synchronization Algorithm The possibility to change the value of OSCCAL during the oscillator operation allows for in-situ calibration of the slave node to entering master frames. The principle of operation is to measure the TBit during the SYNCH byte and to change the calibration value of OSCCAL to recover from local frequency drifts due to local voltage or temperature deviation. The algorithm used for the synchronization of the internal RC oscillator is depicted in Figure 5-130. Figure 5-130. Dichotomic Algorithm Used for LIN Slave Clock Re-synchronization Measuring actual TBit -2% < Delta(TBit) < 2% N Decrement OSCCAL Delta(TBit) > 2% N Increment OSCCAL 274 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 Delta(TBit) < -2% Y STOP: Oscillator Calibrated 5.26.2 Precaution Against OSCCAL Discontinuity The Figure 6-26 on page 288 illustrates the on-purpose discontinuity of RC frequency versus OSCCAL value. For one correct re-synchronization, the frequency change must be kept on the same side of the discontinuity (no change of OSCCAL[7]). Since there will be no device having frequency changed by more than 10% (see Figure 6-24 on page 287), thus no reason to change the frequency value by more than 10%. Therefore, when calibration tries to cross the border because of subsequent increase (or decrease) in OSCCAL values, then the routine must be stopped. Example: For parts operating in the lower part of the curve, if New_OSCCAL > 127 then New_OSCCAL = 127. Similar for parts operating on the high side of the discontinuity. 5.26.2.1 RC Oscillator Precision for LIN Slave implementation For LIN slave devices, the precision of the RC oscillator before and after re-synchronization are described in the Table 5-131. Table 5-131. Oscillator Tolerance Before and After Re-synchronization Algorithm (2.7V < VCC < 5.5V, -40C to +125C) F/FMaster Parameter Clock Tolerance FTOL_UNSYNCH Deviation of slave node clock from the nominal clock rate before synchronization; relevant for nodes making use of synchronization and direct SYNCH BREAK detection. FTOL_SYNCH Deviation of slave node clock relative to the master node clock after synchronization; relevant for nodes making use of synchronization; any slave node must stay within this tolerance for all fields of a frame which follow the SYNCH FIELD. Note: 14.0% 2.0% For communication between any two nodes their bit rate must not differ by more than 2%. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 275 6. 2-wire Serial Interface Characteristics Table 6-1 describes the requirements for devices connected to the 2-wire serial bus. The Atmel(R) ATA6612C/ATA6613C 2-wire serial interface meets or exceeds these requirements under the noted conditions. Timing symbols refer to Figure 6-1 on page 277. Table 6-1. 2-wire Serial Bus Requirements Parameter Condition Input low-voltage Input high-voltage Hysteresis of schmitt trigger inputs Output low-voltage 3mA sink current 10pF < Cb < 400pF 0.1VCC < Vi < 0.9VCC Capacitance for each I/O pin SCL clock frequency Max Units VIL -0.5 0.3 VCC V VIH 0.7 VCC VCC + 0.5 V Vhys(1) 0.05 VCC(2) - V 0 0.4 V 300 ns tr (3) Spikes suppressed by input filter Input current each I/O pin Min VOL Rise time for both SDA and SCL Output fall time from VIHmin to VILmax Symbol (1) (1) tof fCK > max(16fSCL, 250kHz)(5) 250 ns 0 50(2) ns Ii -10 10 A - 10 pF fSCL 0 400 kHz V CC - 0,4V --------------------------3mA 1000ns ----------------Cb V CC - 0,4V --------------------------3mA 300ns -------------Cb 4.0 - s 0.6 - s 4.7 - s 1.3 - s 4.0 - s 0.6 - s 4.7 - s 0.6 - s 0 3.45 s 0 0.9 s 250 - ns - ns Rp fSCL > 100kHz Hold time (repeated) START condition Low period of the SCL clock High period of the SCL clock Set-up time for a repeated START condition Data hold time Data setup time Notes: 276 1. fSCL 100kHz tHD;STA fSCL > 100kHz fSCL 100kHz(6) fSCL > 100kHz fSCL 100kHz fSCL > 100kHz fSCL 100kHz fSCL > 100kHz fSCL 100kHz fSCL > 100kHz fSCL 100kHz (7) 20 + (1) fSCL 100kHz Value of pull-up resistor 20 + 0.1Cb(2,3) 0.1Cb(2,3) tSP(1) Ci (4) (1) tLOW tHIGH tSU;STA tHD;DAT tSU;DAT fSCL > 100kHz 100 In Atmel ATA6612C/ATA6613C, this parameter is characterized and not 100% tested. 2. Required only for fSCL > 100kHz. 3. Cb = capacitance of one bus line in pF. 4. fCK = CPU clock frequency 5. This requirement applies to all Atmel ATA6612C/ATA6613C 2-wire serial interface operation. Other devices connected to the 2-wire serial bus need only obey the general fSCL requirement. 6. The actual low period generated by the Atmel ATA6612C/ATA6613C 2-wire serial interface is (1/fSCL - 2/fCK), thus fCK must be greater than 6MHz for the low time requirement to be strictly met at fSCL = 100kHz. 7. The actual low period generated by the Atmel ATA6612C/ATA6613C 2-wire serial interface is (1/fSCL - 2/fCK), thus the low time requirement will not be strictly met for fSCL > 308kHz when fCK = 8MHz. Still, Atmel ATA6612C/ATA6613C devices connected to the bus may communicate at full speed (400kHz) with other Atmel ATA6612C/ATA6613C devices, as well as any other device with a proper tLOW acceptance margin. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 Table 6-1. 2-wire Serial Bus Requirements (Continued) Parameter Condition fSCL 100kHz Setup time for STOP condition 1. tSU;STO fSCL > 100kHz fSCL 100kHz Bus free time between a STOP and START condition Notes: Symbol tBUF Min Max Units 4.0 - s 0.6 - s 4.7 - s - s fSCL > 100kHz 1.3 In Atmel ATA6612C/ATA6613C, this parameter is characterized and not 100% tested. 2. Required only for fSCL > 100kHz. 3. Cb = capacitance of one bus line in pF. 4. fCK = CPU clock frequency 5. This requirement applies to all Atmel ATA6612C/ATA6613C 2-wire serial interface operation. Other devices connected to the 2-wire serial bus need only obey the general fSCL requirement. 6. The actual low period generated by the Atmel ATA6612C/ATA6613C 2-wire serial interface is (1/fSCL - 2/fCK), thus fCK must be greater than 6MHz for the low time requirement to be strictly met at fSCL = 100kHz. 7. The actual low period generated by the Atmel ATA6612C/ATA6613C 2-wire serial interface is (1/fSCL - 2/fCK), thus the low time requirement will not be strictly met for fSCL > 308kHz when fCK = 8MHz. Still, Atmel ATA6612C/ATA6613C devices connected to the bus may communicate at full speed (400kHz) with other Atmel ATA6612C/ATA6613C devices, as well as any other device with a proper tLOW acceptance margin. Figure 6-1. 2-wire Serial Bus Timing tof tHIGH tLOW tr tLOW SCL tSU,STA tHD,STA tHD,DAT tSU,DAT tSU,STO SDA tBUF ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 277 6.1 SPI Timing Characteristics See Figure 6-2 and Figure 6-3 on page 279 for details. Table 6-2. SPI Timing Parameters Description Mode Min Typ Max 1 SCK period Master See Table 5-70 on page 162 2 SCK high/low Master 50% duty cycle 3 Rise/fall time Master 3.6 4 Setup Master 10 5 Hold Master 10 6 Out to SCK Master 0.5 x tsck 7 SCK to out Master 10 8 SCK to out high Master 10 9 SS low to out Slave 15 10 SCK period Slave 4 x tck 11 SCK high/low(1) Slave 2 x tck 12 Rise/fall time Slave 13 Setup Slave 10 14 Hold Slave tck 15 SCK to out Slave 16 SCK to SS high Slave 17 SS high to tri-state Slave ns 1600 15 20 10 18 SS low to SCK Slave 20 Note: 1. In SPI programming mode the minimum SCK high/low period is: - 2 tCLCL for fCK < 12MHz - 3 tCLCL for fCK > 12MHz Figure 6-2. SPI Interface Timing Requirements (Master Mode) SS 6 1 SCK (CPOL = 0) 2 2 SCK (CPOL = 1) 4 MISO (Data Input) 5 3 ... MSB LSB 8 7 MOSI (Data Output) 278 MSB ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 ... LSB Figure 6-3. SPI Interface Timing Requirements (Slave Mode) SS 16 10 9 SCK (CPOL = 0) 11 11 SCK (CPOL = 1) 13 MOSI (Data Input) 14 12 ... MSB LSB 17 15 MISO (Data Output) 6.2 ... MSB LSB X ADC Characteristics Table 6-3. ADC Characteristics Parameter Condition Symbol Min Resolution Typ Max Units 10 Bits VREF = 4V, VCC = 4V, ADC clock = 200kHz 2 3.5 LSB VREF = 4V, VCC = 4V, ADC clock = 200kHz Noise reduction mode 2 3.5 LSB Integral non-linearity (INL) VREF = 4V, VCC = 4V, ADC clock = 200kHz 0.6 2.5 LSB Differential non-linearity (DNL) VREF = 4V, VCC = 4V, ADC clock = 200kHz 0.40 1.0 LSB Gain error VREF = 4V, VCC = 4V, ADC clock = 200kHz -1.3 3.5 LSB Offset error VREF = 4V, VCC = 4V, ADC clock = 200kHz 1.8 3.5 LSB Conversion time Free running conversion 50 200 kHz Absolute accuracy (including INL, DNL, quantization error, gain and offset error) -3.5 13 cycles Clock frequency s Analog supply voltage AVCC VCC - 0.3 VCC + 0.3 V Reference voltage VREF 1.0 AVCC V Input voltage VIN GND VREF V Internal voltage reference VINT 1.0 1.1 1.2 V Reference input resistance RREF 22.4 32 41.6 k Analog input resistance RAIN 100 M ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 279 6.3 Atmel ATA6612C/ATA6613C Typical Characteristics Note: 6.3.1 Values of temp refer to Tcase. Active Supply Current Figure 6-4. Active Supply Current versus Frequency (1MHz to 20MHz), Temp = 125C 20 18 16 5.5V ICC (mA) 14 5.0V 12 4.5V 10 8 3.3V 3.0V 6 2.7V 4 2 0 0 2 4 6 8 10 12 14 16 18 20 Frequency (MHz) Figure 6-5. Idle Supply Current versus Frequency (1MHz to 20MHz), Temp = 125C 6 4 ICC (mA) 5.5V 5.0V 4.5V 3.3V 3.0V 2.7V 2 0 0 2 4 6 8 10 12 Frequency (MHz) 280 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 14 16 18 20 6.3.1.1 Power-down Supply Current Figure 6-6. Power-down Supply Current versus VCC (Watchdog Timer Disabled) 8 7 ICC (A) 6 125 5 85 4 25 -40 3 2 1 0 3 3.5 4 4.5 5 5.5 VCC (V) Figure 6-7. Power-down Supply Current versus VCC (Watchdog Timer Enabled) 8 7 ICC (A) 6 125 5 85 4 25 -40 3 2 1 0 2.5 3 3.5 4 4.5 5 5.5 VCC (V) ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 281 6.3.1.2 Pin Pull-up Figure 6-8. I/O Pin Pull-up Resistor Current versus Input Voltage (VCC = 5V) 160 125 140 -40 IOP (A) 120 100 80 60 40 20 0 0 1 2 3 4 5 6 VOP (V) Figure 6-9. Output Low Voltage versus Output Low Current (VCC = 5V) 0.8 0.7 125C 0.6 85C VOL (V) 0.5 25C 0.4 -40C 0.3 0.2 0.1 0 0 2 4 6 8 10 12 14 16 18 20 IOL (mA) Figure 6-10. Output Low Voltage versus Output Low Current (VCC = 3V) 1.2 125C 1.0 85C IOL (mA) 0.8 25C 0.6 -40C 0.4 0.2 0 0 2 4 6 8 10 VOL (V) 282 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 12 14 16 18 20 Figure 6-11. Output High Voltage versus Output High Current (VCC = 5V) 5.2 5 VOH (V) 4.8 4.6 -40C 25C 85C 125C 4.4 4.2 4 0 2 4 6 8 10 12 14 16 18 20 IOH (mA) Figure 6-12. Output High Voltage versus Output High Current (VCC = 3V) 3.5 3 Current (V) 2.5 -40C 25C 85C 125C 2 1.5 1 0.5 0 0 2 4 6 8 10 12 14 16 18 20 IOH (mA) Figure 6-13. Reset Pull-Up Resistor Current versus Reset Pin Voltage (VCC = 5V) 160 125 140 120 -40 IOP (A) 100 80 60 40 20 0 0 1 2 3 4 5 6 VOP (V) ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 283 6.3.1.3 Pin Driver Strength Figure 6-14. Output Low Voltage versus Output Low Current (VCC = 5V) 0.8 0.7 125C 0.6 85C VOL (V) 0.5 25C 0.4 -40C 0.3 0.2 0.1 0 0 2 4 6 8 10 12 14 16 18 20 IOL (mA) Figure 6-15. Output Low Voltage versus Output Low Current (VCC = 3V) 1.2 125C 1.0 85C IOL (mA) 0.8 25C 0.6 -40C 0.4 0.2 0 0 2 4 6 8 10 12 14 16 18 20 VOL (V) Figure 6-16. Output High Voltage versus Output High Current (VCC = 5V) 5.2 5 VOH (V) 4.8 4.6 -40C 25C 85C 125C 4.4 4.2 4 0 2 4 6 8 10 IOH (mA) 284 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 12 14 16 18 20 Figure 6-17. Output High Voltage versus Output High Current (VCC = 3V) 3.5 3 Current (V) 2.5 -40C 25C 85C 125C 2 1.5 1 0.5 0 0 2 4 6 8 10 14 12 16 18 20 IOH (mA) 6.3.1.4 Pin Thresholds and Hysteresis Figure 6-18. I/O Pin Input Threshold versus VCC (VIH, I/O Pin Read as 1) 3.5 Vih (V) 3 125 2.5 85 25 2 -40 1.5 0 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) Figure 6-19. I/O Pin Input Threshold versus VCC (VIL, I/O Pin Read as 0) 3 125 C -40 C 2.5 Vil (V) 2 1.5 1 0.5 0 2 2.5 3 3.5 4 4.5 5 5.5 6 VCC (V) ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 285 Figure 6-20. Reset Input Threshold Voltage versus VCC (VIH, Reset Pin Read as 1) 4 3.5 Threshold (V) 3 -40C 25C 85C 125C 2.5 2 1.5 1 0.5 0 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) Figure 6-21. Reset Input Threshold Voltage versus VCC (VIL, Reset Pin Read as 0) 2.5 125C 85C 25C -40C Threshold (V) 2 1.5 1 0.5 0 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 6.3.1.5 Internal Oscillator Speed Figure 6-22. Watchdog Oscillator Frequency versus VCC 130 128 -40C 126 FRC (kHz) 124 25C 122 120 85C 125C 118 116 114 112 110 2.5 3 3.5 4 VCC (V) 286 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 4.5 5 5.5 Figure 6-23. Calibrated 8MHz RC Oscillator Frequency versus Temperature 8.4 8.3 FRC (MHz) 8.2 5.0V 8.1 2.7V 8.0 7.9 7.8 7.7 7.6 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 Temperature Figure 6-24. Calibrated 8MHz RC Oscillator Frequency versus VCC 8.4 FRC (MHz) 8.2 8 125C 85C 25C 7.8 -40C 7.6 7.4 7.2 7 2.5 3 3.5 4 4.5 5 5.5 VCC (V) Figure 6-25. Calibrated 8MHz RC Oscillator Frequency versus OSCAL Value (for ATA6613C) 16 125C 85C 25C -40C 14 FRC (MHz) 12 10 8 6 4 2 0 16 32 48 64 80 96 112 128 144 160 176 192 208 224 240 OSCCAL (X1) ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 287 Figure 6-26. Calibrated 8MHz RC Oscillator Frequency versus OSCAL Value (for Atmel ATA6612C only) 14 125C 85C 25C -40C 12 FRC (MHz) 10 8 6 4 2 0 16 32 48 64 80 96 112 128 144 160 176 192 208 224 240 OSCCAL (X1) 6.3.1.6 BOD Thresholds and Analog Comparator Offset Figure 6-27. BOD Threshold versus Temperature (BODLEVEL is 4.0V) 4.6 4.5 Threshold (V) Rising VCC 4.4 Falling VCC 4.3 4.2 4.1 4 -55 -45 -35 -25 -15 -5 5 15 25 35 45 55 65 75 85 95 105 115 125 Temperature (C) Figure 6-28. BOD Threshold versus Temperature (BODLEVEL is 2.7V) 3 Threshold (V) 2.9 2.8 Rising VCC 2.7 Falling VCC 2.6 2.5 2.4 -50 -40 -30 -20 -10 0 10 20 30 40 50 Temperature (C) 288 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 60 70 80 90 100 110 120 Figure 6-29. Bandgap Voltage versus VCC 1.1 Bandgap Voltage (V) 1.095 1.09 85C 25C 125C 1.085 1.08 -40C 1.075 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 6.3.1.7 Peripheral Units Figure 6-30. Analog to Digital Converter GAIN versus VCC 0 -0.2 Error (LSB) -0.4 -0.6 4V IDLE -0.8 4V STD -1.0 -1.2 -1.4 -1.6 -50 0 50 100 150 Temperature Figure 6-31. Analog to Digital Converter OFFSET versus VCC 2.5 Error (LSB) 2.0 1.5 4V IDLE 4V STD 1.0 0.5 0 -50 0 50 100 150 Temperature ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 289 Figure 6-32. Analog to Digital Converter DNL versus VCC 0.40 0.35 Error (LSB) 0.30 0.25 4V IDLE 0.20 4V STD 0.15 0.10 0.05 0 -50 0 50 100 150 Temperature Figure 6-33. Analog to Digital Converter INL versus VCC 0.7 0.6 Error (LSB) 0.5 0.4 4V IDLE 4V STD 0.3 0.2 0.1 0 -50 0 50 Temperature 290 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 100 150 6.4 Register Summary Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 (0xFF) Reserved - - - - - - - - (0xFE) Reserved - - - - - - - - (0xFD) Reserved - - - - - - - - (0xFC) Reserved - - - - - - - - (0xFB) Reserved - - - - - - - - (0xFA) Reserved - - - - - - - - (0xF9) Reserved - - - - - - - - (0xF8) Reserved - - - - - - - - (0xF7) Reserved - - - - - - - - (0xF6) Reserved - - - - - - - - (0xF5) Reserved - - - - - - - - (0xF4) Reserved - - - - - - - - (0xF3) Reserved - - - - - - - - (0xF2) Reserved - - - - - - - - (0xF1) Reserved - - - - - - - - (0xF0) Reserved - - - - - - - - (0xEF) Reserved - - - - - - - - (0xEE) Reserved - - - - - - - - (0xED) Reserved - - - - - - - - (0xEC) Reserved - - - - - - - - (0xEB) Reserved - - - - - - - - (0xEA) Reserved - - - - - - - - (0xE9) Reserved - - - - - - - - (0xE8) Reserved - - - - - - - - (0xE7) Reserved - - - - - - - - (0xE6) Reserved - - - - - - - - (0xE5) Reserved - - - - - - - - (0xE4) Reserved - - - - - - - - (0xE3) Reserved - - - - - - - - (0xE2) Reserved - - - - - - - - (0xE1) Reserved - - - - - - - - (0xE0) Reserved - - - - - - - - Reserved - - - - - - - - (0xDF) Notes: Page 1. For compatibility with future devices, reserved bits should be written to zero if accessed. Reserved I/O memory addresses should never be written. 2. I/O registers within the address range 0x00 - 0x1F are directly bit-accessible using the SBI and CBI instructions. In these registers, the value of single bits can be checked by using the SBIS and SBIC instructions. 3. Some of the status flags are cleared by writing a logical one to them. Note that, unlike most other AVRs, the CBI and SBI instructions will only 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. 4. 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. The Atmel ATA6612C/ATA6613C is a complex microcontroller with more peripheral units than can be supported within the 64 location reserved in Opcode for the IN and OUT instructions. For the extended I/O space from 0x60 - 0xFF in SRAM, only the ST/STS/STD and LD/LDS/LDD instructions can be used. 5. Only valid for Atmel ATA6612C/ATA6613C ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 291 6.4 Register Summary (Continued) Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 (0xDE) Reserved - - - - - - - - (0xDD) Reserved - - - - - - - - (0xDC) Reserved - - - - - - - - (0xDB) Reserved - - - - - - - - (0xDA) Reserved - - - - - - - - (0xD9) Reserved - - - - - - - - (0xD8) Reserved - - - - - - - - (0xD7) Reserved - - - - - - - - (0xD6) Reserved - - - - - - - - (0xD5) Reserved - - - - - - - - (0xD4) Reserved - - - - - - - - (0xD3) Reserved - - - - - - - - (0xD2) Reserved - - - - - - - - (0xD1) Reserved - - - - - - - - (0xD0) Reserved - - - - - - - - (0xCF) Reserved - - - - - - - - (0xCE) Reserved - - - - - - - - (0xCD) Reserved - - - - - - - - (0xCC) Reserved - - - - - - - - (0xCB) Reserved - - - - - - - - (0xCA) Reserved - - - - - - - - (0xC9) Reserved - - - - - - - - (0xC8) Reserved - - - - - - - - (0xC7) Reserved - - - - - - - - (0xC6) UDR0 (0xC5) UBRR0H (0xC4) UBRR0L (0xC3) Reserved Page USART I/O data register 180 USART baud rate register high 183 USART baud rate register low - - - - 183 - - - - UCSZ00 / UCPHA0 UCPOL0 182/191 (0xC2) UCSR0C UMSEL01 UMSEL00 UPM01 UPM00 USBS0 UCSZ01 /UDORD0 (0xC1) UCSR0B RXCIE0 TXCIE0 UDRIE0 RXEN0 TXEN0 UCSZ02 RXB80 TXB80 181 (0xC0) UCSR0A RXC0 TXC0 UDRE0 FE0 DOR0 UPE0 U2X0 MPCM0 180 (0xBF) Reserved - - - - - - - - Reserved - - - - - - - - (0xBE) Notes: 292 1. For compatibility with future devices, reserved bits should be written to zero if accessed. Reserved I/O memory addresses should never be written. 2. I/O registers within the address range 0x00 - 0x1F are directly bit-accessible using the SBI and CBI instructions. In these registers, the value of single bits can be checked by using the SBIS and SBIC instructions. 3. Some of the status flags are cleared by writing a logical one to them. Note that, unlike most other AVRs, the CBI and SBI instructions will only 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. 4. 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. The Atmel ATA6612C/ATA6613C is a complex microcontroller with more peripheral units than can be supported within the 64 location reserved in Opcode for the IN and OUT instructions. For the extended I/O space from 0x60 - 0xFF in SRAM, only the ST/STS/STD and LD/LDS/LDD instructions can be used. 5. Only valid for Atmel ATA6612C/ATA6613C ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 6.4 Register Summary (Continued) Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page (0xBD) TWAMR TWAM6 TWAM5 TWAM4 TWAM3 TWAM2 TWAM1 TWAM0 - 202 (0xBC) TWCR TWINT TWEA TWSTA TWSTO TWWC TWEN - TWIE 200 (0xBB) TWDR 2-wire serial interface data register 201 (0xBA) TWAR TWA6 TWA5 TWA4 TWA3 TWA2 TWA1 TWA0 TWGCE 202 (0xB9) TWSR TWS7 TWS6 TWS5 TWS4 TWS3 - TWPS1 TWPS0 201 - - (0xB8) TWBR (0xB7) Reserved - 2-wire serial interface bit rate register (0xB6) ASSR - (0xB5) Reserved - - - EXCLK AS2 TCN2UB - - - - - 199 OCR2AUB OCR2BUB TCR2AUB - - - TCR2BUB 154 - (0xB4) OCR2B Timer/counter2 output compare register B 151 (0xB3) OCR2A Timer/counter2 output compare register A 151 (0xB2) TCNT2 (0xB1) TCCR2B FOC2A FOC2B - Timer/counter2 (8-bit) - WGM22 CS22 CS21 CS20 151 150 (0xB0) TCCR2A COM2A1 COM2A0 COM2B1 COM2B0 - - WGM21 WGM20 148 (0xAF) Reserved - - - - - - - - (0xAE) Reserved - - - - - - - - (0xAD) Reserved - - - - - - - - (0xAC) Reserved - - - - - - - - (0xAB) Reserved - - - - - - - - (0xAA) Reserved - - - - - - - - (0xA9) Reserved - - - - - - - - (0xA8) Reserved - - - - - - - - (0xA7) Reserved - - - - - - - - (0xA6) Reserved - - - - - - - - (0xA5) Reserved - - - - - - - - (0xA4) Reserved - - - - - - - - (0xA3) Reserved - - - - - - - - (0xA2) Reserved - - - - - - - - (0xA1) Reserved - - - - - - - - (0xA0) Reserved - - - - - - - - (0x9F) Reserved - - - - - - - - (0x9E) Reserved - - - - - - - - (0x9D) Reserved - - - - - - - - Reserved - - - - - - - - (0x9C) Notes: 1. For compatibility with future devices, reserved bits should be written to zero if accessed. Reserved I/O memory addresses should never be written. 2. I/O registers within the address range 0x00 - 0x1F are directly bit-accessible using the SBI and CBI instructions. In these registers, the value of single bits can be checked by using the SBIS and SBIC instructions. 3. Some of the status flags are cleared by writing a logical one to them. Note that, unlike most other AVRs, the CBI and SBI instructions will only 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. 4. 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. The Atmel ATA6612C/ATA6613C is a complex microcontroller with more peripheral units than can be supported within the 64 location reserved in Opcode for the IN and OUT instructions. For the extended I/O space from 0x60 - 0xFF in SRAM, only the ST/STS/STD and LD/LDS/LDD instructions can be used. 5. Only valid for Atmel ATA6612C/ATA6613C ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 293 6.4 Register Summary (Continued) Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 (0x9B) Reserved - - - - - - - - (0x9A) Reserved - - - - - - - - (0x99) Reserved - - - - - - - - (0x98) Reserved - - - - - - - - (0x97) Reserved - - - - - - - - (0x96) Reserved - - - - - - - - (0x95) Reserved - - - - - - - - (0x94) Reserved - - - - - - - - (0x93) Reserved - - - - - - - - (0x92) Reserved - - - - - - - - (0x91) Reserved - - - - - - - - (0x90) Reserved - - - - - - - - (0x8F) Reserved - - - - - - - - (0x8E) Reserved - - - - - - - - (0x8D) Reserved - - - - - - - - (0x8C) Reserved - - - - - - - - (0x8B) OCR1BH Page Timer/counter1 - output compare register B high byte 135 (0x8A) OCR1BL Timer/counter1 - output compare register B low byte 135 (0x89) OCR1AH Timer/counter1 - output compare register A high byte 135 (0x88) OCR1AL Timer/counter1 - output compare register A low byte 135 (0x87) ICR1H Timer/counter1 - input capture register high byte 136 (0x86) ICR1L Timer/counter1 - input capture register low byte 136 (0x85) TCNT1H Timer/counter1 - counter register high byte 135 (0x84) TCNT1L (0x83) Reserved - - - (0x82) TCCR1C FOC1A FOC1B - - - - - - 135 (0x81) TCCR1B ICNC1 ICES1 - WGM13 WGM12 CS12 CS11 CS10 134 (0x80) TCCR1A COM1A1 COM1A0 COM1B1 COM1B0 - - WGM11 WGM10 132 (0x7F) DIDR1 - - - - - - AIN1D AIN0D 223 (0x7E) DIDR0 - - ADC5D ADC4D ADC3D ADC2D ADC1D ADC0D 238 (0x7D) Reserved - - - - - - - - (0x7C) ADMUX REFS1 REFS0 ADLAR - MUX3 MUX2 MUX1 MUX0 235 (0x7B) ADCSRB - ACME - - - ADTS2 ADTS1 ADTS0 238 ADCSRA ADEN ADSC ADATE ADIF ADIE ADPS2 ADPS1 ADPS0 236 (0x7A) Notes: 294 Timer/counter1 - counter register low byte - - - 135 - - 1. For compatibility with future devices, reserved bits should be written to zero if accessed. Reserved I/O memory addresses should never be written. 2. I/O registers within the address range 0x00 - 0x1F are directly bit-accessible using the SBI and CBI instructions. In these registers, the value of single bits can be checked by using the SBIS and SBIC instructions. 3. Some of the status flags are cleared by writing a logical one to them. Note that, unlike most other AVRs, the CBI and SBI instructions will only 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. 4. 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. The Atmel ATA6612C/ATA6613C is a complex microcontroller with more peripheral units than can be supported within the 64 location reserved in Opcode for the IN and OUT instructions. For the extended I/O space from 0x60 - 0xFF in SRAM, only the ST/STS/STD and LD/LDS/LDD instructions can be used. 5. Only valid for Atmel ATA6612C/ATA6613C ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 6.4 Register Summary (Continued) Address Name (0x79) ADCH Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page ADC data register high byte 237 (0x78) ADCL (0x77) Reserved - - - ADC data register low byte - - - - - 237 (0x76) Reserved - - - - - - - - (0x75) Reserved - - - - - - - - (0x74) Reserved - - - - - - - - (0x73) Reserved - - - - - - - - (0x72) Reserved - - - - - - - - (0x71) Reserved - - - - - - - - (0x70) TIMSK2 - - - - - OCIE2B OCIE2A TOIE2 152 (0x6F) TIMSK1 - - ICIE1 - - OCIE1B OCIE1A TOIE1 136 (0x6E) TIMSK0 - - - - - OCIE0B OCIE0A TOIE0 111 (0x6D) PCMSK2 PCINT23 PCINT22 PCINT21 PCINT20 PCINT19 PCINT18 PCINT17 PCINT16 96 (0x6C) PCMSK1 - PCINT14 PCINT13 PCINT12 PCINT11 PCINT10 PCINT9 PCINT8 96 (0x6B) PCMSK0 PCINT7 PCINT6 PCINT5 PCINT4 PCINT3 PCINT2 PCINT1 PCINT0 96 (0x6A) Reserved - - - - - - - - (0x69) EICRA - - - - ISC11 ISC10 ISC01 ISC00 (0x68) PCICR - - - - - PCIE2 PCIE1 PCIE0 (0x67) Reserved - - - - - - - - Oscillator Calibration Register 93 (0x66) OSCCAL (0x65) Reserved - - - - - - - - 52 (0x64) PRR PRTWI PRTIM2 PRTIM0 - PRTIM1 PRSPI PRUSAR0 PRADC (0x63) Reserved - - - - - - - - (0x62) Reserved - - - - - - - - (0x61) CLKPR CLKPCE - - - CLKPS3 CLKPS2 CLKPS1 CLKPS0 54 (0x60) WDTCSR WDIF WDIE WDP3 WDCE WDE WDP2 WDP1 WDP0 68 0x3F (0x5F) SREG I T H S V N Z C 33 (5) 58 0x3E (0x5E) SPH - - - - - (SP10) SP9 SP8 35 0x3D (0x5D) SPL SP7 SP6 SP5 SP4 SP3 SP2 SP1 SP0 35 0x3C (0x5C) Reserved - - - - - - - - 0x3B (0x5B) Reserved - - - - - - - - 0x3A (0x5A) Reserved - - - - - - - - 0x39 (0x59) Reserved - - - - - - - - 0x38 (0x58) Reserved - - - - - - - - Notes: 1. For compatibility with future devices, reserved bits should be written to zero if accessed. Reserved I/O memory addresses should never be written. 2. I/O registers within the address range 0x00 - 0x1F are directly bit-accessible using the SBI and CBI instructions. In these registers, the value of single bits can be checked by using the SBIS and SBIC instructions. 3. Some of the status flags are cleared by writing a logical one to them. Note that, unlike most other AVRs, the CBI and SBI instructions will only 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. 4. 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. The Atmel ATA6612C/ATA6613C is a complex microcontroller with more peripheral units than can be supported within the 64 location reserved in Opcode for the IN and OUT instructions. For the extended I/O space from 0x60 - 0xFF in SRAM, only the ST/STS/STD and LD/LDS/LDD instructions can be used. 5. Only valid for Atmel ATA6612C/ATA6613C ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 295 6.4 Register Summary (Continued) Address Name Bit 7 Bit 6 Bit 5 5. Bit 4 (5) - (RWWSRE) Bit 3 Bit 2 Bit 1 Bit 0 Page BLBSET PGWRT PGERS SELFPRGEN 244 0x37 (0x57) SPMCSR SPMIE (RWWSB) 0x36 (0x56) Reserved - - - - - - - - 0x35 (0x55) MCUCR - - - PUD - - IVSEL IVCE 0x34 (0x54) MCUSR - - - - WDRF BORF EXTRF PORF 0x33 (0x53) SMCR - - - - SM2 SM1 SM0 SE 0x32 (0x52) Reserved - - - - - - - - 0x31 (0x51) Reserved - - - - - - - - 56 0x30 (0x50) ACSR ACD ACBG ACO ACI ACIE ACIC ACIS1 ACIS0 0x2F (0x4F) Reserved - - - - - - - - 0x2E (0x4E) SPDR 0x2D (0x4D) SPSR SPIF WCOL - - - - - SPI2X 162 0x2C (0x4C) SPCR SPIE SPE DORD MSTR CPOL CPHA SPR1 SPR0 161 0x2B (0x4B) GPIOR2 SPI data register 163 General purpose I/O register 2 45 0x2A (0x4A) GPIOR1 0x29 (0x49) Reserved 0x28 (0x48) OCR0B Timer/counter0 output compare register B 0x27 (0x47) OCR0A Timer/counter0 output compare register A General purpose I/O register 1 - - - - 45 - - - - CS01 CS00 0x26 (0x46) TCNT0 0x25 (0x45) TCCR0B FOC0A FOC0B - - WGM02 CS02 0x24 (0x44) TCCR0A COM0A1 COM0A0 COM0B1 COM0B0 - - WGM01 WGM00 0x23 (0x43) GTCCR TSM - - - - - PSRASY PSRSYNC Timer/counter0 (8-bit) 0x22 (0x42) EEARH (EEPROM address register high byte) 0x21 (0x41) EEARL EEPROM address register low byte 0x20 (0x40) EEDR 0x1F (0x3F) EECR 0x1E (0x3E) GPIOR0 0x1D (0x3D) 222 113/156 5. 41 41 EEPROM data register - EEPM1 EIMSK - - - - - 0x1C (0x3C) EIFR - - - - - - 0x1B (0x3B) PCIFR - - - - - PCIF2 0x1A (0x3A) Reserved - - - - - - - - 0x19 (0x39) Reserved - - - - - - - - 0x18 (0x38) Reserved - - - - - - - - 0x17 (0x37) TIFR2 - - - - - OCF2B OCF2A TOV2 152 TIFR1 - - ICF1 - - OCF1B OCF1A TOV1 137 0x16 (0x36) Notes: 296 EEPM0 EERIE 41 - EEMPE EEPE EERE 41 INT1 INT0 94 INTF1 INTF0 94 PCIF1 PCIF0 General purpose I/O register 0 45 - 1. For compatibility with future devices, reserved bits should be written to zero if accessed. Reserved I/O memory addresses should never be written. 2. I/O registers within the address range 0x00 - 0x1F are directly bit-accessible using the SBI and CBI instructions. In these registers, the value of single bits can be checked by using the SBIS and SBIC instructions. 3. Some of the status flags are cleared by writing a logical one to them. Note that, unlike most other AVRs, the CBI and SBI instructions will only 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. 4. 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. The Atmel ATA6612C/ATA6613C is a complex microcontroller with more peripheral units than can be supported within the 64 location reserved in Opcode for the IN and OUT instructions. For the extended I/O space from 0x60 - 0xFF in SRAM, only the ST/STS/STD and LD/LDS/LDD instructions can be used. 5. Only valid for Atmel ATA6612C/ATA6613C ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 6.4 Register Summary (Continued) Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 0x15 (0x35) TIFR0 - - - - - OCF0B OCF0A TOV0 0x14 (0x34) Reserved - - - - - - - - 0x13 (0x33) Reserved - - - - - - - - 0x12 (0x32) Reserved - - - - - - - - 0x11 (0x31) Reserved - - - - - - - - 0x10 (0x30) Reserved - - - - - - - - 0x0F (0x2F) Reserved - - - - - - - - Page 0x0E (0x2E) Reserved - - - - - - - - 0x0D (0x2D) Reserved - - - - - - - - 0x0C (0x2C) Reserved - - - - - - - - 0x0B (0x2B) PORTD PORTD7 PORTD6 PORTD5 PORTD4 PORTD3 PORTD2 PORTD1 PORTD0 92 0x0A (0x2A) DDRD DDD7 DDD6 DDD5 DDD4 DDD3 DDD2 DDD1 DDD0 92 0x09 (0x29) PIND PIND7 PIND6 PIND5 PIND4 PIND3 PIND2 PIND1 PIND0 92 0x08 (0x28) PORTC - PORTC6 PORTC5 PORTC4 PORTC3 PORTC2 PORTC1 PORTC0 91 0x07 (0x27) DDRC - DDC6 DDC5 DDC4 DDC3 DDC2 DDC1 DDC0 91 0x06 (0x26) PINC - PINC6 PINC5 PINC4 PINC3 PINC2 PINC1 PINC0 92 0x05 (0x25) PORTB PORTB7 PORTB6 PORTB5 PORTB4 PORTB3 PORTB2 PORTB1 PORTB0 91 0x04 (0x24) DDRB DDB7 DDB6 DDB5 DDB4 DDB3 DDB2 DDB1 DDB0 91 0x03 (0x23) PINB PINB7 PINB6 PINB5 PINB4 PINB3 PINB2 PINB1 PINB0 91 0x02 (0x22) Reserved - - - - - - - - 0x01 (0x21) Reserved - - - - - - - - Reserved - - - - - - - - 0x0 (0x20) Notes: 1. For compatibility with future devices, reserved bits should be written to zero if accessed. Reserved I/O memory addresses should never be written. 2. I/O registers within the address range 0x00 - 0x1F are directly bit-accessible using the SBI and CBI instructions. In these registers, the value of single bits can be checked by using the SBIS and SBIC instructions. 3. Some of the status flags are cleared by writing a logical one to them. Note that, unlike most other AVRs, the CBI and SBI instructions will only 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. 4. 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. The Atmel ATA6612C/ATA6613C is a complex microcontroller with more peripheral units than can be supported within the 64 location reserved in Opcode for the IN and OUT instructions. For the extended I/O space from 0x60 - 0xFF in SRAM, only the ST/STS/STD and LD/LDS/LDD instructions can be used. 5. Only valid for Atmel ATA6612C/ATA6613C ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 297 6.5 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 x Rr Z,N,V 1 ANDI Rd, K Logical AND register and constant Rd Rd x 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 x (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 x Rd Z,N,V 1 CLR Rd Clear register Rd Rd Rd Z,N,V 1 SER Rd Set register Rd 0xFF None 1 MUL Rd, Rr Multiply unsigned R1:R0 Rd x Rr Z,C 2 MULS Rd, Rr Multiply signed R1:R0 Rd x Rr Z,C 2 MULSU Rd, Rr Multiply signed with unsigned R1:R0 Rd x Rr Z,C 2 FMUL Rd, Rr Fractional multiply unsigned R1:R0 (Rd x Rr) << 1 Z,C 2 FMULS Rd, Rr Fractional multiply signed R1:R0 (Rd x Rr) << 1 Z,C 2 FMULSU Rd, Rr Fractional multiply signed with unsigned R1:R0 (Rd x Rr) << 1 Z,C 2 Branch Instructions RJMP k IJMP Relative jump PC PC + k + 1 None 2 Indirect jump to (Z) PC Z None 2 (1) JMP k Direct jump PC k None 3 RCALL k Relative subroutine call PC PC + k + 1 None 3 Indirect call to (Z) PC Z None 3 Direct subroutine call PC k None 4 RET Subroutine return PC STACK None 4 RETI Interrupt return PC STACK I 4 None 1/2/3 ICALL CALL (1) CPSE Rd,Rr Compare, skip if equal if (Rd = Rr) PC PC + 2 or 3 CP Rd,Rr Compare Rd - Rr Z, N,V,C,H 1 Rd - Rr - C Z, N,V,C,H 1 CPC Note: 1. 298 k Rd,Rr Compare with carry These instructions are only available in ATA6613C ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 6.5 Instruction Set Summary (Continued) Mnemonics Operands Description Operation Flags #Clocks 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 SBIC P, b Skip if bit in register is set if (Rr(b)=1) PC PC + 2 or 3 None 1/2/3 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) 1 None 2 CBI P,b Clear bit in I/O register I/O (P, b) 0 None 2 LSL Rd Logical shift left Rd(n+1) Rd (n), Rd(0) 0 Z,C,N,V 1 LSR Rd Logical shift right Rd (n) Rd(n+1), Rd(7) 0 Z,C,N,V 1 ROL Rd Rotate left through carry Rd(0) C, Rd(n+1) Rd (n), C Rd(7) Z,C,N,V 1 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 SWAP Rd Swap nibbles Rd(3..0) Rd(7..4), Rd(7..4) Rd(3..0) None 1 BSET s Flag set SREG(s) 1 SREG(s) 1 BCLR s Flag clear SREG(s) 0 SREG(s) 1 T 1 BST Note: 1. Rr, b Bit store from register to T These instructions are only available in ATA6613C T Rr(b) ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 299 6.5 Instruction Set Summary (Continued) Mnemonics Operands Description Operation Flags #Clocks BLD Rd, b Bit load from T to register Rd(b) T None 1 SEC Set carry C1 C 1 CLC Clear carry C0 C 1 SEN Set negative flag N1 N 1 CLN Clear negative flag N0 N 1 SEZ Set zero flag Z1 Z 1 CLZ Clear zero flag Z0 Z 1 SEI Global interrupt enable I1 I 1 CLI Global interrupt disable I0 I 1 SES Set signed test flag S1 S 1 CLS Clear signed test flag S0 S 1 SEV Set twos complement overflow. V1 V 1 CLV Clear twos complement overflow V0 V 1 SET Set T in SREG T1 T 1 CLT Clear T in SREG T0 T 1 SEH Set half carry flag in SREG H1 H 1 CLH Clear half carry flag in SREG H0 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 K None 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 Load indirect and pre-dec. Y Y - 1, Rd (Y) None 2 Load indirect with displacement Rd (Y + q) None 2 LD Rd, - Y LDD Rd, Y+ q LD Rd, Z Load indirect Rd (Z) None 2 LD Rd, Z+ Load indirect and post-inc. Rd (Z), Z Z+1 None 2 Load indirect and pre-dec. Z Z - 1, Rd (Z) None 2 Load indirect with displacement Rd (Z + q) None 2 LD Rd, -Z LDD Rd, Z+q 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 (Z) Rr None 2 ST Z, Rr Store indirect These instructions are only available in ATA6613C Note: 1. 300 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 6.5 Instruction Set Summary (Continued) Mnemonics Operands Description Operation Flags #Clocks ST Z+, Rr Store indirect and post-inc. (Z) Rr, Z Z + 1 None 2 ST -Z, Rr Store indirect and pre-dec. Z Z - 1, (Z) Rr None 2 STD Z+q,Rr Store indirect with displacement (Z + q) Rr None 2 STS k, Rr Store direct to SRAM (k) Rr None 2 Load program memory R0 (Z) None 3 LPM LPM Rd, Z Load program memory Rd (Z) None 3 LPM Rd, Z+ Load program memory and post-inc Rd (Z), Z Z+1 None 3 Store program memory (Z) R1:R0 None - SPM IN Rd, P In port Rd P None 1 OUT P, Rr Out port P Rr None 1 PUSH Rr Push register on stack STACK Rr None 2 POP Rd Pop register from stack Rd STACK None 2 None 1 MCU Control Instructions NOP SLEEP WDR BREAK Note: 1. No operation Sleep (see specific descr. for sleep function) None 1 Watchdog reset (see specific descr. for WDR/timer) None 1 For on-chip debug only None N/A Break These instructions are only available in ATA6613C ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 301 7. Application Figure 7-1. Typical LIN Slave Application C1 100nF 37 GND2 38 39 PB6 MCUVCC 40 PB7 41 PD5 42 PD6 43 PD7 44 PB0 45 PB1 46 PB2 47 PB3 VCC LIN 32 31 30 29 28 VBAT 27 26 PVCC 25 GND PVCC + 24 23 14 13 22 PC5 KL_15 PC4 MODE VS TM PC3 WD_OSC EN NRES PC2 PC6 12 33 GND NTRIG 220pF 34 WAKE PC1 21 11 PC0 TDX 10 Atmel ATA6612C/ATA6613C ADC7 20 9 LIN INH 8 PD3 GND4 19 7 AREF RXD 6 PD4 18 5 ADC6 C2 100nF 35 GND1 PD2 4 36 MCUVCC MCUAVCC 17 3 PB5 PD1 2 16 1 PD0 PB5 15 100nF PB4 48 PB4 PB3 100nF 22F + 100nF 100nF 10F PC6 10k 47k INH KL_15 MODE* 51k 10k* PB4 1 PVCC PB5 PB3 PC6 ISP * The MODE pin can be connected directly to GND, if it is not needed to disable the Watchdog Note: 302 All open pins of the SiP can be used for application-specific purposes. AVR: Internal clock, no ADC application, TXD, RXD, NRES, EN and NTRIG connected for LIN Slave. The connection between the LIN-SBC and the AVR(R) requires the software being programmed correspondingly. SBC: LIN slave operation with watchdog, 5V regulator and KL15 wake up RF emissions: Best results for RF emissions will be achieved by connecting the blocking capacitors of the microcontroller supply (C1 and C2) between the microcontroller pins and the GND/PVCC line. See also Figure 7-1. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 Figure 7-2. Typical LIN Master Application 1 PB4 22pF 22pF PVCC PB5 XTAL PB3 PC6 C1 100nF ISP 37 GND2 38 39 PB6 MCUVCC 40 PB7 41 PD5 42 PD6 43 PD7 44 PB0 45 PB1 46 PB2 47 PB3 ADC7 GND ATA6612C/ATA6613C PC0 WAKE PC1 NTRIG PC2 EN PC3 VS VCC KL_15 MODE PVCC C2 100nF 35 560pF 34 33 LIN 32 31 33k 30 WAKE 29 10k 28 VBAT 27 26 PVCC 25 GND 1k + 24 TM 23 WD_OSC 22 14 13 21 PC5 NRES PC4 PC6 12 LIN Atmel TDX 11 GND4 20 9 10 PD3 INH 8 AREF 19 7 PD4 RXD 6 ADC6 18 5 GND1 PD2 4 36 MCUVCC MCUAVCC 17 3 PB5 PD1 2 16 1 PD0 PB5 15 100nF PB4 48 PB4 PB3 100nF 22F + 51k PC6 100nF 10F MODE* 10k 10k* * The MODE pin can be connected directly to GND, if it is not needed to disable the Watchdog Note: All open pins of the SiP can be used for application-specific purposes. AVR: TXD, RXD, NRES and EN connected for LIN Master. The connection between the LIN-SBC and the AVR requires the software being programmed correspondingly. Analog digital converter not active; system clock from external crystal. LIN-SBC: Master application with 5V regulator and watchdog, 1k master resistance connected via diode to VBAT, local wake up via pin WAKE. RF emissions: Best results for RF emissions will be achieved by connecting the blocking capacitors of the microcontroller supply (C1 and C2) between the microcontroller pins and the GND/PVCC line. See also Figure 7-2. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 303 Figure 7-3. Typical LIN Master Application LIN Master Pull-up Switched Off during Sleep Mode 1 PB4 22pF 22pF PVCC PB5 XTAL PB3 PC6 C1 100nF ISP 37 GND2 38 39 PB6 MCUVCC 40 PB7 41 PD5 42 PD6 43 PD7 44 PB0 45 PB1 46 PB2 47 PB3 Atmel ATA6612C/ATA6613C ADC7 PC0 GND WAKE PC1 NTRIG PC2 EN PC3 VS VCC KL_15 MODE PVCC C2 100nF 35 34 10k 560pF 33 LIN 32 31 33k 30 WAKE 29 10k 28 VBAT 27 26 PVCC 25 GND 1k + 24 TM 23 WD_OSC 22 14 13 21 PC5 NRES PC4 PC6 12 LIN TDX 11 GND4 20 9 10 PD3 INH 8 AREF 19 7 PD4 RXD 6 ADC6 18 5 GND1 PD2 4 36 MCUVCC MCUAVCC 17 3 PB5 PD1 2 16 1 PD0 PB5 15 100nF PB4 48 PB4 PB3 100nF 22F + 51k 100nF 10F PC6 MODE* 10k 10k* * The MODE pin can be connected directly to GND, if it is not needed to disable the Watchdog Note: 304 All open pins of the SiP can be used for application-specific purposes. AVR: TXD, RXD, NRES and EN connected for LIN Master. The connection between the LIN-SBC and the AVR requires the software being programmed correspondingly. Analog digital converter not active; system clock from external crystal. LIN-SBC: Master application with 5V regulator and watchdog, 1k master resistance connected via diode and INH output to VBAT, local wake up via pin WAKE. RF emissions: Best results for RF emissions will be achieved by connecting the blocking capacitors of the microcontroller supply (C1 and C2) between the microcontroller pins and the GND/PVCC line. See also Figure 7-3. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 Figure 7-4. LIN Slave Application with Minimum External Components C1 100nF 37 GND2 38 MCUVCC 39 PB6 40 PB7 41 42 PD6 43 PD7 44 PB0 45 PB1 46 PB2 47 PB3 PD5 GND ATA6612C/ATA6613C PC0 WAKE PC1 NTRIG PC2 EN PC3 VS VCC KL_15 MODE C2 100nF 35 34 220pF 33 LIN 32 31 30 29 28 VBAT 27 26 PVCC 25 GND PVCC + 24 TM 23 WD_OSC 22 14 13 21 PC5 NRES PC4 PC6 12 ADC7 TDX 11 LIN Atmel 20 10 GND4 INH 9 PD3 19 8 AREF RXD 7 PD4 18 6 ADC6 PD2 5 GND1 17 4 36 MCUVCC MCUAVCC PD1 3 PB5 16 2 PD0 PB5 1 15 100nF PB4 48 PB4 PB3 100nF 22F + 100nF PC6 10F 10k PB4 1 PVCC PB5 PB3 PC6 ISP Note: All open pins of the SiP can be used for application-specific purposes. AVR: Internal clock, no ADC application, TXD, RXD, NRES and EN connected for LIN Slave. The connection between the LIN-SBC and the AVR requires the software being programmed correspondingly. SBC: LIN slave operation with 5V regulator, no watchdog, no local wake-up. RF emissions: Best results for RF emissions will be achieved by connecting the blocking capacitors of the microcontroller supply (C1 and C2) between the microcontroller pins and the GND/PVCC line. See also Figure 7-4. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 305 8. 9. Ordering Information Extended Type Number Program Memory Package MOQ ATA6612C-PLQW-1 8kB flash QFN48, 7x7 4,000 pieces ATA6613C-PLQW-1 16kB flash QFN48, 7x7 4,000 pieces Package Information Top View D 48 1 technical drawings according to DIN specifications E PIN 1 ID Dimensions in mm A Side View A3 A1 12 Bottom View D2 13 24 25 12 E2 COMMON DIMENSIONS 1 A 36 48 37 e L A (10:1) (Unit of Measure = mm) Symbol MIN NOM MAX A 0.8 0.85 0.9 A1 0 0.035 0.05 A3 0.16 0.21 0.26 D 6.9 7 7.1 D2 5.5 5.6 5.7 E 6.9 7 7.1 E2 5.5 5.6 5.7 L 0.35 0.4 0.45 b e 0.2 0.25 0.5 0.3 NOTE b 05/20/14 TITLE Package Drawing Contact: packagedrawings@atmel.com 306 Package: QFN_7x7_48L Exposed pad 5.6x5.6 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 GPC DRAWING NO. REV. 6.543-5188.03-4 1 10. Errata 10.1 Atmel ATA6612C Interrupts may be lost when writing the timer registers in the asynchronous timer 1. Interrupts may be lost when writing the timer registers in the asynchronous timer If one of the timer registers which is synchronized to the asynchronous timer2 clock is written in the cycle before an overflow interrupt occurs, the interrupt may be lost. Problem Fix/Workaround Always check that the timer2 timer/counter register, TCNT2, does not have the value 0xFF before writing the timer2 control register, TCCR2, or output compare register, OCR2. 10.2 Atmel ATA6613C Interrupts may be lost when writing the timer registers in the asynchronous timer 1. Interrupts may be lost when writing the timer registers in the asynchronous timer If one of the timer registers which is synchronized to the asynchronous timer2 clock is written in the cycle before an overflow interrupt occurs, the interrupt may be lost. Problem Fix/Workaround Always check that the timer2 timer/counter register, TCNT2, does not have the value 0xFF before writing the timer2 control register, TCCR2, or output compare register, OCR2. ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 307 11. Revision History Please note that the following page numbers referred to in this section refer to the specific revision mentioned, not to this document. Revision No. History * Put datasheet in the latest template 9111L-AUTO-11/14 * Section 8 "Ordering Information" on page 306 updated * Section 9 "Package Information" on page 306 updated * Section 2 "Pin Configuration" on pages 2 to 3 updated * Table 3-1 "Maximum Ratings of the SIP" on page 4 updated * Table 3-2 "Maximum Ratings of the LIN-SBC" on pages 4 to 5 added * Table 3-3 "Maximum Ratings of the Microcontroller" on page 5 added 9111K-AUTO-03/13 * Figure 8-1 "Typical LIN Slave Application" on page 351 updated * Figure 8-2 "Typical LIN Master Application" on page 352 updated * Figure 8-3 "LIN Slave Application with Minimum External Components" on page 353 updated * Figure 8-4 "Typical LIN Master Application LIN Master Pull-up Switched Off during Sleep Mode" on page 354 updated 9111J-AUTO-11/12 * ATA6612P/ATA6613P renamed in ATA6612C/ATA6613C * General Features on page 1 changed * Section 3.1 "Features" on page 5 changed 9111I-AUTO-02/12 * Section 3.3 "Functional Description" on pages 7 to 19 changed * Section 4 "Absolute Maximum Ratings" on page 20 changed * Section 5 "Electrical Characteristics" on page 21 changed * Section 8 "Application" on pages 355 to 358 changed * Section 3.1 "Features" on page 5 changed * Section 3.3.3 "Ground Pin" on page 7 changed * Section 3.3.12 "Mode Input Pin (Mode)" on page 8 changed 9111H-AUTO-01/11 * Figure 3.2 "Modes of Operation" on page 10 changed * Section 3.3.20.4 "Fail-safe Mode" on page 13 changed * Section 3.3.23 "Voltage Regulator" on pages 16 to 17 changed * Section 6 "Electrical Characteristics" on pages 21 to 26 changed * Table 2-2 "Maximum Ratings of the SiP" on page 4 changed * Section 3.1 "Features" on page 5 changed * Section 3.2 "Description" on page 5 changed * Section 3.3.1 "Physical Layer Compatibility" on page 7 changed * Section 3.3.6 "Bus Pin LIN" on page 7 changed * Section 3.3.8 "TX Dominant Time-out Function" on page 8 changed 9111G-AUTO-05/10 * Section 3.3.10 "Enable Input Pin (EN)" on page 8 changed * Section 3.3.14 "KL_15 Pin" on page 9 changed * Section 3.3.20 "Modes of Operation" on pages 10 to 14 changed * Section 3.3.21 "Wake-up Scenarios from Silent to Sleep Mode on page 15 changed * Section 3.3.23 "Voltage Regulator" on page 16 changed * Section 6 "Electrical Characteristics" on page 23 changed * Section 7.7.7.1 "Power Reduction Register" on page 66 changed 308 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 Please note that the following page numbers referred to in this section refer to the specific revision mentioned, not to this document. Revision No. History 9111F-AUTO-12/08 * Section 11 "Errata" on page 360 changed * Table 2-2 "Maximum Ratings of the SiP" on page 4 changed * Section 4 "Absolute Maximum Ratings" on page 20 changed * Figure 8-1 "Typical LIN Slave Application" on page 355 changed 9111E-AUTO-07/08 * Figure 8-2 "Typical LIN Master Application" on page 356 changed * Figure 8-3 "LIN Slave Application with Minimum External Components" on page 357 changed * Figure 8-4 "Typical LIN Master Application LIN Master Pull-up Switched Off during Sleep Mode" on page 358 added * Figure 3-1 "Block Diagram" on page 6 changed 9111D-AUTO-06/08 9111C-AUTO-02/08 * Section 3.3 "Functional Description" on pages 7 to 18 changed * Section 6.5.3.2 "The EEPROM Address Register - EEARH and EEARL" on page 45 changed * Figure 8-2 "Typical LIN Master Application" on page 356 changed * Section 5 "Electrical Characteristics" on pages 21 to 26 changed 9111B-AUTO-11/07 * Section 6.6.6 "Calibrated Internal RC Oscillator" on page 57 changed * Figure 8-3 "LIN Slave Application with Minimum External Components on page 357 added ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 309 12. Table of Contents General Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1. Pin Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2. Absolute Maximum Ratings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 3. LIN System-basis-chip Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3.1 3.2 3.3 4. 5. Electrical Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Microcontroller Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 5.10 5.11 5.12 5.13 5.14 5.15 5.16 5.17 5.18 5.19 5.20 5.21 5.22 5.23 5.24 5.25 5.26 6. Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 About Code Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 AVR CPU Core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 AVR Atmel ATA6612C/ATA6613C Memories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 System Clock and Clock Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Power Management and Sleep Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 System Control and Reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 I/O-Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 External Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 8-bit Timer/Counter0 with PWM. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 Timer/Counter0 and Timer/Counter1 Prescalers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 16-bit Timer/Counter1 with PWM. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 8-bit Timer/Counter2 with PWM and Asynchronous Operation . . . . . . . . . . . . . . . . . . . . . . 137 Serial Peripheral Interface - SPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 USART0. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 USART in SPI Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 2-wire Serial Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 Analog Comparator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 Analog-to-Digital Converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 debugWIRE On-chip Debug System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 Boot Loader Support - Read-While-Write Self-Programming, Atmel ATA6612C and ATA6613C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240 Memory Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253 Electrical Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 LIN Re-synchronization Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274 2-wire Serial Interface Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276 6.1 6.2 6.3 6.4 6.5 310 Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Functional Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 SPI Timing Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ADC Characteristics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Atmel ATA6612C/ATA6613C Typical Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . Register Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Instruction Set Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7. Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302 8. Ordering Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 278 279 280 291 298 9. 10. Package Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306 Errata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307 10.1 10.2 Atmel ATA6612C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307 Atmel ATA6613C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307 11. Revision History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308 12. Table of Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 ATA6612C/ATA6613C [DATASHEET] 9111L-AUTO-11/14 311 XXXXXX Atmel Corporation 1600 Technology Drive, San Jose, CA 95110 USA T: (+1)(408) 441.0311 F: (+1)(408) 436.4200 | www.atmel.com (c) 2014 Atmel Corporation. / Rev.: 9111L-AUTO-11/14 Atmel(R), Atmel logo and combinations thereof, Enabling Unlimited Possibilities(R), AVR(R), and others are registered trademarks or trademarks of Atmel Corporation in U.S. and other countries. Other terms and product names may be trademarks of others. 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 THE ATMEL TERMS AND CONDITIONS OF SALES LOCATED ON THE ATMEL WEBSITE, 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 AND 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 products 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 products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. SAFETY-CRITICAL, MILITARY, AND AUTOMOTIVE APPLICATIONS DISCLAIMER: Atmel products are not designed for and will not be used in connection with any applications where the failure of such products would reasonably be expected to result in significant personal injury or death ("Safety-Critical Applications") without an Atmel officer's specific written consent. Safety-Critical Applications include, without limitation, life support devices and systems, equipment or systems for the operation of nuclear facilities and weapons systems. Atmel products are not designed nor intended for use in military or aerospace applications or environments unless specifically designated by Atmel as military-grade. Atmel products are not designed nor intended for use in automotive applications unless specifically designated by Atmel as automotive-grade. Mouser Electronics Authorized Distributor Click to View Pricing, Inventory, Delivery & Lifecycle Information: Atmel: ATA6613C-PLQW ATA6612C-PLQW ATA6613C-PLQW-1 ATA6612C-PLQW-1