AT90PWM81-16MN [MICROCHIP]

IC MCU 8BIT 8KB FLASH 32QFN;
AT90PWM81-16MN
型号: AT90PWM81-16MN
厂家: MICROCHIP    MICROCHIP
描述:

IC MCU 8BIT 8KB FLASH 32QFN

时钟 ATM 异步传输模式 微控制器 外围集成电路 闪存
文件: 总327页 (文件大小:3136K)
中文:  中文翻译
下载:  下载PDF数据表文档文件
Features  
High performance, low power Atmel®AVR® 8-bit Microcontroller  
Advanced RISC architecture  
– 131 powerful instructions - most single clock cycle execution  
– 32 × 8 general purpose working registers  
– Fully static operation  
– Up to 1 MIPS throughput per MHz  
– On-chip 2-cycle multiplier  
Data and non-volatile program memory  
– 8/16Kbytes of in-system programmable program memory flash  
• Endurance: 10,000 write/erase cycles  
• Lock bits protection  
8-bit Atmel  
Microcontroller  
with 8/16K  
Bytes In-System  
Programmable  
Flash  
• Optional 2/4Kbytes boot code section with independent lock bits  
• In-system programming by on-chip boot program  
• True read-while-write operation  
– 512 Bytes of in-system programmable EEPROM  
• Four bytes page size  
– 256/1024 Bytes Internal SRAM  
On-chip debug support (debugWIRE)  
Peripheral features  
– One 12-bit high speed PSC (Power Stage Controllers with extended PSC2 features)  
• Non overlapping inverted PWM output pins with flexible dead-time  
• Variable PWM duty cycle and frequency  
• Synchronous update of all PWM registers  
• Enhanced resolution mode (16 bits)  
AT90PWM81  
AT90PWM161  
• Additional register for ADC synchronization  
• Input capture  
• Four output pins and output matrix  
– One 12-bit high speed PSC (Power Stage Controller)  
• Auto-stop function for event driven PFC implementation  
• Non overlapping inverted PWM output pins with flexible dead-time  
• Variable PWM duty cycle and frequency  
• Synchronous update of all PWM registers  
• Enhanced resolution mode (16 bits)  
• Input capture  
– One 16-bit simple general purpose timer/counter  
– 10-bit ADC  
• Up to 11 single ended channels and one fully differential ADC channel pair  
• Programmable gain (5×, 10×, 20×, 40× on differential channel)  
• Internal reference voltage  
– One 10-bit DAC  
– Three analog comparators with  
• Resistor-array to adjust comparison voltage  
• DAC to adjust comparison voltage  
– One SPI  
– Three external interrupts  
– Programmable watchdog timer with separate on-chip oscillator  
Special microcontroller features  
– Low power idle, noise reduction, and power down modes  
7734Q–AVR–02/12  
 
AT90PWM81/161  
– Power-on reset and programmable brown-out detection  
– Flag array in bit-programmable I/O space (three bytes)  
– In-system programmable via SPI port  
– Internal low power calibrated RC oscillator (8MHz or 1MHz, low jitter)  
– On chip PLL for fast PWM (32MHz, 48MHz, 64MHz) and CPU (12MHz, 16MHz); PLL source RC & XTAL  
– Dynamic clock switch  
– Temperature sensor  
Operating voltage: 2.7V - 5.5V  
Operating temperature:  
– -40°C to +105°C or -40°C to +125°C  
Operating speed  
– 5V: 16MHz core, 64MHz PLL  
– 3.3V: 12MHz core, 48MHz PLL  
1. Products Configuration  
The different product configurations are described per Table 1-1.  
Table 1-1.  
Package  
PWM81/PWM161 configurations.  
SO20  
QFN32  
Pins  
20  
32  
Flash size  
EEPROM size  
RAM size  
8/16K (1)  
8/16K (1)  
512  
512  
256/1024 (2)  
256/1024 (2)  
PSC 12 bits with extended features  
PSC 12 bits  
1
1
-
1
1
-
Timer 8 bits  
Timer 16 bits  
1
8
1
1
3
1
-
1
11  
1
1
3
1
-
ADC inputs  
Amplifiers for ADC  
Temperature sensor  
Analog Comparators  
DAC  
DAC amplifiers  
UART/DALI  
-
-
SPI  
1
1
Notes: 1. Flash size is 8Kbytes for AT90PWM81 and 16Kbytes for AT90PWM161.  
2. RAM size is 256 bytes for AT90PWM81 and 1024 bytes for AT90PWM161.  
2
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
2. Pin Configurations  
Figure 2-1. 20-pin packages.  
AT90PWM81/161  
SO20  
(ACMP3_OUT/T1/PSCOUT23) PB0  
(RESET/OCD/INT2) PE0  
(PSCOUT20) PB1  
PB7 (ADC9/ICP1/PSCOUT22)  
PB6 (ADC8/ACMP3/MISO)  
PD6 (AMP0+)  
1
20  
19  
18  
17  
16  
15  
14  
13  
12  
11  
2
3
(INT0/PSCOUT21) PB2  
VCC  
PD5 (AMP0-/ADC7)  
PE3/AREF/ADC6  
4
5
GND  
AGND  
6
(ACMP1_OUT/PSCIN2/XTAL1) PE1  
(PSCINr/ACMP1M/XTAL2) PE2  
(PSCOUTR0/PSCINrB) PD1  
(ADC0/ACMP1) PD2  
AVCC  
7
PB5 (ADC5/INT1/ACMP2/SCK)  
PB4 (ADC3/ACMPM/MOSI)  
PB3 (PSCOUTR1/ADC2/ACMP2M)  
8
9
10  
3
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Figure 2-2. 32-pin packages.  
AT90PWM81/161  
QFN 32 5*5  
24  
23  
22  
21  
20  
19  
18  
17  
NC  
1
2
3
4
5
6
7
8
NC  
(ACMP3_OUT_A/SS/CLKO) PD0  
PD5 (AMP0-/ADC7)  
(PSCOUT20) PB1  
PE3/AREF/ADC6  
(INT0/PSCOUT21) PB2  
AGND  
AVCC  
VCC  
PB5 (ADC5/INT1/SCK/ACMP2)  
PD4 (PSCIN2A/ACMP3M/ADC4)  
NC  
GND  
(ACPM1_OUT/PSCIN2/XTAL1) PE1  
NC  
4
7734Q–AVR–02/12  
 
AT90PWM81/161  
Table 2-1.  
Functions description.  
MNEMONIC  
NAME, FUNCTION & ALTERNATE FUNCTION  
GND  
AGND  
VCC  
Ground: 0V reference  
Analog Ground: 0V reference for analog part  
Power Supply  
Analog Power Supply: This is the power supply voltage for analog part  
AVCC  
For a normal use this pin must be connected.  
Analog Reference: Reference for analog converter. This is the reference voltage of the A/D  
converter. As output, can be used by external analog  
AREF  
CLKO  
System Clock Output  
Reset Input  
RESET# OCD  
On Chip Debug I/O  
XTAL1  
XTAL2  
XTAL Input  
XTAL Output  
MISO  
MOSI  
SCK  
SS  
SPI Master In Slave Out  
SPI Master Out Slave In  
SPI Clock  
SPI Slave Select  
INTn  
Tn  
External interrupt n  
Timer n clock input  
PSCOUTxn  
PSCINx  
PSCx output n  
PSCx Digital Input  
PSCOUT0n  
PSCINr  
PSC reduced output n  
PSC reduced Digital Input  
ACMPn  
Analog Comparator n Positive Input  
Analog Comparator n Negative Input  
Negative input for analog comparators  
Analog Comparator n Output  
ACMPMn  
ACMPM  
ACOMPn_OUT  
AMPn-  
Analog Differential Amplifier n Input Channel  
Analog Differential Amplifier n Input Channel  
Analog Converter Input Channel n  
AMPn+  
ADCn  
5
7734Q–AVR–02/12  
 
AT90PWM81/161  
Table 2-2.  
Pin out description.  
SO 20 QFN32  
Port  
PB0  
PE0  
PD0  
PB1  
PB2  
VCC  
GND  
PE1  
PE2  
pins  
pins  
GP  
30 T1  
31 RESET# OCD, INT2  
2 CLKO, SS  
3
PSC  
PSCOUT23  
ADC  
Analog  
ACMP3_OUT  
1
2
NA  
ACMP3_OUT_A  
3
4
5
6
7
8
PSCOUT20  
PSCOUT21  
4 INT0  
5 Power Supply  
6 Ground  
7 XTAL1  
PSCIN2  
PSCINr  
ACMP1_OUT  
ACMP1M  
10 XTAL2  
PSCOUTR0,  
PSCINrB  
PD1  
9
11  
PD2  
PD3  
PB3  
PB4  
PD4  
PB5  
AVCC  
AGND  
10  
12  
13  
14  
15 MOSI  
ADC0  
ADC1  
PSCOUTR1 ADC2  
ADC3  
ACMP1  
NA  
NA  
ACMP2_OUT  
ACMP2M  
ACMPM  
ACMP3M  
ACMP2  
11  
12  
18  
PSCIN2A  
ADC4  
ADC5  
13  
14  
15  
16  
17  
18  
19  
19 INT1, SCK  
20 Analog Supply  
21 Analog Ground  
22 AREF, Analog Ref  
23  
26  
27 MISO  
28  
29 ICP1  
ADC6  
ADC7  
PD5  
PD6  
PB6  
PD7  
PB7  
AMP0-  
AMP0+  
ACMP3  
ADC8  
ADC10  
ADC9  
NA  
PSCINrA  
PSCOUT22  
20  
2.1  
Pin Descriptions  
2.1.1  
VCC  
Digital supply voltage.  
2.1.2  
2.1.3  
GND  
Ground.  
Port B (PB7..PB0)  
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.  
Port B also serves the functions of various special features of the AT90PWM81/161 as listed on  
Table 9-3 on page 75.  
6
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
2.1.4  
Port D (PD7..PD0)  
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.  
Port D also serves the functions of various special features of the AT90PWM81/161 as listed on  
Table 9-6 on page 78.  
2.1.5  
Port E (P32..0) RESET/XTAL1/XTAL2/AREF  
Port E is an 4-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The  
Port E output buffers have symmetrical drive characteristics with both high sink and source  
capability. As inputs, Port E pins that are externally pulled low will source current if the pull-up  
resistors are activated. The Port E pins are tri-stated when a reset condition becomes active,  
even if the clock is not running.  
If the RSTDISBL Fuse is programmed, PE0 is used as an I/O pin. Note that the electrical char-  
acteristics of PE0 differ from those of the other pins.  
If the RSTDISBL Fuse is unprogrammed, PE0 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 7-1 on page 51. Shorter pulses are not guaranteed  
to generate a Reset.  
Depending on the clock selection fuse settings, PE1 can be used as input to the inverting Oscil-  
lator amplifier and input to the internal clock operating circuit.  
Depending on the clock selection fuse settings, PE2 can be used as output from the inverting  
Oscillator amplifier.  
The various special features of Port E are elaborated in Table 9-9 on page 80 and  
Section “Clock Systems and their Distribution”, page 27.  
2.1.6  
AVCC  
AVCC is the supply voltage pin for the A/D converter. It 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.  
7
7734Q–AVR–02/12  
AT90PWM81/161  
3. AVR CPU Core  
3.1  
Introduction  
This section discusses the AVR core architecture in general. The main function of the CPU core  
is to ensure correct program execution. The CPU must therefore be able to access memories,  
perform calculations, control peripherals, and handle interrupts.  
3.2  
Architectural Overview  
Figure 3-1. Block diagram of the AVR architecture.  
Data Bus 8-bit  
Program  
Counter  
Status  
and Control  
Flash  
Program  
Memory  
Interrupt  
Unit  
32 x 8  
General  
Purpose  
Registrers  
Instruction  
Register  
SPI  
Unit  
Instruction  
Decoder  
Watchdog  
Timer  
ALU  
Analog  
Comparator  
Control Lines  
I/O Module1  
I/O Module 2  
I/O Module n  
Data  
SRAM  
EEPROM  
I/O Lines  
In order to maximize performance and parallelism, the AVR uses a Harvard architecture – with  
separate memories and buses for program and data. Instructions in the program memory are  
executed with a single level pipelining. While one instruction is being executed, the next instruc-  
tion 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.  
8
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
The fast-access Register File contains 32 × 8-bit general purpose working registers with a single  
clock cycle access time. This allows single-cycle Arithmetic Logic Unit (ALU) operation. In a typ-  
ical ALU operation, two operands are output from the Register File, the operation is executed,  
and the result is stored back in the Register File – in one clock cycle.  
Six of the 32 registers can be used as 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-register, Y-register, 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 opera-  
tion, 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 for-  
mat. Every program memory address contains a 16-bit 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 (Store Program Memory) 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 posi-  
tion. The lower the Interrupt Vector address, the higher is the priority.  
The I/O memory space contains 64 addresses for CPU peripheral functions as Control Regis-  
ters, 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  
AT90PWM81/161 has Extended I/O space from 0x60 - 0xFF in SRAM where only the  
ST/STS/STD and LD/LDS/LDD instructions can be used.  
3.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 Summary” on page 301 for a detailed description.  
9
7734Q–AVR–02/12  
 
AT90PWM81/161  
3.4  
Status Register  
The Status Register contains information about the result of the most recently executed arithme-  
tic 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 Summary” on page 301. This will in many cases remove the  
need for using the dedicated compare instructions, resulting in faster and more compact code.  
The Status Register is not automatically stored when entering an interrupt routine and restored  
when returning from an interrupt. This must be handled by software.  
The AVR Status Register – SREG – is defined as:  
Bit  
7
6
5
4
3
2
1
0
I
T
H
S
V
N
Z
C
SREG  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
• Bit 7 – I: Global Interrupt Enable  
The Global Interrupt Enable bit must be set to enabled the interrupts. 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 Summary”  
on page 301.  
• Bit 6 – T: Bit Copy Storage  
The Bit Copy instructions BLD (Bit LoaD) and BST (Bit STore) use the T-bit as source or desti-  
nation 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 Summary” on page 301 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 Summary” on page 301 for detailed information.  
• Bit 3 – V: Two’s Complement Overflow Flag  
The Two’s Complement Overflow Flag V supports two’s complement arithmetic. See the  
“Instruction Set Summary” on page 301 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 Summary” on page 301 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 Summary” on page 301 for detailed information.  
10  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
• Bit 0 – C: Carry Flag  
The Carry Flag C indicates a carry in an arithmetic or logic operation. See the “Instruction Set  
Summary” on page 301 for detailed information.  
3.5  
General Purpose Register File  
The Register File is optimized for the AVR Enhanced RISC instruction set. In order to achieve  
the required performance and flexibility, the following input/output schemes are supported by the  
Register File:  
• One 8-bit output operand and one 8-bit result input  
Two 8-bit output operands and one 8-bit result input  
Two 8-bit output operands and one 16-bit result input  
• One 16-bit output operand and one 16-bit result input  
Figure 3-2 shows the structure of the 32 general purpose working registers in the CPU.  
Figure 3-2. AVR CPU General Purpose Working Registers.  
7
0
Addr.  
R0  
0x00  
0x01  
0x02  
R1  
R2  
R13  
R14  
R15  
R16  
R17  
0x0D  
0x0E  
0x0F  
0x10  
0x11  
General  
Purpose  
Working  
Registers  
R26  
R27  
R28  
R29  
R30  
R31  
0x1A  
0x1B  
0x1C  
0x1D  
0x1E  
0x1F  
X-register Low Byte  
X-register High Byte  
Y-register Low Byte  
Y-register High Byte  
Z-register Low Byte  
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 3-2, each register is also assigned a data memory address, mapping them  
directly into the first 32 locations of the user Data Space. Although not being physically imple-  
mented 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.  
3.5.1  
The X-register, Y-register, and Z-register  
The registers R26..R31 have some added functions to their general purpose usage. These reg-  
isters are 16-bit address pointers for indirect addressing of the data space. The three indirect  
address registers X, Y, and Z are defined as described in Figure 3-3 on page 12.  
11  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
Figure 3-3. The X-register, Y-register, and Z-register.  
15  
XH  
XL  
0
0
X-register  
7
0
7
R27 (0x1B)  
R26 (0x1A)  
15  
YH  
YL  
ZL  
0
0
Y-register  
Z-register  
7
0
7
R29 (0x1D)  
R28 (0x1C)  
15  
ZH  
0
0
7
7
0
R31 (0x1F)  
R30 (0x1E)  
In the different addressing modes these address registers have functions as fixed displacement,  
automatic increment, and automatic decrement (see “Instruction Set Summary” on page 301 for  
details).  
3.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 loca-  
tions 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 0x100. The Stack Pointer is decremented by one when data is pushed onto the  
Stack with the PUSH instruction, and it is decremented by two when the return address is  
pushed onto the Stack with subroutine call or interrupt. The Stack Pointer is incremented by one  
when data is popped from the Stack with the POP instruction, and it is incremented by two when  
data is popped from the Stack with return from subroutine RET or return from interrupt RETI.  
The AVR Stack Pointer is implemented as two 8-bit registers in the I/O space. The number of  
bits actually used is implementation dependent. Note that the data space in some implementa-  
tions of the AVR architecture is so small that only SPL is needed. In this case, the SPH Register  
will not be present.  
Bit  
15  
14  
13  
12  
11  
10  
9
8
SP15  
SP7  
7
SP14  
SP6  
6
SP13  
SP5  
5
SP12  
SP4  
4
SP11  
SP3  
3
SP10  
SP2  
2
SP9  
SP1  
1
SP8  
SP0  
0
SPH  
SPL  
Read/Write  
Initial Value  
R/W  
R/W  
0
R/W  
R/W  
0
R/W  
R/W  
0
R/W  
R/W  
0
R/W  
R/W  
0
R/W  
R/W  
0
R/W  
R/W  
0
R/W  
R/W  
0
0
0
0
0
0
0
0
0
3.7  
Instruction Execution Timing  
This section describes the general access timing concepts for instruction execution. The AVR  
CPU is driven by the CPU clock clkCPU, directly generated from the selected clock source for the  
chip. No internal clock division is used.  
12  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
Figure 3-4 shows the parallel instruction fetches and instruction executions enabled by the Har-  
vard architecture and the fast-access Register File concept. This is the basic pipelining concept  
to obtain up to 1 MIPS per MHz with the corresponding unique results for functions per cost,  
functions per clocks, and functions per power-unit.  
Figure 3-4. The parallel instruction fetches and instruction executions.  
T1  
T2  
T3  
T4  
clkCPU  
1st Instruction Fetch  
1st Instruction Execute  
2nd Instruction Fetch  
2nd Instruction Execute  
3rd Instruction Fetch  
3rd Instruction Execute  
4th Instruction Fetch  
Figure 3-5 shows the internal timing concept for the Register File. In a single clock cycle an ALU  
operation using two register operands is executed, and the result is stored back to the destina-  
tion register.  
Figure 3-5. Single cycle ALU operation.  
T1  
T2  
T3  
T4  
clkCPU  
Total Execution Time  
Register Operands Fetch  
ALU Operation Execute  
Result Write Back  
3.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 the section “Memory Program-  
ming” on page 248 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 “Interrupts” on page 62. 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 PSC2 CAPT – the PSC2 Capture  
Event. 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 “Interrupts” on page 62 for more infor-  
mation. The Reset Vector can also be moved to the start of the Boot Flash section by  
13  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
programming the BOOTRST Fuse, see “Boot Loader Support – Read-While-Write Self-Pro-  
gramming” on page 233.  
3.8.1  
Interrupt Behavior  
When an interrupt occurs, the Global Interrupt Enable I-bit is cleared and all interrupts are dis-  
abled. The user software can write logic one to the I-bit to enable nested interrupts. All enabled  
interrupts can then interrupt the current interrupt routine. The I-bit is automatically set when a  
Return from Interrupt instruction – RETI – is executed.  
There are basically two types of interrupts. The first type is triggered by an event that sets the  
interrupt flag. For these interrupts, the Program Counter is vectored to the actual Interrupt Vector  
in order to execute the interrupt handling routine, and hardware clears the corresponding inter-  
rupt flag. Interrupt flags can also be cleared by writing a logic one to the flag bit position(s) to be  
cleared. If an interrupt condition occurs while the corresponding interrupt enable bit is cleared,  
the interrupt flag will be set and remembered until the interrupt is enabled, or the flag is cleared  
by software. Similarly, if one or more interrupt conditions occur while the Global Interrupt Enable  
bit is cleared, the corresponding interrupt flag(s) will be set and remembered until the Global  
Interrupt Enable bit is set, and will then be executed by order of priority.  
The second type of interrupts will trigger as long as the interrupt condition is present. These  
interrupts do not necessarily have interrupt flags. If the interrupt condition disappears before the  
interrupt is enabled, the interrupt will not be triggered.  
When the AVR exits from an interrupt, it will always return to the main program and execute one  
more instruction before any pending interrupt is served.  
Note that the Status Register is not automatically stored when entering an interrupt routine, nor  
restored when returning from an interrupt routine. This must be handled by software.  
When using the CLI instruction to disable interrupts, the interrupts will be immediately disabled.  
No interrupt will be executed after the CLI instruction, even if it occurs simultaneously with the  
CLI instruction. The following example shows how this can be used to avoid interrupts during the  
timed EEPROM write sequence.  
Assembly code example  
in r16, SREG  
; store SREG value  
cli  
; disable interrupts during timed sequence  
sbiEECR, EEMWE ; start EEPROM write  
sbiEECR, EEWE  
outSREG, r16  
; restore SREG value (I-bit)  
C code example  
char cSREG;  
cSREG = SREG;  
/* store SREG value */  
/* disable interrupts during timed sequence */  
_CLI();  
EECR |= (1<<EEMWE); /* start EEPROM write */  
EECR |= (1<<EEWE);  
SREG = cSREG;  
/* restore SREG value (I-bit) */  
14  
7734Q–AVR–02/12  
AT90PWM81/161  
When using the SEI instruction to enable interrupts, the instruction following SEI will be exe-  
cuted before any pending interrupts, as shown in this example.  
Assembly code example  
sei ; set Global Interrupt Enable  
sleep; enter sleep, waiting for interrupt  
; note: will enter sleep before any pending  
; interrupt(s)  
C code example  
_SEI(); /* set Global Interrupt Enable */  
_SLEEP(); /* enter sleep, waiting for interrupt */  
/* note: will enter sleep before any pending interrupt(s) */  
3.8.2  
Interrupt Response Time  
The interrupt execution response for all the enabled AVR interrupts is four clock cycles mini-  
mum. After four clock cycles the program vector address for the actual interrupt handling routine  
is executed. During this four clock cycle period, the Program Counter is pushed onto the Stack.  
The vector is normally a jump to the interrupt routine, and this jump takes three clock cycles. If  
an interrupt occurs during execution of a multi-cycle instruction, this instruction is completed  
before the interrupt is served. If an interrupt occurs when the MCU is in sleep mode, the interrupt  
execution response time is increased by four clock cycles. This increase comes in addition to the  
start-up time from the selected sleep mode.  
A return from an interrupt handling routine takes four clock cycles. During these four clock  
cycles, the Program Counter (two bytes) is popped back from the Stack, the Stack Pointer is  
incremented by two, and the I-bit in SREG is set.  
15  
7734Q–AVR–02/12  
AT90PWM81/161  
4. Memories  
This section describes the different memories in the Atmel AT90PWM81/161. The AVR architec-  
ture has two main memory spaces, the Data Memory and the Program Memory space. In  
addition, the AT90PWM81/161 features an EEPROM Memory for data storage. All three mem-  
ory spaces are linear and regular.  
4.1  
In-System Reprogrammable Flash Program Memory  
The AT90PWM81/161 contains 8/16Kbytes On-chip In-System Reprogrammable Flash memory  
for program storage. Since all AVR instructions are 16 or 32 bits wide, the Flash is organized as  
4K × 16bits for the AT90PWM81, and 8K × 16bits for the AT90PWM161. For software security,  
the Flash Program memory space is divided into two sections, Boot Program section and Appli-  
cation Program section.  
The Flash memory has an endurance of at least 10,000 write/erase cycles. The AT90PWM81  
Program Counter (PC) is 12 bits wide, thus addressing the 8Kbytes program memory locations.  
The AT90PWM161 Program Counter (PC) is 13 bits wide, thus addressing the 16Kbytes pro-  
gram memory locations. The operation of Boot Program section and associated Boot Lock bits  
for software protection are described in detail in “Boot Loader Support – Read-While-Write Self-  
Programming” on page 233. “Memory Programming” on page 248 contains a detailed descrip-  
tion on Flash programming in SPI or Parallel programming mode.  
Constant tables can be allocated within the entire program memory address space (see the  
description of LPM – Load Program Memory in “Instruction Set Summary” on page 301).  
Timing diagrams for instruction fetch and execution are presented in “Instruction Execution Tim-  
ing” on page 12.  
Figure 4-1. Program memory map.  
Program Memory  
0x0000  
Application Flash Section  
Boot Flash Section  
0x0FFF/0x1FFF  
16  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
4.2  
SRAM Data Memory  
Figure 4-2 shows how the Atmel AT90PWM81/161 SRAM memory is organized.  
The AT90PWM81/161 is a complex microcontroller with more peripheral units than can be sup-  
ported within the 64 locations reserved in the 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 instruc-  
tions can be used.  
The lower 512 data memory locations address both the Register File, the I/O memory, Extended  
I/O memory, and the internal data SRAM. The first 32 locations address the Register File, the  
next 64 location the standard I/O memory, then 160 locations of Extended I/O memory, and the  
next 256 locations address the internal data SRAM.  
The five different addressing modes for the data memory cover: Direct, Indirect with Displace-  
ment, Indirect, Indirect with Pre-decrement, and Indirect with Post-increment. In the Register  
File, registers R26 to R31 feature the indirect addressing pointer registers.  
The direct addressing reaches the entire data space.  
The Indirect with Displacement mode reaches 63 address locations from the base address given  
by the Y-register or Z-register.  
When using register indirect addressing modes with automatic pre-decrement and post-incre-  
ment, the address registers X, Y, and Z are decremented or incremented.  
The 32 general purpose working registers, 64 I/O Registers, 160 Extended I/O Registers, and  
the 256/1024 bytes of internal data SRAM in the AT90PWM81/161 are all accessible through all  
these addressing modes. The Register File is described in “General Purpose Register File” on  
page 11.  
Figure 4-2. Data memory map.  
Data Memory  
0x0000 - 0x001F  
0x0020 - 0x005F  
0x0060 - 0x00FF  
0x0100  
32 Registers  
64 I/O Registers  
160 Ext I/O Reg.  
Internal SRAM  
(256/1024 x 8)  
0x01FF/0x04FF  
4.2.1  
SRAM Data Access Times  
This section describes the general access timing concepts for internal memory access. The  
internal data SRAM access is performed in two clkCPU cycles as described in Figure 4-3 on page  
18.  
17  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Figure 4-3. On-chip data SRAM access cycles.  
T1  
T2  
T3  
clkCPU  
Address valid  
Compute Address  
Address  
Data  
WR  
Data  
RD  
Memory Access Instruction  
Next Instruction  
4.3  
EEPROM Data Memory  
The AT90PWM81/161 contains 512 bytes of data EEPROM memory. It is organized as a sepa-  
rate data space, in which single bytes can be read and written. The EEPROM has an endurance  
of at least 100,000 write/erase cycles. The access between the EEPROM and the CPU is  
described in the following, specifying the EEPROM Address Registers, the EEPROM Data Reg-  
ister, and the EEPROM Control Register.  
For a detailed description of SPI and Parallel data downloading to the EEPROM, see “Serial  
Downloading” on page 261, and “Parallel Programming Parameters, Pin Mapping, and Com-  
mands” on page 252 respectively.  
4.3.1  
EEPROM Read/Write Access  
The EEPROM Access Registers are accessible in the I/O space.  
The write access time for the EEPROM is given in Table 4-2 on page 21. A self-timing function,  
however, lets the user software detect when the next byte can be written. If the user code con-  
tains instructions that write the EEPROM, some precautions must be taken. In heavily filtered  
power supplies, VCC is likely to rise or fall slowly on power-up/down. This causes the device for  
some period of time to run at a voltage lower than specified as minimum for the clock frequency  
used. For details on how to avoid problems in these situations see “Preventing EEPROM Cor-  
ruption” on page 25.  
In order to prevent unintentional EEPROM writes, a specific write procedure must be followed.  
Refer to the description of the EEPROM Control Register for details on this.  
When the EEPROM is read, the CPU is halted for four clock cycles before the next instruction is  
executed. When the EEPROM is written, the CPU is halted for two clock cycles before the next  
instruction is executed.  
18  
7734Q–AVR–02/12  
 
AT90PWM81/161  
4.3.2  
EEARH and EEARL - EEPROM Address Registers  
Bit  
15  
14  
13  
12  
11  
10  
9
8
EEAR8  
EEAR0  
0
EEARH  
EEAR7  
EEAR6  
EEAR5  
EEAR4  
EEAR3  
EEAR2  
EEAR1  
EEARL  
7
6
5
4
3
2
1
Read/Write  
Initial Value  
R
R
R
R
R
R
R
R/W  
R/W  
X
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
X
X
X
X
X
X
X
X
• Bits 15..9 – Reserved Bits  
These bits are reserved bits in the AT90PWM81/161 and will always read as zero.  
• Bits 8..0 – EEAR8..0: EEPROM Address  
The EEPROM Address Registers – EEARH and EEARL specify the EEPROM address in the  
512 bytes EEPROM space. The EEPROM data bytes are addressed linearly between 0 and  
511. The initial value of EEAR is undefined. A proper value must be written before the EEPROM  
may be accessed.  
4.3.3  
EEDR - EEPROM Data Register  
Bit  
7
6
5
4
3
2
1
0
EEDR7  
R/W  
0
EEDR6  
R/W  
0
EEDR5  
R/W  
0
EEDR4  
R/W  
0
EEDR3  
R/W  
0
EEDR2  
R/W  
0
EEDR1  
R/W  
0
EEDR0  
R/W  
0
EEDR  
Read/Write  
Initial Value  
• Bits 7..0 – EEDR7.0: EEPROM Data  
For the EEPROM write operation, the EEDR Register contains the data to be written to the  
EEPROM in the address given by the EEAR Register. For the EEPROM read operation, the  
EEDR contains the data read out from the EEPROM at the address given by EEAR.  
4.3.4  
EECR - EEPROM Control Register  
Bit  
7
6
5
4
3
2
1
0
NVMBSY EEPAGE  
EEPM1  
R/W  
X
EEPM0  
R/W  
X
EERIE  
R/W  
0
EEMWE  
R/W  
0
EEWE  
R/W  
X
EERE  
R/W  
0
EECR  
Read/Write  
Initial Value  
R/W  
X
R/W  
X
• Bits 7 – NVMBSY: Non-volatile memory busy  
The NVMBSY bit is a status bit that indicates that the NVM memory (FLASH, EEPROM, Lock-  
bits) is busy programming. Once a program operation is started, the bit will be set and it remains  
set until the program operation is completed.  
Bits 6 – EEPAGE: EEPROM page access (multiple bytes access mode)  
Writing EEPAGE to one enables the multiple bytes access mode. That means that several bytes  
can be programmed simultaneously into the EEPROM. When the EEPAGE bit has been written  
to one, the EEPAGE bit remains set until an EEPROM program operation is completed. Alterna-  
tively the bit is cleared when the temporary EEPROM buffer is flushed in software (see EEPMn  
bits description). Any write to EEPAGE while EEPE is one will be ignored. See  
Section “Program multiple bytes in one Atomic operation”, page 21 for details on how to load  
data into the temporary EEPROM page and the usage of the EEPAGE bit.  
19  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
• Bits 5..4 – EEPM1 and EEPM0: EEPROM Programming Mode Bits  
The EEPROM Programming mode bit setting defines which programming action that will be trig-  
gered when writing EEWE. It is possible to program data in one atomic operation (erase the old  
value and program the new value) or to split the Erase and Write operations in two different  
operations. The Programming times for the different modes are shown in Table 4-1. While  
EEWE is set, any write to EEPMn will be ignored. During reset, the EEPMn bits will be reset to  
0b00 unless the EEPROM is busy programming.  
Table 4-1.  
EEPROM mode bits.  
Programming  
EEPM1  
EEPM0  
time  
3.4ms  
1.8ms  
1.8ms  
Operation  
0
0
1
1
0
1
0
1
Erase and write in one operation (atomic operation)  
Erase only  
Write only  
Flush temporary EEPROM page buffer  
• Bit 3 – EERIE: EEPROM Ready Interrupt Enable  
Writing EERIE to one enables the EEPROM Ready Interrupt if the I bit in SREG is set. Writing  
EERIE to zero disables the interrupt. The EEPROM Ready interrupt generates a constant inter-  
rupt when EEWE is cleared. The interrupt will not be generated during EEPROM write or SPM.  
• Bit 2 – EEMWE: EEPROM Master Write Enable  
The EEMWE bit determines whether setting EEWE to one causes the EEPROM to be written.  
When EEMWE is set, setting EEWE within four clock cycles will write data to the EEPROM at  
the selected address If EEMWE is zero, setting EEWE will have no effect. When EEMWE has  
been written to one by software, hardware clears the bit to zero after four clock cycles. See the  
description of the EEWE bit for an EEPROM write procedure.  
• Bit 1 – EEWE: EEPROM Write Enable  
The EEPROM Write Enable Signal EEWE is the write strobe to the EEPROM. When address  
and data are correctly set up, the EEWE bit must be written to one to write the value into the  
EEPROM. The EEMWE bit must be written to one before a logical one is written to EEWE, oth-  
erwise no EEPROM write takes place. The following procedure should be followed when writing  
the EEPROM (the order of steps 3 and 4 is not essential):  
1. Wait until EEWE becomes zero.  
2. Wait until SPMEN (Store Program Memory Enable) in SPMCSR (Store Program Mem-  
ory Control and Status Register) becomes zero.  
3. Write new EEPROM address to EEAR (optional).  
4. Write new EEPROM data to EEDR (optional).  
5. Write a logical one to the EEMWE bit while writing a zero to EEWE in EECR.  
6. Within four clock cycles after setting EEMWE, write a logical one to EEWE.  
The EEPROM can not be programmed during a CPU write to the Flash memory. The software  
must check that the Flash programming is completed before initiating a new EEPROM write.  
Step 2 is only relevant if the software contains a Boot Loader allowing the CPU to program the  
Flash. If the Flash is never being updated by the CPU, step 2 can be omitted. See “Boot Loader  
Support – Read-While-Write Self-Programming” on page 233 for details about Boot  
programming.  
20  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Caution: An interrupt between step 5 and step 6 will make the write cycle fail, since the  
EEPROM Master Write Enable will time-out. If an interrupt routine accessing the EEPROM is  
interrupting another EEPROM access, the EEAR or EEDR Register will be modified, causing the  
interrupted EEPROM access to fail. It is recommended to have the Global Interrupt Flag cleared  
during all the steps to avoid these problems.  
When the write access time has elapsed, the EEWE bit is cleared by hardware. The user soft-  
ware can poll this bit and wait for a zero before writing the next byte. When EEWE has been set,  
the CPU is halted for two cycles before the next instruction is executed.  
• Bit 0 – EERE: EEPROM Read Enable  
The EEPROM Read Enable Signal EERE is the read strobe to the EEPROM. When the correct  
address is set up in the EEAR Register, the EERE bit must be written to a logic one to trigger the  
EEPROM read. The EEPROM read access takes one instruction, and the requested data is  
available immediately. When the EEPROM is read, the CPU is halted for four cycles before the  
next instruction is executed.  
The user should poll the EEWE bit before starting the read operation. If a write operation is in  
progress, it is neither possible to read the EEPROM, nor to change the EEAR Register.  
The calibrated Oscillator is used to time the EEPROM accesses. Table 4-2 lists the typical pro-  
gramming time for EEPROM access from the CPU.  
Table 4-2.  
Symbol  
EEPROM programming time.  
Number of calibrated RC oscillator cycles  
Typical programming time  
EEPROM write  
(from CPU)  
26368  
3.3ms  
4.3.5  
Program multiple bytes in one Atomic operation  
It is possible to write multiple bytes into the EEPROM. Before initiating a programming  
(erase/write), the data to be written has to be loaded into the temporary EEPROM page buffer.  
Writing EEPAGE to one enables a load operation.  
When EEPAGE bit is written to one, the temporary EEPROM page buffer is ready for loading. To  
load data into the temporary EEPROM page buffer, the address and data must be written into  
EEARL and EEDR respectively. Note that the data is loaded when EEDR is updated. Therefore,  
the address must be written before data. This operation is repeated until the temporary  
EEPROM page buffer is filled up or until all data to be written have been loaded. The number of  
bytes that is loaded must not exceed the temporary EEPROM page size before performing a  
program operation. Note that it is not possible to write more than one time to each byte in the  
temporary EEPROM page buffer before executing a program operation. If the same byte is writ-  
ten multiple times, the content in the temporary EEPROM page will be bit wise AND between the  
written data (that is, if 0xaa and 0x55 is loaded to the same byte, the result will be 0x00). The  
temporary EEPROM buffer will be ready for new data after the program operation has com-  
pleted. Alternatively, the temporary EEPROM buffer is flushed and ready for new data by writing  
EEPE (within four cycles after EEMPE is written) if the EEPMn bits are 0b11. When the tempo-  
rary EEPROM buffer is flushed, the EEPAGE bit will be cleared. Loading data into the temporary  
EEPROM buffer takes three CPU clock cycles. If EEDR is written while EEPAGE is set, the CPU  
is halted to ensure that the operation takes three cycles.  
21  
7734Q–AVR–02/12  
 
AT90PWM81/161  
The order the different bits and registers should be accessed is:  
1
2
3
4
5
Write EEPAGE in EECR (loading of temporary EEPROM buffer is enabled).  
Write the address bits needed to address bytes within a page into EEARL.  
Write data to EEDR.  
Repeat 2 and 3 above until the buffer is filled up or until all data is loaded.  
Write the remaining address bits into EEARH:EEARL.  
a.  
Select which programming mode that should be executed (EEPMn bits). Write the EEPE  
bit in EECR (within four cycles after EEMPE has been written) to start a program opera-  
tion. The temporary EEPROM page buffer will auto-erase after program operation is  
completed.  
OR  
b.  
If an error situation occurred and the loading should be terminated by software: Write  
EEPM1:0 to 0b11 and trigger the flushing by writing EEPE (within four cycles after  
EEMPE has been written).  
4.4  
Fuse Bits  
The AT90PWM81/161 has three Fuse bytes. Table 4-3 through Table 4-5 on page 23 describe  
briefly the functionality of all the fuses and how they are mapped into the Fuse bytes. Note that  
the fuses are read as logical zero, “0”, if they are programmed.  
Table 4-3.  
Extended low fuse byte.  
Extended fuse byte  
PSC2RB  
Bit no.  
Description  
Default value  
7
6
5
4
3
2
1
0
PSC2 reset behavior  
1
PSC2RBA  
PSC2 reset behavior for OUT22 & 23  
PSC reduced reset behavior  
PSCOUT & PSCOUTR reset value  
PSC & PSCR inputs reset behavior  
Brown-out detector trigger level  
Brown-out detector trigger level  
Brown-out detector trigger level  
1
PSCRRB  
1
PSCRV  
1
PSCINRB  
1
BODLEVEL2 (1)  
BODLEVEL1 (1)  
BODLEVEL0 (1)  
1 (unprogrammed)  
0 (programmed)  
1 (unprogrammed)  
Notes: 1. See Table 7-2 on page 53 for BODLEVEL fuse decoding.  
22  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
Table 4-4.  
High fuse byte  
RSTDISBL (1)  
DWEN  
Fuse high byte.  
Bit no.  
Description  
Default value  
7
6
External reset disable  
debugWIRE enable  
1 (unprogrammed)  
1 (unprogrammed)  
Enable serial program and data  
downloading  
0 (programmed, SPI  
programming enabled)  
SPIEN (2)  
WDTON (3)  
EESAVE  
5
4
3
Watchdog timer always on  
1 (unprogrammed)  
EEPROM memory is preserved  
through the chip erase  
1 (unprogrammed), EEPROM  
not reserved  
Select boot size  
(see Table 20-7 on page 246 for  
details)  
BOOTSZ1  
2
0 (programmed) (4)  
Select boot size  
(see Table 20-7 on page 246 for  
details)  
BOOTSZ0  
BOOTRST  
1
0
0 (programmed) (4)  
1 (unprogrammed)  
Select reset vector  
Notes: 1. See “Alternate Functions of Port E” on page 80 for description of RSTDISBL fuse.  
2. The SPIEN Fuse is not accessible in serial programming mode.  
3. See “Watchdog timer configuration.” on page 60 for details.  
4. The default value of BOOTSZ1..0 results in maximum boot size.  
Table 4-5.  
Low fuse byte  
CKDIV8 (4)  
CKOUT (3)  
SUT1  
Fuse low byte.  
Bit no.  
Description  
Default value  
7
6
5
4
3
2
1
0
Divide clock by 8  
Clock output  
0 (programmed)  
1 (unprogrammed)  
1 (unprogrammed) (1)  
0 (programmed) (1)  
0 (programmed) (2)  
0 (programmed) (2)  
1 (unprogrammed) (2)  
0 (programmed) (2)  
Select start-up time  
Select start-up time  
Select clock source  
Select clock source  
Select clock source  
Select clock source  
SUT0  
CKSEL3  
CKSEL2  
CKSEL1  
CKSEL0  
Note:  
1. The default value of SUT1..0 results in maximum start-up time for the default clock source.  
See Table 5-4 on page 30 for details.  
2. The default setting of CKSEL3..0 results in internal RC oscillator @ 8MHz. See Table 5-1 on  
page 28 for details.  
3. The CKOUT fuse allows the system clock to be output on PORTD0. See “Clock Output Buffer”  
on page 34 for details.  
4. See “System Clock Prescaler” on page 39 for details.  
The status of the Fuse bits is not affected by Chip Erase. Note that the Fuse bits are locked if  
Lock bit1 (LB1) is programmed. Program the Fuse bits before programming the Lock bits.  
23  
7734Q–AVR–02/12  
 
 
 
 
 
 
 
 
 
AT90PWM81/161  
4.4.1  
Code examples  
The following code examples show one assembly and one C function for writing to the  
EEPROM. The examples assume that interrupts are controlled (for example, by disabling inter-  
rupts globally) so that no interrupts will occur during execution of these functions. The examples  
also assume that no Flash Boot Loader is present in the software. If such code is present, the  
EEPROM write function must also wait for any ongoing SPM command to finish.  
Assembly code example  
EEPROM_write:  
; Wait for completion of previous write  
sbic EECR,EEWE  
rjmp EEPROM_write  
; Set up address (r18:r17) in address register  
out EEARH, r18  
out EEARL, r17  
; Write data (r16) to data register  
out EEDR,r16  
; Write logical one to EEMWE  
sbi EECR,EEMWE  
; Start eeprom write by setting EEWE  
sbi EECR,EEWE  
ret  
C code example  
void EEPROM_write (unsigned int uiAddress, unsigned char ucData)  
{
/* Wait for completion of previous write */  
while(EECR & (1<<EEWE))  
;
/* Set up address and data registers */  
EEAR = uiAddress;  
EEDR = ucData;  
/* Write logical one to EEMWE */  
EECR |= (1<<EEMWE);  
/* Start eeprom write by setting EEWE */  
EECR |= (1<<EEWE);  
}
24  
7734Q–AVR–02/12  
AT90PWM81/161  
The next code examples show assembly and C functions for reading the EEPROM. The exam-  
ples assume that interrupts are controlled so that no interrupts will occur during execution of  
these functions.  
Assembly code example  
EEPROM_read:  
; Wait for completion of previous write  
sbic EECR,EEWE  
rjmp EEPROM_read  
; Set up address (r18:r17) in address register  
out EEARH, r18  
out EEARL, r17  
; Start eeprom read by writing EERE  
sbi EECR,EERE  
; Read data from data register  
in r16,EEDR  
ret  
C code example  
unsigned char EEPROM_read(unsigned int uiAddress)  
{
/* Wait for completion of previous write */  
while(EECR & (1<<EEWE))  
;
/* Set up address register */  
EEAR = uiAddress;  
/* Start eeprom read by writing EERE */  
EECR |= (1<<EERE);  
/* Return data from data register */  
return EEDR;  
}
4.4.2  
Preventing EEPROM Corruption  
During periods of low VCC, the EEPROM data can be corrupted because the supply voltage is  
too low for the CPU and the EEPROM to operate properly. These issues are the same as for  
board level systems using EEPROM, and the same design solutions should be applied.  
An EEPROM data corruption can be caused by two situations when the voltage is too low. First,  
a regular write sequence to the EEPROM requires a minimum voltage to operate correctly. Sec-  
ondly, the CPU itself can execute instructions incorrectly, if the supply voltage is too low.  
EEPROM data corruption can easily be avoided by following this design recommendation:  
Keep the AVR RESET active (low) during periods of insufficient power supply voltage. This can  
be done by enabling the internal Brown-out Detector (BOD). If the detection level of the internal  
BOD does not match the needed detection level, an external low VCC reset Protection circuit can  
be used. If a reset occurs while a write operation is in progress, the write operation will be com-  
pleted provided that the power supply voltage is sufficient.  
25  
7734Q–AVR–02/12  
AT90PWM81/161  
4.5  
I/O Memory  
The I/O space definition of the AT90PWM81/161 is shown in “Register Summary” on page 297.  
All AT90PWM81/161 I/Os and peripherals are placed in the I/O space. All I/O locations may be  
accessed by the LD/LDS/LDD and ST/STS/STD instructions, transferring data between the 32  
general purpose working registers and the I/O space. I/O registers within the address range  
0x00 - 0x1F are directly bit-accessible using the SBI and CBI instructions. In these registers, the  
value of single bits can be checked by using the SBIS and SBIC instructions. Refer to the  
“Instruction Set Summary” on page 301 for more details. When using the I/O specific commands  
IN and OUT, the I/O addresses 0x00 - 0x3F must be used. When addressing I/O registers as  
data space using LD and ST instructions, 0x20 must be added to these addresses. The  
AT90PWM81/161 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.  
For compatibility with future devices, reserved bits should be written to zero if accessed.  
Reserved I/O memory addresses should never be written.  
Some of the status flags are cleared by writing a logical one to them. Note that, unlike most other  
AVR’s, the CBI and SBI instructions will only operate on the specified bit, and can therefore be  
used on registers containing such status flags. The CBI and SBI instructions work with registers  
0x00 to 0x1F only.  
The I/O and peripherals control registers are explained in later sections.  
4.6  
General Purpose I/O Registers  
The AT90PWM81/161 contains four General Purpose I/O Registers. These registers can be  
used for storing any information, and they are particularly useful for storing global variables and  
status flags.  
The General Purpose I/O Registers, within the address range 0x00 - 0x1F, are directly bit-  
accessible using the SBI, CBI, SBIS, and SBIC instructions.  
4.6.1  
4.6.2  
4.6.3  
GPIOR0 - General Purpose I/O Register 0  
Bit  
7
6
5
4
3
2
1
0
GPIOR07 GPIOR06 GPIOR05 GPIOR04 GPIOR03 GPIOR02 GPIOR01 GPIOR00 GPIOR0  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
GPIOR1 - General Purpose I/O Register 1  
Bit  
7
6
5
4
3
2
1
0
GPIOR17 GPIOR16 GPIOR15 GPIOR14 GPIOR13 GPIOR12 GPIOR11 GPIOR10 GPIOR1  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
GPIOR2 - General Purpose I/O Register 2  
Bit  
7
6
5
4
3
2
1
0
GPIOR27 GPIOR26 GPIOR25 GPIOR24 GPIOR23 GPIOR22 GPIOR21 GPIOR20 GPIOR2  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
26  
7734Q–AVR–02/12  
 
 
 
 
 
AT90PWM81/161  
5. System Clock and Clock Options  
The Atmel AT90PWM81/161 provides a large number of clock sources. Those can be divided in  
two categories: internal and external.  
After reset, CKSEL fuses select one clock source. Once the device is running, software clock  
switching is available on any other clock sources.  
Some hardware controls are provided for clock switching management but some specific proce-  
dures must be observed. Some settings may lead the user to program the device in an  
inadequate configuration.  
5.1  
Clock Systems and their Distribution  
Figure 5-1 presents the principal clock systems in the AVR and their distribution. All of the clocks  
may not be active at a given time. In order to reduce power consumption, the clocks from mod-  
ules not being used can be halted by using different sleep modes or by using features of the  
dynamic clock switch (“Power Management and Sleep Modes” on page 45 or “Dynamic Clock  
Switch” on page 35). The clock systems are detailed below.  
Figure 5-1. Clock distribution.  
PSC2/PSCR  
General I/O  
Modules  
Flash and  
EEPROM  
ADC  
CPU Core  
RAM  
clkADC  
clkCPU  
clkI/O  
AVR Clock  
Control Unit  
clkFLASH  
CLK  
PLL  
PLL  
Reset Logic  
Watchdog Timer  
Source Clock  
CLK PLL/4  
Prescaler  
Watchdog Clock  
PLL Input  
Multiplexer  
Clock switch  
CKOUT  
Fuse  
(Crystal  
Oscillator)  
Calibrated RC  
Oscillator  
External Clock  
Watchdog  
Oscillator  
XTAL1  
XTAL2  
CLKO  
5.1.1  
clkCPU - CPU Clock  
The CPU clock is routed to parts of the system concerned with operation of the AVR core.  
Examples of such modules are the General Purpose Register File, the Status Register and the  
27  
7734Q–AVR–02/12  
 
 
 
 
 
 
AT90PWM81/161  
Data memory holding the Stack Pointer. Halting the CPU clock inhibits the core from performing  
general operations and calculations.  
5.1.2  
clkI/O - I/O Clock  
The I/O clock is used by the majority of the I/O modules, like Timer/Counter. The I/O clock is  
also used by the External Interrupt module, but note that some external interrupts are detected  
by asynchronous logic, allowing such interrupts to be detected even if the I/O clock is halted.  
5.1.3  
5.1.4  
5.1.5  
clkFLASH - Flash Clock  
The Flash clock controls operation of the Flash interface. The Flash clock is usually active simul-  
taneously with the CPU clock.  
clkPLL - PLL Clock  
The PLL clock allows the PSC modules to be clocked directly from a 64/32MHz clock. A 16MHz  
clock is also derived for the CPU.  
clkADC - ADC Clock  
The ADC is provided with a dedicated clock domain. This allows halting the CPU and I/O clocks  
in order to reduce noise generated by digital circuitry. This gives more accurate ADC conversion  
results.  
5.2  
Clock Sources  
The device has the following clock source options, selectable by Flash Fuse bits (default) or by  
the CLKSELR register (dynamic clock switch circuit) as shown below. The clock from the  
selected source is input to the AVR clock generator, and routed to the appropriate modules.  
Table 5-1.  
Device clocking options select (1) , PLL source and PE1 and PE2 functionality.  
Device clocking option  
System  
clock  
CKSEL3..0 (3)  
CSEL3..0 (4)  
PLL input (2)  
RC Osc (6)  
RC Osc (6)  
RC Osc (6)  
N/A  
PE1  
CLKI  
I/O  
PE2  
I/O  
I/O  
I/O  
I/O  
External clock  
Ext Clk (8)  
0000  
0001  
0010  
0011  
PLL output divided by 4 : 16MHz driven by internal RC  
Calibrated internal RC oscillator 8MHz  
Internal 128kHz RC oscillator (WD)  
PLL / 4  
RC Osc (6)  
WD (7)  
I/O  
I/O  
PLL output divided by 4 / PLL driven by external  
crystal/ceramic resonator  
PLL / 4  
Ext Osc (5)  
0100  
XTAL1  
XTAL2  
PLL output divided by 4/ PLL driven by external clock  
Calibrated internal RC oscillator 1MHz  
PLL / 4  
Ext Clk (8)  
N/A  
0101  
0110  
CLKI  
I/O  
I/O  
RC Osc (6)  
Ext Osc (5)  
Ext Osc (5)  
Ext Osc (5)  
Ext Osc (5)  
Ext Osc (5)  
Ext Osc (5)  
I/O  
External crystal/ceramic resonator (3.0MHz - 8.0MHz)  
External crystal/ceramic resonator (0.9MHz - 3.0MHz)  
External crystal/ceramic resonator (0.9MHz - 3.0MHz)  
External crystal/ceramic resonator (3.0MHz - 8.0MHz)  
External crystal/ceramic resonator (3.0MHz - 8.0MHz)  
External crystal/ceramic resonator (3.0MHz - 8.0MHz)  
Ext Osc (5)  
RC Osc (6)  
RC Osc (6)  
RC Osc (6)  
RC Osc (6)  
RC Osc (6)  
0111 b  
1000 b  
1001 b  
1010 b  
1011 b  
1100 b  
XTAL1  
XTAL1  
XTAL1  
XTAL1  
XTAL1  
XTAL1  
XTAL2  
XTAL2  
XTAL2  
XTAL2  
XTAL2  
XTAL2  
28  
7734Q–AVR–02/12  
 
 
 
 
 
AT90PWM81/161  
Table 5-1.  
Device clocking options select (1) , PLL source and PE1 and PE2 functionality. (Continued)  
Device clocking option  
System  
clock  
CKSEL3..0 (3)  
PLL input (2)  
RC Osc (6)  
RC Osc (6)  
RC Osc (6)  
CSEL3..0 (4)  
1101 b  
PE1  
PE2  
External crystal/ceramic resonator (3.0MHz - 8.0MHz)  
External crystal/ceramic resonator (8.0MHz - 16.0MHz)  
External crystal/ceramic resonator (8.0MHz - 16.0MHz)  
Ext Osc (5)  
Ext Osc (5)  
Ext Osc (5)  
XTAL1  
XTAL1  
XTAL1  
XTAL2  
XTAL2  
XTAL2  
1110 b  
1111 b  
Note:  
1. For all fuses “1” means unprogrammed while “0” means programmed.  
2. PLL must be driven by a nominal 8MHz clock source.  
3. Flash fuse bits.  
4. CLKSELR register bits.  
5. Ext Osc: External oscillator.  
6. RC Osc: Internal RC oscillator (1MHz or 8MHz).  
7. WD:  
Internal watch dog RC oscillator 128kHz.  
8. Ext Clk: External clock input.  
The various choices for each clocking option is given in the following sections.  
When the CPU wakes up from Power-down, or when a new clock source is enabled by the  
dynamic clock switch circuit, the selected clock source is used to time the start-up, ensuring sta-  
ble oscillator operation before instruction execution starts.  
When the CPU starts from reset, there is an additional delay allowing the power to reach a sta-  
ble level before commencing normal operation. The Watchdog Oscillator is used for timing this  
real-time part of the start-up time. The number of WDT Oscillator cycles used for each time-out  
is shown in Table 5-2.  
Table 5-2.  
Number of watchdog oscillator cycles.  
Typical time-out  
4ms  
Number of cycles  
512  
64ms  
8K (8,192)  
5.2.1  
Default Clock Source  
The device will always starts up from reset using the clock source defined by CKSEL Fuses the  
start-up time defined by SUT Fuses. This configuration is latched in CLKSELR register at reset.  
The device will always starts up at Power-on using the clock source defined by CLKSELR regis-  
ter (CSEL3..0 and CSUT1:0).  
The device is shipped with CKSEL Fuses = 0010 b, SUT Fuses = 10 b, and CKDIV8 Fuse pro-  
grammed. The default clock source setting is therefore the Internal RC Oscillator running at  
8MHz with longest start-up time and an initial system clock prescaling of 8. This default setting  
ensures that all users can make their desired clock source setting using an In-System or High-  
voltage Programmer. This set-up must be taken into account when using ISP tools.  
5.2.2  
Calibrated Internal RC Oscillator  
By default, the Internal RC OScillator provides an approximate 8.0MHz clock or a 1MHz clock.  
Though voltage and temperature dependent, this clock can be very accurately calibrated by the  
user.  
29  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
The switch between 8MHz and 1MHz is done by the CKRC81 bit in MCUCR register. See  
“MCUCR - MCU Control Register” on page 42 for more details.The RC oscillator can be  
accessed by two CKSEL or CSEL configurations. At reset, the CKRC81 bit is initialised with the  
value compatible with CKSEL value (1 for CKSEL3..0 = 0110, 0 for all other values).  
The RC oscillator is active for any CKSEL3..0 or CSEL3..0 configuration where it is used as sys-  
tem clock or PLL source clock. The RC oscillator is diabled in the following CKSEL3..0 or  
CSEL3..0 cases:  
0011 (128k oscillator)  
0100, 0101 (PLL/4 system clock driven by external clock or oscillator)  
1100, 1101 (External oscillator)  
The device is shipped with the CKDIV8 Fuse programmed. See “System Clock Prescaler” on  
page 39 for more details. This clock may be selected as the system clock by programming the  
CKSEL Fuses or CSEL field as shown in Table 5-1 on page 28. If selected, it will operate with no  
external components. During reset, hardware loads the calibration byte into the OSCCAL Regis-  
ter and thereby automatically calibrates the RC Oscillator. The accuracy of this calibration is  
shown as Factory calibration in Table 22-1 on page 270.  
By changing the OSCCAL register from SW, see “OSCCAL – Oscillator Calibration Register” on  
page 39, it is possible to get a higher calibration accuracy than by using the factory calibration.  
The accuracy of this calibration is shown as User calibration in Table 22-1 on page 270.  
When this Oscillator is used as the chip clock, the Watchdog Oscillator will still be used for the  
Watchdog Timer and for the Reset Time-out. For more information on the pre-programmed cali-  
bration value, see the section “Calibration Byte” on page 252.  
Table 5-3.  
Internal calibrated RC oscillator operating modes (1)(3)  
.
Frequency range (2) (MHz)  
CKSEL3..0  
0010  
7.6 - 8.4  
0.95 - 1.05 (4)  
0010  
Notes: 1. The device is shipped with this option selected.  
2. The frequency ranges are preliminary values. Actual values are TBD.  
3. If 8MHz frequency exceeds the specification of the device (depends on VCC), the CKDIV8  
Fuse can be programmed in order to divide the internal frequency by 8.  
4. Switch between 8MHz and 1MHz is done by CKRC81 bit in MCUCR register.  
When this oscillator is selected, start-up times are determined by the SUT Fuses as shown in  
Table 5-4 on page 30.  
Table 5-4.  
Start-up times for the internal calibrated RC Oscillator clock selection.  
Start-up time from power-  
down  
Additional delay from  
reset (VCC = 5.0V)  
Power conditions  
BOD enabled  
SUT1..0  
00  
6CK  
6CK  
14CK (1)  
Fast rising power  
Slowly rising power  
14CK + 4.1ms  
14CK + 65ms (2)  
01  
6CK  
10  
Reserved  
11  
Note:  
1. If the RSTDISBL fuse is programmed, this start-up time will be increased to  
14CK + 4.1ms to ensure programming mode can be entered.  
2. The device is shipped with this option selected.  
30  
7734Q–AVR–02/12  
 
 
 
 
 
 
 
 
AT90PWM81/161  
5.2.2.1  
RC Oscillator calibration at Factory  
The RC oscillator is calibrated at 3V, 25°C for an 8MHz target frequency with an Accuracy 1%.  
The corresponding value OSCAL (@Amb.) is stored in the signature row and automatically  
loaded in the OSCAL register at reset.  
The RC oscillator is monitored at 105°C or 125°C (versus Product version) with an accuracy  
within 5% limits.  
5.2.3  
128KHz Internal Oscillator  
The 128kHz internal Oscillator is a low power Oscillator providing a clock of 128kHz. The fre-  
quency is nominal at 3V and 25°C. This clock may be select as the system clock by  
programming CKSEL Fuses or CSEL field as shown in Table 5-1 on page 28.  
When this clock source is selected, start-up times are determined by the SUT Fuses or by CSUT  
field as shown in Table 5-5.  
Table 5-5.  
Start-up times for the 128kHz internal oscillator.  
SUT1..0 (1)  
Start-up time from power-  
down  
Additional delay from  
Recommended  
usage  
CSUT1..0 (2)  
reset  
00  
01  
10  
11  
6 CK  
6 CK  
6 CK  
14CK  
BOD enabled  
14CK + 4ms  
14CK + 64ms  
Fast rising power  
Slowly rising power  
Reserved  
Notes: 1. Flash Fuse bits.  
2. CLKSELR register bits.  
5.2.4  
Crystal Oscillator  
XTAL1 and XTAL2 are input and output, respectively, of an inverting amplifier which can be con-  
figured for use as an On-chip Oscillator, as shown in Figure 5-2 on page 31. Either a quartz  
crystal or a ceramic resonator may be used.  
C1 and C2 should always be equal for both crystals and resonators. The optimal value of the  
capacitors depends on the crystal or resonator in use, the amount of stray capacitance, and the  
electromagnetic noise of the environment. Some initial guidelines for choosing capacitors for  
use with crystals are given in Table 5-6. For ceramic resonators, the capacitor values given by  
the manufacturer should be used.  
Figure 5-2. Crystal oscillator connections.  
C2  
XTAL2  
C1  
XTAL1  
GND  
31  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
The Oscillator can operate in three different modes, each optimized for a specific frequency  
range. The operating mode is selected by CKSEL3..1 fuses or by CSEL3..1 field as shown in  
Table 5-6.  
Table 5-6.  
CKSEL3..1 (1)  
CSEL3..1 (2)  
Crystal oscillator operating modes.  
Recommended range for capacitors  
C1 and C2 for use with crystals [pF]  
Frequency range [MHz]  
100 (3)  
0.4 - 0.9  
0.9 - 3.0  
3.0 - 8.0  
8.0 - 16.0  
101  
12 - 22  
12 - 22  
12 - 22  
110  
111  
Notes: 1. Flash fuse bits.  
2. CLKSELR register bits.  
3. This option should not be used with crystals, only with ceramic resonators.  
The CKSEL0 Fuse together with the SUT1..0 Fuses or CSEL0 together with CSUT1..0 field  
select the start-up times as shown in Table 5-7.  
Table 5-7.  
Start-up times for the crystal oscillator clock selection.  
CKSEL0  
Start-up time from  
power-down and  
power-save  
Additional delay  
from reset  
(VCC = 5.0V)  
SUT1..0 (1)  
CSUT1..0 (2)  
(1)  
CSEL0 (2)  
Recommended usage  
Ceramic resonator,  
fast rising power  
0
00  
01  
10  
11  
00  
01  
10  
11  
258CK (3)  
14CK + 4.1ms  
14CK + 65ms  
14CK  
Ceramic resonator,  
slowly rising power  
0
0
0
1
1
1
1
258CK (3)  
Ceramic resonator,  
BOD enabled  
1K (1024)CK (4)  
1K (1024)CK (4)  
1K (1024)CK (4)  
16K (16384)CK  
16K (16384)CK  
16K (16384)CK  
Ceramic resonator,  
fast rising power  
14CK + 4.1ms  
14CK + 65ms  
14CK  
Ceramic resonator,  
slowly rising power  
Crystal oscillator,  
BOD enabled  
Crystal oscillator,  
fast rising power  
14CK + 4.1ms  
14CK + 65ms  
Crystal oscillator,  
slowly rising power  
Notes: 1. Flash fuse bits.  
2. CLKSELR register bits.  
3. These options should only be used when not operating close to the maximum frequency of the  
device, and only if frequency stability at start-up is not important for the application. These  
options are not suitable for crystals.  
4. These options are intended for use with ceramic resonators and will ensure frequency stability  
at start-up. They can also be used with crystals when not operating close to the maximum fre-  
quency of the device, and if frequency stability at start-up is not important for the application.  
32  
7734Q–AVR–02/12  
 
 
 
 
 
 
 
 
 
AT90PWM81/161  
5.2.5  
External Clock  
To drive the device from this external clock source, CLKI should be driven as shown in Figure 5-  
3. To run the device on an external clock, the CKSEL Fuses or CSEL field must be programmed  
as shown in Table 5-1 on page 28.  
Figure 5-3. External clock drive configuration.  
External  
Clock  
Signal  
CLKI  
(XTAL1)  
GND  
When this clock source is selected, start-up times are determined by the SUT Fuses or CSUT  
field as shown in Table 5-8.  
Table 5-8.  
Start-up times for the external clock selection.  
SUT1..0 (1)  
CSUT1..0 (2)  
Start-up time from  
Additional delay from reset  
Recommended usage  
power-down  
00  
01  
10  
11  
6CK  
14CK  
BOD enabled  
6CK  
14CK + 4ms  
14CK + 64ms  
Reserved  
Fast rising power  
Slowly rising power  
6CK  
Notes: 1. Flash Fuse bits.  
2. CLKSELR register bits.  
Note that the System Clock Prescaler can be used to implement run-time changes of the internal  
clock frequency while still ensuring stable operation. Refer to “System Clock Prescaler” on page  
39 for details.  
5.2.6  
PLL  
To generate high frequency and accurate PWM waveforms, the ‘PSC’s need high frequency  
clock input. This clock is generated by a PLL. To keep all PWM accuracy, the frequency factor of  
PLL must be configured by software.  
The internal PLL in AT90PWM81/161 generates a clock frequency multiplied from nominally  
8MHz input. The source of the 8MHz PLL input clock can be selected from three possible  
sources (see the Figure 5-4 on page 34):  
Internal RC Oscillator  
Crystal oscillator  
External clock  
The internal PLL is enabled only when the PLLE bit in the register PLLCSR is set. The bit  
PLOCK from the register PLLCSR is set when PLL is locked.  
When selected as clock source by fuse, the PLL multiplication factor is initialized at the value of  
6, compatible with a 3V supply.  
33  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
The PLL is locked on the source oscillator which must remains close to 8MHz to assure proper  
lock of the PLL.  
Both internal RC Oscillator and PLL are switched off in Power-down and Standby sleep modes  
Start-up times when the PLL is selected as system clock.  
Table 5-9.  
CKSEL3..0  
Start-up time from power-  
down  
Additional delay from reset  
(VCC = 5.0V)  
SUT1..0  
00  
Clock source  
1K CK  
1K CK  
1K CK  
16K CK  
16K CK  
16K CK  
16K CK  
16K CK  
1K CK  
1K CK  
1K CK  
14CK  
01  
14CK + 4ms  
14CK + 64ms  
14CK  
External crystal or  
resonator  
0100  
10  
11  
00  
14CK  
01  
14CK + 4ms  
14CK + 4ms  
14CK + 64ms  
14CK  
0101  
0001  
External clock  
10  
11  
00  
01  
14CK + 4ms  
14CK + 64ms  
Internal RC oscillator  
10  
Figure 5-4. PCK clocking system.  
PLLF3..0  
OSCCAL  
PLLE  
CKSEL3..0  
Lock  
Detector  
PLOCK  
RCOSCILLATOR  
CLK PLL  
PLL  
*N  
8MHz  
DIVIDE  
BY 4  
CK SOURCE  
XTAL1  
OSCILLATORS  
XTAL2  
5.2.7  
Clock Output Buffer  
The device can output the system clock on the CLKO pin. To enable the output, the CKOUT  
Fuse or COUT bit of CLKSELR register has to be programmed. This mode is suitable when the  
chip clock is used to drive other circuits on the system. Note that the clock will not be output dur-  
ing reset and the normal operation of I/O pin will be overridden when the fuses are programmed.  
Any clock source can be selected when the clock is output on CLKO. If the System Clock Pres-  
caler is used, it is the divided system clock that is output.  
34  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
5.3  
Dynamic Clock Switch  
5.3.1  
Features  
AT90PWM81/161 provides a powerful dynamic clock switch that allows users to turn on and off  
clocks of the device on the fly. The built-in de-glitching circuitry allows clocks to be enabled or  
disabled asynchronously. This enables efficient power management schemes to be imple-  
mented easily and quickly. In a safety application, the dynamic clock switch circuit may  
continuously monitor the external clock fails.  
The AT90PWM81/161 provides one register for Clock Fuse substitution (CLKSELR) and one  
register to control the dynamic clock switch circuit (CLKCSR). The watchdog is used to monitor  
external clock source if needed. The control of the dynamic clock switch circuit must be super-  
vised by software. The low level control is performed by hardware through the CLKCSR register.  
The features are:  
Safe commands, to avoid unintentional commands, a special write procedure must be  
followed to change the CLKCSR register bits (see “CLKCSR – Clock Control & Status  
Register” on page 42):  
Exclusive action, the actions are controlled by a decoding (command table). The main  
commands of the dynamic clock switching are:  
– ‘Disable Clock Source’,  
– ‘Enable Clock Source’,  
– ‘Request for Clock Availability’,  
– ‘Clock Source Switching’,  
– ‘Recover System Clock Source’.  
Status, a status on the availability of the enabled clock and the code recovering of clock  
source used to drive the system clock are provided.  
5.3.2  
5.3.3  
Fuses substitution  
During reset, bits of the Low Fuse Byte are latched in the CLKSELR register. The content of this  
register can operate as well as the Low Fuse Byte. CKSEL3..0, SUT1..0 and CKOUT fuses are  
substituted as shown in Figure 5-5 and replaced respectively by CSEL3..0, CSUT1:0 and  
COUT.  
Clock Source Selection  
The available codes of clock source is given are in Table 5-1 on page 28.  
35  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Figure 5-5. Fuses substitution and clock source selection.  
Fuse:  
Register:  
Fuse Low Byte  
CLKSELR  
SEL-0  
SEL-1  
SEL-2  
CKSEL[3..0]  
SEL-n  
Reset  
Selected  
Configuration  
SUT[1..0]  
(
)
*
SCLKRq  
CKOUT  
EN-0  
EN-1  
EN-2  
Clock  
Switch  
Current  
Configuration  
(
)
*
EN-n  
SCLKRq : Command of Clock Control & Status Register  
When ‘Enable/Disable Clock Source’, ‘Request for Clock Availability’ or ‘Clock Source Switching’  
command is entered, the selected configuration provided by the CLKSELR register is latched for  
each targeted clock source.  
Recover System Clock Source’ command enables the code recovering of clock source used to  
drive the system clock. The CKSEL field of CLKSELR register is then updated with this code.  
There is no information on the SUT used or status on CKOUT.  
Because the selected configuration is latched at clock source level, it is possible to enable many  
clock sources at a given time (ex: the internal RC oscillator for system clock + an oscillator with  
external crystal). The user’s software has the responsibility of this management.  
Request for Clock Availability’ command returns the working order of the clock source  
addressed. The status is set in the CLKRDY bit of CLKCSR register.  
5.3.4  
Enable/Disable Clock Source  
Enable Clock Source’ command selects and enables the clock source provided by the setting of  
CLKSELR register (CSEL3..0 and CSUT1:0). CSEL field will select the clock source and CSUT  
field will select the start-up time (as CKSEL and SUT fuse bits do it). To be sure that a clock  
source has been enabled, it will be better to perform a ‘Request for Clock Availability’ command  
after the ‘Enable Clock Source’ command.  
Disable Clock Source’ command disables the clock source provided by the setting of CLKSELR  
register (only CSEL3..0). If the clock source is the one that is used to drive the system clock, the  
command is not taken into account.  
5.3.5  
Clock Availability  
‘Request for Clock Availability’ command enables an oscillation-counting of the selected source  
clock, CSEL3..0. The count is provided by CSUT1..0. The clock is declared ready (CLKRDY = 1)  
when the count is finished. This flag remains unchanged up to a new count. The CLKRDY flag is  
reset when the count starts. To perform this checking, the CKSEL and CSUT fields should not  
change all long the operation is running.  
Two usages are possible:  
36  
7734Q–AVR–02/12  
AT90PWM81/161  
1. Clock stability before switching  
Once the new clock source is selected, the count procedure is running. The user (code)  
should wait for the setting of the CLKRDY flag in CLKSCR register before to perform a  
switching.  
2. Clock available on request  
AT any time, the user (code) can ask for the availability of a clock source. The user (code)  
can request it writing the appropriate command in the CLKSCR register. A full status on  
clock sources then can be done.  
5.3.6  
Clock Switching  
To drive the system clock, the user can switch from the current clock source to the following  
ones (one of them is the current clock source):  
1. Calibrated internal RC oscillator 8.0MHz/1.0MHz,  
2. Internal watchdog oscillator 128kHz,  
3. External clock,  
4. External Crystal/Ceramic Resonator,  
5. PLL output divided by four.  
The clock switching is performed in a sequence of commands. First, the user (code) must make  
sure that the new clock source is running. Then the switching command can be entered. At the  
end, the user (code) can stop the previous clock source. It will be better to run this sequence  
once the interrupts disabled. The user (code) has the responsibility of the clock switching  
sequence.  
37  
7734Q–AVR–02/12  
AT90PWM81/161  
Here is a “light” C-code that describes such a sequence of commands.  
C code example  
void ClockSwiching (unsigned char clk-number, unsigned char sut) {  
#define CLOCK-RECOVER 0x05  
#define CLOCK-ENABLE  
#define CLOCK-SWITCH  
0x02  
0x04  
#define CLOCK-DISABLE 0x01  
unsigned char previous-clk, temp;  
// Disable interrupts  
asm ("cli"); temp = SREG;  
// “Recover System Clock Source” command  
CLKCSR = 1 << CLKCCE;  
CLKCSR = CLOCK-RECOVER;  
previous-clk = CLKSELR & 0x0F;  
// “Enable Clock Source” command  
CLKSELR = ((sut << 4 ) & 0x30) | (clk-number & 0x0F);  
CLKCSR = 1 << CLKCCE;  
CLKCSR = CLOCK-ENABLE;  
// Wait for clock availability  
while ((CLKCSR & (1 << CLKRDY)) == 0);  
// “Clock Source Switching” command  
CLKCSR = 1 << CLKCCE;  
CLKCSR = CLOCK-SWITCH;  
// Wait for effective switching  
while (1){  
CLKCSR = 1 << CLKCCE;  
CLKCSR = CLOCK-RECOVER;  
if ((CLKSELR & 0x0F) == (clk-number & 0x0F)) break;  
}
// “Disable Clock Source” command  
CLKSELR = previous-clk;  
CLKCSR = 1 << CLKCCE;  
CLKCSR = CLOCK-DISABLE;  
// Re-enable interrupts  
SREG = temp; asm ("sei");  
}
Warning:  
In the AT90PWM81/161, only one among the external clock sources can be enabled at a given  
time and it is not possible to switch from external clock to external oscillator as both sources  
share one pin.  
Also, it is not possible to switch the synchronization source of the PLL when the sytem clock is  
PLL/4. See Table 5-1 on page 28 to identify these cases.  
As they are two CSEL adresses to access the Calibrated internal RC oscillator 8.0MHz/1.0MHz,  
the change between the two frequencies is not allowed by the clock switching features. The  
CKRC81 bit in MCUCR register must be used for this purpose.  
38  
7734Q–AVR–02/12  
AT90PWM81/161  
5.4  
System Clock Prescaler  
5.4.1  
Features  
The AT90PWM81/161 system clock can be divided by setting the Clock Prescaler Register –  
CLKPR. This feature can be used to decrease power consumption when the requirement for  
processing power is low. This can be used with all clock source options, and it will affect the  
clock frequency of the CPU and all synchronous peripherals. clkI/O, clkADC, clkCPU, and clkFLASH  
are divided by a factor as shown in Table 5-10 on page 40.  
5.4.2  
Switching Time  
When switching between prescaler settings, the System Clock Prescaler ensures that no  
glitches occur in the clock system and that no intermediate frequency is higher than neither the  
clock frequency corresponding to the previous setting, nor the clock frequency corresponding to  
the new setting.  
The ripple counter that implements the prescaler runs at the frequency of the undivided clock,  
which may be faster than the CPU’s clock frequency. Hence, it is not possible to determine the  
state of the prescaler – even if it were readable, and the exact time it takes to switch from one  
clock division to another cannot be exactly predicted.  
From the time the CLKPS values are written, it takes between T1 + T2 and T1 + 2 × T2 before  
the new clock frequency is active. In this interval, 2 active clock edges are produced. Here, T1 is  
the previous clock period, and T2 is the period corresponding to the new prescaler setting.  
5.5  
Register Description  
5.5.1  
OSCCAL – Oscillator Calibration Register  
Bit  
7
6
5
4
3
2
1
0
CAL7  
R/W  
CAL6  
R/W  
CAL5  
R/W  
CAL4  
R/W  
CAL3  
R/W  
CAL2  
R/W  
CAL1  
R/W  
CAL0  
R/W  
OSCCAL  
Read/Write  
Initial Value  
Device Specific Calibration Value  
• Bits 7:0 – CAL7:0: Oscillator Calibration Value  
The Oscillator Calibration Register is used to trim the Calibrated Internal RC Oscillator to  
remove process variations from the oscillator frequency. The factory-calibrated value is automat-  
ically written to this register during chip reset, giving an oscillator frequency of 8.0MHz at 25°C.  
The application software can write this register to change the oscillator frequency. The oscillator  
can be calibrated to any frequency in the range 7.6MHz - 8.4MHz within 1% accuracy. Calibra-  
tion outside that range is not guaranteed.  
Note that this oscillator is used to time EEPROM and Flash write accesses, and these write  
times will be affected accordingly. If the EEPROM or Flash are written, do not calibrate to more  
than 8.8MHz. Otherwise, the EEPROM or Flash write may fail.  
The CAL7..0 bits are used to tune the frequency within the selected range. A setting of 0x00  
gives the lowest frequency in that range, and a setting of 0x7F gives the highest frequency in the  
range. Incrementing CAL7..0 by 1 will give a frequency increment of less than 0.5% in the fre-  
quency range 7.6MHz - 8.4MHz.  
39  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
5.5.2  
CLKPR – Clock Prescaler Register  
Bit  
7
CLKPCE  
R/W  
6
5
4
3
2
1
0
CLKPS3  
R/W  
CLKPS2  
R/W  
CLKPS1  
R/W  
CLKPS0  
R/W  
CLKPR  
Read/Write  
Initial Value  
R
0
R
0
R
0
0
See Bit Description  
• Bit 7 – CLKPCE: Clock Prescaler Change Enable  
The CLKPCE bit must be written to logic one to enable change of the CLKPS bits. The CLKPCE  
bit is only updated when the other bits in CLKPR are simultaneously written to zero. CLKPCE is  
cleared by hardware four cycles after it is written or when the CLKPS bits are written. Rewriting  
the CLKPCE bit within this time-out period does neither extend the time-out period, nor clear the  
CLKPCE bit.  
• Bits 6:4 – Res: Reserved Bits  
These bits are reserved bits in the AT90PWM81/161 and will always read as zero.  
• Bits 3:0 – CLKPS3:0: Clock Prescaler Select Bits 3 - 0  
These bits define the division factor between the selected clock source and the internal system  
clock. These bits can be written run-time to vary the clock frequency to suit the application  
requirements. As the divider divides the master clock input to the MCU, the speed of all synchro-  
nous peripherals is reduced when a division factor is used. The division factors are given in  
Table 5-10.  
To avoid unintentional changes of clock frequency, a special write procedure must be followed  
to change the CLKPS bits:  
1. Write the Clock Prescaler Change Enable (CLKPCE) bit to one and all other bits in  
CLKPR to zero.  
2. Within four cycles, write the desired value to CLKPS while writing a zero to CLKPCE.  
Interrupts must be disabled when changing prescaler setting in order not to disturb the  
procedure.  
The CKDIV8 Fuse determines the initial value of the CLKPS bits. If CKDIV8 is unprogrammed,  
the CLKPS bits will be reset to “0000”. If CKDIV8 is programmed, CLKPS bits are reset to  
“0011”, giving a division factor of eight at start up. This feature should be used if the selected  
clock source has a higher frequency than the maximum frequency of the device at the present  
operating conditions. Note that any value can be written to the CLKPS bits regardless of the  
CKDIV8 Fuse setting. The Application software must ensure that a sufficient division factor is  
chosen if the selected clock source has a higher frequency than the maximum frequency of the  
device at the present operating conditions. The device is shipped with the CKDIV8 Fuse  
programmed.  
Table 5-10. Clock prescaler select.  
CLKPS3  
CLKPS2  
CLKPS1  
CLKPS0  
Clock division factor  
0
0
0
0
0
0
0
0
0
1
0
0
1
1
0
0
1
0
1
0
1
2
4
8
16  
40  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Table 5-10. Clock prescaler select. (Continued)  
CLKPS3  
CLKPS2  
CLKPS1  
CLKPS0  
Clock division factor  
32  
0
0
0
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
1
1
1
1
0
1
1
0
0
1
1
0
0
1
1
1
0
1
0
1
0
1
0
1
0
1
64  
128  
256  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
5.5.3  
PLLCSR - PLL Control and Status Register  
Bit  
7
R
0
6
R
0
5
4
3
2
1
0
$29 ($29)  
Read/Write  
Initial Value  
PLLF3  
R/W  
0
PLLF2  
R/W  
1
PLLF1  
R/W  
0
PLLF0  
R/W  
0
PLLE  
R/W  
0/1  
PLOCK  
PLLCSR  
R
0
• Bit 7..3 – Res: Reserved Bits  
These bits are reserved bits in the AT90PWM81/161 and always read as zero.  
• Bit 5..2-– PLLF: PLL Factor  
The PLLF bits is used to select the multiplication factor of the PLL.  
Table 5-11. PLL multiplication factor.  
PLLF3..0  
N+2  
PLL frequency [MHz]  
7-F  
6
Reserved  
8
7
6
5
4
64  
56  
5
4
48  
3
40  
2
32  
0-1  
Reserved  
Note:  
PLLF3 is used for debug purpose (must be wired).  
41  
7734Q–AVR–02/12  
 
AT90PWM81/161  
• Bit 1 – PLLE: PLL Enable  
When the PLLE is set, the PLL is started and if not yet started the internal RC Oscillator is  
started as PLL reference clock. If PLL is selected as a system clock source the value for this bit  
is always 1.  
• Bit 0 – PLOCK: PLL Lock Detector  
When the PLOCK bit is set, the PLL is locked to the reference clock, and it is safe to enable  
CLKPLL for PSC. The time to lock is specified in Table 5-9 on page 34.  
5.5.4  
MCUCR - MCU Control Register  
Bit  
7
6
R
0
5
R
0
4
3
2
1
0
R
0
PUD  
R/W  
0
RSTDIS  
R/W  
0/1 (1)  
CKRC81  
IVSEL  
R/W  
0
IVCE  
R/W  
0
MCUCR  
Read/Write  
Initial Value  
R/W  
0
Notes: 1. Value is initialized with the fuse CKSEL2.  
2. Value is initialized with fuses CKSEL3..0 (1 when CKSEL3..0= 0110, 0 in all other cases).  
• Bit 2– CKRC81: Frequency Selection of the calibrated 8/1MHz RC Oscillator  
Thanks to CKRC81 in MCUCR Sfr, the typical frequency of the calibrated RC oscillator is  
changed.  
– When the CKRC81 bit is written to zero, the RC oscillator frequency is 8MHz.  
– When the CKRC81 bit is written to one, the RC oscillator frequency is 1MHz.  
Note: This bit only can be changed only when the RC oscillator is enabled.  
Note: When the RC oscillator is used as the PLL source, CKRC81 must not be written to 1.  
Note: If the RC oscillator is disabled, this bit is cleared by hardware.  
5.5.5  
CLKCSR – Clock Control & Status Register  
Bit  
7
6
5
4
3
CLKC3  
R/W  
0
2
CLKC2  
R/W  
0
1
CLKC1  
R/W  
0
0
CLKC0  
R/W  
0
CLKCCE  
CLKRDY  
CLKCSR  
Read/Write  
Initial Value  
R/W  
0
R
0
R
0
R
0
• Bit 7 – CLKCCE: Clock Control Change Enable  
The CLKCCE bit must be written to logic one to enable change of the CLKCSR bits. The  
CLKCCE bit is only updated when the other bits in CLKCSR are simultaneously written to zero.  
CLKCCE is cleared by hardware four cycles after it is written or when the CLKCSR bits are  
written. Rewriting the CLKCCE bit within this time-out period does neither extend the time-out  
period, nor clear the CLKCCE bit.  
• Bits 6:5 – Res: Reserved Bits  
These bits are reserved bits in the AT90PWM81/161 and will always read as zero.  
• Bits 4 – CLKRDY: Clock Ready Flag  
This flag is the output of the ‘Clock Availability’ logic.  
This flag is reset once the ‘Request for Clock Availability’ command is entered.  
It is set when ‘Clock Availability’ logic confirms that the (selected) clock is running and is stable.  
The delay from the request and the flag setting is not fixed, it depends on the clock start-up time,  
42  
7734Q–AVR–02/12  
 
 
 
 
 
AT90PWM81/161  
the clock frequency and, of course, if the clock is alive. The user’s has itself to do the difference  
between ‘no_clock_signaland clock_signal_not_yet_available’.  
• Bits 3:0 – CLKC3:0: Clock Control Bits 3 - 0  
These bits define the command to provide to the ‘Clock Switch’ module. The special write  
procedure must be followed to change the CLKC bits (see “Bit 7 – CLKCCE: Clock Control Change  
Enable” on page 42).  
1. Write the Clock Control Change Enable (CLKCCE) bit to one and all other bits in  
CLKCSR to zero.  
2. Within four cycles, write the desired value to CLKCSR register while clearing CLKCCE  
bit.  
Interrupts should be disabled when setting CLKCSR register in order not to disturb the  
procedure.  
Table 5-12. Clock command list.  
Clock command  
CLKC3..0  
0000 b  
0001 b  
0010 b  
0011 b  
0100 b  
0101 b  
0111 b  
1xxx b  
No command  
Disable clock source  
Enable clock source  
Request for clock availability  
Clock source switch  
Recover system clock source code  
CKOUT command  
No command  
5.5.6  
CLKSELR - Clock Selection Register  
Bit  
7
6
5
4
3
2
1
0
-
COUT  
R/W  
CSUT1  
R/W  
CSUT0  
R/W  
CSEL3  
R/W  
CSEL2  
R/W  
CSEL1  
R/W  
CSEL0  
R/W  
CLKSELR  
Read/Write  
Initial Value  
R
0
CKOUT  
fuse  
SUT1..0  
fuses  
CKSEL3..0  
fuses  
• Bit 7– Res: Reserved Bit  
This bit is reserved bit in the AT90PWM81/161 and will always read as zero.  
• Bit 6 – COUT: Clock Out  
The COUT bit is initialized with CKOUT Fuse bit.  
The COUT bit is only used in case of ‘CKOUT’ command. Refer to Section 5.2.7 ”Clock Output  
Buffer” on page 34 for using.  
In case of ‘Recover System Clock Source’ command, COUT it is not affected (no recovering of  
this setting).  
• Bits 5:4 – CSUT1:0: Clock Start-up Time  
CSUT bits are initialized with the values of SUT Fuse bits.  
In case of ‘Enable/Disable Clock Source’ command, CSUT field provides the code of the clock  
start-up time. Refer to subdivisions of Section 5.2 ”Clock Sources” on page 28 for code of clock  
43  
7734Q–AVR–02/12  
 
AT90PWM81/161  
start-up times.  
In case of ‘Recover System Clock Source’ command, CSUT field is not affected (no recovering  
of SUT code).  
• Bits 3:0 – CSEL3:0: Clock Source Select  
CSEL bits are initialized with the values of CKSEL Fuse bits.  
In case of ‘Enable/Disable Clock Source’, ‘Request for Clock Availability’ or ‘Clock Source  
Switch’ command, CSEL field gets back the code of the clock source. Refer to Table 5-1 on  
page 28 and subdivisions of Section 5.2 ”Clock Sources” on page 28 for clock source codes.  
In case of ‘Recover System Clock Source’ command, CSEL field receives the code of the clock  
source used to drive the Clock Control Unit as described in Figure 5-1 on page 27.  
44  
7734Q–AVR–02/12  
AT90PWM81/161  
6. Power Management and Sleep Modes  
Sleep modes enable the application to shut down unused modules in the MCU, thereby saving  
power. The AVR provides various sleep modes allowing the user to tailor the power consump-  
tion to the application’s requirements.  
6.1  
Sleep Modes  
Figure 5-1 on page 27 presents the different clock systems in the AT90PWM81/161, and their  
distribution. The figure is helpful in selecting an appropriate sleep mode. Table 6-1 shows the  
different sleep modes, their wake up sources.  
Table 6-1.  
Active clock domains and wake-up sources in the different sleep modes.  
Active clock domains  
Oscillators  
Wake-up sources  
Sleep  
mode  
Idle  
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
ADC noise  
reduction  
X (2)  
Power-  
down  
X (2)  
X (2)  
X
X
Standby (1)  
X
Notes: 1. Only recommended with external crystal or resonator selected as clock source.  
2. Only level interrupt.  
To enter any of the five sleep modes, the SE bit in SMCR must be written to logic one and a  
SLEEP instruction must be executed. The SM2, SM1, and SM0 bits in the SMCR Register select  
which sleep mode (Idle, ADC Noise Reduction, Power-down or Standby) will be activated by the  
SLEEP instruction. See Table 6-2 on page 48 for a summary.  
If an enabled interrupt occurs while the MCU is in a sleep mode, the MCU wakes up. The MCU  
is then halted for four cycles in addition to the start-up time, executes the interrupt routine, and  
resumes execution from the instruction following SLEEP. The contents of the register file and  
SRAM are unaltered when the device wakes up from sleep. If a reset occurs during sleep mode,  
the MCU wakes up and executes from the Reset Vector.  
6.2  
Idle Mode  
When the SM2..0 bits are written to 000, the SLEEP instruction makes the MCU enter Idle  
mode, stopping the CPU but allowing SPI, Analog Comparator, ADC, Timer/Counters, Watch-  
dog, and the interrupt system to continue operating. This sleep mode basically halt clkCPU and  
clkFLASH, while allowing the other clocks to run.  
Idle mode enables the MCU to wake up from external triggered interrupts as well as internal  
ones like the Timer Overflow interrupts. If wake-up from the Analog Comparator interrupt is not  
required, the Analog Comparator can be powered down by clearing the ACnEN bit in the Analog  
Comparator Control and Status Register – ACnCON. This will reduce power consumption in Idle  
mode. If the ADC is enabled, a conversion starts automatically when this mode is entered.  
45  
7734Q–AVR–02/12  
 
 
 
 
 
 
AT90PWM81/161  
6.3  
ADC Noise Reduction Mode  
When the SM2..0 bits are written to 001, the SLEEP instruction makes the MCU enter ADC  
Noise Reduction mode, stopping the CPU but allowing the ADC, the External Interrupts,  
Timer/Counter (if their clock source is external - T0 or T1) and the Watchdog to continue operat-  
ing (if enabled). This sleep mode basically halts clkI/O, clkCPU, and clkFLASH, while allowing the  
other clocks to run.  
This improves the noise environment for the ADC, enabling higher resolution measurements. If  
the ADC is enabled, a conversion starts automatically when this mode is entered. Apart from the  
ADC Conversion Complete interrupt, only an External Reset, a Watchdog Reset, a Brown-out  
Reset, a Timer/Counter interrupt, an SPM/EEPROM ready interrupt, an External Level Interrupt  
on INT2:0 can wake up the MCU from ADC Noise Reduction mode.  
6.4  
Power-down Mode  
When the SM2..0 bits are written to 010, the SLEEP instruction makes the MCU enter Power-  
down mode. In this mode, the External Oscillator is stopped, while the External Interrupts and  
the Watchdog continue operating (if enabled). Only an External Reset, a Watchdog Reset, a  
Brown-out Reset, a PSC Interrupt, an External Level Interrupt on INT2:0 can wake up the MCU.  
This sleep mode basically halts all generated clocks, allowing operation of asynchronous mod-  
ules only.  
Note that if a level triggered interrupt is used for wake-up from Power-down mode, the changed  
level must be held for some time to wake up the MCU. Refer to “External Interrupts” on page 83  
for details.  
When waking up from Power-down mode, there is a delay from the wake-up condition occurs  
until the wake-up becomes effective. This allows the clock to restart and become stable after  
having been stopped. The wake-up period is defined by the same CKSEL fuses that define the  
Reset Time-out period, as described in “Clock Sources” on page 28.  
6.5  
6.6  
Standby Mode  
When the SM2..0 bits are 110 and an external crystal/resonator clock option is selected, the  
SLEEP instruction makes the MCU enter Standby mode. This mode is identical to Power-down  
with the exception that the Oscillator is kept running. From Standby mode, the device wakes up  
in six clock cycles.  
Power Reduction Register  
The Power Reduction Register, PRR, provides a method to stop the clock to individual peripher-  
als to reduce power consumption. The current state of the peripheral is frozen and the I/O  
registers can not be read or written. Resources used by the peripheral when stopping the clock  
will remain occupied, hence the peripheral should in most cases be disabled before stopping the  
clock. Waking up a module, which is done by clearing the bit in PRR, puts the module in the  
same state as before shutdown.  
A full predictable behavior of a peripheral is not guaranteed during and after a cycle of stopping  
and starting of its clock. So its recommended to stop a peripheral before stopping its clock with  
PRR register.  
Module shutdown can be used in Idle mode and Active mode to significantly reduce the overall  
power consumption. In all other sleep modes, the clock is already stopped.  
46  
7734Q–AVR–02/12  
 
 
 
 
 
AT90PWM81/161  
6.7  
Minimizing Power Consumption  
There are several issues to consider when trying to minimize the power consumption in an AVR  
controlled system. In general, sleep modes should be used as much as possible, and the sleep  
mode should be selected so that as few as possible of the device’s functions are operating. All  
functions not needed should be disabled. In particular, the following modules may need special  
consideration when trying to achieve the lowest possible power consumption.  
6.7.1  
6.7.2  
Analog to Digital Converter  
If enabled, the ADC will be enabled in all sleep modes. To save power, the ADC should be dis-  
abled before entering any sleep mode. When the ADC is turned off and on again, the next  
conversion will be an extended conversion. Refer to “ADC Noise Canceler” on page 210 for  
details on ADC operation.  
Analog Comparator  
When entering Idle mode, the Analog Comparator should be disabled if not used. When entering  
ADC Noise Reduction mode, the Analog Comparator should be disabled.  
In other sleep modes, the Analog Comparator is NOT automatically disabled, so it should be dis-  
abled if not used.  
However, if the Analog Comparator is set up to use the Internal Voltage Reference as input, the  
Analog Comparator should be disabled in all sleep modes. Otherwise, the Internal Voltage Ref-  
erence will be enabled, independent of sleep mode. Refer to “Analog Comparator” on page 194  
for details on how to configure the Analog Comparator.  
6.7.3  
6.7.4  
Brown-out Detector  
If the Brown-out Detector is not needed by the application, this module should be turned off. If  
the Brown-out Detector is enabled by the BODLEVEL Fuses, it will be enabled in all sleep  
modes, and hence, always consume power. In the deeper sleep modes, this will contribute sig-  
nificantly to the total current consumption. Refer to “Brown-out Detection” on page 53 for details  
on how to configure the Brown-out Detector.  
Internal Voltage Reference  
The Internal Voltage Reference will be enabled when needed by the Brown-out Detection, the  
Analog Comparator or the ADC. If these modules are disabled as described in the sections  
above, the internal voltage reference will be disabled and it will not be consuming power. When  
turned on again, the user must allow the reference to start up before the output is used. If the  
reference is kept on in sleep mode, the output can be used immediately. Refer to “Internal Volt-  
age Reference” on page 55 for details on the start-up time.  
6.7.5  
6.7.6  
Watchdog Timer  
If the Watchdog Timer is not needed in the application, the module should be turned off. If the  
Watchdog Timer is enabled, it will be enabled in all sleep modes, and hence, always consume  
power. In the deeper sleep modes, this will contribute significantly to the total current consump-  
tion. Refer to “Watchdog Timer” on page 56 for details on how to configure the Watchdog Timer.  
Port Pins  
When entering a sleep mode, all port pins should be configured to use minimum power. The  
most important is then to ensure that no pins drive resistive loads. In sleep modes where both  
the I/O clock (clkI/O) and the ADC clock (clkADC) are stopped, the input buffers of the device will  
47  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
be disabled. This ensures that no power is consumed by the input logic when not needed. In  
some cases, the input logic is needed for detecting wake-up conditions, and it will then be  
enabled. Refer to the section “I/O-Ports” on page 68 for details on which pins are enabled. If the  
input buffer is enabled and the input signal is left floating or have an analog signal level close to  
V
CC/2, the input buffer will use excessive power.  
For analog input pins, the digital input buffer should be disabled at all times. An analog signal  
level close to VCC/2 on an input pin can cause significant current even in active mode. Digital  
input buffers can be disabled by writing to the Digital Input Disable Registers (DIDR1 and  
DIDR0). Refer to “DIDR1 - Digital Input Disable Register 1” on page 222 and “DIDR0 - Digital  
Input Disable Register 0” on page 202 for details.  
6.7.7  
On-chip Debug System  
If the On-chip debug system is enabled by OCDEN Fuse and the chip enter sleep mode, the  
main clock source is enabled, and hence, always consumes power. In the deeper sleep modes,  
this will contribute significantly to the total current consumption.  
6.8  
Register description  
6.8.1  
SMCR - Sleep Mode Control Register  
The Sleep Mode Control Register contains control bits for power management.  
Bit  
7
R
0
6
R
0
5
R
0
4
R
0
3
2
1
0
SM2  
R/W  
0
SM1  
R/W  
0
SM0  
R/W  
0
SE  
R/W  
0
SMCR  
Read/Write  
Initial Value  
• Bits 3..1 – SM2..0: Sleep Mode Select Bits 2, 1, and 0  
These bits select between the five available sleep modes as shown in Table 6-2.  
Table 6-2.  
Sleep mode select.  
SM2  
SM1  
SM0  
Sleep mode  
Idle  
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
ADC noise reduction  
Power-down  
Reserved  
Reserved  
Reserved  
Standby (1)  
Reserved  
Note:  
1. Standby mode is only recommended for use with external crystals or resonators.  
• Bit 1 – SE: Sleep Enable  
The SE bit must be written to logic one to make the MCU enter the sleep mode when the SLEEP  
instruction is executed. To avoid the MCU entering the sleep mode unless it is the programmer’s  
purpose, it is recommended to write the Sleep Enable (SE) bit to one just before the execution of  
the SLEEP instruction and to clear it immediately after waking up.  
48  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
6.8.2  
PRR - Power Reduction Register  
Bit  
7
6
-
5
4
3
-
2
1
-
0
PRPSC2  
PRPSCR  
PRTIM1  
R/W  
0
PRSPI  
R/W  
0
PRADC  
R/W  
0
PRR  
Read/Write  
Initial Value  
R/W  
0
R
0
R/W  
0
R
0
R
0
• Bit 7 - PRPSC2: Power Reduction PSC2  
Writing a logic one to this bit reduces the consumption of the PSC2 by stopping the clock to this  
module. When waking up the PSC2 again, the PSC2 should be re initialized to ensure proper  
operation.  
• Bit 6 - Reserved  
• Bit 5 - PRPSCR: Power Reduction PSC reduced  
Writing a logic one to this bit reduces the consumption of the PSCR by stopping the clock to this  
module. When waking up the PSCR again, the PSCR should be re initialized to ensure proper  
operation.  
• Bit 4 - PRTIM1: Power Reduction Timer/Counter1  
Writing a logic one to this bit reduces the consumption of the Timer/Counter1 module. When the  
Timer/Counter1 is enabled, operation will continue like before the setting of this bit.  
• Bit 3 - Reserved  
• Bit 2 - PRSPI: Power Reduction Serial Peripheral Interface  
Writing a logic one to this bit reduces the consumption of the Serial Peripheral Interface by stop-  
ping the clock to this module. When waking up the SPI again, the SPI should be re initialized to  
ensure proper operation.  
• Bit 1 - Reserved  
• Bit 0 - PRADC: Power Reduction ADC  
Writing a logic one to this bit reduces the consumption of the ADC by stopping the clock to this  
module. The ADC must be disabled before using this function. The analog comparator cannot  
use the ADC input MUX when the clock of ADC is stopped.  
49  
7734Q–AVR–02/12  
 
AT90PWM81/161  
7. System Control and Reset  
7.1  
System Control overview  
7.1.1  
Resetting the AVR  
During reset, all I/O Registers are set to their initial values, and the program starts execution  
from the Reset Vector. The instruction placed at the Reset Vector must be a JMP – Absolute  
Jump – instruction to the reset handling routine. If the program never enables an interrupt  
source, the Interrupt Vectors are not used, and regular program code can be placed at these  
locations. 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. The circuit diagram in Figure 7-1 on page 51  
shows the reset logic. Table 7-1 on page 51 defines the electrical parameters of the reset  
circuitry.  
The I/O ports of the AVR are immediately reset to their initial state when a reset source goes  
active. This does not require any clock source to be running.  
After all reset sources have gone inactive, a delay counter is invoked, stretching the internal  
reset. This allows the power to reach a stable level before normal operation starts. The time-out  
period of the delay counter is defined by the user through the SUT and CKSEL Fuses. The dif-  
ferent selections for the delay period are presented in “Clock Sources” on page 28.  
7.1.2  
Reset Sources  
The Atmel AT90PWM81/161 has four sources of reset:  
Power-on Reset. The MCU is reset when the supply voltage is below the Power-on Reset  
threshold (VPOT).  
External Reset. The MCU is reset when a low level is present on the RESET pin for longer  
than the minimum pulse length. The external reset pin can be disabled in 2 ways:  
– By the RSTDISBL fuse. In this case , the SPI programming is disabled.  
– By software using the RSTDIS bit in MCUCR register. In this case , the SPI  
programming is still active at power up time.  
Watchdog Reset. The MCU is reset when the Watchdog Timer period expires and the  
Watchdog is enabled.  
Brown-out Reset. The MCU is reset when the supply voltage VCC is below the Brown-out  
Reset threshold (VBOT) and the brown-out detector is enabled.  
50  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Figure 7-1. Reset logic.  
DATA BUS  
MCU Status  
Register (MCUSR)  
Power-on Reset  
Circuit  
Brown-out  
Reset Circuit  
BODLEVEL [2..0]  
Pull-up Resistor  
Spike  
Filter  
RSTDIS  
Watchdog  
Oscillator  
Delay Counters  
Clock  
Generator  
CK  
TIMEOUT  
CKSEL[3:0]  
SUT[1:0]  
Table 7-1.  
Symbol Parameter  
Power-on reset threshold  
Reset characteristics (1)  
.
Condition  
Minimum Typical Maximum  
Units  
1.4  
1.3  
2.3  
V
voltage (rising)  
VPOT  
Power-on reset threshold  
voltage (falling) (2)  
2.3  
V
V
VRST  
tRST  
RESET pin threshold voltage  
0.2VCC  
0.85VCC  
Minimum pulse width on  
RESET pin  
400  
ns  
Notes: 1. Values are guidelines only.  
2. The power-on reset will not work unless the supply voltage has been below VPOT (falling).  
7.1.3  
Power-on Reset  
A Power-on Reset (POR) pulse is generated by an On-chip detection circuit. The detection level  
is defined in Table 7-1. The POR is activated whenever VCC is below the detection level. The  
POR circuit can be used to trigger the start-up Reset, as well as to detect a failure in supply  
voltage.  
A Power-on Reset (POR) circuit ensures that the device is reset from Power-on. Reaching the  
Power-on Reset threshold voltage invokes the delay counter, which determines how long the  
device is kept in RESET after VCC rise. The RESET signal is activated again, without any delay,  
when VCC decreases below the detection level.  
51  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
Figure 7-2. MCU start-up, RESET tied to VCC  
.
VPOT  
VCC  
RESET  
VRST  
tTOUT  
TIME-OUT  
INTERNAL  
RESET  
Figure 7-3. MCU start-up, RESET extended externally.  
VPOT  
VCC  
VRST  
RESET  
tTOUT  
TIME-OUT  
INTERNAL  
RESET  
7.1.4  
External Reset  
An External Reset is generated by a low level on the RESET pin. Reset pulses longer than the  
minimum pulse width (see Table 7-1 on page 51) will generate a reset, even if the clock is not  
running. Shorter pulses are not guaranteed to generate a reset. When the applied signal  
reaches the Reset Threshold Voltage – VRST – on its positive edge, the delay counter starts the  
MCU after the Time-out period – tTOUT – has expired.  
Figure 7-4. External reset during operation.  
CC  
52  
7734Q–AVR–02/12  
AT90PWM81/161  
7.1.5  
Brown-out Detection  
AT90PWM81/161 has an On-chip Brown-out Detection (BOD) circuit for monitoring the VCC level  
during operation by comparing it to a fixed trigger level. The trigger level for the BOD can be  
selected by the BODLEVEL Fuses. The trigger level has a hysteresis to ensure spike free  
Brown-out Detection. The hysteresis on the detection level should be interpreted as  
V
BOT+ = VBOT + VHYST/2 and VBOT- = VBOT - VHYST/2.  
BODLEVEL fuse coding (1)(2)  
BODLEVEL 2..0 fuses Min VBOT  
Table 7-2.  
.
Typ VBOT  
Max VBOT  
Units  
111  
Forbidden, BOD must be enabled  
110  
1.8  
2.7  
101 (default configuration)  
100  
011  
010  
001  
000  
3.9  
4.3  
2.3  
2.2  
1.9  
2.0  
4.6  
V
2.5  
2.9  
Notes: 1. VBOT may be below nominal minimum operating voltage for some devices. For devices where  
this is the case, the device is tested down to VCC = VBOT during the production test. This guar-  
antees that a Brown-Out Reset will occur before VCC drops to a voltage where correct  
operation of the microcontroller is no longer guaranteed. The test is performed using  
BODLEVEL = 010 for Low Operating Voltageand BODLEVEL = 101 for High Operating  
Voltage.  
2. Values are guidelines only.  
Table 7-3.  
Symbol  
VHYST  
Brown-out characteristics (1)  
Parameter  
.
Minimum  
Typical  
Maximum  
Units  
mV  
Brown-out detector hysteresis  
70  
2
tBOD  
Minimum pulse width on brown-out reset  
µs  
Notes: 1. Values are guidelines only.  
When VCC decreases to a value below the trigger level (VBOT- in Figure 7-5 on page 54), the  
Brown-out Reset is immediately activated. When VCC increases above the trigger level (VBOT+ in  
Figure 7-5 on page 54), the delay counter starts the MCU after the Time-out period tTOUT has  
expired.  
The BOD circuit will only detect a drop in VCC if the voltage stays below the trigger level for lon-  
ger than tBOD given in Table 7-3.  
53  
7734Q–AVR–02/12  
 
 
 
 
 
AT90PWM81/161  
Figure 7-5. Brown-out reset during operation.  
VBOT+  
VCC  
VBOT-  
RESET  
t
TOUT  
TIME-OUT  
INTERNAL  
RESET  
7.1.6  
Watchdog Reset  
When the Watchdog times out, it will generate a short reset pulse of one CK cycle duration. On  
the falling edge of this pulse, the delay timer starts counting the Time-out period tTOUT. Refer to  
page 56 for details on operation of the Watchdog Timer.  
Figure 7-6. Watchdog reset during operation.  
CC  
CK  
7.2  
System Control registers  
7.2.1  
MCUSR - MCU Status Register  
The MCU Status Register provides information on which reset source caused an MCU reset.  
Bit  
7
R
0
6
R
0
5
R
0
4
R
0
3
2
1
0
WDRF  
R/W  
BORF  
R/W  
EXTRF  
R/W  
PORF  
R/W  
MCUSR  
Read/Write  
Initial Value  
See Bit Description  
• Bit 3 – WDRF: Watchdog Reset Flag  
This bit is set if a Watchdog Reset occurs. The bit is reset by a Power-on Reset, or by writing a  
logic zero to the flag.  
54  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
• Bit 2 – BORF: Brown-out Reset Flag  
This bit is set if a Brown-out Reset occurs. The bit is reset by a Power-on Reset, or by writing a  
logic zero to the flag.  
• Bit 1 – EXTRF: External Reset Flag  
This bit is set if an External Reset occurs. The bit is reset by a Power-on Reset, or by writing a  
logic zero to the flag.  
• Bit 0 – PORF: Power-on Reset Flag  
This bit is set if a Power-on Reset occurs. The bit is reset only by writing a logic zero to the flag.  
To make use of the Reset flags to identify a reset condition, the user should read and then reset  
the MCUSR as early as possible in the program. If the register is cleared before another reset  
occurs, the source of the reset can be found by examining the reset flags.  
7.2.2  
MCUCR - MCU Control Register  
Bit  
7
6
R
0
5
R
0
4
3
2
1
0
R
0
PUD  
R/W  
0
RSTDIS  
R/W  
0
CKRC81  
IVSEL  
R/W  
0
IVCE  
R/W  
0
MCUCR  
Read/Write  
Initial Value  
R/W  
0
• Bit 3– RSTDIS: Reset Pin Disable  
Thanks to RSTDIS in MCUCR Sfr, the reset function can be disabled, leaving this pin for func-  
tional purpose.  
– When the RSTDIS bit is written to zero, the reset signal is active.  
– When the RSTDIS bit is written to one, the reset signal is inactive.  
7.3  
Internal Voltage Reference  
AT90PWM81/161 features an internal bandgap reference. This bandgap reference is used for  
Brown-out Detection and can be used as analog input for the analog comparators or the ADC.  
The internal voltage reference for the DAC and/or the ADC and the comparators is derived from  
this bandgap voltage, see “On Chip voltage Reference and Temperature sensor overview” on  
page 189.  
The VREF voltage is configured thanks to the REFS1 and REFS0 bits in the ADMUX register; see  
“ADMUX - ADC Multiplexer Register” on page 217.  
7.3.1  
Bandgap and Internal Voltage Reference Enable Signals and Start-up Time  
The bandgap and the internal voltage reference characteristics is given on Table 7-4 on page  
56. To save power, the reference is not always turned on. The bandgap and the internal refer-  
ence is on during the following situations:  
1. When the BOD is enabled (by programming the BODLEVEL [2..0] Fuse).  
2. When the internal reference is selected (REFS1 = 1).  
3. When the bandgap reference is connected to the Analog Comparator.  
4. When the ADC is enabled.  
Thus, when the BOD is not enabled, after enabling the ADC, comparator or the internal refer-  
ence, the user must always allow the reference to start up before the output from the Analog  
Comparator or ADC or DAC is used. To reduce power consumption in Power-down mode, the  
55  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
user can avoid the four conditions above to ensure that the reference is turned off before enter-  
ing Power-down mode.  
7.3.2  
Voltage Reference Characteristics  
Table 7-4.  
Symbol  
VBG  
Internal voltage reference characteristics (1)  
.
Parameter  
Condition  
Minimum  
Typical  
Maximum  
Units  
Bandgap reference voltage  
1.1  
V
Bandgap reference start-up  
time  
tBG  
40  
15  
µs  
Bandgap reference current  
consumption  
IBG  
µA  
Note:  
1. Values are guidelines only.  
7.4  
Watchdog Timer  
AT90PWM81/161 has an Enhanced Watchdog Timer (WDT). The main features are:  
Clocked from separate On-chip Oscillator  
Three operating modes  
– Interrupt  
– System reset  
– Interrupt and system reset  
Selectable time-out period from 1ms to 8s  
Possible hardware fuse watchdog always on (WDTON) for fail-safe mode  
Figure 7-7. Watchdog timer.  
128 KHz  
OSCILLATOR  
WDP3  
MCU RESET  
WDIF  
INTERRUPT  
WDIE  
The Watchdog Timer (WDT) is a timer counting cycles of a separate on-chip 128kHz oscillator.  
The WDT gives an interrupt or a system reset when the counter reaches a given time-out value.  
In normal operation mode, it is required that the system uses the WDR - Watchdog Timer Reset  
- instruction to restart the counter before the time-out value is reached. If the system doesn't  
restart the counter, an interrupt or system reset will be issued.  
56  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
In Interrupt mode, the WDT gives an interrupt when the timer expires. This interrupt can be used  
to wake the device from sleep-modes, and also as a general system timer. One example is to  
limit the maximum time allowed for certain operations, giving an interrupt when the operation  
has run longer than expected. In System Reset mode, the WDT gives a reset when the timer  
expires. This is typically used to prevent system hang-up in case of runaway code. The third  
mode, Interrupt and System Reset mode, combines the other two modes by first giving an inter-  
rupt and then switch to System Reset mode. This mode will for instance allow a safe shutdown  
by saving critical parameters before a system reset.  
The “Watchdog Timer Always On” (WDTON) fuse, if programmed, will force the Watchdog Timer  
to System Reset mode. With the fuse programmed the System Reset mode bit (WDE) and Inter-  
rupt mode bit (WDIE) are locked to 1 and 0 respectively. To further ensure program security,  
alterations to the Watchdog set-up must follow timed sequences. The sequence for clearing  
WDE and changing time-out configuration is as follows:  
1. In the same operation, write a logic one to the Watchdog change enable bit (WDCE)  
and WDE. A logic one must be written to WDE regardless of the previous value of the  
WDE bit.  
2. Within the next four clock cycles, write the WDE and Watchdog prescaler bits (WDP) as  
desired, but with the WDCE bit cleared. This must be done in one operation.  
The following code example shows one assembly and one C function for turning off the Watch-  
dog Timer. The example assumes that interrupts are controlled (for example by disabling  
interrupts globally) so that no interrupts will occur during the execution of these functions.  
57  
7734Q–AVR–02/12  
AT90PWM81/161  
Assembly code example (1)  
WDT_off:  
; Turn off global interrupt  
cli  
; Reset Watchdog Timer  
wdr  
; Clear WDRF in MCUSR  
in  
andi r16, (0xff & (0<<WDRF))  
out MCUSR, r16  
; Write logical one to WDCE and WDE  
r16, MCUSR  
; Keep old prescaler setting to prevent unintentional time-out  
lds r16, WDTCSR  
ori  
r16, (1<<WDCE) | (1<<WDE)  
sts WDTCSR, r16  
; Turn off WDT  
ldi  
r16, (0<<WDE)  
sts WDTCSR, r16  
; Turn on global interrupt  
sei  
ret  
C code example (1)  
void WDT_off(void)  
{
__disable_interrupt();  
__watchdog_reset();  
/* Clear WDRF in MCUSR */  
MCUSR &= ~(1<<WDRF);  
/* Write logical one to WDCE and WDE */  
/* Keep old prescaler setting to prevent unintentional time-out */  
WDTCSR |= (1<<WDCE) | (1<<WDE);  
/* Turn off WDT */  
WDTCSR = 0x00;  
__enable_interrupt();  
}
Note:  
1. The example code assumes that the part specific header file is included.  
Note: If the Watchdog is accidentally enabled, for example by a runaway pointer or brown-out  
condition, the device will be reset and the Watchdog Timer will stay enabled. If the code is not  
set up to handle the Watchdog, this might lead to an eternal loop of time-out resets. To avoid this  
situation, the application software should always clear the Watchdog System Reset Flag  
(WDRF) and the WDE control bit in the initialisation routine, even if the Watchdog is not in use.  
The following code example shows one assembly and one C function for changing the time-out  
value of the Watchdog Timer.  
58  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Assembly code example (1)  
WDT_Prescaler_Change:  
; Turn off global interrupt  
cli  
; Reset Watchdog Timer  
wdr  
; Start timed sequence  
lds r16, WDTCSR  
ori  
r16, (1<<WDCE) | (1<<WDE)  
sts WDTCSR, r16  
; -- Got four cycles to set the new values from here -  
; Set new prescaler(time-out) value = 64K cycles (~0.5 s)  
ldi  
r16, (1<<WDE) | (1<<WDP2) | (1<<WDP0)  
sts WDTCSR, r16  
; -- Finished setting new values, used 2 cycles -  
; Turn on global interrupt  
sei  
ret  
C code example (1)  
void WDT_Prescaler_Change(void)  
{
__disable_interrupt();  
__watchdog_reset();  
/* Start timed equence */  
WDTCSR |= (1<<WDCE) | (1<<WDE);  
/* Set new prescaler(time-out) value = 64K cycles (~0.5 s) */  
WDTCSR = (1<<WDE) | (1<<WDP2) | (1<<WDP0);  
__enable_interrupt();  
}
Note:  
1. The example code assumes that the part specific header file is included.  
Note: The Watchdog Timer should be reset before any change of the WDP bits, since a change  
in the WDP bits can result in a time-out when switching to a shorter time-out period.  
7.4.1  
WDTCSR - Watchdog Timer Control Register  
Bit  
7
6
5
4
3
2
1
0
WDIF  
WDIE  
WDP3  
R/W  
0
WDCE  
R/W  
0
WDE  
R/W  
X
WDP2  
R/W  
0
WDP1  
R/W  
0
WDP0  
R/W  
0
WDTCSR  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
• Bit 7 - WDIF: Watchdog Interrupt Flag  
This bit is set when a time-out occurs in the Watchdog Timer and the Watchdog Timer is config-  
ured for interrupt. WDIF is cleared by hardware when executing the corresponding interrupt  
handling vector. Alternatively, WDIF is cleared by writing a logic one to the flag. When the I-bit in  
SREG and WDIE are set, the Watchdog Time-out Interrupt is executed.  
59  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
• Bit 6 - WDIE: Watchdog Interrupt Enable  
When this bit is written to one and the I-bit in the Status Register is set, the Watchdog Interrupt is  
enabled. If WDE is cleared in combination with this setting, the Watchdog Timer is in Interrupt  
Mode, and the corresponding interrupt is executed if time-out in the Watchdog Timer occurs.  
If WDE is set, the Watchdog Timer is in Interrupt and System Reset Mode. The first time-out in  
the Watchdog Timer will set WDIF. Executing the corresponding interrupt vector will clear WDIE  
and WDIF automatically by hardware (the Watchdog goes to System Reset Mode). This is use-  
ful for keeping the Watchdog Timer security while using the interrupt. To stay in Interrupt and  
System Reset Mode, WDIE must be set after each interrupt. This should however not be done  
within the interrupt service routine itself, as this might compromise the safety-function of the  
Watchdog System Reset mode. If the interrupt is not executed before the next time-out, a Sys-  
tem Reset will be applied.  
Table 7-5.  
Watchdog timer configuration.  
WDTON (1)  
WDE  
WDIE  
Mode  
Action on time-out  
None  
0
0
0
0
0
1
0
1
0
Stopped  
Interrupt mode  
System reset mode  
Interrupt  
Reset  
Interrupt and system reset  
mode  
Interrupt, then go to system  
reset mode  
0
1
1
x
1
x
System reset mode  
Reset  
Note:  
1. For the WDTON fuse “1” means unprogrammed while “0” means programmed.  
• Bit 4 - WDCE: Watchdog Change Enable  
This bit is used in timed sequences for changing WDE and prescaler bits. To clear the WDE bit,  
and/or change the prescaler bits, WDCE must be set.  
Once written to one, hardware will clear WDCE after four clock cycles.  
• Bit 3 - WDE: Watchdog System Reset Enable  
WDE is overridden by WDRF in MCUSR. This means that WDE is always set when WDRF is  
set. To clear WDE, WDRF must be cleared first. This feature ensures multiple resets during con-  
ditions causing failure, and a safe start-up after the failure.  
• Bit 5, 2..0 - WDP3..0: Watchdog Timer Prescaler 3, 2, 1 and 0  
The WDP3..0 bits determine the Watchdog Timer prescaling when the Watchdog Timer is run-  
ning. The different prescaling values and their corresponding time-out periods are shown in  
Table 7-6 on page 61.  
60  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
.
Table 7-6.  
Watchdog timer prescaler select.  
Number of WDT oscillator  
Typical time-out at  
VCC = 5.0V  
WDP3  
WDP2  
WDP1  
WDP0  
cycles  
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
0
0
0
0
1
1
1
1
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
2K (2048) cycles  
4K (4096) cycles  
8K (8192) cycles  
16K (16384) cycles  
32K (32768) cycles  
64K (65536) cycles  
128K (131072) cycles  
256K (262144) cycles  
512K (524288) cycles  
1024K (1048576) cycles  
1K (1024) cycles  
512 cycles  
16ms  
32ms  
64ms  
0.125s  
0.25s  
0.5s  
1.0s  
2.0s  
4.0s  
8.0s  
8ms  
4ms  
256 cycles  
2ms  
128 cycles  
1ms  
Reserved  
61  
7734Q–AVR–02/12  
AT90PWM81/161  
8. Interrupts  
This section describes the specifics of the interrupt handling as performed in the Atmel  
AT90PWM81/161. For a general explanation of the AVR interrupt handling, refer to “Reset and  
Interrupt Handling” on page 13.  
8.1  
Interrupt Vectors in AT90PWM81/161  
Table 8-1.  
Reset and interrupt vectors.  
AT90PWM81  
program  
address  
AT90PWM161  
program  
Vector  
no.  
address  
Source  
Interrupt definition  
External pin, power-on reset, brown-out  
reset, watchdog reset, and emulation  
AVR reset  
1
0x0000  
0x0000  
RESET  
2
3
0x0001  
0x0002  
0x0003  
0x0004  
0x0005  
0x0006  
0x0007  
0x0008  
0x0009  
0x000A  
0x0002  
0x0004  
0x0006  
0x0008  
0x000A  
0x000C  
0x000E  
0x0010  
0x0012  
0x0014  
PSC2 CAPT  
PSC2 EC  
PSC2 capture event  
PSC2 end cycle  
4
PSC2 EEC  
PSCr CAPT  
PSCr EC  
PSC2 end of enhanced cycle  
PSC reduced capture event  
PSC reduced end cycle  
PSC reduced end of enhanced cycle  
Analog comparator 0  
5
6
7
PSCr EEC  
ANACOMP 0  
ANACOMP 1  
ANACOMP 2  
INT0  
8
9
Analog comparator 1  
10  
11  
Analog comparator 2  
External interrupt request 0  
TIMER1  
CAPT  
12  
0x000B  
0x0016  
Timer/Counter1 capture event  
13  
14  
15  
16  
17  
18  
19  
20  
0x000C  
0x000D  
0x000E  
0x000F  
0x0010  
0x0011  
0x0012  
0x0013  
0x0018  
0x001A  
0x001C  
0x001E  
0x0020  
0x0022  
0x0024  
0x0026  
TIMER1 OVF  
ADC  
Timer/Counter1 overflow  
ADC conversion complete  
External interrupt request 1  
SPI serial transfer complete  
External interrupt request 2  
Watchdog time-out interrupt  
EEPROM ready  
INT1  
SPI, STC  
INT2  
WDT  
EE READY  
SPM READY  
Store program memory ready  
Notes: 1. When the BOOTRST fuse is programmed, the device will jump to the boot loader address at  
reset, see “Boot Loader Support – Read-While-Write Self-Programming” on page 233.  
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.  
Table 8-2 on page 63 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  
62  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
the case if the Reset Vector is in the Application section while the Interrupt Vectors are in the  
Boot section or vice versa.  
Table 8-2.  
BOOTRST  
Reset and interrupt vectors placement in AT90PWM81/161 (1)  
.
IVSEL  
Reset address  
0x000  
Interrupt vectors start address  
0x001  
1
1
0
0
0
1
0
1
0x000  
Boot reset address + 0x001  
0x001  
Boot reset address  
Boot reset address  
Boot reset address + 0x001  
Note:  
1. The Boot Reset Address is shown in Table 20-7 on page 246. 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  
AT90PWM81 is:  
(for AT90PWM161, interrupt vector address have an increment equal to 2 in place of 1 for  
AT90PWM81)  
Address  
0x000  
0x001  
0x002  
0x003  
0x004  
0x005  
0x006  
0x007  
0x008  
0x009  
0x00A  
0x00B  
0x00C  
0x00D  
0x00E  
0x00F  
0x010  
0x011  
0x012  
0x013  
0x014  
0x015  
0x016  
0x017  
0x018  
0x019  
0x01A  
0x01B  
Labels Code  
Comments  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
rjmp  
RESET  
; Reset Handler  
PSC2_CAPT  
PSC2_EC  
PSC2_EEC  
PSCR_CAPT  
PSCR_EC  
PSCR_EEC  
ANA_COMP_0  
ANA_COMP_1  
ANA_COMP_2  
EXT_INT0  
TIM1_CAPT  
TIM1_OVF  
ADC  
; PSC2 Capture event Handler  
; PSC2 End Cycle Handler  
; PSC2 End Enhanced Cycle Handler  
; PSCr Capture event Handler  
; PSC0 End Cycle Handler  
; PSCr End Enhanced Cycle Handler  
; Analog Comparator 0 Handler  
; Analog Comparator 1 Handler  
; Analog Comparator 2 Handler  
; IRQ0 Handler  
; Timer1 Capture Handler  
; Timer1 Overflow Handler  
; ADC Conversion Complete Handler  
; IRQ1 Handler  
EXT_INT1  
SPI_STC  
EXT_INT2  
WDT  
; SPI Transfer Complete Handler  
; IRQ2 Handler  
; Watchdog Timer Handler  
; EEPROM Ready Handler  
EE_RDY  
SPM_RDY  
; Store Program Memory Ready Handler  
63  
7734Q–AVR–02/12  
 
AT90PWM81/161  
0x01C  
0x01F  
;
rjmp  
rjmp  
0x020RESET:  
0x021  
0x022  
ldi  
out  
ldi  
r16, high(RAMEND); Main program start  
SPH,r16 ; Set Stack Pointer to top of RAM  
r16, low(RAMEND)  
0x023  
0x024  
out  
sei  
SPL,r16  
; Enable interrupts  
0x025  
<instr> xxx  
... ...  
...  
...  
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 AT90PWM81/161 is:  
Address Labels Code  
Comments  
0x000  
0x001  
0x002  
RESET: ldi  
out  
r16,high(RAMEND); Main program start  
SPH,r16  
; Set Stack Pointer to top of RAM  
ldi  
r16,low(RAMEND)  
SPL,r16  
0x003  
0x004  
out  
sei  
; Enable interrupts  
0x005  
;
<instr> xxx  
For AT90PWM81  
.org 0xC01  
0xC01  
rjmp  
rjmp  
...  
PSC2_CAPT  
PSC2_EC  
...  
; PSC2 Capture event Handler  
; PSC2 End Cycle Handler  
;
0xC02  
...  
0xC1F  
rjmp  
SPM_RDY  
; Store Program Memory Ready Handler  
For AT90PWM161  
.org 0xC01  
0xC02  
rjmp  
rjmp  
...  
PSC2_CAPT  
PSC2_EC  
...  
; PSC2 Capture event Handler  
; PSC2 End Cycle Handler  
;
0xC04  
...  
0xC3F  
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  
AT90PWM81/161 is:  
Address Labels Code  
For AT90PWM81  
.org 0x001  
Comments  
0x001  
0x002  
...  
rjmp  
rjmp  
...  
PSC2_CAPT  
PSC2_EC  
...  
; PSC2 Capture event Handler  
; PSC2 End Cycle Handler  
;
0x01F  
rjmp  
SPM_RDY  
; Store Program Memory Ready Handler  
64  
7734Q–AVR–02/12  
AT90PWM81/161  
For AT90PWM161  
.org 0x001  
0x002  
rjmp  
rjmp  
...  
PSC2_CAPT  
PSC2_EC  
...  
; PSC2 Capture event Handler  
0x004  
; PSC2 End Cycle Handler  
...  
;
0x03F  
rjmp  
SPM_RDY  
; Store Program Memory Ready Handler  
;
.org 0xC00  
0xC00  
0xC01  
0xC02  
RESET: ldi  
r16,high(RAMEND); Main program start  
out  
ldi  
SPH,r16  
; Set Stack Pointer to top of RAM  
r16,low(RAMEND)  
SPL,r16  
0xC03  
0xC04  
out  
sei  
; Enable interrupts  
0xC05  
<instr> 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 AT90PWM81/161 is:  
Address Labels Code  
;
Comments  
For AT90PWM81  
.org 0xC00  
0xC00  
rjmp  
rjmp  
rjmp  
...  
RESET  
; Reset handler  
0xC01  
PSC2_CAPT  
PSC2_EC  
...  
; PSC2 Capture event Handler  
; PSC2 End Cycle Handler  
;
0xC02  
...  
0xC1F  
rjmp  
SPM_RDY  
; Store Program Memory Ready Handler  
For AT90PWM161  
.org 0xC00  
0xC00  
rjmp  
rjmp  
rjmp  
...  
RESET  
; Reset handler  
0xC02  
0xC04  
...  
PSC2_CAPT  
PSC2_EC  
...  
; PSC2 Capture event Handler  
; PSC2 End Cycle Handler  
;
0xC3F  
;
rjmp  
SPM_RDY  
; Store Program Memory Ready Handler  
0xC20  
0xC21  
0xC22  
RESET: ldi  
r16,high(RAMEND); Main program start  
out  
ldi  
SPH,r16  
; Set Stack Pointer to top of RAM  
r16,low(RAMEND)  
SPL,r16  
0xC23  
0xC24  
out  
sei  
; Enable interrupts  
0xC25  
<instr> xxx  
8.1.1  
Moving Interrupts Between Application and Boot Space  
The MCU Control Register controls the placement of the Interrupt Vector table.  
65  
7734Q–AVR–02/12  
 
AT90PWM81/161  
8.1.2  
MCUCR - MCU Control Register  
Bit  
7
R
0
6
R
0
5
R
0
4
3
2
1
0
PUD  
R/W  
0
RSTDIS  
R/W  
0
CKRC81  
IVSEL  
R/W  
0
IVCE  
R/W  
0
MCUCR  
Read/Write  
Initial Value  
R/W  
0
• 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 deter-  
mined by the BOOTSZ Fuses. Refer to the section “Boot Loader Support – Read-While-Write  
Self-Programming” on page 233 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 the section “Boot Loader Support – Read-While-  
Write Self-Programming” on page 233 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 next page.  
66  
7734Q–AVR–02/12  
AT90PWM81/161  
Assembly code example  
Move_interrupts:  
; Enable change of Interrupt Vectors  
ldi r16, (1<<IVCE)  
out MCUCR, r16  
; Move interrupts to Boot Flash section  
ldi r16, (1<<IVSEL)  
out MCUCR, r16  
ret  
C code example  
void Move_interrupts(void)  
{
/* Enable change of Interrupt Vectors */  
MCUCR = (1<<IVCE);  
/* Move interrupts to Boot Flash section */  
MCUCR = (1<<IVSEL);  
}
67  
7734Q–AVR–02/12  
AT90PWM81/161  
9. I/O-Ports  
9.1  
Introduction  
All AVR ports have true Read-Modify-Write functionality when used as general digital I/O ports.  
This means that the direction of one port pin can be changed without unintentionally changing  
the direction of any other pin with the SBI and CBI instructions. The same applies when chang-  
ing drive value (if configured as output) or enabling/disabling of pull-up resistors (if configured as  
input). Each output buffer has symmetrical drive characteristics with both high sink and source  
capability. All port pins have individually selectable pull-up resistors with a supply-voltage invari-  
ant resistance. All I/O pins have protection diodes to both VCC and Ground as indicated in Figure  
9-1. Refer to “Electrical Characteristics (1)” on page 265 for a complete list of parameters.  
Figure 9-1. I/O pin equivalent schematic.  
Rpu  
Pxn  
Logic  
Cpin  
See Figure  
"General Digital I/O" for  
Details  
All registers and bit references in this section are written in general form. A lower case “x” repre-  
sents the numbering letter for the port, and a lower case “n” represents the bit number. However,  
when using the register or bit defines in a program, the precise form must be used. For example,  
PORTB3 for bit no. 3 in Port B, here documented generally as PORTxn. The physical I/O Regis-  
ters and bit locations are listed in “Register Description for I/O-Ports” on page 81.  
Three I/O memory address locations are allocated for each port, one each for the Data Register  
– PORTx, Data Direction Register – DDRx, and the Port Input Pins – PINx. The Port Input Pins  
I/O location is read only, while the Data Register and the Data Direction Register are read/write.  
However, writing a logic one to a bit in the PINx Register, will result in a toggle in the correspond-  
ing bit in the Data Register. In addition, the Pull-up Disable – PUD bit in MCUCR disables the  
pull-up function for all pins in all ports when set.  
Using the I/O port as General Digital I/O is described in “Ports as General Digital I/O” on page  
69. Most port pins are multiplexed with alternate functions for the peripheral features on the  
device. How each alternate function interferes with the port pin is described in “Alternate Port  
Functions” on page 73. Refer to the individual module sections for a full description of the alter-  
nate functions.  
Note that enabling the alternate function of some of the port pins does not affect the use of the  
other pins in the port as general digital I/O.  
68  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
9.2  
Ports as General Digital I/O  
The ports are bi-directional I/O ports with optional internal pull-ups. Figure 9-2 shows a func-  
tional description of one I/O-port pin, here generically called Pxn.  
Figure 9-2. General digital I/O (1)  
.
PUD  
Q
D
DDxn  
Q CLR  
WDx  
RDx  
RESET  
1
0
Q
D
Pxn  
PORTxn  
Q CLR  
WPx  
WRx  
RESET  
SLEEP  
RRx  
SYNCHRONIZER  
RPx  
D
Q
D
L
Q
Q
PINxn  
Q
clk I/O  
WDx: WRITE DDRx  
RDx: READ DDRx  
WRx: WRITE PORTx  
RRx: READ PORTx REGISTER  
RPx: READ PORTx PIN  
PUD: PULLUP DISABLE  
SLEEP: SLEEP CONTROL  
clkI/O: I/O CLOCK  
WPx: WRITE PINx REGISTER  
Note:  
1. WRx, WPx, WDx, RRx, RPx, and RDx are common to all pins within the same port. clkI/O  
,
SLEEP, and PUD are common to all ports.  
9.2.1  
Configuring the Pin  
Each port pin consists of three register bits: DDxn, PORTxn, and PINxn. As shown in “Register  
Description for I/O-Ports” on page 81, the DDxn bits are accessed at the DDRx I/O address, the  
PORTxn bits at the PORTx I/O address, and the PINxn bits at the PINx I/O address.  
The DDxn bit in the DDRx Register selects the direction of this pin. If DDxn is written logic one,  
Pxn is configured as an output pin. If DDxn is written logic zero, Pxn is configured as an input  
pin.  
If PORTxn is written logic one when the pin is configured as an input pin, the pull-up resistor is  
activated. To switch the pull-up resistor off, PORTxn has to be written logic zero or the pin has to  
be configured as an output pin.  
The port pins are tri-stated when reset condition becomes active, even if no clocks are running.  
69  
7734Q–AVR–02/12  
 
 
 
 
 
AT90PWM81/161  
If PORTxn is written logic one when the pin is configured as an output pin, the port pin is driven  
high (one). If PORTxn is written logic zero when the pin is configured as an output pin, the port  
pin is driven low (zero).  
9.2.2  
9.2.3  
Toggling the Pin  
Writing a logic one to PINxn toggles the value of PORTxn, independent on the value of DDRxn.  
Note that the SBI instruction can be used to toggle one single bit in a port.  
Switching Between Input and Output  
When switching between tri-state ({DDxn, PORTxn} = 0b00) and output high ({DDxn, PORTxn}  
= 0b11), an intermediate state with either pull-up enabled {DDxn, PORTxn} = 0b01) or output  
low ({DDxn, PORTxn} = 0b10) must occur. Normally, the pull-up enabled state is fully accept-  
able, as a high-impedant environment will not notice the difference between a strong high driver  
and a pull-up. If this is not the case, the PUD bit in the MCUCR Register can be set to disable all  
pull-ups in all ports.  
Switching between input with pull-up and output low generates the same problem. The user  
must use either the tri-state ({DDxn, PORTxn} = 0b00) or the output high state ({DDxn, PORTxn}  
= 0b11) as an intermediate step.  
Table 9-1 summarizes the control signals for the pin value.  
Table 9-1.  
Port pin configurations.  
PUD  
DDxn  
PORTxn  
(in MCUCR)  
I/O  
Pull-up  
Comment  
Default configuration after reset.  
Tri-state (Hi-Z)  
0
0
X
Input  
No  
0
0
1
1
1
1
0
1
0
1
Input  
Input  
Yes  
No  
No  
No  
Pxn will source current if ext. pulled low  
Tri-state (Hi-Z)  
X
X
Output  
Output  
Output low (Sink)  
Output high (Source)  
9.2.4  
Reading the Pin Value  
Independent of the setting of Data Direction bit DDxn, the port pin can be read through the  
PINxn Register bit. As shown in Figure 9-2 on page 69, the PINxn Register bit and the preceding  
latch constitute a synchronizer. This is needed to avoid metastability if the physical pin changes  
value near the edge of the internal clock, but it also introduces a delay. Figure 9-3 on page 71  
shows a timing diagram of the synchronization when reading an externally applied pin value.  
The maximum and minimum propagation delays are denoted tpd,max and tpd,min respectively.  
70  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Figure 9-3. Synchronization when reading an externally applied pin value.  
SYSTEM CLK  
INSTRUCTIONS  
SYNC LATCH  
PINxn  
XXX  
XXX  
in r17, PINx  
0x00  
tpd, max  
0xFF  
r17  
tpd, min  
Consider the clock period starting shortly after the first falling edge of the system clock. The latch  
is closed when the clock is low, and goes transparent when the clock is high, as indicated by the  
shaded region of the “SYNC LATCH” signal. The signal value is latched when the system clock  
goes low. It is clocked into the PINxn Register at the succeeding positive clock edge. As indi-  
cated by the two arrows tpd,max and tpd,min, a single signal transition on the pin will be delayed  
between ½ and 1½ system clock period depending upon the time of assertion.  
When reading back a software assigned pin value, a nop instruction must be inserted as indi-  
cated in Figure 9-4. The out instruction sets the “SYNC LATCH” signal at the positive edge of  
the clock. In this case, the delay tpd through the synchronizer is 1 system clock period.  
Figure 9-4. Synchronization when reading a software assigned pin value.  
SYSTEM CLK  
0xFF  
r16  
out PORTx, r16  
nop  
in r17, PINx  
INSTRUCTIONS  
SYNC LATCH  
PINxn  
0x00  
tpd  
0xFF  
r17  
The following code example shows how to set port B pins 0 and 1 high, 2 and 3 low, and define  
the port pins from 4 to 7 as input with pull-ups assigned to port pins 6 and 7. The resulting pin  
values are read back again, but as previously discussed, a nop instruction is included to be able  
to read back the value recently assigned to some of the pins.  
71  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Assembly code example (1)  
...  
; Define pull-ups and set outputs high  
; Define directions for port pins  
ldi r16, (1<<PB7)|(1<<PB6)|(1<<PB1)|(1<<PB0)  
ldi r17, (1<<DDB3)|(1<<DDB2)|(1<<DDB1)|(1<<DDB0)  
out PORTB, r16  
out DDRB, r17  
; Insert nop for synchronization  
nop  
; Read port pins  
in  
r16, PINB  
...  
C code example  
unsigned char i;  
...  
/* Define pull-ups and set outputs high */  
/* Define directions for port pins */  
PORTB = (1<<PB7)|(1<<PB6)|(1<<PB1)|(1<<PB0);  
DDRB = (1<<DDB3)|(1<<DDB2)|(1<<DDB1)|(1<<DDB0);  
/* Insert nop for synchronization*/  
_NOP();  
/* Read port pins */  
i = PINB;  
...  
Note:  
1. For the assembly program, two temporary registers are used to minimize the time from pull-  
ups are set on pins 0, 1, 6, and 7, until the direction bits are correctly set, defining bit 2 and 3  
as low and redefining bits 0 and 1 as strong high drivers.  
9.2.5  
Digital Input Enable and Sleep Modes  
As shown in Figure 9-2 on page 69, the digital input signal can be clamped to ground at the input  
of the schmitt-trigger. The signal denoted SLEEP in the figure, is set by the MCU Sleep Control-  
ler in Power-down mode, and Standby mode to avoid high power consumption if some input  
signals are left floating, or have an analog signal level close to VCC/2.  
SLEEP is overridden for port pins enabled as external interrupt pins. If the external interrupt  
request is not enabled, SLEEP is active also for these pins. SLEEP is also overridden by various  
other alternate functions as described in “Alternate Port Functions” on page 73.  
If a logic high level (“one”) is present on an Asynchronous External Interrupt pin configured as  
“Interrupt on Rising Edge, Falling Edge, or Any Logic Change on Pin” while the external interrupt  
is not enabled, the corresponding External Interrupt Flag will be set when resuming from the  
above mentioned sleep modes, as the clamping in these sleep modes produces the requested  
logic change.  
72  
7734Q–AVR–02/12  
 
AT90PWM81/161  
9.3  
Alternate Port Functions  
Most port pins have alternate functions in addition to being general digital I/Os. Figure 9-5 shows  
how the port pin control signals from the simplified Figure 9-2 on page 69 can be overridden by  
alternate functions. The overriding signals may not be present in all port pins, but the figure  
serves as a generic description applicable to all port pins in the AVR microcontroller family.  
Figure 9-5. Alternate port functions (1)  
.
PUOExn  
PUOVxn  
1
0
PUD  
DDOExn  
DDOVxn  
1
0
Q
D
DDxn  
Q CLR  
WDx  
RDx  
PVOExn  
PVOVxn  
RESET  
1
1
0
Pxn  
Q
D
0
PORTxn  
PTOExn  
WPx  
Q CLR  
DIEOExn  
DIEOVxn  
SLEEP  
RESET  
WRx  
1
0
RRx  
RPx  
SYNCHRONIZER  
SET  
D
Q
D
L
Q
Q
PINxn  
Q
CLR  
CLR  
clk I/O  
DIxn  
AIOxn  
PUOExn: Pxn PULL-UP OVERRIDE ENABLE  
PUOVxn: Pxn PULL-UP OVERRIDE VALUE  
DDOExn: Pxn DATA DIRECTION OVERRIDE ENABLE  
PUD: PULLUP DISABLE  
WDx: WRITE DDRx  
RDx: READ DDRx  
DDOVxn: Pxn DATA DIRECTION OVERRIDE VALUE  
PVOExn: Pxn PORT VALUE OVERRIDE ENABLE  
PVOVxn: Pxn PORT VALUE OVERRIDE VALUE  
RRx: READ PORTx REGISTER  
WRx: WRITE PORTx  
RPx: READ PORTx PIN  
WPx: WRITE PINx  
DIEOExn: Pxn DIGITAL INPUT-ENABLE OVERRIDE ENABLE  
DIEOVxn: Pxn DIGITAL INPUT-ENABLE OVERRIDE VALUE  
SLEEP: SLEEP CONTROL  
PTOExn: Pxn, PORT TOGGLE OVERRIDE ENABLE  
clkI/O  
DIxn: DIGITAL INPUT PIN n ON PORTx  
AIOxn: ANALOG INPUT/OUTPUT PIN n ON PORTx  
: I/O CLOCK  
Note:  
1. WRx, WPx, WDx, RRx, RPx, and RDx are common to all pins within the same port. clkI/O  
,
SLEEP, and PUD are common to all ports. All other signals are unique for each pin.  
Table 9-2 on page 74 summarizes the function of the overriding signals. The pin and port  
indexes from Figure 9-5 are not shown in the succeeding tables. The overriding signals are gen-  
erated internally in the modules having the alternate function.  
73  
7734Q–AVR–02/12  
 
 
 
 
 
AT90PWM81/161  
Table 9-2.  
Generic description of overriding signals for alternate functions.  
Signal name  
Full name  
Description  
If this signal is set, the pull-up enable is controlled by the PUOV  
signal. If this signal is cleared, the pull-up is enabled when  
{DDxn, PORTxn, PUD} = 0b010.  
Pull-up override  
enable  
PUOE  
PUOV  
DDOE  
DDOV  
If PUOE is set, the pull-up is enabled/disabled when PUOV is  
set/cleared, regardless of the setting of the DDxn, PORTxn,  
and PUD Register bits.  
Pull-up override  
value  
If this signal is set, the Output Driver Enable is controlled by the  
DDOV signal. If this signal is cleared, the Output driver is  
enabled by the DDxn Register bit.  
Data direction  
override enable  
If DDOE is set, the Output Driver is enabled/disabled when  
DDOV is set/cleared, regardless of the setting of the DDxn  
Register bit.  
Data direction  
override value  
If this signal is set and the Output Driver is enabled, the port  
value is controlled by the PVOV signal. If PVOE is cleared, and  
the Output Driver is enabled, the port Value is controlled by the  
PORTxn Register bit.  
Port value override  
enable  
PVOE  
Port value override  
value  
If PVOE is set, the port value is set to PVOV, regardless of the  
setting of the PORTxn Register bit.  
PVOV  
PTOE  
Port toggle  
override enable  
If PTOE is set, the PORTxn Register bit is inverted.  
If this bit is set, the Digital Input Enable is controlled by the  
DIEOV signal. If this signal is cleared, the Digital Input Enable  
is determined by MCU state (Normal mode, sleep mode).  
Digital input enable  
override enable  
DIEOE  
DIEOV  
If DIEOE is set, the Digital Input is enabled/disabled when  
DIEOV is set/cleared, regardless of the MCU state (Normal  
mode, sleep mode).  
Digital input enable  
override value  
This is the Digital Input to alternate functions. In the Figure 9-5  
on page 73, the signal is connected to the output of the schmitt  
trigger but before the synchronizer. Unless the Digital Input is  
used as a clock source, the module with the alternate function  
will use its own synchronizer.  
DI  
Digital input  
This is the Analog Input/output to/from alternate functions. The  
signal is connected directly to the pad, and can be used bi-  
directionally.  
Analog  
input/output  
AIO  
The following subsections shortly describe the alternate functions for each port, and relate the  
overriding signals to the alternate function. Refer to the alternate function description Table 9-2  
for further details.  
9.3.1  
MCUCR - MCU Control Register  
Bit  
7
6
R
0
5
R
0
4
3
2
1
0
R
0
PUD  
R/W  
0
RSTDIS  
CKRC81  
IVSEL  
R/W  
0
IVCE  
R/W  
0
MCUCR  
Read/Write  
Initial Value  
RW  
0
R/W  
0
74  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
• Bit 4 – PUD: Pull-up Disable  
When this bit is written to one, the pull-ups in the I/O ports are disabled even if the DDxn and  
PORTxn Registers are configured to enable the pull-ups ({DDxn, PORTxn} = 0b01). See “Con-  
figuring the Pin” on page 69 for more details about this feature.  
9.3.2  
Alternate Functions of Port B  
The Port B pins with alternate functions are shown in Table 9-3.  
Table 9-3.  
Port pin  
Port B pins alternate functions.  
Alternate functions  
PSCOUT22 output  
PB7  
PB6  
ICP1 (Timer/Counter1 Input Capture Pin )  
ADC9 (Analog Input Channel 9)  
MISO (SPI Master In Slave Out)  
ACMP3 (Analog Comparator 3 Positive Input )  
ADC8 (Analog Input Channel 8)  
ADC5 (Analog Input Channel 5)  
ACMP2 (Analog Comparator 2 Positive Input)  
INT1(External Interrupt 1 Input)  
SCK (SPI Clock)  
PB5  
MOSI (SPI Master Out Slave In)  
PB4  
PB3  
ADC3 (Analog Input Channel 3)  
ACMPM reference for analog comparators  
PSCOUTR1 Output  
ADC2 (Analog Input Channel 2)  
ACMP2M (Analog Comparator 2 Negative Input)  
INT0 (External Interrupt 0 Input)  
PSCOUT21 output  
PB2  
PB1  
PSCOUT20 output  
T1 counter source  
PB0  
PSCOUT23 output  
ACMP3_OUT( Analog Comparator3 Output)  
The alternate pin configuration is as follows:  
• PSCOUT22/ICP1/ADC9 – Bit 7  
PSCOUT22: Output 2 of PSC 2  
ICP1 – Input Capture Pin1: This pin can act as an input capture pin for Timer/Counter1.  
ADC9: Analog to Digital Converter, input channel 9.  
• MISO/ACMP3/ADC8– Bit 6  
MISO: Master Data input, Slave Data output pin for SPI channel. When the SPI is enabled as a  
master, this pin is configured as an input regardless of the setting of DDB6. When the SPI is  
enabled as a slave, the data direction of this pin is controlled by DDB6. When the pin is forced to  
be an input, the pull-up can still be controlled by the PORTB6 and PUD bits.  
ACMP3: Analog Comparator 3 Positive Input. Configure the port pin as input with the internal  
pull-up switched off to avoid the digital port function from interfering with the function of the Ana-  
log Comparator.  
ADC8: Analog to Digital Converter, input channel 8.  
75  
7734Q–AVR–02/12  
 
 
 
 
 
AT90PWM81/161  
• ADC5/ACMP2/INT1/SCK – Bit 5  
ADC5: Analog to Digital Converter, input channel 5.  
ACMP2: Analog Comparator 2 Positive Input. Configure the port pin as input with the internal  
pull-up switched off to avoid the digital port function from interfering with the function of the Ana-  
log Comparator.  
INT1: External Interrupt source 1. This pin can serve as an external interrupt source to the MCU.  
SCK: Master Clock output, Slave Clock input pin for SPI channel. When the SPI is enabled as a  
slave, this pin is configured as an input regardless of the setting of DDB5. When the SPI is  
enabled as a master, the data direction of this pin is controlled by DDB5. When the pin is forced  
to be an input, the pull-up can still be controlled by the PORTB5 bit.  
• MOSI/ADC3/ACMPM– Bit 4  
MOSI: SPI Master Data output, Slave Data input for SPI channel. When the SPI is enabled as a  
slave, this pin is configured as an input regardless of the setting of DDB4 When the SPI is  
enabled as a master, the data direction of this pin is controlled by DDB4. When the pin is forced  
to be an input, the pull-up can still be controlled by the PORTB4 and PUD bits.  
ADC3: Analog to Digital Converter, input channel 3.  
ACMPM: Analog Comparators Negative Input. Configure the port pin as input with the internal  
pull-up switched off to avoid the digital port function from interfering with the function of the Ana-  
log Comparator.  
• PSCOUTR1/ADC2/ACMP2M– Bit 3  
PSCOUTR1: Output 1 of PSCR.  
ADC2: Analog to Digital Converter, input channel 2.  
ACMP2M: Analog Comparator 2 Negative Input. Configure the port pin as input with the internal  
pull-up switched off to avoid the digital port function from interfering with the function of the Ana-  
log Comparator.  
• INT0/PSCOUT21 – Bit 2  
INT0: External Interrupt source 0. This pin can serve as an external interrupt source to the MCU.  
PSCOUT21: Output 1 of PSC 2.  
• PSCOUT20 – Bit 1  
PSCOUT20: Output 0 of PSC 2.  
• T1/PSCOUT23/ACMP3_OUT – Bit 0  
T1: Timer/Counter1 counter source.  
PSCOUT23: Output 3 of PSC 2.  
ACMP3_OUT: Analog Comparator3 Output.  
76  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Table 9-4 and Table 9-5 relates the alternate functions of Port B to the overriding signals shown  
in Figure 9-5 on page 73.  
Table 9-4.  
Overriding signals for alternate functions in PB7..PB4.  
Signal  
name  
PB7/PSCOUT22/  
ICP1/ADC9  
PB6/MISO/  
ACMP3/ADC8  
PB5/ADC5/  
ACMP2/INT1/SCK  
PB4/MOSI/ADC3  
/ACMPM  
PUOE  
PUOV  
DDOE  
DDOV  
PVOE  
PVOV  
DIEOE  
DIEOV  
DI  
0
SPE.MSTR  
PB6.PUD  
SPE.MSTR  
0
SPE.MSTR  
PB5.PUD  
SPE.MSTR  
0
SPE.MSTR  
PB4.PUD  
SPE.MSTR  
0
0
PSCen22  
1
PSCen22  
PSCout22  
ADC9D  
0
SPE.MSTR  
MISO  
SPE.MSTR  
SCK  
SPE.MSTR  
MOSI  
ADC8D  
0
ADC5D|In1en  
In1en  
ADC3D  
0
ICP1  
-
INT1  
-
AIO  
ADC9  
ACMP3/ADC8  
ADC5/ACMP2  
ADC3/ACMPM  
Table 9-5.  
Overriding signals for alternate functions in PB3..PB0.  
Signal  
name  
PB3/PSCOUTR1/ PB2/INT0/PSCOUT21/  
PB0/T1/PSCOUT23  
PB1/PSCOUT20 /ACMP3_OUT  
ADC2/ACMP2M  
ADC2/ACMP2M  
PUOE  
PUOV  
DDOE  
DDOV  
PVOE  
PVOV  
DIEOE  
DIEOV  
DI  
0
0
0
0
0
0
0
0
PSCen01  
PSCen21  
1
PSCen20  
PSCen23|AC3EN  
1
1
1
PSCen01  
PSCen21  
PCOUT21  
In0en  
In0en  
INT0  
PSCen20  
PSCen23|AC3EN  
PSCOUTR1  
PCOUT20  
(1)  
ADC2D  
-
-
-
-
-
-
-
-
0
-
AIO  
ADC2/ACMP2M  
-
Note:  
1. If PSCen23 : PSCOUT23  
else  
{if AC3EN : ACMP3OUT  
else : Ø  
}
77  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
The alternate pin configuration is as follows:  
9.3.3  
Alternate Functions of Port D  
The Port D pins with alternate functions are shown in Table 9-6.  
Table 9-6.  
Port pin  
Port D pins alternate functions.  
Alternate function  
ADC10 (Analog Input Channel 10)  
PCSINrA (PSCR first Alternate Digital Input )  
PD7  
PD6  
PD5  
AMP0+ (Analog Differential Amplifier 0 Input Channel )  
AMP0- (Analog Differential Amplifier 0 Input Channel )  
ADC7 (Analog Input Channel 7)  
ACMP3M (Analog Comparator 3 Negative Input)  
ADC4 (Analog Input Channel 4)  
PD4  
PCSIN2A (PSC 2 Digital Input)  
ADC1 (Analog Input Channel 1)  
ACMP2_OUT (Analog Comparator 2 Output)  
PD3  
PD2  
PD1  
ADC0 (Analog Input Channel 0)  
ACMP1 (Analog Comparator 1 Positive Input)  
PSCOUTR0 Output 0  
PCSINrB (PSCR Second Alternate Digital Input)  
ACMP3_OUT_A (Analog Comparator 2 Alternate Output)  
CLKO ( System Clock)  
PD0  
SS ( SPI Slave Select)  
The alternate pin configuration is as follows:  
• ADC10/PSCINrA – Bit 7  
ADC10: Analog to Digital Converter, input channel 10.  
PCSINrA: PSCR First Alternate Digital Input.  
• APM0+ – Bit 6  
AMP0+: Analog Differential Amplifier 0 Positive Input Channel.  
• AMP0-/ADC7 – Bit 5  
AMP0-: Analog Differential Amplifier 0 Negative Input Channel.  
ADC7: Analog to Digital Converter, input channel 7.  
• ACMP3M/ADC4/PSCIN2A – Bit 4  
ACMP3M: Analog Comparator 3 Negative Input. Configure the port pin as input with the internal  
pull-up switched off to avoid the digital port function from interfering with the function of the Ana-  
log Comparator.  
ADC4: Analog to Digital Converter, input channel 4.  
PCSIN2A: PSC 2 Alternate Digital Input.  
78  
7734Q–AVR–02/12  
 
AT90PWM81/161  
• ADC1/ACMP2_OUT, Bit 3  
ADC1: Analog to Digital Converter, input channel 1.  
ACMP2_OUT: Analog Comparator 2 Output.  
• ADC0/ACMP1, Bit 2  
ADC0: Analog to Digital Converter, input channel 0.  
ACMP1: Analog Comparator 1 Positive Input. Configure the port pin as input with the internal  
pull-up switched off to avoid the digital port function from interfering with the function of the Ana-  
log Comparator.  
• PSCOUTR0/PSCINrB – Bit 1  
PSCOUTR0: Output 0 of PSCR.  
PCSINrB: PSCR Second Alternate Digital Input.  
• ACMP3_OUT_A/SS/CLKO – Bit 0  
ACMP2_OUT_A: Analog Comparator 2 Alternate Output.  
SS: Slave Port Select input. When the SPI is enabled as a slave, this pin is configured as an  
input regardless of the setting of DDDn. As a slave, the SPI is activated when this pin is driven  
low. When the SPI is enabled as a master, the data direction of this pin is controlled by DDDn.  
When the pin is forced to be an input, the pull-up can still be controlled by the PORTDn bit.  
CLKO: Divided System Clock: The divided system clock can be output on this pin. The divided  
system clock will be output if the CKOUT Fuse is programmed, regardless of the PORTDn and  
DDDn settings. It will also be output during reset.  
Table 9-7 and Table 9-8 on page 80 relates the alternate functions of Port D to the overriding  
signals shown in Figure 9-5 on page 73.  
Table 9-7.  
Overriding signals for alternate functions PD7..PD4.  
PD7/ADC10/  
PSCINrA  
PD4/ACMP3M/  
ADC4/PSCIN2A  
Signal name  
PUOE  
PUOV  
DDOE  
DDOV  
PVOE  
PVOV  
DIEOE  
DIEOV  
DI  
PD6/APM0+  
PD5/AMP0-/ADC7  
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
ADC10D  
0
AMP0+D  
ADC7D  
ADC4D  
0
0
0
PSCiNrA  
ADC10  
-
-
PSCIN2A  
ADC4/ACMP3M  
AIO  
AMP0+  
ADC7/AMP0-  
79  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Table 9-8.  
Overriding signals for alternate functions in PD3..PD0.  
PD3/ADC1/  
ACMP2_OUT  
PD2/ADC0/  
ACMP1  
PD1/PSCOUTR0/  
PSCINrB  
PD0/ACMP3_OUT/SS/  
CLKO  
Signal name  
PUOE  
PUOV  
DDOE  
DDOV  
PVOE  
PVOV  
DIEOE  
DIEOV  
DI  
0
0
0
SPE.MSTR  
0
0
0
PD0.PUD  
ACE2EN  
0
PSCen00  
ACMP3D|(SPE.MSTR)  
1
0
1
AC3EN  
AC2EN  
0
PSCen00  
AC3EN  
ACMP2_OUT  
0
PSCOUT00  
AVCMP3_OUT  
ADC1D  
ADC0D  
0
0
0
0
0
0
-
-
PSCINrB  
-
SS  
-
AIO  
ADC1  
ADC0/ACMP1  
9.3.4  
Alternate Functions of Port E  
The Port E pins with alternate functions are shown in Table 9-9.  
Table 9-9.  
Port pin  
Port E pins alternate functions.  
Alternate function  
AREF (Analog reference voltage)  
ADC6 (Analog input channel 6)  
PE3  
XTAL2: XTAL Output  
PE2  
ACMP1M (Analog Comparator 1 Negative Input)  
PCSINr (PSCR Digital Input)  
XTAL1: XTAL Input  
PE1  
PE0  
PCSIN2 (PSC 2 Digital Input)  
ACMP1_OUT (Analog Comparator 1 Output)  
RESET (Reset Input)  
OCD (On Chip Debug I/O)  
INT2 (External Interrupt 2 Input)  
The alternate pin configuration is as follows:  
• AREF/ADC6, Bit 3  
AREF: Analog reference voltage. See Table 17-3 on page 218 for the definition of this pin.  
ADC6: Analog to Digital Converter, input channel 6.  
This pin can only be used as a digital output pin. It cannot be read as a digital input.  
• XTAL2/ACMP1M/PSCINr – Bit 2  
XTAL2: Chip clock Oscillator pin 2. Used as clock pin for crystal Oscillator or Low-frequency  
crystal Oscillator. When used as a clock pin, the pin can not be used as an I/O pin.  
80  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
ACMP1M: Analog Comparator 1 Negative Input. Configure the port pin as input with the internal  
pull-up switched off to avoid the digital port function from interfering with the function of the Ana-  
log Comparator.  
PCSINr: PSCR Digital Input.  
• XTAL1/PSCIN2/ACMP1_OUT – Bit 1  
XTAL1: Chip clock Oscillator pin 1. Used for all chip clock sources except internal calibrated RC  
Oscillator. When used as a clock pin, the pin can not be used as an I/O pin.  
PCSIN2: PSC 2 Digital Input.  
ACMP1_OUT: Analog Comparator 1 Output.  
• RESET/OCD/INT2 – Bit 0  
RESET: Reset pin: When the RSTDISBL Fuse is programmed, this pin functions as a normal I/O  
pin, and the part will have to rely on Power-on Reset and Brown-out Reset as its reset sources.  
When the RSTDISBL Fuse is unprogrammed, the reset circuitry is connected to the pin, and the  
pin can not be used as an I/O pin.  
If PE0 is used as a reset pin, DDE0, PORTE0 and PINE0 will all read 0.  
INT2: External Interrupt source 2. This pin can serve as an External Interrupt source to the MCU.  
Table 9-10 relates the alternate functions of Port E to the overriding signals shown in Figure 9-5  
on page 73.  
Table 9-10. Overriding signals for alternate functions in PE2..PE0.  
PE2/XTAL2/ACM  
P1M/PSCINr  
PE1/XTAL1/PSCI  
N2/ ACMP1_OUT  
PE0/RESET/OCD/  
INT2  
Signal name  
PUOE  
PUOV  
DDOE  
DDOV  
PVOE  
PVOV  
DIEOE  
DIEOV  
DI  
PE3/AREF/ADC6  
0
0
0
0
0
0
0
0
0
0
AC1EN  
0
0
0
1
0
0
0
AC1EN  
0
0
0
ACMP1_OUT  
0
0
ACMP1MD  
0
0
In2en  
In2en  
INT2  
-
0
0
-
PSCINr  
ACMP1M  
PSCIN2  
-
AIO  
ADC6  
9.4  
Register Description for I/O-Ports  
9.4.1  
PORTB - Port B Data Register  
Bit  
7
6
5
4
3
2
1
0
PORTB7  
PORTB6  
PORTB5  
PORTB4  
PORTB3  
PORTB2  
PORTB1  
PORTB0  
PORTB  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
81  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
9.4.2  
9.4.3  
9.4.4  
9.4.5  
9.4.6  
9.4.7  
9.4.8  
9.4.9  
DDRB - Port B Data Direction Register  
Bit  
7
6
5
4
3
2
1
0
DDB7  
R/W  
0
DDB6  
R/W  
0
DDB5  
R/W  
0
DDB4  
R/W  
0
DDB3  
R/W  
0
DDB2  
R/W  
0
DDB1  
R/W  
0
DDB0  
R/W  
0
DDRB  
Read/Write  
Initial Value  
PINB - Port B Input Pins Address  
Bit  
7
6
5
4
3
2
1
0
PINB7  
R/W  
N/A  
PINB6  
R/W  
N/A  
PINB5  
R/W  
N/A  
PINB4  
R/W  
N/A  
PINB3  
R/W  
N/A  
PINB2  
R/W  
N/A  
PINB1  
R/W  
N/A  
PINB0  
R/W  
N/A  
PINB  
Read/Write  
Initial Value  
PORTD - Port D Data Register  
Bit  
7
6
5
4
3
2
1
0
PORTD7  
PORTD6  
PORTD5  
PORTD4  
PORTD3  
PORTD2  
PORTD1  
PORTD0  
PORTD  
DDRD  
PIND  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
DDRD - Port D Data Direction RegisterS  
Bit  
7
6
5
4
3
2
1
0
DDD7  
R/W  
0
DDD6  
R/W  
0
DDD5  
R/W  
0
DDD4  
R/W  
0
DDD3  
R/W  
0
DDD2  
R/W  
0
DDD1  
R/W  
0
DDD0  
R/W  
0
Read/Write  
Initial Value  
PIND - Port D Input Pins Address  
Bit  
7
6
5
4
3
2
1
0
PIND7  
R/W  
N/A  
PIND6  
R/W  
N/A  
PIND5  
R/W  
N/A  
PIND4  
R/W  
N/A  
PIND3  
R/W  
N/A  
PIND2  
R/W  
N/A  
PIND1  
R/W  
N/A  
PIND0  
R/W  
N/A  
Read/Write  
Initial Value  
PORTE - Port E Data Register  
Bit  
7
R
0
6
R
0
5
R
0
4
R
0
3
R
0
2
1
0
PORTE2  
PORTE1  
PORTE0  
PORTE  
DDRE  
PINE  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
DDRE - Port E Data Direction Register  
Bit  
7
R
0
6
R
0
5
R
0
4
R
0
3
R
0
2
1
0
DDE2  
R/W  
0
DDE1  
R/W  
0
DDE0  
R/W  
0
Read/Write  
Initial Value  
PINE - Port E Input Pins Address  
Bit  
7
R
0
6
R
0
5
R
0
4
R
0
3
R
0
2
1
0
PINE2  
R/W  
N/A  
PINE1  
R/W  
N/A  
PINE0  
R/W  
N/A  
Read/Write  
Initial Value  
82  
7734Q–AVR–02/12  
 
 
 
 
 
 
 
 
AT90PWM81/161  
10. External Interrupts  
The External Interrupts are triggered by the INT2:0 pins. Observe that, if enabled, the interrupts  
will trigger even if the INT2:0 pins are configured as outputs. This feature provides a way of gen-  
erating a software interrupt. The External Interrupts can be triggered by a falling or rising edge or  
a low level. This is set up as indicated in the specification for the External Interrupt Control Reg-  
isters – EICRA (INT2:0). When the external interrupt is enabled and is configured as level  
triggered, the interrupt will trigger as long as the pin is held low. Note that recognition of falling or  
rising edge interrupts on INT2:0 requires the presence of an I/O clock, described in “Clock Sys-  
tems and their Distribution” on page 27. The I/O clock is halted in all sleep modes except Idle  
mode.  
Note that if a level triggered interrupt is used for wake-up from Power-down mode, the changed  
level must be held for some time to wake up the MCU. This makes the MCU less sensitive to  
noise. The changed level is sampled twice by the Watchdog Oscillator clock. The period of the  
Watchdog Oscillator is 1µs (nominal) at 5.0V and 25°C. The frequency of the Watchdog Oscilla-  
tor is voltage dependent as shown in the “Electrical Characteristics (1)” on page 265. The MCU  
will wake up if the input has the required level during this sampling or if it is held until the end of  
the start-up time. The start-up time is defined by the SUT fuses as described in “System Clock  
and Clock Options” on page 27. If the level is sampled twice by the Watchdog Oscillator clock  
but disappears before the end of the start-up time, the MCU will still wake up, but no interrupt will  
be generated. The required level must be held long enough for the MCU to complete the wake  
up to trigger the level interrupt.  
10.0.1  
EICRA - External Interrupt Control Register A  
Bit  
7
6
5
4
3
2
1
0
-
-
ISC21  
R/W  
0
ISC20  
R/W  
0
ISC11  
R/W  
0
ISC10  
R/W  
0
ISC01  
R/W  
0
ISC00  
R/W  
0
EICRA  
Read/Write  
Initial Value  
R
0
R
0
• Bits 7..0 – ISC21, ISC20 – ISC01, ISC00: External Interrupt 2 - 0 Sense Control Bits  
The External Interrupts 3 - 0 are activated by the external pins INT2:0 if the SREG I-flag and the  
corresponding interrupt mask in the EIMSK is set. The level and edges on the external pins that  
activate the interrupts are defined in Table 10-1. Edges on INT3..INT0 are registered asynchro-  
nously.The value on the INT2:0 pins are sampled before detecting edges. If edge or toggle  
interrupt is selected, pulses that last longer than one clock period will generate an interrupt.  
Shorter pulses are not guaranteed to generate an interrupt. Observe that CPU clock frequency  
can be lower than the XTAL frequency if the XTAL divider is enabled. If low level interrupt is  
selected, the low level must be held until the completion of the currently executing instruction to  
generate an interrupt. If enabled, a level triggered interrupt will generate an interrupt request as  
long as the pin is held low.  
Table 10-1.  
Interrupt sense Ccntrol (1)  
ISCn0 Description  
.
ISCn1  
0
0
1
1
0
1
0
1
The low level of INTn generates an interrupt request  
Any logical change on INTn generates an interrupt request  
The falling edge between two samples of INTn generates an interrupt request  
The rising edge between two samples of INTn generates an interrupt request  
83  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
Note:  
1. n = 3, 2, 1 or 0.  
When changing the ISCn1/ISCn0 bits, the interrupt must be disabled by clearing its Interrupt  
Enable bit in the EIMSK register. Otherwise an interrupt can occur when the bits are changed.  
10.0.2  
EIMSK - External Interrupt Mask Register  
Bit  
7
6
5
4
3
2
1
0
-
-
-
-
-
INT2  
R/W  
0
INT1  
R/W  
0
IINT0  
R/W  
0
EIMSK  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
• Bits 2..0 – INT2 – INT0: External Interrupt Request 3 - 0 Enable  
When an INT2 – INT0 bit is written to one and the I-bit in the Status Register (SREG) is set  
(one), the corresponding external pin interrupt is enabled. The Interrupt Sense Control bits in the  
External Interrupt Control Register – EICRA – defines whether the external interrupt is activated  
on rising or falling edge or level sensed. Activity on any of these pins will trigger an interrupt  
request even if the pin is enabled as an output. This provides a way of generating a software  
interrupt.  
10.0.3  
EIFR - External Interrupt Flag Register  
Bit  
7
6
5
4
3
2
1
0
-
-
-
-
-
INTF2  
R/W  
0
INTF1  
R/W  
0
IINTF0  
R/W  
0
EIFR  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
• Bits 2..0 – INTF2 - INTF0: External Interrupt Flags 3 - 0  
When an edge or logic change on the INT2:0 pin triggers an interrupt request, INTF2:0 becomes  
set (one). If the I-bit in SREG and the corresponding interrupt enable bit, INT2:0 in EIMSK, are  
set (one), the MCU will jump to the interrupt vector. The flag is cleared when the interrupt routine  
is executed. Alternatively, the flag can be cleared by writing a logical one to it. These flags are  
always cleared when INT2:0 are configured as level interrupt.  
84  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
11. Reduced 16-bit Timer/Counter1  
The 16-bit Timer/Counter unit allows accurate program execution timing (event management).  
The main features are:  
Clear timer on compare match (auto reload)  
One input capture unit  
Input capture noise canceler  
External event counter  
Two independent interrupt sources (TOV1, ICF1)  
11.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, that is, TCNT1 for accessing Timer/Counter1 counter value and so on.  
A simplified block diagram of the 16-bit Timer/Counter is shown in Figure 11-1 on page 86. For  
the actual placement of I/O pins, refer to Table 2-2 on page 6. CPU accessible I/O Registers,  
including I/O bits and I/O pins, are shown in bold. The device-specific I/O Register and bit loca-  
tions are listed in the “16-bit Timer/Counter Register Description” on page 97.  
The PRTIM1 bit in “Power Reduction Register” on page 46 must be written to zero to enable  
Timer/Counter1 module.  
85  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Figure 11-1. 16-bit timer/counter block diagram (1)  
.
Count  
TOVn  
(Int.Req.)  
Clear  
Control Logic  
Clock Select  
clkTn  
Edge  
Detector  
Tn  
TOP  
BOTTOM  
(Ckio )  
Timer/Counter  
TCNTn  
=
= 0  
Fixed  
TOP  
Values  
( From Analog  
Comparator Ouput )  
ICFn (Int.Req.)  
Edge  
Detector  
Noise  
Canceler  
ICPn  
ICRn  
AC1ICE  
TCCRnB  
Note:  
1. Refer to Table 2-1 on page 5 for Timer/Counter1 pin placement and description.  
11.1.1  
Registers  
The Timer/Counter (TCNT1), 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 “Accessing 16-bit Registers” on page 87. The Timer/Counter Control  
Registers (TCCR1A/B) are 8-bit registers and have no CPU access restrictions. Interrupt  
requests (abbreviated to Int.Req. in Figure 11-1) 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 Figure 11-1.  
The Timer/Counter can be clocked internally, 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 incre-  
ment (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 (clk ).  
1
T
The Input Capture Register can capture the Timer/Counter value at a given external (edge trig-  
gered) event on either the Input Capture pin (ICP1). The Input Capture unit includes a digital  
filtering unit (Noise Canceler) for reducing the chance of capturing noise spikes.  
86  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
The TOP value, or maximum Timer/Counter value, can in some modes of operation be defined  
by the ICR1 Register, or by a set of fixed values.  
11.1.2  
Definitions  
The following definitions are used extensively throughout the section:  
BOTTOM  
MAX  
The counter reaches the BOTTOM when it becomes 0x0000.  
The counter reaches its MAXimum when it becomes 0xFFFF (decimal 65535).  
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 ICR1 Register. The assignment is dependent of  
the mode of operation.  
TOP  
11.2 Accessing 16-bit Registers  
The TCNT1, and ICR1 are 16-bit registers that can be accessed by the AVR CPU via the 8-bit  
data bus. The 16-bit register must be byte accessed using two read or write operations. Each  
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.  
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.  
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 ICR1 Registers. Note that when using “C”, the compiler handles the 16-bit access.  
87  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Assembly code examples (1)  
...  
; Set TCNT1 to 0x01FF  
ldir17,0x01  
ldir16,0xFF  
outTCNT1H,r17  
outTCNT1L,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 Regis-  
ters, 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.  
88  
7734Q–AVR–02/12  
 
AT90PWM81/161  
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  
outSREG,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.  
89  
7734Q–AVR–02/12  
 
AT90PWM81/161  
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  
outTCNT1H,r17  
outTCNT1L,r16  
; Restore global interrupt flag  
outSREG,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 writ-  
ten to TCNT1.  
11.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.  
11.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).  
90  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
11.3.1  
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 11-2  
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/clkT pulse for each positive (CSn2:0 = 7) or negative  
0
(CSn2:0 = 6) edge it detects.  
Figure 11-2. T1/T0 pin sampling.  
Tn_sync  
(To Clock  
Tn  
D
Q
D
Q
D
Q
Select Logic)  
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 sys-  
tem 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 fre-  
quency (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.  
11.4 Counter Unit  
The main part of the 16-bit Timer/Counter is the programmable 16-bit bi-directional counter unit.  
Figure 11-3 shows a block diagram of the counter and its surroundings.  
Figure 11-3. Counter unit block diagram.  
DATA BUS (8-bit)  
TOVn  
(Int.Req.)  
TEMP (8-bit)  
Clock Select  
Count  
Clear  
Edge  
Detector  
Tn  
TCNTnH (8-bit)  
TCNTnL (8-bit)  
clkTn  
Control Logic  
TCNTn (16-bit Counter)  
( Ckio )  
TOP  
BOTTOM  
91  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
Signal description (internal signals):  
Count  
Clear  
Increment TCNT1 by 1.  
Clear TCNT1 (set all bits to zero).  
Timer/Counter clock.  
clkT  
1
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) con-  
taining 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 (clk ). The clk 1 can be generated from an external or internal clock source,  
1
T
T
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 clkT is present or not. A CPU write overrides (has priority over) all counter clear or  
1
count operations.  
The counting sequence is determined by the setting of the Waveform Generation mode bit  
(WGM13) located in the Timer/Counter Control Registers B ( TCCR1B).  
The Timer/Counter Overflow Flag (TOV1) is set according to the mode of operation selected by  
the WGM13 bit. TOV1 can be used for generating a CPU interrupt.  
11.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 mul-  
tiple 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 sig-  
nal 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 11-4 on page 93. 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.  
92  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Figure 11-4. Input capture unit block diagram.  
DATA BUS (8-bit)  
TEMP (8-bit)  
ICRnH (8-bit)  
ICRnL (8-bit)  
TCNTnH (8-bit)  
TCNTnL (8-bit)  
ICRn (16-bit Register)  
TCNTn (16-bit Counter)  
WRITE  
ICNC  
ICES  
Noise  
Canceler  
Edge  
Detector  
ICFn (Int.Req.)  
ICPnA  
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 Genera-  
tion mode (WGM13) 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 “Accessing 16-bit Registers”  
on page 87.  
11.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 (AC1ICE) bit in the Analog Comparator Extended Control Register  
(AC1ECON). Be aware that changing trigger source can trigger a capture. The Input Capture  
Flag must therefore be cleared after the change.  
93  
7734Q–AVR–02/12  
AT90PWM81/161  
Both the Input Capture pin (ICP1) and the Analog Comparator 1 output (AC1O) inputs are sam-  
pled using the same technique as for the T1 pin (see Figure 11-2 on page 91). 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/Coun-  
ter 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.  
11.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 addi-  
tional 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.  
11.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 inter-  
rupt 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).  
11.6 Modes of Operation  
The mode of operation, that is, the behavior of the Timer/Counter and the Output Compare pins,  
is defined by the Waveform Generation mode (WGM1).  
For detailed timing information refer to “Timer/Counter Timing Diagrams” on page 95.  
11.6.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  
94  
7734Q–AVR–02/12  
 
AT90PWM81/161  
interrupt that automatically clears the TOV1 Flag, the timer resolution can be increased by soft-  
ware. 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 must be used to extend the resolution  
for the capture unit.  
11.6.2  
Clear Timer on Compare Match (CTC) Mode  
In Clear Timer on Compare or CTC mode (WGM13 = 1, previous mode 12), the ICR1 Register  
are used to manipulate the counter resolution. In CTC mode the counter is cleared to zero when  
the counter value (TCNT1) matches the ICR1 . The ICR1 define the top value for the counter,  
hence also its resolution. This mode allows greater control of the compare match output fre-  
quency. It also simplifies the operation of counting external events.  
The timing diagram for the CTC mode is shown in Figure 11-5. The counter value (TCNT1)  
increases until a compare match occurs with ICR1, and then counter (TCNT1) is cleared.  
Figure 11-5. CTC mode, timing diagram.  
ICFn Interrupt Flag Set  
(Interrupt on TOP)  
TCNTn  
An interrupt can be generated at each time the counter value reaches the TOP value by using  
the ICF1 Flag . 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 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.  
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.  
11.7 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.  
Figure 11-6 on page 96 shows the count sequence close to TOP in various modes.  
95  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Figure 11-6. Timer/counter timing diagram, no prescaling.  
clkI/O  
clkTn  
(clkI/O/1)  
TCNTn  
TOP - 1  
TOP  
BOTTOM  
BOTTOM + 1  
ICFn  
Figure 11-7 shows the count sequence close to MAX in various modes.  
Figure 11-7. Timer/counter timing diagram, no prescaling.  
clkI/O  
clkTn  
(clkI/O/1)  
TCNTn  
BOTTOM  
BOTTOM + 1  
MAX-1  
MAX  
TOVn  
96  
7734Q–AVR–02/12  
 
AT90PWM81/161  
11.8 16-bit Timer/Counter Register Description  
11.8.1  
TCCR1B - Timer/Counter1 Control Register B  
Bit  
7
6
5
-
4
3
-
2
1
0
ICNC1  
R/W  
0
ICES1  
R/W  
0
WGM13  
R/W  
0
CS12  
R/W  
0
CS11  
R/W  
0
CS10  
R/W  
0
TCCR1B  
Read/Write  
Initial Value  
R
0
R
0
• 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 Cap-  
ture function is disabled.  
• Bit 5 – Reserved  
• Bit 4 – WGM13: Waveform Generation Mode  
See Table 11-1 for the modes definition  
Table 11-1. Waveform generation mode bit description.  
Timer/counter mode of  
operation  
TOV1 flag  
set on  
Mode  
0
WGM13  
TOP  
0
1
Normal  
CTC  
0xFFFF  
ICR1  
MAX  
MAX  
12  
• Bit 3 – Reserved  
• Bit 2:0 – CS12:0: Clock Select  
The three Clock Select bits select the clock source to be used by the Timer/Counter, see  
Table 11-2.  
Table 11-2. Clock select bit description.  
CS12  
CS11  
CS10  
Description  
0
0
0
0
0
1
0
1
0
No clock source (Timer/Counter stopped)  
clkI/O/1 (No prescaling)  
Reserved  
97  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
Table 11-2. Clock select bit description. (Continued)  
CS12  
CS11  
CS10  
Description  
Reserved  
Reserved  
Reserved  
0
1
1
1
1
1
0
0
1
1
1
0
1
0
1
External clock source on T1 pin. Clock on falling edge  
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.  
11.8.2  
TCNT1H and TCNT1L - Timer/Counter1  
Bit  
7
6
5
4
3
2
1
0
TCNT1[15:8]  
TCNT1[7:0]  
TCNT1H  
TCNT1L  
Read/Write  
Initial Value  
R/W  
0
R/W  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
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 “Accessing 16-bit  
Registers” on page 87.  
Modifying the counter (TCNT1) while the counter is running introduces a risk of missing a com-  
pare 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.  
11.8.3  
ICR1H and ICR1L - Input Capture Register 1  
Bit  
7
6
5
4
3
2
1
0
ICR1[15:8]  
ICR1[7:0]  
R/W  
ICR1H  
ICR1L  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
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 “Accessing 16-bit Registers” on page 87.  
98  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
11.8.4  
TIMSK1 - Timer/Counter1 Interrupt Mask Register  
Bit  
7
R
0
6
R
0
5
4
R
0
3
R
0
2
1
0
ICIE1  
R/W  
0
TOIE1  
R/W  
0
TIMSK1  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
• Bit 7, 6 – Res: Reserved Bits  
These bits are unused bits in the AT90PWM81/161, 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 Table 8-1 on page 62) is executed when the ICF1 Flag, located in TIFR1, is set.  
• Bit 4, 3, 2,1 – Res: Reserved Bits  
These bits are unused bits in the AT90PWM81/161, and will always read as zero.  
• 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 Table 8-1 on page 62) is executed when the TOV1 Flag, located in TIFR1, is set.  
11.8.5  
TIFR1 - Timer/Counter1 Interrupt Flag Register  
Bit  
7
6
5
4
R
0
3
R
0
2
1
0
ICF1  
R/W  
0
TOV1  
R/W  
0
TIFR1  
Read/Write  
Initial Value  
R
0
R
0
R/W  
0
R/W  
0
• Bit 7, 6 – Res: Reserved Bits  
These bits are unused bits in the AT90PWM81/161, 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 coun-  
ter 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, 2,1 – Res: Reserved Bits  
• Bit 0 – TOV1: Timer/Counter1, Overflow Flag  
The setting of this flag is dependent of the WG.  
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.  
99  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
12. Power Stage Controller – (PSCn)  
The Power Stage Controller is a high performance waveform controller.  
The Atmel AT90PWM81 includes one PSC2 block.  
12.1 Features  
PWM waveform generation function (two complementary programmable outputs)  
Dead time control  
Standard mode up to 12 bit resolution  
Frequency and pulse width resolution enhancement mode (12 + 4 bits)  
Frequency up to 64Mhz  
Conditional waveform on external events (zero crossing, current sensing ...)  
All on chip PSC synchronization  
ADC synchronization with digital delay register  
Input blanking  
Overload protection function  
Abnormality protection function, emergency input to force all outputs to low level  
Center aligned and edge aligned modes synchronization  
Fast emergency stop by hardware  
12.2 Overview  
Many register and bit references in this section are written in general form.  
• A lower case “n” replaces the PSC number, in this case 2. However, when using the register  
or bit defines in a program, the precise form must be used, that is, PSOC2 for accessing PSC  
2 Synchro and Output Configuration register and so on.  
• A lower case “x” replaces the PSC part , in this case A or B. However, when using the register  
or bit defines in a program, the precise form must be used, that is, PFRC2A for accessing  
PSC n Fault/Retrigger 2 A Control register and so on.  
The purpose of a Power Stage Controller (PSC) is to control power modules on a board. It has  
two outputs on PSCn and four outputs on PSC2.  
These outputs can be used in various ways:  
• “Two Outputs” to drive a half bridge (lighting, DC motor ...)  
• “One Output” to drive single power transistor (DC/DC converter, PFC, DC motor ...)  
• “Four Outputs” in the case of PSC2 to drive a full bridge (lighting, DC motor ...)  
Each PSC has two inputs the purpose of which is to provide means to act directly on the gener-  
ated waveforms:  
• Current sensing regulation  
• Zero crossing retriggering  
• Demagnetization retriggering  
• Fault input  
The PSC can be chained and synchronized to provide a configuration to drive three half bridges.  
Thanks to this feature it is possible to generate a three phase waveforms for applications such  
as Asynchronous or BLDC motor drive.  
100  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
12.3 PSC Description  
Figure 12-1. Power Stage Controller 0 or 1 block diagram.  
PSC Counter  
Waveform  
Generator B  
PSCOUTn1  
=
OCRnRB  
PSC Input  
Module B  
PSCn Input B  
=
OCRnSB  
Par t B  
PSC Input  
Module A  
PSCn Input A  
=
OCRnRA  
PSCOUTn0  
Waveform  
Generator A  
=
OCRnSA  
Par t A  
PICRn  
PCNFEn  
PCNFn  
PASDLYn  
PFRCnB  
PFRCnA  
PCTLn  
PSOCn  
Note:  
n = 0, 1.  
The principle of the PSC is based on the use of a counter (PSC counter). This counter is able to  
count up and count down from and to values stored in registers according to the selected run-  
ning mode.  
The PSC is seen as two symmetrical entities. One part named part A which generates the output  
PSCOUTn0 and the second one named part B which generates the PSCOUTn1 output.  
Each part A or B has its own PSC Input Module to manage selected input.  
101  
7734Q–AVR–02/12  
 
AT90PWM81/161  
12.3.1  
PSC2 Distinctive Feature  
Figure 12-2. PSC2 versus PSC1&PSC0 block diagram.  
PSC Counter  
PSCOUTn3  
PSCOUTn1  
POS23  
Waveform  
Generator B  
=
OCRnRB  
PSC Input  
Module B  
PSCn Input B  
=
OCRnSB  
Output  
Matrix  
Part A  
PSC Input  
Module A  
=
PSCn Input A  
OCRnRA  
PSCOUTn2  
PSCOUTn0  
POS22  
Waveform  
Generator A  
=
OCRnSA  
Part B  
PICRn  
PCNFEn  
PCNFn  
PASDLYn  
PFRCnB  
PFRCnA  
POM2(PSC2 only)  
PSOCn  
PCTLn  
Note:  
n = 2.  
PSC2 has two supplementary outputs PSCOUT22 and PSCOUT23. Thanks to a first selector  
PSCOUT22 can duplicate PSCOUT20 or PSCOUT21. Thanks to a second selector PSCOUT23  
can duplicate PSCOUT20 or PSCOUT21.  
The Output Matrix is a kind of 2 × 2 look up table which gives the possibility to program the out-  
put values according to a PSC sequence (see “Output Matrix” on page 129).  
12.3.2  
Output Polarity  
The polarity “active high” or “active low” of the PSC outputs is programmable. All the timing dia-  
grams in the following examples are given in the “active high” polarity.  
102  
7734Q–AVR–02/12  
AT90PWM81/161  
12.4 Signal Description  
Figure 12-3. PSC external block view.  
CLK  
PLL  
CLK  
I/O  
SYnIn  
StopOut  
12  
12  
12  
12  
4
OCRnRB[11:0]  
OCRnSB[11:0]  
OCRnRA[11:0]  
OCRnSA[11:0]  
OCRnRB[15:12]  
PSCOUTn0  
PSCOUTn1  
PSCOUTn2  
PSCOUTn3  
(1)  
(1)  
(Flank Width  
Modulation)  
12  
2
2
PICRn[11:0]  
PSCINn  
IRQ PSCn  
Analog  
Comparator  
n Output  
StopIn SYnOut PSCnASY  
Note:  
1. available only for PSC2.  
2. n = 0, 1 or 2.  
12.4.1  
Input Description  
Table 12-1. Internal inputs.  
Name  
Description  
Type width  
Register 12 bits  
Register 12 bits  
Register 12 bits  
Register 12 bits  
OCRnRB[11:0]  
OCRnSB[11:0]  
OCRnRA[11:0]  
OCRnSA[11:0]  
Compare value which reset signal on Part B (PSCOUTn1)  
Compare value which set signal on Part B (PSCOUTn1)  
Compare value which reset signal on Part A (PSCOUTn0)  
Compare value which set signal on Part A (PSCOUTn0)  
Frequency resolution enhancement value (flank width  
modulation)  
OCRnRB[15:12]  
Register 4 bits  
CLK I/O  
CLK PLL  
SYnIn  
Clock input from I/O clock  
Signal  
Signal  
Signal  
Signal  
Clock input from PLL  
Synchronization in (from adjacent PSC) (1)  
StopIn  
Stop input (for synchronized mode)  
Note:  
1. See Figure 12-41 on page 132  
103  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Table 12-2. Block inputs.  
Name Description  
PSCINn  
Type width  
Signal  
Input 0 used for Retrigger or Fault functions  
Input 1 used for Retrigger or Fault functions  
Input 2 used for Retrigger or Fault functions  
Input 3 used for Retrigger or Fault functions  
from 1st A C  
PSCINnA  
Signal  
Signal  
from 2nd A C  
Signal  
12.4.2  
Output Description  
Table 12-3. Block outputs.  
Name  
PSCOUTn0  
PSCOUTn1  
Description  
Type width  
Signal  
PSC n Output 0 (from part A of PSC)  
PSC n Output 1 (from part B of PSC)  
Signal  
PSCOUTn2  
(PSC2 only)  
PSC n Output 2 (from part A or part B of PSC)  
PSC n Output 3 (from part A or part B of PSC)  
Signal  
Signal  
PSCOUTn3  
(PSC2 only)  
Table 12-4. Internal outputs.  
Name Description  
SYnOut  
Type width  
Signal  
Synchronization Output (1)  
PICRn  
[11:0]  
PSC n Input Capture Register  
Counter value at retriggering event  
Register  
12 bits  
PSC Interrupt Request : three sources, overflow, fault, and  
input capture  
IRQPSCn  
Signal  
Signal  
PSCnASY  
StopOut  
ADC Synchronization (+ Amplifier Syncho.) (2)  
Stop Output (for synchronized mode)  
Note:  
1. See Figure 12-41 on page 132  
2. See “Analog Synchronization” on page 131  
12.5 Functional Description  
12.5.1  
Waveform Cycles  
The waveform generated by PSC can be described as a sequence of two waveforms.  
The first waveform is relative to PSCOUTn0 output and part A of PSC. The part of this waveform  
is sub-cycle A in Figure 12-4 on page 105.  
The second waveform is relative to PSCOUTn1 output and part B of PSC. The part of this wave-  
form is sub-cycle B in Figure 12-4 on page 105.  
The complete waveform is ended with the end of sub-cycle B. It means at the end of waveform  
B.  
104  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
Figure 12-4. Cycle presentation in 1, 2, and 4 ramp mode.  
PSC Cycle  
Sub-Cycle A  
Sub-Cycle B  
4 Ramp Mode  
Ramp A0  
Ramp A1  
Ramp B0  
Ramp B1  
2 Ramp Mode  
Ramp A  
Ramp B  
1 Ramp Mode  
UPDATE  
Figure 12-5. Cycle presentation in centered mode.  
PSC Cycle  
Centered Mode  
UPDATE  
Ramps illustrate the output of the PSC counter included in the waveform generators. Centered  
Mode is like a one ramp mode which count down up and down.  
Notice that the update of a new set of values is done regardless of ramp Mode at the top of the  
last ramp.  
12.5.2  
Running Mode Description  
Waveforms and length of output signals are determined by Time Parameters (DT0, OT0, DT1,  
OT1) and by the running mode. Four modes are possible:  
– Four Ramp mode  
Two Ramp mode  
– One Ramp mode  
– Center Aligned mode  
12.5.2.1  
Four Ramp Mode  
In Four Ramp mode, each time in a cycle has its own definition.  
105  
7734Q–AVR–02/12  
AT90PWM81/161  
Figure 12-6. PSCn0 & PSCn1 basic waveforms in Four Ramp mode.  
OCRnRA  
PSC Counter  
OCRnSA  
OCRnRB  
OCRnSB  
0
0
On-Time 0  
On-Time 1  
PSCOUTn0  
PSCOUTn1  
Dead-Time 0  
Dead-Time 1  
PSC Cycle  
The input clock of PSC is given by CLKPSC.  
PSCOUTn0 and PSCOUTn1 signals are defined by On-Time 0, Dead-Time 0, On-Time 1 and  
Dead-Time 1 values with:  
On-Time 0 = OCRnRAH/L × 1/Fclkpsc  
On-Time 1 = OCRnRBH/L × 1/Fclkpsc  
Dead-Time 0 = (OCRnSAH/L + 2) × 1/Fclkpsc  
Dead-Time 1 = (OCRnSBH/L + 2) × 1/Fclkpsc  
Note:  
Minimal value for Dead-Time 0 and Dead-Time 1 = 2 × 1/Fclkpsc.  
12.5.2.2  
Two Ramp Mode  
In Two Ramp mode, the whole cycle is divided in two moments:  
One moment for PSCn0 description with OT0 which gives the time of the whole moment.  
One moment for PSCn1 description with OT1 which gives the time of the whole moment.  
106  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Figure 12-7. PSCn0 & PSCn1 basic waveforms in Two Ramp mode.  
OCRnRA  
OCRnRB  
PSC Counter  
OCRnSA  
OCRnSB  
0
0
On-Time 0  
On-Time 1  
PSCOUTn0  
PSCOUTn1  
Dead-Time 0  
Dead-Time 1  
PSC Cycle  
PSCOUTn0 and PSCOUTn1 signals are defined by On-Time 0, Dead-Time 0, On-Time 1 and  
Dead-Time 1 values with:  
On-Time 0 = (OCRnRAH/L - OCRnSAH/L) × 1/Fclkpsc  
On-Time 1 = (OCRnRBH/L - OCRnSBH/L) × 1/Fclkpsc  
Dead-Time 0 = (OCRnSAH/L + 1) × 1/Fclkpsc  
Dead-Time 1 = (OCRnSBH/L + 1) × 1/Fclkpsc  
Note:  
Minimal value for Dead-Time 0 and Dead-Time 1 = 1/Fclkpsc.  
12.5.2.3  
One Ramp Mode  
In One Ramp mode, PSCOUTn0 and PSCOUTn1 outputs can overlap each other.  
107  
7734Q–AVR–02/12  
AT90PWM81/161  
Figure 12-8. PSCn0 & PSCn1 basic waveforms in One Ramp mode.  
OCRnRB  
OCRnSB  
OCRnRA  
PSC Counter  
OCRnSA  
0
On-Time 0  
On-Time 1  
PSCOUTn0  
PSCOUTn1  
Dead-Time 0  
Dead-Time 1  
PSC Cycle  
On-Time 0 = (OCRnRAH/L - OCRnSAH/L) × 1/Fclkpsc  
On-Time 1 = (OCRnRBH/L - OCRnSBH/L) × 1/Fclkpsc  
Dead-Time 0 = (OCRnSAH/L + 1) × 1/Fclkpsc  
Dead-Time 1 = (OCRnSBH/L - OCRnRAH/L) × 1/Fclkpsc  
Note:  
Minimal value for Dead-Time 0 = 1/Fclkpsc.  
12.5.2.4  
Center Aligned Mode  
In center aligned mode, the center of PSCn00 and PSCn01 signals are centered.  
108  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Figure 12-9. PSCn0 & PSCn1 basic waveforms in Center Aligned mode.  
PSC Counter  
OCRnRB  
OCRnSB  
OCRnSA  
0
On-Time 0  
On-Time 1  
On-Time 1  
PSCOUTn0  
PSCOUTn1  
Dead-Time  
Dead-Time  
PSC Cycle  
On-Time 0 = 2 × OCRnSAH/L × 1/Fclkpsc  
On-Time 1 = 2 × (OCRnRBH/L - OCRnSBH/L + 1) × 1/Fclkpsc  
Dead-Time = (OCRnSBH/L - OCRnSAH/L) × 1/Fclkpsc  
PSC Cycle = 2 × (OCRnRBH/L + 1) × 1/Fclkpsc  
Note:  
Minimal value for PSC Cycle = 2 × 1/Fclkpsc.  
OCRnRAH/L is not used to control PSC Output waveform timing. Nevertheless, it can be useful  
to adjust ADC synchronization (see “Analog Synchronization” on page 131).  
Figure 12-10. Run and stop mechanism in Centered mode.  
OCRnRB  
OCRnSB  
OCRnSA  
PSC Counter  
Run  
PSCOUTn0  
PSCOUTn1  
Note:  
See “PCTL2 - PSC 2 Control Register” on page 140 (or PCTL1 or PCTL2).  
109  
7734Q–AVR–02/12  
AT90PWM81/161  
12.5.3  
Fifty Percent Waveform Configuration  
When PSCOUTn0 and PSCOUTn1 have the same characteristics, it’s possible to configure the  
PSC in a Fifty Percent mode. When the PSC is in this configuration, it duplicates the OCRn-  
SBH/L and OCRnRBH/L registers in OCRnSAH/L and OCRnRAH/L registers. So it is not  
necessary to program OCRnSAH/L and OCRnRAH/L registers.  
12.6 Update of Values  
The update of PSC waveform registers are done in the following way:  
• Immediately when the PSC is stopped  
• At the PSC end of cycle when the PSC is running  
• At the PSC end of cycle following the required condition when LOCK or AUTOLOCK modes  
are used  
To avoid asynchronous and incoherent values in a cycle, if an update of one of several values is  
necessary, all values can be updated at the same time at the end of the cycle by the PSC. The  
new set of values is calculated by software and the update is initiated by software.  
Figure 12-11. Update at the end of complete PSC cycle.  
Regulation Loop  
Calculation  
Writting in  
PSC Registers  
Request for  
an Update  
Software  
Cycle  
With Set i  
Cycle  
With Set i  
Cycle  
With Set i  
Cycle  
With Set i  
PSC  
Cycle  
With Set j  
End of Cycle  
The software can stop the cycle before the end to update the values and restart a new PSC  
cycle.  
12.6.1  
Value Update Synchronization  
New timing values or PSC output configuration can be written during the PSC cycle. Thanks to  
LOCK and AUTOLOCK configuration bits, the new whole set of values can be taken into  
account with the following conditions:  
• When AUTOLOCK configuration is selected, the update of the PSC internal registers will be  
done at the end of the PSC cycle following a write in the Output Compare Register RB. The  
AUTOLOCK configuration bit is taken into account at the end of the first PSC cycle.  
• When LOCK configuration bit is set, there is no update. The update of the PSC internal  
registers will be done at the end of the PSC cycle if the LOCK bit is released to zero.  
The registers which update is synchronized thanks to LOCK and AUTOLOCK are PSOCn,  
POM2, OCRnSAH/L, OCRnRAH/L, OCRnSBH/L and OCRnRBH/L.  
See these register’s description starting on page 135.  
When set, AUTOLOCK configuration bit prevails over LOCK configuration bit.  
See “PCNF2 - PSC 2 Configuration Register” on page 136.  
110  
7734Q–AVR–02/12  
 
AT90PWM81/161  
12.7 Enhanced Resolution  
Lamp Ballast applications need an enhanced resolution down to 50Hz. The method to improve  
the normal resolution is based on Flank Width Modulation (also called Fractional Divider).  
Cycles are grouped into frames of 16 cycles. Cycles are modulated by a sequence given by the  
fractional divider number. The resulting output frequency is the average of the frequencies in the  
frame. The fractional divider (d) is given by OCRnRB[15:12].  
The PSC output period is directly equal to the PSCOUTn0 On Time + Dead Time (OT0+DT0)  
and PSCOUTn1 On Time + Dead Time (OT1+DT1) values. These values are 12 bits numbers.  
The frequency adjustment can only be done in steps like the dedicated counters. The step width  
is defined as the frequency difference between two neighboring PSC frequencies.  
It is possible to apply the Flank Width Modulation (FWM) on RB, RB+RA, SB, SB+SA. The  
selection is done bit the bits PBFMn0 and PBFMn.  
According to the ramp mode and the enhanced resolution mode (defined by PBFMn1:0), the fre-  
quency difference Df can take three different values:  
Δf = 0  
fPSC fPSC  
Δf1 = f1 f2 = ---------- ----------- = fPSC  
k + 1  
1
-------------------  
×
×
k(k + 1)  
k
fPSC fPSC  
Δf2 = f1 f2 = ---------- ----------- = fPSC  
k + 2  
2
-------------------  
k(k + 2)  
k
with k is the number of CLKPSC period in a PSC cycle and is given by the following formula:  
fPSC  
k = ----------  
fOP  
with fOP is the output operating frequency.  
Example, in normal mode, with maximum operating frequency 160kHz and fPLL = 64Mhz, k  
equals 400. The resulting resolution is Delta F equals 64MHz / 400 / 401 = 400Hz.  
In enhanced mode, the output frequency is the average of the frame formed by the 16 consecu-  
tive cycles.  
fb1 and fb2 are two neighboring base frequencies.  
16 d  
16  
d
16  
--------------  
-----  
fAVERAGE  
=
× fb1  
+
× fb2  
111  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Then the frequency resolution is divided by 16. In the example above, the resolution equals  
25Hz.  
fPLL  
fPLL  
16 d  
16  
d
-------------- ---------- ----- -----------  
fAVERAGE  
=
×
+
×
k
16 k + 1  
According to the ramp mode and the enhanced resolution mode (defined by PBFMn1:0), the  
average frequency deviation Df can take three different values:  
Δf(average) = 0  
d
-------------------------  
Δf1(average) = fPSC  
×
16k(k + 1)  
d
----------------------  
Δf2(average) = fPSC  
×
8k(k + 2)  
These values are applied according to the running mode and the enhanced resolution mode as  
per Table 12-5;  
It must be noted that, in one and two ramps modes, it is possible to apply the FWM only on  
pulse width while keeping a constant frequency.  
Table 12-5. Frequency deviation with Flank Width Modulation.  
PBFMn1:0  
00  
01  
RB+RA  
Df2  
10  
SB  
Df1  
0 (1)  
0
11  
SB+SA  
Df2  
0
Running mode  
Four Ramps  
RB  
Df1  
Df1  
Df1  
Df2  
Two Ramps  
One Ramp  
Df2  
Df1  
0
Center aligned  
Df2  
Df2  
Df2  
Notes: 1. The modulation is on the pulse width.  
12.7.1  
Frequency distribution  
The frequency modulation is done by switching two frequencies in a 16 consecutive cycle frame.  
These two frequencies are fb1 and fb2 where fb1 is the nearest base frequency above the wanted  
frequency and fb2 is the nearest base frequency below the wanted frequency. The number of fb1  
in the frame is (d-16) and the number of fb2 is d. The fb1 and fb2 frequencies are evenly distrib-  
uted in the frame according to a predefined pattern. This pattern can be as given in the following  
table or by any other implementation which give an equivalent evenly distribution.  
At the end of the 15th cycle (numbered 14 on Table 12-6 on page 113) an interrupt can be gen-  
erated. This is the case if the bit PEOEPEn (PSC n End Of Enhanced Cycle Interrupt Enable) is  
set. This allows:  
To modify the modulation only on a new enhanced cycle start  
To extend the enhanced modulation accuracy by software  
112  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Table 12-6. Distribution of fb2 in the modulated frame.  
Distribution of fb2 in the modulated frame  
PWM - cycle  
Fractional  
0
1
2
3
4
5
6
7
8
9
10 11 12 13 14 15  
divider (d)  
0
1
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
2
X
X
X
X
X
X
X
X
X
X
X
X
X
X
3
X
X
X
X
X
X
X
X
X
X
X
X
X
4
X
X
5
X
X
X
X
X
X
X
X
X
X
X
6
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
7
X
X
X
X
X
X
X
X
X
8
X
X
X
X
X
X
X
X
9
X
X
X
X
X
X
X
10  
11  
12  
13  
14  
15  
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
While ‘X’ in the table, fb2 prime to fb1 in cycle corresponding cycle.  
So for each row, a number of fb2 take place of fb1.  
Figure 12-12. Resulting frequency versus d.  
f
f
b2  
b1  
0
fOP  
d:  
1
2
3
4
5
6
7
8
9 10 11 12 13 14 15  
12.7.2  
Modes of Operation  
12.7.2.1  
Normal Mode  
The simplest mode of operation is the normal mode. See Figure 12-6 on page 106.  
The active time of PSCOUTn0 is given by the OT0 value. The active time of PSCOUTn1 is given  
by the OT1 value. Both of them are 12 bit values. Thanks to DT0 & DT1 to adjust the dead time  
between PSCOUTn0 and PSCOUTn1 active signals.  
113  
7734Q–AVR–02/12  
 
AT90PWM81/161  
The waveform frequency is defined by the following equation:  
f
1
CLK_PSCn  
f
= ----------------------------- = --------------------------------------------------------------------  
PSCn  
PSCnCycle  
(OT0 + OT1 + DT0 + DT1)  
12.7.2.2  
Enhanced Mode  
The Enhanced Mode uses the previously described method to generate a high resolution fre-  
quency. Figure 12-13 gives an example of FWM with PBFMn1:0 = 00.  
Figure 12-13. Enhanced mode, timing diagram.  
DT1  
DT0  
OT0  
DT1  
OT1  
DT0  
DT0  
OT1+1  
OT0  
PSCOUTn0  
PSCOUTn1  
Period  
T2  
T1  
The supplementary step in counting to generate fb2 is added on the PSCn0 signal while needed  
in the frame according to the fractional divider. See Table 12-6 on page 113.  
The waveform frequency is defined by the following equations:  
f
1
CLK_PSCn  
f1  
= ----- = --------------------------------------------------------------------  
PSCn  
T
(OT0 + OT1 + DT0 + DT1)  
1
f
1
CLK_PSCn  
f2  
= ----- = ------------------------------------------------------------------------------  
PSCn  
T
(OT0 + OT1 + DT0 + DT1 + 1)  
2
d
16  
16 d  
16  
-----  
--------------  
fAVERAGE  
=
× f1PSCn  
+
× f2PSCn  
d is the fractional divider factor.  
The FWM can be applied on different locations within the PSC output waveforms as defined per  
Table 12-15 on page 138.  
12.8 PSC Inputs  
Part A or B of PSC has its own system to take into account one PSC n internal input. Each part  
A or B is configured by the PSC n Input A/B Control Register (“PFRCnA - PSC n Input A Control  
Register” on page 141 and “PFRCnB - PSC n Input B Control Register” on page 141) and the  
PSC n Extended Configuration Register (see Section “PCNF2 - PSC 2 Configuration Register”,  
page 136).  
The PSC input module A is shown in Table 12-14 on page 115.  
114  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
According to PSC n Input A Control Register (see “PFRCnA - PSC n Input A Control Register”  
on page 141), PSC n input A can act as a Retrigger or Fault input.  
Each part A or B can be triggered by up to four signals as defined per Table 12-18 on page 139  
and Table 12-19 on page 139.  
Part A of PSC has also a blanking module allowing to cancel unwanted transitions which may  
appear on the PSC n input A during a certain period of time.  
The blanking start is defined by the bits PASDLKn(2:0) as per Table 12-14 on page 138.  
The blanking duration is defined by the register PASDLYn. If the blanking is selected by the cor-  
responding PASDLKn(2:0) bit, all transitions which may appears from the blanking start until a  
time period are ignored.  
Blanking is level sensitive, that is, a pulse started in the blanking window and still at active level  
after the window will generate a valid retriggering event.  
Figure 12-14. PSC input module A.  
PAOCnA  
Input  
Blanking  
0
0
PSCINn  
0
AC2O: Analog  
Comparator  
Output  
PSC n Input A  
0
1
1
0
Digital  
Filter  
1
PSCINnA  
AC3O: Analog  
Comparator  
Output  
PFLTEnA  
1
1
PISELnA1 PISELnA0  
CLK  
PSC  
PASDLY  
OCR SB  
OSR SA  
3
2
1
Blanking Start  
PSC start  
cycle  
Input  
Processing  
(retriggering ...)  
PCAEnA  
=0, 4..7  
No Blanking  
PASDLKn(2:0)  
4
PRFMnA3:0  
PELEVnA /  
PSC Core  
(Counter,  
Waveform  
Generator, ...)  
Output  
Control  
PSCOUTn0  
(PSCOUTn1)  
(PSCOUT22)  
(PSCOUT23)  
CLK  
PSC  
PSC input module B is shown on Table 12-15 on page 116.  
According to PSC n Input B Control Register (see “PFRCnB - PSC n Input B Control Register”  
on page 141), PSC n input B can act as a Retrigger or Fault input.  
115  
7734Q–AVR–02/12  
AT90PWM81/161  
Figure 12-15. PSC input module B.  
PAOCnB  
0
0
0
PSCINn  
AC2O: Analog  
Comparator  
Output  
0
1
1
0
PSC n Input B  
Digital  
Filter  
1
PSCINnA  
PFLTEnB  
CLK  
PSC  
AC3O:Analog  
Comparator  
Output  
1
1
PCAEnB  
Input  
PELEVnB  
Processing  
(retriggering ...)  
4
PISELnB1 PISELnB0  
PRFMnB3:0  
CLK  
PSC  
PSC Core  
(Counter,  
Waveform  
Generator, ...)  
Output  
Control  
PSCOUTn0  
(PSCOUTn1)  
(PSCOUT22)  
(PSCOUT23)  
CLK  
PSC  
12.8.1  
12.8.2  
PSC Retrigger Behavior versus PSC running modes  
In centered mode, Retrigger Inputs have no effect.  
In two ramp or four ramp mode, Retrigger Inputs A or B cause the end of the corresponding  
cycle A or B and the beginning of the following cycle B or A.  
In one ramp mode, Retrigger Inputs A or B reset the current PSC counting to zero.  
Retrigger PSCOUTn0 On External Event  
PSCOUTn0 output can be reset before end of On-Time 0 on the change on PSCn Input A.  
PSCn Input A can be configured to do not act or to act on level or edge modes. The polarity of  
PSCn Input A is configurable thanks to a sense control block. PSCn Input A can be the Output of  
the analog comparator or the PSCINn input.  
As the period of the cycle decreases, the instantaneous frequency of the two outputs increases.  
116  
7734Q–AVR–02/12  
AT90PWM81/161  
Figure 12-16. PSCOUTn0 retrograde by PSCn Input A (edge retriggering).  
On-Time 0  
On-Time 1  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
(falling edge)  
PSCn Input A  
(rising edge)  
Dead-Time 0  
Dead-Time 1  
Note:  
This example is given in “Input Mode 8” in “2 or 4 ramp mode”. See Figure 12-33 on page 126 for  
details.  
Figure 12-17. PSCOUTn0 retriggered by PSCn Input A (level acting).  
On-Time 0  
On-Time 1  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
(high level)  
PSCn Input A  
(low level)  
Dead-Time 0  
Dead-Time 1  
Note:  
This example is given in “Input Mode 1” in “2 or 4 ramp mode”. See Figure 12-22 on page 121 for  
details.  
12.8.3  
Retrigger PSCOUTn1 On External Event  
PSCOUTn1 output can be reset before end of On-Time 1 on the change on PSCn Input B. The  
polarity of PSCn Input B is configurable thanks to a sense control block. PSCn Input B can be  
configured to do not act or to act on level or edge modes. PSCn Input B can be the Output of the  
analog comparator or the PSCINn input.  
As the period of the cycle decreases, the instantaneous frequency of the two outputs increases.  
117  
7734Q–AVR–02/12  
AT90PWM81/161  
Figure 12-18. PSCOUTn1 retriggered by PSCn Input B (edge retriggering).  
On-Time 0  
On-Time 1  
PSCOUTn0  
PSCOUTn1  
PSCn Input B  
(falling edge)  
PSCn Input B  
(rising edge)  
Dead-Time 0  
Dead-Time 1  
Dead-Time 0  
Note:  
This example is given in “Input Mode 8” in “2 or 4 ramp mode”. See Figure 12-33 on page 126 for  
details.  
Figure 12-19. PSCOUTn1 retriggered by PSCn Input B (level acting).  
On-Time 0  
On-Time 1  
PSCOUTn0  
PSCOUTn1  
PSCn Input B  
(high level)  
PSCn Input B  
(low level)  
Dead-Time 0  
Dead-Time 1  
Dead-Time 0  
Note:  
This example is given in “Input Mode 1” in “2 or 4 ramp mode”. See Figure 12-22 on page 121 for  
details.  
12.8.3.1  
Burst Generation  
Note:  
On level mode, it’s possible to use PSC to generate burst by using Input Mode 3 or Mode 4 (see  
Figure 12-26 on page 123 and Figure 12-27 on page 123 for details).  
118  
7734Q–AVR–02/12  
AT90PWM81/161  
Figure 12-20. Burst generation.  
OFF  
BURST  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
(high level)  
PSCn Input A  
(low level)  
12.8.4  
PSC Input Configuration  
The PSC Input Configuration is done by programming bits in configuration registers.  
12.8.4.1  
Filter Enable  
If the “Filter Enable” bit is set, a digital filter of four cycles is inserted before evaluation of the sig-  
nal. The disable of this function is mainly needed for prescaled PSC clock sources, where the  
noise cancellation gives too high latency.  
Important: If the digital filter is active, the level sensitivity is true also with a disturbed PSC clock  
to deactivate the outputs (emergency protection of external component). Likewise when used as  
fault input, PSCn Input A or Input B have to go through PSC to act on PSCOUTn0/1/2/3 output.  
This way needs that CLKPSC is running. So thanks to PSC Asynchronous Output Control bit  
(PAOCnA/B), PSCnIN0/1 input can deactivate directly the PSC output. Notice that in this case,  
input is still taken into account as usually by Input Module System as soon as CLKPSC is running.  
Figure 12-21. PSC input filtering.  
CLK  
PSC  
Digital  
Filter  
PSCn Input A or B  
4 x CLK  
PSC  
PSC Input  
Module X  
Ouput  
Stage  
PSCOUTnX  
PIN  
12.8.4.2  
Signal Polarity  
One can select the active edge (edge modes) or the active level (level modes). See PELEVnx bit  
description in “PFRCnA - PSC n Input A Control Register” on page 141.  
If PELEVnx bit set, the significant edge of PSCn Input A or B is rising (edge modes) or the active  
level is high (level modes) and vice versa for unset/falling/low.  
119  
7734Q–AVR–02/12  
AT90PWM81/161  
- In 2- or 4-ramp mode, PSCn Input A is taken into account only during Dead-Time0 and On-  
Time0 period (respectively Dead-Time1 and On-Time1 for PSCn Input B).  
- In 1-ramp-mode PSC Input A or PSC Input B act on the whole ramp.  
12.8.4.3  
Input Mode Operation  
Thanks to 4 configuration bits (PRFM3:0), it’s possible to define the mode of the PSC input.  
Thanks to four configuration bits (PRFM3:0), it is possible to define all the modes of the PSCR  
input. These modes are listed in Table 12-7.  
Table 12-7. PSC input mode operation.  
PRFM3:0  
Description  
PSCn input has no action on PSC output  
0
1
0000b  
See “PSC Input Mode 1: Stop signal, Jump to Opposite Dead-Time and  
Wait” on page 121.  
0001b  
0010b  
0011b  
See “PSC Input Mode 2: Stop signal, Execute Opposite Pulse and Wait”  
on page 122.  
2
3
See “PSC Input Mode 3: Stop signal, Execute Opposite Pulse while Fault  
active” on page 123.  
See “PSC Input Mode 4: Deactivate outputs without changing timing” on  
page 124.  
4
5
6
0100b  
0101b  
0110b  
See “PSC Input Mode 5: Stop signal and Insert Dead-Time” on page 124.  
See “PSC Input Mode 6: Stop signal, Jump to Opposite Dead-Time and  
Wait” on page 125.  
See “PSC Input Mode 7: Halt PSC and Wait for Software Action” on page  
125.  
See “PSC Input Mode 8: Edge Retrigger PSC” on page 126.  
7
8
9
0111b  
1000b  
1001b  
See “PSC Input Mode 9: Fixed Frequency Edge Retrigger PSC” on page  
127.  
Reserved: Do not use  
10  
11  
12  
13  
1010b  
1011b  
1100b  
1101b  
See “PSC Input Mode 14: Fixed Frequency Edge Retrigger PSC and  
Deactivate Output” on page 128.  
Reserved: Do not use  
14  
15  
1110b  
1111b  
Note: All following examples are given with rising edge or high level active inputs.  
120  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
12.9 PSC Input Mode 1: Stop signal, Jump to Opposite Dead-Time and Wait  
Figure 12-22. PSCn behavior versus PSCn Input A in Fault Mode 1.  
DT0 OT0 DT1 OT1 DT0 OT0  
DT1 OT1  
DT0 OT0  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSC Input A  
PSC Input B  
PSC Input A is taken into account during DT0 and OT0 only. It has no effect during DT1 and  
OT1.  
When PSC Input A event occurs, PSC releases PSCOUTn0, waits for PSC Input A inactive state  
and then jumps and executes DT1 plus OT1.  
Figure 12-23. PSCn behavior versus PSCn Input B in Fault Mode 1.  
DT0 OT0 DT1 OT1 DT0 OT0 DT1 OT1  
DT0 OT0  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSC Input A  
PSC Input B  
PSC Input B is take into account during DT1 and OT1 only. It has no effect during DT0 and OT0.  
When PSC Input B event occurs, PSC releases PSCOUTn1, waits for PSC Input B inactive state  
and then jumps and executes DT0 plus OT0.  
121  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
12.10 PSC Input Mode 2: Stop signal, Execute Opposite Pulse and Wait  
Figure 12-24. PSCn behavior versus PSCn Input A in Fault Mode 2.  
DT0 OT0 DT1 OT1 DT0 OT0 DT1 OT1  
DT0 OT0  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSC Input A  
PSC Input B  
PSC Input A is take into account during DT0 and OT0 only. It has no effect during DT1 and OT1.  
When PSCn Input A event occurs, PSC releases PSCOUTn0, jumps and executes DT1 plus  
OT1 and then waits for PSC Input A inactive state.  
Even if PSC Input A is released during DT1 or OT1, DT1 plus OT1 sub-cycle is always com-  
pletely executed.  
Figure 12-25. PSCn behavior versus PSCn Input B in Fault Mode 2.  
DT0 OT0 DT1 OT1 DT0 OT0 DT1 OT1 DT0 OT0  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSC Input A  
PSC Input B  
PSC Input B is take into account during DT1 and OT1 only. It has no effect during DT0 and OT0.  
When PSC Input B event occurs, PSC releases PSCOUTn1, jumps and executes DT0 plus OT0  
and then waits for PSC Input B inactive state.  
Even if PSC Input B is released during DT0 or OT0, DT0 plus OT0 sub-cycle is always com-  
pletely executed.  
122  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
12.11 PSC Input Mode 3: Stop signal, Execute Opposite Pulse while Fault active  
Figure 12-26. PSCn behavior versus PSCn Input A in Mode 3.  
DT0 OT0  
DT1 OT1  
DT0 OT0 DT1 OT1  
DT1 OT1  
DT1 OT1  
DT0 OT0  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSC Input A  
PSC Input B  
PSC Input A is taken into account during DT0 and OT0 only. It has no effect during DT1 and  
OT1.  
When PSC Input A event occurs, PSC releases PSCOUTn0, jumps and executes DT1 plus OT1  
plus DT0 while PSC Input A is in active state.  
Even if PSC Input A is released during DT1 or OT1, DT1 plus OT1 sub-cycle is always com-  
pletely executed.  
Figure 12-27. PSCn behavior versus PSCn Input B in Mode 3.  
DT0 OT0  
DT1 OT1  
DT0 OT0  
DT1 OT1 DT0 OT0  
DT0 OT0  
DT0 OT0  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSC Input A  
PSC Input B  
PSC Input B is taken into account during DT1 and OT1 only. It has no effect during DT0 and  
OT0.  
When PSC Input B event occurs, PSC releases PSCnOUT1, jumps and executes DT0 plus OT0  
plus DT1 while PSC Input B is in active state.  
Even if PSC Input B is released during DT0 or OT0, DT0 plus OT0 sub-cycle is always com-  
pletely executed.  
123  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
12.12 PSC Input Mode 4: Deactivate outputs without changing timing  
Figure 12-28. PSC behavior versus PSCn Input A or Input B in Mode 4.  
DT0 OT0  
DT1 OT1  
DT0 OT0  
DT1 OT1  
DT0 OT0  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
or  
PSCn Input B  
Figure 12-29. PSC behavior versus PSCn Input A or Input B in Fault Mode 4.  
DT0 OT0 DT1 OT1 DT0 OT0 DT1 OT1  
DT0 OT0  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
or  
PSCn Input B  
PSCn Input A or PSCn Input B act indifferently on On-Time0/Dead-Time0 or on On-  
Time1/Dead-Time1.  
12.13 PSC Input Mode 5: Stop signal and Insert Dead-Time  
Figure 12-30. PSC behavior versus PSCn Input A in Fault Mode 5.  
DT0 OT0  
DT0 OT0  
DT0 OT0  
DT1  
OT1  
DT1 OT1  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
or  
PSCn Input B  
Used in Fault mode 5, PSCn Input A or PSCn Input B act indifferently on On-Time0/Dead-Time0  
or on On-Time1/Dead-Time1.  
124  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
12.14 PSC Input Mode 6: Stop signal, Jump to Opposite Dead-Time and Wait  
Figure 12-31. PSC behavior versus PSCn Input A in Fault Mode 6.  
DT0 OT0 DT0 OT0  
DT0 OT0  
DT1 OT1  
DT1 OT1  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
or  
PSCn Input B  
Used in Fault mode 6, PSCn Input A or PSCn Input B act indifferently on On-Time0/Dead-Time0  
or on On-Time1/Dead-Time1.  
12.15 PSC Input Mode 7: Halt PSC and Wait for Software Action  
Figure 12-32. PSC behavior versus PSCn Input A in Fault Mode 7.  
DT0 OT0  
DT0 OT0  
DT0 OT0  
DT1 OT1  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
or  
PSCn Input B  
Software Action (1)  
Note:  
1. Software action is the setting of the PRUNn bit in PCTLn register.  
Used in Fault mode 7, PSCn Input A or PSCn Input B act indifferently on On-Time0/Dead-Time0  
or on On-Time1/Dead-Time1.  
125  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
12.16 PSC Input Mode 8: Edge Retrigger PSC  
Figure 12-33. PSC behavior versus PSCn Input A in Mode 8.  
DT0 OT0  
DT0 OT0  
DT0 OT0  
DT1 OT1  
DT1 OT1  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
The output frequency is modulated by the occurrence of significative edge of retriggering input.  
Figure 12-34. PSC behavior versus PSCn Input B in Mode 8.  
DT0 OT0  
DT0 OT0  
DT0 OT0  
DT1 OT1  
DT1 OT1  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input B  
or  
PSCn Input B  
The output frequency is modulated by the occurrence of significative edge of retriggering input.  
The retrigger event is taken into account only if it occurs during the corresponding On-Time.  
Note: In one ramp mode, the retrigger event on input A resets the whole ramp. So the PSC  
doesn’t jump to the opposite dead-time.  
126  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
12.17 PSC Input Mode 9: Fixed Frequency Edge Retrigger PSC  
Figure 12-35. PSC behavior versus PSCn Input A in Mode 9.  
DT0 OT0  
DT0 OT0  
DT0 OT0  
DT1 OT1  
DT1 OT1  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
The output frequency is not modified by the occurrence of significative edge of retriggering input.  
Only the output is deactivated when significative edge on retriggering input occurs.  
Note: In this mode the output of the PSC becomes active during the next ramp even if the Retrig-  
ger/Fault input is active. Only the significative edge of Retrigger/Fault input is taken into account.  
Figure 12-36. PSC behavior versus PSCn Input B in Mode 9.  
DT0 OT0 DT0 OT0  
DT0 OT0  
DT1 OT1  
DT1 OT1  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input B  
The retrigger event is taken into account only if it occurs during the corresponding On-Time.  
127  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
12.18 PSC Input Mode 14: Fixed Frequency Edge Retrigger PSC and Deactivate Output  
Figure 12-37. PSC behavior versus PSCn Input A in Mode 14.  
DT0 OT0  
DT0 OT0  
DT0 OT0  
DT0 OT0  
DT1 OT1  
DT1 OT1  
DT1 OT1  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
The output frequency is not modified by the occurrence of significative edge of retriggering input.  
Figure 12-38. PSC behavior versus PSCn Input B in Mode 14.  
DT0 OT0  
DT0 OT0  
DT0 OT0  
DT0 OT0  
DT1 OT1  
DT1 OT1  
DT1 OT1  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input B  
The output is deactivated while retriggering input is active.  
The output of the PSC is set to an inactive state and the corresponding ramp is not aborted. The  
output stays in an inactive state while the Retrigger/Fault input is active. The PSC runs at con-  
stant frequency.  
12.18.1 Available Input Mode according to Running Mode  
Some input modes are not consistent with some running modes. Table 12-8 gives the input  
modes which are valid according to running modes.  
Table 12-8. Available input modes according to running modes.  
Input mode  
number:  
1 ramp mode  
Valid  
2 ramp mode  
Valid  
4 ramp mode  
Valid  
Centered mode  
Do not use  
Do not use  
Do not use  
Valid  
1
2
3
4
5
6
Do not use  
Do not use  
Valid  
Valid  
Valid  
Valid  
Valid  
Valid  
Valid  
Do not use  
Do not use  
Valid  
Valid  
Do not use  
Do not use  
Valid  
Valid  
128  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
Table 12-8. Available input modes according to running modes. (Continued)  
Input mode  
number:  
1 ramp mode  
Valid  
2 ramp mode  
Valid  
4 ramp mode  
Valid  
Centered mode  
Valid  
7
8
Valid  
Valid  
Valid  
Do not use  
Do not use  
9
Valid  
Valid  
Valid  
10  
11  
12  
13  
14  
15  
Do not use  
Valid  
Valid  
Valid  
Do not use  
Do not use  
12.18.2 Event Capture  
The PSC can capture the value of time (PSC counter) when a retrigger event or fault event  
occurs on PSC inputs. This value can be read by software in PICRnH/L register.  
12.18.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 PICR1 Register before the next event occurs, the PICR1 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 PICR1 Register should be read as early in the inter-  
rupt 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.  
12.19 PSC2 Outputs  
12.19.1 Output Matrix  
PSC2 has an output matrix which allow in 4 ramp mode to program a value of PSCOUT20 and  
PSCOUT21 binary value for each ramp.  
Table 12-9. Output matrix versus ramp number.  
Ramp 0  
Ramp 1  
Ramp 2  
Ramp 3  
PSCOUT20  
PSCOUT21  
POMV2A0  
POMV2B0  
POMV2A1  
POMV2B1  
POMV2A2  
POMV2B2  
POMV2A3  
POMV2B3  
PSCOUT2m takes the value given in Table 12-9. during all corresponding ramp. Thanks to the  
Output Matrix it is possible to generate all kind of PSCOUT20/PSCOUT21 combination.  
When Output Matrix is used, the PSC n Output Polarity POPn has no action on the outputs.  
129  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
12.19.2 PSCOUT22 & PSCOUT23 Selectors  
PSC 2 has two supplementary outputs PSCOUT22 and PSCOUT23.  
According to POS22 and POS23 bits in PSOC2 register, PSCOUT22 and PSCOUT23 duplicate  
PSCOUT20 and PSCOU21.  
If POS22 bit in PSOC2 register is clear, PSCOUT22 duplicates PSCOUT20.  
If POS22 bit in PSOC2 register is set, PSCOUT22 duplicates PSCOUT21.  
If POS23 bit in PSOC2 register is clear, PSCOUT23 duplicates PSCOUT21.  
If POS23 bit in PSOC2 register is set, PSCOUT23 duplicates PSCOUT20.  
Figure 12-39. PSCOUT22 and PSCOUT23 outputs.  
PSCOUT20  
PSCOUT22  
Waveform  
Generator A  
0
1
POS22  
POS23  
Output  
Matrix  
1
0
PSCOUT23  
PSCOUT21  
Waveform  
Generator B  
130  
7734Q–AVR–02/12  
AT90PWM81/161  
12.20 Analog Synchronization  
PSC generates a signal to synchronize the sample and hold or the ADC start; synchronization is  
mandatory for measurements.  
This signal can be selected between all falling or rising edge of PSCn0 or PSCn1 outputs as  
defined per Table 12-11 on page 134 and Table 12-12 on page 135.  
The signal can be shifted by a digital delay defined by the register PASDLY. The shifting clock  
can be either Clkpsc or Clkpsc/4, as described per Bit 7, 6, 5– PASDLKn(2:0): Analog Synchro-  
nization Output Delay or Input Blanking select on page 137.  
Figure 12-40. Analog synchronization.  
OCRnRA  
match  
OCRnRB  
match  
A Trig/Fault B Trig/Fault  
OCRnSA  
match  
OCRnSB  
match  
PSYNCn(1:0)  
CLKPSCn/8  
CLKPSCn/4  
CLKPSCn/2  
CLKPSCn  
7
6
5
4
Digital  
Delay  
PASDLYn  
0
PSCnASY  
1
PASDLKn(2:0)  
PASDLKn(2)  
12.21 Interrupt Handling  
As each PSC can be dedicated for one function, each PSC has its own interrupt system.  
List of interrupt sources:  
• Counter reload (end of On Time 1)  
• End of Enhanced Cycle  
• PSC Input event (active edge or at the beginning of level configured event)  
• PSC Mutual Synchronization Error  
131  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
12.22 PSC Synchronization  
Note: In AT90PWM81/161, this feature is not relevant and PRUN2, PARUN2 are stuck at zero.  
2 or 3 PSC can be synchronized together. In this case, two waveform alignments are possible:  
• The waveforms are center aligned in the Center Aligned mode if master and slaves are all  
with the same PSC period (which is the natural use).  
• The waveforms are edge aligned in the 1, 2 or 4 ramp mode  
Figure 12-41. PSC run synchronization.  
SY0In  
PRUN0  
Run PSC0  
PARUN0  
PSC0  
SY0Out  
SY1In  
PRUN1  
Run PSC1  
PARUN1  
PSC1  
SY1Out  
SY2In  
PRUN2  
Run PSC2  
PARUN2  
PSC2  
SY2Out  
If the PSCm has its PARUNn bit set, then it can start at the same time than PSCn-1.  
PRUNn and PARUNn bits are located in PCTLn register. See “PCTL2 - PSC 2 Control Register”  
on page 140.  
Note: Do not set the PARUNn bits on the three PSC at the same time.  
Thanks to this feature, we can for example configure two PSC in slave mode (PARUNn = 1 /  
PRUNn = 0) and one PSC in master mode (PARUNm = 0 / PRUNm = 0). This PSC master can  
start all PSC at the same moment (PRUNm = 1).  
12.22.1 Fault events in Autorun mode  
To complete this master/slave mechanism, fault event (input mode 7) is propagated from PSCn-  
1 to PSCn and from PSCn to PSCn-1.  
A PSC which propagate a Run signal to the following PSC stops this PSC when the Run signal  
is deactivate.  
According to the architecture of the PSC synchronization which build a “daisy-chain on the PSC  
run signal” between the three PSC, only the fault event (mode 7) which is able to “stop” the PSC  
through the PRUN bits is transmitted along this daisy-chain.  
132  
7734Q–AVR–02/12  
 
AT90PWM81/161  
A PSC which receive its Run signal from the previous PSC transmits its fault signal (if enabled)  
to this previous PSC. So a slave PSC propagates its fault events when they are configured and  
enabled.  
12.23 PSC Clock Sources  
PSC must be able to generate high frequency with enhanced resolution.  
Each PSC has two clock inputs:  
• CLK PLL from the PLL  
• CLK I/O  
Figure 12-42. Clock selection.  
CLK  
CLK  
1
0
PLL  
I/O  
CK  
PRESCALER  
PCLKSELn  
PPREn1/0  
CLK  
PSCn  
PCLKSELn bit in PSC n Configuration register (PCNFn) is used to select the clock source.  
PPREn1/0 bits in PSC n Control Register (PCTLn) are used to select the divide factor of the  
clock.  
Table 12-10. Output Clock versus selection and prescaler.  
PCLKSELn  
PPREn1  
PPREn0  
CLKPSCn output  
CLK I/O  
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
CLK I/O / 4  
CLK I/O / 32  
CLK I/O / 256  
CLK PLL  
CLK PLL / 4  
CLK PLL / 32  
CLK PLL / 256  
133  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
12.24 Interrupts  
This section describes the specifics of the interrupt handling as performed in AT90PWM81/161.  
12.24.1 List of Interrupt Vector  
Each PSC provides three interrupt vectors  
PSCn EC (End of Cycle): When enabled and when a match with OCRnRB occurs  
PSCn EEC (End of Enhanced Cycle): When enabled and when a match with OCRnRB  
occurs at the 15th enhanced cycle  
PSCn CAPT (Capture Event): When enabled and one of the two following events occurs:  
retrigger, capture of the PSC counter or Synchro Error.  
See “PIM2 - PSC2 Interrupt Mask Register” on page 143.  
12.25 PSC Register Definition  
Registers are explained for PSC0. They are identical for PSC1. For PSC2 only different registers  
are described.  
12.25.1 PSOC2 - PSC 2 Synchro and Output Configuration  
Bit  
7
6
5
4
3
2
1
0
POS23  
POS22  
PSYNC21 PSYNC20 POEN2D  
POEN2B  
POEN2C  
POEN2A  
PSOC2  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
• Bit 7 – POS23: PSCOUT23 Selection (PSC2 only)  
When this bit is clear, PSCOUT23 outputs the waveform generated by Waveform Generator B.  
When this bit is set, PSCOUT23 outputs the waveform generated by Waveform Generator A.  
• Bit 6 – POS22: PSCOUT22 Selection (PSC2 only)  
When this bit is clear, PSCOUT22 outputs the waveform generated by Waveform Generator A.  
When this bit is set, PSCOUT22 outputs the waveform generated by Waveform Generator B.  
• Bit 5:4 – PSYNCn1:0: Synchronization Out for ADC Selection  
Select the polarity and signal source for generating a signal which will be sent to the ADC for  
synchronization.  
Table 12-11. Synchronization source description in one/two/four ramp modes.  
PSYNCn1  
PSYNCn0  
Description  
0
0
Send signal on leading edge of PSCOUTn0 (match with OCRnSA)  
Send signal on trailing edge of PSCOUTn0 (match with OCRnRA or  
fault/retrigger on part A)  
0
1
1
1
0
1
Send signal on leading edge of PSCOUTn1 (match with OCRnSB)  
Send signal on trailing edge of PSCOUTn1 (match with OCRnRB or  
fault/retrigger on part B)  
134  
7734Q–AVR–02/12  
 
 
 
 
 
AT90PWM81/161  
Table 12-12. Synchronization source description in centered mode.  
PSYNCn1  
PSYNCn0  
Description  
Send signal on match with OCRnRA (during counting down of PSC)  
The minimum value of OCRnRA must be 1  
0
0
Send signal on match with OCRnRA (during counting up of PSC)  
The minimum value of OCRnRA must be 1  
0
1
1
1
0
1
No synchronization signal  
No synchronization signal  
• Bit 3 – POEN2D: PSCOUT23 Output Enable (PSC2 only)  
When this bit is clear, second I/O pin affected to PSCOUT23 acts as a standard port.  
When this bit is set, second I/O pin affected to PSCOUT23 is connected to the PSC waveform  
generator B output and is set and clear according to the PSC operation.  
• Bit 2 – POENnB: PSC n OUT Part B Output Enable  
When this bit is clear, I/O pin affected to PSCOUTn1 acts as a standard port.  
When this bit is set, I/O pin affected to PSCOUTn1 is connected to the PSC waveform generator  
B output and is set and clear according to the PSC operation.  
• Bit 1 – POEN2C: PSCOUT22 Output Enable (PSC2 only)  
When this bit is clear, second I/O pin affected to PSCOUT22 acts as a standard port.  
When this bit is set, second I/O pin affected to PSCOUT22 is connected to the PSC waveform  
generator A output and is set and clear according to the PSC operation.  
• Bit 0 – POENnA: PSC n OUT Part A Output Enable  
When this bit is clear, I/O pin affected to PSCOUTn0 acts as a standard port.  
When this bit is set, I/O pin affected to PSCOUTn0 is connected to the PSC waveform generator  
A output and is set and clear according to the PSC operation.  
12.25.2 OCRnSAH and OCRnSAL - Output Compare SA Register  
Bit  
7
6
5
4
3
2
1
0
OCRnSA[11:8]  
OCRnSAH  
OCRnSAL  
OCRnSA[7:0]  
Read/Write  
Initial Value  
W
0
W
W
0
W
0
W
0
W
0
W
0
W
0
0
12.25.3 OCRnRAH and OCRnRAL - Output Compare RA Register  
Bit  
7
6
5
4
3
2
1
0
OCRnRA[11:8]  
OCRnRAH  
OCRnRAL  
OCRnRA[7:0]  
Read/Write  
Initial Value  
W
0
W
0
W
0
W
0
W
0
W
0
W
0
W
0
135  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
12.25.4 OCRnSBH and OCRnSBL - Output Compare SB Register  
Bit  
7
6
5
4
3
2
1
0
OCRnSB[11:8]  
OCRnSBH  
OCRnSBL  
OCRnSB[7:0]  
Read/Write  
Initial Value  
W
0
W
W
0
W
0
W
0
W
0
W
0
W
0
0
12.25.5 OCRnRBH and OCRnRBL - Output Compare RB Register  
Bit  
7
6
5
4
3
2
1
0
OCRnRB[15:12]  
OCRnRB[7:0]  
OCRnRB[11:8]  
OCRnRBH  
OCRnRBL  
Read/Write  
Initial Value  
W
0
W
0
W
0
W
0
W
0
W
0
W
0
W
0
Note: n = 0 to 2 according to PSC number.  
The Output Compare Registers RA, RB, SA and SB contain a 12-bit value that is continuously  
compared with the PSC counter value. A match can be used to generate an Output Compare  
interrupt, or to generate a waveform output on the associated pin.  
The Output Compare Registers RB contains also a 4-bit value that is used for the flank width  
modulation.  
The Output Compare Registers are 16-bit and 12-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 per-  
formed using an 8-bit temporary high byte register (TEMP). This temporary register is shared by  
all the other 16-bit registers.  
12.25.6 PCNF2 - PSC 2 Configuration Register  
Bit  
7
6
5
4
3
2
1
0
PFIFTY2  
PALOCK2 PLOCK2  
PMODE21 PMODE20 POP2  
PCLKSEL2 POME2  
PCNF2  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
The PSC n Configuration Register is used to configure the running mode of the PSC.  
• Bit 7 - PFIFTYn: PSC n Fifty  
Writing this bit to one, set the PSC in a fifty percent mode where only OCRnRBH/L and OCRn-  
SBH/L are used. They are duplicated in OCRnRAH/L and OCRnSAH/L during the update of  
OCRnRBH/L. This feature is useful to perform fifty percent waveforms.  
• Bit 6 - PALOCKn: PSC n Autolock  
When this bit is set, the Output Compare Registers RA, SA, SB, the Output Matrix POM2 and  
the PSC Output Configuration PSOCn can be written without disturbing the PSC cycles. The  
update of the PSC internal registers will be done at the end of the PSC cycle if the Output Com-  
pare Register RB has been the last written.  
When set, this bit prevails over LOCK (bit 5).  
136  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
• Bit 5 – PLOCKn: PSC n Lock  
When this bit is set, the Output Compare Registers RA, RB, SA, SB, the Output Matrix POM2  
and the PSC Output Configuration PSOCn can be written without disturbing the PSC cycles.  
The update of the PSC internal registers will be done if the LOCK bit is released to zero.  
• Bit 4:3 – PMODEn1: 0: PSC n Mode  
Select the mode of PSC.  
Table 12-13. PSC n mode selection.  
PMODEn1  
PMODEn0  
Description  
0
0
1
1
0
1
0
1
One Ramp mode  
Two Ramp mode  
Four Ramp mode  
Center Aligned mode  
• Bit 2 – POPn: PSC n Output Polarity  
If this bit is cleared, the PSC outputs are active Low.  
If this bit is set, the PSC outputs are active High.  
• Bit 1 – PCLKSELn: PSC n Input Clock Select  
This bit is used to select between CLKPF or CLKPS clocks.  
Set this bit to select the fast clock input (CLKPF).  
Clear this bit to select the slow clock input (CLKPS).  
• Bit 0 – POME2: PSC 2 Output Matrix Enable (PSC2 only)  
Set this bit to enable the Output Matrix feature on PSC2 outputs. See “PSC2 Outputs” on page  
129.  
When Output Matrix is used, the PSC n Output Polarity POPn has no action on the outputs.  
12.25.7 PCNFE2 - PSC 2 Extended Configuration Register  
Bit  
7
6
5
4
3
2
1
0
PASDLKn2 PASDLKn1 PASDLKn0 PBFMn1  
PELEVnA1 PELEVnB1 PISELnA1 PISELnB1 PCNFE2  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
The PSC n Extended Configuration Register is used to configure the running mode of the PSC.  
• Bit 7, 6, 5– PASDLKn(2:0): Analog Synchronization Output Delay or Input Blanking  
select  
Defines the modes for Analog signal synchronization delay or Input Blanking.  
137  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Table 12-14. Analog signal synchronization or Input Blanking mode selection.  
PASDLKn2  
PASDLKn1  
PASDLKn0  
Description  
0
0
0
No Analog signal synchronization delay, no Input Blanking  
No Analog signal synchronization delay, Input Blanking using PSC clock,  
started on PSC end of cycle  
0
0
0
0
1
1
1
0
1
No Analog signal synchronization delay, Input Blanking using PSC clock,  
started on OCR SA event  
No Analog signal synchronization delay, Input Blanking using PSC clock,  
started on OCR SB event  
1
1
1
1
0
0
1
1
0
1
0
1
Analog signal synchronization delay with PSC clock, no Input Blanking  
Analog signal synchronization delay with PSC clock /2, no Input Blanking  
Analog signal synchronization delay with PSC clock /4, no Input Blanking  
Analog signal synchronization delay with PSC clock /8, no Input Blanking  
• Bit 4- PBFMn1: Balance Flank Width Modulation, bit 1  
Defines the Flank Width Modulation, together with PBFMn0 bit in PCTLn register.  
Table 12-15. Flank Width Mode selection.  
PBFMn1  
PBFMn0  
Description  
0
0
Flank Width Modulation operates on RB (On-Time 1 only)  
Flank Width Modulation operates on RB + RA (On-Time 0 and On-  
Time 1)  
0
1
1
1
0
1
Flank Width Modulation operates on SB (Dead-Time 1 only) (1)  
Flank Width Modulation operates on SB +SA (Dead-Time 0 and  
Dead-Time 1)  
Note:  
1. In one ramp mode, changing SA or SA+BSB also affect On-Time; see Figure 12-8 on page  
108.  
• Bit 3– PELEVnA1: PSC n Input Select for part A  
Together with PELEVnA0, defines active edge or level on PSC part A.  
Table 12-16. PSC edge & level input selection.  
PELEVnA1  
PELEVnA0  
Description  
The falling edge or low level of selected input generates the  
significative event for retrigger or fault function  
0
0
The rising edge or high level of selected input generates the  
significative event for retrigger or fault function  
0
1
The toggle of selected input generates the significative event for  
retrigger or fault function  
1
1
0
1
Reserved  
138  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
• Bit 2– PELEVnB1: PSC n Input Select for part B  
Together with PELEVnB0, defines active edge or level on PSC part B.  
Table 12-17. PSC edge & level input selection.  
PELEVnB1  
PELEVnB0  
Description  
The falling edge or low level of selected input generates the  
significative event for retrigger or fault function  
0
0
The rising edge or high level of selected input generates the  
significative event for retrigger or fault function  
0
1
The toggle of selected input generates the significative event for  
retrigger or fault function  
1
1
0
1
Reserved  
• Bit 1– PISELnA1: PSC n Input Select for part A  
Together with PISELnA0, defines active signal on PSC part A.  
Table 12-18. PSC trigger & fault input selection.  
PISELnA1  
PISELnA0  
Description  
0
0
1
1
0
1
0
1
PSCINn  
First analog comparator output  
PSCINnA  
Second analog comparator output  
• Bit 0– PISELnB1: PSC n Input Select for part B  
Together with PISELnB0, defines active signal on PSC part B.  
Table 12-19. PSC trigger & fault input selection.  
PISELnB1  
PISELnB0  
Description  
0
0
1
1
0
1
0
1
PSCINn  
First analog comparator output  
PSCINnA  
Second analog comparator output  
12.25.8 PASDLYn - Analog Synchronization Delay Register  
Bit  
7
6
5
4
3
2
1
0
PASDLYn[7:0]  
PASDLYn  
Read/Write  
Initial Value  
W
0
W
0
W
0
W
0
W
0
W
0
W
0
W
0
The Analog Synchronization Delay Register store an 8 bit delay used:  
• For the input signal blanking. See Section “PSC Inputs”, page 114  
• For shifting the PSCOUTnx edges and the PSCnASY signal. See Section “Analog  
Synchronization”, page 131  
139  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
See also the bit definition Section “Bit 7, 6, 5– PASDLKn(2:0): Analog Synchronization Output  
Delay or Input Blanking select”, page 137 and Section “Bit 5:4 – PSYNCn1:0: Synchronization  
Out for ADC Selection”, page 134.  
12.25.9 PCTL2 - PSC 2 Control Register  
Bit  
7
6
5
4
3
2
1
0
PPRE21  
R/W  
0
PPRE20  
R/W  
0
PBFM20  
R/W  
PAOC2B  
PAOC2A  
PARUN2  
PCCYC2  
PRUN2  
R/W  
0
PCTL2  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
0
• Bit 7:6 – PPREn1:0 : PSC n Prescaler Select  
This two bits select the PSC input clock division factor. All generated waveform will be modified  
by this factor.  
Table 12-20. PSC n Prescaler selection.  
PPREn1  
PPREn0  
Description  
0
0
1
1
0
1
0
1
No divider on PSC input clock  
Divide the PSC input clock by 4  
Divide the PSC input clock by 16  
Divide the PSC clock by 64  
• Bit 5 – PBFMn0: Balance Flank Width Modulation bit 0  
Defines the Flank Width Modulation, together with PBFMn1 bit in PCNFEn register. See Table  
12-15 on page 138.  
• Bit 4 – PAOCnB: PSC n Asynchronous Output Control B  
When this bit is set, Fault input selected to block B can act directly to PSCOUTn1 and  
PSCOUT23 outputs. See Section “PSC Clock Sources”, page 133.  
• Bit 3 – PAOCnA: PSC n Asynchronous Output Control A  
When this bit is set, Fault input selected to block A can act directly to PSCOUTn0 and  
PSCOUT22 outputs. See Section “PSC Clock Sources”, page 133.  
• Bit 2 – PARUNn: PSC n Autorun  
When this bit is set, the PSC n starts with PSCn-1. That means that PSC n starts:  
• when PRUNn bit in PCTLn register is set,  
• or when PARUNn bit in PCTLn is set and PRUNn-1 bit in PCTLn-1 register is set (or PARUN0  
bit and PRUN0)  
• Bit 1 – PCCYCn: PSC n Complete Cycle  
When this bit is set, the PSC n completes the entire waveform cycle before halt operation  
requested by clearing PRUNn. This bit is not relevant in slave mode (PARUNn = 1).  
• Bit 0 – PRUNn: PSC n Run  
Writing this bit to one starts the PSC n.  
When set, this bit prevails over PARUNn bit.  
140  
7734Q–AVR–02/12  
 
AT90PWM81/161  
12.25.10 PFRCnA - PSC n Input A Control Register  
Bit  
7
6
5
4
3
2
1
0
PCAEnA  
PISELnA0 PELEVnA0 PFLTEnA PRFMnA3 PRFMnA2 PRFMnA1 PRFMnA0 PFRCnA  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
12.25.11 PFRCnB - PSC n Input B Control Register  
Bit  
7
6
5
4
3
2
1
0
PCAEnB  
PISELnB0 PELEVnB0 PFLTEnB PRFMnB3 PRFMnB2 PRFMnB1 PRFMnB0 PFRCnB  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
The Input Control Registers are used to configure the 2 PSC’s Retrigger/Fault block A & B. The  
2 blocks are identical, so they are configured on the same way.  
• Bit 7 – PCAEnx: PSC n Capture Enable Input Part x  
Writing this bit to one enables the capture function when external event occurs on input selected  
as input for Part x (see PISELnx1:0 bit in the same register).  
• Bit 6 – PISELnx0: PSC n Input Select for Part x  
Together with PISELnx1 in PCNFEn register, defines active signal on PSC module A. See Table  
12-18 on page 139 and Table 12-19 on page 139.  
• Bit 5 –PELEVnx0: PSC n Edge Level Selector of Input Part x  
Together with PELEVnx1 n PCNFEn register, defines active edge & level on PSC part x; See  
Table 12-16 on page 138 and Table 12-17 on page 139.  
• Bit 4 – PFLTEnx: PSC n Filter Enable on Input Part x  
Setting this bit (to one) activates the Input Capture Noise Canceler. When the noise canceler is  
activated, the input from the retrigger pin is filtered. The filter function requires four successive  
equal valued samples of the retrigger pin for changing its output. The Input Capture is therefore  
delayed by four oscillator cycles when the noise canceler is enabled.  
• Bit 3:0 – PRFMnx3:0: PSC n Fault Mode  
These four bits define the mode of operation of the Fault or Retrigger functions.  
(see Table 12-7 on page 120 for more explanations).  
Table 12-21. Level sensitivity and Fault Mode operation.  
PRFMnx3:0  
Description  
No action, PSC Input is ignored  
0000b  
“PSC Input Mode 1: Stop signal, Jump to Opposite Dead-Time and Wait”,  
page 121  
0001b  
“PSC Input Mode 2: Stop signal, Execute Opposite Pulse and Wait”,  
page 122  
0010b  
0011b  
“PSC Input Mode 3: Stop signal, Execute Opposite Pulse while Fault active”,  
page 123  
141  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
Table 12-21. Level sensitivity and Fault Mode operation. (Continued)  
PRFMnx3:0  
0100b  
Description  
“PSC Input Mode 4: Deactivate outputs without changing timing”, page 124  
“PSC Input Mode 5: Stop signal and Insert Dead-Time”, page 124  
0101b  
“PSC Input Mode 6: Stop signal, Jump to Opposite Dead-Time and Wait”,  
page 125  
0110b  
“PSC Input Mode 7: Halt PSC and Wait for Software Action”, page 125  
0111b  
1000b  
1001b  
1010b  
1011b  
1100b  
1101b  
“PSC Input Mode 8: Edge Retrigger PSC”, page 126  
“PSC Input Mode 9: Fixed Frequency Edge Retrigger PSC”, page 127  
Reserved (do not use)  
“PSC Input Mode 14: Fixed Frequency Edge Retrigger PSC and Deactivate  
Output”, page 128  
Reserved (do not use)  
1110b  
1111b  
12.25.12 PICR2H and PICR2L - PSC 2 Input Capture Register  
Bit  
7
6
5
4
3
2
1
0
PCST2  
PICR2[11:8]  
PICR2H  
PICR2L  
PICR2[7:0]  
Read/Write  
Initial Value  
R
0
R
0
R
0
R
0
R
0
R
0
R
0
R
0
• Bit 7 – PCSTn: PSC Capture Software Trig bit  
Set this bit to trigger off a capture of the PSC counter. When reading, if this bit is set it means  
that the capture operation was triggered by PCSTn setting otherwise it means that the capture  
operation was triggered by a PSC input.  
The Input Capture is updated with the PSC counter value each time an event occurs on the  
enabled PSC input pin (or optionally on the Analog Comparator output) if the capture function is  
enabled (bit PCAEnx in PFRCnx register is set).  
The Input Capture Register is 12-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 or  
12-bit registers.  
12.26 PSC2 Specific Register  
12.26.1 POM2 - PSC 2 Output Matrix  
Bit  
7
6
5
4
3
2
1
0
POMV2B3 POMV2B2 POMV2B1 POMV2B0 POMV2A3 POMV2A2 POMV2A1 POMV2A0 POM2  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
142  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
• Bit 7 – POMV2B3: Output Matrix Output B Ramp 3  
This bit gives the state of the PSCOUT21 (and/or PSCOUT23) during ramp 3.  
• Bit 6 – POMV2B2: Output Matrix Output B Ramp 2  
This bit gives the state of the PSCOUT21 (and/or PSCOUT23) during ramp 2.  
• Bit 5 – POMV2B1: Output Matrix Output B Ramp 1  
This bit gives the state of the PSCOUT21 (and/or PSCOUT23) during ramp 1.  
• Bit 4 – POMV2B0: Output Matrix Output B Ramp 0  
This bit gives the state of the PSCOUT21 (and/or PSCOUT23) during ramp 0.  
• Bit 3 – POMV2A3: Output Matrix Output A Ramp 3  
This bit gives the state of the PSCOUT20 (and/or PSCOUT22) during ramp 3.  
• Bit 2 – POMV2A2: Output Matrix Output A Ramp 2  
This bit gives the state of the PSCOUT20 (and/or PSCOUT22) during ramp 2.  
• Bit 1 – POMV2A1: Output Matrix Output A Ramp 1  
This bit gives the state of the PSCOUT20 (and/or PSCOUT22) during ramp 1.  
• Bit 0 – POMV2A0: Output Matrix Output A Ramp 0  
This bit gives the state of the PSCOUT20 (and/or PSCOUT22) during ramp 0.  
12.26.2 PIM2 - PSC2 Interrupt Mask Register  
Bit  
7
6
5
4
3
2
-
1
0
-
-
PSEIE2  
R/W  
0
PEVE2B  
R/W  
PEVE2A  
R/W  
PEOEPE2 PEOPE2  
PIM2  
Read/Write  
Initial Value  
R
0
R
0
R
0
R/W  
0
R/W  
0
0
0
• Bit 5 – PSEIEn: PSC n Synchro Error Interrupt Enable  
When this bit is set, the PSEIn bit (if set) generate an interrupt.  
• Bit 4 – PEVEnB: PSC n External Event B Interrupt Enable  
When this bit is set, an external event which can generates a capture from Retrigger/Fault block  
B generates also an interrupt.  
• Bit 3 – PEVEnA: PSC n External Event A Interrupt Enable  
When this bit is set, an external event which can generates a capture from Retrigger/Fault block  
A generates also an interrupt.  
• Bit 1– PEOEPEn: PSC n End Of Enhanced Cycle Interrupt Enable  
When this bit is set, an interrupt is generated when PSC reaches the end of the 15th PSC cycle.  
This allows to update the PSC values in the interrupt routine and to start a new enhanced cycle  
with the new values at the next PSC cycle end.  
• Bit 0 – PEOPEn: PSC n End Of Cycle Interrupt Enable  
When this bit is set, an interrupt is generated when PSC reaches the end of the whole cycle.  
143  
7734Q–AVR–02/12  
 
AT90PWM81/161  
12.26.3 PIFR2 - PSC2 Interrupt Flag Register  
Bit  
7
6
5
4
3
2
1
0
POAC2B  
POAC2A  
PSEI2  
R/W  
0
PEV2B  
R/W  
0
PEV2A  
R/W  
0
PRN21  
PRN20  
PEOP2  
R/W  
0
PIFR2  
Read/Write  
Initial Value  
R
0
R
0
R
0
R
0
• Bit 7 – POACnB: PSC n Output B Activity  
This bit is set by hardware each time the output PSCOUTn1 changes from 0 to 1 or from 1 to 0.  
Must be cleared by software by writing a one to its location.  
This feature is useful to detect that a PSC output doesn’t change due to a frozen external input  
signal.  
• Bit 6 – POACnA: PSC n Output A Activity  
This bit is set by hardware each time the output PSCOUTn0 changes from 0 to 1 or from 1 to 0.  
Must be cleared by software by writing a one to its location.  
This feature is useful to detect that a PSC output doesn’t change due to a frozen external input  
signal.  
• Bit 5 – PSEIn: PSC n Synchro Error Interrupt  
This bit is set by hardware when the update (or end of PSC cycle) of the PSCn configured in  
auto run (PARUNn = 1) does not occur at the same time than the PSCn-1 which has generated  
the input run signal. (For PSC0, PSCn-1 is PSC2).  
Must be cleared by software by writing a one to its location.  
This feature is useful to detect that a PSC doesn’t run at the same speed or with the same phase  
than the PSC master.  
• Bit 4 – PEVnB: PSC n External Event B Interrupt  
This bit is set by hardware when an external event which can generates a capture or a retrigger  
from Retrigger/Fault block B occurs.  
Must be cleared by software by writing a one to its location.  
This bit can be read even if the corresponding interrupt is not enabled (PEVEnB bit = 0).  
• Bit 3 – PEVnA: PSC n External Event A Interrupt  
This bit is set by hardware when an external event which can generates a capture or a retrigger  
from Retrigger/Fault block A occurs.  
Must be cleared by software by writing a one to its location.  
This bit can be read even if the corresponding interrupt is not enabled (PEVEnA bit = 0).  
• Bit 2:1 – PRNn1:0: PSC n Ramp Number  
Memorization of the ramp number when the last PEVnA or PEVnB occurred.  
144  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Table 12-22. PSC n ramp number description.  
PRNn1  
PRNn0  
Description  
0
0
1
1
0
1
0
1
The last event which has generated an interrupt occurred during ramp 1  
The last event which has generated an interrupt occurred during ramp 2  
The last event which has generated an interrupt occurred during ramp 3  
The last event which has generated an interrupt occurred during ramp 4  
• Bit 0 – PEOPn: End Of PSC n Interrupt  
This bit is set by hardware when PSC n achieves its whole cycle.  
Must be cleared by software by writing a one to its location.  
12.26.4 PSC Output Behavior During Reset  
For external component safety reason, the state of PSC outputs during Reset can be pro-  
grammed by fuses PSCRV, PSCRRB & PSC2RB.  
These fuses are located in the Extended Fuse Byte:  
Table 12-23. Extended Low Fuse byte.  
Extended fuse byte  
Bit No  
Description  
Default value  
PSC2RB  
7
PSC2 reset behavior  
1
PSC2 reset behavior for  
OUT22 & 23  
PSC2RBA  
PSCRRB  
PSCRV  
6
5
4
1
1
1
PSC reduced reset behavior  
PSCOUT & PSCOUTR reset  
value  
PSC & PSCR inputs reset  
behavior  
PSCINRB  
3
2
1
0
1
Brown-out detector trigger  
level  
BODLEVEL2 (1)  
BODLEVEL1 (1)  
BODLEVEL0 (1)  
1 (unprogrammed)  
0 (programmed)  
1 (unprogrammed)  
Brown-out detector trigger  
level  
Brown-out detector trigger  
level  
Notes: 1. See Table 7-2 on page 53 for BODLEVEL Fuse decoding.  
PSCRV gives the state low or high which will be forced on PSC outputs selected by PSC0RB &  
PSC2RB fuses.  
If PSCRV fuse equals 0 (programmed), the selected PSC outputs will be forced to low state. If  
PSCRV fuse equals 1 (unprogrammed), the selected PSC outputs will be forced to high state.  
If PSCRRB fuse equals 1 (unprogrammed), PSCOUTR0 & PSCOUTR1 keep a standard port  
behavior. If PSC0RB fuse equals 0 (programmed), PSCOUTR0 & PSCOUTR1 are forced at  
reset to low level or high level according to PSCRV fuse bit. In this second case, PSCOUTR0 &  
PSCOUTR1 keep the forced state until PSOC0 register is written.  
145  
7734Q–AVR–02/12  
 
AT90PWM81/161  
If PSC2RB fuse equals 1 (unprogrammed), PSCOUT20 & PSCOUT21 keep a standard port  
behavior. If PSC2RB fuse equals 0 (programmed), PSCOUT20 & PSCOUT21 are forced at  
reset to low level or high level according to PSCRV fuse bit. In this second case, PSCOUT20 &  
PSCOUT21 keep the forced state until PSOC2 register is written.  
If PSC2RBA fuse equals 1 (unprogrammed), PSCOUT22 & PSCOUT23 keep a standard port  
behavior. If PSC2RBA fuse equals 0 (programmed), PSCOUT22 & PSCOUT23 are forced at  
reset to low level or high level according to PSCRV fuse bit. In this second case, PSCOUT22 &  
PSCOUT23 keep the forced state until PSOC2 register is written.  
12.26.5 PSC Input Behavior During Reset  
For power consumption under reset reason, the state of PSC & PSCR inputs during Reset can  
be programmed by fuse PSCINRB.  
If PSCINRB fuse equals 1 (unprogrammed), PSC & PSCR input keep a standard port behavior.  
If PSCINRB fuse equals 0 (programmed), PSC & PSCR input pull-up are forced while the reset  
is active. Affected pins are PSCIN2, PSCINr, PSCIN2A, PSCINrA. To prevent any conflict on  
PD1, this fuse has no effect on PSCINrB.  
146  
7734Q–AVR–02/12  
AT90PWM81/161  
13. Reduced Power Stage Controller – (PSCR)  
The Reduced Power Stage Controller is a high performance waveform controller.  
13.1 Features  
PWM waveform generation function (two complementary programmable outputs)  
Dead time control  
Standard mode up to 12-bit resolution  
Enhanced resolution up to 16 bits  
Frequency up to 64Mhz  
Conditional waveform on external events (zero crossing, current sensing ...)  
ADC synchronization  
Overload protection function  
Abnormality protection function, emergency input to force all outputs to high impedance or in  
inactive state (fuse configurable)  
Fast emergency stop by hardware  
13.2 Overview  
Many register and bit references in this section are written in general form.  
• A lower case “r” (or “n” replaces the PSC number, in this case 0. However, when using the  
register or bit defines in a program, the precise form must be used, that is, PSOC0 for  
accessing PSCR 0 Synchro and Output Configuration register and so on  
• A lower case “x” replaces the PSCR part , in this case A or B. However, when using the  
register or bit defines in a program, the precise form must be used, that is, PFRC0A for  
accessing PSCR 0 Fault/Retrigger A Control register and so on  
The purpose of a Power Stage Controller (PSC) is to control power modules on a board. It has  
two outputs.  
These outputs can be used in various ways:  
• “Two Outputs” to drive a half bridge (for example, Lighting applications)  
• “One Output” to drive single power transistor (for example, DC/DC converter, PFC  
applications)  
The PSCR has two inputs the purpose of which is to provide means to act directly on the gener-  
ated waveforms:  
• Current sensing regulation  
• Zero crossing retriggering  
• Demagnetization retriggering  
• Fault input  
147  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
13.3 PSCR Description  
Figure 13-1. Power Stage Controller block diagram.  
PSCR Counter  
Waveform  
Gererator B  
PSCOUTr1  
=
OCRrRB  
PSC Input  
Module B  
PSCr Input B  
=
OCRrSB  
Part B  
PSC Input  
Module A  
PSCr Input A  
=
OCRrRA  
PSCOUTr0  
Waveform  
Gererator A  
=
OCRrSA  
Part A  
PICRr  
PCNFr  
PCTLr  
PFRCrB  
PFRCrA  
PSOCr  
The principle of the PSCR is based on the use of a counter (PSCR counter). This counter is  
able to count up and count down from and to values stored in registers according to the selected  
running mode.  
The PSCR is seen as two symmetrical entities. One part named part A which generates the out-  
put PSCOUTr0 and the second one named part B which generates the PSCOUTr1 output.  
Each part A or B has its own PSCR Input Module to manage selected input.  
13.3.1  
Output Polarity  
The polarity “active high” or “active low” of the PSCR outputs is programmable. All the timing  
diagrams in the following examples are given in the “active high” polarity.  
148  
7734Q–AVR–02/12  
 
AT90PWM81/161  
13.4 Signal Description  
Figure 13-2. PSCR external block view.  
CLK  
PLL  
CLK  
I/O  
12  
12  
12  
12  
OCRrRB[11:0]  
OCRrSB[11:0]  
OCRrRA[11:0]  
OCRrSA[11:0]  
PSCOUTr0  
PSCOUTr1  
12  
3
PICRr[11:0]  
PSCINr  
IRQ PSCr  
Analog  
Comparator  
Output  
PSCrASY  
13.4.1  
Input Description  
Table 13-1. Internal inputs.  
Name  
Description  
Type width  
Register 12 bits  
Register 12 bits  
Register 12 bits  
Register 12 bits  
Signal  
OCRrRB[11:0]  
OCRrSB[11:0]  
OCRrRA[11:0]  
OCRrSA[11:0]  
CLK I/O  
Compare value which reset signal on Part B (PSCOUTr1)  
Compare value which set signal on Part B (PSCOUTr1)  
Compare value which reset signal on Part A (PSCOUTr0)  
Compare value which set signal on Part A (PSCOUTr0)  
Clock input from I/O clock  
CLK PLL  
Clock input from PLL  
Signal  
149  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Table 13-2. Block inputs.  
Name Description  
PSCINr  
Type width  
Signal  
Input 0 used for retrigger or fault functions  
Input 1 used for retrigger or fault functions  
From analog  
comparator  
Signal  
PSCINrA  
PSCINrB  
Input 2 used for retrigger or fault functions  
Input 3 used for retrigger or fault functions  
Signal  
Signal  
13.4.2  
Output Description  
Table 13-3. Block outputs.  
Name  
PSCOUTr0  
PSCOUTr1  
Description  
Type width  
Signal  
PSCR Output 0 (from part A of PSC)  
PSCR Output 1 (from part B of PSC)  
Signal  
Table 13-4. Internal Outputs.  
Name  
Description  
Type width  
PSCR Input Capture Register  
Counter value at retriggering event  
PICRr[11:0]  
Register 12 bits  
PSCR Interrupt Request: three sources, overflow, fault, and  
input capture  
IRQPSCr  
PSCrASY  
Signal  
Signal  
ADC synchronization (+ amplifier synchro.) (2)  
2. See “Analog Synchronization” on page 169.  
150  
7734Q–AVR–02/12  
 
AT90PWM81/161  
13.5 Functional Description  
13.5.1  
Waveform Cycles  
The waveform generated by PSCR can be described as a sequence of two waveforms.  
The first waveform is relative to PSCOUTr0 output and part A of PSC. The part of this waveform  
is sub-cycle A in Figure 13-3.  
The second waveform is relative to PSCOUTr1 output and part B of PSC. The part of this wave-  
form is sub-cycle B in Figure 13-3.  
The complete waveform is ended with the end of sub-cycle B. It means at the end of waveform  
B.  
Figure 13-3. Cycle presentation in 1, 2, and 4 Ramp mode.  
PSC Cycle  
Sub-Cycle A  
Sub-Cycle B  
4 Ramp Mode  
Ramp A0  
Ramp A1  
Ramp B0  
Ramp B1  
2 Ramp Mode  
Ramp A  
Ramp B  
1 Ramp Mode  
UPDATE  
Ramps illustrate the output of the PSCR counter included in the waveform generators. Centered  
Mode is like a one ramp mode which count down up and down.  
Notice that the update of a new set of values is done regardless of ramp Mode at the top of the  
last ramp.  
13.5.2  
Running Mode Description  
Waveforms and length of output signals are determined by Time Parameters (DT0, OT0, DT1,  
OT1) and by the running mode. Three modes are possible:  
– Four Ramp mode  
Two Ramp mode  
– One Ramp mode  
The active time of PSCOUTn0 is given by the OT0 value. The active time of PSCOUTn1 is given  
by the OT1 value. Both of them are 12 bit values. Thanks to DT0 & DT1 to adjust the dead time  
between PSCOUTn0 and PSCOUTn1 active signals.  
151  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
The waveform frequency is defined by the following equation:  
f
1
CLK_PSCn  
f
= ----------------------------- = --------------------------------------------------------------------  
PSCn  
PSCnCycle  
(OT0 + OT1 + DT0 + DT1)  
13.5.2.1  
Four Ramp Mode  
In Four Ramp mode, each time in a cycle has its own definition.  
Figure 13-4. PSCr0 & PSCr1 basic waveforms in Four Ramp mode.  
OCRnRA  
PSC Counter  
OCRnSA  
OCRnRB  
OCRnSB  
0
0
On-Time 0  
On-Time 1  
PSCOUTn0  
PSCOUTn1  
Dead-Time 0  
Dead-Time 1  
PSC Cycle  
The input clock of PSCR is given by CLKPSC.  
PSCOUTr0 and PSCOUTr1 signals are defined by On-Time 0, Dead-Time 0, On-Time 1 and  
Dead-Time 1 values with:  
On-Time 0 = OCRrRAH/L × 1/Fclkpsc  
On-Time 1 = OCRrRBH/L × 1/Fclkpsc  
Dead-Time 0 = (OCRrSAH/L + 2) × 1/Fclkpsc  
Dead-Time 1 = (OCRrSBH/L + 2) × 1/Fclkpsc  
Note:  
Minimal value for Dead-Time 0 and Dead-Time 1 = 2 × 1/Fclkpsc.  
152  
7734Q–AVR–02/12  
AT90PWM81/161  
13.5.2.2  
Two Ramp Mode  
In Two Ramp mode, the whole cycle is divided in two moments:  
• One moment for PSCr0 description with OT0 which gives the time of the whole moment  
• One moment for PSCr1 description with OT1 which gives the time of the whole moment  
Figure 13-5. PSCr0 & PSCr1 basic waveforms in Two Ramp mode.  
OCRnRA  
OCRnRB  
PSC Counter  
OCRnSA  
OCRnSB  
0
0
On-Time 0  
On-Time 1  
PSCOUTn0  
PSCOUTn1  
Dead-Time 0  
Dead-Time 1  
PSC Cycle  
PSCOUTr0 and PSCOUTr1 signals are defined by On-Time 0, Dead-Time 0, On-Time 1 and  
Dead-Time 1 values with:  
On-Time 0 = (OCRrRAH/L - OCRrSAH/L) × 1/Fclkpsc  
On-Time 1 = (OCRrRBH/L - OCRrSBH/L) × 1/Fclkpsc  
Dead-Time 0 = (OCRrSAH/L + 1) × 1/Fclkpsc  
Dead-Time 1 = (OCRrSBH/L + 1) × 1/Fclkpsc  
Note:  
Minimal value for Dead-Time 0 and Dead-Time 1 = 1/Fclkpsc.  
13.5.2.3  
One Ramp Mode  
In One Ramp mode, PSCOUTr0 and PSCOUTr1 outputs can overlap each other.  
153  
7734Q–AVR–02/12  
AT90PWM81/161  
Figure 13-6. PSCr0 & PSCr1 basic waveforms in One Ramp mode.  
OCRnRB  
OCRnSB  
OCRnRA  
PSC Counter  
OCRnSA  
0
On-Time 0  
On-Time 1  
PSCOUTn0  
PSCOUTn1  
Dead-Time 0  
Dead-Time 1  
PSC Cycle  
On-Time 0 = (OCRrRAH/L - OCRrSAH/L) × 1/Fclkpsc  
On-Time 1 = (OCRrRBH/L - OCRrSBH/L) × 1/Fclkpsc  
Dead-Time 0 = (OCRrSAH/L + 1) × 1/Fclkpsc  
Dead-Time 1 = (OCRrSBH/L - OCRrRAH/L) × 1/Fclkpsc  
Note:  
Minimal value for Dead-Time 0 = 1/Fclkpsc.  
13.5.3  
Fifty Percent Waveform Configuration  
When PSCOUTr0 and PSCOUTr1 have the same characteristics, it’s possible to configure the  
PSCR in a Fifty Percent mode. When the PSCR is in this configuration, it duplicates the  
OCRrSBH/L and OCRrRBH/L registers in OCRrSAH/L and OCRrRAH/L registers. So it is not  
necessary to program OCRrSAH/L and OCRrRAH/L registers.  
13.6 Update of Values  
The update of PSCR waveform registers are done in the following way:  
Immediately when the PSC is stopped  
At the PSC end of cycle when the PSC is running  
At the PSC end of cycle following the required condition when LOCK or AUTOLOCK modes  
are used  
To avoid asynchronous and incoherent values in a cycle, if an update of one of several values is  
necessary, all values are updated at the same time at the end of the cycle by the PSC. The new  
set of values is calculated by software and the update is initiated by software.  
154  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Figure 13-7. Update at the end of complete PSCR cycle.  
Regulation Loop  
Calculation  
Writting in  
PSC Registers  
Request for  
an Update  
Software  
Cycle  
With Set i  
Cycle  
With Set i  
Cycle  
With Set i  
Cycle  
With Set i  
PSC  
Cycle  
With Set j  
End of Cycle  
The software can stop the cycle before the end to update the values and restart a new PSCR  
cycle.  
13.6.1  
Value Update Synchronization  
New timing values or PSCR output configuration can be written during the PSCR cycle. Thanks  
to LOCK and AUTOLOCK configuration bits, the new whole set of values can be taken into  
account with the following conditions:  
• When AUTOLOCK configuration is selected, the update of the PSCR internal registers will be  
done at the end of the PSCR cycle following a write in the Output Compare Register RB. The  
AUTOLOCK configuration bit is taken into account at the end of the first PSCR cycle  
• When LOCK configuration bit is set, there is no update. The update of the PSCR internal  
registers will be done at the end of the PSCR cycle if the LOCK bit is released to zero  
The registers which update is synchronized thanks to LOCK and AUTOLOCK are OCRrSAH/L,  
OCRrRAH/L, OCRrSBH/L, OCRrRBH/L and PSOCr. PISELrA1 and PISELrB1 bits of PSOCr are  
immediatly updated in order to behave as PISELrA0 and PISELrB0.  
See these register’s description starting on page 172.  
When set, AUTOLOCK configuration bit prevails over LOCK configuration bit.  
See “PCNF0 - PSCR Configuration Register” on page 173.  
13.7 Enhanced resolution  
The PSCR includes the same resolution enhancement as in PSC. Please see  
Section “Enhanced Resolution”, page 111 for the description of this feature.  
13.8 PSCR Inputs  
Each part A or B of PSCR has its own system to take into account one PSCR input. According to  
PSCR Input A/B Control Register (see description “PFRC0A - PSCR Input A Control Register”  
on page 175), PSCrIN0/1 input can act has a Retrigger or Fault input.  
This system A or B is also configured by this PSCR Input A/B Control Register (PFRCrA/B).  
155  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Figure 13-8. PSCR input module.  
PAOCrA  
(PAOCrB)  
0
0
1
PSCINr  
0
1
AC1O: Analog  
Comparator  
Output  
PSCR Input A  
(PSCR Input B)  
0
1
Digital  
Filter  
0
PSCINrA  
PSCINrB  
PFLTErA  
(PFLTErB)  
CLK  
PSC  
1
1
PELEVrA / PCAErA  
(PELEVrB) (PCAErB)  
2
4
Input  
Processing  
(retriggering ...)  
PISELrA1 PISELrA0  
(PISELrB1) (PISELrB0)  
PRFMrA3:0  
(PRFMrB3:0)  
CLK  
PSC  
PSC Core  
(Counter,  
Waveform  
Generator, ...)  
Output  
Control  
PSCOUTr0  
(PSCOUTr1)  
CLK  
PSC  
13.8.1  
13.8.2  
PSCR Retrigger Behavior versus PSCR running modes  
In two ramp or four ramp mode, Retrigger Inputs A or B cause the end of the corresponding  
cycle A or B and the beginning of the following cycle B or A.  
In one ramp mode, Retrigger Inputs A or B reset the current PSCR counting to zero.  
Retrigger PSCOUTr0 On External Event  
PSCOUTr0 output can be reset before end of On-Time 0 on the change on PSCr Input A. PSCr  
Input A can be configured to do not act or to act on level or edge modes. The polarity of PSCr  
Input A is configurable thanks to a sense control block. PSCr Input A can be the Output of the  
analog comparator or the PSCINr input.  
As the period of the cycle decreases, the instantaneous frequency of the two outputs increases.  
156  
7734Q–AVR–02/12  
AT90PWM81/161  
Figure 13-9. PSCOUTr0 retriggered by PSCr Input A (edge retriggering).  
On-Time 0  
On-Time 1  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
(falling edge)  
PSCn Input A  
(rising edge)  
Dead-Time 0  
Dead-Time 1  
Note:  
This example is given in “Input Mode 8” in “2 or 4 ramp mode”. See Figure 13-26 on page 166 for  
details.  
Figure 13-10. PSCOUTr0 retriggered by PSCr Input A (level acting).  
On-Time 0  
On-Time 1  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
(high level)  
PSCn Input A  
(low level)  
Dead-Time 0  
Dead-Time 1  
Note:  
This example is given in “Input Mode 1” in “2 or 4 ramp mode”. See Figure 13-15 on page 161 for  
details.  
13.8.3  
Retrigger PSCOUTr1 On External Event  
PSCOUTr1 output can be reset before end of On-Time 1 on the change on PSCr Input B. The  
polarity of PSCr Input B is configurable thanks to a sense control block. PSCr Input B can be  
configured to do not act or to act on level or edge modes. PSCr Input B can be the Output of the  
analog comparator or the PSCINr input.  
157  
7734Q–AVR–02/12  
AT90PWM81/161  
As the period of the cycle decreases, the instantaneous frequency of the two outputs increases.  
Figure 13-11. PSCOUTr1 retriggered by PSCr Input B (edge retriggering).  
On-Time 0  
On-Time 1  
PSCOUTn0  
PSCOUTn1  
PSCn Input B  
(falling edge)  
PSCn Input B  
(rising edge)  
Dead-Time 0  
Dead-Time 1  
Dead-Time 0  
Note:  
This example is given in “Input Mode 8” in “2 or 4 ramp mode”. See Figure 13-26 on page 166 for  
details.  
Figure 13-12. PSCOUTr1 retriggered by PSCr Input B (level acting).  
On-Time 0  
On-Time 1  
PSCOUTn0  
PSCOUTn1  
PSCn Input B  
(high level)  
PSCn Input B  
(low level)  
Dead-Time 0  
Dead-Time 1  
Dead-Time 0  
Note:  
This example is given in “Input Mode 1” in “2 or 4 ramp mode”. See Figure 13-15 on page 161 for  
details.  
13.8.3.1  
Burst Generation  
Note:  
On level mode, it’s possible to use PSCR to generate burst by using Input Mode 3 or Mode 4 (see  
Figure 13-19 on page 163 and Figure 13-20 on page 163 for details.)  
158  
7734Q–AVR–02/12  
AT90PWM81/161  
Figure 13-13. Burst generation.  
OFF  
BURST  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
(high level)  
PSCn Input A  
(low level)  
13.8.4  
PSCR Input Configuration  
The PSCR Input Configuration is done by programming bits in configuration registers.  
13.8.4.1  
Filter Enable  
If the “Filter Enable” bit is set, a digital filter of four cycles is inserted before evaluation of the sig-  
nal. The disable of this function is mainly needed for prescaled PSCR clock sources, where the  
noise cancellation gives too high latency.  
Important: If the digital filter is active, the level sensitivity is true also with a disturbed PSCR  
clock to deactivate the outputs (emergency protection of external component). Likewise when  
used as fault input, PSCr Input A or Input B have to go through PSCR to act on PSCOUTr0/1/2/3  
output. This way needs that CLKPSCR is running. So thanks to PSCR Asynchronous Output Con-  
trol bit (PAOCrA/B), PSCrIN0/1 input can deactivate directly the PSCR output. Notice that in this  
case, input is still taken into account as usually by Input Module System as soon as CLKPSCR is  
running.  
Figure 13-14. PSCR input filtering.  
CLK  
PSC  
Digital  
Filter  
PSCn Input A or B  
4 x CLK  
PSC  
PSC Input  
Module X  
Ouput  
Stage  
PSCOUTnX  
PIN  
13.8.4.2  
Signal Polarity  
One can select the active edge (edge modes) or the active level (level modes). See PELEV0x bit  
description in Section “PFRC0A - PSCR Input A Control Register”, page 175.  
If PELEV0x bit set, the significant edge of PSCr Input A or B is rising (edge modes) or the active  
level is high (level modes) and vice versa for unset/falling/low.  
159  
7734Q–AVR–02/12  
 
AT90PWM81/161  
- In 2- or 4-ramp mode, PSCr Input A is taken into account only during Dead-Time0 and On-  
Time0 period (respectively Dead-Time1 and On-Time1 for PSCr Input B).  
- In 1-ramp-mode PSCR Input A or PSCR Input B act on the whole ramp.  
13.8.4.3  
Input Mode Operation  
Thanks to four configuration bits (PRFM3:0), it is possible to define all the modes of the PSCR  
input. These modes are listed in Table 13-5.  
Table 13-5. PSCR input mode operation.  
PRFM3:0  
Description  
PSCr Input has no action on PSCR output  
0
1
0000b  
See “PSCR Input Mode 1: Stop signal, Jump to Opposite Dead-Time and  
Wait” on page 161.  
See “PSCR Input Mode 2: Stop signal, Execute Opposite Dead-Time and  
Wait” on page 162.  
See “PSCR Input Mode 3: Stop signal, Execute Opposite while Fault  
active” on page 163.  
See “PSCR Input Mode 4: Deactivate outputs without changing timing” on  
page 164.  
See “PSCR Input Mode 5: Stop signal and Insert Dead-Time” on page  
164.  
See “PSCR Input Mode 6: Stop signal, Jump to Opposite Dead-Time and  
Wait” on page 165.  
0001b  
0010b  
0011b  
0100b  
0101b  
0110b  
2
3
4
5
6
See “PSCR Input Mode 7: Halt PSCR and Wait for Software Action” on  
page 165.  
See “PSCR Input Mode 8: Edge Retrigger PSC” on page 166.  
7
8
9
0111b  
1000b  
1001b  
See “PSCR Input Mode 9: Fixed Frequency Edge Retrigger PSC” on  
page 167.  
Reserved: Do not use  
10  
11  
12  
13  
1010b  
1011b  
1100b  
1101b  
See “PSCR Input Mode 14: Fixed Frequency Edge Retrigger PSCR and  
Deactivate Output” on page 168.  
Reserved: Do not use  
14  
15  
1110b  
1111b  
Note: All the following examples are given with rising edge or high level active inputs.  
160  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
13.9 PSCR Input Mode 1: Stop signal, Jump to Opposite Dead-Time and Wait  
Figure 13-15. PSCr behavior versus PSCr Input A in Fault Mode 1.  
DT0 OT0 DT1 OT1 DT0 OT0  
DT1 OT1  
DT0 OT0  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSC Input A  
PSC Input B  
PSCR Input A is taken into account during DT0 and OT0 only. It has no effect during DT1 and  
OT1.  
When PSCR Input A event occurs, PSCR releases PSCOUTr0, waits for PSCR Input A inactive  
state and then jumps and executes DT1 plus OT1.  
Figure 13-16. PSCr behavior versus PSCr Input B in Fault Mode 1.  
DT0 OT0 DT1 OT1 DT0 OT0 DT1 OT1  
DT0 OT0  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSC Input A  
PSC Input B  
PSCR Input B is take into account during DT1 and OT1 only. It has no effect during DT0 and  
OT0.  
When PSCR Input B event occurs, PSCR releases PSCOUTr1, waits for PSCR Input B inactive  
state and then jumps and executes DT0 plus OT0.  
161  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
13.10 PSCR Input Mode 2: Stop signal, Execute Opposite Dead-Time and Wait  
Figure 13-17. PSCr behavior versus PSCr Input A in Fault Mode 2.  
DT0 OT0 DT1 OT1 DT0 OT0 DT1 OT1  
DT0 OT0  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSC Input A  
PSC Input B  
PSCR Input A is take into account during DT0 and OT0 only. It has no effect during DT1 and  
OT1.  
When PSCr Input A event occurs, PSCR releases PSCOUTr0, jumps and executes DT1 plus  
OT1 and then waits for PSCR Input A inactive state.  
Even if PSCR Input A is released during DT1 or OT1, DT1 plus OT1 sub-cycle is always com-  
pletely executed.  
Figure 13-18. PSCr behavior versus PSCr Input B in Fault Mode 2.  
DT0 OT0 DT1 OT1 DT0 OT0 DT1 OT1 DT0 OT0  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSC Input A  
PSC Input B  
PSCR Input B is take into account during DT1 and OT1 only. It has no effect during DT0 and  
OT0.  
When PSCR Input B event occurs, PSCR releases PSCOUTr1, jumps and executes DT0 plus  
OT0 and then waits for PSCR Input B inactive state.  
Even if PSCR Input B is released during DT0 or OT0, DT0 plus OT0 sub-cycle is always com-  
pletely executed.  
162  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
13.11 PSCR Input Mode 3: Stop signal, Execute Opposite while Fault active  
Figure 13-19. PSCr behavior versus PSCr Input A in Mode 3.  
DT0 OT0  
DT1 OT1  
DT0 OT0 DT1 OT1  
DT1 OT1  
DT1 OT1  
DT0 OT0  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSC Input A  
PSC Input B  
PSCR Input A is taken into account during DT0 and OT0 only. It has no effect during DT1 and  
OT1.  
When PSCR Input A event occurs, PSCR releases PSCOUTr0, jumps and executes DT1 plus  
OT1 plus DT0 while PSCR Input A is in active state.  
Even if PSCR Input A is released during DT1 or OT1, DT1 plus OT1 sub-cycle is always com-  
pletely executed.  
Figure 13-20. PSCr behavior versus PSCr Input B in Mode 3.  
DT0 OT0  
DT1 OT1  
DT0 OT0  
DT1 OT1 DT0 OT0  
DT0 OT0  
DT0 OT0  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSC Input A  
PSC Input B  
PSCR Input B is taken into account during DT1 and OT1 only. It has no effect during DT0 and  
OT0.  
When PSCR Input B event occurs, PSCR releases PSCOUTR1, jumps and executes DT0 plus  
OT0 plus DT1 while PSCR Input B is in active state.  
Even if PSCR Input B is released during DT0 or OT0, DT0 plus OT0 sub-cycle is always com-  
pletely executed.  
163  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
13.12 PSCR Input Mode 4: Deactivate outputs without changing timing  
Figure 13-21. PSCR behavior versus PSCr Input A or Input B in Mode 4.  
DT0 OT0  
DT1 OT1  
DT0 OT0  
DT1 OT1  
DT0 OT0  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
or  
PSCn Input B  
Figure 13-22. PSCR behavior versus PSCr Input A or Input B in Fault Mode 4.  
DT0 OT0 DT1 OT1 DT0 OT0 DT1 OT1  
DT0 OT0  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
or  
PSCn Input B  
PSCr Input A or PSCr Input B act indifferently on On-Time0/Dead-Time0 or on On-Time1/Dead-  
Time1.  
13.13 PSCR Input Mode 5: Stop signal and Insert Dead-Time  
Figure 13-23. PSCR behavior versus PSCr Input A in Fault Mode 5.  
DT0 OT0  
DT0 OT0  
DT0 OT0  
DT1  
OT1  
DT1 OT1  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
or  
PSCn Input B  
Used in Fault mode 5, PSCr Input A or PSCr Input B act indifferently on On-Time0/Dead-Time0  
or on On-Time1/Dead-Time1.  
164  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
13.14 PSCR Input Mode 6: Stop signal, Jump to Opposite Dead-Time and Wait  
Figure 13-24. PSCR behavior versus PSCr Input A in Fault Mode 6.  
DT0 OT0 DT0 OT0  
DT0 OT0  
DT1 OT1  
DT1 OT1  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
or  
PSCn Input B  
Used in Fault mode 6, PSCr Input A or PSCr Input B act indifferently on On-Time0/Dead-Time0  
or on On-Time1/Dead-Time1.  
13.15 PSCR Input Mode 7: Halt PSCR and Wait for Software Action  
Figure 13-25. PSCR behavior versus PSCr Input A in Fault Mode 7.  
DT0 OT0  
DT0 OT0  
DT0 OT0  
DT1 OT1  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
or  
PSCn Input B  
Software Action (1)  
Note:  
1. Software action is the setting of the PRUNn bit in PCTLr register.  
Used in Fault mode 7, PSCr Input A or PSCr Input B act indifferently on On-Time0/Dead-Time0  
or on On-Time1/Dead-Time1.  
165  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
13.16 PSCR Input Mode 8: Edge Retrigger PSC  
Figure 13-26. PSCR behavior versus PSCr Input A in Mode 8.  
DT0 OT0  
DT0 OT0  
DT0 OT0  
DT1 OT1  
DT1 OT1  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
The output frequency is modulated by the occurrence of significative edge of retriggering input.  
Figure 13-27. PSCR behavior versus PSCr Input B in Mode 8.  
DT0 OT0  
DT0 OT0  
DT0 OT0  
DT1 OT1  
DT1 OT1  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input B  
or  
PSCn Input B  
The output frequency is modulated by the occurrence of significative edge of retriggering input.  
The retrigger event is taken into account only if it occurs during the corresponding On-Time.  
Note: In one ramp mode, the retrigger event on input A resets the whole ramp. So the PSCR  
doesn’t jump to the opposite dead-time.  
166  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
13.17 PSCR Input Mode 9: Fixed Frequency Edge Retrigger PSC  
Figure 13-28. PSCR behavior versus PSCr Input A in Mode 9.  
DT0 OT0  
DT0 OT0  
DT0 OT0  
DT1 OT1  
DT1 OT1  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
The output frequency is not modified by the occurrence of significative edge of retriggering input.  
Only the output is deactivated when significative edge on retriggering input occurs.  
Note: In this mode the output of the PSCR becomes active during the next ramp even if the  
Retrigger/Fault input is active. Only the significative edge of Retrigger/Fault input is taken into  
account.  
Figure 13-29. PSCR behavior versus PSCr Input B in Mode 9.  
DT0 OT0 DT0 OT0  
DT0 OT0  
DT1 OT1  
DT1 OT1  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input B  
The retrigger event is taken into account only if it occurs during the corresponding On-Time.  
167  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
13.18 PSCR Input Mode 14: Fixed Frequency Edge Retrigger PSCR and Deactivate Output  
Figure 13-30. PSCR behavior versus PSCr Input A in Mode 14.  
DT0 OT0  
DT0 OT0  
DT0 OT0  
DT0 OT0  
DT1 OT1  
DT1 OT1  
DT1 OT1  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input A  
The output frequency is not modified by the occurrence of significative edge of retriggering input.  
Figure 13-31. PSCR behavior versus PSCr Input B in Mode 14.  
DT0 OT0  
DT0 OT0  
DT0 OT0  
DT0 OT0  
DT1 OT1  
DT1 OT1  
DT1 OT1  
DT1 OT1  
PSCOUTn0  
PSCOUTn1  
PSCn Input B  
The output is deactivated while retriggering input is active.  
The output of the PSCR is set to an inactive state and the corresponding ramp is not aborted.  
The output stays in an inactive state while the Retrigger/Fault input is active. The PSCR runs at  
constant frequency.  
13.18.1 Available Input Mode according to Running Mode  
Some Input Modes are not consistent with some Running Modes. So Table 13-6 gives the input  
modes which are valid according to running modes.  
Table 13-6. Available input modes according to running modes.  
Input mode number:  
1 Ramp mode  
Valid  
2 Ramp mode  
Valid  
4 Ramp mode  
Valid  
1
2
3
4
5
6
7
8
9
Do not use  
Do not use  
Valid  
Valid  
Valid  
Valid  
Valid  
Valid  
Valid  
Do not use  
Do not use  
Valid  
Valid  
Valid  
Valid  
Valid  
Valid  
Valid  
Valid  
Valid  
Valid  
Valid  
Valid  
Valid  
168  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
Table 13-6. Available input modes according to running modes. (Continued)  
Input mode number:  
1 Ramp mode  
2 Ramp mode  
4 Ramp mode  
10  
11  
12  
13  
14  
15  
Do not use  
Valid  
Valid  
Valid  
Do not use  
13.18.2 Event Capture  
The PSCR can capture the value of time (PSCR counter) when a retrigger event or fault event  
occurs on PSCR inputs. This value can be read by software in PICRrH/L register.  
13.18.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 PICR1 Register before the next event occurs, the PICR1 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 PICR1 Register should be read as early in the inter-  
rupt 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.  
13.19 Analog Synchronization  
PSCR generates a signal to synchronize the sample and hold; synchronization is mandatory for  
measurements.  
This signal can be selected between all falling or rising edge of PSCr0 or PSCr1 outputs.  
13.20 Interrupt Handling  
List of interrupt sources:  
• Counter reload (end of On Time 1)  
• PSCR Input event (active edge or at the beginning of level configured event)  
13.21 PSC Clock Sources  
PSCR must be able to generate high frequency with enhanced resolution.  
The PSCR has two clock inputs:  
• CLK PLL from the PLL  
• CLK I/O  
169  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
Figure 13-32. Clock selection.  
CLK  
1
PLL  
CK  
PRESCALER  
CLK  
0
I/O  
PCLKSELr  
PPREr1/0  
CLK  
PSCr  
PCLKSELr bit in PSCR Configuration register (PCNFr) is used to select the clock source.  
PPREr1/0 bits in PSCR Control Register (PCTLr) are used to select the divide factor of the  
clock.  
Table 13-7. Output clock versus selection and prescaler.  
PCLKSELr  
PPREr1  
PPREr0  
CLKPSCr output  
CLK I/O  
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
CLK I/O / 4  
CLK I/O / 32  
CLK I/O / 256  
CLK PLL  
CLK PLL / 4  
CLK PLL / 32  
CLK PLL / 256  
13.22 Interrupts  
This section describes the specifics of the interrupt handling as performed in AT90PWM81/161.  
13.22.1 List of Interrupt Vector  
The PSCR provides 3 interrupt vectors:  
PSC0EC (End of Cycle): When enabled and when a match with OCRrRB occurs  
PSC0EEC (End of Enhanced Cycle): When enabled and when a match with OCRrRB  
occurs at the 15th enhanced cycle  
PSC0CAPT (Capture Event): When enabled and one of the two following events occurs :  
retrigger, capture of the PSCR counter or Synchro Error  
See PSC0 Interrupt Mask Register page 177 and PSC0 Interrupt Flag Register page 178.  
170  
7734Q–AVR–02/12  
 
AT90PWM81/161  
13.23 PSCR Register Definition  
13.23.1 PSOC0 - PSCR Synchro and Output Configuration  
Bit  
7
6
5
4
3
2
1
0
PISEL0A1 PISEL0B1 PSYNC01 PSYNC00  
-
POEN0B  
-
POEN0A  
PSOC0  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
• Bit 7– PISEL0A1: PSC Input Select for part A  
Together with PISEL0A0, defines active signal on PSCR part A.  
Table 13-8. PSC trigger & fault input selection.  
PISEL0A1  
PISEL0A0  
Description  
PSCINr  
0
0
1
1
0
1
0
1
Analog comparator output  
PSCINrA  
PSCINrB  
• Bit 6– PISEL0B1: PSCR Input Select for part B  
Together with PISEL0B0, defines active signal on PSCR part B.  
Table 13-9. PSC trigger & fault input selection.  
PISEL0B1  
PISEL0B0  
Description  
PSCINr  
0
0
1
1
0
1
0
1
Analog comparator output  
PSCINrA  
PSCINrB  
• Bit 5:4 – PSYNC01:0: Synchronization Out for ADC Selection)  
Select the polarity and signal source for generating a signal which will be sent to the ADC for  
synchronization.  
Table 13-10. Synchronization source description in one/two/four Ramp modes.  
PSYNC01  
PSYNC00  
Description  
0
0
Send signal on leading edge of PSCOUT00 (match with OCR0SA)  
Send signal on trailing edge of PSCOUT00 (match with OCR0RA or  
fault/retrigger on part A)  
0
1
1
1
0
1
Send signal on leading edge of PSCOUT01 (match with OCR0SB)  
Send signal on trailing edge of PSCOUT01 (match with OCR0RB or  
fault/retrigger on part B)  
• Bit 3 – Reserved  
• Bit 2 – POEN0B: PSCR OUT Part B Output Enable  
When this bit is clear, I/O pin affected to PSCOUT01 acts as a standard port.  
171  
7734Q–AVR–02/12  
 
 
 
 
 
 
AT90PWM81/161  
When this bit is set, I/O pin affected to PSCOUT01 is connected to the PSCR waveform genera-  
tor B output and is set and clear according to the PSCR operation.  
• Bit 1 – Reserved  
• Bit 0 – POEN0A: PSCR OUT Part A Output Enable  
When this bit is clear, I/O pin affected to PSCOUT00 acts as a standard port.  
When this bit is set, I/O pin affected to PSCOUT00 is connected to the PSCR waveform genera-  
tor A output and is set and clear according to the PSCR operation.  
13.23.2 OCR0SAH and OCR0SAL - Output Compare SA Register  
Bit  
7
6
5
4
3
2
1
0
OCR0SA[11:8]  
OCR0SAH  
OCR0SAL  
OCR0SA[7:0]  
Read/Write  
Initial Value  
W
0
W
W
0
W
0
W
0
W
0
W
0
W
0
0
13.23.3 OCR0RAH and OCR0RAL - Output Compare RA Register  
Bit  
7
6
5
4
3
2
1
0
OCR0RA[11:8]  
OCR0RAH  
OCR0RAL  
OCR0RA[7:0]  
Read/Write  
Initial Value  
W
0
W
W
0
W
0
W
0
W
0
W
0
W
0
0
13.23.4 OCR0SBH and OCR0SBL - Output Compare SB Register  
Bit  
7
6
5
4
3
2
1
0
OCR0SB[11:8]  
OCR0SBH  
OCR0SBL  
OCR0SB[7:0]  
Read/Write  
Initial Value  
W
0
W
W
0
W
0
W
0
W
0
W
0
W
0
0
13.23.5 OCR0RBH and OCR0RBL - Output Compare RB Register  
Bit  
7
6
5
4
3
2
1
0
OCR0RB[15:12]  
OCR0RB[7:0]  
OCR0RB[11:8]  
OCR0RBH  
OCR0RBL  
Read/Write  
Initial Value  
W
0
W
0
W
0
W
0
W
0
W
0
W
0
W
0
The Output Compare Registers RA, RB, SA and SB contain a 12-bit value that is continuously  
compared with the PSCR counter value. A match can be used to generate an Output Compare  
interrupt, or to generate a waveform output on the associated pin.  
The Output Compare Registers RB contains also a 4-bit value that is used for the flank width  
modulation.  
The Output Compare Registers are 12-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.  
172  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
13.23.6 PCNF0 - PSCR Configuration Register  
Bit  
7
6
5
4
3
2
1
0
PFIFTY0  
PALOCK0 PLOCK0  
PMODE01 PMODE00 POP0  
PCLKSEL0 -  
PCNF0  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
• Bit 7 - PFIFTY0: PSCR Fifty  
Writing this bit to one, set the PSCR in a fifty percent mode where only OCR0RBH/L and  
OCR0SBH/L are used. They are duplicated in OCR0RAH/L and OCR0SAH/L during the update  
of OCR0RBH/L. This feature is useful to perform fifty percent waveforms.  
• Bit 6 - PALOCK0: PSCR Autolock  
When this bit is set, the Output Compare Registers RA, SA, SB, the Output Matrix POM2 and  
the PSCR Output Configuration PSOC0 can be written without disturbing the PSCR cycles. The  
update of the PSCR internal registers will be done at the end of the PSCR cycle if the Output  
Compare Register RB has been the last written.  
When set, this bit prevails over LOCK (bit 5).  
• Bit 5 – PLOCK0: PSCR Lock  
When this bit is set, the Output Compare Registers RA, RB, SA, SB, the Output Matrix POM2  
and the PSCR Output Configuration PSOC0 can be written without disturbing the PSCR cycles.  
The update of the PSCR internal registers will be done if the LOCK bit is released to zero.  
• Bit 4:3 – PMODE01: 0: PSCR Mode  
Select the mode of PSC.  
Table 13-11. PSCR mode selection.  
PMODE01  
PMODE00  
Description  
0
0
1
1
0
1
0
1
One Ramp mode  
Two Ramp mode  
Four Ramp mode  
Reserved  
• Bit 2 – POP0: PSCR Output Polarity  
If this bit is cleared, the PSCR outputs are active Low.  
If this bit is set, the PSCR outputs are active High.  
• Bit 1 – PCLKSEL0: PSCR Input Clock Select  
This bit is used to select between CLKPF or CLKPS clocks.  
Set this bit to select the fast clock input (CLKPF).  
Clear this bit to select the slow clock input (CLKPS).  
• Bit 0 – Reserved  
173  
7734Q–AVR–02/12  
 
AT90PWM81/161  
13.23.7 PCTL0 - PSCR Control Register  
Bit  
7
6
5
4
3
2
1
0
PPRE01  
R/W  
0
PPRE00  
R/W  
0
PBFM01  
R/W  
PAOC0B  
PAOC0A  
PBFM00  
R/W  
PCCYC0  
PRUN0  
R/W  
0
PCTL0  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
0
0
• Bit 7:6 – PPRE01:0 : PSCR Prescaler Select  
This two bits select the PSCR input clock division factor. All generated waveform will be modified  
by this factor.  
Table 13-12. PSCR prescaler selection.  
PPRE01  
PPRE00  
Description  
0
0
1
1
0
1
0
1
No divider on PSCR input clock  
Divide the PSCR input clock by 4  
Divide the PSCR input clock by 32  
Divide the PSCR clock by 256  
174  
7734Q–AVR–02/12  
 
AT90PWM81/161  
• Bit 5- PBFM01: Balance Flank Width Modulation, bit 1  
Defines the Flank Width Modulation, together with PBFM00 bit.  
Table 13-13. Flank Width mode selection.  
PBFM01  
PBFM00  
Description  
0
0
Flank Width Modulation operates on RB (On-Time 1 only)  
Flank Width Modulation operates on RB + RA (On-Time 0 and On-  
Time 1)  
0
1
1
1
0
1
Flank Width Modulation operates on SB (Dead-Time 1 only) (1)  
Flank Width Modulation operates on SB +SA (Dead-Time 0 and  
Dead-Time 1)  
Note:  
1. In one ramp mode, changing SA or SA+SB also affect On-Time; see Figure 13-6 on page 154.  
• Bit 4 – PAOC0B: PSCR Asynchronous Output Control B  
When this bit is set, Fault input selected to block B can act directly to PSCOUT01 output. See  
Section “PSCR Input Configuration”, page 159.  
• Bit 3 – PAOC0A: PSCR Asynchronous Output Control A  
When this bit is set, Fault input selected to block A can act directly to PSCOUT00 output. See  
Section “PSCR Input Configuration”, page 159.  
• Bit 2- PBFM00: Balance Flank Width Modulation, bit 0  
Defines the Flank Width Modulation, together with PBFM01 bit.  
• Bit 1 – PCCYC0: PSCR Complete Cycle  
When this bit is set, the PSCR completes the entire waveform cycle before halt operation  
requested by clearing PRUN0. This bit is not relevant in slave mode (PARUN0 = 1).  
• Bit 0 – PRUN0: PSCR Run  
Writing this bit to one starts the PSCR.  
When set, this bit prevails over PARUN0 bit.  
13.23.8 PFRC0A - PSCR Input A Control Register  
Bit  
7
6
5
4
3
2
1
0
PCAE0A  
PISEL0A0 PELEV0A PFLTE0A PRFM0A3 PRFM0A2 PRFM0A1 PRFM0A0 PFRC0A  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
13.23.9 PFRC0B - PSCR Input B Control Register  
Bit  
7
6
5
4
3
2
1
0
PCAE0B  
PISEL0B0 PELEV0B PFLTE0B PRFM0B3 PRFM0B2 PRFM0B1 PRFM0B0 PFRC0B  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
The Input Control Registers are used to configure the 2 PSC’s Retrigger/Fault block A & B. The  
2 blocks are identical, so they are configured on the same way.  
175  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
• Bit 7 – PCAE0x: PSCR Capture Enable Input Part x  
Writing this bit to one enables the capture function when external event occurs on input selected  
as input for Part x (see PISEL0x0 bit in the same register).  
• Bit 6 – PISEL0x0: PSCR Input Select for Part x  
Together with PISEL0x1 in PSOC0 register, defines active signal on PSC module A. See Table  
13-8 on page 171 and Table 13-9 on page 171.  
• Bit 5 –PELEV0x: PSCR Edge Level Selector of Input Part x  
When this bit is clear, the falling edge or low level of selected input generates the significative  
event for retrigger or fault function.  
When this bit is set, the rising edge or high level of selected input generates the significative  
event for retrigger or fault function.  
• Bit 4 – PFLTE0x: PSCR Filter Enable on Input Part x  
Setting this bit (to one) activates the Input Capture Noise Canceler. When the noise canceler is  
activated, the input from the retrigger pin is filtered. The filter function requires four successive  
equal valued samples of the retrigger pin for changing its output. The Input Capture is therefore  
delayed by four oscillator cycles when the noise canceler is enabled.  
• Bit 3:0 – PRFM0x3:0: PSCR Fault Mode  
These four bits define the mode of operation of the Fault or Retrigger functions. (See Table 13-5  
on page 160 for more explanations).  
Table 13-14. Level sensitivity and Fault mode operation.  
PRFM0x3:0  
Description  
No action, PSCR Input is ignored  
0000b  
“PSCR Input Mode 1: Stop signal, Jump to Opposite Dead-Time and Wait”,  
page 161  
0001b  
“PSCR Input Mode 2: Stop signal, Execute Opposite Dead-Time and Wait”,  
page 162  
0010b  
0011b  
“PSCR Input Mode 3: Stop signal, Execute Opposite while Fault active”,  
page 163  
“PSCR Input Mode 4: Deactivate outputs without changing timing”, page 164  
0100b  
0101b  
“PSCR Input Mode 5: Stop signal and Insert Dead-Time”, page 164  
“PSCR Input Mode 6: Stop signal, Jump to Opposite Dead-Time and Wait”,  
page 165  
0110b  
“PSCR Input Mode 7: Halt PSCR and Wait for Software Action”, page 165  
0111b  
1000b  
1001b  
“PSCR Input Mode 8: Edge Retrigger PSC”, page 166  
“PSCR Input Mode 9: Fixed Frequency Edge Retrigger PSC”, page 167  
176  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Table 13-14. Level sensitivity and Fault mode operation. (Continued)  
PRFM0x3:0  
1010b  
Description  
Reserved (do not use)  
1011b  
1100b  
1101b  
“PSCR Input Mode 14: Fixed Frequency Edge Retrigger PSCR and Deactivate  
Output”, page 168  
Reserved (do not use)  
1110b  
1111b  
13.23.10 PICR0H and PICR0L - PSCR Input Capture Register  
Bit  
7
6
5
4
3
2
1
0
PCST0  
PICR0[11:8]  
PICR0H  
PICR0L  
PICR0[7:0]  
Read/Write  
Initial Value  
R
0
R
0
R
0
R
0
R
0
R
0
R
0
R
0
• Bit 7 – PCST0: PSCR Capture Software Trig bit  
Set this bit to trigger off a capture of the PSCR counter. When reading, if this bit is set it means  
that the capture operation was triggered by PCST0 setting otherwise it means that the capture  
operation was triggered by a PSCR input.  
The Input Capture is updated with the PSCR counter value each time an event occurs on the  
enabled PSCR input pin (or optionally on the Analog Comparator output) if the capture function  
is enabled (bit PCAE0x in PFRC0x register is set).  
The Input Capture Register is 12-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 or  
12-bit registers.  
13.23.11 PIM0 - PSCR Interrupt Mask Register  
Bit  
7
6
5
-
4
3
2
-
1
0
-
-
PEVE0B  
R/W  
PEVE0A  
R/W  
PEOEPE0 PEOPE0  
PIM0  
Read/Write  
Initial Value  
R
0
R
0
R
0
R
0
R
0
R/W  
0
0
0
• Bit 7- 5 – Reserved  
• Bit 4 – PEVE0B: PSCR External Event B Interrupt Enable  
When this bit is set, an external event which can generates a capture from Retrigger/Fault block  
B generates also an interrupt.  
• Bit 3 – PEVE0A: PSCR External Event A Interrupt Enable  
When this bit is set, an external event which can generates a capture from Retrigger/Fault block  
A generates also an interrupt.  
• Bit 2 – Reserved  
177  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
• Bit 1– PEOEPE0: PSCR End Of Enhanced Cycle Interrupt Enable  
When this bit is set, an interrupt is generated when PSC reduced reaches the end of the 15th  
PSC cycle. This allows to update the PSCR values in the interrupt routine and to start a new  
enhanced cycle with the new values at the next PSCR cycle end.  
• Bit 0 – PEOPE0: PSCR End Of Cycle Interrupt Enable  
When this bit is set, an interrupt is generated when PSCR reaches the end of the whole cycle.  
13.23.12 PIFR0 - PSCR Interrupt Flag Register  
Bit  
7
6
5
-
4
3
2
1
0
POAC0B  
POAC0A  
PEV0B  
R/W  
0
PEV0A  
R/W  
0
PRN01  
PRN00  
PEOP0  
R/W  
0
PIFR0  
Read/Write  
Initial Value  
R
0
R
0
R
0
R
0
R
0
• Bit 7 – POAC0B: PSCR Output B Activity  
This bit is set by hardware each time the output PSCOUT01 changes from 0 to 1 or from 1 to 0.  
Must be cleared by software by writing a one to its location.  
This feature is useful to detect that a PSCR output doesn’t change due to a frozen external input  
signal.  
• Bit 6 – POAC0A: PSCR Output A Activity  
This bit is set by hardware each time the output PSCOUT00 changes from 0 to 1 or from 1 to 0.  
Must be cleared by software by writing a one to its location.  
This feature is useful to detect that a PSCR output doesn’t change due to a freezen external  
input signal.  
• Bit 5 – Reserved  
• Bit 4 – PEV0B: PSCR External Event B Interrupt  
This bit is set by hardware when an external event which can generates a capture or a retrigger  
from Retrigger/Fault block B occurs.  
Must be cleared by software by writing a one to its location.  
This bit can be read even if the corresponding interrupt is not enabled (PEVE0B bit = 0).  
• Bit 3 – PEV0A: PSCR External Event A Interrupt  
This bit is set by hardware when an external event which can generates a capture or a retrigger  
from Retrigger/Fault block A occurs.  
Must be cleared by software by writing a one to its location.  
This bit can be read even if the corresponding interrupt is not enabled (PEVE0A bit = 0).  
• Bit 2:1 – PRN01:0 : PSCR Ramp Number  
Memorization of the ramp number when the last PEV0A or PEV0B occurred.  
178  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Table 13-15. PSCR ramp number description.  
PRN01  
PRN00  
Description  
0
0
1
1
0
1
0
1
The last event which has generated an interrupt occurred during ramp 1  
The last event which has generated an interrupt occurred during ramp 2  
The last event which has generated an interrupt occurred during ramp 3  
The last event which has generated an interrupt occurred during ramp 4  
• Bit 0 – PEOP0: End Of PSCR Interrupt  
This bit is set by hardware when PSCR achieves its whole cycle.  
Must be cleared by software by writing a one to its location.  
179  
7734Q–AVR–02/12  
AT90PWM81/161  
14. Serial Peripheral Interface – SPI:  
14.1 Features  
Full-duplex, three-wire synchronous data transfer  
Master or Slave operation  
LSB first or MSB first data transfer  
Seven programmable bit rates  
End of transmission interrupt flag  
Write collision flag protection  
Wake-up from idle mode  
Double speed (CK/2) Master SPI mode  
14.2 Overview  
The Serial Peripheral Interface (SPI) allows high-speed synchronous data transfer between the  
AT90PWM81/161 and peripheral devices or between several AVR devices.  
The AT90PWM81/161 SPI includes the following features.  
Figure 14-1. SPI block diagram (1)  
.
MISO  
clkIO  
MOSI  
SCK  
SS  
DIVIDER  
/2/4/8/16/32/64/128  
Note:  
1. Refer to Figure 2-1 on page 3, and Table 9-3 on page 75 for SPI pin placement.  
180  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
The interconnection between Master and Slave CPUs with SPI is shown in Figure 14-2. The sys-  
tem 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 Mas-  
ter 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.  
Figure 14-2. SPI Master-slave interconnection.  
SHIFT  
ENABLE  
The system is single buffered in the transmit direction and double buffered in the receive direc-  
tion. 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. Oth-  
erwise, 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 fclkio/4.  
181  
7734Q–AVR–02/12  
 
AT90PWM81/161  
When the SPI is enabled, the data direction of the MOSI, MISO, SCK, and SS pins is overridden  
according to Table 14-1. For more details on automatic port overrides, refer to “Alternate Port  
Functions” on page 73.  
Table 14-1. SPI pin overrides (1)  
.
Pin  
MOSI  
MISO  
SCK  
SS  
Direction, Master SPI  
Direction, Slave SPI  
User defined  
Input  
Input  
User defined  
Input  
User defined  
User defined  
Input  
Note:  
1. See “Alternate Functions of Port B” on page 75 for a detailed description of how to define the  
direction of the user defined SPI pins.  
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. For example, if MOSI is placed on pin PB2, replace DD_MOSI with DDB2 and  
DDR_SPI with DDRB.  
182  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
Assembly code example (1)  
SPI_MasterInit:  
; Set MOSI and SCK output, all others input  
ldi r17,(1<<DD_MOSI)|(1<<DD_SCK)  
out DDR_SPI,r17  
; Enable SPI, Master, set clock rate fck/16  
ldi r17,(1<<SPE)|(1<<MSTR)|(1<<SPR0)  
out SPCR,r17  
ret  
SPI_MasterTransmit:  
; Start transmission of data (r16)  
out SPDR,r16  
Wait_Transmit:  
; Wait for transmission complete  
sbis SPSR,SPIF  
rjmp Wait_Transmit  
ret  
C code example (1)  
void SPI_MasterInit(void)  
{
/* Set MOSI and SCK output, all others input */  
DDR_SPI = (1<<DD_MOSI)|(1<<DD_SCK);  
/* Enable SPI, Master, set clock rate fck/16 */  
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);  
}
void SPI_MasterTransmit(char cData)  
{
/* Start transmission */  
SPDR = cData;  
/* Wait for transmission complete */  
while(!(SPSR & (1<<SPIF)))  
;
}
Note:  
1. The example code assumes that the part specific header file is included.  
The following code examples show how to initialize the SPI as a Slave and how to perform a  
simple reception.  
183  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Assembly code example (1)  
SPI_SlaveInit:  
; Set MISO output, all others input  
ldi r17,(1<<DD_MISO)  
out DDR_SPI,r17  
; Enable SPI  
ldi r17,(1<<SPE)  
out SPCR,r17  
ret  
SPI_SlaveReceive:  
; Wait for reception complete  
sbis SPSR,SPIF  
rjmp SPI_SlaveReceive  
; Read received data and return  
in  
r16,SPDR  
ret  
C code example (1)  
void SPI_SlaveInit(void)  
{
/* Set MISO output, all others input */  
DDR_SPI = (1<<DD_MISO);  
/* Enable SPI */  
SPCR = (1<<SPE);  
}
char SPI_SlaveReceive(void)  
{
/* Wait for reception complete */  
while(!(SPSR & (1<<SPIF)))  
;
/* Return data register */  
return SPDR;  
}
Note:  
1. The example code assumes that the part specific header file is included.  
14.3 SS Pin Functionality  
14.3.1  
Slave Mode  
When the SPI is configured as a Slave, the Slave Select (SS) pin is always input. When SS is  
held low, the SPI is activated, and MISO becomes an output if configured so by the user. All  
other pins are inputs. When SS is driven high, all pins are inputs, and the SPI is passive, which  
184  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
means that it will not receive incoming data. Note that the SPI logic will be reset once the SS pin  
is driven high.  
The SS pin is useful for packet/byte synchronization to keep the slave bit counter synchronous  
with the master clock generator. When the SS pin is driven high, the SPI slave will immediately  
reset the send and receive logic, and drop any partially received data in the Shift Register.  
14.3.2  
Master Mode  
When the SPI is configured as a Master (MSTR in SPCR is set), the user can determine the  
direction of the SS pin.  
If SS is configured as an output, the pin is a general output pin which does not affect the SPI  
system. Typically, the pin will be driving the SS pin of the SPI Slave.  
If SS is configured as an input, it must be held high to ensure Master SPI operation. If the SS pin  
is driven low by peripheral circuitry when the SPI is configured as a Master with the SS pin  
defined as an input, the SPI system interprets this as another master selecting the SPI as a  
slave and starting to send data to it. To avoid bus contention, the SPI system takes the following  
actions:  
1. The MSTR bit in SPCR is cleared and the SPI system becomes a Slave. As a result of  
the SPI becoming a Slave, the MOSI and SCK pins become inputs.  
2. The SPIF flag in SPSR is set, and if the SPI interrupt is enabled, and the I-bit in SREG  
is set, the interrupt routine will be executed.  
Thus, when interrupt-driven SPI transmission is used in Master mode, and there exists a possi-  
bility that SS is driven low, the interrupt should always check that the MSTR bit is still set. If the  
MSTR bit has been cleared by a slave select, it must be set by the user to re-enable SPI Master  
mode.  
14.4 Data Modes  
There are four combinations of SCK phase and polarity with respect to serial data, which are  
determined by control bits CPHA and CPOL. The SPI data transfer formats are shown in Figure  
14-3 on page 186 and Figure 14-4 on page 186. Data bits are shifted out and latched in on  
opposite edges of the SCK signal, ensuring sufficient time for data signals to stabilize. This is  
clearly seen by summarizing Table 14-3 on page 187 and Table 14-4 on page 187, as done  
below:  
Table 14-2. CPOL functionality.  
Leading edge  
Sample (rising)  
Setup (rising)  
Sample (falling)  
Setup (falling)  
Trailing edge  
Setup (falling)  
Sample (falling)  
Setup (rising)  
Sample (rising)  
SPI mode  
CPOL=0, CPHA=0  
CPOL=0, CPHA=1  
CPOL=1, CPHA=0  
CPOL=1, CPHA=1  
0
1
2
3
185  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Figure 14-3. SPI transfer format with CPHA = 0.  
SCK (CPOL = 0)  
mode 0  
SCK (CPOL = 1)  
mode 2  
SAMPLE I  
MOSI/MISO  
CHANGE 0  
MOSI PIN  
CHANGE 0  
MISO PIN  
SS  
MSB first (DORD = 0) MSB  
LSB first (DORD = 1) LSB  
Bit 6  
Bit 1  
Bit 5  
Bit 2  
Bit 4  
Bit 3  
Bit 3  
Bit 4  
Bit 2  
Bit 5  
Bit 1  
Bit 6  
LSB  
MSB  
Figure 14-4. SPI transfer format with CPHA = 1.  
SCK (CPOL = 0)  
mode 1  
SCK (CPOL = 1)  
mode 3  
SAMPLE I  
MOSI/MISO  
CHANGE 0  
MOSI PIN  
CHANGE 0  
MISO PIN  
SS  
MSB first (DORD = 0)  
LSB first (DORD = 1)  
MSB  
LSB  
Bit 6  
Bit 1  
Bit 5  
Bit 2  
Bit 4  
Bit 3  
Bit 3  
Bit 4  
Bit 2  
Bit 5  
Bit 1  
Bit 6  
LSB  
MSB  
14.5 SPI registers  
14.5.1  
SPCR - SPI Control Register  
Bit  
7
6
5
4
3
2
1
0
SPIE  
R/W  
0
SPE  
R/W  
0
DORD  
R/W  
0
MSTR  
R/W  
0
CPOL  
R/W  
0
CPHA  
R/W  
0
SPR1  
R/W  
0
SPR0  
SPCR  
Read/Write  
Initial Value  
R/W  
0
• Bit 7 – SPIE: SPI Interrupt Enable  
This bit causes the SPI interrupt to be executed if SPIF bit in the SPSR Register is set and the if  
the Global Interrupt Enable bit in SREG is set.  
• Bit 6 – SPE: SPI Enable  
When the SPE bit is written to one, the SPI is enabled. This bit must be set to enable any SPI  
operations.  
186  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
• Bit 5 – DORD: Data Order  
When the DORD bit is written to one, the LSB of the data word is transmitted first.  
When the DORD bit is written to zero, the MSB of the data word is transmitted first.  
• Bit 4 – MSTR: Master/Slave Select  
This bit selects Master SPI mode when written to one, and Slave SPI mode when written logic  
zero. If SS is configured as an input and is driven low while MSTR is set, MSTR will be cleared,  
and SPIF in SPSR will become set. The user will then have to set MSTR to re-enable SPI Mas-  
ter mode.  
• Bit 3 – CPOL: Clock Polarity  
When this bit is written to one, SCK is high when idle. When CPOL is written to zero, SCK is low  
when idle. Refer to Figure 14-3 on page 186 and Figure 14-4 on page 186 for an example. The  
CPOL functionality is summarized below:  
Table 14-3. CPOL functionality.  
CPOL  
Leading edge  
Rising  
Trailing edge  
Falling  
0
1
Falling  
Rising  
• Bit 2 – CPHA: Clock Phase  
The settings of the Clock Phase bit (CPHA) determine if data is sampled on the leading (first) or  
trailing (last) edge of SCK. Refer to Figure 14-3 on page 186 and Figure 14-4 on page 186 for an  
example. The CPOL functionality is summarized below:  
Table 14-4. CPHA functionality.  
CPHA  
Leading edge  
Sample  
Trailing edge  
Setup  
0
1
Setup  
Sample  
• Bits 1, 0 – SPR1, SPR0: SPI Clock Rate Select 1 and 0  
These two bits control the SCK rate of the device configured as a Master. SPR1 and SPR0 have  
no effect on the Slave. The relationship between SCK and the clkIO frequency fclkio is shown in  
Table 14-5:  
Table 14-5. Relationship between SCK and the oscillator frequency.  
SPI2X  
SPR1  
SPR0  
SCK frequency  
fclkio/4  
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
fclkio/16  
fclkio/64  
fclkio/128  
fclkio/2  
fclkio/8  
fclkio/32  
fclkio/64  
187  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
14.5.2  
SPSR - SPI Status Register  
Bit  
7
6
5
R
0
4
R
0
3
R
0
2
R
0
1
R
0
0
SPIF  
R
WCOL  
SPI2X  
R/W  
0
SPSR  
Read/Write  
Initial Value  
R
0
0
• Bit 7 – SPIF: SPI Interrupt Flag  
When a serial transfer is complete, the SPIF flag is set. An interrupt is generated if SPIE in  
SPCR is set and global interrupts are enabled. If SS is an input and is driven low when the SPI is  
in Master mode, this will also set the SPIF flag. SPIF is cleared by hardware when executing the  
corresponding interrupt handling vector. Alternatively, the SPIF bit is cleared by first reading the  
SPI Status Register with SPIF set, then accessing the SPI Data Register (SPDR).  
• Bit 6 – WCOL: Write COLlision Flag  
The WCOL bit is set if the SPI Data Register (SPDR) is written during a data transfer. The  
WCOL bit (and the SPIF bit) are cleared by first reading the SPI Status Register with WCOL set,  
and then accessing the SPI Data Register.  
• Bit 5..1 – Res: Reserved Bits  
These bits are reserved bits in the AT90PWM81/161 and will always read as zero.  
• Bit 0 – SPI2X: Double SPI Speed Bit  
When this bit is written logic one the SPI speed (SCK Frequency) will be doubled when the SPI  
is in Master mode (see Table 14-5 on page 187). This means that the minimum SCK period will  
be two CPU clock periods. When the SPI is configured as Slave, the SPI is only guaranteed to  
work at fclkio/4 or lower.  
The SPI interface on the AT90PWM81/161 is also used for program memory and EEPROM  
downloading or uploading. See “Serial Programming Algorithm” on page 261 for serial program-  
ming and verification.  
14.5.3  
SPDR - SPI Data Register  
Bit  
7
6
5
4
3
2
1
0
SPD7  
R/W  
X
SPD6  
R/W  
X
SPD5  
R/W  
X
SPD4  
R/W  
X
SPD3  
R/W  
X
SPD2  
R/W  
X
SPD1  
R/W  
X
SPD0  
R/W  
X
SPDR  
Read/Write  
Initial Value  
Undefined  
• Bits 7:0 - SPD7:0: SPI Data  
The SPI Data Register is a read/write register used for data transfer between the Register File  
and the SPI Shift Register. Writing to the register initiates data transmission. Reading the regis-  
ter causes the Shift Register Receive buffer to be read.  
188  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
15. Voltage Reference and Temperature Sensor  
15.1 Features  
Accurate voltage reference of 2.56V  
Internal temperature sensor  
Possibility for runtime compensation of temperature drift in both voltage reference and on-chip  
oscillators  
Low power consumption  
15.2 On Chip voltage Reference and Temperature sensor overview  
A low power band-gap reference provides AT90PWM81/161 with an accurate On-chip Bandgap  
voltage of 1.100V (Vbg).  
Then when SW1 is off and SW2/SW3 is on, the bandgap voltage is multiplied and generates the  
internal reference VREF of 2.56V. This reference voltage is used as reference for the ADC, the  
DAC and can use a buffer with external decoupling capacitor (when SW0 is on) to enable excel-  
lent noise performance with minimum power consumption as shown on Figure 15-1 on page  
190.  
The selection of the Voltage Reference for all the analog components (ADC, DAC, Compara-  
tors) is done using the REFS1:0 bits in ADMUX register; see “ADMUX - ADC Multiplexer  
Register” on page 217.  
For conditions using the Bandgap and the internal voltage reference, see “Bandgap and Internal  
Voltage Reference Enable Signals and Start-up Time” on page 55.  
189  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
Figure 15-1. Reference circuitry.  
Aref  
SW0  
REFS0, REFS1  
are used to  
control  
AVcc  
SW0..3  
SW1  
SW2  
Vref  
Voltage Reference  
VPTAT  
Vbg  
/1.60  
BG Reference  
/2.13  
BG Calibration  
Fuses  
/3.20  
ADC  
/6.40  
BG Calibration  
Registers  
BGCCR, BGCRR  
Comp  
SW3  
AT90PWM81/161 has an On-chip temperature sensor for monitoring the die temperature. A volt-  
age Proportional-To-Absolute-Temperature, VPTAT, is generated in the voltage reference circuit  
and after buffering, is connected to the ADC multiplexer. This temperature sensor can be used  
for runtime compensation of temperature drift in both the voltage reference and the On-chip  
Oscillator. To get the absolute temperature in degrees Kelvin, the measured Vtemp voltage  
must be scaled with the Vtemp factory calibration value stored in the signature row. See  
Section “Temperature Measurement”, page 192 for details.  
Vbg and Vtemp can be measured with the integrated ADC by selecting the proper ADC channel  
with ADMUX (see “ADMUX - ADC Multiplexer Register” on page 217).  
15.3 Register Description  
15.3.1  
BGCCR – Bandgap Calibration Current Register  
Bit  
7
-
6
-
5
-
4
-
3
2
1
0
BGCC3  
R/W  
1
BGCC2  
R/W  
0
BGCC1  
R/W  
0
BGCC0  
R/W  
0
BGCCR  
Read/Write  
Initial Value  
-
-
-
-
0
0
0
0
190  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
• Bit 7:4 – Res: Reserved Bit  
This bit is reserved for future use.  
• Bit 3:0 – BGCC3:0: BG Calibration of PTAT Current  
These bits are used for trimming of the nominal value of the bandgap reference voltage. These  
bits are binary coded, so the lowest value for Vbg is reached when BGCC3:0 is 0000 and the  
maximum value when BGCC3:0 is 1111. The step size is approximately 5mV.  
Updating the BGCC bits will affect the BOD detection level. The BOD will react quickly to the  
new detection level.  
15.3.2  
BGCRR – Bandgap Calibration Resistor Register  
Bit  
7
6
5
4
-
3
2
1
0
-
-
-
BGCR3  
R/W  
1
BGCR2  
R/W  
0
BGCR1  
R/W  
0
BGCR0  
R/W  
0
BGCRR  
Read/Write  
Initial Value  
-
-
-
-
0
0
0
0
• Bit 7:4 – Res: Reserved Bit  
This bit is reserved for future use.  
• Bit 3:0 – BGCR3:0: BG Calibration of Resistor ladder  
These bits are used for temperature gradient adjustment of the bandgap reference. Figure 15-2  
on page 192 illustrates Vbg as a function of temperature. Vbg has a positive temperature coeffi-  
cient at low temperatures and negative temperature coefficient at high temperatures. Depending  
on the process variations, the top of the Vbg curve may be located at higher or lower  
temperatures.  
To minimize the temperature drift in the temperature range of interest, BGCRR is used to adjust  
the top of the curve towards the centre of the temperature range of interest. The BGCRR bits are  
thermometer coded, resulting in 5 possible settings: 0000, 0001, 0011, 0111, 1111. The value  
0000 shifts the top of the Vbg curve to the highest possible temperature, and the value 1111  
shifts the top of the Vbg curve to the lowest possible temperature.  
191  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Figure 15-2. Illustration of Vbg as a function of temperature.  
1.5  
BGCRR is used to move the top of the Vbg curve to the  
center of the temperature range of interest  
1.0  
Temperature range of interest  
0.5  
-40  
-20  
-0  
20  
40  
60  
80  
100  
Temperature (°C)  
15.4 Temperature Measurement  
The temperature measurement is based on an on-chip temperature sensor that is coupled to a  
single ended ADC12 channel, as shown on Figure 15-3.  
Figure 15-3. Temperature sensor circuitry.  
Enable when  
ADEN=1  
Enable when  
ADC Mux=1100  
VPTAT  
Current-voltage  
Convertor  
+
-
Vtemp  
ADC Mux=1100  
BG Reference  
Selecting the ADC12 channel by writing the MUX3..0 bits in ADMUX register to “1100” enables  
the temperature sensor (see “ADMUX - ADC Multiplexer Register” on page 217). The recom-  
mended ADC voltage reference source is the internal 2.56V voltage reference for temperature  
sensor measurement. When the temperature sensor is enabled, the ADC converter can be used  
in single conversion mode to measure the voltage over the temperature sensor. The amplifier  
allows to charge the ADC sample capacitor at full CKadc clock speed. The measured voltage  
has a linear relationship to temperature as described in Table 15-1 on page 193. When the volt-  
age reference equals 2.56V, the conversion result has approximately a 1LSB/°C (or 2.5mV/°C)  
192  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
correlation to temperature and the typical accuracy of the temperature measurement is 10°C  
after offset calibration.  
Table 15-1. Temperature vs. sensor output voltage (typical case).  
Temperature  
Voltage (mV)  
ADC  
-40°C  
600  
25°C  
762  
105°C  
125°C  
1012  
405  
240  
305  
The values described in Table 15-1 are typical values. However, due to the process variation the  
temperature sensor output voltage varies from one chip to another. To be capable of achieving  
more accurate results the temperature measurement can be calibrated in the application  
software.  
When using temperature sensor, the temperature (in Kelvin) is calculated as follows:  
T = A × Tptat + B, where  
A - Gain correction multiplier (constant '1', or unsigned fixed point number)  
B - Offset correction term (2. complement signed byte)  
T
ptat - ADC result when measuring temperature sensor voltage, VREF with 2.56V internal  
reference  
T - Temperature in Kelvin (°K = °C + 273)  
Example:  
If A = 0x80 (=1.00) and B = 8, and ADC result is 0x15E (=350), this gives a measured tempera-  
ture of:  
T = 1.00 × 350 + 8 = 358K (+85°C)  
15.4.1  
Manufacturing Calibration  
One can also use the calibration values available in the signature row. See “Reading the Signa-  
ture Row from Software” on page 243.  
The calibration values are determined from values measured during test at room temperature  
which is approximatively +25°C. Calibration measures are done at VCC = 3V and with ADC in  
internal VREF (1.1V) mode.  
The temperature in Celsius degrees can be calculated utilizing the formula:  
T = ((([(ADCH << 8) | ADCL] -(273 + 25-TSOFFSET)) × TSGAIN)/128) + 25  
Where:  
a. ADCH & ADCL are the ADC data registers.  
b. TSGAIN is the temperature sensor gain (unsigned fixed point 8-bit temperature sensor gain  
factor in 1/128th units stored as previously in the signature row at address 0x0007). See  
“Reading the Signature Row from Software” on page 243.  
c. TSOFFSET is the temperature sensor offset correction term (signed twos complement 7-bit  
temperature sensor offset reading stored as previously in the signature row at address  
0x0005).  
193  
7734Q–AVR–02/12  
 
AT90PWM81/161  
16. Analog Comparator  
The Analog Comparator compares the input values on the positive pin ACMPx and negative pin  
ACMPM or ACMPMx.  
16.1 Features  
Three analog comparators  
High speed analog comparators  
25mV or 10mV or 0 hysteresis  
Four reference levels  
Generation of configurable interrupts  
16.2 Overview  
The AT90PWM81/161 features three fast analog comparators.  
Each comparator has a dedicated input on the positive input, and the negative input of each  
comparator can be configured as:  
• A steady value among the four internal reference levels defined by the VREF selected thanks  
to the REFS1:0 bits in ADMUX register  
• A value generated from the internal DAC  
• An external analog input ACMPMx  
When the voltage on the positive ACMPn pin is higher than the voltage selected by the ACnM  
multiplexer on the negative input, the Analog Comparator output, ACnO, is set.  
Each comparator can trigger a separate interrupt, exclusive to the Analog Comparator. In addi-  
tion, the user can select Interrupt triggering on comparator output rise, fall or toggle.  
The interrupt flags can also be used to synchronize ADC or DAC conversions.  
Moreover, the comparator’s output of the comparator 1 can be set to trigger the Timer/Counter1  
Input Capture function.  
A block diagram of the comparators and their surrounding logic is shown in Figure 16-1 on page  
195.  
194  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
Figure 16-1. Analog comparator block diagram.  
AC1OI  
AC1OE  
ACMP1_OUT  
AC1O (to PSCR)  
AC1IF  
AC1H  
2
1 0  
ACMP1  
+
Band Gap  
Interrupt Sensitivity Control  
Analog Comparator 1 Interrupt  
-
AC1IE  
AC1IS1  
AC1IS0  
AC1EN  
T1 Capture Trigger  
ACMPM1  
AC1ICE  
AC2OI  
AC2OE  
AC1M  
ACMP2_OUT  
2
1 0  
AC2O (to PSC2)  
AC2IF  
ACMP2  
AC2H  
Band Gap  
Interrupt Sensitivity Control  
Analog Comparator 2 Interrupt  
2
1 0  
AC2IE  
+
AC2IS1  
AC2IS0  
-
ACMPM2  
AC3OEA  
AC3OE  
AC2EN  
ACMP3_OUT_A  
AC3OI  
AC2M  
2
1 0  
AC3O (to PSC2)  
AC3IF  
ACMP3_OUT  
ACMP3  
AC3H  
Band Gap  
2
1 0  
Interrupt Sensitivity Control  
Analog Comparator 3 Interrupt  
+
AC3IE  
AC3IS0  
AC3IS1  
-
ACMPM3  
ACMPM  
AC3EN  
DAC  
Result  
Vref  
DAC 10  
AC3M  
2
1 0  
DACEN  
Aref  
REFS0  
AVcc  
Vref  
Internal 2.56V  
Reference  
/1.60  
/2.13  
/3.20  
/6.40  
REFS1  
REFS0  
+REFS1  
Notes: 1. Refer to Figure 2-1 on page 3 and Figure 2-2 on page 4 for Analog Comparator pin placement.  
2. The voltage on VREF is defined in Table 17-3, “ADC voltage reference selection.,” on  
page 218.  
195  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Figure 16-2. Comparator PSC links.  
+
ACMP1  
-
ACMPM1  
AC1EN  
PSCINr  
PSCINrA  
PSCINrB  
PSCR  
PSCIN2  
ACMP2  
+
-
ACMPM2  
AC2EN  
PSCIN2A  
ACMP3  
PSC2  
+
-
ACMPM3  
AC3EN  
16.3 Shared pins between Analog Comparator and ADC  
Several Analog comparators input pins can also be used as ADC inputs, so it is possible to mea-  
sure the comparison voltages. However, when a comparator input is selected as the ADC input,  
a spike occurs during the sampling phase of the ADC. This may lead to an unwanted transition  
on the comparator output. So it is a safe software practice to devalidate the comparator output  
before measuring the voltage on one of the inputs.  
16.4 Analog Comparator Register Description  
Each analog comparator has its own control register.  
A dedicated register has been designed to consign the outputs and the flags of the three analog  
comparators.  
196  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
16.4.1  
AC1CON - Analog Comparator 1 Control Register  
Bit  
7
6
5
4
3
2
1
0
AC1EN  
R/W  
0
AC1IE  
R/W  
0
AC1IS1  
R/W  
0
AC1IS0  
-
AC1M2  
R/W  
0
AC1M1  
R/W  
0
AC1M0  
R/W  
0
AC1CON  
Read/Write  
Initial Value  
R
0
R/W  
0
• Bit 7– AC1EN: Analog Comparator 1 Enable Bit  
Set this bit to enable the analog comparator 1.  
Clear this bit to disable the analog comparator 1.  
• Bit 6– AC1IE: Analog Comparator 1 Interrupt Enable bit  
Set this bit to enable the analog comparator 1 interrupt.  
Clear this bit to disable the analog comparator 1 interrupt.  
• Bit 5, 4– AC1IS1, AC1IS0: Analog Comparator 1 Interrupt Select bit  
These two bits determine the sensitivity of the interrupt trigger.  
The different setting are shown in Table 16-1.  
Table 16-1. Interrupt sensitivity selection.  
AC1IS1  
AC1IS0  
Description  
0
0
1
1
0
1
0
1
Comparator Interrupt on output toggle  
Reserved  
Comparator interrupt on output falling edge  
Comparator interrupt on output rising edge  
• Bit 3– Reserved  
• Bit 2, 1, 0– AC1M2, AC1M1, AC1M0: Analog Comparator 1 Multiplexer register  
These three bits determine the input of the negative input of the analog comparator.  
The different settings are shown in Table 16-2.  
Table 16-2. Analog Comparator 1 negative input selection.  
AC1M2  
AC1M1  
AC1M0  
Description  
“VREF”/6.40  
“VREF”/3.20  
“VREF”/2.13  
“VREF”/1.60  
Band gap voltage  
DAC result  
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
Analog comparator negative input (ACMPM1 pin)  
Analog comparator negative input (ACMPM pin)  
197  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
16.4.2  
AC2CON - Analog Comparator 2 Control Register  
Bit  
7
6
5
4
3
2
1
0
AC2EN  
R/W  
0
AC2IE  
R/W  
0
AC2IS1  
R/W  
0
AC2IS0  
R/W  
0
-
AC2M2  
R/W  
0
AC2M1  
R/W  
0
AC2M0  
R/W  
0
AC2CON  
Read/Write  
Initial Value  
-R  
0
• Bit 7– AC2EN: Analog Comparator 2 Enable bit  
Set this bit to enable the analog comparator 2.  
Clear this bit to disable the analog comparator 2.  
• Bit 6– AC2IE: Analog Comparator 2 Interrupt Enable bit  
Set this bit to enable the analog comparator 2 interrupt.  
Clear this bit to disable the analog comparator 2 interrupt.  
• Bit 5, 4– AC2IS1, AC2IS0: Analog Comparator 2 Interrupt Select bit  
These two bits determine the sensitivity of the interrupt trigger.  
The different setting are shown in Table 16-3.  
Table 16-3. Interrupt sensitivity selection.  
AC2IS1  
AC2IS0  
Description  
0
0
1
1
0
1
0
1
Comparator Interrupt on output toggle  
Reserved  
Comparator interrupt on output falling edge  
Comparator interrupt on output rising edge  
• Bit 3– Reserved  
• Bit 2, 1, 0– AC2M2, AC2M1, AC2M0: Analog Comparator 2 Multiplexer register  
These three bits determine the input of the negative input of the analog comparator.  
The different setting are shown in Table 16-4.  
Table 16-4. Analog Comparator 2 negative input selection.  
AC2M2  
AC2M1  
AC2M0  
Description  
“VREF”/6.40  
“VREF”/3.20  
“VREF”/2.13  
“VREF”/1.60  
Band gap voltage  
DAC result  
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
Analog comparator negative input (ACMPM2 pin)  
Analog comparator negative input (ACMPM pin)  
198  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
16.4.3  
AC3CON - Analog Comparator 3 Control Register  
Bit  
7
6
5
4
3
2
1
0
AC3EN  
R/W  
0
AC3IE  
R/W  
0
AC3IS1  
R/W  
0
AC3IS0  
R/W  
0
AC3OEA  
AC3M2  
R/W  
0
AC3M1  
R/W  
0
AC3M0  
R/W  
0
AC3CON  
Read/Write  
Initial Value  
-
0
• Bit 7– AC3EN: Analog Comparator 3 Enable Bit  
Set this bit to enable the analog comparator 3.  
Clear this bit to disable the analog comparator 3.  
• Bit 6– AC3IE: Analog Comparator 3 Interrupt Enable bit  
Set this bit to enable the analog comparator 3 interrupt.  
Clear this bit to disable the analog comparator 3 interrupt.  
• Bit 5, 4– AC3IS1, AC3IS0: Analog Comparator 3 Interrupt Select bit  
These 2 bits determine the sensitivity of the interrupt trigger.  
The different setting are shown in Table 16-5.  
Table 16-5. Interrupt sensitivity selection.  
AC3IS1  
AC3IS0  
Description  
0
0
1
1
0
1
0
1
Comparator interrupt on output toggle  
Reserved  
Comparator interrupt on output falling edge  
Comparator interrupt on output rising edge  
• Bit 3– AC3OEA: Analog Comparator 3 Alternate Output Enable  
Set this bit to enable the analog comparator 3 alternate output pin.  
Clear this bit to disable the analog comparator 3 alternate output pin.  
• Bit 2, 1, 0– AC3M2, AC3M1, AC3M0: Analog Comparator 3 Multiplexer register  
These 3 bits determine the input of the negative input of the analog comparator.  
The different setting are shown in Table 16-6.  
Table 16-6. Analog Comparator 2 negative input selection.  
AC3M2  
AC3M1  
AC3M0  
Description  
“VREF”/6.40  
“VREF”/3.20  
“VREF”/2.13  
“VREF”/1.60  
Band gap voltage  
DAC result  
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
Analog comparator negative input (ACMPM3 pin)  
Analog comparator negative input (ACMPM pin)  
199  
7734Q–AVR–02/12  
 
 
 
 
 
AT90PWM81/161  
16.4.4  
ACnECON - Analog Comparator n Extended Control Register  
Bit  
7
6
5
4
3
2
1
0
ACnOI  
R/W  
0
ACnOE  
R/W  
0
AC1ICE  
R/W  
0
ACnH2  
R/W  
0
ACnH1  
R/W  
0
ACnH0  
R/W  
0
ACnECON  
Read/Write  
Initial Value  
0
0
• Bit 7..6– Reserved  
• Bit 5– AC1OI: Analog Comparator n Output Invert  
Set this bit to invert the analog comparator n output.  
Clear this bit to keep the analog comparator n output.  
• Bit 4– AC1OE: Analog Comparator n Output Enable  
Set this bit to enable the analog comparator n output pin.  
Clear this bit to disable the analog comparator n output pin.  
• Bit 3 – AC1ICE: Analog Comparator 1 Interrupt Capture Enable bit  
Set this bit to enable the input capture of the Timer/Counter1 on the analog comparator event.  
The comparator output is in this case directly connected to the input capture front-end logic,  
making the comparator utilize the noise canceler and edge select features of the  
Timer/Counter1 Input Capture interrupt. To make the comparator trigger the Timer/Counter1  
Input Capture interrupt, the ICIE1 bit in the Timer Interrupt Mask Register (TIMSK1) must be set.  
In case ICES1 bit (“TCCR1B - Timer/Counter1 Control Register B” on page 97) is set high, the  
rising edge of AC3O is the capture/trigger event of the Timer/Counter1, in case ICES1 is set to  
zero, it is the falling edge which is taken into account.  
Clear this bit to disable this function. In this case, no connection between the Analog Compara-  
tor and the input capture function exists.  
• Bit 2, 1, 0– ACnH2, ACnH1, ACnH0: Analog Comparator n Hysteresis select  
These 3 bits determine the hysteresis value of the analog comparator.  
The different setting are shown in Table 16-7.  
Table 16-7. Analog cComparator n hysteresis selection.  
AC1M2  
AC1M1  
AC1M0  
Description  
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
No hysteresis  
Hysteresis + 10mV  
Hysteresis - 10mV  
Hysteresis 10mV  
Reserved  
Hysteresis + 25mV  
Hysteresis - 25mV  
Hysteresis 25mV  
200  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
16.4.5  
ACSR - Analog Comparator Status Register  
Bit  
7
6
5
4
3
2
1
0
-
AC3IF  
R/W  
0
AC2IF  
R/W  
0
AC1IF  
R/W  
0
-
AC3O  
AC2O  
AC1O  
ACSR  
Read/Write  
Initial Value  
R/W  
0
-
R
0
R
0
R
0
0
• Bit 7– AC3IF: Analog Comparator 3 Interrupt Flag Bit  
This bit is set by hardware when comparator 3 output event triggers off the interrupt mode  
defined by AC3IS1 and AC3IS0 bits in AC3CON register.  
This bit is cleared by hardware when the corresponding interrupt vector is executed in case the  
AC3IE in AC3CON register is set. Anyway, this bit is cleared by writing a logical one on it.  
This bit can also be used to synchronize ADC or DAC conversions.  
• Bit 6– AC2IF: Analog Comparator 2 Interrupt Flag Bit  
This bit is set by hardware when comparator 2 output event triggers off the interrupt mode  
defined by AC2IS1 and AC2IS0 bits in AC2CON register.  
This bit is cleared by hardware when the corresponding interrupt vector is executed in case the  
AC2IE in AC2CON register is set. Anyway, this bit is cleared by writing a logical one on it.  
This bit can also be used to synchronize ADC or DAC conversions.  
• Bit 5– AC1IF: Analog Comparator 1 Interrupt Flag Bit  
This bit is set by hardware when comparator 1 output event triggers off the interrupt mode  
defined by AC1IS1 and AC1IS0 bits in AC1CON register.  
This bit is cleared by hardware when the corresponding interrupt vector is executed in case the  
AC1IE in AC1CON register is set. Anyway, this bit is cleared by writing a logical one on it.  
This bit can also be used to synchronize ADC or DAC conversions.  
• Bit 4– Reserved  
• Bit 3– AC3O: Analog Comparator 3 Output Bit  
AC2O bit is directly the output of the Analog comparator 2.  
Set when the output of the comparator is high.  
Cleared when the output comparator is low.  
• Bit 2– AC2O: Analog Comparator 2 Output Bit  
AC2O bit is directly the output of the Analog comparator 2.  
Set when the output of the comparator is high.  
Cleared when the output comparator is low.  
• Bit 1– AC1O: Analog Comparator 1 Output Bit  
AC1O bit is directly the output of the Analog comparator 1.  
Set when the output of the comparator is high.  
Cleared when the output comparator is low.  
• Bit 0– Reserved  
201  
7734Q–AVR–02/12  
 
AT90PWM81/161  
16.4.6  
DIDR0 - Digital Input Disable Register 0  
Bit  
7
6
5
4
3
2
1
0
ADC8D  
ACMP3D  
ADC7D  
AMP0-D  
ADC5D  
ACMP2D  
ADC4D  
ADC3D  
ADC2D  
ADC1D  
ADC0D  
ACMP1D  
DIDR0  
ACMP3MD ACMPMD ACMP2MD  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
• Bit 7:0 – ACMPMxD and ACMPxD: ACMPxMD, ACMPxD & APM0+Digital Input Disable  
When this bit is written logic one, the digital input buffer on the corresponding Analog pin is dis-  
abled. The corresponding PIN Register bit will always read as zero when this bit is set. When an  
analog signal is applied to one of these pins and the digital input from this pin is not needed, this  
bit should be written logic one to reduce power consumption in the digital input buffer.  
16.4.7  
DIDR1 - Digital Input Disable Register 1  
Bit  
7
6
5
4
3
2
1
0
-
-
-
-
ACMP1MD AMP0+D  
ADC10D  
ADC9D  
R/W  
0
DIDR1  
Read/Write  
Initial Value  
-
-
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
0
0
• Bit 3, 0: ACMPxMD, ACMPxD & APM0+ Digital Input Disable  
When this bit is written logic one, the digital input buffer on the corresponding analog pin is dis-  
abled. The corresponding PIN Register bit will always read as zero when this bit is set. When an  
analog signal is applied to one of these pins and the digital input from this pin is not needed, this  
bit should be written logic one to reduce power consumption in the digital input buffer.  
202  
7734Q–AVR–02/12  
 
AT90PWM81/161  
17. Analog to Digital Converter - ADC  
17.1 Features  
10-bit resolution  
0.5LSB integral non-linearity  
2LSB absolute accuracy  
8µs - 250µs conversion time  
Up to 120kSPS at maximum resolution  
11 multiplexed single ended input channels  
One differential input channels with accurate (5%) programmable gain 5, 10, 20, and 40  
Optional left adjustment for ADC result readout  
0 - VCC ADC input voltage range  
Selectable 2.56V ADC reference voltage  
Free running or single conversion mode  
ADC start conversion by auto triggering on interrupt sources  
Interrupt on ADC conversion complete  
Sleep mode noise canceler  
Temperature sensor  
The AT90PWM81/161 features a 10-bit successive approximation ADC. The ADC is connected  
to an 15-channel Analog Multiplexer which allows eleven single-ended input. The single-ended  
voltage inputs refer to 0V (GND).  
The device also supports 2 differential voltage input combinations which are equipped with a  
programmable gain stage, providing amplification steps of 14dB (5×), 20dB (10×), 26dB (20×),  
or 32dB (40×) on the differential input voltage before the A/D conversion. On the amplified chan-  
nels, 8-bit resolution can be expected.  
The ADC contains a Sample and Hold circuit which ensures that the input voltage to the ADC is  
held at a constant level during conversion. A block diagram of the ADC is shown in Figure 17-1  
on page 204.  
The ADC has a separate analog supply voltage pin, AVCC. AVCC must not differ more than 0.3V  
from VCC. See the paragraph “ADC Noise Canceler” on page 210 on how to connect this pin.  
Internal reference voltages of nominally 2.56V or AVCC are provided On-chip. The voltage refer-  
ence may be externally decoupled at the AREF pin by a capacitor for better noise performance.  
203  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Figure 17-1. Analog to digital converter block schematic.  
AREF/ADC6  
AVCC  
Internal 2.56V  
Ref er en ce  
Vref  
Logic  
REFS0,REFS1  
ADC0  
ADC1  
ADC2  
ADC3  
ADC4  
ADC5  
Coarse/ Fine DAC  
10  
10  
ADCH  
+
ADC8  
ADC9  
SAR  
-
10  
ADCL  
ADC10  
AMP0GS  
CKADC CKADC  
AMP0-/ADC7  
-
+
AMP0+  
CONTROL  
ADCCONVERSION  
COMPLETE IRQ  
Temp Sensor  
VCC/4  
GND  
Bandgap  
CK  
PRESCALER  
AMP0CSR  
REFS1  
REFS0  
ADLAR  
MUX3 MUX2  
ADMUX  
MUX1  
MUX0  
ADEN  
ADSC  
ADATE  
ADIF  
ADIE  
ADPS2  
ADPS1  
ADPS0  
ADCSRA  
Ed g e  
ADATE  
Detector  
3
-
ADTS2  
ADTS1  
ADTS0  
ADHSM ADNCDIS  
ADSSEN ADTS3  
ADCSRB  
204  
7734Q–AVR–02/12  
AT90PWM81/161  
17.2 Operation  
The ADC converts an analog input voltage to a 10-bit digital value through successive approxi-  
mation. The minimum value represents GND and the maximum value represents the voltage on  
the AREF pin minus 1LSB. Optionally, AVCC or an internal 2.56V reference voltage may be con-  
nected to the AREF pin by writing to the REFSn bits in the ADMUX Register. The internal  
voltage reference may thus be decoupled by an external capacitor at the AREF pin to improve  
noise immunity.  
The analog input channel are selected by writing to the MUX bits in ADMUX. Any of the ADC  
input pins, as well as GND and a fixed bandgap voltage reference, can be selected as single  
ended inputs to the ADC.  
The ADC is enabled by setting the ADC Enable bit, ADEN in ADCSRA. Voltage reference is set  
by the REFS1 and REFS0 bits in ADMUX register, whatever the ADC is enabled or not. The  
ADC does not consume power when ADEN is cleared, so it is recommended to switch off the  
ADC before entering power saving sleep modes.  
The ADC generates a 10-bit result which is presented in the ADC Data Registers, ADCH and  
ADCL. By default, the result is presented right adjusted, but can optionally be presented left  
adjusted by setting the ADLAR bit in ADMUX.  
If the result is left adjusted and no more than 8-bit precision is required, it is sufficient to read  
ADCH. Otherwise, ADCL must be read first, then ADCH, to ensure that the content of the Data  
Registers belongs to the same conversion. Once ADCL is read, ADC access to Data Registers  
is blocked. This means that if ADCL has been read, and a conversion completed before ADCH  
is read, neither register is updated and the result from the conversion is lost. When ADCH is  
read, ADC access to the ADCH and ADCL Registers is re-enabled.  
The ADC has its own interrupt which can be triggered when a conversion completes. The ADC  
access to the Data Registers is prohibited between reading of ADCH and ADCL, the interrupt  
will trigger even if the result is lost.  
17.3 Starting a Conversion  
A single conversion is started by writing a logical one to the ADC Start Conversion bit, ADSC.  
This bit stays high as long as the conversion is in progress and will be cleared by hardware  
when the conversion is completed. If a different data channel is selected while a conversion is in  
progress, the ADC will finish the current conversion before performing the channel change.  
Alternatively, a conversion can be triggered automatically by various sources. Auto Triggering is  
enabled by setting the ADC Auto Trigger Enable bit, ADATE in ADCSRA. The trigger source is  
selected by setting the ADC Trigger Select bits, ADTS in ADCSRB (see description of the ADTS  
bits for a list of the trigger sources). When a positive edge occurs on the selected trigger signal,  
the ADC prescaler is reset and a conversion is started. This provides a method of starting con-  
versions at fixed intervals. If the trigger signal is still set when the conversion completes, a new  
conversion will not be started. If another positive edge occurs on the trigger signal during con-  
version, the edge will be ignored. Note that an interrupt flag will be set even if the specific  
interrupt is disabled or the Global Interrupt Enable bit in SREG is cleared. A conversion can thus  
be triggered without causing an interrupt. However, the interrupt flag must be cleared in order to  
trigger a new conversion at the next interrupt event.  
Triggering from the PSC’s synchronization signal is different as there is no flag. In this case, a  
new conversion is started at each triggering signal. However, a single shot mode can be acti-  
205  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
vated by setting the bit ADSSEN in ADCSRB register. In this case the synchronization signal is  
blocked until the ADCH registed is read.  
Figure 17-2. ADC auto trigger logic.  
ADTS[2:0]  
PRESCALER  
CLKADC  
START  
ADATE  
ADIF  
SOURCE 1  
.
.
.
.
CONVERSION  
LOGIC  
EDGE  
DETECTOR  
SOURCE n  
ADSC  
Using the ADC Interrupt Flag as a trigger source makes the ADC start a new conversion as soon  
as the ongoing conversion has finished. The ADC then operates in Free Running mode, con-  
stantly sampling and updating the ADC Data Register. The first conversion must be started by  
writing a logical one to the ADSC bit in ADCSRA. In this mode the ADC will perform successive  
conversions independently of whether the ADC Interrupt Flag, ADIF is cleared or not. The free  
running mode is not allowed on the amplified channels.  
If Auto Triggering is enabled, single conversions can be started by writing ADSC in ADCSRA to  
one. ADSC can also be used to determine if a conversion is in progress. The ADSC bit will be  
read as one during a conversion, independently of how the conversion was started.  
17.4 Prescaling and Conversion Timing  
Figure 17-3. ADC prescaler.  
ADEN  
START  
Reset  
7-BIT ADC PRESCALER  
CK  
ADPS0  
ADPS1  
ADPS2  
ADC CLOCK SOURCE  
By default, the successive approximation circuitry requires an input clock frequency between  
50kHz and 2MHz to get maximum resolution. If a lower resolution than 10 bits is needed, the  
input clock frequency to the ADC can be higher than 2MHz to get a higher sample rate.  
The ADC module contains a prescaler, which generates an acceptable ADC clock frequency  
from any CPU frequency above 100kHz. The prescaling is set by the ADPS bits in ADCSRA.  
206  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
The prescaler starts counting from the moment the ADC is switched on by setting the ADEN bit  
in ADCSRA. The prescaler keeps running for as long as the ADEN bit is set, and is continuously  
reset when ADEN is low.  
When initiating a single ended conversion by setting the ADSC bit in ADCSRA, the conversion  
starts at the following rising edge of the ADC clock cycle. See “Changing Channel or Reference  
Selection” on page 209 for details on differential conversion timing.  
A normal conversion takes 13 ADC clock cycles. The first conversion after the ADC is switched  
on (ADEN in ADCSRA is set) takes 25 ADC clock cycles in order to initialize the analog circuitry.  
The actual sample-and-hold takes place 3.5 ADC clock cycles after the start of a normal conver-  
sion and 13.5 ADC clock cycles after the start of an first conversion. When a conversion is  
complete, the result is written to the ADC Data Registers, and ADIF is set. In Single Conversion  
mode, ADSC is cleared simultaneously. The software may then set ADSC again, and a new  
conversion will be initiated on the first rising ADC clock edge.  
When Auto Triggering is used, the prescaler is reset when the trigger event occurs. This assures  
a fixed delay from the trigger event to the start of conversion. In this mode, the sample-and-hold  
takes place two ADC clock cycles after the rising edge on the trigger source signal. Three addi-  
tional CPU clock cycles are used for synchronization logic.  
In Free Running mode, a new conversion will be started immediately after the conversion com-  
pletes, while ADSC remains high. For a summary of conversion times, see Table 17-1 on page  
209.  
Figure 17-4. ADC timing diagram, first conversion (single conversion mode).  
Next  
First Conversion  
Conversion  
Cycle Number  
1
2
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
1
2
3
ADC Clock  
ADEN  
ADSC  
ADIF  
Sign and MSB of Result  
ADCH  
ADCL  
LSB of Result  
MUX  
MUX and REFS  
Update  
Conversion  
Complete  
and REFS  
Update  
Sample & Hold  
207  
7734Q–AVR–02/12  
AT90PWM81/161  
Figure 17-5. ADC timing diagram, single conversion.  
One Conversion  
Next Conversion  
1
2
3
4
5
6
7
8
9
10  
11  
12  
13  
14  
15  
16  
1
2
3
Cycle Number  
ADC Clock  
ADSC  
ADIF  
ADCH  
Sign and MSB of Result  
LSB of Result  
ADCL  
Sample & Hold  
Conversion  
Complete  
MUX and REFS  
Update  
MUX and REFS  
Update  
Figure 17-6. ADC timing diagram, auto triggered conversion.  
One Conversion  
Next Conversion  
1
2
3
4
5
6
7
8
13  
14  
15  
16  
1
2
Cycle Number  
ADC Clock  
Trigger  
Source  
ADATE  
ADIF  
ADCH  
ADCL  
Sign and MSB of Result  
LSB of Result  
Sample &  
Hold  
Prescaler  
Reset  
Conversion  
Complete  
Prescaler  
Reset  
MUX and REFS  
Update  
Figure 17-7. ADC timing diagram, free running conversion.  
One Conversion  
Next Conversion  
14  
15  
16  
1
2
3
4
Cycle Number  
ADC Clock  
ADSC  
ADIF  
ADCH  
ADCL  
Sign and MSB of Result  
LSB of Result  
Sample & Hold  
Conversion  
Complete  
MUX and REFS  
Update  
208  
7734Q–AVR–02/12  
AT90PWM81/161  
Table 17-1. ADC conversion time.  
Normal  
conversion,  
single ended  
Auto triggered  
conversion  
Condition  
First conversion  
Sample & hold  
(cycles from start of conversion)  
13.5  
3.5  
4
Conversion time  
(cycles)  
25  
15.5  
16  
17.5 Changing Channel or Reference Selection  
The MUXn and REFS1:0 bits in the ADMUX Register are single buffered through a temporary  
register to which the CPU has random access. This ensures that the channels and reference  
selection only takes place at a safe point during the conversion. The channel and reference  
selection is continuously updated until a conversion is started. Once the conversion starts, the  
channel and reference selection is locked to ensure a sufficient sampling time for the ADC. Con-  
tinuous updating resumes in the last ADC clock cycle before the conversion completes (ADIF in  
ADCSRA is set). Note that the conversion starts on the following rising ADC clock edge after  
ADSC is written. The user is thus advised not to write new channel or reference selection values  
to ADMUX until one ADC clock cycle after ADSC is written.  
If Auto Triggering is used, the exact time of the triggering event can be indeterministic. Special  
care must be taken when updating the ADMUX Register, in order to control which conversion  
will be affected by the new settings.  
If both ADATE and ADEN is written to one, an interrupt event can occur at any time. If the  
ADMUX Register is changed in this period, the user cannot tell if the next conversion is based  
on the old or the new settings. ADMUX can be safely updated in the following ways:  
a. When ADATE or ADEN is cleared.  
b. During conversion, minimum one ADC clock cycle after the trigger event.  
c. After a conversion, before the interrupt flag used as trigger source is cleared.  
When updating ADMUX in one of these conditions, the new settings will affect the next ADC  
conversion.  
17.5.1  
ADC Input Channels  
When changing channel selections, the user should observe the following guidelines to ensure  
that the correct channel is selected:  
• In Single Conversion mode, always select the channel before starting the conversion. The  
channel selection may be changed one ADC clock cycle after writing one to ADSC. However,  
the simplest method is to wait for the conversion to complete before changing the channel  
selection  
• In Free Running mode, always select the channel before starting the first conversion. The  
channel selection may be changed one ADC clock cycle after writing one to ADSC. However,  
the simplest method is to wait for the first conversion to complete, and then change the  
channel selection. Since the next conversion has already started automatically, the next  
result will reflect the previous channel selection. Subsequent conversions will reflect the new  
channel selection  
209  
7734Q–AVR–02/12  
 
AT90PWM81/161  
• In Free Running mode, because the amplifier clear the ADSC bit at the end of an amplified  
conversion, it is not possible to use the free running mode, unless ADSC bit is set again by  
soft at the end of each conversion  
17.5.2  
ADC Voltage Reference  
The reference voltage for the ADC (VREF) indicates the conversion range for the ADC. Single  
ended channels that exceed VREF will result in codes close to 0x3FF. VREF can be selected as  
either AVCC, internal 2.56V reference, or external AREF pin.  
AVCC is connected to the ADC through a passive switch. The internal 2.56V reference is gener-  
ated from the internal bandgap reference (VBG) through an internal amplifier. If the external  
AREF pin is connected to the ADC, the reference voltage can be made more immune to noise  
by connecting a capacitor between the AREF pin and ground. VREF can also be measured at the  
AREF pin with a high impedant voltmeter. Note that VREF is a high impedant source, and only a  
capacitive load should be connected in a system.  
The user may switch between AVCC, AREF pin and 2.56V as reference selection. The first ADC  
conversion result after switching reference voltage source may be inaccurate, and the user is  
advised to discard this result.  
17.6 ADC Noise Canceler  
The ADC features a noise canceler that enables conversion during sleep mode to reduce noise  
induced from the CPU core and other I/O peripherals. The noise canceler can be used with ADC  
Noise Reduction and Idle mode. To make use of this feature, the following procedure should be  
used:  
a. Make sure the ADNCDIS bit is reset  
b. Make sure the ADATE bit is reset  
c. Make sure that the ADC is enabled and is not busy converting (ADSC reset). Single  
Conversion mode must be selected and the ADC conversion complete interrupt  
must be enabled  
d. Enter ADC Noise Reduction mode (or Idle mode). The ADC will start a conversion  
once the CPU has been halted  
e. If no other interrupts occur before the ADC conversion completes, the ADC inter-  
rupt will wake up the CPU and execute the ADC Conversion Complete interrupt  
routine. If another interrupt wakes up the CPU before the ADC conversion is com-  
plete, that interrupt will be executed, and an ADC Conversion Complete interrupt  
request will be generated when the ADC conversion completes. The CPU will  
remain in active mode until a new sleep command is executed  
Another possible procedure is possible for Auto trigger conversions:  
a. Make sure the ADNCDIS bit is set  
b. Make sure the ADATE bit is set  
c. Enter ADC Noise Reduction mode (or Idle mode). The ADC will start a conversion  
on the next triggering event  
d. If no other interrupts occur before the ADC conversion completes, the ADC inter-  
rupt will wake up the CPU and execute the ADC Conversion Complete interrupt  
routine. If another interrupt wakes up the CPU before the ADC conversion is com-  
plete, that interrupt will be executed, and an ADC Conversion Complete interrupt  
210  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
request will be generated when the ADC conversion completes. The CPU will  
remain in active mode until a new sleep command is executed  
Note that the ADC will not be automatically turned off when entering other sleep modes than Idle  
mode and ADC Noise Reduction mode. The user is advised to write zero to ADEN before enter-  
ing such sleep modes to avoid excessive power consumption.  
If the ADC is enabled in such sleep modes and the user wants to perform differential conver-  
sions, the user is advised to switch the ADC off and on after waking up from sleep to prompt an  
extended conversion to get a valid result.  
17.6.1  
Analog Input Circuitry  
The analog input circuitry for single ended channels is illustrated in Figure 17-8 An analog  
source applied to ADCn is subjected to the pin capacitance and input leakage of that pin, regard-  
less of whether that channel is selected as input for the ADC. When the channel is selected, the  
source must drive the S/H capacitor through the series resistance (combined resistance in the  
input path).  
The ADC is optimized for analog signals with an output impedance of approximately 5kW or  
less. If such a source is used, the sampling time will be negligible. If a source with higher imped-  
ance is used, the sampling time will depend on how long time the source needs to charge the  
S/H capacitor, witch can vary widely. The user is recommended to only use low impedant  
sources with slowly varying signals, since this minimizes the required charge transfer to the S/H  
capacitor.  
If differential gain channels are used, the input circuitry looks somewhat different, although  
source impedances of a few hundred kW or less is recommended.  
Signal components higher than the Nyquist frequency (fADC/2) should not be present for either  
kind of channels, to avoid distortion from unpredictable signal convolution. The user is advised  
to remove high frequency components with a low-pass filter before applying the signals as  
inputs to the ADC.  
Figure 17-8. Analog input circuitry.  
I
IH  
ADCn  
1..100kΩ  
C
= 14pF  
S/H  
I
IL  
V
/2  
CC  
17.6.2  
Analog Noise Canceling Techniques  
Digital circuitry inside and outside the device generates EMI which might affect the accuracy of  
analog measurements. If conversion accuracy is critical, the noise level can be reduced by  
applying the following techniques:  
211  
7734Q–AVR–02/12  
 
AT90PWM81/161  
a. Keep analog signal paths as short as possible. Make sure analog tracks run over  
the analog ground plane, and keep them well away from high-speed switching digi-  
tal tracks.  
b. The AVCC pin on the device should be connected to the digital VCC supply voltage  
via an LC network as shown in Figure 17-9.  
c. Use the ADC noise canceler function to reduce induced noise from the CPU.  
d. If any ADC port pins are used as digital outputs, it is essential that these do not  
switch while a conversion is in progress.  
Figure 17-9. ADC power connections.  
10µH  
VCC  
AREF  
AGND  
GND  
AVCC  
100nF  
Analog Ground Plane  
17.6.3  
17.6.4  
Offset Compensation Schemes  
The gain stage has a built-in offset cancellation circuitry that nulls the offset of differential mea-  
surements as much as possible. The remaining offset in the analog path can be measured  
directly by shortening both differential inputs using the AMPxIS bit with both inputs unconnected  
(see “AMP0CSR - Amplifier 0 Control and Status register” on page 225). This offset residue can be  
then subtracted in software from the measurement results. Using this kind of software based off-  
set correction, offset on any channel can be reduced below one LSB.  
ADC Accuracy Definitions  
An n-bit single-ended ADC converts a voltage linearly between GND and VREF in 2n steps  
(LSBs). The lowest code is read as 0, and the highest code is read as 2n-1.  
Several parameters describe the deviation from the ideal behavior:  
• Offset: The deviation of the first transition (0x000 to 0x001) compared to the ideal transition  
(at 0.5LSB). Ideal value: 0LSB  
212  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Figure 17-10. Offset error.  
Output Code  
Ideal ADC  
Actual ADC  
Offset  
Error  
V
Input Voltage  
REF  
• Gain Error: After adjusting for offset, the Gain Error is found as the deviation of the last  
transition (0x3FE to 0x3FF) compared to the ideal transition (at 1.5LSB below maximum).  
Ideal value: 0LSB  
Figure 17-11. Gain error.  
Gain  
Error  
Output Code  
Ideal ADC  
Actual ADC  
VREF  
Input Voltage  
• Integral Non-linearity (INL): After adjusting for offset and gain error, the INL is the maximum  
deviation of an actual transition compared to an ideal transition for any code. Ideal value:  
0LSB  
213  
7734Q–AVR–02/12  
AT90PWM81/161  
Figure 17-12. Integral non-linearity (INL).  
Output Code  
Ideal ADC  
Actual ADC  
VREF Input Voltage  
• Differential Non-linearity (DNL): The maximum deviation of the actual code width (the interval  
between two adjacent transitions) from the ideal code width (1LSB). Ideal value: 0LSB  
Figure 17-13. Differential non-linearity (DNL).  
Output Code  
0x3FF  
1 LSB  
DNL  
0x000  
0
V
Input Voltage  
REF  
• Quantization Error: Due to the quantization of the input voltage into a finite number of codes,  
a range of input voltages (1LSB wide) will code to the same value. Always 0.5LSB  
• Absolute Accuracy: The maximum deviation of an actual (unadjusted) transition compared to  
an ideal transition for any code. This is the compound effect of offset, gain error, differential  
error, non-linearity, and quantization error. Ideal value: 0.5LSB  
214  
7734Q–AVR–02/12  
AT90PWM81/161  
17.7 ADC Conversion Result  
After the conversion is complete (ADIF is high), the conversion result can be found in the ADC  
Result Registers (ADCL, ADCH).  
For single ended conversion, the result is:  
V
1023  
IN  
ADC = -------------------------  
V
REF  
where VIN is the voltage on the selected input pin and VREF the selected voltage reference (see  
Table 17-3 on page 218 and Table 17-4 on page 218). 0x000 represents analog ground, and  
0x3FF represents the selected reference voltage.  
If differential channels are used, the result is:  
(V  
V  
) ⋅ GAIN 512  
NEG  
POS  
ADC = -----------------------------------------------------------------------  
V
REF  
where VPOS is the voltage on the positive input pin, VNEG the voltage on the negative input pin,  
GAIN the selected gain factor and VREF the selected voltage reference. The result is presented  
in two’s complement form, from 0x200 (-512d) through 0x1FF (+511d). Note that if the user  
wants to perform a quick polarity check of the result, it is sufficient to read the MSB of the result  
(ADC9 in ADCH). If the bit is one, the result is negative, and if this bit is zero, the result is posi-  
tive. Figure 17-14 on page 216 shows the decoding of the differential input range.  
Table 17-2 on page 217 shows the resulting output codes if the differential input channel pair  
(ADCn - ADCm) is selected with a reference voltage of VREF  
.
215  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Figure 17-14. Differential measurement range.  
Output Code  
0x1FF  
0x000  
0
Differential Input  
Voltage (Volts)  
- V  
VREF/Gain  
REF/Gain  
0x3FF  
0x200  
216  
7734Q–AVR–02/12  
AT90PWM81/161  
Table 17-2. Correlation between input voltage and output codes.  
VADCn  
Read code  
0x1FF  
0x1FF  
0x1FE  
...  
Corresponding decimal value  
VADCm + VREF /GAIN  
511  
511  
510  
...  
VADCm + 0.999 VREF /GAIN  
VADCm + 0.998 VREF /GAIN  
...  
V
ADCm + 0.001 VREF /GAIN  
VADCm  
ADCm - 0.001 VREF /GAIN  
0x001  
0x000  
0x3FF  
...  
1
0
V
-1  
...  
...  
VADCm - 0.999 VREF /GAIN  
0x201  
0x200  
-511  
-512  
VADCm - VREF /GAIN  
Example 1:  
– ADMUX = 0xED (ADC3 - ADC2, 10× gain, 2.56V reference, left adjusted result)  
– Voltage on ADC3 is 300mV, voltage on ADC2 is 500mV  
– ADCR = 512 × 10 × (300 - 500) / 2560 = -400 = 0x270  
– ADCL will thus read 0x00, and ADCH will read 0x9C.  
Writing zero to ADLAR right adjusts the result: ADCL = 0x70, ADCH = 0x02  
Example 2:  
– ADMUX = 0xFB (ADC3 - ADC2, 1× gain, 2.56V reference, left adjusted result)  
– Voltage on ADC3 is 300mV, voltage on ADC2 is 500mV  
– ADCR = 512 × 1 × (300 - 500) / 2560 = -41 = 0x029  
– ADCL will thus read 0x40, and ADCH will read 0x0A.  
Writing zero to ADLAR right adjusts the result: ADCL = 0x00, ADCH = 0x29  
17.8 ADC Register Description  
The ADC of the AT90PWM81/161 is controlled through 3 different registers. The ADCSRA and  
The ADCSRB registers which are the ADC Control and Status registers, and the ADMUX which  
allows to select the VREF source and the channel to be converted.  
The conversion result is stored on ADCH and ADCL register which contain respectively the most  
significant bits and the less significant bits.  
17.8.1  
ADMUX - ADC Multiplexer Register  
Bit  
7
6
5
4
-
3
2
1
0
REFS1  
R/W  
0
REFS0  
R/W  
0
ADLAR  
R/W  
0
MUX3  
R/W  
0
MUX2  
R/W  
0
MUX1  
R/W  
0
MUX0  
R/W  
0
ADMUX  
Read/Write  
Initial Value  
-R  
0
217  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
• Bit 7, 6 – REFS1, 0: ADC VREF Selection Bits  
These 2 bits determine the voltage reference for the ADC and for the other analog devices.  
The different setting are shown in Table 17-3.  
Table 17-3. ADC voltage reference selection.  
REFS1  
REFS0  
Description  
Voltage reference  
External VREF  
AVCC  
PE3/AREF pin  
0
0
0
1
External voltage reference  
External capacitor for decoupling of  
the internal reference voltage  
1
1
0
1
Internal 2.56V reference voltage  
Internal 2.56V reference voltage  
PE3 pin free as port  
If these bits are changed during a conversion, the change will not take effect until this conversion  
is complete (it means while the ADIF bit in ADCSRA register is set).  
In case the internal VREF is selected, it is turned ON as soon as an analog feature needed it is  
set.  
• Bit 5 – ADLAR: ADC Left Adjust Result  
Set this bit to left adjust the ADC result.  
Clear it to right adjust the ADC result.  
The ADLAR bit affects the configuration of the ADC result data registers. Changing this bit  
affects the ADC data registers immediately regardless of any on going conversion. For a com-  
plete description of this bit, see Section “ADCH and ADCL - ADC Result Data Registers”,  
page 221.  
• Bit 3, 2, 1, 0 – MUX3, MUX2, MUX1, MUX0: ADC Channel Selection Bits  
These 4 bits determine which analog inputs are connected to the ADC input. The different set-  
ting are shown in Table 17-4.  
Table 17-4. ADC input channel selection.  
MUX3  
MUX2  
MUX1  
MUX0  
Description  
ADC0  
ADC1  
ADC2  
ADC3  
ADC4  
ADC5  
ADC6  
ADC7  
ADC8  
ADC9  
ADC10  
AMP0  
0
0
0
0
0
0
0
0
1
1
1
1
0
0
0
0
1
1
1
1
0
0
0
0
0
0
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
218  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Table 17-4. ADC input channel selection. (Continued)  
MUX3  
MUX2  
MUX1  
MUX0  
Description  
1
1
1
1
1
1
1
1
0
0
1
1
0
1
0
1
Temp sensor (Vtemp)  
VCC/4  
Bandgap (Vbg)  
GND  
If these bits are changed during a conversion, the change will not take effect until this conversion  
is complete (it means while the ADIF bit in ADCSRA register is set).  
17.8.2  
ADCSRA - ADC Control and Status Register A  
Bit  
7
6
5
4
3
2
1
0
ADEN  
ADSC  
ADATE  
R/W  
0
ADIF  
ADIE  
R/W  
0
ADPS2  
R/W  
0
ADPS1  
R/W  
0
ADPS0  
R/W  
0
ADCSRA  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R
0
• Bit 7 – ADEN: ADC Enable Bit  
Set this bit to enable the ADC.  
Clear this bit to disable the ADC.  
Clearing this bit while a conversion is running will take effect at the end of the conversion.  
• Bit 6– ADSC: ADC Start Conversion Bit  
Set this bit to start a conversion in single conversion mode or to start the first conversion in free  
running mode.  
Cleared by hardware when the conversion is complete. Writing this bit to zero has no effect.  
The first conversion performs the initialization of the ADC.  
• Bit 5 – ADATE: ADC Auto trigger Enable Bit  
Set this bit to enable the auto triggering mode of the ADC.  
Clear it to return in single conversion mode.  
In auto trigger mode the trigger source is selected by the ADTS bits in the ADCSRB register.  
See Table 17-6 on page 221.  
• Bit 4– ADIF: ADC Interrupt Flag  
Set by hardware as soon as a conversion is complete and the Data register are updated with the  
conversion result.  
Cleared by hardware when executing the corresponding interrupt handling vector.  
Alternatively, ADIF can be cleared by writing it to logical one.  
• Bit 3– ADIE: ADC Interrupt Enable Bit  
Set this bit to activate the ADC end of conversion interrupt.  
Clear it to disable the ADC end of conversion interrupt.  
• Bit 2, 1, 0– ADPS2, ADPS1, ADPS0: ADC Prescaler Selection Bits  
These 3 bits determine the division factor between the system clock frequency and input clock of  
the ADC.  
The different setting are shown in Table 17-5 on page 220.  
219  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Table 17-5. ADC prescaler selection.  
ADPS2  
ADPS1  
ADPS0  
Division factor  
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
2
2
4
8
16  
32  
64  
128  
17.8.3  
ADCSRB - ADC Control and Status Register B  
Bit  
7
6
5
-
4
3
2
1
0
ADHSM  
R/W  
0
ADNCDIS  
ADSSEN ADTS3  
ADTS2  
R/W  
0
ADTS1  
R/W  
0
ADTS0  
R/W  
0
ADCSRB  
Read/Write  
Initial Value  
R/W  
0
-
R/W  
0
R/W  
0
0
• Bit 7 – ADHSM: ADC High Speed Mode  
Writing this bit to one enables the ADC High Speed mode. Set this bit if you wish to convert with  
an ADC clock frequency higher than 200kHz.  
• Bit 6 – ADNCDIS: ADC Noise Canceller Disable  
Set this bit to disable automatic ADC start when entering Idle or ADC Noise reduction Modes.  
Clear it to enable automatic ADC start when entering Idle or ADC reduction Modes.  
The ADNCDIS must be set before entering Idle or ADC Noise reduction Modes if the ADC is run-  
ning or Auto triggered to prevent false ADC restart.  
• Bit 5 – Reserved  
• Bit 4 – ADSSEN: ADC Single Shot Enable on PSC’s synchronization signals  
Set this bit to enable single shot mode when auto trigger on PSCRASY & PSC2ASY. In this  
case a single conversion will be performed and PSCRASY & PSC2ASY will be blocked until  
ADCH reading.  
Clear it to enable continuous conversion on PSCRASY & PSC2ASY auto triggering.  
• Bit 3, 2, 1, 0– ADTS3:ADTS0: ADC Auto Trigger Source Selection Bits  
These bits are only necessary in case the ADC works in auto trigger mode. It means if ADATE  
bit in ADCSRA register is set.  
In accordance with the Table 17-6 on page 221, these 3 bits select the interrupt event which will  
generate the trigger of the start of conversion. The start of conversion will be generated by the  
rising edge of the selected interrupt flag whether the interrupt is enabled or not.  
220  
7734Q–AVR–02/12  
 
AT90PWM81/161  
In case of trig on PSCnASY event, there is no flag. So, if ADSSEN is reset, a conversion will  
start each time the trig event appears and the previous conversion is completed.  
Table 17-6. ADC auto trigger source selection.  
ADTS3  
ADTS2  
ADTS1  
ADTS0  
Description  
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
0
0
0
0
1
1
1
1
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
Free running mode  
Analog comparator 1  
External Interrupt Request 0  
Timer/Counter1 overflow  
Timer/Counter1 capture event  
PSCRASY event  
PSC2ASY event  
Analog comparator 2  
Analog comparator 3  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
17.8.4  
ADCH and ADCL - ADC Result Data Registers  
When an ADC conversion is complete, the conversion results are stored in these two result data  
registers.  
When the ADCL register is read, the two ADC result data registers can’t be updated until the  
ADCH register has also been read.  
Consequently, in 10-bit configuration, the ADCL register must be read first before the ADCH.  
Nevertheless, to work easily with only 8-bit precision, there is the possibility to left adjust the  
result thanks to the ADLAR bit in the ADCSRA register. Like this, it is sufficient to only read  
ADCH to have the conversion result.  
17.8.4.1  
ADLAR = 0  
Bit  
7
6
5
4
3
2
1
0
-
-
-
-
-
-
ADC9  
ADC8  
ADCH  
ADCL  
ADC7  
ADC6  
ADC5  
ADC4  
ADC3  
ADC2  
ADC1  
ADC0  
Read/Write  
Initial Value  
R
R
0
R
R
0
R
R
0
R
R
0
R
R
0
R
R
0
R
R
0
R
R
0
0
0
0
0
0
0
0
0
221  
7734Q–AVR–02/12  
 
AT90PWM81/161  
17.8.4.2  
ADLAR = 1  
Bit  
7
6
5
4
3
2
1
0
ADC9  
ADC8  
ADC7  
ADC6  
ADC5  
ADC4  
ADC3  
ADC2  
ADCH  
ADCL  
ADC1  
ADC0  
-
-
-
-
-
-
Read/Write  
Initial Value  
R
R
0
R
R
0
R
R
0
0
R
R
0
0
R
R
0
0
R
R
0
0
R
R
0
0
R
R
0
0
0
0
17.8.5  
DIDR0 - Digital Input Disable Register 0  
Bit  
7
6
5
4
3
2
1
0
ADC8D  
ACMP3D  
ADC7D  
AMP0-D  
ADC5D  
ACMP2D  
ADC4D  
ADC3D  
ADC2D  
ADC1D  
ADC0D  
ACMP1D  
DIDR0  
ACMP3MD ACMPMD ACMP2MD  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
• Bit 7:0 – ADC7D..ADC0D: AMP0-D and ADC7:0 Digital Input Disable  
When this bit is written logic one, the digital input buffer on the corresponding ADC pin is dis-  
abled. The corresponding PIN Register bit will always read as zero when this bit is set. When an  
analog signal is applied to the ADC7..0 pin and the digital input from this pin is not needed, this  
bit should be written logic one to reduce power consumption in the digital input buffer.  
17.8.6  
DIDR1 - Digital Input Disable Register 1  
Bit  
7
6
5
4
3
2
1
0
-
-
-
-
ADC10D  
ADC9D  
DIDR1  
ACMP1MD AMP0+D  
Read/Write  
Initial Value  
-
-
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
0
0
• Bit 2:0 – AMP0+D and ADC10:8 Digital Input Disable  
When this bit is written logic one, the digital input buffer on the corresponding ADC pin is dis-  
abled. The corresponding PIN Register bit will always read as zero when this bit is set. When an  
analog signal is applied to an analog pin and the digital input from this pin is not needed, this bit  
should be written logic one to reduce power consumption in the digital input buffer.  
17.9 Amplifier  
The AT90PWM81/161 features one differential amplified channel with programmable 5, 10, 20,  
and 40 gain stage. Despite the result is given by the 10bit ADC, the amplifier has been sized to  
give a 8bits resolution.  
The negative input on the amplifier can be internally switched to the analog ground. However,  
amplifier characteristics are specified with differential inputs.  
Because the amplifier is a switching capacitor amplifier, it needs to be clocked by a synchroniza-  
tion signal called in this document the amplifier synchronization clock. The amplifier samples the  
input value at the falling edge of the synchronization signal. This allow to measure analog sig-  
nals with same period as the synchronization. The maximum clock for the amplifier is 250kHz.  
To ensure an accurate result in case of large voltage change, the amplifier input needs to have a  
quite stable sampled input value during at least four Amplifier synchronization clock periods.  
222  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
Amplified conversions can be synchronized to PSC events (see “Synchronization source  
description in one/two/four ramp modes.” on page 134 and “Synchronization source description  
in centered mode.” on page 135) or to the internal clock CKADC equal to eighth the ADC clock  
frequency. In case the synchronization is done by the ADC clock divided by eight, this synchro-  
nization is done automatically by the ADC interface in such a way that the sample-and-hold  
occurs at a specific phase of CKADC2. A conversion initiated by the user (that is, all single conver-  
sions, and the first free running conversion) when CKADC2 is low will take the same amount of  
time as a single ended conversion (13 ADC clock cycles from the next prescaled clock cycle). A  
conversion initiated by the user when CKADC2 is high will take 14 ADC clock cycles due to the  
synchronization mechanism.  
The normal way to use the amplifier is to select a synchronization clock via the AMPxTS1:0 bits  
in the AMPxCSR register. Then the amplifier can be switched on, and the amplification is done  
on each synchronization event. The amplification is done independently of the ADC.  
In order to start an amplified Analog to Digital Conversion on the amplified channel, the ADMUX  
must be configured as specified on Table 17-4 on page 218.  
The ADC starting is done by setting the ADSC (ADC Start conversion) bit in the ADCSRB  
register.  
Until the conversion is not achieved, it is not possible to start a conversion on another channel.  
On AT90PWM81/161, conversion takes advantage of the amplifier characteristics to ensure  
minimum conversion time.  
As soon as a conversion is requested thanks to the ADSC bit, the Analog to Digital Conversion  
is started. In order to have a better understanding of the functioning of the amplifier synchroniza-  
tion, a timing diagram example is shown Figure 17-15 on page 224.  
In case the amplifier output is modified during the sample phase of the ADC, the on-going con-  
version is aborted and restarted as soon as the output of the amplifier is stable as shown Figure  
17-16 on page 224.  
The only precaution to take is to be sure that the trig signal (PSC) frequency is lower than  
ADCclk/4.  
It is also possible to auto trigger conversion on the amplified channel. In this case, the conver-  
sion is started at the next amplifier clock event following the last auto trigger event selected  
thanks to the ADTS bits in the ADCSRB register. In auto trigger conversion, the free running  
mode is not possible unless the ADSC bit in ADCSRA is set by soft after each conversion.  
223  
7734Q–AVR–02/12  
AT90PWM81/161  
Figure 17-15. Amplifier synchronization timing diagram with change on analog input signal.  
Delta V  
4th stable sample  
Signal to be  
measured  
PSC  
Block  
PSCn_ASY  
AMPLI_clk  
(Sync Clock)  
CK ADC  
Ampli er  
Block  
Ampli er Sample  
Enable  
Ampli er Hold  
Value  
Valid sample  
ADSC  
ADC  
ADC  
ADC  
ADC  
Activity  
Conv  
Conv  
ADC  
Sampling  
ADC  
Sampling  
ADC Result  
Ready  
ADC Resu  
Ready  
Figure 17-16. Amplifier synchronization timing diagram: behavior when ADSC is set when the  
amplifier output is changing.  
Signal to be  
measured  
PSC  
Block  
PSCn_ASY  
AMPLI_clk  
(Sync Clock)  
CK ADC  
Ampli er  
Block  
Ampli er Sample  
Enable  
Ampli er Hold  
Value  
Valid sample  
ADSC  
ADC  
ADC  
Sampling  
Aborted  
ADC  
Activity  
ADC  
Conv  
ADC  
Conv  
ADC  
Sampling  
ADC  
Sampling  
ADC Result  
Ready  
ADC Result  
Ready  
224  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
The block diagram of the two amplifiers is shown on Figure 17-17.  
Figure 17-17. Amplifiers block diagram.  
AMP0+  
+
-
To w ar d A D C M UX  
(AMP0)  
AMP0-  
ADCK/8  
PSCRASY  
00  
01  
10  
Sam p l i n g  
Clock  
1 1  
PSC2ASY  
no short  
AMP0+ GND  
AMP0EN AMP0IS AMP0G1 AMP0G0 AMP0GS  
-
AMP0TS1 AMP0TS0  
AMP0CSR  
If APMP0GS bit is set, the AMP0- input is open and PD5/AMP0- pin is free for another use. At  
the same time the negative input of the Amplifier is internally grounded.  
17.10 Amplifier Control Registers  
The configuration of the amplifier is controlled via the register AMP0CSR. Then the start of con-  
version is done via the ADC control and status registers.  
The conversion result is stored on ADCH and ADCL register which contain respectively the most  
significant bits and the least significant bits.  
17.10.1 AMP0CSR - Amplifier 0 Control and Status register  
Bit  
7
6
5
4
3
2
-
1
0
AMP0EN  
AMP0IS  
AMP0G1  
AMP0G0  
AMP0GS  
AMP0TS1 AMP0TS0 AMP0CSR  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
-
-
R/W  
0
R/W  
0
0
0
• Bit 7 – AMP0EN: Amplifier 0 Enable Bit  
Set this bit to enable the Amplifier 0.  
Clear this bit to disable the Amplifier 0.  
Clearing this bit while a conversion is running will take effect at the end of the conversion.  
• Bit 6– AMP0IS: Amplifier 0 Input Shunt  
Set this bit to short-circuit the Amplifier 0 input. If AMP0GS is set, the ground switch is released  
during shunt of inputs.  
Clear this bit to normally use the Amplifier 0.  
225  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
• Bit 5, 4– AMP0G1, 0: Amplifier 0 Gain Selection Bits  
These two bits determine the gain of the amplifier 0.  
The different setting are shown in Table 17-7.  
Table 17-7. Amplifier 0 gain selection.  
AMP0G1  
AMP0G0  
Description  
Gain 5  
0
0
1
1
0
1
0
1
Gain 10  
Gain 20  
Gain 40  
To ensure an accurate result, after the gain value has been changed, the amplifier input needs  
to have a quite stable input value during at least four Amplifier synchronization clock periods.  
• Bit 3– AMP0GS: Amplifier 0 Ground Select of AMP0  
This bit select negative input of the amplifier:  
Set this bit to ground the Amplifier 0 negative input.  
Clear this bit to normally use the Amplifier 0 differential input.  
• Bit 1, 0– AMP0TS1, AMP0TS0: Amplifier 0 Trigger Source Selection Bits  
In accordance with the Table 17-8, these two bits select the event which will generate the trigger  
for the amplifier 0. This trigger source is necessary to start the conversion on the amplified  
channel.  
Table 17-8. AMP0 auto trigger source selection.  
AMP0TS1  
AMP0TS0  
Description  
0
0
1
1
0
1
0
1
Auto synchronization on ADC Clock/8  
Trig on PSCRASY  
Trig on PSC2ASY  
226  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
18. Digital to Analog Converter - DAC  
18.1 Features  
10 bits resolution  
8 bits linearity  
0.5LSB accuracy between 100mV and AVCC - 100mV  
VOUT = DAC × VREF/1023  
The DAC could be connected to the negative inputs of the analog comparators  
The AT90PWM81/161 features a 10-bit Digital to Analog Converter. This DAC can be used for  
the analog comparators.  
The DAC has a separate analog supply voltage pin, AVCC. AVCC must not differ more than 0.3V  
from VCC. See the paragraph “ADC Noise Canceler” on page 210 on how to connect this pin.  
The reference voltage is the same as the one used for the ADC. See “ADMUX - ADC Multiplexer  
Register” on page 217. These nominally 2.56V VREF or AVCC are provided On-chip. The voltage  
reference may be externally decoupled at the AREF pin by a capacitor for better noise  
performance.  
Figure 18-1. Digital to analog converter block schematic.  
DAC  
Result  
VRef  
DAC  
10  
1
0
10  
10  
DAC High bits  
DAC Low bits  
DACH  
DACL  
Update DAC  
Trigger  
Edge  
Detector  
DAATE  
DATS2  
DATS1  
DATS0  
DACON  
-
DALA  
DAEN  
227  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
18.2 Operation  
The Digital to Analog Converter generates an analog signal proportional to the value of the DAC  
registers value.  
In order to have an accurate sampling frequency control, there is the possibility to update the  
DAC input values through different trigger events.  
18.3 Starting a Conversion  
The DAC is configured thanks to the DACON register. As soon as the DAEN bit in DACON reg-  
ister is set, the DAC converts the value present on the DACH and DACL registers in accordance  
with the register DACON setting.  
Alternatively, a conversion can be triggered automatically by various sources. Auto Triggering is  
enabled by setting the DAC Auto Trigger Enable bit, DAATE in DACON. The trigger source is  
selected by setting the DAC Trigger Select bits, DATS in DACON (see description of the DATS  
bits for a list of the trigger sources). When a positive edge occurs on the selected trigger signal,  
the DAC converts the value present on the DACH and DACL registers in accordance with the  
register DACON setting. This provides a method of starting conversions at fixed intervals. If the  
trigger signal is still set when the conversion completes, a new conversion will not be started. If  
another positive edge occurs on the trigger signal during conversion, the edge will be ignored.  
Note that an interrupt flag will be set even if the specific interrupt is disabled or the Global Inter-  
rupt Enable bit in SREG is cleared. A conversion can thus be triggered without causing an  
interrupt. However, the interrupt flag must be cleared in order to trigger a new conversion at the  
next interrupt event.  
18.3.1  
DAC Voltage Reference  
The reference voltage for the ADC (VREF) indicates the conversion range for the DAC. VREF can  
be selected as either AVCC, internal 2.56V reference, or external AREF pin.  
AVCC is connected to the DAC through a passive switch. The internal 2.56V reference is gener-  
ated from the internal bandgap reference (VBG) through an internal amplifier. When the external  
AREF pin is connected to the DAC, the reference voltage can be made more immune to noise  
by connecting a capacitor between the AREF pin and ground. VREF can also be measured at the  
AREF pin with a high impedance voltmeter. Note that VREF is a high impedance source, and only  
a capacitive load should be connected in a system.  
The user may switch between AVCC, AVCC and 2.56V as reference selection. The first DAC con-  
version result after switching reference voltage source may be inaccurate, and the user is  
advised to discard this result.  
18.4 DAC Register Description  
The DAC is controlled via three dedicated registers:  
• The DACON register which is used for DAC configuration  
• DACH and DACL which are used to set the value to be converted  
18.4.1  
DACON - Digital to Analog Conversion Control Register  
Bit  
7
6
5
4
3
-
2
1
-
0
DAATE  
DATS2  
DATS1  
DATS0  
R/W  
0
DALA  
R/W  
0
DAEN  
R/W  
0
DACON  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
-
-
0
0
228  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
• Bit 7 – DAATE: DAC Auto Trigger Enable bit (not useful, may be left for compatibility)  
Set this bit to update the DAC input value on the positive edge of the trigger signal selected with  
the DACTS2-0 bit in DACON register.  
Clear it to automatically update the DAC input when a value is written on DACH register.  
• Bit 6:4 – DATS2, DATS1, DATS0: DAC Trigger Selection bits (not useful, may be left for  
compatibility)  
These bits are only necessary in case the DAC works in auto trigger mode. It means if DAATE  
bit is set.  
In accordance with the Table 18-1, these 3 bits select the interrupt event which will generate the  
update of the DAC input values. The update will be generated by the rising edge of the selected  
interrupt flag whether the interrupt is enabled or not.  
Table 18-1. DAC auto trigger source selection.  
DATS2  
DATS1  
DATS0  
Description  
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
Analog comparator 0  
Analog comparator 1  
External Interrupt Request 0  
Reserved  
Reserved  
Reserved  
Timer/Counter1 Overflow  
Timer/Counter1 Capture Event  
• Bit 2 – DALA: Digital to Analog Left Adjust  
Set this bit to left adjust the DAC input data.  
Clear it to right adjust the DAC input data.  
The DALA bit affects the configuration of the DAC data registers. Changing this bit affects the  
DAC output on the next DACH writing.  
• Bit 1 – Reserved  
• Bit 0 – DAEN: Digital to Analog Enable bit  
Set this bit to enable the DAC.  
Clear it to disable the DAC.  
18.4.2  
DACH and DACL - Digital to Analog Converter input Register  
DACH and DACL registers contain the value to be converted into analog voltage.  
Writing the DACL register forbid the update of the input value until DACH has not been written  
too. So the normal way to write a 10-bit value in the DAC register is firstly to write DACL the  
DACH.  
In order to work easily with only 8 bits, there is the possibility to left adjust the input value. Like  
this it is sufficient to write DACH to update the DAC value.  
229  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
18.4.2.1  
DALA = 0  
Bit  
7
6
5
4
3
2
1
0
-
-
-
-
-
-
DAC9  
DAC1  
R/W  
R/W  
0
DAC8  
DAC0  
R/W  
R/W  
0
DACH  
DACL  
DAC7  
R/W  
R/W  
0
DAC6  
R/W  
R/W  
0
DAC5  
R/W  
R/W  
0
DAC4  
R/W  
R/W  
0
DAC3  
R/W  
R/W  
0
DAC2  
R/W  
R/W  
0
Read/Write  
Initial Value  
0
0
0
0
0
0
0
0
18.4.2.2  
DALA = 1  
Bit  
7
6
5
4
3
2
1
0
DAC9  
DAC1  
R/W  
R/W  
0
DAC8  
DAC0  
R/W  
R/W  
0
DAC7  
DAC6  
DAC5  
DAC4  
DAC3  
DAC2  
DACH  
DACL  
-
-
-
-
-
-
Read/Write  
Initial Value  
R/W  
R/W  
0
R/W  
R/W  
0
R/W  
R/W  
0
R/W  
R/W  
0
R/W  
R/W  
0
R/W  
R/W  
0
0
0
0
0
0
0
0
0
To work with the 10-bit DAC, two registers have to be updated. In order to avoid intermediate  
value, the DAC input values which are really converted into analog signal are buffering into  
unreachable registers. In normal mode, the update of the shadow register is done when the reg-  
ister DACH is written.  
In case DAATE bit is set, the DAC input values will be updated on the trigger event selected  
through DATS bits.  
In order to avoid wrong DAC input values, the update can only be done after having written  
respectively DACL and DACH registers. It is possible to work on 8-bit configuration by only writ-  
ing the DACH value. In this case, update is done each trigger event.  
In case DAATE bit is cleared, the DAC is in an automatic update mode. Writing the DACH regis-  
ter automatically update the DAC input values with the DACH and DACL register values.  
It means that whatever is the configuration of the DAATE bit, changing the DACL register has no  
effect on the DAC output until the DACH register has also been updated. So, to work with 10  
bits, DACL must be written first before DACH. To work with 8-bit configuration, writing DACH  
allows the update of the DAC.  
230  
7734Q–AVR–02/12  
AT90PWM81/161  
19. debugWIRE On-chip Debug System  
19.1 Features  
Complete program flow control  
Emulates all on-chip functions, both digital and analog, except RESET pin  
Real-time operation  
Symbolic debugging support (both at C and assembler source level, or for other HLLs)  
Unlimited number of program break points (using software break points)  
Non-intrusive operation  
Electrical characteristics identical to real device  
Automatic configuration system  
High-speed operation  
Programming of non-volatile memories  
19.2 Overview  
The debugWIRE On-chip debug system uses a One-wire, bi-directional interface to control the  
program flow, execute AVR instructions in the CPU and to program the different non-volatile  
memories.  
19.3 Physical Interface  
When the debugWIRE Enable (DWEN) Fuse is programmed and Lock bits are unprogrammed,  
the debugWIRE system within the target device is activated. The RESET port pin is configured  
as a wire-AND (open-drain) bi-directional I/O pin with pull-up enabled and becomes the commu-  
nication gateway between target and emulator.  
Figure 19-1. The debugWIRE setup.  
1.8V - 5.5V  
VCC  
dW  
dW(RESET)  
GND  
Figure 19-1 shows the schematic of a target MCU, with debugWIRE enabled, and the emulator  
connector. The system clock is not affected by debugWIRE and will always be the clock source  
selected by the CKSEL Fuses.  
When designing a system where debugWIRE will be used, the following observations must be  
made for correct operation:  
231  
7734Q–AVR–02/12  
 
 
 
 
 
AT90PWM81/161  
• Pull-up resistors on the dW/(RESET) line must not be smaller than 10kW. The pull-up  
resistor is not required for debugWIRE functionality  
• Connecting the RESET pin directly to VCC will not work  
• Capacitors connected to the RESET pin must be disconnected when using debugWire  
• All external reset sources must be disconnected  
19.4 Software Break Points  
The debugWIRE supports Program memory Break Points by the AVR Break instruction. Setting  
a Break Point in AVR Studio® will insert a BREAK instruction in the Program memory. The  
instruction replaced by the BREAK instruction will be stored. When program execution is contin-  
ued, the stored instruction will be executed before continuing from the Program memory. A  
break can be inserted manually by putting the BREAK instruction in the program.  
The Flash must be re-programmed each time a Break Point is changed. This is automatically  
handled by AVR Studio through the debugWIRE interface. The use of Break Points will therefore  
reduce the Flash Data retention. Devices used for debugging purposes should not be shipped to  
end customers.  
19.5 Limitations of debugWIRE  
The debugWIRE communication pin (dW) is physically located on the same pin as External  
Reset (RESET). An External Reset source is therefore not supported when the debugWIRE is  
enabled.  
The debugWIRE system accurately emulates all I/O functions when running at full speed, that is,  
when the program in the CPU is running. When the CPU is stopped, care must be taken while  
accessing some of the I/O Registers via the debugger (AVR Studio).  
A programmed DWEN Fuse enables some parts of the clock system to be running in all sleep  
modes. This will increase the power consumption while in sleep. Thus, the DWEN Fuse should  
be disabled when debugWire is not used.  
19.6 debugWIRE Related Register in I/O Memory  
The following section describes the registers used with the debugWire.  
19.6.1  
DWDR - debugWire Data Register  
Bit  
7
6
5
4
3
2
1
0
DWDR[7:0]  
DWDR  
Read/Write  
Initial Value  
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
R/W  
0
The DWDR Register provides a communication channel from the running program in the MCU  
to the debugger. This register is only accessible by the debugWIRE and can therefore not be  
used as a general purpose register in the normal operations.  
232  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
20. Boot Loader Support – Read-While-Write Self-Programming  
In AT90PWM81/161, the Boot Loader Support provides a real Read-While-Write Self-Program-  
ming mechanism for downloading and uploading program code by the MCU itself. This feature  
allows flexible application software updates controlled by the MCU using a Flash-resident Boot  
Loader program. The Boot Loader program can use any available data interface and associated  
protocol to read code and write (program) that code into the Flash memory, or read the code  
from the program memory. The program code within the Boot Loader section has the capability  
to write into the entire Flash, including the Boot Loader memory. The Boot Loader can thus even  
modify itself, and it can also erase itself from the code if the feature is not needed anymore. The  
size of the Boot Loader memory is configured with fuses and the Boot Loader has two separate  
sets of Boot Lock bits which can be set independently. This gives the user a unique flexibility to  
select different levels of protection.  
20.1 Boot Loader Features  
Read-While-Write Self-Programming  
Flexible Boot Memory Size  
High Security (Separate Boot Lock Bits for a Flexible Protection)  
Separate Fuse to Select Reset Vector  
Optimized Page (1) Size  
Code Efficient Algorithm  
Efficient Read-Modify-Write Support  
Note:  
1. A page is a section in the Flash consisting of several bytes (see Table 21-12 on page 254)  
used during programming. The page organization does not affect normal operation.  
20.2 Application and Boot Loader Flash Sections  
The Flash memory is organized in two main sections, the Application section and the Boot  
Loader section (see Figure 20-2 on page 236). The size of the different sections is configured by  
the BOOTSZ Fuses as shown in Table 20-7 on page 246 and Figure 20-2 on page 236. These  
two sections can have different level of protection since they have different sets of Lock bits.  
20.2.1  
20.2.2  
Application Section  
The Application section is the section of the Flash that is used for storing the application code.  
The protection level for the Application section can be selected by the application Boot Lock bits  
(Boot Lock bits 0), see Table 20-2 on page 237. The Application section can never store any  
Boot Loader code since the SPM instruction is disabled when executed from the Application  
section.  
BLS – Boot Loader Section  
While the Application section is used for storing the application code, the The Boot Loader soft-  
ware must be located in the BLS since the SPM instruction can initiate a programming when  
executing from the BLS only. The SPM instruction can access the entire Flash, including the  
BLS itself. The protection level for the Boot Loader section can be selected by the Boot Loader  
Lock bits (Boot Lock bits 1), see Table 20-3 on page 237.  
20.3 Read-While-Write and No Read-While-Write Flash Sections  
Whether the CPU supports Read-While-Write or if the CPU is halted during a Boot Loader soft-  
ware update is dependent on which address that is being programmed. In addition to the two  
233  
7734Q–AVR–02/12  
 
 
 
 
 
AT90PWM81/161  
sections that are configured by the BOOTSZ Fuses as described above, the Flash is also  
divided into two fixed sections, the Read-While-Write (RWW) section and the No Read-While-  
Write (NRWW) section. The limit between the RWW- and NRWW sections is given in Table 20-  
9 on page 247 and Figure 20-2 on page 236. The main difference between the two sections is:  
• When erasing or writing a page located inside the RWW section, the NRWW section can be  
read during the operation  
• When erasing or writing a page located inside the NRWW section, the CPU is halted during  
the entire operation  
Note that the user software can never read any code that is located inside the RWW section dur-  
ing a Boot Loader software operation. The syntax “Read-While-Write section” refers to which  
section that is being programmed (erased or written), not which section that actually is being  
read during a Boot Loader software update.  
20.3.1  
RWW – Read-While-Write Section  
If a Boot Loader software update is programming a page inside the RWW section, it is possible  
to read code from the Flash, but only code that is located in the NRWW section. During an on-  
going programming, the software must ensure that the RWW section never is being read. If the  
user software is trying to read code that is located inside the RWW section (that is, by a  
call/jmp/lpm or an interrupt) during programming, the software might end up in an unknown  
state. To avoid this, the interrupts should either be disabled or moved to the Boot Loader sec-  
tion. The Boot Loader section is always located in the NRWW section. The RWW Section Busy  
bit (RWWSB) in the Store Program Memory Control and Status Register (SPMCSR) will be read  
as logical one as long as the RWW section is blocked for reading. After a programming is com-  
pleted, the RWWSB must be cleared by software before reading code located in the RWW  
section. See “SPMCSR - Store Program Memory Control and Status Register” on page 238 for  
details on how to clear RWWSB.  
20.3.2  
NRWW – No Read-While-Write Section  
The code located in the NRWW section can be read when the Boot Loader software is updating  
a page in the RWW section. When the Boot Loader code updates the NRWW section, the CPU  
is halted during the entire Page Erase or Page Write operation.  
Table 20-1. Read-while-write features.  
Which section can be  
Which Section does the Z-pointer  
address during the programming?  
read during  
programming?  
Is the CPU  
halted?  
Read-while-write  
supported?  
RWW section  
NRWW section  
None  
No  
Yes  
No  
NRWW section  
Yes  
234  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Figure 20-1. Read-while-write vs. no read-while-write.  
Read-While-Write  
(RWW) Section  
Z-pointer  
Addresses NRWW  
Section  
Z-pointer  
No Read-While-Write  
(NRWW) Section  
Addresses RWW  
Section  
CPU is Halted  
During the Operation  
Code Located in  
NRWW Section  
Can be Read During  
the Operation  
235  
7734Q–AVR–02/12  
AT90PWM81/161  
Figure 20-2. Memory sections.  
Program Memory  
BOOTSZ = '10'  
Program Memory  
BOOTSZ = '11'  
0x0000  
0x0000  
Application Flash Section  
Application Flash Section  
End RWW  
End RWW  
Start NRWW  
Start NRWW  
Application Flash Section  
Boot Loader Flash Section  
Application Flash Section  
Boot Loader Flash Section  
End Application  
End Application  
Start Boot Loader  
Flashend  
Start Boot Loader  
Flashend  
Program Memory  
BOOTSZ = '01'  
Program Memory  
BOOTSZ = '00'  
0x0000  
0x0000  
Application Flash Section  
Application Flash Section  
End RWW, End Application  
End RWW  
Start NRWW, Start Boot Loader  
Start NRWW  
Application Flash Section  
Boot Loader Flash Section  
End Application  
Boot Loader Flash Section  
Start Boot Loader  
Flashend  
Flashend  
Note:  
1. The parameters in the figure above are given in Table 20-7 on page 246.  
20.4 Boot Loader Lock Bits  
If no Boot Loader capability is needed, the entire Flash is available for application code. The  
Boot Loader has two separate sets of Boot Lock bits which can be set independently. This gives  
the user a unique flexibility to select different levels of protection.  
The user can select:  
To protect the entire Flash from a software update by the MCU  
To protect only the Boot Loader Flash section from a software update by the MCU  
To protect only the Application Flash section from a software update by the MCU  
• Allow software update in the entire Flash  
See Table 20-2 on page 237 and Table 20-3 on page 237 for further details. The Boot Lock bits  
can be set in software and in Serial or Parallel Programming mode, but they can be cleared by a  
Chip Erase command only. The general Write Lock (Lock Bit mode 2) does not control the pro-  
gramming of the Flash memory by SPM instruction. Similarly, the general Read/Write Lock  
(Lock Bit mode 1) does not control reading nor writing by LPM/SPM, if it is attempted.  
236  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Table 20-2. Boot Lock Bit0 protection modes (application section) (1)  
.
BLB0  
mode BLB02 BLB01 Protection  
1
2
1
1
1
0
No restrictions for SPM or LPM accessing the Application section.  
SPM is not allowed to write to the Application section.  
SPM is not allowed to write to the Application section, and LPM executing  
from the Boot Loader section is not allowed to read from the Application  
section. If Interrupt Vectors are placed in the Boot Loader section,  
interrupts are disabled while executing from the Application section.  
3
0
0
0
1
LPM executing from the Boot Loader section is not allowed to read from  
the Application section. If Interrupt Vectors are placed in the Boot Loader  
section, interrupts are disabled while executing from the Application  
section.  
4
Note:  
1. “1” means unprogrammed, “0” means programmed.  
Table 20-3. Boot Lock Bit1 protection modes (boot loader section) (1)  
.
BLB1  
Mode  
BLB12 BLB11 Protection  
1
2
1
1
1
0
No restrictions for SPM or LPM accessing the Boot Loader section.  
SPM is not allowed to write to the Boot Loader section.  
SPM is not allowed to write to the Boot Loader section, and LPM  
executing from the Application section is not allowed to read from the Boot  
Loader section. If Interrupt Vectors are placed in the Application section,  
interrupts are disabled while executing from the Boot Loader section.  
3
4
0
0
0
1
LPM executing from the Application section is not allowed to read from the  
Boot Loader section. If Interrupt Vectors are placed in the Application  
section, interrupts are disabled while executing from the Boot Loader  
section.  
Note:  
1. “1” means unprogrammed, “0” means programmed.  
20.5 Entering the Boot Loader Program  
Entering the Boot Loader takes place by a jump or call from the application program. This may  
be initiated by a trigger such as a command received via SPI interface. Alternatively, the Boot  
Reset Fuse can be programmed so that the Reset Vector is pointing to the Boot Flash start  
address after a reset. In this case, the Boot Loader is started after a reset. After the application  
code is loaded, the program can start executing the application code. Note that the fuses cannot  
be changed by the MCU itself. This means that once the Boot Reset Fuse is programmed, the  
Reset Vector will always point to the Boot Loader Reset and the fuse can only be changed  
through the serial or parallel programming interface.  
Table 20-4. Boot reset fuse (1)  
.
BOOTRST  
Reset address  
1
0
Reset vector = application reset (address 0x0000)  
Reset vector = boot loader reset (see Table 20-7 on page 246)  
Note:  
1. “1” means unprogrammed, “0” means programmed.  
237  
7734Q–AVR–02/12  
 
 
 
 
 
 
AT90PWM81/161  
20.5.1  
SPMCSR - Store Program Memory Control and Status Register  
The Store Program Memory Control and Status Register contains the control bits needed to con-  
trol the Boot Loader operations.  
Bit  
7
6
5
4
3
2
1
0
SPMIE  
R/W  
0
RWWSB  
SIGRD  
R/W  
0
RWWSRE  
BLBSET  
PGWRT  
R/W  
0
PGERS  
R/W  
0
SPMEN  
R/W  
0
SPMCSR  
Read/Write  
Initial Value  
R
0
R/W  
0
R/W  
0
• Bit 7 – SPMIE: SPM Interrupt Enable  
When the SPMIE bit is written to one, and the I-bit in the Status Register is set (one), the SPM  
ready interrupt will be enabled. The SPM ready Interrupt will be executed as long as the SPMEN  
bit in the SPMCSR Register is cleared.  
• Bit 6 – RWWSB: Read-While-Write Section Busy  
When a Self-Programming (Page Erase or Page Write) operation to the RWW section is initi-  
ated, the RWWSB will be set (one) by hardware. When the RWWSB bit is set, the RWW section  
cannot be accessed. The RWWSB bit will be cleared if the RWWSRE bit is written to one after a  
Self-Programming operation is completed. Alternatively the RWWSB bit will automatically be  
cleared if a page load operation is initiated.  
• Bit 5 – SIGRD: Signature Row Read  
If this bit is written to one at the same time as SPMEN, the next LPM instruction within three  
clock cycles will read a byte from the signature row into the destination register. See “Reading  
the Signature Row from Software” on page 243 for details.  
An SPM instruction within four cycles after SIGRD and SPMEN are set will have no effect. This  
operation is reserved for future use and should not be used.  
• Bit 4 – RWWSRE: Read-While-Write Section Read Enable  
When programming (Page Erase or Page Write) to the RWW section, the RWW section is  
blocked for reading (the RWWSB will be set by hardware). To re-enable the RWW section, the  
user software must wait until the programming is completed (SPMEN will be cleared). Then, if  
the RWWSRE bit is written to one at the same time as SPMEN, the next SPM instruction within  
four clock cycles re-enables the RWW section. The RWW section cannot be re-enabled while  
the Flash is busy with a Page Erase or a Page Write (SPMEN is set). If the RWWSRE bit is writ-  
ten while the Flash is being loaded, the Flash load operation will abort and the data loaded will  
be lost.  
• Bit 3 – BLBSET: Boot Lock Bit Set  
If this bit is written to one at the same time as SPMEN, the next SPM instruction within four clock  
cycles sets Boot Lock bits and Memory Lock bits, according to the data in R0. The data in R1  
and the address in the Z-pointer are ignored. The BLBSET bit will automatically be cleared upon  
completion of the Lock bit set, or if no SPM instruction is executed within four clock cycles.  
An LPM instruction within three cycles after BLBSET and SPMEN are set in the SPMCSR Reg-  
ister, will read either the Lock bits or the Fuse bits (depending on Z0 in the Z-pointer) into the  
destination register. See “Reading the Fuse and Lock Bits from Software” on page 242 for  
details.  
238  
7734Q–AVR–02/12  
 
AT90PWM81/161  
• Bit 2 – PGWRT: Page Write  
If this bit is written to one at the same time as SPMEN, the next SPM instruction within four clock  
cycles executes Page Write, with the data stored in the temporary buffer. The page address is  
taken from the high part of the Z-pointer. The data in R1 and R0 are ignored. The PGWRT bit  
will auto-clear upon completion of a Page Write, or if no SPM instruction is executed within four  
clock cycles. The CPU is halted during the entire Page Write operation if the NRWW section is  
addressed.  
• Bit 1 – PGERS: Page Erase  
If this bit is written to one at the same time as SPMEN, the next SPM instruction within four clock  
cycles executes Page Erase. The page address is taken from the high part of the Z-pointer. The  
data in R1 and R0 are ignored. The PGERS bit will auto-clear upon completion of a Page Erase,  
or if no SPM instruction is executed within four clock cycles. The CPU is halted during the entire  
Page Write operation if the NRWW section is addressed.  
• Bit 0 – SPMEN: Self Programming Enable  
This bit enables the SPM instruction for the next four clock cycles. If written to one together with  
either RWWSRE, BLBSET, PGWRT or PGERS, the following SPM instruction will have a spe-  
cial meaning, see description above. If only SPMEN is written, the following SPM instruction will  
store the value in R1:R0 in the temporary page buffer addressed by the Z-pointer. The LSB of  
the Z-pointer is ignored. The SPMEN bit will auto-clear upon completion of an SPM instruction,  
or if no SPM instruction is executed within four clock cycles. During Page Erase and Page Write,  
the SPMEN bit remains high until the operation is completed.  
Writing any other combination than “10001”, “01001”, “00101”, “00011” or “00001” in the lower  
five bits will have no effect.  
20.6 Addressing the Flash During Self-Programming  
The Z-pointer is used to address the SPM commands.  
Bit  
15  
Z15  
Z7  
7
14  
Z14  
Z6  
6
13  
Z13  
Z5  
5
12  
Z12  
Z4  
4
11  
Z11  
Z3  
3
10  
Z10  
Z2  
2
9
8
ZH (R31)  
ZL (R30)  
Z9  
Z1  
1
Z8  
Z0  
0
Since the Flash is organized in pages (see Table 21-12 on page 254), the Program Counter can  
be treated as having two different sections. One section, consisting of the least significant bits, is  
addressing the words within a page, while the most significant bits are addressing the pages.  
This is shown in Figure 20-3 on page 240. Note that the Page Erase and Page Write operations  
are addressed independently. Therefore it is of major importance that the Boot Loader software  
addresses the same page in both the Page Erase and Page Write operation. Once a program-  
ming operation is initiated, the address is latched and the Z-pointer can be used for other  
operations.  
The only SPM operation that does not use the Z-pointer is Setting the Boot Loader Lock bits.  
The content of the Z-pointer is ignored and will have no effect on the operation. The LPM  
instruction does also use the Z-pointer to store the address. Since this instruction addresses the  
Flash byte-by-byte, also the LSB (bit Z0) of the Z-pointer is used.  
239  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Figure 20-3. Addressing the flash during SPM (1)  
.
BIT 15  
ZPCMSB  
ZPAGEMSB  
1
0
0
Z - REGISTER  
PCMSB  
PAGEMSB  
PROGRAM  
COUNTER  
PCPAGE  
PCWORD  
PAGE ADDRESS  
WORD ADDRESS  
WITHIN THE FLASH  
WITHIN A PAGE  
PROGRAM MEMORY  
PAGE  
PAGE  
INSTRUCTION WORD  
PCWORD[PAGEMSB:0]:  
00  
01  
02  
PAGEEND  
Note:  
1. The different variables used in Figure 20-3 are listed in Table 20-10 on page 247.  
20.7 Self-Programming the Flash  
The program memory is updated in a page by page fashion. Before programming a page with  
the data stored in the temporary page buffer, the page must be erased. The temporary page buf-  
fer is filled one word at a time using SPM and the buffer can be filled either before the Page  
Erase command or between a Page Erase and a Page Write operation:  
Alternative 1, fill the buffer before a Page Erase:  
• Fill temporary page buffer  
• Perform a Page Erase  
• Perform a Page Write  
Alternative 2, fill the buffer after Page Erase:  
• Perform a Page Erase  
• Fill temporary page buffer  
• Perform a Page Write  
If only a part of the page needs to be changed, the rest of the page must be stored (for example  
in the temporary page buffer) before the erase, and then be rewritten. When using Alternative 1,  
the Boot Loader provides an effective Read-Modify-Write feature which allows the user software  
to first read the page, do the necessary changes, and then write back the modified data. If Alter-  
native 2 is used, it is not possible to read the old data while loading since the page is already  
erased. The temporary page buffer can be accessed in a random sequence. It is essential that  
the page address used in both the Page Erase and Page Write operation is addressing the same  
page. See “Simple Assembly Code Example for a Boot Loader” on page 245 for an assembly  
code example.  
240  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
20.7.1  
Performing Page Erase by SPM  
To execute Page Erase, set up the address in the Z-pointer, write “X0000011” to SPMCSR and  
execute SPM within four clock cycles after writing SPMCSR. The data in R1 and R0 is ignored.  
The page address must be written to PCPAGE in the Z-register. Other bits in the Z-pointer will  
be ignored during this operation.  
• Page Erase to the RWW section:The NRWW section can be read during the Page Erase  
• Page Erase to the NRWW section:The CPU is halted during the operation  
20.7.2  
Filling the Temporary Buffer (Page Loading)  
To write an instruction word, set up the address in the Z-pointer and data in R1:R0, write  
“00000001” to SPMCSR and execute SPM within four clock cycles after writing SPMCSR. The  
content of PCWORD in the Z-register is used to address the data in the temporary buffer. The  
temporary buffer will auto-erase after a Page Write operation or by writing the RWWSRE bit in  
SPMCSR. It is also erased after a system reset. Note that it is not possible to write more than  
one time to each address without erasing the temporary buffer.  
If the EEPROM is written in the middle of an SPM Page Load operation, all data loaded will be  
lost.  
20.7.3  
Performing a Page Write  
To execute Page Write, set up the address in the Z-pointer, write “X0000101” to SPMCSR and  
execute SPM within four clock cycles after writing SPMCSR. The data in R1 and R0 is ignored.  
The page address must be written to PCPAGE. Other bits in the Z-pointer must be written to  
zero during this operation.  
• Page Write to the RWW section:The NRWW section can be read during the Page Write  
• Page Write to the NRWW section:The CPU is halted during the operation  
20.7.4  
Using the SPM Interrupt  
If the SPM interrupt is enabled, the SPM interrupt will generate a constant interrupt when the  
SPMEN bit in SPMCSR is cleared. This means that the interrupt can be used instead of polling  
the SPMCSR Register in software. When using the SPM interrupt, the Interrupt Vectors should  
be moved to the BLS section to avoid that an interrupt is accessing the RWW section when it is  
blocked for reading. How to move the interrupts is described in Section “Moving Interrupts  
Between Application and Boot Space”, page 65.  
20.7.5  
20.7.6  
Consideration While Updating BLS  
Special care must be taken if the user allows the Boot Loader section to be updated by leaving  
Boot Lock bit11 unprogrammed. An accidental write to the Boot Loader itself can corrupt the  
entire Boot Loader, and further software updates might be impossible. If it is not necessary to  
change the Boot Loader software itself, it is recommended to program the Boot Lock bit11 to  
protect the Boot Loader software from any internal software changes.  
Prevent Reading the RWW Section During Self-Programming  
During Self-Programming (either Page Erase or Page Write), the RWW section is always  
blocked for reading. The user software itself must prevent that this section is addressed during  
the self programming operation. The RWWSB in the SPMCSR will be set as long as the RWW  
section is busy. During Self-Programming the Interrupt Vector table should be moved to the BLS  
as described in Section “Moving Interrupts Between Application and Boot Space”, page 65, or  
the interrupts must be disabled. Before addressing the RWW section after the programming is  
241  
7734Q–AVR–02/12  
AT90PWM81/161  
completed, the user software must clear the RWWSB by writing the RWWSRE. See “Simple  
Assembly Code Example for a Boot Loader” on page 245 for an example.  
20.7.7  
Setting the Boot Loader Lock Bits by SPM  
To set the Boot Loader Lock bits, write the desired data to R0, write “X0001001” to SPMCSR  
and execute SPM within four clock cycles after writing SPMCSR. The only accessible Lock bits  
are the Boot Lock bits that may prevent the Application and Boot Loader section from any soft-  
ware update by the MCU.  
Bit  
7
6
5
4
3
2
1
0
R0  
1
1
BLB12  
BLB11  
BLB02  
BLB01  
1
1
See Table 20-2 on page 237 and Table 20-3 on page 237 for how the different settings of the  
Boot Loader bits affect the Flash access.  
If bits 5..2 in R0 are cleared (zero), the corresponding Boot Lock bit will be programmed if an  
SPM instruction is executed within four cycles after BLBSET and SPMEN are set in SPMCSR.  
The Z-pointer is don’t care during this operation, but for future compatibility it is recommended to  
load the Z-pointer with 0x0001 (same as used for reading the lOck bits). For future compatibility it  
is also recommended to set bits 7, 6, 1, and 0 in R0 to “1” when writing the Lock bits. When pro-  
gramming the Lock bits the entire Flash can be read during the operation.  
20.7.8  
20.7.9  
EEPROM Write Prevents Writing to SPMCSR  
Note that an EEPROM write operation will block all software programming to Flash. Reading the  
Fuses and Lock bits from software will also be prevented during the EEPROM write operation. It  
is recommended that the user checks the status bit (EEPE) in the EECR Register and verifies  
that the bit is cleared before writing to the SPMCSR Register.  
Reading the Fuse and Lock Bits from Software  
It is possible to read both the Fuse and Lock bits from software. To read the Lock bits, load the  
Z-pointer with 0x0001 and set the BLBSET and SPMEN bits in SPMCSR. When an LPM instruc-  
tion is executed within three CPU cycles after the BLBSET and SPMEN bits are set in SPMCSR,  
the value of the Lock bits will be loaded in the destination register. The BLBSET and SPMEN  
bits will auto-clear upon completion of reading the Lock bits or if no LPM instruction is executed  
within three CPU cycles or no SPM instruction is executed within four CPU cycles. When BLB-  
SET and SPMEN are cleared, LPM will work as described in the Instruction set Manual.  
Bit  
Rd  
7
6
5
4
3
2
1
0
BLB12  
BLB11  
BLB02  
BLB01  
LB2  
LB1  
The algorithm for reading the Fuse Low byte is similar to the one described above for reading  
the Lock bits. To read the Fuse Low byte, load the Z-pointer with 0x0000 and set the BLBSET  
and SPMEN bits in SPMCSR. When an LPM instruction is executed within three cycles after the  
BLBSET and SPMEN bits are set in the SPMCSR, the value of the Fuse Low byte (FLB) will be  
loaded in the destination register as shown below. Refer to Table 21-4 on page 249 for a  
detailed description and mapping of the Fuse Low byte.  
Bit  
Rd  
7
6
5
4
3
2
1
0
FLB7  
FLB6  
FLB5  
FLB4  
FLB3  
FLB2  
FLB1  
FLB0  
Similarly, when reading the Fuse High byte, load 0x0003 in the Z-pointer. When an LPM instruc-  
tion is executed within three cycles after the BLBSET and SPMEN bits are set in the SPMCSR,  
242  
7734Q–AVR–02/12  
AT90PWM81/161  
the value of the Fuse High byte (FHB) will be loaded in the destination register as shown below.  
Refer to Table 21-5 on page 250 for detailed description and mapping of the Fuse High byte.  
Bit  
Rd  
7
6
5
4
3
2
1
0
FHB7  
FHB6  
FHB5  
FHB4  
FHB3  
FHB2  
FHB1  
FHB0  
When reading the Extended Fuse byte, load 0x0002 in the Z-pointer. When an LPM instruction  
is executed within three cycles after the BLBSET and SPMEN bits are set in the SPMCSR, the  
value of the Extended Fuse byte (EFB) will be loaded in the destination register as shown below.  
Refer to Table 21-4 on page 249 for detailed description and mapping of the Extended Fuse  
byte.  
Bit  
Rd  
7
6
5
4
3
2
1
0
EFB3  
EFB2  
EFB1  
EFB0  
Fuse and Lock bits that are programmed, will be read as zero. Fuse and Lock bits that are  
unprogrammed, will be read as one.  
20.7.10 Reading the Signature Row from Software  
To read the Signature Row from software, load the Z-pointer with the signature byte address  
given in Table 20-5 and set the SIGRD and SPMEN bits in SPMCSR. When an LPM instruction  
is executed within three CPU cycles after the SIGRD and SPMEN bits are set in SPMCSR, the  
signature byte value will be loaded in the destination register. The SIGRD and SPMEN bits will  
auto-clear upon completion of reading the Signature Row Lock bits or if no LPM instruction is  
executed within three CPU cycles. When SIGRD and SPMEN are cleared, LPM will work as  
described in the ”AVR Instruction Set” description.  
Table 20-5. Signature row addressing.  
AT90PWM81  
data  
AT90PWM161  
data  
Signature Byte  
Device ID 0, manufacturer ID  
Address  
0x00  
0x01  
0x02  
0x03  
0x04  
0x05  
0x06  
0x07  
0x0E  
0x0F  
0x10  
0x11  
0x12  
0x13  
0x3C  
1EH  
XXH  
93H  
1EH  
XXH  
94H  
OSCAL 8M, RC-OSC calibration  
Device ID 1, flash size  
Reserved  
XXH  
88H  
XXH  
8BH  
XXH  
XXH  
XXH  
XXH  
XXH  
XXH  
XXH  
XXH  
XXH  
XXH  
Device ID 2, device  
Temperature sensor offset : TSOFFSET  
XXH  
XXH  
XXH  
XXH  
XXH  
XXH  
XXH  
XXH  
XXH  
XXH  
Reserved  
Temperature sensor gain : TSGAIN (1)  
Lot number at sort, byte 2, ASCII  
Lot number at sort, Byte 1, ASCII (most left lot#)  
Lot number at sort, byte 2, ASCII  
Lot number at sort, Byte 1, ASCII  
Lot number at sort, byte 2, ASCII  
Lot number at sort, Byte 1, ASCII  
Final test Amb VREF: LOW BYTE (2)  
243  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Table 20-5. Signature row addressing. (Continued)  
AT90PWM81  
data  
AT90PWM161  
data  
Signature Byte  
Address  
Final test amb VREF: HIGH BYTE (3)  
0x3D  
0x3E  
0x3F  
XXH  
XXH  
XXH  
XXH  
XXH  
XXH  
Final test hot VREF: LOW BYTE (only a Read) (4)  
Final test hot VREF: HIGH BYTE (only a Read) (5)  
Note:  
1. TSGAIN typical value is 0x80=128  
2. See Note 3  
3. Final Test Amb VREF HIGH BYTE and LOW BYTE:  
Typical values are for VREF = 2.56V:  
HIGH BYTE = 0x0A  
LOW BYTE = 0x00  
This means:  
Final Test Amb VREF = 0x0A00 = 2560 = VREF × 1000  
4. See Note 3 which details the value format  
5. See Note 3 which details the value format  
20.7.11 Preventing Flash Corruption  
During periods of low VCC, the Flash program can be corrupted because the supply voltage is  
too low for the CPU and the Flash to operate properly. These issues are the same as for board  
level systems using the Flash, and the same design solutions should be applied.  
A Flash program corruption can be caused by two situations when the voltage is too low. First, a  
regular write sequence to the Flash requires a minimum voltage to operate correctly. Secondly,  
the CPU itself can execute instructions incorrectly, if the supply voltage for executing instructions  
is too low.  
Flash corruption can easily be avoided by following these design recommendations (one is  
sufficient):  
1. If there is no need for a Boot Loader update in the system, program the Boot Loader  
Lock bits to prevent any Boot Loader software updates.  
2. Keep the AVR RESET active (low) during periods of insufficient power supply voltage.  
This can be done by enabling the internal Brown-out Detector (BOD) if the operating  
voltage matches the detection level. If not, an external low VCC reset protection circuit  
can be used. If a reset occurs while a write operation is in progress, the write operation  
will be completed provided that the power supply voltage is sufficient.  
3. Keep the AVR core in Power-down sleep mode during periods of low VCC. This will pre-  
vent the CPU from attempting to decode and execute instructions, effectively protecting  
the SPMCSR Register and thus the Flash from unintentional writes.  
20.7.12 Programming Time for Flash when Using SPM  
The calibrated RC Oscillator is used to time Flash accesses. Table 20-6 shows the typical pro-  
gramming time for Flash accesses from the CPU.  
Table 20-6. SPM programming time.  
Symbol  
Min. programming time  
Max. programming time  
Flash write (Page Erase, Page Write, and  
write Lock bits by SPM)  
3.7ms  
4.5ms  
244  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
20.7.13 Simple Assembly Code Example for a Boot Loader  
;-the routine writes one page of data from RAM to Flash  
; the first data location in RAM is pointed to by the Y pointer  
; the first data location in Flash is pointed to by the Z-pointer  
;-error handling is not included  
;-the routine must be placed inside the Boot space  
; (at least the Do_spm sub routine). Only code inside NRWW section can  
; be read during Self-Programming (Page Erase and Page Write).  
;-registers used: r0, r1, temp1 (r16), temp2 (r17), looplo (r24),  
; loophi (r25), spmcrval (r20)  
; storing and restoring of registers is not included in the routine  
; register usage can be optimized at the expense of code size  
;-It is assumed that either the interrupt table is moved to the Boot  
; loader section or that the interrupts are disabled.  
.equ PAGESIZEB = PAGESIZE*2  
.org SMALLBOOTSTART  
Write_page:  
;PAGESIZEB is page size in BYTES, not words  
; Page Erase  
ldi spmcrval, (1<<PGERS) | (1<<SPMEN)  
call Do_spm  
; re-enable the RWW section  
ldi spmcrval, (1<<RWWSRE) | (1<<SPMEN)  
call Do_spm  
; transfer data from RAM to Flash page buffer  
ldi looplo, low(PAGESIZEB)  
;init loop variable  
ldi loophi, high(PAGESIZEB) ;not required for PAGESIZEB<=256  
Wrloop:  
ld  
ld  
r0, Y+  
r1, Y+  
ldi spmcrval, (1<<SPMEN)  
call Do_spm  
adiw ZH:ZL, 2  
sbiw loophi:looplo, 2  
brne Wrloop  
;use subi for PAGESIZEB<=256  
; execute Page Write  
subi ZL, low(PAGESIZEB)  
sbci ZH, high(PAGESIZEB)  
;restore pointer  
;not required for PAGESIZEB<=256  
ldi spmcrval, (1<<PGWRT) | (1<<SPMEN)  
call Do_spm  
; re-enable the RWW section  
ldi spmcrval, (1<<RWWSRE) | (1<<SPMEN)  
call Do_spm  
; read back and check, optional  
ldi looplo, low(PAGESIZEB)  
;init loop variable  
ldi loophi, high(PAGESIZEB) ;not required for PAGESIZEB<=256  
subi YL, low(PAGESIZEB)  
sbci YH, high(PAGESIZEB)  
Rdloop:  
;restore pointer  
lpm r0, Z+  
ld  
r1, Y+  
cpse r0, r1  
jmp Error  
sbiw loophi:looplo, 1  
brne Rdloop  
;use subi for PAGESIZEB<=256  
245  
7734Q–AVR–02/12  
AT90PWM81/161  
; return to RWW section  
; verify that RWW section is safe to read  
Return:  
in  
temp1, SPMCSR  
sbrs temp1, RWWSB  
ret  
; If RWWSB is set, the RWW section is not ready yet  
; re-enable the RWW section  
ldi spmcrval, (1<<RWWSRE) | (1<<SPMEN)  
call Do_spm  
rjmp Return  
Do_spm:  
; check for previous SPM complete  
Wait_spm:  
in  
temp1, SPMCSR  
sbrc temp1, SPMEN  
rjmp Wait_spm  
; input: spmcrval determines SPM action  
; disable interrupts if enabled, store status  
in  
temp2, SREG  
cli  
; check that no EEPROM write access is present  
Wait_ee:  
sbic EECR, EEPE  
rjmp Wait_ee  
; SPM timed sequence  
out SPMCSR, spmcrval  
spm  
; restore SREG (to enable interrupts if originally enabled)  
out SREG, temp2  
ret  
20.7.14 Boot Loader Parameters  
In Table 20-7 through Table 20-10 on page 247, the parameters used in the description of the  
self programming are given.  
For AT90PWM81.  
Table 20-7. Boot size configuration.  
Boot reset  
address  
End  
application  
section  
(start boot  
loader  
section)  
Boot  
size  
Application  
flash section  
Boot loader  
flash section  
BOOTSZ1  
BOOTSZ0  
Pages  
128  
words  
1
1
4
0x000 - 0xF7F  
0x000 - 0xEFF  
0x000 - 0xDFF  
0x000 - 0xBFF  
0xF80 - 0xFFF  
0xF00 - 0xFFF  
0xE00 - 0xFFF  
0xC00 - 0xFFF  
0xF7F  
0xEFF  
0xDFF  
0xBFF  
0xF80  
0xF00  
0xE00  
0xC00  
256  
words  
1
0
0
0
1
0
8
512  
words  
16  
32  
1024  
words  
Note:  
The different BOOTSZ Fuse configurations are shown in Figure 20-2 on page 236.  
246  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
For AT90PWM161.  
Table 20-8. Boot size configuration.  
Boot  
Boot reset  
Application  
flash  
section  
loader  
flash  
section  
End  
application  
section  
address (start  
boot loader  
section)  
BOOTSZ1  
BOOTSZ0  
Boot size  
Pages  
0x000 -  
0x1EFF  
0x1F00 -  
0x1FFF  
1
1
256 words  
4
0x1EFF  
0x1DFF  
0x1BFF  
0x17FF  
0x1F00  
0x1E00  
0x1C00  
0x1800  
0x000 -  
0x1DFF  
0x1E00 -  
0x1FFF  
1
0
0
0
1
0
512 words  
8
1024  
words  
0x000 -  
0x1BFF  
0x1C00 -  
0x1FFF  
16  
32  
2048  
words  
0x000 -  
0x17FF  
0x1800 -  
0x1FFF  
The different BOOTSZ Fuse configurations are shown in Figure 20-2 on page 236.  
Table 20-9. Read-while-write limit.  
Section  
Pages  
96  
Address  
Read-while-write section (RWW)  
No read-while-write section (NRWW)  
0x000 - 0x17FF  
0x1800 - 0x1FFF  
32  
For details about these two section, see “NRWW – No Read-While-Write Section” on page 234  
and “RWW – Read-While-Write Section” on page 234.  
Table 20-10. Explanation of different variables used in Figure 20-3 on page 240 and the mapping to the Z-pointer.  
AT90PWM81  
correspond-  
AT90PWM161  
correspond-  
Variable  
AT90PWM81 ing Z-value (1) AT90PWM161 ing Z-value (1) Description  
Most significant bit in the Program Counter.  
(The Program Counter is 12 bits PC[11:0])  
PCMSB  
11  
4
12  
4
Most significant bit which is used to address the  
words within one page  
(32 words in a page requires 5 bits PC [4:0])  
PAGEMSB  
ZPCMSB  
Bit in Z-register that is mapped to PCMSB.  
Because Z0 is not used, the ZPCMSB equals  
PCMSB + 1  
Z12  
Z12  
Bit in Z-register that is mapped to PAGEMSB.  
Because Z0 is not used, the ZPAGEMSB equals  
PAGEMSB + 1  
ZPAGEMS  
B
Z5  
Z5  
Program counter page address:  
Page select, for page erase and page write  
PCPAGE  
PC[11:5]  
PC[4:0]  
Z12:Z6  
Z5:Z1  
PC[12:6]  
PC[5:0]  
Z12:Z6  
Z5:Z1  
Program counter word address:  
Word select, for filling temporary buffer (must be  
zero during page write operation)  
PCWORD  
Note:  
1. Z15:Z13: always ignored.  
Z0: should be zero for all SPM commands, byte select for the LPM instruction.  
See “Addressing the Flash During Self-Programming” on page 239 for details about the use of  
Z-pointer during Self-Programming.  
247  
7734Q–AVR–02/12  
 
AT90PWM81/161  
21. Memory Programming  
21.1 Program And Data Memory Lock Bits  
The AT90PWM81/161 provides six Lock bits which can be left unprogrammed (“1”) or can be  
programmed (“0”) to obtain the additional features listed in Table 21-2. The Lock bits can only be  
erased to “1” with the Chip Erase command.  
Table 21-1. Lock bit byte (1)  
Lock bit byte  
Bit no.  
Description  
Default value  
7
6
5
4
3
2
1
0
1 (unprogrammed)  
1 (unprogrammed)  
1 (unprogrammed)  
1 (unprogrammed)  
1 (unprogrammed)  
1 (unprogrammed)  
1 (unprogrammed)  
1 (unprogrammed)  
BLB12  
Boot Lock bit  
Boot Lock bit  
Boot Lock bit  
Boot Lock bit  
Lock bit  
BLB11  
BLB02  
BLB01  
LB2  
LB1  
Lock bit  
Notes: 1. “1” means unprogrammed, “0” means programmed.  
Table 21-2. Lock bit protection modes (1)(2)  
.
Memory lock bits  
Protection type  
LB mode  
LB2  
LB1  
1
1
1
No memory lock features enabled  
Further programming of the Flash and EEPROM is  
disabled in Parallel and Serial Programming mode. The  
Fuse bits are locked in both Serial and Parallel  
Programming mode (1)  
2
3
1
0
0
0
Further programming and verification of the Flash and  
EEPROM is disabled in Parallel and Serial Programming  
mode. The Boot Lock bits and Fuse bits are locked in both  
Serial and Parallel Programming mode (1)  
Notes: 1. Program the Fuse bits and Boot Lock bits before programming the LB1 and LB2.  
2. “1” means unprogrammed, “0” means programmed.  
248  
7734Q–AVR–02/12  
 
 
 
 
 
 
 
AT90PWM81/161  
Table 21-3. Lock bit protection modes (1)(2). Only ATmega88/168.  
BLB0 mode  
BLB02  
BLB01  
1
2
1
1
1
0
No restrictions for SPM or LPM accessing the Application section.  
SPM is not allowed to write to the Application section.  
SPM is not allowed to write to the Application section, and LPM executing from the Boot Loader  
section is not allowed to read from the Application section. If Interrupt Vectors are placed in the  
Boot Loader section, interrupts are disabled while executing from the Application section.  
3
4
0
0
0
1
LPM executing from the Boot Loader section is not allowed to read from the Application section.  
If Interrupt Vectors are placed in the Boot Loader section, interrupts are disabled while  
executing from the Application section.  
BLB1 mode  
BLB12  
BLB11  
1
2
1
1
1
0
No restrictions for SPM or LPM accessing the Boot Loader section.  
SPM is not allowed to write to the Boot Loader section.  
SPM is not allowed to write to the Boot Loader section, and LPM executing from the Application  
section is not allowed to read from the Boot Loader section. If Interrupt Vectors are placed in the  
Application section, interrupts are disabled while executing from the Boot Loader section.  
3
4
0
0
0
1
LPM executing from the Application section is not allowed to read from the Boot Loader section.  
If Interrupt Vectors are placed in the Application section, interrupts are disabled while executing  
from the Boot Loader section.  
Notes: 1. Program the Fuse bits and Boot Lock bits before programming the LB1 and LB2.  
2. “1” means unprogrammed, “0” means programmed.  
21.2 Fuse Bits  
The AT90PWM81/161 has three Fuse bytes. Table 21-4 to Table 21-6 on page 251 describe  
briefly the functionality of all the fuses and how they are mapped into the Fuse bytes. Note that  
the fuses are read as logical zero, “0”, if they are programmed.  
Table 21-4. Extended Low Fuse byte.  
Extended fuse byte  
PSC2RB  
Bit No  
Description  
Default value  
7
6
5
4
3
2
1
0
PSC2 reset behavior  
1
PSC2RBA  
PSC2 reset behavior for OUT22 & 23  
PSC reduced reset behavior  
PSCOUT & PSCOUTR reset value  
PSC & PSCR inputs reset behavior  
Brown-out detector trigger level  
Brown-out detector trigger level  
Brown-out detector trigger level  
1
PSCRRB  
1
PSCRV  
1
PSCINRB  
1
BODLEVEL2 (1)  
BODLEVEL1 (1)  
BODLEVEL0 (1)  
1 (unprogrammed)  
0 (programmed)  
1 (unprogrammed)  
Notes: 1. See Table 7-2 on page 53 for BODLEVEL Fuse decoding.  
21.2.1  
PSC Output Behavior During Reset  
For external component safety reason, the state of PSC outputs during Reset can be pro-  
grammed by fuses PSCRV, PSCRRB & PSC2RB.  
These fuses are located in the Extended Fuse Byte (see Table 21-4).  
249  
7734Q–AVR–02/12  
 
 
 
 
 
AT90PWM81/161  
PSCRV gives the state low or high which will be forced on PSC outputs selected by PSC0RB &  
PSC2RB fuses.  
If PSCRV fuse equals 0 (programmed), the selected PSC outputs will be forced to low state. If  
PSCRV fuse equals 1 (unprogrammed), the selected PSC outputs will be forced to high state.  
If PSCRRB fuse equals 1 (unprogrammed), PSCOUTR0 & PSCOUTR1 keep a standard port  
behavior. If PSC0RB fuse equals 0 (programmed), PSCOUTR0 & PSCOUTR1 are forced at  
reset to low level or high level according to PSCRV fuse bit. In this second case, PSCOUTR0 &  
PSCOUTR1 keep the forced state until PSOC0 register is written.  
If PSC2RB fuse equals 1 (unprogrammed), PSCOUT20 & PSCOUT21 keep a standard port  
behavior. If PSC2RB fuse equals 0 (programmed), PSCOUT20 & PSCOUT21 are forced at  
reset to low level or high level according to PSCRV fuse bit. In this second case, PSCOUT20 &  
PSCOUT21 keep the forced state until PSOC2 register is written.  
If PSC2RBA fuse equals 1 (unprogrammed), PSCOUT22 & PSCOUT23 keep a standard port  
behavior. If PSC2RBA fuse equals 0 (programmed), PSCOUT22 & PSCOUT23 are forced at  
reset to low level or high level according to PSCRV fuse bit. In this second case, PSCOUT22 &  
PSCOUT23 keep the forced state until PSOC2 register is written.  
21.2.2  
PSC Input Behavior During Reset  
For power consumption under reset reason, the state of PSC & PSCR inputs during Reset can  
be programmed by fuse PSCINRB.  
If PSCINRB fuse equals 1 (unprogrammed), PSC & PSCR input keep a standard port behavior.  
If PSCINRB fuse equals 0 (programmed), PSC & PSCR input pull-up are forced while the reset  
is active. Affected pins are PSCIN2, PSCINr, PSCIN2A, PSCINrA. To prevent any conflict on  
PD1, this fuse has no effect on PSCINrB.  
Table 21-5. Fuse High byte.  
High Fuse byte  
RSTDISBL (1)  
DWEN  
Bit no. Description  
Default value  
7
6
External reset disable  
1 (unprogrammed)  
1 (unprogrammed)  
debugWIRE enable  
Enable serial program and data  
downloading  
0 (programmed, SPI  
programming enabled)  
SPIEN (2)  
WDTON (3)  
EESAVE  
5
4
3
Watchdog timer always on  
1 (unprogrammed)  
EEPROM memory is preserved through  
the chip erase  
1 (unprogrammed), EEPROM  
not reserved  
Select boot size  
(see Table 20-7 on page 246 for details)  
BOOTSZ1  
2
0 (programmed) (4)  
Select boot size  
(see Table 20-7 on page 246 for details)  
BOOTSZ0  
BOOTRST  
1
0
0 (programmed) (4)  
1 (unprogrammed)  
Select reset vector  
Notes: 1. See “Alternate Functions of Port E” on page 80 for description of RSTDISBL Fuse.  
2. The SPIEN Fuse is not accessible in serial programming mode.  
3. See “Watchdog timer configuration.” on page 60 for details.  
4. The default value of BOOTSZ1..0 results in maximum Boot Size. See Table 21-8 on page 252  
for details.  
250  
7734Q–AVR–02/12  
 
 
 
 
 
 
AT90PWM81/161  
Table 21-6. Fuse Low byte.  
Low Fuse byte  
CKDIV8 (4)  
CKOUT (3)  
SUT1  
Bit no.  
Description  
Default value  
7
6
5
4
3
2
1
0
Divide clock by 8  
Clock output  
0 (programmed)  
1 (unprogrammed)  
1 (unprogrammed) (1)  
0 (programmed) (1)  
0 (programmed) (2)  
0 (programmed) (2)  
1 (unprogrammed) (2)  
0 (programmed) (2)  
Select start-up time  
Select start-up time  
Select clock source  
Select clock source  
Select clock source  
Select clock source  
SUT0  
CKSEL3  
CKSEL2  
CKSEL1  
CKSEL0  
Note:  
1. The default value of SUT1..0 results in maximum start-up time for the default clock source.  
See Table 5-4 on page 30 for details.  
2. The default setting of CKSEL3..0 results in internal RC Oscillator @ 8MHz. See Table 5-1 on  
page 28 for details.  
3. The CKOUT Fuse allows the system clock to be output on PORTD0. See “Clock Output Buf-  
fer” on page 34 for details.  
4. See “System Clock Prescaler” on page 39 for details.  
The status of the Fuse bits is not affected by Chip Erase. Note that the Fuse bits are locked if  
Lock bit1 (LB1) is programmed. Program the Fuse bits before programming the Lock bits.  
21.2.3  
Latching of Fuses  
The fuse values are latched when the device enters programming mode and changes of the  
fuse values will have no effect until the part leaves Programming mode. This does not apply to  
the EESAVE Fuse which will take effect once it is programmed. The fuses are also latched on  
Power-up in Normal mode.  
21.3 Signature Bytes  
All Atmel microcontrollers have a three-byte signature code which identifies the device. This  
code can be read in both serial and parallel mode, also when the device is locked. The three  
bytes reside in a separate address space, the signature row.  
21.3.1  
Signature Bytes  
Table 21-7. Device ID bytes for AT90PWM81/161 devices.  
Device  
Device ID bytes  
0x004  
88  
0x002  
93  
0x000  
1E  
AT90PWM81  
AT90PWM161  
8B  
94  
1E  
For the AT90PWM81/161 the signature bytes are:  
1. 0x000: 0x1E (indicates manufactured by Atmel).  
2. 0x002: 0x93 (indicates 8KB Flash memory).  
3. 0x004: 0x88 (indicates the AT90PWM81 device when 0x002 is 0x93).  
0x004: 0x8B (indicates the AT90PWM161 device when 0x002 is 0x94).  
251  
7734Q–AVR–02/12  
 
 
 
 
 
 
 
 
AT90PWM81/161  
21.4 Calibration Byte  
The AT90PWM81/161 has a byte calibration value for the internal RC Oscillator. This byte  
resides in the byte of address 0x003 in the signature address space. During reset, this byte is  
automatically written into the OSCCAL Register to ensure correct frequency of the calibrated RC  
Oscillator.  
21.5 Parallel Programming Parameters, Pin Mapping, and Commands  
This section describes how to parallel program and verify Flash Program memory, EEPROM  
Data memory, Memory Lock bits, and Fuse bits in the AT90PWM81/161. Pulses are assumed to  
be at least 250ns unless otherwise stated.  
21.5.1  
Signal Names  
In this section, some pins of the AT90PWM81/161 are referenced by signal names describing  
their functionality during parallel programming, see Figure 21-1 and Table 21-8. Pins not  
described in Table 21-8 are referenced by pin names.  
The XA1/XA0 pins determine the action executed when the XTAL1 pin is given a positive pulse.  
The bit coding is shown in Table 21-10 on page 253.  
When pulsing WR or OE, the command loaded determines the action executed. The different  
Commands are shown in Table 21-11 on page 253.  
Figure 21-1. Parallel programming.  
+5V  
AREF  
PD2  
RDY/BSY  
OE  
VCC  
+5V  
WR  
PD1  
AVCC  
PD5  
XA0  
PB[7:0]  
DATA  
PD6  
XA1/BS2  
PAGEL/BS1  
+12V  
PE 2  
RESET/PE0  
XTAL1/PE1  
GND  
Table 21-8. Pin name mapping.  
Signal name in  
programming mode  
Pin name  
I/O Function  
0: Device is busy programming,  
1: Device is ready for new command  
RDY/BSY  
AREF  
O
OE  
WR  
XA0  
PD2  
PD1  
PD5  
I
I
I
Output enable (active low)  
Write pulse (active low)  
XTAL Action Bit 0  
252  
7734Q–AVR–02/12  
 
 
 
 
 
 
AT90PWM81/161  
Table 21-8. Pin name mapping. (Continued)  
Signal name in  
programming mode  
Pin name  
I/O Function  
XTAL Action Bit 1  
Byte Select 2  
XA1/BS2  
PD6  
I
(“0” selects Low byte, “1” selects 2’nd High byte)  
Program memory and EEPROM Data Page Load  
Byte Select 1 (“0” selects Low byte, “1” selects High byte)  
PAGEL/BS1  
DATA  
PE2  
I
PB[7:0]  
I/O Bi-directional Data bus (Output when OE is low)  
Table 21-9. Pin Values Used to Enter Programming Mode.  
Pin  
XA1/BS2  
XA0  
Symbol  
Value  
Prog_enable[3]  
Prog_enable[2]  
Prog_enable[1]  
Prog_enable[0]  
0
0
0
0
OE  
WR  
Table 21-10. XA1 and XA0 coding.  
XA1  
XA0  
Action when XTAL1 is pulsed  
0
0
1
1
0
1
0
1
Load flash or EEPROM address (high or low address byte determined by BS1)  
Load data (high or low data byte for flash determined by BS1)  
Load command  
No action, idle  
Table 21-11. Command byte bit coding.  
Command byte  
1000 0000  
0100 0000  
0010 0000  
0001 0000  
0001 0001  
0000 1000  
0000 0100  
0000 0010  
0000 0011  
Command executed  
Chip Erase  
Write Fuse bits  
Write Lock bits  
Write Flash  
Write EEPROM  
Read Signature Bytes and Calibration byte  
Read Fuse and Lock bits  
Read Flash  
Read EEPROM  
253  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Table 21-12. No. of words in a page and no. of pages in the flash.  
No. of  
pages  
Device  
Flash size  
Page size  
PCWORD  
PCPAGE  
PCMSB  
4K words  
(8Kbytes)  
AT90PWM81  
32 words  
PC[4:0]  
128  
128  
PC[11:5]  
11  
8K words  
(16Kbytes)  
AT90PWM161  
64 words  
PC[5:0]  
PC[12:6]  
12  
Table 21-13. No. of words in a page and no. of pages in the EEPROM.  
EEPROM  
size  
No. of  
pages  
Device  
Page size  
PCWORD  
PCPAGE  
EEAMSB  
AT90PWM81/161  
512 bytes  
4 bytes  
EEA[1:0]  
128  
EEA[8:2]  
8
21.6 Serial Programming Pin Mapping  
Table 21-14. Pin mapping serial programming.  
Symbol  
MOSI  
MISO  
SCK  
Pins  
I/O  
Description  
Serial Data in  
Serial Data out  
Serial Clock  
I
O
I
21.7 Parallel Programming  
21.7.1  
Enter Programming Mode  
The following algorithm puts the device in Parallel (High-voltage) > Programming mode:  
1. Set Prog_enable pins listed in Table 21-9 on page 253 to “0000”, RESET pin to “0” and  
V
CC to 0V.  
2. Apply 4.5V - 5.5V between VCC and GND. Ensure that VCC reaches at least 1.8V within  
the next 20µs.  
3. Wait 20µs - 60µs, and apply 11.5V - 12.5V to RESET.  
4. Keep the Prog_enable pins unchanged for at least 10µs after the High-voltage has  
been applied to ensure the Prog_enable Signature has been latched.  
5. Wait at least 300µs before giving any parallel programming commands.  
6. Exit Programming mode by power the device down or by bringing RESET pin to 0V.  
If the rise time of the VCC is unable to fulfill the requirements listed above, the following alterna-  
tive algorithm can be used.  
1. Set Prog_enable pins listed in Table 21-9 on page 253 to “0000”, RESET pin to “0” and  
V
CC to 0V.  
2. Apply 4.5V - 5.5V between VCC and GND.  
3. Monitor VCC, and as soon as VCC reaches 0.9V - 1.1V, apply 11.5V - 12.5V to RESET.  
4. Keep the Prog_enable pins unchanged for at least 10µs after the High-voltage has  
been applied to ensure the Prog_enable Signature has been latched.  
254  
7734Q–AVR–02/12  
 
 
 
 
 
AT90PWM81/161  
5. Wait until VCC actually reaches 4.5V -5.5V before giving any parallel programming  
commands.  
6. Exit Programming mode by power the device down or by bringing RESET pin to 0V.  
21.7.2  
Considerations for Efficient Programming  
The loaded command and address are retained in the device during programming. For efficient  
programming, the following should be considered.  
• The command needs only be loaded once when writing or reading multiple memory locations  
• Skip writing the data value 0xFF, that is the contents of the entire EEPROM (unless the  
EESAVE Fuse is programmed) and Flash after a Chip Erase  
• Address high byte needs only be loaded before programming or reading a new 256 word  
window in Flash or 256 byte EEPROM. This consideration also applies to Signature bytes  
reading  
21.7.3  
Chip Erase  
The Chip Erase will erase the Flash and EEPROM(1) memories plus Lock bits. The Lock bits are  
not reset until the program memory has been completely erased. The Fuse bits are not  
changed. A Chip Erase must be performed before the Flash and/or EEPROM are  
reprogrammed.  
Note:  
1. The EEPRPOM memory is preserved during Chip Erase if the EESAVE Fuse is programmed.  
Load Command “Chip Erase”  
1. Set XA1, XA0 to “10”. This enables command loading.  
2. Set BS1 to “0”.  
3. Set DATA to “1000 0000”. This is the command for Chip Erase.  
4. Give XTAL1 a positive pulse. This loads the command.  
5. Give WR a negative pulse. This starts the Chip Erase. RDY/BSY goes low.  
6. Wait until RDY/BSY goes high before loading a new command.  
21.7.4  
Programming the Flash  
The Flash is organized in pages, see Table 21-12 on page 254. When programming the Flash,  
the program data is latched into a page buffer. This allows one page of program data to be pro-  
grammed simultaneously. The following procedure describes how to program the entire Flash  
memory:  
A. Load Command “Write Flash”  
1. Set XA1, XA0 to “10”. This enables command loading.  
2. Set BS1 to “0”.  
3. Set DATA to “0001 0000”. This is the command for Write Flash.  
4. Give XTAL1 a positive pulse. This loads the command.  
B. Load Address Low byte  
1. Set XA1, XA0 to “00”. This enables address loading.  
2. Set BS1 to “0”. This selects low address.  
3. Set DATA = Address low byte (0x00 - 0xFF).  
4. Give XTAL1 a positive pulse. This loads the address low byte.  
C. Load Data Low Byte  
255  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
1. Set XA1, XA0 to “01”. This enables data loading.  
2. Set DATA = Data low byte (0x00 - 0xFF).  
3. Give XTAL1 a positive pulse. This loads the data byte.  
D. Load Data High Byte  
1. Set BS1 to “1”. This selects high data byte.  
2. Set XA1, XA0 to “01”. This enables data loading.  
3. Set DATA = Data high byte (0x00 - 0xFF).  
4. Give XTAL1 a positive pulse. This loads the data byte.  
E. Latch Data  
1. Set BS1 to “1”. This selects high data byte.  
2. Give PAGEL a positive pulse. This latches the data bytes (see Figure 21-3 on page 257  
for signal waveforms).  
F. Repeat B through E until the entire buffer is filled or until all data within the page is loaded  
While the lower bits in the address are mapped to words within the page, the higher bits address  
the pages within the FLASH. This is illustrated in Figure 21-2 on page 257. Note that if less than  
eight bits are required to address words in the page (pagesize <256), the most significant bit(s)  
in the address low byte are used to address the page when performing a Page Write.  
G. Load Address High byte  
1. Set XA1, XA0 to “00”. This enables address loading.  
2. Set BS1 to “1”. This selects high address.  
3. Set DATA = Address high byte (0x00 - 0xFF).  
4. Give XTAL1 a positive pulse. This loads the address high byte.  
H. Program Page  
1. Give WR a negative pulse. This starts programming of the entire page of data.  
RDY/BSY goes low.  
2. Wait until RDY/BSY goes high (see Figure 21-3 on page 257 for signal waveforms).  
I. Repeat B through H until the entire Flash is programmed or until all data has been  
programmed  
J. End Page Programming  
1. 1. Set XA1, XA0 to “10”. This enables command loading.  
2. Set DATA to “0000 0000”. This is the command for No Operation.  
3. Give XTAL1 a positive pulse. This loads the command, and the internal write signals  
are reset.  
256  
7734Q–AVR–02/12  
AT90PWM81/161  
Figure 21-2. Addressing the flash, which is organized in pages (1)  
.
PCMSB  
PAGEMSB  
PROGRAM  
COUNTER  
PCPAGE  
PCWORD  
PAGE ADDRESS  
WITHIN THE FLASH  
WORD ADDRESS  
WITHIN A PAGE  
PROGRAM MEMORY  
PAGE  
PAGE  
INSTRUCTION WORD  
PCWORD[PAGEMSB:0]:  
00  
01  
02  
PAGEEND  
Note:  
1. PCPAGE and PCWORD are listed in Table 21-12 on page 254.  
Figure 21-3. Programming the flash waveforms (1)  
.
F
A
B
C
D
E
B
C
D
E
G
H
0x10  
ADDR. LOW  
DATA LOW  
DATA HIGH  
ADDR. LOW DATA LOW  
DATA HIGH  
ADDR. HIGH  
XX  
XX  
XX  
DATA  
XA1/BS2  
XA0  
PAGEL/BS1  
XTAL1  
WR  
RDY/BSY  
RESET +12V  
OE  
Note:  
1. “XX” is don’t care. The letters refer to the programming description above.  
21.7.5  
Programming the EEPROM  
The EEPROM is organized in pages, see Table 21-13 on page 254. When programming the  
EEPROM, the program data is latched into a page buffer. This allows one page of data to be  
programmed simultaneously. The programming algorithm for the EEPROM data memory is as  
follows (refer to “Programming the Flash” on page 255 for details on Command, Address and  
Data loading):  
1. A: Load Command “0001 0001”.  
2. G: Load Address High Byte (0x00 - 0xFF).  
3. B: Load Address Low Byte (0x00 - 0xFF).  
4. C: Load Data (0x00 - 0xFF).  
5. E: Latch data (give PAGEL a positive pulse).  
K: Repeat 3 through 5 until the entire buffer is filled  
257  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
L: Program EEPROM page  
1. Set BS1 to “0”.  
2. Give WR a negative pulse. This starts programming of the EEPROM page. RDY/BSY  
goes low.  
3. Wait until to RDY/BSY goes high before programming the next page (see Figure 21-4  
for signal waveforms).  
Figure 21-4. Programming the EEPROM waveforms.  
K
A
G
B
C
E
B
C
E
L
0x11  
ADDR. HIGH  
ADDR. LOW  
DATA  
ADDR. LOW  
DATA  
XX  
XX  
DATA  
XA1/BS2  
XA0  
PAGEL/BS1  
XTAL1  
WR  
RDY/BSY  
RESET +12V  
OE  
21.7.6  
Reading the Flash  
The algorithm for reading the Flash memory is as follows (refer to “Programming the Flash” on  
page 255 for details on Command and Address loading):  
1. A: Load Command “0000 0010”.  
2. G: Load Address High Byte (0x00 - 0xFF).  
3. B: Load Address Low Byte (0x00 - 0xFF).  
4. Set OE to “0”, and BS1 to “0”. The Flash word low byte can now be read at DATA.  
5. Set BS1 to “1”. The Flash word high byte can now be read at DATA.  
6. Set OE to “1”.  
21.7.7  
Reading the EEPROM  
The algorithm for reading the EEPROM memory is as follows (refer to “Programming the Flash”  
on page 255 for details on Command and Address loading):  
1. A: Load Command “0000 0011”.  
2. G: Load Address High Byte (0x00 - 0xFF).  
3. B: Load Address Low Byte (0x00 - 0xFF).  
4. Set OE to “0”, and BS1 to “0”. The EEPROM Data byte can now be read at DATA.  
5. Set OE to “1”.  
21.7.8  
Programming the Fuse Low Bits  
The algorithm for programming the Fuse Low bits is as follows (refer to “Programming the Flash”  
on page 255 for details on Command and Data loading):  
1. A: Load Command “0100 0000”.  
2. C: Load Data Low Byte. Bit n = “0” programs and bit n = “1” erases the Fuse bit.  
3. Give WR a negative pulse and wait for RDY/BSY to go high.  
258  
7734Q–AVR–02/12  
 
AT90PWM81/161  
21.7.9  
Programming the Fuse High Bits  
The algorithm for programming the Fuse High bits is as follows (refer to “Programming the  
Flash” on page 255 for details on Command and Data loading):  
1. A: Load Command “0100 0000”.  
2. C: Load Data Low Byte. Bit n = “0” programs and bit n = “1” erases the Fuse bit.  
3. Set BS1 to “1” and BS2 to “0”. This selects high data byte.  
4. Give WR a negative pulse and wait for RDY/BSY to go high.  
5. Set BS1 to “0”. This selects low data byte.  
21.7.10 Programming the Extended Fuse Bits  
The algorithm for programming the Extended Fuse bits is as follows (refer to “Programming the  
Flash” on page 255 for details on Command and Data loading):  
1. 1. A: Load Command “0100 0000”.  
2. 2. C: Load Data Low Byte. Bit n = “0” programs and bit n = “1” erases the Fuse bit.  
3. 3. Set BS1 to “0” and BS2 to “1”. This selects extended data byte.  
4. 4. Give WR a negative pulse and wait for RDY/BSY to go high.  
5. 5. Set BS2 to “0”. This selects low data byte.  
Figure 21-5. Programming the FUSES waveforms.  
Write Fuse Low byte  
Write Fuse high byte  
Write Extended Fuse byte  
A
C
A
C
A
C
0x40  
DATA  
XX  
0x40  
DATA  
XX  
0x40  
DATA  
XX  
DATA  
XA1/BS2  
XA0  
PAGEL/BS1  
XTAL1  
WR  
RDY/BSY  
RESET +12V  
OE  
21.7.11 Programming the Lock Bits  
The algorithm for programming the Lock bits is as follows (refer to “Programming the Flash” on  
page 255 for details on Command and Data loading):  
1. A: Load Command “0010 0000”.  
2. C: Load Data Low Byte. Bit n = “0” programs the Lock bit. If LB mode 3 is programmed  
(LB1 and LB2 is programmed), it is not possible to program the Boot Lock bits by any  
External Programming mode.  
3. Give WR a negative pulse and wait for RDY/BSY to go high.  
The Lock bits can only be cleared by executing Chip Erase.  
259  
7734Q–AVR–02/12  
AT90PWM81/161  
21.7.12 Reading the Fuse and Lock Bits  
The algorithm for reading the Fuse and Lock bits is as follows (refer to “Programming the Flash”  
on page 255 for details on Command loading):  
1. A: Load Command “0000 0100”.  
2. Set OE to “0”, BS2 to “0” and BS1 to “0”. The status of the Fuse Low bits can now be  
read at DATA (“0” means programmed).  
3. Set OE to “0”, BS2 to “1” and BS1 to “1”. The status of the Fuse High bits can now be  
read at DATA (“0” means programmed).  
4. Set OE to “0”, BS2 to “1”, and BS1 to “0”. The status of the Extended Fuse bits can now  
be read at DATA (“0” means programmed).  
5. Set OE to “0”, BS2 to “0” and BS1 to “1”. The status of the Lock bits can now be read at  
DATA (“0” means programmed).  
6. Set OE to “1”.  
Figure 21-6. Mapping between BS1, BS2 and the Fuse and Lock Bits during read.  
0
Fuse Low Byte  
Extended Fuse Byte  
Lock Bits  
0
1
1
0
DATA  
BS2  
BS1  
Fuse High Byte  
1
BS2  
21.7.13 Reading the Signature Bytes  
The algorithm for reading the Signature bytes is as follows (refer to “Programming the Flash” on  
page 255 for details on Command and Address loading):  
1. A: Load Command “0000 1000”.  
2. B: Load Address Low Byte (0x00 - 0x02).  
3. Set OE to “0”, and BS1 to “0”. The selected Signature byte can now be read at DATA.  
4. Set OE to “1”.  
21.7.14 Reading the Calibration Byte  
The algorithm for reading the Calibration byte is as follows (refer to “Programming the Flash” on  
page 255 for details on Command and Address loading):  
1. A: Load Command “0000 1000”.  
2. B: Load Address Low Byte, 0x00.  
3. Set OE to “0”, and BS1 to “1”. The Calibration byte can now be read at DATA.  
4. Set OE to “1”.  
260  
7734Q–AVR–02/12  
 
AT90PWM81/161  
21.8 Serial Downloading  
Both the Flash and EEPROM memory arrays can be programmed using the serial SPI bus while  
RESET is pulled to GND. The serial interface consists of pins SCK, MOSI (input) and MISO (out-  
put). After RESET is set low, the Programming Enable instruction needs to be executed first  
before program/erase operations can be executed. NOTE, in Table 21-14 on page 254, the pin  
mapping for SPI programming is listed. Not all parts use the SPI pins dedicated for the internal  
SPI interface.  
Figure 21-7. Serial programming and verify (1)  
.
+1.8V - 5.5V  
VCC  
+1.8V - 5.5V(2)  
MOSI_A  
MISO_A  
AVCC  
SCK_A  
XTAL1  
RESET  
GND  
Notes: 1. If the device is clocked by the internal Oscillator, it is no need to connect a clock source to the  
XTAL1 pin.  
2. VCC - 0.3V < AVCC < VCC + 0.3V, however, AVCC should always be within 1.8V - 5.5V.  
When programming the EEPROM, an auto-erase cycle is built into the self-timed programming  
operation (in the Serial mode ONLY) and there is no need to first execute the Chip Erase  
instruction. The Chip Erase operation turns the content of every memory location in both the  
Program and EEPROM arrays into 0xFF.  
Depending on CKSEL Fuses, a valid clock must be present. The minimum low and high periods  
for the serial clock (SCK) input are defined as follows:  
Low: > 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  
21.8.1  
Serial Programming Algorithm  
When writing serial data to the AT90PWM81/161, data is clocked on the rising edge of SCK.  
When reading data from the AT90PWM81/161, data is clocked on the falling edge of SCK. See  
Figure 21-8 on page 263 for timing details.  
To program and verify the AT90PWM81/161 in the serial programming mode, the following  
sequence is recommended (see four byte instruction formats in Table 21-16 on page 263):  
1. Power-up sequence:  
Apply power between VCC and GND while RESET and SCK are set to “0”. In some sys-  
tems, the programmer can not guarantee that SCK is held low during power-up. In this  
261  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
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.  
3. The serial programming instructions will not work if the communication is out of syn-  
chronization. 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 21-15 on page 263.) Accessing the serial programming inter-  
face 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 21-15 on page 263.) 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.  
21.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 writ-  
ten. 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 21-15 on page 263 for tWD_FLASH value.  
21.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-pro-  
grammed 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 21-15 on page 263 for tWD_EEPROM value.  
262  
7734Q–AVR–02/12  
AT90PWM81/161  
Table 21-15. Minimum wait delay before writing the next flash or EEPROM location.  
Symbol  
Minimum wait delay  
tWD_FLASH  
tWD_EEPROM  
tWD_ERASE  
4.5ms  
3.6ms  
9.0ms  
Figure 21-8. Serial programming waveforms.  
SERIAL DATA INPUT  
MSB  
LSB  
LSB  
(MOSI)  
SERIAL DATA OUTPUT  
(MISO)  
MSB  
SERIAL CLOCK INPUT  
(SCK)  
SAMPLE  
Table 21-16. Serial programming instruction set.  
Instruction format  
Instruction  
Byte 1  
Byte 2  
Byte 3  
Byte 4  
Operation  
1010 1100  
0101 0011  
xxxx xxxx  
xxxx xxxx  
Enable serial programming after  
RESET goes low  
Programming enable  
Chip erase  
1010 1100  
100x xxxx  
xxxx xxxx  
xxxx xxxx  
Chip erase EEPROM and flash  
0010 H000  
000a aaaa  
bbbb bbbb  
oooo oooo Read H (high or low) data o from  
Program memory at word address a:b  
Read program memory  
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  
Load program memory page  
0100 1100  
1010 0000  
1100 0000  
1100 0001  
000a aaaa  
000x xxaa  
000x xxaa  
0000 0000  
bbxx xxxx  
bbbb bbbb  
bbbb bbbb  
0000 00bb  
xxxx xxxx  
Write Program Memory Page at  
address a:b  
Write program memory page  
Read EEPROM memory  
Write EEPROM memory  
oooo oooo Read data o from EEPROM memory at  
address a:b  
iiii iiii  
Write data i to EEPROM memory at  
address a:b  
iiii iiii  
Load data i to EEPROM memory page  
buffer. After data is loaded, program  
EEPROM page  
Load EEPROM memory  
page (page access)  
Write EEPROM memory  
page (page access)  
1100 0010  
0101 1000  
00xx xxaa  
bbbb bb00  
xxxx xxxx  
Write EEPROM page at address a:b  
0000 0000  
xxxx xxxx  
xxoo oooo  
Read Lock bits. “0” = programmed, “1”  
= unprogrammed. See Table 21-1 on  
page 248 for details  
Read lock bits  
263  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Table 21-16. Serial programming instruction set. (Continued)  
Instruction format  
Instruction  
Byte 1  
Byte 2  
Byte 3  
Byte 4  
Operation  
1010 1100  
111x xxxx  
xxxx xxxx  
11ii iiii  
Write Lock bits. Set bits = “0” to  
program Lock bits. See Table 21-1 on  
page 248 for details  
Write Lock bits  
Read Signature Byte  
Write Fuse bits  
0011 0000  
1010 1100  
000x xxxx  
1010 0000  
xxxx xxbb  
oooo oooo Read Signature Byte o at address b  
xxxx xxxx  
iiii iiii  
Set bits = “0” to program, “1” to  
unprogram. See Table 21-6 on page  
251 for details  
1010 1100  
1010 1100  
0101 0000  
0101 1000  
0101 0000  
1010 1000  
1010 0100  
0000 0000  
0000 1000  
0000 1000  
xxxx xxxx  
xxxx xxxx  
xxxx xxxx  
xxxx xxxx  
xxxx xxxx  
iiii iiii  
Set bits = “0” to program, “1” to  
unprogram. See Table 21-5 on page  
250 for details  
Write Fuse High bits  
Write Extended Fuse Bits  
Read Fuse bits  
xxxx xxii  
Set bits = “0” to program, “1” to  
unprogram. See Table 21-4 on page  
249 for details  
oooo oooo Read Fuse bits. “0” = programmed, “1”  
= unprogrammed. See Table 21-6 on  
page 251 for details  
oooo oooo Read Fuse High bits. “0” = pro-  
grammed, “1” = unprogrammed. See  
Table 21-5 on page 250 for details  
Read Fuse High bits  
oooo oooo Read Extended Fuse bits. “0” = pro-  
grammed, “1” = unprogrammed. See  
Read Extended Fuse Bits  
Read Calibration Byte  
Poll RDY/BSY  
Table 21-4 on page 249 for details  
0011 1000  
1111 0000  
000x xxxx  
0000 0000  
0000 0000  
xxxx xxxx  
oooo oooo Read Calibration Byte  
xxxx xxxo  
If o = “1”, a programming operation is  
still busy. Wait until this bit returns to  
“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 = don’t care.  
21.8.4  
SPI Serial Programming Characteristics  
For characteristics of the SPI module see “SPI Serial Programming Characteristics” on page 264.  
264  
7734Q–AVR–02/12  
 
AT90PWM81/161  
22. Electrical Characteristics (1)  
22.1 Absolute Maximum Ratings*  
*NOTICE:  
Stresses beyond those listed under “Absolute  
Maximum Ratings” may cause permanent dam-  
age to the device. This is a stress rating only and  
functional operation of the device at these or  
other conditions beyond those indicated in the  
operational sections of this specification is not  
implied. Exposure to absolute maximum rating  
conditions for extended periods may affect device  
reliability.  
Operating temperature................................... -40°C to +105°C  
Or operating temperature .............................. -40°C to +125°C  
Storage temperature...................................... -65°C to +150°C  
Voltage on any pin except RESET  
with respect to ground .................................-1.0V to VCC+0.5V  
Voltage on RESET with respect to ground ......-1.0V to +13.0V  
Maximum operating voltage.............................................. 6.0V  
DC current per I/O pin.................................................. 40.0mA  
DC current VCC and GND pins.................................. 200.0mA  
Note:  
1. Electrical characteristics for this product have not yet been finalized. Please consider all values  
listed herein as preliminary and non-contractual.  
265  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
22.2 DC Characteristics  
TA = -40°C to +105°C, VCC = 2.7V to 5.5V (unless otherwise noted).  
Symbol  
Parameter  
Condition  
Minimum  
Typical  
Maximum  
Units  
Port B & D and XTAL1,  
XTAL2 pins as I/O  
(1)  
VIL  
Input low voltage  
-0.5  
0.2VCC  
Port B D and XTAL1,  
XTAL2 pins as I/O  
(2)  
VIH  
Input high voltage  
Input low voltage  
Input high voltage  
0.6VCC  
VCC+0.5  
XTAL1 pin , External  
Clock Selected  
(1)  
VIL1  
VIH1  
-0.5  
0.1VCC  
XTAL1 pin , External  
Clock Selected  
(2)  
0.7VCC  
VCC+0.5  
(1)  
VIL2  
VIH2  
VIL3  
VIH3  
Input low voltage  
Input high voltage  
Input low voltage  
Input high voltage  
RESET pin  
-0.5  
0.2VCC  
(2)  
RESET pin  
0.9VCC  
VCC+0.5  
(1)  
RESET pin as I/O  
RESET pin as I/O  
-0.5  
0.2VCC  
V
(2)  
0.8VCC  
VCC+0.5  
Output low voltage (3)  
(Port B & D and XTAL1,  
XTAL2 pins as I/O)  
IOL = 10mA, VCC = 5V  
IOL = 5mA, VCC = 3V  
0.6  
0.5  
VOL  
Output high voltage (4)  
(Port B & D and XTAL1,  
XTAL2 pins as I/O)  
IOH = -10mA, VCC = 5V  
IOH = -5mA, VCC = 3V  
4.3  
2.5  
VOH  
Output low voltage (3)  
(RESET pin as I/O)  
I
OL = 2.1mA, VCC = 5V  
0.7  
0.5  
VOL3  
VOH3  
IIL  
IOL = 0.8mA, VCC = 3V  
Output high voltage (4)  
(RESET pin as I/O)  
IOH = -0.6mA, VCC = 5V  
IOH = -0.4mA, VCC = 3V  
3.8  
2.2  
Input leakage  
current I/O pin  
VCC = 5.5V, pin low  
(absolute value)  
1
1
µA  
Input leakage  
current I/O pin  
VCC = 5.5V, pin high  
(absolute value)  
IIH  
RRST  
Rpu  
Reset pull-up resistor  
I/O pin pull-up resistor  
30  
20  
200  
50  
kW  
266  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
TA = -40°C to +105°C, VCC = 2.7V to 5.5V (unless otherwise noted). (Continued)  
Symbol  
Parameter  
Condition  
Minimum  
Typical  
Maximum  
Units  
Active 8MHz, VCC = 3V,  
RC osc., PRR = 0xFF  
3.5  
5
Active 16MHz, VCC = 5V,  
Ext Clock, PRR = 0xFF  
10.5  
1.5  
4.5  
7
15  
2
Power supply current  
mA  
Idle 8MHz, VCC = 3V,  
RC Osc  
Idle 16MHz, VCC = 5V,  
Ext Clock  
7
WDT enabled,VCC = 3V  
25°C  
µA  
µA  
µA  
WDT enabled, VCC = 3V  
105°C  
30  
50  
25  
ICC  
WDT enabled, VCC = 5V  
25°C  
10  
0.5  
1
WDT enabled, VCC = 5V  
105°C  
Power-down mode (5)  
WDT disabled, VCC = 3V  
25°C  
WDT disabled, VCC = 3V  
105°C  
WDT disabled, VCC = 5V  
25°C  
WDT disabled, VCC = 5V  
105°C  
40  
µA  
V
Internal voltage reference  
VREF  
@25°C  
2.46  
0.1  
2.56  
2.66  
(7)  
Analog comparator input  
common mode range  
V
CC - 0.1  
Input offset voltage  
0.1<VIN<VCC - 0.1V  
1.5  
10  
25  
10  
Analog comparator input  
offset voltage  
With 10mV hysteresis  
0.1<VIN<VCC - 0.1V  
VACIO  
20  
mV  
With 25mV hysteresis  
0.1<VIN<VCC - 0.1V  
60  
Analog comparator input  
leakage current  
VCC = 5V  
IACLK  
tACID  
-50  
50  
nA  
ns  
VIN = VCC/2  
Analog comparator  
propagation delay  
VCC = 2.7V  
VCC = 5.0V  
50 (6)  
267  
7734Q–AVR–02/12  
AT90PWM81/161  
TA = -40°C to +125°C, VCC = 2.7V to 5.5V (unless otherwise noted). (Continued)  
Symbol  
Parameter  
Condition  
Minimum  
Typical  
Maximum  
Units  
Port B & D and XTAL1,  
XTAL2 pins as I/O  
(1)  
VIL  
Input low voltage  
-0.5  
0.2VCC  
Port B D and XTAL1,  
XTAL2 pins as I/O  
(2)  
VIH  
Input high voltage  
Input low voltage  
Input high voltage  
0.6VCC  
VCC+0.5  
XTAL1 pin,  
External Clock selected  
(1)  
VIL1  
VIH1  
-0.5  
0.1VCC  
XTAL1 pin,  
External Clock selected  
(2)  
0.7VCC  
VCC+0.5  
(1)  
VIL2  
VIH2  
VIL3  
VIH3  
Input low voltage  
Input high voltage  
Input low voltage  
Input high voltage  
RESET pin  
-0.5  
0.2VCC  
(2)  
RESET pin  
0.9VCC  
VCC+0.5  
(1)  
RESET pin as I/O  
RESET pin as I/O  
-0.5  
0.2VCC  
V
(2)  
0.8VCC  
VCC+0.5  
Output low voltage (3)  
(Port B & D and XTAL1,  
XTAL2 pins as I/O)  
IOL = 10mA, VCC = 5V  
IOL = 5mA, VCC = 3V  
0.6  
0.5  
VOL  
Output high voltage (4)  
(Port B & D and XTAL1,  
XTAL2 pins as I/O)  
IOH = -10mA, VCC = 5V  
IOH = -5mA, VCC = 3V  
4.3  
2.5  
VOH  
Output low voltage (3)  
(RESET pin as I/O)  
IOL = 2.1mA, VCC = 5V  
IOL = 0.8mA, VCC = 3V  
0.7  
0.5  
VOL3  
VOH3  
IIL  
Output high voltage (4)  
(RESET pin as I/O)  
IOH = -0.6mA, VCC = 5V  
IOH = -0.4mA, VCC = 3V  
3.8  
2.2  
Input leakage  
current I/O pin  
VCC = 5.5V, pin low  
(absolute value)  
1
1
µA  
Input leakage  
current I/O pin  
VCC = 5.5V, pin high  
(absolute value)  
IIH  
RRST  
RPU  
Reset pull-up resistor  
I/O pin pull-up resistor  
30  
20  
200  
50  
kW  
268  
7734Q–AVR–02/12  
AT90PWM81/161  
Symbol  
Parameter  
Condition  
Minimum  
Typical  
Maximum  
Units  
Active 8MHz, VCC = 3V,  
RC osc, PRR = 0xFF  
3.5  
5
Active 16MHz, VCC = 5V,  
Ext Clock, PRR = 0xFF  
10.5  
1.5  
4.5  
7
15  
2
Power supply current  
mA  
Idle 8MHz, VCC = 3V,  
RC Osc  
Idle 16MHz, VCC = 5V,  
Ext Clock  
7
WDT enabled, VCC = 3V  
25°C  
WDT enabled, VCC = 3V  
125°C  
70  
110  
35  
ICC  
WDT enabled, VCC = 5V  
25°C  
10  
0.5  
1
WDT enabled, VCC = 5V  
125°C  
Power-down mode (5)  
µA  
WDT disabled, VCC = 3V  
25°C  
WDT disabled, VCC = 3V  
125°C  
WDT disabled, VCC = 5V  
25°C  
WDT disabled, VCC = 5V  
125°C  
55  
Internal voltage reference  
VREF  
@25°C  
2.46  
0.1  
2.56  
2.66  
(7)  
V
Analog comparator input  
common mode range  
V
CC - 0.1  
Input offset voltage  
0.1<VIN<VCC - 0.1V  
1.5  
10  
25  
10  
Analog comparator input  
offset voltage  
With 10mV Hysteresis  
0.1<VIN<VCC - 0.1V  
VACIO  
20  
mV  
With 25mV Hysteresis  
0.1<VIN<VCC - 0.1V  
60  
Analog comparator  
input leakage current  
VCC = 5V  
VIN = VCC/2  
IACLK  
tACID  
Note:  
-50  
50  
nA  
ns  
Analog comparator  
propagation delay  
VCC = 2.7V  
VCC = 5.0V  
50 (6)  
1. “Maximum” means the highest value where the pin is guaranteed to be read as low.  
2. “Minimum” 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:  
SO20 and TQFN Package:  
1] The sum of all IOL, for all ports, should not exceed 400mA.  
2] The sum of all IOL, for ports B6 - B7, D0 - D3, E0 should not exceed 100mA.  
3] The sum of all IOL, for ports B0 - B1, D4, E1 - E2 should not exceed 100mA.  
269  
7734Q–AVR–02/12  
 
AT90PWM81/161  
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:  
SO20 and TQFN Package:  
1] The sum of all IOH, for all ports, should not exceed 400mA.  
2] The sum of all IOH, for ports B6 - B7, D0 - D3, E0 should not exceed 150mA.  
3] The sum of all IOH, for ports B0 - B1, D4, E1 - E2 should not exceed 150mA.  
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. Minimum VCC for Power-down is 2.5V.  
6. Propagation delay of the internal comparator with 100mV overdrive condition.  
7. accuracy : 8% from -40°C to +125°C.  
22.3 Clock Drive Characteristics  
22.3.1  
Calibrated Internal RC Oscillator Accuracy  
Table 22-1. Calibration accuracy of internal RC oscillator.  
Frequency  
VCC  
Temperature  
Calibration accuracy  
Factory calibration  
8.0MHz  
3V  
25°C  
1%  
-40°C +  
8.0MHz  
2.7V - 5.5V  
2.7V - 5.5V  
6%  
5%  
Factory calibration  
User calibration  
or 125°C  
7.6MHz - 8.4MHz  
-40°C +105 or 125°C  
22.3.2  
Watchdog Oscillator Accuracy  
Table 22-2. Accuracy of watchdog oscillator.  
Frequency  
Accuracy  
128kHz  
40%  
22.3.3  
External Clock Drive Waveforms  
Figure 22-1. External clock drive waveforms.  
VIH1  
VIL1  
270  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
22.3.4  
External Clock Drive  
Table 22-3. External clock drive.  
VCC = 2.7V - 5.5V  
VCC = 4.5V - 5.5V  
Symbol  
1/tCLCL  
tCLCL  
Parameter  
Oscillator frequency  
Clock period  
High time  
Minimum  
Maximum  
Minimum  
Maximum  
Units  
0
12  
0
16  
MHz  
83  
30  
30  
62  
20  
20  
tCHCX  
tCLCX  
tCLCH  
tCHCL  
ns  
Low time  
Rise time  
1.6  
1.6  
0.5  
0.5  
ms  
%
Fall time  
Change in period from one  
clock cycle to the next  
DtCLCL  
2
2
22.4 Maximum Speed vs. VCC  
Maximum frequency is depending on VCC. As shown in Figure 22-2 on page 271 , the Maximum  
Frequency equals 12MHz when VCC is contained between 2.7V and 4.5V and equals 16Mhz  
when VCC is contained between 4.5V and 5.5V.  
Figure 22-2. Maximum frequency vs. VCC, AT90PWM81/161.  
16Mhz  
12Mhz  
8Mhz  
2.7V  
4.5V  
5.5V  
22.5 PLL Characteristics  
Table 22-4. PLL characteristics - VCC = 2.7V to 5.5V (unless otherwise noted).  
Symbol  
PLLIF  
Parameter  
Minimum  
Typical  
Maximum  
Units  
Input frequency (1)  
8
MHz  
PLLF  
PLL factor  
4
8 (2)  
64  
PLLLT  
Lock-in time  
µS  
271  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
Notes: 1. While connected to external clock or external oscillator, PLL Input Frequency must be selected  
to provide outputs with frequency in accordance with driven parts of the circuit.  
2. When VCC is below 4.5V, maximum PLLF is 6.  
22.6 SPI Timing Characteristics  
See Figure 22-3 on page 273 and Figure 22-4 on page 273 for details.  
Table 22-5. SPI timing parameters.  
Description  
Mode  
Minimum  
Typical  
Maximum  
Units  
See Table 14-  
5 on page 187  
1
SCK period  
Master  
2
3
SCK high/low  
Rise/fall time  
Setup  
Master  
Master  
Master  
Master  
Master  
Master  
Master  
Slave  
Slave  
50% duty cycle  
3.6  
10  
4
ns  
5
Hold  
10  
6
Out to SCK  
SCK to out  
SCK to out high  
SS low to out  
SCK period  
SCK high/low (1)  
Rise/fall time  
Setup  
0.5 • tsck  
10  
7
8
10  
9
15  
10  
11  
12  
13  
14  
15  
16  
17  
18  
4 • tck  
2 • tck  
Slave  
Slave  
Slave  
Slave  
1.6  
10  
tck  
Hold  
ns  
SCK to out  
SCK to SS high  
SS high to tri-state  
SS low to SCK  
Slave  
Slave  
Slave  
Slave  
15  
10  
20  
2 • tck  
Notes: 1. In SPI programming mode the minimum SCK high/low period is:  
- 2 tCLCL for fCK <12MHz  
- 3 tCLCL for fCK >12MHz  
272  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Figure 22-3. SPI interface timing requirements (Master mode).  
SS  
6
1
SCK  
(CPOL = 0)  
2
2
SCK  
(CPOL = 1)  
4
5
3
MISO  
(Data Input)  
MSB  
...  
LSB  
7
8
MOSI  
(Data Output)  
MSB  
...  
LSB  
Figure 22-4. SPI interface timing requirements (Slave mode).  
SS  
10  
16  
9
SCK  
(CPOL = 0)  
11  
11  
SCK  
(CPOL = 1)  
13  
14  
12  
MOSI  
(Data Input)  
MSB  
...  
LSB  
15  
17  
MISO  
(Data Output)  
MSB  
...  
LSB  
X
273  
7734Q–AVR–02/12  
AT90PWM81/161  
22.7 ADC Characteristics  
Table 22-6. ADC characteristics - TA = -45°C to +105°C, VCC = 2.7V to 5.5V (unless otherwise noted).  
Symbol  
Parameter  
Condition  
Minimum  
Typical  
Maximum  
Units  
Single Ended Conversion  
10  
Differential conversion,  
Gain = 5× or 10×  
8
8
Resolution  
Bits  
Differential conversion,  
Gain = 20× or 40×  
Single Ended Conversion,  
VCC = 4V, VREF = 4V  
ADC clock = 1MHz  
2
4
4
Single Ended Conversion,  
VCC = 2.7V, VREF =2.56V  
ADC clock = 2MHz  
2.2  
Differential conversion,  
Gain = 5× or 10×  
VCC = 5V, VREF = 4V  
ADC clock = 1MHz  
Absolute accuracy  
LSB  
1.2  
1.5  
2.0  
3.0  
Differential conversion,  
Gain = 20× or 40×  
VCC = 5V, VREF = 4V  
ADC clock = 2MHz  
Single Ended Conversion,  
V
CC = 4V, VREF = 4V  
0.6  
0.8  
1.0  
1
ADC clock = 1MHz  
Single Ended Conversion,  
VCC = 4V, VREF = 4V  
ADC clock = 2MHz  
1.5  
2.5  
Single Ended Conversion,  
VCC = 2.7V, VREF = 2.56V  
Integral non-linearity  
ADC clock = 2MHz  
LSB  
Differential conversion,  
Gain=5× or 10×  
0.5  
0.8  
1.0  
2.0  
VCC = 5V, VREF = 4V  
ADC clock = 1MHz  
Differential conversion,  
Gain=20× or 40×  
VCC = 5V, VREF = 4V  
ADC clock = 2MHz  
274  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Table 22-6. ADC characteristics - TA = -45°C to +105°C, VCC = 2.7V to 5.5V (unless otherwise noted). (Continued)  
Symbol  
Parameter  
Condition  
Minimum  
Typical  
Maximum  
Units  
Single Ended conversion,  
VCC = 4V, VREF = 4V  
ADC clock = 1MHz  
0.2  
0.5  
Single Ended conversion,  
VCC = 4V, VREF = 4V  
ADC clock = 2MHz  
0.6  
1.0  
1
Single Ended conversion,  
VCC = 2.7V, VREF =2.56V  
ADC clock = 2MHz  
2.5  
Differential non-linearity  
LSB  
Differential conversion,  
Gain=5× or 10×  
VCC = 5V, VREF = 4V  
ADC clock = 1MHz  
0.3  
0.5  
0.8  
1.0  
Differential conversion,  
Gain=20× or 40×  
VCC = 5V, VREF = 4V  
ADC clock = 2MHz  
Single Ended conversion,  
VCC = 4V, VREF = 4V  
ADC clock = 1MHz  
0.0  
0.0  
-6.0  
-6.0  
+2.0  
2.0  
Single Ended conversion,  
Gain error  
VCC = 2.7V, VREF = 2.56V  
LSB  
ADC clock = 2MHz  
Differential conversion,  
VCC = 5V, VREF = 4V  
-2.0  
-1.0  
1.0  
ADC clock = 1MHz  
Single Ended conversion,  
VCC = 4V, VREF = 4V  
ADC clock = 1MHz  
Single Ended conversion,  
Offset error  
VCC = 2.7V, VREF = 2.56V  
4.0  
LSB  
ADC clock = 2MHz  
Differential conversion,  
VCC = 5V, VREF = 4V  
-1.0  
+1.0  
ADC clock = 1MHz  
Conversion time  
Single conversion  
8
50  
260  
2000  
µs  
kHz  
V
Clock frequency  
AVCC  
VREF  
VIN  
Analog supply voltage  
Reference voltage  
VCC - 0.3  
2.56  
VCC + 0.3  
AVCC - 0.6  
VREF  
V
Single Ended conversion  
Differential conversion  
Single Ended conversion  
Differential conversion  
GND  
Input voltage  
-VREF/Gain  
+VREF/Gain  
38.5  
4
Input bandwidth  
kHz  
275  
7734Q–AVR–02/12  
AT90PWM81/161  
Table 22-6. ADC characteristics - TA = -45°C to +105°C, VCC = 2.7V to 5.5V (unless otherwise noted). (Continued)  
Symbol  
RREF  
Parameter  
Condition  
Minimum  
Typical  
30  
Maximum  
Units  
Reference input resistance  
Analog input resistance  
Analog input capacitor  
kW  
RAIN  
23  
CAIN  
10  
pF  
µA  
Increased current  
consumption  
High speed mode  
Single Ended conversion  
IHSM  
380  
22.8 DAC Characteristics  
Table 22-7. DAC characteristics - TA = -45°C to +105°C, VCC = 2.7V to 5.5V (unless otherwise noted).  
Symbol  
Parameter  
Condition  
Minimum  
Typical  
10  
Maximum  
Units  
Resolution  
DAC  
Absolute accuracy  
Integral non-linearity  
Differential non-linearity  
Gain error  
V
CC = 4V, VREF = 4V  
VCC = 4V, VREF = 4V  
CC = 4V, VREF = 4V  
2.5  
5
1.5  
0.8  
V
0.2  
0.5  
LSB  
V
VCC = 4V, VREF = 4V  
VCC = 4V, VREF = 4V  
-5.0  
0.0  
0.0  
Offset error  
2.0  
VREF  
Reference voltage  
2.56  
AVCC  
22.9 Parallel Programming Characteristics  
Figure 22-5. Parallel programming timing, including some general timing requirements.  
tXLWL  
tXHXL  
XTAL1  
tDVXH  
tXLDX  
Data & Contol  
(DATA, XA0, XA1/BS2, PAGEL/BS1)  
tBVPH  
tPLBX tBVWL  
tWLBX  
tWLWH  
WR  
tPLWL  
WLRL  
RDY/BSY  
tWLRH  
276  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
Figure 22-6. Parallel programming timing, loading sequence with timing requirements (1)  
.
LOAD ADDRESS  
(LOW BYTE)  
LOAD DATA  
(LOW BYTE)  
LOAD DATA  
(HIGH BYTE)  
LOAD ADDRESS  
(LOW BYTE)  
tXLXH  
XTAL1  
PAGEL/BS1  
DATA  
ADDR0 (Low Byte)  
DATA (Low Byte)  
DATA (High Byte)  
ADDR1 (Low Byte)  
XA0  
XA1/BS2  
Note:  
1. The timing requirements shown in Figure 22-5 on page 276 (that is, tDVXH, tXHXL, and tXLDX)  
also apply to loading operation.  
Figure 22-7. Parallel programming timing, reading sequence (within the same page) with timing requirements (1)  
.
LOAD ADDRESS  
(LOW BYTE)  
READ DATA  
(LOW BYTE)  
READ DATA  
(HIGH BYTE)  
LOAD ADDRESS  
(LOW BYTE)  
tXLOL  
XTAL1  
tBVDV  
PAGEL/BS1  
tOLDV  
OE  
tOHDZ  
ADDR1 (Low Byte)  
DATA (High Byte)  
DATA  
ADDR0 (Low Byte)  
DATA (Low Byte)  
XA0  
XA1/BS2  
Note:  
1. The timing requirements shown in Figure 22-5 on page 276 (that is, tDVXH, tXHXL, and tXLDX  
also apply to reading operation.  
)
277  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Table 22-8. Parallel programming characteristics, VCC = 5V ±10%.  
Symbol  
VPP  
Parameter  
Minimum  
Typical  
Maximum Units  
Programming enable voltage  
Programming enable current  
Data and control valid before XTAL1 High  
XTAL1 Low to XTAL1 High  
XTAL1 Pulse Width High  
Data and Control Hold after XTAL1 Low  
XTAL1 Low to WR Low  
11.5  
12.5  
250  
V
IPP  
mA  
tDVXH  
tXLXH  
tXHXL  
tXLDX  
tXLWL  
tXLPH  
tPLXH  
tBVPH  
tPHPL  
tPLBX  
tWLBX  
tPLWL  
tBVWL  
tWLWH  
tWLRL  
tWLRH  
67  
200  
150  
67  
0
XTAL1 Low to PAGEL high  
PAGEL low to XTAL1 high  
BS1 Valid before PAGEL High  
PAGEL Pulse Width High  
BS1 Hold after PAGEL Low  
BS2/1 Hold after WR Low  
PAGEL Low to WR Low  
0
150  
67  
150  
67  
67  
67  
67  
150  
0
ns  
BS1 Valid to WR Low  
WR Pulse Width Low  
WR Low to RDY/BSY Low  
WR Low to RDY/BSY High (1)  
1
5
ms  
ms  
3.7  
WR Low to RDY/BSY High for Chip Erase  
tWLRH_CE  
7.5  
10  
(2)  
tXLOL  
tBVDV  
tOLDV  
tOHDZ  
XTAL1 Low to OE Low  
BS1 Valid to DATA valid  
OE Low to DATA Valid  
OE High to DATA Tri-stated  
0
0
250  
250  
250  
ns  
Notes: 1. tWLRH is valid for the Write Flash, Write EEPROM, Write Fuse bits and Write Lock bits  
commands.  
2. tWLRH_CE is valid for the Chip Erase command.  
278  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
23. AT90PWM81/161 Typical Characteristics  
The following charts show typical behavior. These figures are not tested during manufacturing.  
All current consumption measurements are performed with all I/O pins configured as inputs and  
with internal pull-ups enabled. A sine wave generator with rail-to-rail output is used as clock  
source.  
All Active- and Idle current consumption measurements are done with all bits in the PRR register  
set and thus, the corresponding I/O modules are turned off. Also the Analog Comparator is dis-  
abled during these measurements.  
The power consumption in Power-down mode is independent of clock selection.  
The current consumption is a function of several factors such as: operating voltage, operating  
frequency, loading of I/O pins, switching rate of I/O pins, code executed and ambient tempera-  
ture. The dominating factors are operating voltage and frequency.  
The current drawn from capacitive loaded pins may be estimated (for one pin) as CL× VCC × f,  
where:  
CL = load capacitance, VCC = operating voltage and f = average switching frequency of I/O pin.  
The parts are characterized at frequencies higher than test limits. Parts are not guaranteed to  
function properly at frequencies higher than the ordering code indicates.  
The difference between current consumption in Power-down mode with Watchdog Timer  
enabled and Power-down mode with Watchdog Timer disabled represents the differential cur-  
rent drawn by the Watchdog Timer.  
279  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
23.1 Active Supply Current  
Figure 23-1. Active supply current vs. frequency (0.1MHz - 1.0MHz).  
ACTIVE SUPPLY CURRENT vs. LOW FREQUENCY  
1.2  
5.5V  
5.0V  
1
0.8  
0.6  
0.4  
0.2  
0
4.5V  
4.0V  
3.6V  
3.3V  
2.7V  
0.1  
0.2  
0.3  
0.4  
0.5  
0.6  
0.7  
0.8  
0.9  
1
280  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Figure 23-2. Active supply current vs. frequency (1MHz - 16MHz).  
ACTIVE SUPPLY CURRENT vs. FREQUENCY  
14  
12  
10  
8
5.5V  
5.0V  
4.5V  
4.0V  
3.6V  
6
3.3V  
2.7V  
4
2
0
1
3
5
7
9
11  
13  
15  
Frequency [MHz]  
Figure 23-3. Active supply current vs. VCC (internal RC oscillator, 8MHz).  
ACTIVE SUPPLY CURRENT vs. VCC  
INTERNAL RC OSCILLATOR, 8MHz  
10  
9
8
7
6
5
4
3
2
1
0
125°C  
105°C  
25°C  
-40°C  
2.7  
3.2  
3.7  
4.2  
CC [V]  
4.7  
5.2  
V
281  
7734Q–AVR–02/12  
AT90PWM81/161  
Figure 23-4. Active supply current vs. VCC (external clock, 16MHz).  
ACTIVE SUPPLY CURRENT vs. VCC  
EXTERNAL CLOCK 16MHz - ATD ON  
16  
14  
12  
10  
8
125°C  
105°C  
25°C  
-40°C  
6
4
2
0
2.7  
3.2  
3.7  
4.2  
VCC [V]  
4.7  
5.2  
23.2 Idle Supply Current  
Figure 23-5. Idle supply current vs. frequency (0.1MHz - 1.0MHz).  
IDLE SUPPLY CURRENT vs. LOW FREQUENCY  
0.35  
5.5V  
5.0V  
0.3  
0.25  
0.2  
4.5V  
4.0V  
3.6V  
3.3V  
0.15  
0.1  
2.7V  
0.05  
0
0.1  
0.2  
0.3  
0.4  
0.5  
0.6  
0.7  
0.8  
0.9  
1
Frequency [MHz]  
282  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Figure 23-6. Idle supply current vs. frequency (1MHz - 16MHz).  
IDLE SUPPLY CURRENT vs. FREQUENCY  
5
4.5  
4
5.5V  
5.0V  
4.5V  
3.5  
3
4.0V  
3.6V  
2.5  
2
3.3V  
2.7V  
1.5  
1
0.5  
0
1
3
5
7
9
11  
13  
15  
Frequency [MHz]  
Figure 23-7. Idle supply current vs. VCC (internal RC oscillator, 8MHz).  
IDLE SUPPLY CURRENT vs. VCC  
INTERNAL RC OSCILLATOR, 8MHz  
4
3.5  
3
125°C  
105°C  
25°C  
2.5  
2
-40°C  
1.5  
1
0.5  
0
2.7  
3.2  
3.7  
4.2  
VCC [V]  
4.7  
5.2  
283  
7734Q–AVR–02/12  
AT90PWM81/161  
Figure 23-8. Idle supply current vs. VCC (external clock, 16MHz).  
IDLE SUPPLY CURRENT vs. VCC  
EXTERNAL CLOCK 16MHz  
6
5
4
3
2
1
0
-40°C  
125°C  
105°C  
25°C  
2.7  
3.2  
3.7  
4.2  
CC [V]  
4.7  
5.2  
V
23.3 Power-Down Supply Current  
Figure 23-9. Power-down supply current vs. VCC (watchdog timer disabled).  
POWER-DOWN SUPPLY CURRENT vs. VCC  
WATCHDOG TIMER DISABLED  
12  
10  
8
125°C  
6
4
105°C  
2
25°C  
0
-40°C  
2.7  
3.2  
3.7  
4.2  
CC [V]  
4.7  
5.2  
V
284  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Figure 23-10. Power-down supply current vs. VCC (watchdog timer enabled).  
POWER-DOWN SUPPLY CURRENT vs. VCC  
WATCHDOG TIMER ENABLED  
25  
20  
15  
10  
5
125°C  
105°C  
-40°C  
25°C  
0
2.7  
3.2  
3.7  
4.2  
CC [V]  
4.7  
5.2  
V
23.4 Pin Pull-up  
Figure 23-11. I/O pin pull-up resistor current vs. input voltage (VCC = 5V).  
I/O PIN PULL-UP RESISTOR CURRENT vs. INPUT VOLTAGE  
Vcc = 5V  
160  
25°C  
105°C  
140  
-40°C  
120  
125°C  
100  
80  
60  
40  
20  
0
0
0.5  
1
1.5  
2
2.5  
VOP [V]  
3
3.5  
4
4.5  
5
285  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Figure 23-12. I/O pin pull-up resistor current vs. input voltage (VCC = 2.7V).  
I/O PIN PULL-UP RESISTOR CURRENT vs. INPUT VOLTAGE  
Vcc = 2.7V  
80  
25°C  
-40°C  
70  
105°C  
125°C  
60  
50  
40  
30  
20  
10  
0
0
0.5  
1
1.5  
2
2.5  
VOP [V]  
3
3.5  
4
4.5  
5
Figure 23-13. I/O pin pull-up resistor current vs. input voltage, PE1 & PE2 pins (VCC = 5V).  
I/O PIN PULL-UP RESISTOR CURRENT vs. INPUT VOLTAGE  
PE1 & PE2 PINS  
Vcc = 5V  
160  
105°C  
140  
25°C  
-40°C  
120  
100  
80  
60  
40  
20  
0
125°C  
0
0.5  
1
1.5  
2
2.5  
OP [V]  
3
3.5  
4
4.5  
5
V
286  
7734Q–AVR–02/12  
AT90PWM81/161  
Figure 23-14. I/O pin pull-up resistor current vs. input voltage, PE1 & PE2 pins (VCC = 2.7V).  
I/O PIN PULL-UP RESISTOR CURRENT vs. INPUT VOLTAGE  
PE1 & PE2 PINS  
Vcc = 2.7V  
90  
80  
-40°C  
25°C  
105°C  
70  
125°C  
60  
50  
40  
30  
20  
10  
0
0
0.5  
1
1.5  
2
2.5  
VOP [V]  
3
3.5  
4
4.5  
5
Figure 23-15. Reset pull-up resistor current vs. reset pin voltage (VCC = 5V).  
RESET PULL-UP RESISTOR CURRENT vs. RESET PIN VOLTAGE  
Vcc = 5V  
120  
-40°C  
105°C  
25°C  
100  
80  
60  
40  
20  
0
125°C  
0
0.5  
1
1.5  
2
2.5  
3
3.5  
4
4.5  
5
VRESET [V]  
287  
7734Q–AVR–02/12  
AT90PWM81/161  
Figure 23-16. Reset pull-up resistor current vs. reset pin voltage (VCC = 2.7V).  
RESET PULL-UP RESISTOR CURRENT vs. RESET PIN VOLTAGE  
Vcc = 2.7V  
60  
-40°C  
25°C  
105°C  
50  
125°C  
40  
30  
20  
10  
0
0
0.5  
1
1.5  
2
2.5  
RESET [V]  
3
3.5  
4
4.5  
5
V
23.5 Pin output high voltage  
Figure 23-17. I/O pin output voltage vs. source current (VCC = 5V).  
I/O PIN OUTPUT VOLTAGE vs. SOURCE CURRENT  
Vcc = 5.0V  
6
5
4
3
2
1
0
-40°C  
125°C  
25°C  
105°C  
0
1
2
3
4
5
6
7
8
9
10  
IOH [mA]  
288  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Figure 23-18. I/O pin output voltage vs. source current (VCC = 3V).  
I/O PIN OUTPUT VOLTAGE vs. SOURCE CURRENT  
Vcc = 3.0V  
3.5  
3
-40°C  
2.5  
2
25°C  
105°C  
125°C  
1.5  
1
0.5  
0
0
1
2
3
4
5
6
7
8
9
10  
IOH [mA]  
23.6 Pin output low voltage  
Figure 23-19. I/O pin output voltage vs. sink current (VCC = 5V).  
I/O PIN OUTPUT VOLTAGE vs. SINK CURRENT  
Vcc = 5.0V  
0.6  
0.5  
0.4  
0.3  
0.2  
0.1  
0
125°C  
105°C  
25°C  
-40°C  
0
1
2
3
4
5
6
7
8
9
10  
IOL [mA]  
289  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Figure 23-20. I/O pin output voltage vs. sink current (VCC = 3V).  
I/O PIN OUTPUT VOLTAGE vs. SINK CURRENT  
Vcc = 3.0V  
0.8  
0.7  
0.6  
0.5  
0.4  
0.3  
0.2  
0.1  
0
125°C  
105°C  
25°C  
-40°C  
0
1
2
3
4
5
6
7
8
9
10  
I
OL [mA]  
23.7 Pin Thresholds  
Figure 23-21. I/O pin input threshold voltage vs. VCC (VIL, I/O pin read As '0').  
I/O PIN INPUT THRESHOLD VOLTAGE vs. VCC  
VIL, IO PIN READ AS '0'  
3
2.5  
2
125°C  
105°C  
25°C  
-40°C  
1.5  
1
0.5  
0
2.7  
3.2  
3.7  
4.2  
CC [V]  
4.7  
5.2  
V
290  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Figure 23-22. I/O pin input threshold voltage vs. VCC (VIH, I/O pin read as '1').  
I/O PIN INPUT THRESHOLD VOLTAGE vs. VCC  
VIH, IO PIN READ AS '1'  
4
3.5  
3
125°C  
-40°C  
105°C  
25°C  
2.5  
2
1.5  
1
0.5  
0
2.7  
3.2  
3.7  
4.2  
CC [V]  
4.7  
5.2  
V
23.8 BOD Thresholds  
Figure 23-23. BOD thresholds vs. temperature (BODLEVEL is 4.3V).  
BOD THRESHOLDS vs. TEMPERATURE  
BODLEVEL is 4.3V  
4.6  
4.5  
4.4  
4.3  
4.2  
4.1  
4
Rising Vcc  
Falling Vcc  
3.9  
3.8  
-40 -30 -20 -10  
0
10  
20 30  
40 50  
60  
70 80  
90 100 110 120  
Temperature [°C]  
291  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Figure 23-24. BOD thresholds vs. temperature (BODLEVEL is 2.7V).  
BOD THRESHOLDS vs. TEMPERATURE  
BODLEVEL is 2.7V  
2.9  
2.8  
2.7  
2.6  
2.5  
2.4  
Rising Vcc  
Falling Vcc  
-40 -30 -20 -10  
0
10  
20  
30 40  
50  
60  
70 80  
90 100 110 120  
Temperature [°C]  
23.9 Analog Reference  
Figure 23-25. VREF voltage vs. VCC  
.
IINTERNAL VREF vs Vcc  
2.65  
2.6  
125°C  
105°C  
25°C  
2.55  
2.5  
2.45  
2.4  
-40°C  
2.35  
2.3  
2.7  
3.2  
3.7  
4.2  
Vcc (V)  
4.7  
5.2  
292  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Figure 23-26. VREF voltage vs. temperature.  
INTERNAL VREF vs TEMPERATURE  
2.65  
5.5V  
2.7V  
2.6  
2.55  
2.5  
2.45  
2.4  
2.35  
-40 -30 -20 -10  
0
10 20 30 40 50 60 70 80 90 100 110 120  
Temperature (°C)  
23.10 Internal Oscillator Speed  
Figure 23-27. Watchdog oscillator frequency vs. VCC  
.
WATCHDOG OSCILLATOR FREQUENCY vs. OPERATING VOLTAGE  
0.14  
0.135  
0.13  
-40°C  
25°C  
0.125  
0.12  
125°C  
105°C  
0.115  
0.11  
0.105  
0.1  
2.7  
3.2  
3.7  
4.2  
CC [V]  
4.7  
5.2  
V
293  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Figure 23-28. Calibrated 8MHz RC oscillator frequency vs. temperature.  
CALIBRATED 8MHz RC OSCILLATOR FREQUENCY vs. TEMPERATURE  
RC OSC CALIBRATED @ ROOM TEMP  
8.3  
8.2  
8.1  
8
5.4V  
5.6V  
2.6V  
5.2V  
5V  
4V  
2.8V  
V
7.9  
7.8  
7.7  
-40  
-25  
-10  
5
20  
35  
50  
65  
80  
95  
110  
125  
Temperature [°C]  
Figure 23-29. Calibrated 8MHz RC oscillator frequency vs. VCC  
.
CALIBRATED 8MHz RC OSCILLATOR FREQUENCY vs. OPERATING  
VOLTAGE  
RC OSC CALIBRATED @ ROOM TEMP  
8.3  
8.2  
8.1  
8
125°C  
105°C  
25°C  
7.9  
7.8  
7.7  
7.6  
-40°C  
2.4  
2.9  
3.4  
3.9  
CC [V]  
4.4  
4.9  
5.4  
V
294  
7734Q–AVR–02/12  
AT90PWM81/161  
Figure 23-30. Calibrated 8MHz RC oscillator frequency vs. osccal value.  
INT RC OSCILLATOR Frequency vs. OSCCAL  
10000 Cycles sampled with 250nS - VCC 3V  
25°C  
-40°C  
105°C  
1600000  
1400000  
1200000  
1000000  
800000  
600000  
400000  
0
16 32 48 64 80 96 112 128 144 160 176 192 208 224 240  
OSCCAL  
23.11 Current Consumption in Reset  
Figure 23-31. Reset supply current vs. VCC (0.1MHz - 1.0MHz, excluding current through the  
reset pull-up).  
RESET SUPPLY CURRENT vs Vcc  
EXCLUDING CURRENT THROUGH THE RESET PULLUP  
1
0.9  
5.5V  
0.8  
0.7  
0.6  
0.5  
0.4  
0.3  
2.7V  
0.2  
0.1  
0
0.1  
0.2  
0.3  
0.4  
0.5  
0.6  
0.7  
0.8  
0.9  
1
Frequency MHz  
All temperatures  
295  
7734Q–AVR–02/12  
 
AT90PWM81/161  
Figure 23-32. Reset supply current vs. VCC (1MHz - 16MHz, excluding current through the reset  
pull-up).  
4
3.5  
3
5.5V  
2.5  
2
1.5  
1
2.7V  
0.5  
0
1
3
5
7
9
11  
13  
15  
Frequency MHz  
All temperatures  
296  
7734Q–AVR–02/12  
AT90PWM81/161  
24. Register Summary  
Address  
Name  
Bit 7  
Bit 6  
Bit 5  
Bit 4  
Bit 3  
Bit 2  
Bit 1  
Bit 0  
Page  
(0xFF)  
(0xFE)  
(0xFD)  
(0xFC)  
(0xFB)  
(0xFA)  
(0xF9)  
(0xF8)  
(0xF7)  
(0xF6)  
(0xF5)  
(0xF4)  
(0xF3)  
(0xF2)  
(0xF1)  
(0xF0)  
(0xEF)  
(0xEE)  
(0xED)  
(0xEC)  
(0xEB)  
(0xEA)  
(0xE9)  
(0xE8)  
(0xE7)  
(0xE6)  
(0xE5)  
(0xE4)  
(0xE3)  
(0xE2)  
(0xE1)  
(0xE0)  
(0xDF)  
(0xDE)  
(0xDD)  
(0xDC)  
(0xDB)  
(0xDA)  
(0xD9)  
(0xD8)  
(0xD7)  
(0xD6)  
(0xD5)  
(0xD4)  
(0xD3)  
(0xD2)  
(0xD1)  
(0xD0)  
(0xCF)  
(0xCE)  
(0xCD)  
(0xCC)  
(0xCB)  
(0xCA)  
(0xC9)  
(0xC8)  
(0xC7)  
(0xC6)  
(0xC5)  
(0xC4)  
(0xC3)  
(0xC2)  
(0xC1)  
(0xC0)  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
297  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Address  
Name  
Bit 7  
Bit 6  
Bit 5  
Bit 4  
Bit 3  
Bit 2  
Bit 1  
Bit 0  
Page  
(0xBF)  
(0xBE)  
(0xBD)  
(0xBC)  
(0xBB)  
(0xBA)  
(0xB9)  
(0xB8)  
(0xB7)  
(0xB6)  
(0xB5)  
(0xB4)  
(0xB3)  
(0xB2)  
(0xB1)  
(0xB0)  
(0xAF)  
(0xAE)  
(0xAD)  
(0xAC)  
(0xAB)  
(0xAA)  
(0xA9)  
(0xA8)  
(0xA7)  
(0xA6)  
(0xA5)  
(0xA4)  
(0xA3)  
(0xA2)  
(0xA1)  
(0xA0)  
(0x9F)  
(0x9E)  
(0x9D)  
(0x9C)  
(0x9B)  
(0x9A)  
(0x99)  
(0x98)  
(0x97)  
(0x96)  
(0x95)  
(0x94)  
(0x93)  
(0x9r)  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
Reserved  
ICR1H  
(0x91)  
(0x90)  
(0x8F)  
(0x8E)  
(0x8D)  
(0x8C)  
(0x8B)  
(0x8A)  
(0x89)  
(0x88)  
(0x87)  
(0x86)  
(0x85)  
(0x84)  
(0x83)  
(0x82)  
(0x81)  
(0x80)  
(0x7F)  
(0x7E)  
ICR115  
ICR114  
ICR113  
ICR15  
ICR112  
ICR14  
ICR111  
ICR13  
ICR110  
ICR12  
ICR19  
ICR11  
ICR18  
ICR10  
98  
98  
ICR1L  
ICR17  
ICR16  
Reserved  
TCCR1B  
EICRA  
ICNC1  
ICES1  
WGM13  
ISC20  
CAL4  
PLLF2  
PRTIM1  
CS12  
ISC10  
CAL2  
PLLF0  
PRSPI  
CS11  
ISC01  
CAL1  
PLLE  
CS10  
ISC00  
CAL0  
PLOCK  
PRADC  
97  
83  
ISC21  
CAL5  
PLLF3  
PRPSCR  
ISC11  
CAL3  
PLLF1  
OSCCAL  
PLLCSR  
-
CAL6  
39  
-
41  
PRR  
PRPSC2  
49  
CLKSELR  
CLKCSR  
CLKPR  
43  
COUT  
CSUT1  
CSUT0  
CLKRDY  
CSEL3  
CLKC3  
CLKPS3  
WDE  
BGCC3  
BGCR3  
AC3OEA  
CSEL2  
CLKC2  
CLKPS2  
WDP2  
BGCC2  
BGCR2  
AC3M2  
AC2M2  
CSEL1  
CLKC1  
CLKPS1  
WDP1  
BGCC1  
BGCR1  
AC3M1  
AC2M1  
CSEL0  
CLKC0  
CLKPS0  
WDP0  
BGCC0  
BGCR0  
AC3M0  
AC2M0  
CLKCCE  
CLKPCE  
WDIF  
42  
WDP3  
WDCE  
40  
WDTCSR  
BGCCR  
WDIE  
59  
190  
191  
199  
198  
BGCRR  
AC3CON  
AC2CON  
AC3EN  
AC2EN  
AC3IE  
AC2IE  
AC3IS1  
AC2IS1  
AC3IS0  
AC2IS0  
298  
7734Q–AVR–02/12  
AT90PWM81/161  
Address  
Name  
Bit 7  
Bit 6  
Bit 5  
Bit 4  
Bit 3  
Bit 2  
Bit 1  
Bit 0  
Page  
(0x7D)  
(0x7C)  
AC1CON  
AC3ECON  
AC2ECON  
AC1ECON  
AMP0CSR  
DIDR1  
AC1EN  
AC1IE  
AC1IS1  
AC3OI  
AC1IS0  
AC3OE  
AC2OE  
AC1OE  
AMP0G0  
AC1M2  
AC3H2  
AC2H2  
AC1H2  
AC1M1  
AC3H1  
AC1M0  
AC3H0  
197  
200  
200  
200  
225  
222  
222  
228  
(0x7B)  
AC2OI  
AC2H1  
AC2H0  
(0x7A)  
AMP0EN  
AMP0IS  
AC1OI  
AC1ICE  
AMP0GS  
AC1H1  
AC1H0  
(0x79)  
AMP0G1  
AMP0TS1  
AMP0TS0  
ACMP1MD  
AMP0+D  
ADC10D  
ADC9D  
(0x78)  
ADC8D/ACMP3D ADC7D/AMP0-D  
ADC5D/ACMP2D  
ADC4D/ACMP3M ADC3D/ACMPMD ADC2D/ACMP2M ADC1D  
ADC0D/ACMP1D  
DAEN  
(0x77)  
DIDR0  
(0x76)  
DACON  
DAATE  
DATS2  
DATS1  
DATS0  
DALA  
(0x75)  
Room for analog test registers  
(0x74)  
(0x73)  
(0x72)  
(0x71)  
PASDLY2  
PCNFE2  
POM2  
PASDLY2[7:0]  
139  
137  
142  
134  
142  
142  
(0x70)  
PASDLKn2 PASDLKn1  
PASDLKn0  
PBFMn1  
POMV2B0  
PSYNC20  
PELEVnA1  
POMV2A3  
POEN2D  
PELEVnB1  
POMV2A2  
POEN2B  
PISEL0A1  
POMV2A1  
POEN2C  
PISEL0B1  
POMV2A0  
POEN2A  
(0x6F)  
POMV2B3  
POMV2B2  
POS22  
POMV2B1  
PSYNC21  
(0x6E)  
PSOC2  
POS23  
PCST2  
(0x6D)  
PICR2H  
PICR2L  
Reserved  
PSOC0  
PICR2[11:8]  
(0x6C)  
PICR2[7:0]  
(0x6B)  
PISEL0B1  
PSYNC01  
PSYNC00  
(0x6A)  
PISEL0A1  
PCST0  
POEN0B  
POEN0A  
171  
177  
177  
141  
141  
135  
135  
175  
175  
172  
172  
10  
(0x69)  
PICR0H  
PICR0L  
PFRC2B  
PFRC2A  
OCR2SAH  
OCR2SAL  
PFRC0B  
PFRC0A  
OCR0SAH  
OCR0SAL  
SREG  
PICR0[11:8]  
(0x68)  
PICR0[7:0]  
(0x67)  
PCAE2B  
PCAE2A  
PISEL2B  
PISEL2A  
PELEV2B  
PELEV2A  
PFLTE2B  
PFLTE2A  
PRFM2B3  
PRFM2A3  
PRFM2B2  
PRFM2A2  
PRFM2B1  
PRFM2A1  
PRFM2B0  
PRFM2A0  
(0x66)  
(0x65)  
OCR2SA[11:8]  
(0x64)  
OCR2SA[7:0]  
(0x63)  
PCAE0B  
PCAE0A  
PISEL0B  
PISEL0A  
PELEV0B  
PELEV0A  
PFLTE0B  
PFLTE0A  
PRFM0B3  
PRFM0A3  
PRFM0B2  
PRFM0A2  
PRFM0B1  
PRFM0A1  
PRFM0B0  
PRFM0A0  
(0x62)  
(0x61)  
OCR0SA[11:8]  
(0x60)  
OCR0SA[7:0]  
0x3F (0x5F)  
0x3E (0x5E)  
0x3D (0x5D)  
0x3C (0x5C)  
0x3B (0x5B)  
0x3A (0x5A)  
0x39 (0x59)  
0x38 (0x58)  
0x37 (0x57)  
0x36 (0x56)  
0x35 (0x55)  
0x34 (0x54)  
0x33 (0x53)  
0x32 (0x52)  
0x31 (0x51)  
0x30 (0x50)  
0x2F (0x4F)  
0x2E (0x4E)  
0x2D (0x4D)  
0x2C (0x4C)  
0x2B (0x4B)  
0x2A (0x4A)  
0x29 (0x49)  
0x28 (0x48)  
0x27 (0x47)  
0x26 (0x46)  
0x25 (0x45)  
0x24 (0x44)  
0x23 (0x43)  
0x22 (0x42)  
0x21 (0x41)  
0x20 (0x40)  
0x1F (0x3F)  
0x1E (0x3E)  
0x1D (0x3D)  
0x1C (0x3C)  
I
T
H
S
V
N
Z
SP9  
C
SP8  
SPH  
SP5  
SP11  
SP10  
12  
SPL  
SP7  
SP6  
SP4  
SP3  
SP2  
SP1  
SP0  
12  
Reserved  
TCNT1H  
TCNT1L  
DACH  
TCNT115  
TCNT17  
- / DAC9  
TCNT114  
TCNT16  
- / DAC8  
TCNT113  
TCNT15  
- / DAC7  
DAC5 / -  
SIGRD  
SPD5  
TCNT112  
TCNT14  
- / DAC6  
DAC4 / -  
RWWSRE  
SPD4  
PUD  
TCNT111  
TCNT13  
- / DAC5  
DAC3 / -  
BLBSET  
SPD3  
TCNT110  
TCNT12  
- / DAC4  
DAC2 / -  
PGWRT  
SPD2  
TCNT19  
TCNT11  
DAC9 / DAC3  
DAC1 / -  
PGERS  
SPD1  
TCNT18  
TCNT10  
DAC8 / DAC2  
DAC0 /  
SPMEN  
SPD0  
IVCE  
98  
98  
229  
DACL  
DAC7 / DAC1 DAC6 /DAC0  
229  
SPMCSR  
SPDR  
SPMIE  
RWWSB  
238  
SPD7  
SPD6  
188  
MCUCR  
MCUSR  
SMCR  
RSTDIS  
WDRF  
SM2  
CKRC81  
BORF  
SM1  
IVSEL  
EXTRF  
SM0  
55 & 74  
54  
PORF  
SE  
48  
MSMCR  
DWDR  
Monitor Stop Mode Control Register  
DWDR[7:0]  
reserved  
232  
Reserved  
OCR2RAH  
OCR2RAL  
ADCH  
OCR2RA[11:8]  
135  
135  
221  
221  
172  
172  
136  
136  
136  
136  
172  
172  
172  
172  
84  
OCR2RA[7:0]  
- / ADC9  
- / ADC8  
- / ADC7  
ADC5 / -  
- / ADC6  
ADC4 / -  
- / ADC5  
ADC3 / -  
- / ADC4  
ADC2 / -  
ADC9 / ADC3  
ADC1 / -  
ADC8 / ADC2  
ADC0 /  
ADCL  
ADC7 / ADC1 ADC6 / ADC0  
OCR0RAH  
OCR0RAL  
OCR2RBH  
OCR2RBL  
OCR2SBH  
OCR2SBL  
OCR0RBH  
OCR0RBL  
OCR0SBH  
OCR0SBL  
EIMSK  
OCR0RA[11:8]  
OCR0RA[7:0]  
OCR2RB[15:12]  
OCR2RB[11:8]  
OCR2SB[11:8]  
OCR0RB[11:8]  
OCR0SB[11:8]  
OCR2RB[7:0]  
OCR2SB[7:0]  
OCR0RB[7:0]  
OCR0SB[7:0]  
OCR0RB[15:12]  
INT2  
INT1  
INTF1  
INT0  
INTF0  
EEAR8  
EEAR0  
EEDR0  
EERE  
EIFR  
INTF2  
84  
EEARH  
EEARL  
19  
EEAR7  
EEDR7  
NVMBSY  
EEAR6  
EEDR6  
EEPAGE  
EEAR5  
EEDR5  
EEPM1  
EEAR4  
EEDR4  
EEPM0  
EEAR3  
EEDR3  
EERIE  
EEAR2  
EEDR2  
EEMWE  
EEAR1  
EEDR1  
EEWE  
19  
EEDR  
19  
EECR  
19  
299  
7734Q–AVR–02/12  
AT90PWM81/161  
Address  
Name  
Bit 7  
Bit 6  
Bit 5  
Bit 4  
Bit 3  
Bit 2  
Bit 1  
Bit 0  
Page  
0x1B (0x3B)  
0x1A (0x3A)  
0x19 (0x39)  
0x18 (0x38)  
0x17 (0x37)  
0x16 (0x36)  
0x15 (0x35)  
0x14 (0x34)  
0x13 (0x33)  
0x12 (0x32)  
0x11 (0x31)  
0x10 (0x30)  
0x0F (0x2F)  
0x0E (0x2E)  
0x0D (0x2D)  
0x0C (0x2C)  
0x0B (0x2B)  
0x0A (0x2A)  
0x09 (0x29)  
0x08 (0x28)  
0x07 (0x27)  
0x06 (0x26)  
0x05 (0x25)  
0x04 (0x24)  
0x03 (0x23)  
0x02 (0x22)  
0x01 (0x21)  
0x00 (0x20)  
GPIOR2  
GPIOR1  
GPIOR0  
SPSR  
GPIOR27  
GPIOR17  
GPIOR07  
SPIF  
GPIOR26  
GPIOR16  
GPIOR06  
WCOL  
GPIOR25  
GPIOR15  
GPIOR05  
GPIOR24  
GPIOR14  
GPIOR04  
GPIOR23  
GPIOR13  
GPIOR03  
GPIOR22  
GPIOR12  
GPIOR02  
GPIOR21  
GPIOR11  
GPIOR01  
GPIOR20  
GPIOR10  
GPIOR00  
SPI2X  
26  
26  
26  
188  
186  
140  
136  
144  
143  
174  
173  
178  
177  
82  
SPCR  
SPIE  
SPE  
DORD  
MSTR  
CPOL  
CPHA  
PARUN2  
POP2  
SPR1  
SPR0  
PCTL2  
PCNF2  
PIFR2  
PPRE21  
PFIFTY2  
POAC2B  
-
PPRE20  
PALOCK2  
POAC2A  
-
PBFM2  
PLOCK2  
PSEI2  
PAOC2B  
PMODE21  
PEV2B  
PAOC2A  
PMODE20  
PEV2A  
PCCYC2  
PCLKSEL2  
PRN20  
PRUN2  
POME2  
PEOP2  
PEOPE2  
PRN21  
-
PSEIE2  
PEVE2B  
PEVE2A  
PEOEPE2  
PIM2  
PCTL0  
PCNF0  
PIFR0  
PPRE01  
PFIFTY0  
POAC0B  
-
PPRE00  
PALOCK0  
POAC0A  
-
PBFM01  
PLOCK0  
PAOC0B  
PMODE01  
PEV0B  
PAOC0A  
PMODE00  
PEV0A  
PBFM00  
POP0  
PCCYC0  
PCLKSEL0  
PRN00  
PRUN0  
PRN01  
PEOP0  
PEOPE0  
PEVE0B  
PEVE0A  
PEOEPE0  
PIM0  
PORTE  
DDRE  
PORTE2  
DDE2  
PINE2  
PORTD2  
DDD2  
PIND2  
MUX2  
ADTS2  
ADPS2  
PORTB2  
DDB2  
PINB2  
PORTE1  
DDE1  
PINE1  
PORTD1  
DDD1  
PIND1  
MUX1  
ADTS1  
ADPS1  
PORTB1  
DDB1  
PINB1  
PORTE0  
DDE0  
82  
PINE  
PINE0  
PORTD0  
DDD0  
PIND0  
MUX0  
ADTS0  
ADPS0  
PORTB0  
DDB0  
82  
PORTD  
DDRD  
PIND  
PORTD7  
DDD7  
PIND7  
REFS1  
ADHSM  
ADEN  
PORTB7  
DDB7  
PINB7  
PORTD6  
DDD6  
PIND6  
REFS0  
ADNCDIS  
ADSC  
PORTB6  
DDB6  
PINB6  
PORTD5  
DDD5  
PIND5  
ADLAR  
PORTD4  
DDD4  
PIND4  
PORTD3  
DDD3  
PIND3  
MUX3  
ADTS3  
ADIE  
PORTB3  
DDB3  
PINB3  
82  
82  
82  
ADMUX  
ADCSRB  
ADCSRA  
PORTB  
DDRB  
PINB  
217  
220  
219  
81  
ADSSEN  
ADIF  
PORTB4  
DDB4  
PINB4  
ADATE  
PORTB5  
DDB5  
PINB5  
ICF1  
ICIE1  
AC1IF  
82  
PINB0  
TOV1  
82  
TIFR1  
99  
TIMSK1  
ACSR  
TOIE1  
99  
AC3IF  
AC2IF  
AC3O  
AC2O  
AC1O  
201  
Note:  
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 AT90PWM81/161 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.  
300  
7734Q–AVR–02/12  
AT90PWM81/161  
25. Instruction Set Summary  
Mnemonics  
Operands  
Description  
Operation  
Flags  
#Clocks  
ARITHMETIC AND LOGIC INSTRUCTIONS  
ADD  
ADC  
Rd, Rr  
Rd, Rr  
Rdl,K  
Rd, Rr  
Rd, K  
Rd, Rr  
Rd, K  
Rdl,K  
Rd, Rr  
Rd, K  
Rd, Rr  
Rd, K  
Rd, Rr  
Rd  
Add two Registers  
Add with Carry two Registers  
Add Immediate to Word  
Subtract two Registers  
Subtract Constant from Register  
Subtract with Carry two Registers  
Subtract with Carry Constant from Reg.  
Subtract Immediate from Word  
Logical AND Registers  
Logical AND Register and Constant  
Logical OR Registers  
Rd ¬ Rd + Rr  
Rd ¬ Rd + Rr + C  
Rdh:Rdl ¬ Rdh:Rdl + K  
Rd ¬ Rd - Rr  
Z, C, N, V, H  
Z, C, N, V, H  
Z, C, N, V, S  
Z, C, N, V, H  
Z, C, N, V, H  
Z, C, N, V, H  
Z, C, N, V, H  
Z, C, N, V, S  
Z, N, V  
1
1
2
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
ADIW  
SUB  
SUBI  
SBC  
Rd ¬ Rd - K  
Rd ¬ Rd - Rr - C  
Rd ¬ Rd - K - C  
Rdh:Rdl ¬ Rdh:Rdl - K  
Rd ¬ Rd · Rr  
SBCI  
SBIW  
AND  
ANDI  
OR  
Rd ¬ Rd · K  
Z, N, V  
Rd ¬ Rd v Rr  
Z, N, V  
ORI  
Logical OR Register and Constant  
Exclusive OR Registers  
One’s Complement  
Rd ¬ Rd v K  
Z, N, V  
EOR  
COM  
NEG  
SBR  
Rd ¬ Rd Å Rr  
Z, N, V  
Rd ¬ 0xFF - Rd  
Rd ¬ 0x00 - Rd  
Rd ¬ Rd v K  
Z, C, N, V  
Z, C, N, V, H  
Z, N, V  
Rd  
Two’s Complement  
Rd,K  
Rd,K  
Rd  
Set Bit(s) in Register  
CBR  
Clear Bit(s) in Register  
Increment  
Rd ¬ Rd · (0xFF - K)  
Rd ¬ Rd + 1  
Z, N, V  
INC  
Z, N, V  
DEC  
Rd  
Decrement  
Rd ¬ Rd - 1  
Z, N, V  
TST  
Rd  
Test for Zero or Minus  
Rd ¬ Rd · Rd  
Z, N, V  
CLR  
Rd  
Clear Register  
Rd ¬ Rd Å Rd  
Rd ¬ 0xFF  
Z, N, V  
SER  
Rd  
Set Register  
None  
MUL  
Rd, Rr  
Rd, Rr  
Rd, Rr  
Rd, Rr  
Rd, Rr  
Rd, Rr  
Multiply Unsigned  
R1:R0 ¬ Rd x Rr  
R1:R0 ¬ Rd x Rr  
R1:R0 ¬ Rd x Rr  
R1:R0 ¬ (Rd x Rr) << 1  
R1:R0 ¬ (Rd x Rr) << 1  
R1:R0 ¬ (Rd x Rr) << 1  
Z, C  
MULS  
MULSU  
FMUL  
FMULS  
FMULSU  
Multiply Signed  
Z, C  
Multiply Signed with Unsigned  
Fractional Multiply Unsigned  
Fractional Multiply Signed  
Fractional Multiply Signed with Unsigned  
Z, C  
Z, C  
Z, C  
Z, C  
BRANCH INSTRUCTIONS  
JMP  
(AT90PWM161)  
k
Direct jump  
Direct call  
PC ¬ k  
PC ¬ k  
None  
None  
3
4
CALL  
(AT90PWM161)  
k
k
RJMP  
IJMP  
Relative Jump  
Indirect Jump to (Z)  
PC ¬ PC + k + 1  
PC ¬ Z  
None  
None  
2
2
RCALL  
ICALL  
RET  
k
Relative Subroutine Call  
Indirect Call to (Z)  
PC ¬ PC + k + 1  
None  
3
PC ¬ Z  
None  
3
Subroutine Return  
PC ¬ STACK  
None  
4
RETI  
Interrupt Return  
PC ¬ STACK  
I
4
CPSE  
CP  
Rd,Rr  
Compare, Skip if Equal  
Compare  
if (Rd = Rr) PC ¬ PC + 2 or 3  
Rd - Rr  
None  
1/2/3  
1
Rd,Rr  
Z, N, V, C, H  
Z, N, V, C, H  
Z, N, V, C, H  
None  
CPC  
Rd,Rr  
Compare with Carry  
Rd - Rr - C  
1
CPI  
Rd,K  
Compare Register with Immediate  
Skip if Bit in Register Cleared  
Skip if Bit in Register is Set  
Skip if Bit in I/O Register Cleared  
Skip if Bit in I/O Register is Set  
Branch if Status Flag Set  
Branch if Status Flag Cleared  
Branch if Equal  
Rd - K  
1
SBRC  
SBRS  
SBIC  
Rr, b  
if (Rr(b)=0) PC ¬ PC + 2 or 3  
if (Rr(b)=1) PC ¬ PC + 2 or 3  
if (P(b)=0) PC ¬ PC + 2 or 3  
if (P(b)=1) PC ¬ PC + 2 or 3  
if (SREG(s) = 1) then PC¬PC+k + 1  
if (SREG(s) = 0) then PC¬PC+k + 1  
if (Z = 1) then PC ¬ PC + k + 1  
if (Z = 0) then PC ¬ PC + k + 1  
if (C = 1) then PC ¬ PC + k + 1  
if (C = 0) then PC ¬ PC + k + 1  
if (C = 0) then PC ¬ PC + k + 1  
if (C = 1) then PC ¬ PC + k + 1  
if (N = 1) then PC ¬ PC + k + 1  
if (N = 0) then PC ¬ PC + k + 1  
if (N Å V= 0) then PC ¬ PC + k + 1  
if (N Å V= 1) then PC ¬ PC + k + 1  
if (H = 1) then PC ¬ PC + k + 1  
if (H = 0) then PC ¬ PC + k + 1  
if (T = 1) then PC ¬ PC + k + 1  
if (T = 0) then PC ¬ PC + k + 1  
if (V = 1) then PC ¬ PC + k + 1  
1/2/3  
1/2/3  
1/2/3  
1/2/3  
1/2  
1/2  
1/2  
1/2  
1/2  
1/2  
1/2  
1/2  
1/2  
1/2  
1/2  
1/2  
1/2  
1/2  
1/2  
1/2  
1/2  
Rr, b  
None  
P, b  
P, b  
s, k  
s, k  
k
None  
SBIS  
None  
BRBS  
BRBC  
BREQ  
BRNE  
BRCS  
BRCC  
BRSH  
BRLO  
BRMI  
BRPL  
BRGE  
BRLT  
BRHS  
BRHC  
BRTS  
BRTC  
BRVS  
None  
None  
None  
k
Branch if Not Equal  
None  
k
Branch if Carry Set  
None  
k
Branch if Carry Cleared  
Branch if Same or Higher  
Branch if Lower  
None  
k
None  
k
None  
k
Branch if Minus  
None  
k
Branch if Plus  
None  
k
Branch if Greater or Equal, Signed  
Branch if Less Than Zero, Signed  
Branch if Half Carry Flag Set  
Branch if Half Carry Flag Cleared  
Branch if T Flag Set  
None  
k
None  
k
None  
k
None  
k
None  
k
Branch if T Flag Cleared  
Branch if Overflow Flag is Set  
None  
k
None  
301  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
Mnemonics  
Operands  
Description  
Operation  
Flags  
#Clocks  
BRVC  
BRIE  
BRID  
k
k
k
Branch if Overflow Flag is Cleared  
Branch if Interrupt Enabled  
Branch if Interrupt Disabled  
if (V = 0) then PC ¬ PC + k + 1  
if ( I = 1) then PC ¬ PC + k + 1  
if ( I = 0) then PC ¬ PC + k + 1  
None  
None  
None  
1/2  
1/2  
1/2  
BIT AND BIT-TEST INSTRUCTIONS  
SBI  
CBI  
P,b  
P,b  
Rd  
Rd  
Rd  
Rd  
Rd  
Rd  
s
Set Bit in I/O Register  
Clear Bit in I/O Register  
Logical Shift Left  
I/O(P,b) ¬ 1  
None  
2
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
I/O(P,b) ¬ 0  
None  
LSL  
Rd(n+1) ¬ Rd(n), Rd(0) ¬ 0  
Z, C, N, V  
LSR  
ROL  
ROR  
ASR  
SWAP  
BSET  
BCLR  
BST  
BLD  
SEC  
CLC  
SEN  
CLN  
SEZ  
CLZ  
SEI  
Logical Shift Right  
Rd(n) ¬ Rd(n+1), Rd(7) ¬ 0  
Z, C, N, V  
Rotate Left Through Carry  
Rotate Right Through Carry  
Arithmetic Shift Right  
Swap Nibbles  
Rd(0)¬C,Rd(n+1)¬ Rd(n),C¬Rd(7)  
Z, C, N, V  
Rd(7)¬C,Rd(n)¬ Rd(n+1),C¬Rd(0)  
Z, C, N, V  
Rd(n) ¬ Rd(n+1), n=0..6  
Z, C, N, V  
Rd(3..0)¬Rd(7..4),Rd(7..4)¬Rd(3..0)  
None  
Flag Set  
SREG(s) ¬ 1  
SREG(s) ¬ 0  
T ¬ Rr(b)  
Rd(b) ¬ T  
C ¬ 1  
SREG(s)  
s
Flag Clear  
SREG(s)  
Rr, b  
Rd, b  
Bit Store from Register to T  
Bit load from T to Register  
Set Carry  
T
None  
C
C
N
N
Z
Clear Carry  
C ¬ 0  
Set Negative Flag  
N ¬ 1  
Clear Negative Flag  
Set Zero Flag  
N ¬ 0  
Z ¬ 1  
Clear Zero Flag  
Z ¬ 0  
Z
Global Interrupt Enable  
Global Interrupt Disable  
Set Signed Test Flag  
Clear Signed Test Flag  
Set Twos Complement Overflow.  
Clear Twos Complement Overflow  
Set T in SREG  
I ¬ 1  
I
CLI  
I ¬ 0  
I
SES  
CLS  
SEV  
CLV  
SET  
CLT  
SEH  
CLH  
S ¬ 1  
S
S ¬ 0  
S
V ¬ 1  
V
V ¬ 0  
V
T ¬ 1  
T
Clear T in SREG  
T ¬ 0  
T
Set Half Carry Flag in SREG  
Clear Half Carry Flag in SREG  
H ¬ 1  
H
H
H ¬ 0  
DATA TRANSFER INSTRUCTIONS  
MOV  
MOVW  
LDI  
LD  
Rd, Rr  
Rd, Rr  
Rd, K  
Move Between Registers  
Copy Register Word  
Rd ¬ Rr  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
None  
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3
3
3
-
Rd+1:Rd ¬ Rr+1:Rr  
Load Immediate  
Rd ¬ K  
Rd ¬ (X)  
Rd, X  
Load Indirect  
LD  
Rd, X+  
Rd, - X  
Rd, Y  
Load Indirect and Post-Inc.  
Load Indirect and Pre-Dec.  
Load Indirect  
Rd ¬ (X), X ¬ X + 1  
X ¬ X - 1, Rd ¬ (X)  
Rd ¬ (Y)  
LD  
LD  
LD  
Rd, Y+  
Rd, - Y  
Rd,Y+q  
Rd, Z  
Load Indirect and Post-Inc.  
Load Indirect and Pre-Dec.  
Load Indirect with Displacement  
Load Indirect  
Rd ¬ (Y), Y ¬ Y + 1  
Y ¬ Y - 1, Rd ¬ (Y)  
Rd ¬ (Y + q)  
Rd ¬ (Z)  
LD  
LDD  
LD  
LD  
Rd, Z+  
Rd, -Z  
Rd, Z+q  
Rd, k  
Load Indirect and Post-Inc.  
Load Indirect and Pre-Dec.  
Load Indirect with Displacement  
Load Direct from SRAM  
Store Indirect  
Rd ¬ (Z), Z ¬ Z+1  
Z ¬ Z - 1, Rd ¬ (Z)  
Rd ¬ (Z + q)  
Rd ¬ (k)  
LD  
LDD  
LDS  
ST  
X, Rr  
(X) ¬ Rr  
ST  
X+, Rr  
- X, Rr  
Y, Rr  
Store Indirect and Post-Inc.  
Store Indirect and Pre-Dec.  
Store Indirect  
(X) ¬ Rr, X ¬ X + 1  
X ¬ X - 1, (X) ¬ Rr  
(Y) ¬ Rr  
ST  
ST  
ST  
Y+, Rr  
- Y, Rr  
Y+q,Rr  
Z, Rr  
Store Indirect and Post-Inc.  
Store Indirect and Pre-Dec.  
Store Indirect with Displacement  
Store Indirect  
(Y) ¬ Rr, Y ¬ Y + 1  
Y ¬ Y - 1, (Y) ¬ Rr  
(Y + q) ¬ Rr  
ST  
STD  
ST  
(Z) ¬ Rr  
ST  
Z+, Rr  
-Z, Rr  
Z+q,Rr  
k, Rr  
Store Indirect and Post-Inc.  
Store Indirect and Pre-Dec.  
Store Indirect with Displacement  
Store Direct to SRAM  
Load Program Memory  
Load Program Memory  
Load Program Memory and Post-Inc  
Store Program Memory  
In Port  
(Z) ¬ Rr, Z ¬ Z + 1  
Z ¬ Z - 1, (Z) ¬ Rr  
(Z + q) ¬ Rr  
ST  
STD  
STS  
LPM  
LPM  
LPM  
SPM  
IN  
(k) ¬ Rr  
R0 ¬ (Z)  
Rd, Z  
Rd ¬ (Z)  
Rd, Z+  
Rd ¬ (Z), Z ¬ Z+1  
(Z) ¬ R1:R0  
Rd, P  
P, Rr  
Rd ¬ P  
1
1
OUT  
Out Port  
P ¬ Rr  
302  
7734Q–AVR–02/12  
AT90PWM81/161  
Mnemonics  
Operands  
Description  
Operation  
Flags  
#Clocks  
PUSH  
POP  
Rr  
Push Register on Stack  
Pop Register from Stack  
STACK ¬ Rr  
Rd ¬ STACK  
None  
None  
2
2
Rd  
MCU CONTROL INSTRUCTIONS  
NOP  
SLEEP  
WDR  
No Operation  
Sleep  
None  
None  
None  
None  
1
1
(see specific descr. for Sleep function)  
(see specific descr. for WDR/timer)  
For On-chip Debug Only  
Watchdog Reset  
Break  
1
BREAK  
N/A  
303  
7734Q–AVR–02/12  
AT90PWM81/161  
26. Ordering Information  
Speed (MHz)  
Power supply  
Ordering code  
Package  
QFN32 (1)  
SO20  
Operation range  
AT90PWM81-16ME  
AT90PWM81-16SE  
AT90PWM81-16MF  
AT90PWM81-16SF  
Extended (-40°C to  
105°C)  
16  
2.7V - 5.5V  
QFN32 (2)  
Extended (-40°C to  
125°C)  
SO20  
AT90PWM161-16MN  
AT90PWM161-16SN  
AT90PWM161-16MF  
AT90PWM161-16SF  
QFN32 (3)  
SO20  
QFN32 (4)  
Extended (-40°C to  
105°C)  
16  
2.7V - 5.5V  
Extended (-40°C to  
125°C)  
SO20  
Note:  
Note:  
All packages are Pb free, fully LHF  
This device can also be supplied in wafer form. Please contact your local Atmel sales office for detailed ordering information and  
minimum quantities.  
Note:  
Note:  
Parts numbers are for shipping in sticks (SO) or in trays (QFN). Thes devices can also be supplied in Tape and Reel. Please  
contact your local Atmel sales office for detailed ordering information and minimum quantities.  
1. Marking on the package is PWM81-MN.  
2. Marking on the package is PWM81-MF.  
3. Marking on the package is PWM161-MN.  
4. Marking on the package is PWM161-MF.  
Package type  
SO20  
TG, 20-lead, 0.300” body width plastic gull wing small outline package (SOIC)  
PN, 32-lead, 5.0 x 5.0mm body, 0.50mm pitch quad flat no lead package (QFN)  
QFN32  
304  
7734Q–AVR–02/12  
 
 
 
 
 
 
AT90PWM81/161  
26.1 SO20  
305  
7734Q–AVR–02/12  
 
AT90PWM81/161  
26.2 QFN32  
306  
7734Q–AVR–02/12  
 
AT90PWM81/161  
27. Errata  
27.1 Errata AT90PWM81 revA  
Available on request  
27.2 Errata AT90PWM81 revB  
Clock Switch disable  
Crystal oscillator control with Clock Switch  
BOD disable fuse  
PSC output at reset  
Flash and EEPROM programming failure if CPU clock is switched  
ADC AMPlifier measurement is unstable  
ADC measurement reports abnormal values with PSC2-synchronized conversions  
Over-consumption in power down sleep mode  
1. Clock Switch enable & disable  
After a “Enable Clock Source” or a “Disable Clock Source” command, the command is still  
active until the next access of CLKCSR register. If CLKSEL is written with a new value, the  
corresponding clock will be unintentionnaly enabled or disabled.  
Work around:  
After the Enable or Disable command, write CLKCSR with value 1<<CLKCCE  
2. Crystal oscillator control with Clock Switch  
When a Xtal oscillator is active and CLKSELR is written with a new value for the selection of  
another clock source (for instance RC or WD) , the Xtal oscillator gain is not correct.  
Work around:  
After the commands “Enable Clock Source” and “Clock Source Switching”, write back CLK-  
SELR with the values corresponding to the active Xtal oscillator  
3. BOD disable fuse  
It is strongly advised to keep the BOD active. Indeed, the RC oscillator may lock if it is acti-  
vated when the power suppy goes at a low voltage.  
Work around:  
If it is mandatory to disable the BOD, do not set the RC oscillator as clock source during  
reset and makes sure the RC oscillator is never active when the power supply is below the  
lowest POR voltage (2.6V).  
4. PSC output at Reset  
At Reset, the PSC outputs may be set at a value different from the PSC Fuse configuration  
(Bit 4 of Extended Fuse Byte).  
Work around:  
Initiate PSC output states from source code.  
307  
7734Q–AVR–02/12  
 
 
 
AT90PWM81/161  
5. Flash and EEPROM programming failure if CPU clock is switched  
If Clock switching is used in the Application, the memory programming is only possible when  
the internal RC oscillator is selected as System clock.  
If the Application requires a memory programming on a clock source different from the inter-  
nal RC oscillator, do not switch to this clock source.  
Work around:  
- Use internal RC oscillator when programming Flash and EEPROM,  
or  
- Do not use clock switching.  
6. ADC AMPlifier measurement is unstable  
When switching from a single-ended ADC channel to an Amplified channel, noise can  
appear on ADC conversion.  
Work around:  
After switching from a single ended to an amplified channel, discard the first ADC  
conversion.  
7. ADC measurement reports abnormal values with PSC2-synchronized  
conversions  
When using ADC in synchronized mode, an unexpected extra Single ended conversion can  
spuriously re-start.This can occur when the End of conversion and the Trigger event occur  
at the same time.  
Work around:  
No workaround  
8. Over-consumption in power down sleep mode.  
In Power-down mode, an extra power consumption up to 500µA may occur.  
Work around:  
No workaround  
27.3 Errata AT90PWM81 revC  
Clock Switch disable  
Crystal oscillator control with Clock Switch  
BOD disable fuse  
PSC output at Reset  
Flash and EEPROM programming failure if CPU clock is switched  
ADC AMPlifier measurement is unstable  
ADC measurement reports abnormal values with PSC2-synchronized conversions  
Over-consumption in power down sleep mode  
308  
7734Q–AVR–02/12  
 
AT90PWM81/161  
1. Clock Switch enable & disable  
After a “Enable Clock Source” or a “Disable Clock Source” command, the command is still  
active until the next access of CLKCSR register. If CLKSEL is written with a new value, the  
corresponding clock will be unintentionnaly enabled or disabled.  
Work around:  
Atter the Enable or Disable command, write CLKCSR with value 1<<CLKCCE  
2. Crystal oscillator control with Clock Switch  
When a Xtal oscillator is active and CLKSELR is written with a new value for the selection of  
another clock source (for instance RC or WD) , the Xtal oscillator gain is not correct.  
Work around:  
After the commands “Enable Clock Source” and “Clock Source Switching”, write back CLK-  
SELR with the values corresponding to the active Xtal oscillator  
3. BOD disable fuse  
It is strongly advised to keep the BOD active. Indeed, the RC oscillator may lock if it is acti-  
vated when the power suppy goes at a low voltage.  
Work around:  
If it is mandatory to disable the BOD, do not set the RC oscillator as clock source during  
reset and makes sure the RC oscillator is never active when the power supply is below the  
lowest POR voltage (2.6V).  
4. PSC output at Reset  
At Reset, the PSC outputs may be set at a value different from the PSC Fuse configuration  
(Bit 4 of Extended Fuse Byte).  
Work around:  
Initiate PSC output states from source code.  
5. Flash and EEPROM programming failure if CPU clock is switched  
If Clock switching is used in the Application, the memory programming is only possible when  
the internal RC oscillator is selected as System clock.  
If the Application requires a memory programming on a clock source different from the inter-  
nal RC oscillator, do not switch to this clock source.  
Work around:  
- Use internal RC oscillator when programming Flash and EEPROM,  
or  
- Do not use clock switching  
6. ADC AMPlifier measurement is unstable  
When switching from a single-ended ADC channel to an Amplified channel, noise can  
appear on ADC conversion.  
Work around:  
After switching from a single ended to an amplified channel, discard the first ADC  
conversion.  
309  
7734Q–AVR–02/12  
AT90PWM81/161  
7. ADC measurement reports abnormal values with PSC2-synchronized  
conversions  
When using ADC in synchronized mode, an unexpected extra Single ended conversion can  
spuriously re-start.This can occur when the End of conversion and the Trigger event occur  
at the same time.  
Work around:  
No workaround  
8. Over-consumption in power down sleep mode.  
In Power-down mode, an extra power consumption up to 500µA may occur.  
Work around:  
No workaround  
27.4 Errata AT90PWM81 revD  
Clock Switch disable  
Crystal oscillator control with Clock Switch  
BOD disable fuse  
Flash and EEPROM programming failure if CPU clock is switched  
ADC Amplifier measurement is unstable  
ADC measurement reports abnormal values with PSC2-synchronized conversions  
Over-consumption in power down sleep mode  
1. Clock Switch enable & disable  
After a “Enable Clock Source” or a “Disable Clock Source” command, the command is still  
active until the next access of CLKCSR register. If CLKSEL is written with a new value, the  
corresponding clock will be unintentionnaly enabled or disabled.  
Work around:  
Atter the Enable or Disable command, write CLKCSR with value 1<<CLKCCE  
2. Crystal oscillator control with Clock Switch  
When a Xtal oscillator is active and CLKSELR is written with a new value for the selection of  
another clock source (for instance RC or WD) , the Xtal oscillator gain is not correct.  
Work around:  
After the commands “Enable Clock Source” and “Clock Source Switching”, write back CLK-  
SELR with the values corresponding to the active Xtal oscillator  
3. BOD disable fuse  
It is strongly advised to keep the BOD active. Indeed, the RC oscillator may lock if it is acti-  
vated when the power suppy goes at a low voltage.  
Work around:  
If it is mandatory to disable the BOD, do not set the RC oscillator as clock source during  
reset and makes sure the RC oscillator is never active when the power supply is below the  
lowest POR voltage (2.6V).  
310  
7734Q–AVR–02/12  
 
AT90PWM81/161  
4. Flash and EEPROM programming failure if CPU clock is switched  
If Clock switching is used in the Application, the memory programming is only possible when  
the internal RC oscillator is selected as System clock.  
If the Application requires a memory programming on a clock source different from the inter-  
nal RC oscillator, do not switch to this clock source.  
Work around:  
- Use internal RC oscillator when programming Flash and EEPROM,  
or  
- Do not use clock switching  
5. ADC AMPlifier measurement is unstable  
When switching from a single-ended ADC channel to an Amplified channel, noise can  
appear on ADC conversion.  
Work around:  
After switching from a single ended to an amplified channel, discard the first ADC  
conversion.  
6. ADC measurement reports abnormal values with PSC2-synchronized  
conversions  
When using ADC in synchronized mode, an unexpected extra Single ended conversion can  
spuriously re-start.This can occur when the End of conversion and the Trigger event occur  
at the same time.  
Work around:  
No workaround  
7. Over-consumption in power down sleep mode  
In Power-down mode, an extra power consumption up to 500µA may occur.  
Work around:  
No workaround  
27.5 Errata AT90PWM81 revE  
Clock Switch disable  
Crystal oscillator control with Clock Switch  
BOD disable fuse  
1. Clock Switch enable & disable  
After a “Enable Clock Source” or a “Disable Clock Source” command, the command is still  
active until the next access of CLKCSR register. If CLKSEL is written with a new value, the  
corresponding clock will be unintentionnaly enabled or disabled.  
Work around:  
Atter the Enable or Disable command, write CLKCSR with value 1<<CLKCCE  
311  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
2. Crystal oscillator control with Clock Switch  
When a Xtal oscillator is active and CLKSELR is written with a new value for the selection of  
another clock source (for instance RC or WD) , the Xtal oscillator gain is not correct.  
Work around:  
After the commands “Enable Clock Source” and “Clock Source Switching”, write back CLK-  
SELR with the values corresponding to the active Xtal oscillator  
3. BOD disable fuse  
It is strongly advised to keep the BOD active. Indeed, the RC oscillator may lock if it is acti-  
vated when the power suppy goes at a low voltage.  
Work around:  
If it is mandatory to disable the BOD, do not set the RC oscillator as clock source during  
reset and makes sure the RC oscillator is never active when the power-supply is below the  
lowest supply voltage (2.6V).  
27.6 Errata AT90PWM161 revA  
Clock Switch disable  
Crystal oscillator control with Clock Switch  
BOD disable fuse  
PCSCRRB fuse  
Over-consumption in power down sleep mode  
1. Clock Switch enable & disable  
After a “Enable Clock Source” or a “Disable Clock Source” command, the command is still  
active until the next access of CLKCSR register. If CLKSEL is written with a new value, the  
corresponding clock will be unintentionnaly enabled or disabled.  
Work around:  
Atter the Enable or Disable command, write CLKCSR with value 1<<CLKCCE  
2. Crystal oscillator control with Clock Switch  
When a Xtal oscillator is active and CLKSELR is written with a new value for the selection of  
another clock source (for instance RC or WD) , the Xtal oscillator gain is not correct.  
Work around:  
After the commands “Enable Clock Source” and “Clock Source Switching”, write back CLK-  
SELR with the values corresponding to the active Xtal oscillator.  
3. BOD disable fuse  
It is strongly advised to keep the BOD active. Indeed, the RC oscillator may lock if it is acti-  
vated when the power suppy goes at a low voltage.  
Work around:  
If it is mandatory to disable the BOD, do not set the RC oscillator as clock source during  
reset and makes sure the RC oscillator is never active when the power-supply is below the  
lowest supply voltage (2.6V).  
312  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
4. PSCRRB fuse  
When this Fuse bit is programmed in Parallel Programming mode, further parallel and ISP  
programming will not program the device correctly.  
Work around:  
Program the PSCRRB fuse using ISP mode.  
5. Over-consumption in power down sleep mode  
In Power-down mode, an extra power consumption up to 500µA may occur.  
Work around:  
No workaround.  
27.7 Errata AT90PWM161 revB  
Clock Switch disable  
Crystal oscillator control with Clock Switch  
BOD disable fuse  
PSCRRB fuse  
1. Clock Switch enable & disable  
After a “Enable Clock Source” or a “Disable Clock Source” command, the command is still  
active until the next access of CLKCSR register. If CLKSEL is written with a new value, the  
corresponding clock will be unintentionnaly enabled or disabled.  
Work around:  
Atter the Enable or Disable command, write CLKCSR with value 1<<CLKCCE  
2. Crystal oscillator control with Clock Switch  
When a Xtal oscillator is active and CLKSELR is written with a new value for the selection of  
another clock source (for instance RC or WD) , the Xtal oscillator gain is not correct.  
Work around:  
After the commands “Enable Clock Source” and “Clock Source Switching”, write back CLK-  
SELR with the values corresponding to the active Xtal oscillator  
3. BOD disable fuse  
It is strongly advised to keep the BOD active. Indeed, the RC oscillator may lock if it is acti-  
vated when the power suppy goes at a low voltage.  
Work around:  
If it is mandatory to disable the BOD, do not set the RC oscillator as clock source during  
reset and makes sure the RC oscillator is never active when the power-supply is below the  
lowest supply voltage (2.6V).  
4. PSCRRB fuse  
When this Fuse bit is programmed in Parallel Programming mode, further parallel and ISP  
programming will not program the device correctly.  
Work around:  
Program the PSCRRB fuse using ISP mode.  
313  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
28. Datasheet Revision History for AT90PWM81/161  
Please note that the referring page numbers in this section are referred to this document. The  
referring revision in this section are referring to the document revision.  
28.1 Rev. 7734A  
28.2 Rev. 7734B  
1. Document creation.  
1. GPIO3 suppressed for compatibility reason.  
2. Pinout: PB7 & PD7 swapped.  
3. CKSEL values redefined.  
4. Clock switching & clock monitoring added.  
5. PSCrOUT name changed to PSCOUTR.  
6. ADC Auto trigger on PSC synchro improved.  
7. Parallel programming updated for 20 pins.  
8. Fuses updated: compatibility & potential conflict for reset levels.  
28.3 Rev. 7734C  
1. Pin out change request.  
2. Several improvements on paragraph indent and numbering.  
3. P28-29: Device clock option select.  
4. P194: BGD bit suppressed.  
5. P311-314: Register address changed.  
28.4 Rev. 7734D  
28.5 Rev. 7734E  
1. Pin name AGND.  
2. PSC reduced support enhanced resolution (Application request).  
1. Speed at 3V, 12Mhz.  
2. Add chapter Pin description (PE request).  
3. Table 7-1: PE function for 128k RC oscillator is I/O.  
4. Details on RC oscillator enable page 30.  
5. New warnings on clock switching page 40.  
6. Details on CKRC81 page 45.  
7. Wake up source PSC not available in PowedDown page 48.  
8. Typos on DIDR0/1.  
9. ADC sample & hold time on auto conversion.  
10. PSC input beheavior during reset precision.  
11. Update using the PRR examples with exsisting peripherals.  
12. Parallel programing input pins.  
13. I/O hysteresis curve.  
314  
7734Q–AVR–02/12  
 
 
 
 
 
 
AT90PWM81/161  
28.6 Rev. 7734F  
1. Clean chapter clock from all “Power save”.  
2. Update chapter “Calibrated Internal RC Oscillator” on page 29.  
3. Update Table 7-9 on page 35: SUT for PLL.  
4. Update chapter Idle Mode page 48.  
5. Update figure “PSC Input Module A” on page 119 and “PSC Input Module B” on page  
120.  
6. Update figure “PSC behavior versus PSCn Input B in Mode 14” on page 132.  
7. Update tables 14-16 ”PSC edge & level input Selection” on page 142 & 14-17 ”PSC  
edge & level input Selection” on page 142.  
8. Clean chaper PSC (no more PSC0 & PSC1 register).  
9. PSCR registers and bits renamed from “r” to “0”.  
10. Update chapter “Digital Input Disable Register 0 – DIDR0” on page 207 & “Digital Input  
Disable Register 1– DIDR1” on page 208.  
11. Update figures on parallel programming :Figure 23-1 on page 261, Figure 23-3 on page  
265,Figure 23-4 on page 266,Figure 23-5 on page 268.  
12. Suppress chapter ”Parallel Programing Characteristic” after Section 23.7.14, now in  
“Parallel Programming Characteristics” on page 282.  
28.7 Rev. 7734G  
1. Update pin out definitions with PE3 as AREF pin: Figures “20 Pin Packages” on page 4,  
“32Pin Packages” on page 5,Table “Pin out description” on page 7, Chapter “Port E  
(P32..0) RESET/ XTAL1/ XTAL2/AREF” on page 8 and Chapter “Alternate Functions of  
Port E” on page 82.  
2. Update Table 7-1 on page 28 , for CKSEL 0111, 1100 & 1101.  
3. Update figure “Analog to Digital Converter Block Schematic” on page 210.  
4. Update Table 19-3 on page 224; warning no more errata.  
28.8 Rev. 7734H  
1. Udate Product configurationTable 2-1 on page 2.  
2. Add chapter “RC Oscillator calibration” on page 31.  
3. Update chapter “Internal Voltage Reference” on page 58.  
4. Update chapter “On Chip voltage Reference and Temperature sensor overview” on  
page 192.  
5. Update chapter “Temperature Measurement” on page 196.  
6. Update Figure “Analog Comparator Block Diagram” on page 201.  
7. Update chapter “Reading the Signature Row from Software” on page 250.  
8. Update chapter “Calibrated Internal RC Oscillator Accuracy” on page 277.  
9. Add chapter “Power consumption estimation with clock prescaling” on page 290.  
10. Update chapter “Errata” on page 325.  
28.9 Rev. 7734I  
1. Remove PE3 I/O function (Only AREF and ADC functions) : Pages 3, 4, 6, 7, 80, 81, 223.  
2. Remove the ‘Enable Watchdog in Automatic Reload Mode’ Page 34 and in Table 6-12 on  
Page 18.  
3. Update RC Calibartion section 6.2.2.1 page 30.  
4. Remove chapter 6.3.7 on Page 36.  
315  
7734Q–AVR–02/12  
 
 
 
 
AT90PWM81/161  
5. Remove chapter 16.3 Band Gap calibration procedure on Page 191.  
6. Update Temperature calibration on Page 191.  
7. Remove chapter 16.4.3 Two Points Temperature sensor calibration on Page 197.  
8. Update Signature Row Addressing on Page249.  
9. Update DC Characteristics:  
Update table 23-1 Page 275: RC calibartion @25°C  
Update Table 23.2 page 272: -40°C in place of -45°C  
New Table in 23.2: -40°C to +125°C  
10. Update Erratasheet.  
28.10 Rev. 7734J  
1. Page 2 Table 2-1: QFN32 : 32 Pins.  
2. Page 6 Table 3-2: SO24 and QFN20 are removed.  
3. Page 30 section 6.2.2.1: RC Osc. is monitored @125°C.  
4. Page 51: Table 8.2: BODenable is mandatory.  
5. Page 166: removed AT90PWM2/3 comments.  
6. Page 267 Table 23-1: User Calibration at +5%.  
7. Page 271: Update of ADC Characteristics.  
8. Page 273: Add the DAC Characteristics.  
28.11 Rev. 7734K  
1. Page 193 §16.4.1: removed the last sentence about reading of the temperature sensor during  
Hot testing.  
2. Page 193 §16.4.1: T formula modifed with new TSGAIN.  
3. Page 244 Table 21.5: Signature row adressing table updated with right address.  
28.12 Rev. 7734L  
28.13 Rev. 7734M  
1. Update Errata Rev E.  
1. Page 204: Figure 18-1 removed REFS2 bit.  
2. .Pages 277 to 294: update of Typical characteristics.  
28.14 Rev. 7734N  
28.15 Rev. 7734O  
1. Page 52: update of BOD levels.  
2. Pages 267, 268, 269, 270: update of Vref, Icc power-down, Icc operating, Icc Idle and  
Watchdog oscillator characteristics.  
1. Pages 275, 276 Table 23-6: update of ADC characteristics.  
2. Page 270: add a new line in Table 23-1 (Calibrated Internal RC oscillator Accuracy).  
3. Pages 267, 269, 279: update of Analog comparator characteristics.  
316  
7734Q–AVR–02/12  
 
 
 
 
 
 
AT90PWM81/161  
28.16 Rev. 7734P  
28.17 Rev. 7734Q  
1. Updated “Electrical Characteristics (1)” on page 265 and “AT90PWM81/161 Typical  
Characteristics” on page 279.  
1. General update and countless, small corrections.  
2. Table 8-1 on page 62 has been updated.  
3. The text in “Input Mode Operation” on page 160 has been updated.  
4. Changed the overlined text to normal text in the Note below Table 14-1 on page 182.  
5. Removed the text/link “13.9” from row #1 in Table 13-5 on page 160.  
6. Corrected Figure text and Figure for Figure 17-15 on page 224 and Figure 17-16 on page  
224.  
7. The number “2” below the list in “Reading the Calibration Byte” on page 260 has been  
removed.  
8. New links have been added.  
9. Two places in Table 21-16 on page 263 the text “See Table XXX on page XXX for details”  
has been replaced by “See Table 21-6 on page 251 for details”.  
10. The text “Table 113” two places in Table 4-4 on page 23 has been replaced by “Table 20-7  
on page 246”.  
11. In Bit 4 – PUD: Pull-up Disable75 the text “Se” has been replaced by “See “Configuring the  
Pin” on page 69 for more details about this feature.”  
12. In Bit 5 – ICIE1: Timer/Counter1, Input Capture Interrupt Enable on page 99, the text “XXX”  
has been replaced by “Table 8-1 on page 62”.  
13. In “Input Mode Operation” on page 120 the text “All” has been replaced by “These modes  
are listed in Table 12-7”.  
14. The figure text in Table 2-2 has been corrected to Pin out description.  
15. In the first sentence in “Interrupt Handling” on page 131 the text “(vector...)” has been  
removed.  
16. In Figure 13-2 on page 149 the text “Aralog” has been corrected to “Analog”.  
17. In “Prescaling and Conversion Timing” on page 206, section 6, the text “(four XXX to be  
confirmed)” has been removed.  
18. In “ADC Conversion Result” on page 215 the text “Table 82” has been replaced by “Table  
17-2 on page 217”.  
19. In Table 22-4 on page 271, Note 1, the text “(CPU core, PSC... “ has been removed.  
20. “Ordering Information” on page 304 has been updated.  
21. Added AT90PWM161 (16K Flash, 1K SRAM) and updated the datasheet accordingly.  
22. In chapter “Analog to Digital Converter” on page 47 the text “CROSS REFERENCE  
MOVED” has been replaced by ““ADC Noise Canceler” on page 210”.  
23. In Table 9-2 on page 74 the text “figure” has been replaced by the cross reference “Figure 9-  
5 on page 73”.  
24. In chapter “Alternate Port Functions” on page 73, just below Table 9-2 on page 74 the cross  
reference Table 9-2 has been added.  
25. In chapter “Registers” on page 86 the text “figure” has been replaced by the cross reference  
Figure 11-1 two places.  
26. In chapter “PSOC2 - PSC 2 Synchro and Output Configuration” on page 134, in bullet point  
“Bit 3:0 – PRFMnx3:0: PSC n Fault Mode”, page 141, the text “PSC Functional  
Specification” has been replaced by “Table 12-7 on page 120”.  
317  
7734Q–AVR–02/12  
 
 
AT90PWM81/161  
27. In chapter “PFRC0B - PSCR Input B Control Register” on page 175, in bullet point “Bit 3:0 –  
PRFM0x3:0: PSCR Fault Mode”, page 176, the text “PSCR Functional Specification” has  
been replaced by “Table 13-5 on page 160”.  
28. In “Bit 2, 1, 0– AC3M2, AC3M1, AC3M0: Analog Comparator 3 Multiplexer register”,  
page 199, the reference “Table 16-4” has been corrected to “Table 16-6”.  
29. In Table 21-5 on page 250, the reference “Table 113” has been corrected to “Table 20-7 on  
page 246” two places.  
30. In chapter “Signal Names” on page 252, the text “in the following table” has been replaced  
by the reference “Table 21-8 on page 252”.  
31. Several cross references have been corrected.  
32. The text “The accuracy of this calibration is shown as Factory calibration in Table 24-1 on  
page 277” on page 30 has been changed into “The accuracy of this calibration is shown as  
Factory calibration in Table 22-2 on page 270”.  
33. The first Note in Bit 2– CKRC81: Frequency Selection of the calibrated 8/1MHz RC  
Oscillator on page 42 is corrected to This bit only can be changed only when the RC  
oscillator is enabled.  
34. Note 1 below Figure 16-1 on page 195 is changed to “Refer to Figure 2-1 on page 3 and  
Figure 2-2 on page 4 for Analog Comparator pin placement.”  
35. Figure 16-2 on page 196 has been corrected.  
36. In “MISO/ACMP3/ADC8– Bit 6” on page 75 the “DDB0” has been corrected to “DDB6”, and  
the “PORTB0” has been corrected to “PORTB6”.  
37. In “ADC5/ACMP2/INT1/SCK – Bit 5” on page 76 the “DDD4” has been corrected to “DDB5”,  
and the “PORT” has been corrected to “PORTB5”.  
38. In “MOSI/ADC3/ACMPM– Bit 4” on page 76 the “DDB1” has been corrected to “DDB4”, and  
the “PORTB1” has been corrected to “PORTB4”.  
39. Missing information in Table 9-4 on page 77, Table 9-5 on page 77, Table 9-7 on page 79,  
Table 9-8 on page 80 and Table 9-10 on page 81 has been added.  
40. Paragraphs one and two in “In-System Reprogrammable Flash Program Memory” on page  
16 have been changed to to include more data regarding the AT90PWM161.  
41. The text “TBD” in Table 21-7 on page 251 has been changed into “8B”.  
42. The text in bullet point number three below Table 21-7 on page 251 has been expanded to  
include the AT90PWM161.  
43. The text “Calibration accuracy” in the heading of Table 22-2 on page 270 has been changed  
into “Accuracy”.  
44. The text “AT90PWM161 revA” has been added to the heading in Section 27.5 on page 311.  
45. JMP and CALL instructions are added to “BRANCH INSTRUCTIONS” in Section 25. on  
page 301.  
46. “Errata AT90PWM161 revA” on page 312 and “Errata AT90PWM161 revB” on page 313 are  
added.  
47. In “Errata AT90PWM161 revB” on page 313, and in “Errata AT90PWM161 revA” on page  
312 the PSCRRB fuse is added.  
48. In “Features” on page 227 the bullet points “The DAC could be connected to the negative  
inputs of the analog comparators and/or to a dedicated output driver” and “Output  
impedance around 1KOhm” have been removed.  
49. The text “AMP3D” has been replaced by “ACMP3D” in “DIDR0 - Digital Input Disable  
Register 0” on page 202, “DIDR0 - Digital Input Disable Register 0” on page 222, and  
“Register Summary” on page 297.  
318  
7734Q–AVR–02/12  
AT90PWM81/161  
50. In “Features” on page 100, the text in one of the bullet pints has been corrected to  
“Abnormality protection function, emergency input to force all outputs to low level”.  
51. @25°C has been removed several places in the table in “DC Characteristics” .  
52. The rows describing 105°C on page 269 in the table in “DC Characteristics” have been  
removed.  
53. The values in Table 7-2 on page 53 has been corrected.  
54. The text below “Description” in Table 13-8 on page 171 has been corrected.  
55. The text below “Description” in Table 13-9 on page 171 has been corrected.  
56. A new feature has been added in Section 18.1, page 227.  
57. The address for Atmel Japan has been changed.  
319  
7734Q–AVR–02/12  
AT90PWM81/161  
Table Of Contents  
Features..................................................................................................... 1  
Products Configuration ........................................................................... 2  
Pin Configurations ................................................................................... 3  
1
2
2.1  
Pin Descriptions .................................................................................................6  
3
AVR CPU Core .......................................................................................... 8  
3.1  
3.2  
3.3  
3.4  
3.5  
3.6  
3.7  
3.8  
Introduction ........................................................................................................8  
Architectural Overview .......................................................................................8  
ALU – Arithmetic Logic Unit ...............................................................................9  
Status Register ................................................................................................10  
General Purpose Register File ........................................................................11  
Stack Pointer ...................................................................................................12  
Instruction Execution Timing ...........................................................................12  
Reset and Interrupt Handling ...........................................................................13  
4
Memories ................................................................................................ 16  
4.1  
4.2  
4.3  
4.4  
4.5  
4.6  
In-System Reprogrammable Flash Program Memory .....................................16  
SRAM Data Memory ........................................................................................17  
EEPROM Data Memory ..................................................................................18  
Fuse Bits ..........................................................................................................22  
I/O Memory ......................................................................................................26  
General Purpose I/O Registers .......................................................................26  
5
6
System Clock and Clock Options ......................................................... 27  
5.1  
5.2  
5.3  
5.4  
5.5  
Clock Systems and their Distribution ...............................................................27  
Clock Sources .................................................................................................28  
Dynamic Clock Switch .....................................................................................35  
System Clock Prescaler ..................................................................................39  
Register Description ........................................................................................39  
Power Management and Sleep Modes ................................................. 45  
6.1  
6.2  
6.3  
6.4  
6.5  
Sleep Modes ....................................................................................................45  
Idle Mode .........................................................................................................45  
ADC Noise Reduction Mode ............................................................................46  
Power-down Mode ...........................................................................................46  
Standby Mode .................................................................................................46  
i
7734Q–AVR–02/12  
 
AT90PWM81/161  
6.6  
6.7  
6.8  
Power Reduction Register ...............................................................................46  
Minimizing Power Consumption ......................................................................47  
Register description .........................................................................................48  
7
System Control and Reset .................................................................... 50  
7.1  
7.2  
7.3  
7.4  
System Control overview .................................................................................50  
System Control registers .................................................................................54  
Internal Voltage Reference ..............................................................................55  
Watchdog Timer ..............................................................................................56  
8
9
Interrupts ................................................................................................ 62  
8.1  
Interrupt Vectors in AT90PWM81/161 .............................................................62  
I/O-Ports .................................................................................................. 68  
9.1  
9.2  
9.3  
9.4  
Introduction ......................................................................................................68  
Ports as General Digital I/O .............................................................................69  
Alternate Port Functions ..................................................................................73  
Register Description for I/O-Ports ....................................................................81  
10 External Interrupts ................................................................................. 83  
11 Reduced 16-bit Timer/Counter1 ........................................................... 85  
11.1  
11.2  
11.3  
11.4  
11.5  
11.6  
11.7  
11.8  
Overview ..........................................................................................................85  
Accessing 16-bit Registers ..............................................................................87  
Timer/Counter Clock Sources .........................................................................90  
Counter Unit ....................................................................................................91  
Input Capture Unit ...........................................................................................92  
Modes of Operation .........................................................................................94  
Timer/Counter Timing Diagrams .....................................................................95  
16-bit Timer/Counter Register Description ......................................................97  
12 Power Stage Controller – (PSCn) ....................................................... 100  
12.1  
12.2  
12.3  
12.4  
12.5  
12.6  
12.7  
12.8  
Features ........................................................................................................100  
Overview ........................................................................................................100  
PSC Description ............................................................................................101  
Signal Description ..........................................................................................103  
Functional Description ...................................................................................104  
Update of Values ...........................................................................................110  
Enhanced Resolution ....................................................................................111  
PSC Inputs ....................................................................................................114  
ii  
7734Q–AVR–02/12  
AT90PWM81/161  
12.9  
PSC Input Mode 1: Stop signal, Jump to Opposite Dead-Time and Wait .....121  
12.10 PSC Input Mode 2: Stop signal, Execute Opposite Pulse and Wait ..............122  
12.11 PSC Input Mode 3: Stop signal, Execute Opposite Pulse while Fault active 123  
12.12 PSC Input Mode 4: Deactivate outputs without changing timing ...................124  
12.13 PSC Input Mode 5: Stop signal and Insert Dead-Time ..................................124  
12.14 PSC Input Mode 6: Stop signal, Jump to Opposite Dead-Time and Wait .....125  
12.15 PSC Input Mode 7: Halt PSC and Wait for Software Action ..........................125  
12.16 PSC Input Mode 8: Edge Retrigger PSC .......................................................126  
12.17 PSC Input Mode 9: Fixed Frequency Edge Retrigger PSC ...........................127  
12.18 PSC Input Mode 14: Fixed Frequency Edge Retrigger PSC and Deactivate Out-  
put 128  
12.19 PSC2 Outputs ................................................................................................129  
12.20 Analog Synchronization .................................................................................131  
12.21 Interrupt Handling ..........................................................................................131  
12.22 PSC Synchronization .....................................................................................132  
12.23 PSC Clock Sources .......................................................................................133  
12.24 Interrupts .......................................................................................................134  
12.25 PSC Register Definition .................................................................................134  
12.26 PSC2 Specific Register .................................................................................142  
13 Reduced Power Stage Controller – (PSCR) ....................................... 147  
13.1  
13.2  
13.3  
13.4  
13.5  
13.6  
13.7  
13.8  
13.9  
Features ........................................................................................................147  
Overview ........................................................................................................147  
PSCR Description .........................................................................................148  
Signal Description ..........................................................................................149  
Functional Description ...................................................................................151  
Update of Values ...........................................................................................154  
Enhanced resolution ......................................................................................155  
PSCR Inputs ..................................................................................................155  
PSCR Input Mode 1: Stop signal, Jump to Opposite Dead-Time and Wait ...161  
13.10 PSCR Input Mode 2: Stop signal, Execute Opposite Dead-Time and Wait ..162  
13.11 PSCR Input Mode 3: Stop signal, Execute Opposite while Fault active ........163  
13.12 PSCR Input Mode 4: Deactivate outputs without changing timing ................164  
13.13 PSCR Input Mode 5: Stop signal and Insert Dead-Time ...............................164  
13.14 PSCR Input Mode 6: Stop signal, Jump to Opposite Dead-Time and Wait ...165  
13.15 PSCR Input Mode 7: Halt PSCR and Wait for Software Action .....................165  
13.16 PSCR Input Mode 8: Edge Retrigger PSC ....................................................166  
iii  
7734Q–AVR–02/12  
AT90PWM81/161  
13.17 PSCR Input Mode 9: Fixed Frequency Edge Retrigger PSC ........................167  
13.18 PSCR Input Mode 14: Fixed Frequency Edge Retrigger PSCR and Deactivate  
Output 168  
13.19 Analog Synchronization .................................................................................169  
13.20 Interrupt Handling ..........................................................................................169  
13.21 PSC Clock Sources .......................................................................................169  
13.22 Interrupts .......................................................................................................170  
13.23 PSCR Register Definition ..............................................................................171  
14 Serial Peripheral Interface – SPI: ........................................................ 180  
14.1  
14.2  
14.3  
14.4  
14.5  
Features ........................................................................................................180  
Overview ........................................................................................................180  
SS Pin Functionality ......................................................................................184  
Data Modes ...................................................................................................185  
SPI registers ..................................................................................................186  
15 Voltage Reference and Temperature Sensor .................................... 189  
15.1  
15.2  
15.3  
15.4  
Features ........................................................................................................189  
On Chip voltage Reference and Temperature sensor overview ....................189  
Register Description ......................................................................................190  
Temperature Measurement ...........................................................................192  
16 Analog Comparator ............................................................................. 194  
16.1  
16.2  
16.3  
16.4  
Features ........................................................................................................194  
Overview ........................................................................................................194  
Shared pins between Analog Comparator and ADC .....................................196  
Analog Comparator Register Description ......................................................196  
17 Analog to Digital Converter - ADC ..................................................... 203  
17.1  
17.2  
17.3  
17.4  
17.5  
17.6  
17.7  
17.8  
17.9  
Features ........................................................................................................203  
Operation .......................................................................................................205  
Starting a Conversion ....................................................................................205  
Prescaling and Conversion Timing ................................................................206  
Changing Channel or Reference Selection ...................................................209  
ADC Noise Canceler .....................................................................................210  
ADC Conversion Result .................................................................................215  
ADC Register Description ..............................................................................217  
Amplifier .........................................................................................................222  
17.10 Amplifier Control Registers ............................................................................225  
iv  
7734Q–AVR–02/12  
AT90PWM81/161  
18 Digital to Analog Converter - DAC ..................................................... 227  
18.1  
18.2  
18.3  
18.4  
Features ........................................................................................................227  
Operation .......................................................................................................228  
Starting a Conversion ....................................................................................228  
DAC Register Description ..............................................................................228  
19 debugWIRE On-chip Debug System .................................................. 231  
19.1  
19.2  
19.3  
19.4  
19.5  
19.6  
Features ........................................................................................................231  
Overview ........................................................................................................231  
Physical Interface ..........................................................................................231  
Software Break Points ...................................................................................232  
Limitations of debugWIRE .............................................................................232  
debugWIRE Related Register in I/O Memory ................................................232  
20 Boot Loader Support – Read-While-Write Self-Programming ......... 233  
20.1  
20.2  
20.3  
20.4  
20.5  
20.6  
20.7  
Boot Loader Features ....................................................................................233  
Application and Boot Loader Flash Sections .................................................233  
Read-While-Write and No Read-While-Write Flash Sections ........................233  
Boot Loader Lock Bits ...................................................................................236  
Entering the Boot Loader Program ................................................................237  
Addressing the Flash During Self-Programming ...........................................239  
Self-Programming the Flash ..........................................................................240  
21 Memory Programming ......................................................................... 248  
21.1  
21.2  
21.3  
21.4  
21.5  
21.6  
21.7  
21.8  
Program And Data Memory Lock Bits ...........................................................248  
Fuse Bits ........................................................................................................249  
Signature Bytes .............................................................................................251  
Calibration Byte .............................................................................................252  
Parallel Programming Parameters, Pin Mapping, and Commands ...............252  
Serial Programming Pin Mapping ..................................................................254  
Parallel Programming ....................................................................................254  
Serial Downloading ........................................................................................261  
22 Electrical Characteristics (1) ............................................................................................... 265  
22.1  
22.2  
22.3  
22.4  
22.5  
Absolute Maximum Ratings* .........................................................................265  
DC Characteristics .........................................................................................266  
Clock Drive Characteristics ...........................................................................270  
Maximum Speed vs. VCC ....................................................................................................................271  
PLL Characteristics .......................................................................................271  
v
7734Q–AVR–02/12  
AT90PWM81/161  
22.6  
22.7  
22.8  
22.9  
SPI Timing Characteristics ............................................................................272  
ADC Characteristics ......................................................................................274  
DAC Characteristics ......................................................................................276  
Parallel Programming Characteristics ...........................................................276  
23 AT90PWM81/161 Typical Characteristics .......................................... 279  
23.1  
23.2  
23.3  
23.4  
23.5  
23.6  
23.7  
23.8  
23.9  
Active Supply Current ....................................................................................280  
Idle Supply Current ........................................................................................282  
Power-Down Supply Current .........................................................................284  
Pin Pull-up .....................................................................................................285  
Pin output high voltage ..................................................................................288  
Pin output low voltage ...................................................................................289  
Pin Thresholds ...............................................................................................290  
BOD Thresholds ............................................................................................291  
Analog Reference ..........................................................................................292  
23.10 Internal Oscillator Speed ...............................................................................293  
23.11 Current Consumption in Reset ......................................................................295  
24 Register Summary .............................................................................. 297  
25 Instruction Set Summary .................................................................... 301  
26 Ordering Information ........................................................................... 304  
26.1  
26.2  
SO20 .............................................................................................................305  
QFN32 ...........................................................................................................306  
27 Errata ..................................................................................................... 307  
27.1  
27.2  
27.3  
27.4  
27.5  
27.6  
27.7  
Errata AT90PWM81 revA ..............................................................................307  
Errata AT90PWM81 revB ..............................................................................307  
Errata AT90PWM81 revC ..............................................................................308  
Errata AT90PWM81 revD ..............................................................................310  
Errata AT90PWM81 revE ..............................................................................311  
Errata AT90PWM161 revA ............................................................................312  
Errata AT90PWM161 revB ............................................................................313  
28 Datasheet Revision History for AT90PWM81/161 ............................. 314  
28.1  
28.2  
28.3  
28.4  
Rev. 7734A ....................................................................................................314  
Rev. 7734B ....................................................................................................314  
Rev. 7734C ....................................................................................................314  
Rev. 7734D ....................................................................................................314  
vi  
7734Q–AVR–02/12  
AT90PWM81/161  
28.5  
28.6  
28.7  
28.8  
28.9  
Rev. 7734E ....................................................................................................314  
Rev. 7734F ....................................................................................................315  
Rev. 7734G ...................................................................................................315  
Rev. 7734H ....................................................................................................315  
Rev. 7734I .....................................................................................................315  
28.10 Rev. 7734J ....................................................................................................316  
28.11 Rev. 7734K ....................................................................................................316  
28.12 Rev. 7734L ....................................................................................................316  
28.13 Rev. 7734M ...................................................................................................316  
28.14 Rev. 7734N ....................................................................................................316  
28.15 Rev. 7734O ...................................................................................................316  
28.16 Rev. 7734P ....................................................................................................317  
28.17 Rev. 7734Q ...................................................................................................317  
Table Of Contents...................................................................................... i  
vii  
7734Q–AVR–02/12  
Atmel Corporation  
2325 Orchard Parkway  
San Jose, CA 95131  
USA  
Tel: (+1)(408) 441-0311  
Fax: (+1)(408) 487-2600  
www.atmel.com  
Atmel Asia Limited  
Unit 1-5 & 16, 19/F  
BEA Tower, Millennium City 5  
418 Kwun Tong Road  
Kwun Tong, Kowloon  
HONG KONG  
Atmel Munich GmbH  
Business Campus  
Parkring 4  
D-85748 Garching b. Munich  
GERMANY  
Atmel Japan  
16F, Shin Osaki Kangyo Bldg.  
1-6-4 Osaki Shinagawa-ku  
Tokyo 104-0032  
JAPAN  
Tel: (+81) 3-6417-0300  
Fax: (+81) 3-6417-0370  
Tel: (+49) 89-31970-0  
Fax: (+49) 89-3194621  
Tel: (+852) 2245-6100  
Fax: (+852) 2722-1369  
© 2012 Atmel Corporation. All rights reserved.  
Atmel®, Atmel logo and combinations thereof, AVR®, AVR Logo®, AVR Studio®, and others are registered trademarks or trademarks of  
Atmel Corporation or its subsidiaries. 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 PROF-  
ITS, 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 com-  
pleteness of the contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice.  
Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suit-  
able for, and shall not be used in, automotive applications. Atmel products are not intended, authorized, or warranted for use as components in applica-  
tions intended to support or sustain life.  
7734Q–AVR–02/12  

相关型号:

AT90PWM81-16SE

8-bit AVR Microcontroller with 8K Bytes In- System Programmable Flash
ATMEL

AT90PWM81-16SF

8-bit AVR Microcontroller with 8K Bytes In- System Programmable Flash
ATMEL

AT90PWM81-16SF

IC MCU 8BIT 8KB FLASH 20SOIC
MICROCHIP

AT90PWM81-16SN

8-bit AVR Microcontroller with 8K Bytes In- System Programmable Flash
ATMEL

AT90PWM81-16SN

IC MCU 8BIT 8KB FLASH 20SOIC
MICROCHIP

AT90PWM81_14

Data and non-volatile program memory
ATMEL

AT90RF135602

INTEGRATED 13.56 MHz CONTACTLESS READER WITH EMBEDED SOFTWARE
ATMEL

AT90RF135602-7MTUL

Microprocessor Circuit, CMOS, PBGA36, GREEN, LBGA-36
ATMEL

AT90S1200

8-Bit Microcontroller with 1K bytes In-System Programmable Flash
ATMEL

AT90S1200-12PC

8-Bit Microcontroller with 1K bytes In-System Programmable Flash
ATMEL

AT90S1200-12PI

8-Bit Microcontroller with 1K bytes In-System Programmable Flash
ATMEL

AT90S1200-12PJ

RISC Microcontroller, 8-Bit, FLASH, 12MHz, CMOS, PDIP20, 0.300 INCH, PLASTIC, DIP-20
ATMEL