attiny416 / attiny816 complete - microchip
TRANSCRIPT
ATtiny416816 tinyAVRreg 1-series
Introduction
The ATtiny416816 are members of the tinyAVRreg 1-series of microcontrollers using the AVRreg processorwith hardware multiplier running at up to 20 MHz with 48 KB Flash 256512 bytes of SRAM and 128bytes of EEPROM in a 20-pin package The tinyAVRreg 1-series uses the latest technologies with aflexible low-power architecture including Event System and SleepWalking accurate analog features andCore Independent Peripherals Capacitive touch interfaces with driven shield are supported with theintegrated QTouchreg peripheral touch controller(1)
Attention Automotive products are documented in separate data sheets
Features
bull CPUndash AVRreg CPUndash Running at up to 20 MHzndash Single-cycle IO accessndash Two-level interrupt controllerndash Two-cycle hardware multiplier
bull Memoriesndash 48 KB In-system self-programmable Flash memoryndash 128B EEPROMndash 256512B SRAMndash Writeerase endurance
bull Flash 10000 cyclesbull EEPROM 100000 cycles
ndash Data retention 40 years at 55degCbull System
ndash Power-on Reset (POR)ndash Brown-out Detector (BOD)ndash Clock options
bull 1620 MHz low-power internal RC oscillatorbull 32768 kHz Ultra Low-Power (ULP) internal RC oscillatorbull 32768 kHz external crystal oscillator
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 1
bull External clock inputndash Single-pin Unified Program and Debug Interface (UPDI)ndash Three sleep modes
bull Idle with all peripherals running for immediate wake-upbull Standby
ndash Configurable operation of selected peripheralsndash SleepWalking peripherals
bull Power-Down with full data retentionbull Peripherals
ndash One 16-bit TimerCounter Type A (TCA) with a dedicated period register and three comparechannels
ndash One 16-bit TimerCounter Type B (TCB) with input capturendash One 12-bit TimerCounter Type D (TCD) optimized for control applicationsndash One 16-bit Real-Time Counter (RTC) running from external crystal or internal RC oscillatorndash Watchdog Timer (WDT) with Window mode with a separate on-chip oscillatorndash One USART with fractional baud rate generator auto-baud and start-of-frame detectionndash One masterslave Serial Peripheral Interface (SPI)ndash One Two-Wire Interface (TWI) with dual address match
bull Philips I2C compatiblebull Standard mode (Sm 100 kHz)bull Fast mode (Fm 400 kHz)bull Fast mode plus (Fm+ 1 MHz)
ndash One Analog Comparator (AC) with a low propagation delayndash One 10-bit 115 ksps Analog-to-Digital Converter (ADC)ndash One 8-bit Digital-to-Analog Converter (DAC)ndash Multiple voltage references (VREF)
bull 055Vbull 11Vbull 15Vbull 25Vbull 43V
ndash Event System (EVSYS) for CPU independent and predictable inter-peripheral signalingndash Configurable Custom Logic (CCL) with two programmable look-up tablesndash Automated CRC memory scan (CRCSCAN)ndash Peripheral Touch Controller (PTC)(1)
bull Capacitive touch buttons sliders wheels and 2D surfacesbull Wake-up on touchbull Driven shield for improved moisture and noise handling performancebull Up to six self capacitance channelsbull Up to nine mutual capacitance channels
ndash External interrupt on all general purpose pinsbull IO and Packages
ndash 18 programmable IO lines
ATtiny416816
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 2
ndash 20-pin VQFN 3x3 mmndash 20-pin SOIC300
bull Temperature Rangesndash -40degC to 105degCndash -40degC to 125degC
bull Speed Gradesndash 0-5 MHz 18V ndash 55Vndash 0-10 MHz 27V ndash 55Vndash 0-20 MHz 45V ndash 55V
Note 1 Only available in devices with 8 KB Flash
ATtiny416816
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 3
Table of Contents
Introduction1
Features 1
1 Silicon Errata and Data Sheet Clarification Document 11
2 tinyAVRreg 1-series Overview1221 Configuration Summary12
3 Block Diagram 14
4 Pinout 1641 20-pin SOIC1642 20-pin VQFN 17
5 IO Multiplexing and Considerations1851 Multiplexed Signals 18
6 Memories1961 Overview 1962 Memory Map 2063 In-System Reprogrammable Flash Program Memory2064 SRAM Data Memory 2165 EEPROM Data Memory 2166 User Row2167 Signature Bytes2168 IO Memory2269 FUSES - Configuration and User Fuses 24
7 Peripherals and Architecture 4471 Peripheral Module Address Map4472 Interrupt Vector Mapping4573 SYSCFG - System Configuration47
8 AVR CPU5081 Features 5082 Overview 5083 Architecture 5084 ALU - Arithmetic Logic Unit 5285 Functional Description5386 Register Summary - CPU5887 Register Description58
9 NVMCTRL - Non Volatile Memory Controller 6291 Features 6292 Overview 62
ATtiny416816
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 4
93 Functional Description6394 Register Summary - NVMCTRL7095 Register Description70
10 CLKCTRL - Clock Controller 78101 Features 78102 Overview 78103 Functional Description80104 Register Summary - CLKCTRL85105 Register Description85
11 SLPCTRL - Sleep Controller 95111 Features 95112 Overview 95113 Functional Description96114 Register Summary - SLPCTRL 99115 Register Description99
12 RSTCTRL - Reset Controller101121 Features 101122 Overview 101123 Functional Description102124 Register Summary - RSTCTRL105125 Register Description105
13 CPUINT - CPU Interrupt Controller 108131 Features 108132 Overview 108133 Functional Description 110134 Register Summary - CPUINT 116135 Register Description 116
14 EVSYS - Event System 121141 Features 121142 Overview 121143 Functional Description124144 Register Summary - EVSYS 126145 Register Description126
15 PORTMUX - Port Multiplexer 133151 Overview 133152 Register Summary - PORTMUX 134153 Register Description134
16 PORT - IO Pin Configuration 139161 Features 139162 Overview 139163 Functional Description141
ATtiny416816
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 5
164 Register Summary - PORT 145165 Register Description - Ports 145166 Register Summary - VPORT 157167 Register Description - Virtual Ports 157
17 BOD - Brownout Detector162171 Features 162172 Overview 162173 Functional Description164174 Register Summary - BOD166175 Register Description166
18 VREF - Voltage Reference 173181 Features 173182 Overview 173183 Functional Description173184 Register Summary - VREF175185 Register Description175
19 WDT - Watchdog Timer 178191 Features 178192 Overview 178193 Functional Description180194 Register Summary - WDT 184195 Register Description184
20 TCA - 16-bit TimerCounter Type A 188201 Features 188202 Overview 188203 Functional Description192204 Register Summary - TCA in Normal Mode (CTRLDSPLITM=0) 202205 Register Description - Normal Mode 202206 Register Summary - TCA in Split Mode (CTRLDSPLITM=1)222207 Register Description - Split Mode222
21 TCB - 16-bit TimerCounter Type B 238211 Features 238212 Overview 238213 Functional Description241214 Register Summary - TCB 249215 Register Description249
22 TCD - 12-bit TimerCounter Type D261221 Features 261222 Overview 261223 Functional Description265224 Register Summary - TCD287225 Register Description287
ATtiny416816
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 6
23 RTC - Real Time Counter307231 Features 307232 Overview 307233 RTC Functional Description 310234 PIT Functional Description 310235 Events311236 Interrupts 311237 Sleep Mode Operation 312238 Synchronization312239 Configuration Change Protection 3122310 Register Summary - RTC3132311 Register Description313
24 USART - Universal Synchronous and Asynchronous Receiver and Transmitter 329241 Features 329242 Overview 329243 Functional Description332244 Register Summary - USART 347245 Register Description347
25 SPI - Serial Peripheral Interface366251 Features 366252 Overview 366253 Functional Description369254 Register Summary - SPI377255 Register Description377
26 TWI - Two Wire Interface384261 Features 384262 Overview 384263 Functional Description386264 Register Summary - TWI400265 Register Description400
27 CRCSCAN - Cyclic Redundancy Check Memory Scan 418271 Features 418272 Overview 418273 Functional Description420274 Register Summary - CRCSCAN423275 Register Description423
28 CCL ndash Configurable Custom Logic427281 Features 427282 Overview 427283 Functional Description429284 Register Summary - CCL 438285 Register Description438
ATtiny416816
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 7
29 AC ndash Analog Comparator 445291 Features 445292 Overview 445293 Functional Description447294 Register Summary - AC 449295 Register Description449
30 ADC - Analog to Digital Converter454301 Features 454302 Overview 454303 Functional Description458304 Register Summary - ADC467305 Register Description467
31 DAC - Digital to Analog Converter485311 Features 485312 Overview 485313 Functional Description487314 Register Summary - DAC489315 Register Description489
32 PTC - Peripheral Touch Controller492321 Features 492322 Overview 492323 Functional Description495
33 UPDI - Unified Program and Debug Interface 497331 Features 497332 Overview 497333 Functional Description500334 Register Summary - UPDI520335 Register Description520
34 Electrical Characteristics 531341 Disclaimer531342 Absolute Maximum Ratings 531343 General Operating Ratings 532344 Power Consumption for ATtiny416533345 Power Consumption for ATtiny816534346 Wake-Up Time536347 Peripherals Power Consumption536348 BOD and POR Characteristics537349 External Reset Characteristics5383410 Oscillators and Clocks5383411 IO Pin Characteristics5403412 USART5423413 SPI 543
ATtiny416816
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 8
3414 TWI5443415 Bandgap and VREF 5463416 ADC5473417 DAC5493418 AC 5503419 PTC5513420 UPDI Timing5523421 Programming Time552
35 Typical Characteristics554351 Power Consumption554352 GPIO 569353 VREF Characteristics577354 BOD Characteristics579355 ADC Characteristics582356 AC Characteristics587357 OSC20M Characteristics589358 OSCULP32K Characteristics 591359 TWI SDA Hold timing for ATtiny816 5923510 PTC Characteristics for ATtiny816592
36 Ordering Information595361 Product Information595362 Product Identification System595
37 Packaging Information597371 Package Drawings 597372 Thermal Considerations 605
38 Instruction Set Summary 606
39 Conventions612391 Numerical Notation612392 Memory Size and Type612393 Frequency and Time612394 Registers and Bits 613
40 Acronyms and Abbreviations614
41 Errata617411 Errata - ATtiny416816 617
42 Datasheet Revision History 618421 Rev B - 072019618422 Rev A - 012017619
The Microchip Website620
Product Change Notification Service620
ATtiny416816
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 9
Customer Support 620
Microchip Devices Code Protection Feature 620
Legal Notice621
Trademarks 621
Quality Management System 622
Worldwide Sales and Service623
ATtiny416816
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 10
1 Silicon Errata and Data Sheet Clarification DocumentOur intention is to provide our customers with the best documentation possible to ensure successful useof Microchip products Between data sheet updates a Silicon Errata and Data Sheet ClarificationDocument will contain the most recent information for the data sheet The ATtiny416816 Silicon Errataand Data Sheet Clarification Document is available at the device product page on httpswwwmicrochipcom
ATtiny416816Silicon Errata and Data Sheet Clarification
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 11
2 tinyAVRreg 1-series OverviewThe figure below shows the tinyAVRreg 1-series devices laying out pin count variants and memory sizes
bull Vertical migration upwards is possible without code modification as these devices are pin compatibleand provide the same or more features Downward migration may require code modification due tofewer available instances of some peripherals
bull Horizontal migration to the left reduces the pin count and therefore the available features
Figure 2-1 tinyAVRreg 1-series Overview
48 KB
32 KB
16 KB
8 KB
4 KB
2 KB
8 14 20 24Pins
Flash
ATtiny816 ATtiny817ATtiny814
ATtiny417
ATtiny1616 ATtiny1617
ATtiny414 ATtiny416ATtiny412
ATtiny214ATtiny212
ATtiny1614
ATtiny3216 ATtiny3217
devicesATtiny~~
ATtiny~~Legend
common data sheet
Devices with different Flash memory size typically also have different SRAM and EEPROM
21 Configuration Summary
211 Peripheral SummaryTable 2-1 Peripheral Summary
ATtin
y416
ATtin
y816
Pins 20 20SRAM 256B 512BFlash 4 KB 8 KBEEPROM 128B 128BMax frequency (MHz) 20 2016-bit TimerCounter type A (TCA) 1 116-bit TimerCounter type B (TCB) 1 112-bit TimerCounter type D (TCD) 1 1Real-Time Counter (RTC) 1 1
ATtiny416816tinyAVRreg 1-series Overview
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 12
continued
ATtin
y416
ATtin
y816
USART 1 1SPI 1 1TWI (I2C) 1 1ADC 1 1ADC channels 12 12DAC 1 1AC 1 1Peripheral Touch Controller (PTC)(1) No 1PTC number of self capacitance channels(1) - 6PTC number of mutual capacitance channels(1) - 9Configurable Custom Logic 1 1Window Watchdog 1 1Event System channels 6 6General purpose IO 18 18External interrupts 18 18CRCSCAN 1 1
Note 1 The PTC takes control over the ADC while the PTC is used
ATtiny416816tinyAVRreg 1-series Overview
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 13
3 Block DiagramFigure 3-1 ATtiny416 Block Diagram
INOUT
DATABUS
Clock generation
BUS Matrix
CPU
USART0
SPI0
CCL
AC0
ADC0
TCA0
TCB0
AINP0AINN0
OUT
AIN[110]
WO[50]
RXDTXDXCK
XDIR
MISOMOSISCK
SS
PORTS
System Management
SLPCTRL
RSTCTRL
CLKCTRL
EVENT
ROUTING
NETWORK
DATABUS
UPDICRC
SRAM
NVMCTRL
Flash
EEPROM
OSC20M
OSC32K
Detectorsreferences
BODVLM
POR
Bandgap
WDT
RTC
CPUINT
M M
S
MS
S
OCD
RST
S
EXTCLK
LUTn-IN[20]LUTn-OUT
WO
CLKOUT
PA[70]PB[50]PC[30]
GPIOR
TWI0SDASCL
TCD0WO[ABCD]
XOSC32k
TOSC2
TOSC1
To detectors
UPDI RESET
EVSYS EVOUT[n0]
DAC0OUT
ATtiny416816Block Diagram
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 14
Figure 3-2 ATtiny816 Block Diagram
AIN[110] X[50] Y[50]
INOUT
DATABUS
Clock generation
BUS Matrix
CPU
USART0
SPI0
CCL
AC0
ADC0 PTC
TCA0
TCB0
AINP0AINN0
OUT
WO[50]
RXDTXDXCK
XDIR
MISOMOSISCK
SS
PORTS
System Management
SLPCTRL
RSTCTRL
CLKCTRL
EVENT
ROUTING
NETWORK
DATABUS
UPDICRC
SRAM
NVMCTRL
Flash
EEPROM
OSC20M
OSC32K
Detectorsreferences
BODVLM
POR
Bandgap
WDT
RTC
CPUINT
M M
S
MS
S
OCD
RST
S
EXTCLK
LUTn-IN[20]LUTn-OUT
WO
CLKOUT
PA[70]PB[50]PC[30]
GPIOR
TWI0SDASCL
TCD0WO[ABCD]
XOSC32k
TOSC2
TOSC1
To detectors
UPDI RESET
EVSYS EVOUT[n0]
DAC0OUT
ATtiny416816Block Diagram
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 15
4 Pinout
41 20-pin SOIC
1
2
3
4
5
6
7
13
11
12
14
VDD GND
PA1
PA2
PA4
PA5
PA7
PA6
PB0
8
9
10
15
20
19
18
17
16
PB1
PB4
PB5
PC0
PC2
PC3
PC1
PA0RESETUPDI
PA3EXTCLK
TOSC2PB3TOSC1
PB2
GPIO VDD power domain
Clock crystal
Programming Debug ResetInput supply
Ground
Analog function
Digital function only
ATtiny416816Pinout
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 16
42 20-pin VQFN
1
2
3
4
5
6 7 8
20 19 18 179
13
14
15
1610
11
12
PA1
PA4PA
7
PA6
PB0
PB1
PB4
PB5
PC2
PC3
PA5
GND
VDD
PA2 PC0
PC1
PA0
RES
ETU
PDI
PB3
TOSC2
EXTCLK PA3
PB2
TOSC1
GPIO VDD power domain
Clock crystal
Programming Debug ResetInput supply
Ground
Analog function
Digital function only
ATtiny416816Pinout
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 17
5 IO Multiplexing and Considerations
51 Multiplexed SignalsTable 5-1 PORT Function Multiplexing
VQFN
20-
Pin
SOIC
20-
Pin Pin Name (12) OtherSpecial ADC0 PTC(4) AC0 DAC0 USART0 SPI0 TWI0 TCA0 TCB0 TCD0 CCL
19 16 PA0 RESET UPDI AIN0 LUT0-IN020 17 PA1 AIN1 TxD(3) MOSI SDA(3) LUT0-IN11 18 PA2 EVOUT0 AIN2 RxD(3) MISO SCL(3) LUT0-IN22 19 PA3 EXTCLK AIN3 XCK(3) SCK WO33 20 GND4 1 VDD5 2 PA4 AIN4 X0Y0 XDIR(3) SS WO4 WOA LUT0-OUT6 3 PA5 AIN5 X1Y1 OUT WO5 WO WOB7 4 PA6 AIN6 X2Y2 AINN0 OUT8 5 PA7 AIN7 X3Y3 AINP0 LUT1-OUT9 6 PB5 CLKOUT AIN8 AINP1 WO2(3)
10 7 PB4 AIN9 AINN1 WO1(3) LUT0-OUT(3)
11 8 PB3 TOSC1 RxD WO0(3)
12 9 PB2 TOSC2 EVOUT1 TxD WO213 10 PB1 AIN10 X4Y4 XCK SDA WO114 11 PB0 AIN11 X5Y5 XDIR SCL WO015 12 PC0 SCK(3) WO(3) WOC16 13 PC1 MISO(3) WOD LUT1-OUT(3)
17 14 PC2 EVOUT2 MOSI(3)
18 15 PC3 SS(3) WO3(3) LUT1-IN0
Note 1 Pin names are of type Pxn with x being the PORT instance (A B) and n the pin number Notation
for signals is PORTx_PINn All pins can be used as event input2 All pins can be used for external interrupt where pins Px2 and Px6 of each port have full
asynchronous detection3 Alternate pin positions For selecting the alternate positions refer to the PORTMUX documentation4 PTC is only available in devices with 8 KB Flash (ATtiny816) Every PTC line can be configured as
X- or Y-line
ATtiny416816IO Multiplexing and Considerations
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 18
6 Memories
61 OverviewThe main memories are SRAM data memory EEPROM data memory and Flash program memory Inaddition the peripheral registers are located in the IO memory space
Table 6-1 Physical Properties of Flash Memory
Property ATtiny416 ATtiny816
Size 4KB 8KB
Page size 64B 64B
Number of pages 64 128
Start address 0x8000 0x8000
Table 6-2 Physical Properties of SRAM
Property ATtiny416 ATtiny816
Size 256B 512B
Start address 0x3F00 0x3E00
Table 6-3 Physical Properties of EEPROM
Property ATtiny416 ATtiny816
Size 128B 128B
Page size 32B 32B
Number of pages 4 4
Start address 0x1400 0x1400
Related Links68 IO Memory
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 19
62 Memory MapFigure 6-1 Memory Map Flash 48KB Internal SRAM 256512B EEPROM 128B
(Reserved)
(Reserved)
NVM IO Registers and data
64 IO Registers
960 Ext IO Registers
0x0000 ndash 0x003F
0x0040 ndash 0x0FFF
0x1400 - 0x1480EEPROM128B
Flash code
0x1000 ndash 0x13FF
Internal SRAM256512B
0x3F00 (for SRAM 256B)0x3E00 (for SRAM 512B)
48KB
0x8FFF (for Flash 4K)0x9FFF (for Flash 8K)
0x8000
0x3FFF
Flash code48KB
0x0000
CPU Code space UPDICPU Data space
63 In-System Reprogrammable Flash Program MemoryThe ATtiny416816 contains 48KB On-Chip In-System Reprogrammable Flash memory for programstorage Since all AVR instructions are 16 or 32 bits wide the Flash is organized as 4K x 16 For writeprotection the Flash Program memory space can be divided into three sections Boot Loader sectionApplication code section and Application data section with restricted access rights among them
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 20
The program counter is 1112 bits wide to address the whole program memory The procedure for writingFlash memory is described in detail in the documentation of the Non-Volatile Memory Controller(NVMCTRL) peripheral
The entire Flash memory is mapped in the memory space and is accessible with normal LDSTinstructions as well as the LPM instruction For LDST instructions the Flash is mapped from address0x8000 For the LPM instruction the Flash start address is 0x0000
The ATtiny416816 also has a CRC module that is a master on the bus If the CRC is configured to run inthe background it will read the Flash memory and can affect the program timing
Related Links21 Configuration Summary9 NVMCTRL - Non Volatile Memory Controller
64 SRAM Data MemoryThe 256B512B SRAM is used for data storage and stack
Related Links8 AVR CPU854 Stack and Stack Pointer
65 EEPROM Data MemoryThe ATtiny416816 has 128 bytes of EEPROM data memory see Memory Map The EEPROM memorysupports single byte read and write The EEPROM is controlled by the Non-Volatile Memory Controller(NVMCTRL)
Related Links62 Memory Map9 NVMCTRL - Non Volatile Memory Controller
66 User RowIn addition to the EEPROM the ATtiny416816 has one extra page of EEPROM memory that can be usedfor firmware settings the User Row (USERROW) This memory supports single byte read and write asthe normal EEPROM The CPU can write and read this memory as normal EEPROM and the UPDI canwrite and read it as a normal EEPROM memory if the part is unlocked The User Row can also be writtenby the UPDI when the part is locked USERROW is not affected by a chip erase
Related Links62 Memory Map9 NVMCTRL - Non Volatile Memory Controller33 UPDI - Unified Program and Debug Interface
67 Signature BytesAll Atmel microcontrollers have a three-byte signature code which identifies the device This code can beread in both serial and parallel mode also when the device is locked The three bytes reside in aseparate address space For the device the signature bytes are given in the following table
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 21
Table 6-4 Device ID
Device Name Signature Bytes Address
0x00 0x01 0x02
ATtiny416 0x1E 0x92 0x21
ATtiny816 0x1E 0x93 0x21
68 IO MemoryAll ATtiny416816 IOs and peripherals are located in the IO space The IO address range from 0x00 to0x3F can be accessed in a single cycle using IN and OUT instructions The Extended IO space from0x0040 - 0x0FFF can be accessed by the LDLDSLDD and STSTSSTD instructions transferring databetween the 32 general purpose working registers and the IO space
IO Registers within the address range 0x00 - 0x1F are directly bit-accessible using the SBI and CBIinstructions In these registers the value of single bits can be checked by using the SBIS and SBICinstructions Refer to the Instruction Set section for more details
For compatibility with future devices reserved bits should be written to zero if accessed Reserved IOmemory addresses should never be written
Some of the interrupt flags are cleared by writing a 1 to them On ATtiny416816 devices the CBI andSBI instructions will only operate on the specified bit and can therefore be used on registers containingsuch interrupt flags The CBI and SBI instructions work with registers 0x00 - 0x1F only
General Purpose IO RegistersThe ATtiny416816 devices provide four General Purpose IO Registers These registers can be used forstoring any information and they are particularly useful for storing global variables and interrupt flagsGeneral Purpose IO Registers which recide in the address range 0x1C - 0x1F are directly bit-accessibleusing the SBI CBI SBIS and SBIC instructions
Related Links62 Memory Map71 Peripheral Module Address Map38 Instruction Set Summary
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 22
681 Register Summary - GPIOR
Offset Name Bit Pos
0x00 GPIOR0 70 GPIOR[70]0x01 GPIOR1 70 GPIOR[70]0x02 GPIOR2 70 GPIOR[70]0x03 GPIOR3 70 GPIOR[70]
682 Register Description - GPIOR
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 23
6821 General Purpose IO register n
Name GPIOROffset 0x00 + n0x01 [n=03]Reset 0x00Property -
These are general purpose registers that can be used to store data such as global variables and flags inthe bitaccessible IO memory space
Bit 7 6 5 4 3 2 1 0 GPIOR[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash GPIOR[70] GPIO Register byte
69 FUSES - Configuration and User FusesFuses are part of the non-volatile memory and holds factory calibration data and device configurationThe fuses are available from device power-up The fuses can be read by the CPU or the UPDI but canonly be programmed or cleared by the UPDI The configuration and calibration values stored in the fusesare written to their respective target registers at the end of the start-up sequence
The content of the Signature Row fuses (SIGROW) is pre-programmed and cannot be altered SIGROWholds information such as device ID serial number and calibration values
The fuses for peripheral configuration (FUSE) are pre-programmed but can be altered by the userAltered values in the configuration fuses will be effective only after a Reset
This device also provides a User Row fuse area (USERROW) that can hold application data TheUSERROW can be programmed on a locked device by the UPDI This can be used for final configurationwithout having programming or debugging capabilities enabled
Related Links692 Signature Row Description694 Fuse Description
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 24
691 Signature Row Summary - SIGROW
Offset Name Bit Pos
0x00 DEVICEID0 70 DEVICEID[70]0x01 DEVICEID1 70 DEVICEID[70]0x02 DEVICEID2 70 DEVICEID[70]0x03 SERNUM0 70 SERNUM[70]0x04 SERNUM1 70 SERNUM[70]0x05 SERNUM2 70 SERNUM[70]0x06 SERNUM3 70 SERNUM[70]0x07 SERNUM4 70 SERNUM[70]0x08 SERNUM5 70 SERNUM[70]0x09 SERNUM6 70 SERNUM[70]0x0A SERNUM7 70 SERNUM[70]0x0B SERNUM8 70 SERNUM[70]0x0C SERNUM9 70 SERNUM[70]0x0D
0x1F
Reserved
0x20 TEMPSENSE0 70 TEMPSENSE[70]0x21 TEMPSENSE1 70 TEMPSENSE[70]0x22 OSC16ERR3V 70 OSC16ERR3V[70]0x23 OSC16ERR5V 70 OSC16ERR5V[70]0x24 OSC20ERR3V 70 OSC20ERR3V[70]0x25 OSC20ERR5V 70 OSC20ERR5V[70]
692 Signature Row Description
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 25
6921 Device ID n
Name DEVICEIDnOffset 0x00 + n0x01 [n=02]Reset [Device ID]Property -
Each device has a Device ID identifying the device and its properties such as memory sizes pin countand die revision This can be used to identify a device and hence the available features by software TheDevice ID consists of three bytes SIGROWDEVICEID[20]
Bit 7 6 5 4 3 2 1 0 DEVICEID[70]
Access R R R R R R R R Reset x x x x x x x x
Bits 70 ndash DEVICEID[70] Byte n of the Device ID
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 26
6922 Serial Number Byte n
Name SERNUMnOffset 0x03 + n0x01 [n=09]Reset [device serial number]Property -
Each device has an individual serial number representing a unique ID This can be used to identify aspecific device in the field The serial number consists of ten bytes SIGROWSERNUM[90]
Bit 7 6 5 4 3 2 1 0 SERNUM[70]
Access R R R R R R R R Reset x x x x x x x x
Bits 70 ndash SERNUM[70] Serial Number Byte n
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 27
6923 Temperature Sensor Calibration n
Name TEMPSENSEnOffset 0x20 + n0x01 [n=01]Reset [Temperature sensor calibration value]Property -
These registers contain correction factors for temperature measurements by the ADCSIGROWTEMPSENSE0 is a correction factor for the gainslope (unsigned) SIGROWTEMPSENSE1 isa correction factor for the offset (signed)
Bit 7 6 5 4 3 2 1 0 TEMPSENSE[70]
Access R R R R R R R R Reset 0 0 0 0 0 0 0 0
Bits 70 ndash TEMPSENSE[70] Temperature Sensor Calibration Byte nRefer to 30326 Temperature Measurement for how to use the values 692 Signature Row Descriptionsection for location of values
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 28
6924 OSC16 error at 3V
Name OSC16ERR3VOffset 0x22Reset [Oscillator frequency error value]Property -
Bit 7 6 5 4 3 2 1 0 OSC16ERR3V[70]
Access R R R R R R R R Reset 0 0 0 0 0 0 0 0
Bits 70 ndash OSC16ERR3V[70] OSC16 error at 3VThis registers contain the signed oscillator frequency error value when running at internal 16MHz at 3Vas measured during production
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 29
6925 OSC16 error at 5V
Name OSC16ERR5VOffset 0x23Reset [Oscillator frequency error value]Property -
Bit 7 6 5 4 3 2 1 0 OSC16ERR5V[70]
Access R R R R R R R R Reset 0 0 0 0 0 0 0 0
Bits 70 ndash OSC16ERR5V[70] OSC16 error at 5VThis registers contain the signed oscillator frequency error value when running at internal 16MHz at 5Vas measured during production
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 30
6926 OSC20 error at 3V
Name OSC20ERR3VOffset 0x24Reset [Oscillator frequency error value]Property -
Bit 7 6 5 4 3 2 1 0 OSC20ERR3V[70]
Access R R R R R R R R Reset 0 0 0 0 0 0 0 0
Bits 70 ndash OSC20ERR3V[70] OSC20 error at 3VThis registers contain the signed oscillator frequency error value when running at internal 20MHz at 3Vas measured during production
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 31
6927 OSC20 error at 5V
Name OSC20ERR5VOffset 0x25Reset [Oscillator frequency error value]Property -
Bit 7 6 5 4 3 2 1 0 OSC20ERR5V[70]
Access R R R R R R R R Reset 0 0 0 0 0 0 0 0
Bits 70 ndash OSC20ERR5V[70] OSC20 error at 5VThis registers contain the signed oscillator frequency error value when running at internal 20MHz at 5Vas measured during production
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 32
693 Fuse Summary - FUSE
Offset Name Bit Pos
0x00 WDTCFG 70 WINDOW[30] PERIOD[30]0x01 BODCFG 70 LVL[20] SAMPFREQ ACTIVE[10] SLEEP[10]0x02 OSCCFG 70 OSCLOCK FREQSEL[10]0x03 Reserved 0x04 TCD0CFG 70 CMPDEN CMPCEN CMPBEN CMPAEN CMPD CMPC CMPB CMPA0x05 SYSCFG0 70 CRCSRC[10] RSTPINCFG[10] EESAVE0x06 SYSCFG1 70 SUT[20]0x07 APPEND 70 APPEND[70]0x08 BOOTEND 70 BOOTEND[70]0x09 Reserved 0x0A LOCKBIT 70 LOCKBIT[70]
694 Fuse Description
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 33
6941 Watchdog Configuration
Name WDTCFGOffset 0x00Reset -Property -
Bit 7 6 5 4 3 2 1 0 WINDOW[30] PERIOD[30]
Access R R R R R R R R Reset 0 0 0 0 0 0 0 0
Bits 74 ndash WINDOW[30] Watchdog Window Timeout PeriodThis value is loaded into the WINDOW bit field of the Watchdog Control A register (WDTCTRLA) duringReset
Bits 30 ndash PERIOD[30] Watchdog Timeout PeriodThis value is loaded into the PERIOD bit field of the Watchdog Control A register (WDTCTRLA) duringResetRelated Links194 Register Summary - WDT12 RSTCTRL - Reset Controller
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 34
6942 BOD Configuration
Name BODCFGOffset 0x01Reset -Property -
The settings of the BOD will be reloaded from this Fuse after a Power-on Reset For all other Resets theBOD configuration remains unchanged
Bit 7 6 5 4 3 2 1 0 LVL[20] SAMPFREQ ACTIVE[10] SLEEP[10]
Access R R R R R R R R Reset 0 0 0 0 0 0 0 0
Bits 75 ndash LVL[20] BOD LevelThis value is loaded into the LVL bit field of the BOD Control B register (BODCTRLB) during ResetValue Name Description0x0 BODLEVEL0 18V0x2 BODLEVEL2 26V0x7 BODLEVEL7 42V
Note bull Values in the description are typical valuesbull Refer to the BOD and POR Characteristics in Electrical Characteristics for maximum and minimum
values
Bit 4 ndash SAMPFREQ BOD Sample FrequencyThis value is loaded into the SAMPFREQ bit of the BOD Control A register (BODCTRLA) during ResetValue Description0x0 Sample frequency is 1 kHz0x1 Sample frequency is 125 Hz
Bits 32 ndash ACTIVE[10] BOD Operation Mode in Active and IdleThis value is loaded into the ACTIVE bit field of the BOD Control A register (BODCTRLA) during ResetValue Description0x0 Disabled0x1 Enabled0x2 Sampled0x3 Enabled with wake-up halted until BOD is ready
Bits 10 ndash SLEEP[10] BOD Operation Mode in SleepThis value is loaded into the SLEEP bit field of the BOD Control A register (BODCTRLA) during ResetValue Description0x0 Disabled0x1 Enabled0x2 Sampled0x3 Reserved
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 35
Related Links174 Register Summary - BOD12 RSTCTRL - Reset Controller
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 36
6943 Oscillator Configuration
Name OSCCFGOffset 0x02Reset -Property -
Bit 7 6 5 4 3 2 1 0 OSCLOCK FREQSEL[10]
Access R R R Reset 0 1 0
Bit 7 ndash OSCLOCK Oscillator LockThis fuse bit is loaded to LOCK in CLKCTRLOSC20MCALIBB during resetValue Description0 Calibration registers of the 20 MHz oscillator are accessible1 Calibration registers of the 20 MHz oscillator are locked
Bits 10 ndash FREQSEL[10] Frequency SelectThese bits selects the operation frequency of the 1620MHz internal oscillator (OSC20M) and determinethe respective factory calibration values to be written to CAL20M in CLKCTRLOSC20MCALIBA andTEMPCAL20M in CLKCTRLOSC20MCALIBBValue Description0x1 Run at 16MHz with corresponding factory calibration0x2 Run at 20MHz with corresponding factory calibrationOther Reserved
Related Links104 Register Summary - CLKCTRL12 RSTCTRL - Reset Controller
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 37
6944 Timer Counter Type D Configuration
Name TCD0CFGOffset 0x04Reset -Property -
The bit values of this fuse register are written to the corresponding bits in the TCDFAULTCTRL registerof TCD0 at start-upThe CMPEN and CMP settings of the TCD will only be reloaded from the FUSE values after a Power-OnReset For all other resets the corresponding TCD settings of the device will remain unchanged
Bit 7 6 5 4 3 2 1 0 CMPDEN CMPCEN CMPBEN CMPAEN CMPD CMPC CMPB CMPA
Access R R R R R R R R Reset 0 0 0 0 0 0 0 0
Bits 4 5 6 7 ndash CMPEN Compare x EnableValue Description0 Compare x output on Pin is disabled1 Compare x output on Pin is enabled
Bits 0 1 2 3 ndash CMP Compare xThis bit selects the default state of Compare x after Reset or when entering debug if FAULTDET is 1Value Description0 Compare x default state is 01 Compare x default state is 1
Related Links224 Register Summary - TCD12 RSTCTRL - Reset Controller
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 38
6945 System Configuration 0
Name SYSCFG0Offset 0x05Reset 0xC4Property -
Bit 7 6 5 4 3 2 1 0 CRCSRC[10] RSTPINCFG[10] EESAVE
Access R R R R R Reset 1 1 0 1 0
Bits 76 ndash CRCSRC[10] CRC SourceSee the CRC description for more information about the functionalityValue Name Description00 FLASH CRC of full Flash (boot application code and application data)01 BOOT CRC of the boot section10 BOOTAPP CRC of application code and boot sections11 NOCRC No CRC
Bits 32 ndash RSTPINCFG[10] Reset Pin ConfigurationThese bits select the ResetUPDI pin configurationValue Description0x0 GPIO0x1 UPDI0x2 RESET0x3 Reserved
Note When configuring the Reset Pin as GPIO there is a potential conflict between the GPIO activelydriving the output and a 12V UPDI enable sequence initiation To avoid this the GPIO output driver isdisabled for 768 OSC32K cycles after a System Reset Enable any interrupts for this pin only after thisperiod
Bit 0 ndash EESAVE EEPROM Save During Chip EraseIf the device is locked the EEPROM is always erased by a chip erase regardless of this bitValue Description0 EEPROM erased during chip erase1 EEPROM not erased under chip erase
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 39
6946 System Configuration 1
Name SYSCFG1Offset 0x06Reset -Property -
Bit 7 6 5 4 3 2 1 0 SUT[20]
Access R R R Reset 1 1 1
Bits 20 ndash SUT[20] Start Up Time SettingThese bits selects the start-up time between power-on and code executionValue Description0x0 0ms0x1 1ms0x2 2ms0x3 4ms0x4 8ms0x5 16ms0x6 32ms0x7 64ms
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 40
6947 Application Code End
Name APPENDOffset 0x07Reset -Property -
Bit 7 6 5 4 3 2 1 0 APPEND[70]
Access R R R R R R R R Reset 0 0 0 0 0 0 0 0
Bits 70 ndash APPEND[70] Application Code Section EndThese bits set the end of the application code section in blocks of 256 bytes The end of the applicationcode section should be set as BOOT size + application code size The remaining Flash will be applicationdata A value of 0x00 defines the Flash from BOOTEND256 to end of Flash as application code Whenboth FUSEAPPEND and FUSEBOOTEND are 0x00 the entire Flash is BOOT sectionRelated Links9 NVMCTRL - Non Volatile Memory Controller9311 Flash
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 41
6948 Boot End
Name BOOTENDOffset 0x08Reset -Property -
Bit 7 6 5 4 3 2 1 0 BOOTEND[70]
Access R R R R R R R R Reset 0 0 0 0 0 0 0 0
Bits 70 ndash BOOTEND[70] Boot Section EndThese bits set the end of the boot section in blocks of 256 bytes A value of 0x00 defines the whole Flashas BOOT section When both FUSEAPPEND and FUSEBOOTEND are 0x00 the entire Flash is BOOTsectionRelated Links9 NVMCTRL - Non Volatile Memory Controller9311 Flash
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 42
6949 Lock Bits
Name LOCKBITOffset 0x0AReset -Property -
Bit 7 6 5 4 3 2 1 0 LOCKBIT[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash LOCKBIT[70] Lock BitsWhen the part is locked UPDI cannot access the system bus so it cannot read out anything but CS-spaceValue Description0xC5 The device is openother The device is locked
ATtiny416816Memories
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 43
7 Peripherals and Architecture
71 Peripheral Module Address MapThe address map show the base address for each peripheral For complete register description andsummary for each peripheral module refer to the respective module chapters
Table 7-1 Peripheral Module Address Map
Base Address Name Description
0x0000 VPORTA Virtual Port A
0x0004 VPORTB Virtual Port B
0x0008 VPORTC Virtual Port C
0x001C GPIO General Purpose IO registers
0x0030 CPU CPU
0x0040 RSTCTRL Reset Controller
0x0050 SLPCTRL Sleep Controller
0x0060 CLKCTRL Clock Controller
0x0080 BOD Brown-Out Detector
0x00A0 VREF Voltage Reference
0x0100 WDT Watchdog Timer
0x0110 CPUINT Interrupt Controller
0x0120 CRCSCAN Cyclic Redundancy Check Memory Scan
0x0140 RTC Real Time Counter
0x0180 EVSYS Event System
0x01C0 CCL Configurable Custom Logic
0x0200 PORTMUX Port Multiplexer
0x0400 PORTA Port A Configuration
0x0420 PORTB Port B Configuration
0x0440 PORTC Port C Configuration
0x0600 ADC0 Analog to Digital ConverterPeripheral Touch Controller
0x06A0 DAC0 Digital to Analog Converter 0
0x0670 AC0 Analog Comparator
0x0680 DAC0 Digital to Analog Converter
0x0800 USART0 Universal Synchronous Asynchronous Receiver Transmitter
ATtiny416816Peripherals and Architecture
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 44
continuedBase Address Name Description
0x0810 TWI0 Two Wire Interface
0x0820 SPI0 Serial Peripheral Interface
0x0A00 TCA0 TimerCounter Type A instance 0
0x0A40 TCB0 TimerCounter Type B instance 0
0x0A80 TCD0 TimerCounter Type D instance 0
0x0F00 SYSCFG System Configuration
0x1000 NVMCTRL Non Volatile Memory Controller
0x1100 SIGROW Signature Row
0x1280 FUSES Device specific fuses
0x1300 USERROW User Row
72 Interrupt Vector MappingEach of the 26 interrupt vectors is connected to one peripheral instance as shown in the table below Aperipheral can have one or more interrupt sources see the Interrupt section in the FunctionalDescription of the respective peripheral for more details on the available interrupt sources
When the interrupt condition occurs an Interrupt Flag (nameIF) is set in the Interrupt Flags register of theperipheral (peripheralINTFLAGS)
An interrupt is enabled or disabled by writing to the corresponding Interrupt Enable bit (nameIE) in theperipherals Interrupt Control register (peripheralINTCTRL)
The naming of the registers may vary slightly in some peripherals
An interrupt request is generated when the corresponding interrupt is enabled and the Interrupt Flag isset The interrupt request remains active until the Interrupt Flag is cleared See the peripheralsINTFLAGS register for details on how to clear Interrupt Flags
Interrupts must be enabled globally for interrupt requests to be generatedTable 7-2 Interrupt Vector Mapping
Vector Number Peripheral Source Definition
0 RESET RESET
1 CRCSCAN_NMI NMI - Non-Maskable Interrupt from CRC
2 BOD_VLM VLM - Voltage Level Monitor
3 PORTA_PORT PORTA - Port A
4 PORTB_PORT PORTB - Port B
5 PORTC_PORT PORTC - Port C
6 RTC_CNT RTC - Real Time Counter
ATtiny416816Peripherals and Architecture
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 45
continuedVector Number Peripheral Source Definition
7 RTC_PIT PIT - Periodic Interrupt Timer (in RTC peripheral)
8 TCA0_LUNF TCA0_OVF TCA0 - Timer Counter Type A LUNF OVF
9 TCA0_HUNF TCA0 HUNF
10 TCA0_LCMP0 TCA0_CMP0 TCA0 LCMP0 CMP0
11 TCA0_LCMP1 TCA0_CMP1 TCA0 LCMP1 CMP1
12 TCA0_CMP2 TCA0_LCMP2 TCA0 LCMP2 CMP2
13 TCB0_INT TCB0 - Timer Counter Type B
14 TCD0_OVF TCD0 - Timer Counter Type D OVF
15 TCD0_TRIG TCD0 TRIG
16 AC0_AC AC0 ndash Analog Comparator
17 ADC0_RESRDY ADC0 ndash Analog-to-Digital Converter RESRDY
18 ADC0_WCOMP ADC0 WCOMP
19 TWI0_TWIS TWI0 - Two Wire Interface I2C TWIS
20 TWI0_TWIM TWI0 TWIM
21 SPI0_INT SPI0 - Serial Peripheral Interface
22 USART0_RXC USART0 - Universal Asynchronous Receiver-Transmitter RXC
23 USART0_DRE USART0 DRE
24 USART0_TXC USART0 TXC
25 NVMCTRL_EE NVM - Non Volatile Memory
Related Links9 NVMCTRL - Non Volatile Memory Controller16 PORT - IO Pin Configuration23 RTC - Real Time Counter25 SPI - Serial Peripheral Interface24 USART - Universal Synchronous and Asynchronous Receiver and Transmitter26 TWI - Two Wire Interface27 CRCSCAN - Cyclic Redundancy Check Memory Scan20 TCA - 16-bit TimerCounter Type A21 TCB - 16-bit TimerCounter Type B22 TCD - 12-bit TimerCounter Type D29 AC ndash Analog Comparator30 ADC - Analog to Digital Converter
ATtiny416816Peripherals and Architecture
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 46
73 SYSCFG - System ConfigurationThe System Configuration contains the revision ID of the part The Revision ID is readable from the CPUmaking it useful for implementing application changes between part revisions
ATtiny416816Peripherals and Architecture
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 47
731 Register Summary - SYSCFG
Offset Name Bit Pos
0x01 REVID 70 REVID[70]
732 Register Description - SYSCFG
ATtiny416816Peripherals and Architecture
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 48
7321 Device Revision ID Register
Name REVIDOffset 0x01Reset [revision ID]Property -
This register is read only and give the device revision ID
Bit 7 6 5 4 3 2 1 0 REVID[70]
Access R R R R R R R R Reset
Bits 70 ndash REVID[70] Revision IDThese bits contain the device revision 0x00 = A 0x01 = B and so on
ATtiny416816Peripherals and Architecture
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 49
8 AVR CPU
81 Featuresbull 8-bit high-performance AVR RISC CPU
ndash 135 instructionsndash Hardware multiplier
bull 32 8-bit registers directly connected to the ALUbull Stack in RAMbull Stack pointer accessible in IO memory spacebull Direct addressing of up to 64KB of unified memory
ndash Entire Flash accessible with all LDST instructionsbull True 16-bit access to 16-bit IO registersbull Efficient support for 8- 16- and 32-bit arithmeticbull Configuration Change Protection for system-critical features
82 OverviewAll AVR devices use the 8-bit AVR CPU The CPU is able to access memories perform calculationscontrol peripherals and execute instructions in the program memory Interrupt handling is described in aseparate section
Related Links6 Memories9 NVMCTRL - Non Volatile Memory Controller13 CPUINT - CPU Interrupt Controller
83 ArchitectureIn order to maximize performance and parallelism the AVR CPU uses a Harvard architecture withseparate buses for program and data Instructions in the program memory are executed with single-levelpipelining While one instruction is being executed the next instruction is pre-fetched from the programmemory This enables instructions to be executed on every clock cycle
ATtiny416816AVR CPU
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 50
Figure 8-1 AVR CPU Architecture
Register file
Flash programmemory
Programcounter
Instructionregister
Instructiondecode
Data memory
ALUStatusregister
R0R1R2R3R4R5R6R7R8R9
R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25
R26 (XL)R27 (XH)R28 (YL)R29 (YH)R30 (ZL)R31 (ZH)
Stackpointer
The Arithmetic Logic Unit (ALU) supports arithmetic and logic operations between registers or between aconstant and a register Single-register operations can also be executed in the ALU After an arithmeticoperation the status register is updated to reflect information about the result of the operation
The ALU is directly connected to the fast-access register file The 32 8-bit general purpose workingregisters all have single clock cycle access time allowing single-cycle arithmetic logic unit operation
ATtiny416816AVR CPU
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 51
between registers or between a register and an immediate Six of the 32 registers can be used as three16-bit address pointers for program and data space addressing enabling efficient address calculations
The program memory bus is connected to Flash and the first program memory Flash address is 0x0000
The data memory space is divided into IO registers SRAM EEPROM and Flash
All IO status and control registers reside in the lowest 4KB addresses of the data memory This isreferred to as the IO memory space The lowest 64 addresses are accessed directly with single cycleINOUT instructions or as the data space locations from 0x00 to 0x3F These addresses can also beaccessed using load (LDLDSLDD) and store (STSTSSTD) instructions The lowest 32 addresses caneven be accessed with single cycle SBICBI instructions and SBISSBIC instructions The rest is theextended IO memory space ranging from 0x0040 to 0x0FFF IO registers here must be accessed asdata space locations using load and store instructions
Data addresses 0x1000 to 0x1800 are reserved for memory mapping of fuses the NVM controller andEEPROM The addresses from 0x1800 to 0x7FFF are reserved for other memories such as SRAM
The Flash is mapped in the data space from 0x8000 and above The Flash can be accessed with all loadand store instructions by using addresses above 0x8000 The LPM instruction accesses the Flash as inthe code space where the Flash starts at address 0x0000
For a summary of all AVR instructions refer to the Instruction Set Summary For details of all AVRinstructions refer to httpwwwmicrochipcomdesign-centers8-bit
Related Links9 NVMCTRL - Non Volatile Memory Controller6 Memories38 Instruction Set Summary
84 ALU - Arithmetic Logic UnitThe Arithmetic Logic Unit supports arithmetic and logic operations between registers or between aconstant and a register Single-register operations can also be executed
The ALU operates in direct connection with all 32 general purpose registers Arithmetic operationsbetween general purpose registers or between a register and an immediate are executed in a single clockcycle and the result is stored in the register file After an arithmetic or logic operation the Status register(CPUSREG) is updated to reflect information about the result of the operation
ALU operations are divided into three main categories ndash arithmetic logical and bit functions Both 8- and16-bit arithmetic is supported and the instruction set allows for efficient implementation of 32-bitarithmetic The hardware multiplier supports signed and unsigned multiplication and fractional format
841 Hardware MultiplierThe multiplier is capable of multiplying two 8-bit numbers into a 16-bit result The hardware multipliersupports different variations of signed and unsigned integer and fractional numbers
bull Multiplication of signedunsigned integersbull Multiplication of signedunsigned fractional numbersbull Multiplication of a signed integer with an unsigned integerbull Multiplication of a signed fractional number with an unsigned one
A multiplication takes two CPU clock cycles
ATtiny416816AVR CPU
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 52
85 Functional Description
851 Program FlowAfter Reset the CPU will execute instructions from the lowest address in the Flash program memory0x0000 The program counter (PC) address the next instruction to be fetched
Program flow is supported by conditional and unconditional jump and call instructions capable ofaddressing the whole address space directly Most AVR instructions use a 16-bit word format and alimited number uses a 32-bit format
During interrupts and subroutine calls the return address PC is stored on the stack as a word pointerThe stack is allocated in the general data SRAM and consequently the stack size is only limited by thetotal SRAM size and the usage of the SRAM After Reset the stack pointer (SP) points to the highestaddress in the internal SRAM The SP is readwrite accessible in the IO memory space enabling easyimplementation of multiple stacks or stack areas The data SRAM can easily be accessed through thefive different addressing modes supported by the AVR CPU
852 Instruction Execution TimingThe AVR CPU is clocked by the CPU clock CLK_CPU No internal clock division is applied The Figurebelow shows the parallel instruction fetches and instruction executions enabled by the Harvardarchitecture and the fast-access register file concept This is the basic pipelining concept enabling up to1MIPSMHz performance with high efficiency
Figure 8-2 The Parallel Instruction Fetches and Instruction Executions
clk
1st Instruction Fetch1st Instruction Execute
2nd Instruction Fetch2nd Instruction Execute
3rd Instruction Fetch3rd Instruction Execute
4th Instruction Fetch
T1 T2 T3 T4
CPU
The following Figure shows the internal timing concept for the register file In a single clock cycle an ALUoperation using two register operands is executed and the result is stored in the destination register
Figure 8-3 Single Cycle ALU Operation
Total Execution Time
Register Operands Fetch
ALU Operation Execute
Result Write Back
T1 T2 T3 T4
clkCPU
853 Status RegisterThe Status register (CPUSREG) contains information about the result of the most recently executedarithmetic or logic instruction This information can be used for altering program flow in order to performconditional operations
ATtiny416816AVR CPU
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 53
CPUSREG is updated after all ALU operations as specified in the Instruction Set Summary This will inmany cases remove the need for using the dedicated compare instructions resulting in faster and morecompact code CPUSREG is not automatically storedrestored when enteringreturning from an interruptservice routine Maintaining the status register between context switches must therefore be handled byuser defined software CPUSREG is accessible in the IO memory space
Related Links38 Instruction Set Summary
854 Stack and Stack PointerThe Stack is used for storing return addresses after interrupts and subroutine calls It can also be usedfor storing temporary data The Stack Pointer (SP) always point to the top of the Stack The SP is definedby the Stack Pointer bits (SP) in the Stack Pointer register (CPUSP) CPUSP is implemented as two 8-bit registers that are accessible in the IO memory space
Data is pushed and popped from the Stack using the PUSH and POP instructions The Stack grows fromhigher to lower memory locations This implies that pushing data onto the Stack decreases the SP andpopping data off the Stack increases the SP The Stack Pointer is automatically set to the highest addressof the internal SRAM after Reset If the Stack is changed it must be set to point above address 0x2000and it must be defined before both any subroutine calls are executed and before interrupts are enabled
During interrupts or subroutine calls the return address is automatically pushed on the Stack as a wordpointer and the SP is decremented by 2 The return address consists of two bytes and the leastsignificant byte is pushed on the Stack first (at the higher address) As an example a byte pointer returnaddress of 0x0006 is saved on the Stack as 0x0003 (shifted one bit to the right) pointing to the fourth 16-bit instruction word in the program memory The return address is popped off the Stack with RETI (whenreturning from interrupts) and RET (when returning from subroutine calls) and the SP is incremented by2
The SP is decremented by 1 when data is pushed on the Stack with the PUSH instruction andincremented by 1 when data is popped off the Stack using the POP instruction
To prevent corruption when updating the Stack pointer from software a write to SPL will automaticallydisable interrupts for up to four instructions or until the next IO memory write
855 Register FileThe register file consists of 32 8-bit general purpose working registers with single clock cycle access timeThe register file supports the following inputoutput schemes
bull One 8-bit output operand and one 8-bit result inputbull Two 8-bit output operands and one 8-bit result inputbull Two 8-bit output operands and one 16-bit result inputbull One 16-bit output operand and one 16-bit result input
Six of the 32 registers can be used as three 16-bit address register pointers for data space addressingenabling efficient address calculations
ATtiny416816AVR CPU
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 54
Figure 8-4 AVR CPU General Purpose Working Registers
7 0R0R1R2
R13R14R15R16R17
R26R27R28R29R30R31
Addr0x000x010x02
0x0D0x0E0x0F0x100x11
0x1A0x1B0x1C0x1D0x1E0x1F
X-register Low ByteX-register High ByteY-register Low ByteY-register High ByteZ-register Low ByteZ-register High Byte
The register file is located in a separate address space and is therefore not accessible trough instructionsoperation on data memory
8551 The X- Y- and Z- RegistersRegisters R26R31 have added functions besides their general-purpose usage
These registers can form 16-bit address pointers for addressing data memory These three addressregisters are called the X-register Y-register and Z-register Load and store instructions can use all X- Y-and Z-registers while the LPM instructions can only use the Z-register Indirect calls and jumps (ICALLand IJMP) also use the Z-register
Refer to the instruction set or Instruction Set Summary for more information about how the X- Y- and Z-registers are used
Figure 8-5 The X- Y- and Z-registersBit (individually)
X-register
Bit (X-register)
7 0 7 0
15 8 7 0
R27 R26
XH XL
Bit (individually)
Y-register
Bit (Y-register)
7 0 7 0
15 8 7 0
R29 R28
YH YL
Bit (individually)
Z-register
Bit (Z-register)
7 0 7 0
15 8 7 0
R31 R30
ZH ZL
The lowest register address holds the least-significant byte (LSB) and the highest register address holdsthe most-significant byte (MSB) In the different addressing modes these address registers function asfixed displacement automatic increment and automatic decrement
Related Links38 Instruction Set Summary
ATtiny416816AVR CPU
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 55
856 Accessing 16-bit RegistersThe AVR data bus is 8 bits wide and so accessing 16-bit registers requires atomic operations Theseregisters must be byte-accessed using two read or write operations 16-bit registers are connected to the8-bit bus and a temporary register using a 16-bit bus
For a write operation the low byte of the 16-bit register must be written before the high byte The low byteis then written into the temporary register When the high byte of the 16-bit register is written thetemporary register is copied into the low byte of the 16-bit register in the same clock cycle
For a read operation the low byte of the 16-bit register must be read before the high byte When the lowbyte register is read by the CPU the high byte of the 16-bit register is copied into the temporary registerin the same clock cycle as the low byte is read When the high byte is read it is then read from thetemporary register
This ensures that the low and high bytes of 16-bit registers are always accessed simultaneously whenreading or writing the register
Interrupts can corrupt the timed sequence if an interrupt is triggered and accesses the same 16-bitregister during an atomic 16-bit readwrite operation To prevent this interrupts can be disabled whenwriting or reading 16-bit registers
The temporary registers can also be read and written directly from user software
857 CCP - Configuration Change ProtectionSystem critical IO register settings are protected from accidental modification Flash self-programming(via store to NVM controller) is protected from accidental execution This is handled globally by theconfiguration change protection (CCP) register
Changes to the protected IO registers or bits or execution of protected instructions are only possibleafter the CPU writes a signature to the CCP register The different signatures are listed in the descriptionof the CCP register (CPUCCP)
There are two modes of operation one for protected IO registers and one for the protected self-programming
Related Links871 CCP
8571 Sequence for Write Operation to Configuration Change Protected IO RegistersIn order to write to registers protected by CCP these steps are required
1 The software writes the signature that enables change of protected IO registers to the CCP bit fieldin the CPUCCP register
2 Within four instructions the software must write the appropriate data to the protected registerMost protected registers also contain a write enablechange enablelock bit This bit must be writtento 1 in the same operation as the data are written
The protected change is immediately disabled if the CPU performs write operations to the IOregister or data memory if load or store accesses to Flash NVMCTRL EEPROM are conductedor if the SLEEP instruction is executed
8572 Sequence for Execution of Self-ProgrammingIn order to execute self-programming (the execution of writes to the NVM controllers command register)these steps are required
ATtiny416816AVR CPU
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 56
1 The software temporary enables self-programming by writing the SPM signature to the CCPregister (CPUCCP)
2 Within four instructions the software must execute the appropriate instruction The protectedchange is immediately disabled if the CPU performs accesses to the Flash NVMCTRL orEEPROM or if the SLEEP instruction is executed
Once the correct signature is written by the CPU interrupts will be ignored for the duration of theconfiguration change enable period Any interrupt request (including non-maskable interrupts) during theCCP period will set the corresponding interrupt flag as normal and the request is kept pending After theCCP period is completed any pending interrupts are executed according to their level and priority
ATtiny416816AVR CPU
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 57
86 Register Summary - CPU
Offset Name Bit Pos
0x04 CCP 70 CCP[70]0x05
0x0C
Reserved
0x0D SP70 SP[70]158 SP[158]
0x0F SREG 70 I T H S V N Z C
87 Register Description
ATtiny416816AVR CPU
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 58
871 Configuration Change Protection
Name CCPOffset 0x04Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 CCP[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash CCP[70] Configuration Change ProtectionWriting the correct signature to this bit field allows changing protected IO registers or executing protectedinstructions within the next four CPU instructions executedAll interrupts are ignored during these cycles After these cycles interrupts will automatically be handledagain by the CPU and any pending interrupts will be executed according to their level and priorityWhen the protected IO register signature is written CCP[0] will read as 1 as long as the CCP feature isenabledWhen the protected self-programming signature is written CCP[1] will read as 1 as long as the CCPfeature is enabledCCP[72] will always read as zeroValue Name Description0x9D SPM Allow Self-Programming0xD8 IOREG Un-protect protected IO registers
ATtiny416816AVR CPU
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 59
872 Stack Pointer
Name SPOffset 0x0DReset 0xxxxxProperty -
The CPUSP holds the Stack Pointer (SP) that points to the top of the Stack After Reset the StackPointer points to the highest internal SRAM address
Only the number of bits required to address the available data memory including external memory (up to64KB) is implemented for each device Unused bits will always read as zero
The CPUSPL and CPUSPH register pair represents the 16-bit value CPUSP The low byte [70] (suffixL) is accessible at the original offset The high byte [158] (suffix H) can be accessed at offset + 0x01 Formore details on reading and writing 16-bit registers refer to 856 Accessing 16-bit Registers
To prevent corruption when updating the Stack Pointer from software a write to CPUSPL willautomatically disable interrupts for the next four instructions or until the next IO memory write
Bit 15 14 13 12 11 10 9 8 SP[158]
Access RW RW RW RW RW RW RW RW Reset x x x x x x x x
Bit 7 6 5 4 3 2 1 0 SP[70]
Access RW RW RW RW RW RW RW RW Reset x x x x x x x x
Bits 158 ndash SP[158] Stack Pointer high byteThese bits hold the MSB of the 16-bit register
Bits 70 ndash SP[70] Stack Pointer low byteThese bits hold the LSB of the 16-bit register
ATtiny416816AVR CPU
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 60
873 Status Register
Name SREGOffset 0x0FReset 0x00Property -
The Status register contains information about the result of the most recently executed arithmetic or logicinstruction For details about the bits in this register and how they are affected by the differentinstructions see the Instruction Set Summary
Bit 7 6 5 4 3 2 1 0 I T H S V N Z C
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bit 7 ndash I Global Interrupt EnableWriting a 1 to this bit enable interrupts on the deviceWriting a 0 to this bit disables interrupts on the device independent of the individual interrupt enablesettings of the peripheralsThis bit is not cleared by hardware after an interrupt has occurredThis bit can be set and cleared by software with the SEI and CLI instructionsChanging the I flag through the IO-register result in a one-cycle wait state on the access
Bit 6 ndash T Bit Copy StorageThe bit copy instructions bit load (BLD) and bit store (BST) use the T bit as source or destination for theoperated bitA bit from a register in the register file can be copied into this bit by the BST instruction and this bit canbe copied into a bit in a register in the register file by the BLD instruction
Bit 5 ndash H Half Carry FlagThis bit indicates a half carry in some arithmetic operations Half carry is useful in BCD arithmetic
Bit 4 ndash S Sign Bit S = N oplus VThe sign bit (S) is always an exclusive or (xor) between the negative flag (N) and the tworsquos complementoverflow flag (V)
Bit 3 ndash V Tworsquos Complement Overflow FlagThe tworsquos complement overflow flag (V) supports tworsquos complement arithmetic
Bit 2 ndash N Negative FlagThe negative flag (N) indicates a negative result in an arithmetic or logic operation
Bit 1 ndash Z Zero FlagThe zero flag (Z) indicates a zero result in an arithmetic or logic operation
Bit 0 ndash C Carry FlagThe carry flag (C) indicates a carry in an arithmetic or logic operation
ATtiny416816AVR CPU
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 61
9 NVMCTRL - Non Volatile Memory Controller
91 Featuresbull Unified memorybull In-system programmablebull Self-programming and boot loader supportbull Configurable sections for write protection
ndash Boot section for boot loader code or application codendash Application code section for application codendash Application data section for application code or data storage
bull Signature Row for factory-programmed datandash ID for each device typendash Serial number for each devicendash Calibration bytes for factory calibrated peripherals
bull User Row for application datandash 32 bytes in sizendash Can be read and written from softwarendash Can be written from UPDI on locked devicendash Content is kept after chip erase
92 OverviewThe NVM Controller (NVMCTRL) is the interface between the device the Flash and the EEPROM TheFlash and EEPROM are reprogrammable memory blocks that retain their values even when not poweredThe Flash is mainly used for program storage but can also be used for data storage The EEPROM isused for data storage and can be programmed while the CPU is running the program from the Flash
921 Block DiagramFigure 9-1 NVMCTRL Block Diagram
Flash
EEPROM
NVM Block
Signature Row
User Row
NVMCTRL
Program Memory Bus
Data Memory Bus
ATtiny416816NVMCTRL - Non Volatile Memory Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 62
922 System DependenciesIn order to use this peripheral other parts of the system must be configured correctly as described below
Table 9-1 NVMCTRL System Dependencies
Dependency Applicable Peripheral
Clocks Yes CLKCTRL
IO Lines and Connections No -
Interrupts Yes CPUINT
Events No -
Debug Yes UPDI
Related Links9221 Clocks9225 Debug Operation9223 Interrupts
9221 ClocksThis peripheral always runs on the CPU clock (CLK_CPU) It will request this clock also in sleep modes ifa writeerase is ongoing
Related Links10 CLKCTRL - Clock Controller
9222 IO Lines and ConnectionsNot applicable
9223 InterruptsUsing the interrupts of this peripheral requires the Interrupt Controller to be configured first
9224 EventsNot applicable
9225 Debug OperationWhen run-time debugging this peripheral will continue normal operation Halting the CPU in debuggingmode will halt normal operation of the peripheral
If the peripheral is configured to require periodical service by the CPU through interrupts or similarimproper operation or data loss may result during halted debugging
Related Links33 UPDI - Unified Program and Debug Interface
93 Functional Description
931 Memory Organization
9311 FlashThe Flash is divided into a set of pages A page is the basic unit addressed when programming the FlashIt is only possible to write or erase a whole page at a time One page consists of several words
ATtiny416816NVMCTRL - Non Volatile Memory Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 63
The Flash can be divided into three sections in blocks of 256 bytes for different security The threedifferent sections are BOOT application code (APPCODE) and application data (APPDATA)
Figure 9-2 Flash SectionsFLASHSTART 0x8000
BOOTENDgt0 0x8000+BOOTEND256
BO OT
APPENDgt0 0x8000+APPEND256
AP PL ICA TIO NCO DE
AP PLICA TIO NDA TA
Section SizesThe sizes of these sections are set by the Boot Section End fuse (FUSEBOOTEND) and ApplicationCode Section End fuse (FUSEAPPEND)
The fuses select the section sizes in blocks of 256 bytes As shown in Figure 9-2 the BOOT sectionstretches from the start of the Flash until BOOTEND The APPCODE section runs from BOOTEND untilAPPEND The remaining area is the APPDATA section If APPEND is written to 0 the APPCODE sectionruns from BOOTEND to the end of Flash (removing the APPDATA section) If BOOTEND and APPENDare written to 0 the entire Flash is regarded as BOOT section APPEND should either be set to 0 or avalue greater or equal than BOOTEND
Table 9-2 Setting up Flash sections
BOOTEND APPEND BOOT section APPCODE section APPDATA section
0 0 0 to FLASHEND - -
gt 0 0 0 to 256BOOTEND 256BOOTEND toFLASHEND
-
gt 0 ==BOOTEND
0 to 256BOOTEND - 256BOOTEND toFLASHEND
gt 0 gtBOOTEND
0 to 256BOOTEND 256BOOTEND to256APPEND
256APPEND toFLASHEND
ATtiny416816NVMCTRL - Non Volatile Memory Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 64
Note bull Also see 6948 BOOTEND and 6947 APPEND descriptionsbull Interrupt vectors are by default located after the BOOT section This can be changed in the interrupt
controller Refer to 13322 Interrupt Vector Locations
If FUSEBOOTEND is written to 0x04 and FUSEAPPEND is written to 0x08 the first4256 bytes will be BOOT the next 4256 bytes will be APPCODE and the remainingFlash will be APPDATA
Inter-Section Write ProtectionBetween the three Flash sections a directional write protection is implemented
bull Code in the BOOT section can write to APPCODE and APPDATAbull Code in APPCODE can write to APPDATAbull Code in APPDATA cannot write to Flash or EEPROM
Boot Section Lock and Application Code Section Write ProtectionThe two lock bits (APCWP and BOOTLOCK in NVMCTRLCTRLB) can be set to lock further updates ofthe respective APPCODE or BOOT section until the next Reset
The CPU can never write to the BOOT section NVMCTRL_CTRLBBOOTLOCK prevents reads andexecution of code from the BOOT section
9312 EEPROMThe EEPROM is divided into a set of pages where one page consists of multiple bytes The EEPROMhas byte granularity on erase write Within one page only the bytes marked to be updated will be erasedwritten The byte is marked by writing a new value to the page buffer for that address location
9313 User RowThe User Row is one extra page of EEPROM This page can be used to store various data such ascalibrationconfiguration data and serial numbers This page is not erased by a chip erase The User Rowis written as normal EEPROM but in addition it can be written through UPDI on a locked device
932 Memory Access
9321 ReadReading of the Flash and EEPROM is done by using a load instructions with address according to thememory map Reading any of the arrays while a write or erase is in progress will result in a bus wait andthe instruction will be suspended until the ongoing operation is complete
9322 Page Buffer LoadThe page buffer is loaded by writing directly to the memories as defined in the memory map FlashEEPROM and User Row share the same page buffer so only one section can be programmed at onetime The least significant bits of the address are used to select where in the page buffer the data iswritten The resulting data will be a binary AND operation between the new and the previous content ofthe page buffer The page buffer will automatically be erased (all bits set) after
bull a device resetbull any page write or erase operationbull a clear page buffer commandbull the device wakes up from any sleep mode
ATtiny416816NVMCTRL - Non Volatile Memory Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 65
9323 ProgrammingFor page programming filling the page buffer and writing the page buffer into Flash User Row andEEPROM are two separate operations
Before programming a flash page with the data in the page buffer the flash page must be erased Thepage buffer is also erased when the device enter sleep mode Programming an un-erased flash page willcorrupt its content
The flash can either be written with the erase and write separately or one command handling both
Alternative 1bull Fill the page bufferbull Write the page buffer to flash with the erase-write page command
Alternative 2bull Write to a location in the page to set up the addressbull Perform a erase page commandbull Fill the page bufferbull Perform a write page command
The NVM command set supports both a single erase and write operation and split page erase and pagewrite commands This split commands enable shorter programming time for each command and theerase operations can be done during non-time-critical programming execution
The EEPROM programming is similar but only the bytes updated in the page buffer will be written orerased in the EEPROM
9324 CommandsReading of the FlashEEPROM and writing of the page buffer is handled with normal loadstoreinstructions Other operations such as writing and erasing the memory arrays are handled by commandsin the NVM
To execute a command in the NVM1 Write the NVM command unlock to the Configuration Change Protection register in the CPU
(CPUCCP)2 Write the desired command value to the CMD bits in the Control A register (NVMCTRLCTRLA)
within the next 4 instructions
93241 Write CommandThe write command of the Flash controller writes the content of the page buffer to the Flash orEEPROM
If the write is to the Flash the CPU will stop executing code as long as the Flash is busy with the writeoperation If the write is to the EEPROM the CPU can continue executing code while the operation isongoing
The page buffer will be automatically cleared after the operation is finished
93242 Erase CommandThe erase command erases the current page There must be one byte written in the page buffer for theerase command to take effect
For erasing the Flash first write to one address in the desired page then execute the command Thewhole page in the Flash will then be erased The CPU will be halted while the erase is ongoing
ATtiny416816NVMCTRL - Non Volatile Memory Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 66
For the EEPROM only the bytes written in the page buffer will be erased when the command isexecuted To erase a specific byte write to its corresponding address before executing the command Toerase a whole page all the bytes in the page buffer has to be updated before executing the commandThe CPU can continue running code while the operation is ongoing
The page buffer will be automatically cleared after the operation is finished
93243 Erase-Write OperationThe erase-write command is a combination of the erase and write command but without clearingthe page buffer after the erase command The erase-write operation first erases the selected pagethen it writes the content of the page buffer to the same page
When executed on the Flash the CPU will be halted when the operations are ongoing When executedon EEPROM the CPU can continue executing code
The page buffer will be automatically cleared after the operation is finished
93244 Page Buffer Clear CommandThe page buffer clear command clears the page buffer The contents of the page buffer will be all-ones after the operation The CPU will be halted when the operation executes (7 CPU cycles)
93245 Chip Erase CommandThe chip erase command erases the Flash and the EEPROM The EEPROM is unaltered if theEEPROM Save During Chip Erase (EESAVE) fuse in FUSESYSCFG0 is set The memory will be all-ones after the operation
93246 EEPROM Erase CommandThe EEPROM erase command erases the EEPROM The EEPROM will be all-ones after the operationThe CPU will be halted while the EEPROM is being erased
93247 Fuse Write CommandThe fuse write command writes the fuses It can only be used by the UPDI the CPU cannot start thiscommand
Follow this procedure to use this commandbull Write the address of the fuse to the Address register (NVMCTRLADDR)bull Write the data to be written to the fuse to the Data register (NVMCTRLDATA)bull Execute the fuse write commandbull After the fuse is written a Reset is required for the updated value to take effect
For reading fuses use a regular read on the memory location
933 Preventing FlashEEPROM CorruptionDuring periods of low VDD the Flash program or EEPROM data can be corrupted if the supply voltage istoo low for the CPU and the FlashEEPROM to operate properly These issues are the same as for boardlevel systems using FlashEEPROM and the same design solutions should be applied
A FlashEEPROM corruption can be caused by two situations when the voltage is too low First a regularwrite sequence to the Flash requires a minimum voltage to operate correctly Also the CPU itself canexecute instructions incorrectly when the supply voltage is too low See the Electrical Characteristicschapter for Maximum Frequency vs VDD
FlashEEPROM corruption can be avoided by these measures
Keep the device in reset during periods of insufficient power supply voltage This can be done by enablingthe internal Brown-Out Detector (BOD)
ATtiny416816NVMCTRL - Non Volatile Memory Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 67
The voltage level monitor in the BOD can be used to prevent starting a write to the EEPROM close to theBOD level
If the detection levels of the internal BOD does not match the required detection level an external low-VDD-reset protection circuit can be used If a Reset occurs while a write operation is ongoing the writeoperation will be aborted
Related Links343 General Operating Ratings17 BOD - Brownout Detector
934 InterruptsTable 9-3 Available Interrupt Vectors and Sources
Offset Name Vector Description Conditions
0x00 EEREADY NVM The EEPROM is ready for new writeerase operations
When an interrupt condition occurs the corresponding Interrupt Flag is set in the Interrupt Flags registerof the peripheral (NVMCTRLINTFLAGS)
An interrupt source is enabled or disabled by writing to the corresponding bit in the peripherals InterruptEnable register (NVMCTRLINTEN)
An interrupt request is generated when the corresponding interrupt source is enabled and the InterruptFlag is set The interrupt request remains active until the Interrupt Flag is cleared See the peripheralsINTFLAGS register for details on how to clear Interrupt Flags
935 Sleep Mode OperationIf there is no ongoing write operation the NVMCTRL will enter sleep mode when the system enters sleepmode
If a write operation is ongoing when the system enters a sleep mode the NVM block the NVM Controllerand the system clock will remain on until the write is finished This is valid for all sleep modes includingPower Down sleep mode
The EEPROM Ready interrupt will wake up the device only from Idle sleep mode
The page buffer is cleared when waking up from sleep
936 Configuration Change ProtectionThis peripheral has registers that are under Configuration Change Protection (CCP) In order to write tothese a certain key must be written to the CPUCCP register first followed by a write access to theprotected bits within four CPU instructions
It is possible to try writing to these registers any time but the values are not altered
The following registers are under CCP
Table 9-4 NVMCTRL - Registers under Configuration Change Protection
Register Key
NVMCTRLCTRLA SPM
Related Links
ATtiny416816NVMCTRL - Non Volatile Memory Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 68
8572 Sequence for Execution of Self-Programming
ATtiny416816NVMCTRL - Non Volatile Memory Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 69
94 Register Summary - NVMCTRL
Offset Name Bit Pos
0x00 CTRLA 70 CMD[20]0x01 CTRLB 70 BOOTLOCK APCWP0x02 STATUS 70 WRERROR EEBUSY FBUSY0x03 INTCTRL 70 EEREADY0x04 INTFLAGS 70 EEREADY0x05 Reserved
0x06 DATA70 DATA[70]158 DATA[158]
0x08 ADDR70 ADDR[70]158 ADDR[158]
95 Register Description
ATtiny416816NVMCTRL - Non Volatile Memory Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 70
951 Control A
Name CTRLAOffset 0x00Reset 0x00Property Configuration Change Protection
Bit 7 6 5 4 3 2 1 0 CMD[20]
Access RW RW RW Reset 0 0 0
Bits 20 ndash CMD[20] CommandWrite this bit field to issue a command The Configuration Change Protection key for self-programming(SPM) has to be written within four instructions before this writeValue Name Description0x0 - No command0x1 WP Write page buffer to memory (NVMCTRLADDR selects which memory)0x2 ER Erase page (NVMCTRLADDR selects which memory)0x3 ERWP Erase and write page (NVMCTRLADDR selects which memory)0x4 PBC Page buffer clear0x5 CHER Chip erase erase Flash and EEPROM (unless EESAVE in FUSESYSCFG is 1)0x6 EEER EEPROM Erase0x7 WFU Write fuse (only accessible through UPDI)
ATtiny416816NVMCTRL - Non Volatile Memory Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 71
952 Control B
Name CTRLBOffset 0x01Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 BOOTLOCK APCWP
Access RW RW Reset 0 0
Bit 1 ndash BOOTLOCK Boot Section LockWriting a 1 to this bit locks the boot section from read and instruction fetchIf this bit is 1 a read from the boot section will return 0 A fetch from the boot section will also return 0as instructionThis bit can only be written from the boot section It can only be cleared to 0 by a ResetThis bit will only take effect when the boot section is left the first time after the bit is written
Bit 0 ndash APCWP Application Code Section Write ProtectionWriting a 1 to this bit protects the application code section from further writesThis bit can only be written to 1 it is cleared to 0 only by Reset
ATtiny416816NVMCTRL - Non Volatile Memory Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 72
953 Status
Name STATUSOffset 0x02Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 WRERROR EEBUSY FBUSY
Access R R R Reset 0 0 0
Bit 2 ndash WRERROR Write ErrorThis bit will read 1 when a write error has happened A write error could be writing to different sectionsbefore doing a page write or writing to a protected area This bit is valid for the last operation
Bit 1 ndash EEBUSY EEPROM BusyThis bit will read 1 when the EEPROM is busy with a command
Bit 0 ndash FBUSY Flash BusyThis bit will read 1 when the Flash is busy with a command
ATtiny416816NVMCTRL - Non Volatile Memory Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 73
954 Interrupt Control
Name INTCTRLOffset 0x03Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 EEREADY
Access RW Reset 0
Bit 0 ndash EEREADY EEPROM Ready InterruptWriting a 1 to this bit enables the interrupt which indicates that the EEPROM is ready for new writeeraseoperationsThis is a level interrupt that will be triggered only when the EEREADY flag in the INTFLAGS register is setto zero Thus the interrupt should not be enabled before triggering an NVM command as the EEREADYflag will not be set before the NVM command issued The interrupt should be disabled in the interrupthandler
ATtiny416816NVMCTRL - Non Volatile Memory Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 74
955 Interrupt Flags
Name INTFLAGSOffset 0x04Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 EEREADY
Access RW Reset 0
Bit 0 ndash EEREADY EEREADY Interrupt FlagInterrupt flag for the EEPROM interrupt This bit is cleared by writing a 1 to it When this interrupt isenabled it will immediately request an interrupt and it will continue to request interrupts continuously -even if no EEPROM writes are initiated
ATtiny416816NVMCTRL - Non Volatile Memory Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 75
956 Data
Name DATAOffset 0x06Reset 0x00Property -
The NVMCTRLDATAL and NVMCTRLDATAH register pair represents the 16-bit valueNVMCTRLDATA The low byte [70] (suffix L) is accessible at the original offset The high byte [158](suffix H) can be accessed at offset + 0x01 For more details on reading and writing 16-bit registers referto 856 Accessing 16-bit Registers
Bit 15 14 13 12 11 10 9 8 DATA[158]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0 DATA[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 150 ndash DATA[150] Data RegisterThis register is used by the UPDI for fuse write operations
ATtiny416816NVMCTRL - Non Volatile Memory Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 76
957 Address
Name ADDROffset 0x08Reset 0x00Property -
The NVMCTRLADDRL and NVMCTRLADDRH register pair represents the 16-bit valueNVMCTRLADDR The low byte [70] (suffix L) is accessible at the original offset The high byte [158](suffix H) can be accessed at offset + 0x01 For more details on reading and writing 16-bit registers referto 856 Accessing 16-bit Registers
Bit 15 14 13 12 11 10 9 8 ADDR[158]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0 ADDR[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 150 ndash ADDR[150] AddressThe Address register contains the address to the last memory location that has been updated
ATtiny416816NVMCTRL - Non Volatile Memory Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 77
10 CLKCTRL - Clock Controller
101 Featuresbull All clocks and clock sources are automatically enabled when requested by peripheralsbull Internal oscillators
ndash 1620MHz oscillator (OSC20M)ndash 32KHz Ultra Low Power oscillator (OSCULP32K)
bull External clock optionsndash 32768kHz crystal oscillator (XOSC32K)ndash External clock
bull Main clock featuresndash Safe run-time switchingndash Prescaler with 1x to 64x division in 12 different settings
102 OverviewThe Clock Controller peripheral (CLKCTRL) controls distributes and prescales the clock signals from theavailable oscillators The CLKCTRL supports internal and external clock sources
The CLKCTRL is based on an automatic clock request system implemented in all peripherals on thedevice The peripherals will automatically request the clocks needed If multiple clock sources areavailable the request is routed to the correct clock source
The Main Clock (CLK_MAIN) is used by the CPU RAM and the IO bus The Main Clock source can beselected and prescaled Some peripherals can share the same clock source as the Main Clock or runasynchronously to the Main Clock domain
ATtiny416816CLKCTRL - Clock Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 78
1021 Block Diagram - CLKCTRLFigure 10-1 CLKCTRL Block Diagram
CPURAMNVM TCDBODRTC
OSC20Mint Oscillator
WDT
32768kHzext Crystal Osc
DIV32
TOSC2 TOSC1
RTCCLKSEL
CLK_RTCCLK_PER
CLK_MAIN
CLK_WDT CLK_BOD CLK_TCD
TCDCLKCSEL
Main Clock Prescaler
Main Clock Switch
INT
PRESCALER
XOSC32KSEL
CLK_CPU
OtherPeripherals
CLKOUT
OSC20M
XOSC32K
OSCULP32K
32KHz ULPInt Oscillator
EXTCLK
The clock system consists of the Main Clock and other asynchronous clocksbull Main Clock
This clock is used by the CPU RAM Flash the IO bus and all peripherals connected to the IO bus Itis always running in Active and Idle sleep mode and can be running in Standby sleep mode ifrequested
The main clock CLK_MAIN is prescaled and distributed by the Clock Controllerbull CLK_CPU is used by the CPU SRAM and the NVMCTRL peripheral to access the non-volatile
memorybull CLK_PER is used by all peripherals that are not listed under asynchronous clocks
bull Clocks running asynchronously to the Main Clock domainndash CLK_RTC is used by the RTCPIT It will be requested when the RTCPIT is enabled The clock
source for CLK_RTC should only be changed if the peripheral is disabledndash CLK_WDT is used by the WDT It will be requested when the WDT is enabled
ATtiny416816CLKCTRL - Clock Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 79
ndash CLK_BOD is used by the BOD It will be requested when the BOD is enabled in Sampled Modendash CLK_TCD is used by the TCD It will be requested when the TCD is enabled The clock source
can only be changed if the peripheral is disabled
The clock source for the for the Main Clock domain is configured by writing to the Clock Select bits(CLKSEL) in the Main Clock Control A register (CLKCTRLMCLKCTRLA) The asynchronous clocksources are configured by registers in the respective peripheral
1022 Signal Description
Signal Type Description
CLKOUT Digital output CLK_PER output
Related Links5 IO Multiplexing and Considerations
103 Functional Description
1031 Sleep Mode OperationWhen a clock source is not usedrequested it will turn off It is possible to request an clock source directlyby writing a 1 to the Run Standby bit (RUNSTDBY) in the respective oscillators Control A register(CLKCTRL[osc]CTRLA) This will cause the oscillator to run constantly except for Power Down sleepmode Additionally when this bit is written to 1 the oscillator start-up time is eliminated when the clocksource is requested by a peripheral
The Main Clock will always run in Active and Idle sleep mode In Standby sleep mode the Main Clock willonly run if any peripheral is requesting it or the Run in Standby bit (RUNSTDBY) in the respectiveoscillators Control A register (CLKCTRL[osc]CTRLA) is written to 1
In Power Down sleep mode the Main Clock will stop after all NVM operations are completed
1032 Main Clock Selection and PrescalerAll internal oscillators can be used as the Main Clock source for CLK_MAIN The Main Clock source isselectable from software and can be safely changed during normal operation
Built-in hardware protection prevents unsafe clock switching
Upon selection of an external clock source a switch to the chosen clock source will only occur if edgesare detected indicating it is stable Until a sufficient number of clock edges are detected the switch willnot occur and it will not be possible to change to another clock source again without executing a Reset
An ongoing clock source switch is indicated by the System Oscillator Changing flag (SOSC) in the MainClock Status register (CLKCTRLMCLKSTATUS) The stability of the external clock sources is indicatedby the respective status flags (EXTS and XOSC32KS in CLKCTRLMCLKSTATUS)
CAUTION If an external clock source fails while used as CLK_MAIN source only the WDT can provide amechanism to switch back via System Reset
CLK_MAIN is fed into a prescaler before it is used by the peripherals (CLK_PER) in the device Theprescaler divide CLK_MAIN by a factor from 1 to 64
ATtiny416816CLKCTRL - Clock Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 80
Figure 10-2 Main Clock and Prescaler
(Div 1 2 4 8 16 32 64 6 10 24 48)
OSC20M
32kHz Osc
32768kHz crystal Osc
External clock
CLK_MAIN CLK_PERMain Clock Prescaler
The Main Clock and Prescaler configuration registers (CLKCTRLMCLKCTRLACLKCTRLMCLKCTRLB) are protected by the Configuration Change Protection Mechanism employing atimed write procedure for changing these registers
Related Links857 CCP - Configuration Change Protection
1033 Main Clock after Reset
After any Reset CLK_MAIN is provided by the 1620MHz oscillator (OSC20M) and with a Prescalerdivision factor of 6 Since the actual frequency of the OSC20M is determined by the Frequency Selectbits (FREQSEL) of the Oscillator Configuration fuse (FUSEOSCCFG) these frequencies are possibleafter ResetTable 10-1 Peripheral Clock Frequencies after Reset
CLK_MAINas per FREQSEL in FUSEOSCCFG
Resulting CLK_PER
16MHz 266MHz
20MHz 333MHz
See the OSC20M description for further details
Related Links103411 1620MHz Oscillator (OSC20M)
1034 Clock SourcesAll internal clock sources are enabled automatically when they are requested by a peripheral The crystaloscillator based on an external crystal must be enabled by writing a 1 to the ENABLE bit in the 32KHzCrystal Oscillator Control A register (CLKCTRLXOSC32KCTRLA) before it can serve as clock source
The respective Oscillator Status bits in the Main Clock Status register (CLKCTRLMCLKSTATUS) indicatewhether the clock source is running and stable
Related Links69 FUSES - Configuration and User Fuses857 CCP - Configuration Change Protection
10341 Internal OscillatorsThe internal oscillators do not require any external components to run See the related links for accuracyand electrical characteristics
Related Links34 Electrical Characteristics
ATtiny416816CLKCTRL - Clock Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 81
103411 1620MHz Oscillator (OSC20M)This oscillator can operate at multiple frequencies selected by the value of the Frequency Select bits(FREQSEL) in the Oscillator Configuration fuse (FUSEOSCCFG) The center frequencies are
bull 16MHzbull 20MHz
After a System Reset FUSEOSCCFG determines the initial frequency of CLK_MAIN
During Reset the calibration values for the OSC20M are loaded from fuses There are two differentcalibration bit fields The Calibration bit field (CAL20M) in the Calibration A register(CLKCTRLOSC20MCALIBA) enables calibration around the current center frequency The OscillatorTemperature Coefficient Calibration bit field (TEMPCAL20M) in the Calibration B register(CLKCTRLOSC20MCALIBB) enables adjustment of the slope of the temperature drift compensation
For applications requiring more fine-tuned frequency setting than the oscillator calibration providesfactory stored frequency error after calibrations are available
The oscillator calibration can be locked by the Oscillator Lock (OSCLOCK) fuse (FUSEOSCCFG) Whenthis fuse is 1 it is not possible to change the calibration The calibration is also locked if this oscillator isused as Main Clock source and the Lock Enable bit (LOCKEN) in the Control B register(CLKCTRLOSC20MCALIBB) is 1
The calibration bits are also protected by the Configuration Change Protection Mechanism requiring atimed write procedure for changing the Main Clock and Prescaler settings
The start-up time of this oscillator is analog start-up time plus 4 oscillator cycles Refer to ElectricalCharacteristics chapter for the start-up time
When changing oscillator calibration value the frequency may overshoot If the oscillator is used as themain clock (CLK_MAIN) it is recommended to change the main clock prescaler so that the main clockfrequency does not exceed frac14 of the maximum operation main clock frequency as described in theGeneral Operating Ratings The system clock prescaler can be changed back after the oscillatorcalibration value has been updated
Related Links34 Electrical Characteristics69 FUSES - Configuration and User Fuses1035 Configuration Change Protection343 General Operating Ratings1033 Main Clock after Reset1033 Main Clock after Reset3410 Oscillators and Clocks
OSC20M Stored Frequency Error CompensationThis oscillator can operate at multiple frequencies selected by the value of the Frequency Select bits(FREQSEL) in the Oscillator Configuration fuse (FUSEOSCCFG) at Reset As previously mentionedappropriate calibration values are loaded to adjust to center frequency (OSC20M) and temperature driftcompensation (TEMPCAL20M) meeting the specifications defined in the Internal OscillatorCharacteristics For applications requiring wider operating range the relative factory stored frequencyerror after calibrations can be used The 4 errors are measured at different setting and are available inSignature Row as signed byte values
bull SIGROWOSC16ERR3V is the frequency error from 16MHz measured at 3V
ATtiny416816CLKCTRL - Clock Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 82
bull SIGROWOSC16ERR5V is the frequency error from 16MHz measured at 5Vbull SIGROWOSC20ERR3V is the frequency error from 20MHz measured at 3Vbull SIGROWOSC20ERR5V is the frequency error from 20MHz measured at 5V
The Error is stored as a compressed Q110 fixed point 8 bit value in order not to lose resolution wherethe MSB is the sign bit and the 7 LSBs the lower bits of the Q10BAUDact = BAUD+ BAUD 1024The minimum legal BAUD register value is 0x40 the target BAUD register value should therefor not belower than 0x4A to ensure that the compensated BAUD value stays within the legal range even for partswith negative compensation values The example code below demonstrates how to apply this value formore accurate USART baud rate
include ltasserthgt Baud rate compensated with factory stored frequency error Asynchronous communication without Auto-baud (Sync Field) 16MHz Clock 3V and 600 BAUD
int8_t sigrow_val = SIGROWOSC16ERR3V read signed error int32_t baud_reg_val = 600 ideal BAUD register value assert (baud gt= 0x4A) Verify legal min BAUD register value with max neg comp baud_reg_val = (1024 + sigrow_value) sum resolution + error baud_reg_val = 1024 divide by resolution USART0BAUD = (int16_t) baud_reg_val set adjusted baud rate
Related Links3410 Oscillators and Clocks
103412 32KHz Oscillator (OSCULP32K)The 32KHz oscillator is optimized for Ultra Low Power (ULP) operation Power consumption is decreasedat the cost of decreased accuracy compared to an external crystal oscillator
This oscillator also provides the 1KHz signal for the Real Time Counter (RTC) the Watchdog Timer(WDT) and the Brownout Detector (BOD)
The start-up time of this oscillator is the oscillator start-up time plus 4 oscillator cycles Refer to ElectricalCharacteristics chapter for the start-up time
Related Links34 Electrical Characteristics17 BOD - Brownout Detector19 WDT - Watchdog Timer23 RTC - Real Time Counter
10342 External Clock SourcesThese external clock sources are available
bull External clock from pin (EXTCLK)bull The TOSC1 and TOSC2 pins are dedicated to driving a 32768kHz crystal oscillator (XOSC32K)bull Instead of a crystal oscillator TOSC1 can be configured to accept an external clock source
ATtiny416816CLKCTRL - Clock Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 83
103421 32768kHz Crystal Oscillator (XOSC32K)This oscillator supports two input options Either a crystal is connected to the pins TOSC1 and TOSC2 oran external clock running at 32KHz is connected to TOSC1 The input option must be configured bywriting the Source Select bit (SEL) in the XOSC32K Control A register (CLKCTRLXOSC32KCTRLA)
The XOSC32K is enabled by writing a 1 to its ENABLE bit in CLKCTRLXOSC32KCTRLA Whenenabled the configuration of the GPIO pins used by the XOSC32K is overridden as TOSC1 TOSC2 pinsThe Enable bit needs to be set for the oscillator to start running when requested
The start-up time of a given crystal oscillator can be accommodated by writing to the Crystal Start-upTime bits (CSUT) in CLKCTRLXOSC32KCTRLA
When XOSC32K is configured to use an external clock on TOSC1 the start-up time is fixed to 2 cycles
103422 External Clock (EXTCLK)The External Clock is taken directly from the pin This GPIO pin is automatically configured for EXTCLK ifany peripheral is requesting this clock
This clock source has a start-up time of 2 cycles when first requested
1035 Configuration Change ProtectionThis peripheral has registers that are under Configuration Change Protection (CCP) In order to write tothese a certain key must be written to the CPUCCP register first followed by a write access to theprotected bits within four CPU instructions
It is possible to try writing to these registers any time but the values are not altered
The following registers are under CCP
Table 10-2 CLKCTRL - Registers under Configuration Change Protection
Register Key
CLKCTRLMCLKCTRLB IOREG
CLKCTRLMCLKLOCK IOREG
CLKCTRLXOSC32KCTRLA IOREG
CLKCTRLMCLKCTRLA IOREG
CLKCTRLOSC20MCTRLA IOREG
CLKCTRLOSC20MCALIBA IOREG
CLKCTRLOSC20MCALIBB IOREG
CLKCTRLOSC32KCTRLA IOREG
Related Links8571 Sequence for Write Operation to Configuration Change Protected IO Registers
ATtiny416816CLKCTRL - Clock Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 84
104 Register Summary - CLKCTRL
Offset Name Bit Pos
0x00 MCLKCTRLA 70 CLKOUT CLKSEL[10]0x01 MCLKCTRLB 70 PDIV[30] PEN0x02 MCLKLOCK 70 LOCKEN0x03 MCLKSTATUS 70 EXTS XOSC32KS OSC32KS OSC20MS SOSC0x04
0x0F
Reserved
0x10 OSC20MCTRLA 70 RUNSTDBY0x11 OSC20MCALIBA 70 CAL20M[50]0x12 OSC20MCALIBB 70 LOCK TEMPCAL20M[30]0x13
0x17
Reserved
0x18 OSC32KCTRLA 70 RUNSTDBY0x19
0x1B
Reserved
0x1C XOSC32KCTRLA 70 CSUT[10] SEL RUNSTDBY ENABLE
105 Register Description
ATtiny416816CLKCTRL - Clock Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 85
1051 Main Clock Control A
Name MCLKCTRLAOffset 0x00Reset 0x00Property Configuration Change Protection
Bit 7 6 5 4 3 2 1 0 CLKOUT CLKSEL[10]
Access RW R R R R R RW RW Reset 0 0 0 0 0 0 0 0
Bit 7 ndash CLKOUT System Clock OutWhen this bit is written to 1 the system clock is output to CLKOUT pinWhen the device is in a sleep mode there is no clock output unless a peripheral is using the systemclock
Bits 10 ndash CLKSEL[10] Clock SelectThis bit field selects the source for the Main Clock (CLK_MAIN)Value Name Description0x0 OSC20M 1620MHz internal oscillator0x1 OSCULP32K 32KHz internal Ultra Low Power oscillator0x2 XOSC32K 32768kHz external crystal oscillator0x3 EXTCLK External clock
ATtiny416816CLKCTRL - Clock Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 86
1052 Main Clock Control B
Name MCLKCTRLBOffset 0x01Reset 0x11Property Configuration Change Protection
Bit 7 6 5 4 3 2 1 0 PDIV[30] PEN
Access R R R RW RW RW RW RW Reset 0 0 0 1 0 0 0 1
Bits 41 ndash PDIV[30] Prescaler DivisionIf the Prescaler Enable (PEN) bit is written to 1 these bits define the division ratio of the Main ClockprescalerThese bits can be written during run-time to vary the clock frequency of the system to suit the applicationrequirementsUser software must ensure a correct configuration of input frequency (CLK_MAIN) and Prescaler settingssuch that the resulting frequency of CLK_PER never exceeds the allowed maximum (see ElectricalCharacteristics)Value DescriptionValue Division0x0 20x1 40x2 80x3 160x4 320x5 640x8 60x9 100xA 120xB 240xC 48other Reserved
Bit 0 ndash PEN Prescaler EnableThis bit must be written 1 to enable the prescaler When enabled the division ratio is selected by thePDIV bit fieldWhen this bit is written to 0 the Main Clock will pass through undivided (CLK_PER=CLK_MAIN)regardless of the value of PDIV
ATtiny416816CLKCTRL - Clock Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 87
1053 Main Clock Lock
Name MCLKLOCKOffset 0x02Reset 0x00Property Configuration Change Protection
Bit 7 6 5 4 3 2 1 0 LOCKEN
Access R R R R R R R RW Reset 0 0 0 0 0 0 0 x
Bit 0 ndash LOCKEN Lock EnableWriting this bit to 1 will lock the CLKCTRLMCLKCTRLA and CLKCTRLMCLKCTRLB registers and ifapplicable the calibration settings for the current Main Clock source from further software updates Oncelocked the CLKCTRLMCLKLOCK registers cannot be accessed until the next hardware ResetThis provides protection for the CLKCTRLMCLKCTRLA and CLKCTRLMCLKCTRLB registers andcalibration settings for the Main Clock source from unintentional modification by softwareRelated Links69 FUSES - Configuration and User Fuses
ATtiny416816CLKCTRL - Clock Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 88
1054 Main Clock Status
Name MCLKSTATUSOffset 0x03Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 EXTS XOSC32KS OSC32KS OSC20MS SOSC
Access R R R R R R R R Reset 0 0 0 0 0 0 0 0
Bit 7 ndash EXTS External Clock StatusValue Description0 EXTCLK has not started1 EXTCLK has started
Bit 6 ndash XOSC32KS XOSC32K StatusThe status bit will only be available if the source is requested as the main clock or by another module Ifthe oscillators RUNSTDBY bit is set but the oscillator is unusednot requested this bit will be 0Value Description0 XOSC32K is not stable1 XOSC32K is stable
Bit 5 ndash OSC32KS OSCULP32K StatusThe status bit will only be available if the source is requested as the main clock or by another module Ifthe oscillators RUNSTDBY bit is set but the oscillator is unusednot requested this bit will be 0Value Description0 OSCULP32K is not stable1 OSCULP32K is stable
Bit 4 ndash OSC20MS OSC20M StatusThe status bit will only be available if the source is requested as the main clock or by another module Ifthe oscillators RUNSTDBY bit is set but the oscillator is unusednot requested this bit will be 0Value Description0 OSC20M is not stable1 OSC20M is stable
Bit 0 ndash SOSC Main Clock Oscillator ChangingValue Description0 The clock source for CLK_MAIN is not undergoing a switch1 The clock source for CLK_MAIN is undergoing a switch and will change as soon as the new
source is stable
ATtiny416816CLKCTRL - Clock Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 89
1055 1620MHz Oscillator Control A
Name OSC20MCTRLAOffset 0x10Reset 0x00Property Configuration Change Protection
Bit 7 6 5 4 3 2 1 0 RUNSTDBY
Access R R R R R R RW R Reset 0 0 0 0 0 0 0 0
Bit 1 ndash RUNSTDBY Run StandbyThis bit force the oscillator on in all modes even when unused by the system In standby sleep mode thiscan be used to ensure immediate wake-up and not waiting for oscillator start-up timeWhen not requested by peripherals no oscillator output is providedIt takes 4 oscillator cycles to open the clock gate after a request but the oscillator analog start-up time willbe removed when this bit is set
ATtiny416816CLKCTRL - Clock Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 90
1056 1620MHz Oscillator Calibration A
Name OSC20MCALIBAOffset 0x11Reset Based on FREQSEL in FUSEOSCCFGProperty Configuration Change Protection
Bit 7 6 5 4 3 2 1 0 CAL20M[50]
Access RW RW RW RW RW RW Reset x x x x x x
Bits 50 ndash CAL20M[50] CalibrationThese bits change the frequency around the current center frequency of the OSC20M for fine tuningAt Reset factory calibrated values are loaded based on FREQSEL bits in FUSEOSCCFG
ATtiny416816CLKCTRL - Clock Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 91
1057 1620MHz Oscillator Calibration B
Name OSC20MCALIBBOffset 0x12Reset Based on FUSEOSCCFGProperty Configuration Change Protection
Bit 7 6 5 4 3 2 1 0 LOCK TEMPCAL20M[30]
Access R RW RW RW RW Reset x x x x x
Bit 7 ndash LOCK Oscillator Calibration Locked by FuseWhen this bit is set the calibration settings in CLKCTRLOSC20MCALIBA andCLKCTRLOSC20MCALIBB cannot be changedThe Reset value is loaded from the OSCLOCK bit in the Oscillator Configuration fuse (FUSEOSCCFG)
Bits 30 ndash TEMPCAL20M[30] Oscillator Temperature Coefficient CalibrationThese bits tune the slope of the temperature compensationAt Reset factory calibrated values are loaded based on FREQSEL bits in FUSEOSCCFG
ATtiny416816CLKCTRL - Clock Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 92
1058 32KHz Oscillator Control A
Name OSC32KCTRLAOffset 0x18Reset 0x00Property Configuration Change Protection
Bit 7 6 5 4 3 2 1 0 RUNSTDBY
Access R R R R R R RW R Reset 0 0 0 0 0 0 0 0
Bit 1 ndash RUNSTDBY Run StandbyThis bit force the oscillator on in all modes even when unused by the system In standby sleep mode thiscan be used to ensure immediate wake-up and not waiting for oscillator start-up timeWhen not requested by peripherals no oscillator output is providedIt takes 4 oscillator cycles to open the clock gate after a request but the oscillator analog start-up time willbe removed when this bit is set
ATtiny416816CLKCTRL - Clock Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 93
1059 32768kHz Crystal Oscillator Control A
Name XOSC32KCTRLAOffset 0x1CReset 0x00Property Configuration Change Protection
The SEL and CSUT bits cannot be changed as long as the ENABLE bit is set or the XOSC32K Stable bit(XOSC32KS) in CLKCTRLMCLKSTATUS is highTo change settings in a safe way write a 0 to the ENABLE bit and wait until XOSC32KS is 0 before re-enabling the XOSC32K with new settings
Bit 7 6 5 4 3 2 1 0 CSUT[10] SEL RUNSTDBY ENABLE
Access R R RW RW R RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 54 ndash CSUT[10] Crystal Start-Up TimeThese bits select the start-up time for the XOSC32K It is write protected when the oscillator is enabled(ENABLE=1)If SEL=1 the start-up time will not be appliedValue Name Description0x0 1K 1k cycles0x1 16K 16k cycles0x2 32K 32k cycles0x3 64K 64k cycles
Bit 2 ndash SEL Source SelectThis bit select the external source type It is write protected when the oscillator is enabled (ENABLE=1)Value Description0 External crystal1 External clock on TOSC1 pin
Bit 1 ndash RUNSTDBY Run StandbyWriting this bit to 1 starts the crystal oscillator and forces the oscillator on in all modes even whenunused by the system if the ENABLE bit is set In standby sleep mode this can be used to ensureimmediate wake-up and not waiting for oscillator start-up time When this bit is 0 the crystal oscillator isonly running when requested and the ENABLE bit is setThe output of XOSC32K is not sent to other peripherals unless it is requested by one or more peripheralsWhen the RUNSTDBY bit is set there will only be a delay of two to three crystal oscillator cycles after arequest until the oscillator output is received if the initial crystal start-up time already has completedAccording to RUNSTBY bit the oscillator will be turned on all the time if the device is in Active Idle orStandby sleep mode or only be enabled when requestedThis bit is IO protected to prevent unintentional enabling of the oscillator
Bit 0 ndash ENABLE EnableWhen this bit is written to 1 the configuration of the respective input pins is overridden to TOSC1 andTOSC2 Also the Source Select bit (SEL) and Crystal Start-Up Time (CSUT) become read-onlyThis bit is IO protected to prevent unintentional enabling of the oscillator
ATtiny416816CLKCTRL - Clock Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 94
11 SLPCTRL - Sleep Controller
111 Featuresbull Three sleep modes
ndash Idlendash Standbyndash Power Down
bull Configurable Standby sleep mode where peripherals can be configured as on or offbull SleepWalking in Standby sleep mode where the PTC can start running on an Event without waking
up the device
112 OverviewSleep modes are used to shut down peripherals and clock domains in the device in order to save powerThe Sleep Controller (SLPCTRL) controls and handles the transitions between active mode and sleepmode
There are in total four modes available one active mode in which software is executed and three sleepmodes The available sleep modes are Idle Standby and Power Down
When the device enters a sleep mode program execution is stopped and depending on the enteredsleep mode different peripherals and clock domains are turned off
To enter a sleep mode the SLPCTRL must be enabled and the desired sleep mode must be stated Thesoftware decides when to enter that sleep mode by using a dedicated sleep instruction (SLEEP)
Interrupts are used to wake up the device from sleep The available Interrupt wake-up sources depend onthe configured sleep mode When an interrupt occurs the device will wake up and execute the interruptservice routine before continuing normal program execution from the first instruction after the sleepinstruction Any Reset will also take the device out of a sleep mode
1121 Block DiagramFigure 11-1 Sleep Controller in System
SLPCTRL
Sleep instruction
Interrupt request
Peripheral
Interrupt request
Sleep state
CPU
ATtiny416816SLPCTRL - Sleep Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 95
1122 System DependenciesIn order to use this peripheral other parts of the system must be configured correctly as described below
Table 11-1 SLPCTRL System Dependencies
Dependency Applicable Peripheral
Clocks Yes CLKCTRL
IO Lines and Connections No -
Interrupts no -
Events No -
Debug Yes UPDI
11221 ClocksThis peripheral depends on the peripheral clock
Related Links10 CLKCTRL - Clock Controller
11222 IO Lines and ConnectionsNot applicable
11223 InterruptsNot applicable
11224 EventsNot applicable
11225 Debug OperationWhen run-time debugging this peripheral will continue normal operation The SLPCTRL is only affectedby a break in debug operation If the SLPCTRL is in a sleep mode when a break occurs the device willwake up and the SLPCTRL will go to active mode even if there are no pending interrupt requests
If the peripheral is configured to require periodical service by the CPU through interrupts or similarimproper operation or data loss may result during halted debugging
113 Functional Description
1131 InitializationTo put the device into a sleep mode follow these steps
bull Configure and enable the interrupts that should wake up the device from sleep Also enable globalinterrupts
WARNING If there are no interrupts enabled when going to sleep the device cannot wake up againOnly a reset will allow the device to continue operation
bull Select the sleep mode to be entered and enable the Sleep Controller by writing to the Sleep Modebits (SMODE) and the Enable bit (SEN) in the Control A register (SLPCTRLCTRLA) A SLEEPinstruction must be run to make the device actually go to sleep
ATtiny416816SLPCTRL - Sleep Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 96
1132 Operation
11321 Sleep ModesIn addition to Active mode there are three different sleep modes with decreasing power consumptionand functionality
Idle The CPU stops executing code no peripherals are disabledAll interrupt sources can wake up the device
Standby The user can configure peripherals to be enabled or not using the respective RUNSTBY bitThis means that the power consumption is highly dependent on what functionality is enabledand thus may vary between the Idle and Power Down levelsSleepWalking is available for the ADC moduleThe wake-up sources are Pin interrupts TWI address match UART Start-of-Frame interrupt(if USART is enabled to run in Standby) ADC window interrupt (if PTC enabled to run inStandby) RTC interrupt (if RTC enabled to run in Standby) and TCB interrupt
PowerDown
Only the WDT and the PIT (component of the RTC) are activeThe only wake-up sources are the pin change interrupt and TWI address match
Table 11-2 Sleep Mode Activity Overview
Group Peripheral Active in Sleep Mode
Clock Idle Standby Power Down
Active ClockDomain
CPU CLK_CPU
Peripherals CLK_PER X
RTC CLK_RTC X X
ADCPTC CLK_PER X X
PIT (RTC) CLK_RTC X X X
WDT CLK_WDT X X X
Oscillators Main ClockSource
X X
RTC ClockSource
X X
WDT Oscillator X X X
Wake-UpSources
INTn and pin change X X X
TWI address match X X X
Periodic Interrupt Timer X X X
UART start of frame X X
ADCPTC window X X
RTC interrupt X X
All other interrupts X
ATtiny416816SLPCTRL - Sleep Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 97
Note bull X means active X indicates that the RUNSTBY bit of the corresponding peripheral must be set to
enter active statebull PTC is only available in devices with 8KB Flash (ATtiny816)
11322 Wake-Up TimeThe normal wake-up time for the device is 6 Main Clock cycles (CLK_PER) plus the time it takes to startup the Main Clock source
bull In Idle sleep mode the Main Clock source is kept running so it will not be any extra wake-up timebull In Standby sleep mode the Main Clock might be running so it depends on the peripheral
configurationbull In Power Down sleep mode only the ULP 32KHz oscillator and RTC clock may be running if it is
used by the BOD or WDT All other clock sources will be off
Table 11-3 Sleep modes and Start-up time
Sleep mode Start-up time
IDLE 6 CLK
Standby 6 CLK + OSC start-up
Power Down 6 CLK + OSC start-up
The start-up time for the different clock sources is described in the Clock Controller (CLKCTRL) section
In addition to the normal wake-up time it is possible to make the device wait until the BOD is ready beforeexecuting code This is done by writing 0x3 to the BOD Operation Mode in Active and Idle bits (ACTIVE)in the BOD Configuration fuse (FUSEBODCFG) If the BOD is ready before the normal wake-up time thenet wake-up time will be the same If the BOD takes longer than the normal wake-up time the wake-uptime will be extended until the BOD is ready This is ensures correct supply voltage whenever code isexecuted
1133 Configuration Change ProtectionNot applicable
ATtiny416816SLPCTRL - Sleep Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 98
114 Register Summary - SLPCTRL
Offset Name Bit Pos
0x00 CTRLA 70 SMODE[10] SEN
115 Register Description
ATtiny416816SLPCTRL - Sleep Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 99
1151 Control A
Name CTRLAOffset 0x00Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 SMODE[10] SEN
Access R R R R R RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 21 ndash SMODE[10] Sleep ModeWriting these bits selects the sleep mode entered when the Sleep Enable bit (SEN) is written to 1 andthe SLEEP instruction is executedValue Name Description0x0 IDLE Idle sleep mode enabled0x1 STANDBY Standby sleep mode enabled0x2 PDOWN Power Down sleep mode enabledother - Reserved
Bit 0 ndash SEN Sleep EnableThis bit must be written to 1 before the SLEEP instruction is executed to make the MCU enter theselected sleep mode
ATtiny416816SLPCTRL - Sleep Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 100
12 RSTCTRL - Reset Controller
121 Featuresbull Reset the device and set it to an initial statebull Reset Flag register for identifying the Reset source in softwarebull Multiple Reset sources
ndash Power supply Reset sources Brownout Detect (BOD) Power On Reset (POR)ndash User Reset sources External Reset pin (RESET) Watchdog Reset (WDT) Software Reset
(SW) and UPDI Reset
122 OverviewThe Reset Controller (RSTCTRL) manages the Reset of the device It issues a device Reset sets thedevice to its initial state and allows the Reset source to be identified by software
1221 Block DiagramFigure 12-1 Reset System Overview
RESET SOURCES
POR
BOD
WDT
CPU (SW)
RESET
RESET CONTROLLER
UPDI
UPDI
All other Peripherals
TCD pin override settings
(Loaded from fuses)
External ResetFILTER
VDD
Pull-upresistor
1222 Signal Description
Signal Description Type
RESET External Reset (active low) Digital input
ATtiny416816RSTCTRL - Reset Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 101
123 Functional Description
1231 InitializationThe Reset Controller (RSTCTRL) is always enabled but some of the Reset sources must be enabled(either by fuses or by software) before they can request a Reset
After any Reset the Reset source that caused the Reset is found in the Reset Flag register(RSTCTRLRSTFR)
After a Power-On Reset only the POR flag will be set
The flags are kept until they are cleared by writing a 1 to them
After reset from any source all registers that are loaded from fuses are reloaded
1232 Operation
12321 Reset SourcesThere are two kind of sources for Resets
bull Power supply Resets which are caused by changes in the power supply voltage Power-on Reset(POR) and Brownout Detector (BOD)
bull User Resets which are issued by the application by debug operation or by pin changes (SoftwareReset Watchdog Reset UPDI Reset and external Reset pin RESET)
123211 Power-On Reset (POR)A power-on-reset (POR) is generated by an on-chip detection circuit The POR is activated when the VDDrises until it reach the POR treshold voltage The POR is always enabled and will also detect when theVDD falls below the treshold voltage
All logic is reset on POR All fuses are reloaded after the reset is released While POR is active TCD pinoverride functionality is not available
123212 Brown-Out Detector (BOD) Reset SourceThe on-chip Brown-out Detection circuit will monitor the VDD level during operation by comparing it to afixed trigger level The trigger level for the BOD can be selected by fuses If BOD is unused in theapplication it is forced to a configured level in order to ensure safe operation during chip erase
All logic is reset on BOD Reset except the BOD configuration All fuses are reloaded after the Reset isreleased
Related Links17 BOD - Brownout Detector
123213 Software ResetThe software reset makes it possible to issue a system reset from software The reset is generated bywriting a 1 to the Software Reset Enable bit (SWRE) in the Software Reset register (RSTCTRLSWRR)
The reset will take place immediately after the bit is written and the device will be kept in reset until thereset sequence is completed All logic is reset on software reset except UPDI TCD pin override settingsand BOD configuration All fuses are reloaded after the reset is released
123214 External ResetThe External Reset is enabled by fuse (see fuse map)
ATtiny416816RSTCTRL - Reset Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 102
When enabled the External Reset requests a Reset as long as the RESET pin is low The device willstay in Reset until RESET is high again All logic is reset on external reset except UPDI TCD pinoverride settings and BOD configuration All fuses are reloaded after the reset is released
Related Links69 FUSES - Configuration and User Fuses
123215 Watchdog ResetThe watchdog timer (WDT) is a system function for monitoring correct program operation If the WDT isnot reset from software according to the programmed timeout period a watchdog reset will be issuedSee the WDT documentation for further details
All logic is reset on WDT reset except UPDI TCD pin override settings and BOD configuration All fusesare reloaded after the reset is released
Related Links19 WDT - Watchdog Timer
123216 Universal Program Debug Interface (UPDI) ResetThe UPDI contains a separate reset source that is used to reset the device during external programmingand debugging The reset source is accessible only from external debuggers and programmers All logicis reset on UPDI reset except the UPDI itself TCD pin override settings and BOD configuration All fusesare reloaded after the reset is released See UPDI chapter on how to generate a UPDI reset request
Related Links33 UPDI - Unified Program and Debug Interface
12322 Reset time
The reset time can be split in two
The first part is when any of the Reset sources are active This part depends on the input to the Resetsources The external reset is active as long as the RESET pin is low the power-on-reset (POR) andBrownout detector (BOD) is active as long as the supply voltage is below reset source threshold
When all the Reset sources are released an Internal reset initialization of the device is done The time ittake to do the Internal reset initialization is typical 250 micros This time will be increased with the Start Uptime given by the Start Up time fuse setting (SYSCFG1SUT) The Internal reset initialization time will alsoincrease if the CRC source is setup to run (SYSCFG0CRCSRC) The additional Internal reset time willincrease by 500 micros for each KB of memory that is checked
1233 Sleep Mode OperationThe Reset Controller continues to operate in all active and sleep modes
1234 Configuration Change ProtectionThis peripheral has registers that are under Configuration Change Protection (CCP) In order to write tothese a certain key must be written to the CPUCCP register first followed by a write access to theprotected bits within four CPU instructions
It is possible to try writing to these registers any time but the values are not altered
The following registers are under CCP
ATtiny416816RSTCTRL - Reset Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 103
Table 12-1 RSTCTRL - Registers under Configuration Change Protection
Register Key
RSTCTRLSWRR IOREG
Related Links8571 Sequence for Write Operation to Configuration Change Protected IO Registers
ATtiny416816RSTCTRL - Reset Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 104
124 Register Summary - RSTCTRL
Offset Name Bit Pos
0x00 RSTFR 70 UPDIRF SWRF WDRF EXTRF BORF PORF0x01 SWRR 70 SWRE
125 Register Description
ATtiny416816RSTCTRL - Reset Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 105
1251 Reset Flag Register
Name RSTFROffset 0x00Reset 0xXXProperty -
All flags are cleared by writing a 1 to them They are also cleared by a Power-on Reset with theexception of the Power-On Reset Flag (PORF)
Bit 7 6 5 4 3 2 1 0 UPDIRF SWRF WDRF EXTRF BORF PORF
Access R R RW RW RW RW RW RW Reset 0 0 x x x x x x
Bit 5 ndash UPDIRF UPDI Reset FlagThis bit is set if a UPDI Reset occurs
Bit 4 ndash SWRF Software Reset FlagThis bit is set if a Software Reset occurs
Bit 3 ndash WDRF Watchdog Reset FlagThis bit is set if a Watchdog Reset occurs
Bit 2 ndash EXTRF External Reset FlagThis bit is set if an External reset occurs
Bit 1 ndash BORF Brownout Reset FlagThis bit is set if a Brownout Reset occurs
Bit 0 ndash PORF Power-On Reset FlagThis bit is set if a Power-on Reset occursThis flag is only cleared by writing a 1 itAfter a POR only the POR flag is set and all other flags are cleared No other flag can be set before a fullsystem boot is run after the POR
ATtiny416816RSTCTRL - Reset Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 106
1252 Software Reset Register
Name SWRROffset 0x01Reset 0x00Property Configuration Change Protection
Bit 7 6 5 4 3 2 1 0 SWRE
Access R R R R R R R RW Reset 0 0 0 0 0 0 0 0
Bit 0 ndash SWRE Software Reset EnableWhen this bit is written to 1 a software reset will occurThis bit will always read as 0
ATtiny416816RSTCTRL - Reset Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 107
13 CPUINT - CPU Interrupt Controller
131 Featuresbull Short and predictable interrupt response timebull Separate interrupt configuration and vector address for each interruptbull Interrupt prioritizing by level and vector addressbull Two interrupt priority levels 0 (normal) and 1 (high)bull Higher priority for one interruptbull Optional round-robin priority scheme for priority level 0 interruptsbull Non-maskable interrupts (NMI) for critical functionsbull Interrupt vectors optionally placed in the application section or the boot loader sectionbull Selectable compact vector table
132 OverviewAn interrupt request signals a change of state inside a peripheral and can be used to alter programexecution Peripherals can have one or more interrupts and all are individually enabled and configured
When an interrupt is enabled and configured it will generate an interrupt request when the interruptcondition occurs
The CPU Interrupt Controller (CPUINT) handles and prioritizes interrupt requests When an interrupt isenabled and the interrupt condition occurs the CPUINT will receive the interrupt request Based on theinterrupts priority level and the priority level of any ongoing interrupts the interrupt request is eitheracknowledged or kept pending until it has priority When an interrupt request is acknowledged by theCPUINT the program counter is set to point to the interrupt vector The interrupt vector is normally a jumpto the interrupt handler (ie the software routine that handles the interrupt) After returning from theinterrupt handler program execution continues from where it was before the interrupt occurred Oneinstruction is always executed before any pending interrupt is served
The CPUINT Status register (CPUINTSTATUS) contains state information that ensures that the CPUINTreturns to the correct interrupt level when the RETI (interrupt return) instruction is executed at the end ofan interrupt handler Returning from an interrupt will return the CPUINT to the state it had before enteringthe interrupt CPUINTSTATUS is not saved automatically upon an interrupt request
By default all peripherals are priority level 0 It is possible to set one single interrupt vector to the higherpriority level 1 Interrupts are prioritized according to their priority level and their interrupt vector addressPriority level 1 interrupts will interrupt level 0 interrupt handlers Among priority level 0 interrupts thepriority is determined from the interrupt vector address where the lowest interrupt vector address has thehighest interrupt priority
Optionally a round-robin scheduling scheme can be enabled for priority level 0 interrupts This ensuresthat all interrupts are serviced within a certain amount of time
Interrupt generation must be globally enabled by writing a 1 to the Global Interrupt Enable bit (I) in theCPU Status register (CPUSREG) This bit is not cleared when an interrupt is acknowledged
ATtiny416816CPUINT - CPU Interrupt Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 108
1321 Block DiagramFigure 13-1 CPUINT Block Diagram
INT REQ
INT LEVEL
INT ACK
Peripheral 1
Peripheral n
Interrupt Controller
SleepController
CPU
PriorityDecoder
STATUS
CPUSREG
INT REQ
INT REQ
GlobalInterruptEnable
CPU RETICPU INT ACK
CPU INT REQ
Wake-upLVL0PRILVL1VEC
1322 Signal DescriptionNot applicable
1323 System DependenciesIn order to use this peripheral other parts of the system must be configured correctly as described below
Table 13-1 CPUINT System Dependencies
Dependency Applicable Peripheral
Clocks Yes CLKCTRL
IO Lines and Connections No -
Interrupts No -
Events No -
Debug Yes UPDI
Related Links13235 Debug Operation13231 Clocks
13231 ClocksThis peripheral depends on the peripheral clock
Related Links10 CLKCTRL - Clock Controller
13232 IO Lines and ConnectionsNot applicable
13233 InterruptsNot applicable
13234 EventsNot applicable
ATtiny416816CPUINT - CPU Interrupt Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 109
13235 Debug OperationWhen run-time debugging this peripheral will continue normal operation Halting the CPU in debuggingmode will halt normal operation of the peripheral
If the peripheral is configured to require periodical service by the CPU through interrupts or similarimproper operation or data loss may result during halted debugging
Related Links33 UPDI - Unified Program and Debug Interface
133 Functional Description
1331 InitializationAn interrupt must be initialized in the following order
1 Configure the CPUINT if the default configuration is not adequate (optional)ndash Vector handling is configured by writing to the respective bits (IVSEL and CVT) in the Control A
register (CPUINTCTRLA)ndash Vector prioritizing by round-robin is enabled by writing a 1 to the Round-Robin Priority Enable
bit (LVL0RR) in CPUINTCTRLAndash Select the priority level 1 vector by writing its address to the Interrupt Vector (LVL1VEC) in the
Level 1 Priority register (CPUINTLVL1VEC)2 Configure the interrupt conditions within the peripheral and enable the peripherals interrupt3 Enable interrupts globally by writing a 1 to the Global Interrupt Enable bit (I) in the CPU Status
register (CPUSREG)
1332 Operation
13321 Enabling Disabling and ResettingGlobal enabling of interrupts is done by writing a 1 to the Global Interrupt Enable bit (I) in the CPU Statusregister (CPUSREG) To disable interrupts globally write a 0 to the I bit in CPUSREG
The desired interrupt lines must also be enabled in the respective peripheral by writing to the peripheralsInterrupt Control register ([peripheral]INTCTRL)
Interrupt flags are not automatically cleared after the interrupt is executed The respective INTFLAGSregister descriptions provide information on how to clear specific flags
13322 Interrupt Vector LocationsThe table below shows Reset addresses and Interrupt vector placement dependent on the value ofInterrupt Vector Select bit (IVSEL) in the Control A register (CPUINTCTRLA)
If the program never enables an interrupt source the Interrupt Vectors are not used and regular programcode can be placed at these locations
Table 13-2 Reset and Interrupt Vector Placement
IVSEL Reset address Interrupt vectors start address
0 0x0000 Application start address +Interrupt vector offset address
1 0x0000 Interrupt vector offset address
ATtiny416816CPUINT - CPU Interrupt Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 110
13323 Interrupt Response TimeThe minimum interrupt response time for all enabled interrupts is three CPU clock cycles one cycle tofinish the ongoing instruction and two cycles to store the program counter to the stack After the programcounter is pushed on the stack the program vector for the interrupt is executed See also figure belowfirst diagram
The jump to the interrupt handler takes three clock cycles If an interrupt occurs during execution of amulticycle instruction this instruction is completed before the interrupt is served See also figure belowsecond diagram
ATtiny416816CPUINT - CPU Interrupt Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 111
Figure 13-2 Interrupt Execution of a Single Cycle Instruction Multicycle Instruction and fromSleep
Single Cycle Instruction
Multicycle Instruction
Sleep
If an interrupt occurs when the device is in sleep mode the interrupt execution response time isincreased by five clock cycles In addition the response time is increased by the start-up time from theselected sleep mode
A return from an interrupt handling routine takes four to five clock cycles depending on the size of theprogram counter During these clock cycles the program counter is popped from the stack and the stackpointer is incremented See also figure above bottom diagram
ATtiny416816CPUINT - CPU Interrupt Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 112
13324 Interrupt LevelThe interrupt level is default on level 0 (normal) for all interrupt sources It is possible to select oneinterrupt source to level 1 (high) by writing interrupt address to CPUINTLVL1VEC register This sourcewill have higher priority than normal level interrupts
An interrupt request from a level 1 source will interrupt any ongoing interrupt handler from a level 0interrupt When returning from the level 1 interrupt handler the execution of the level 0 interrupt handlerwill continue
13325 Interrupt Priority
133251 NMI - Non-Maskable InterruptsAn NMI will be executed regardless of the setting of the I bit in CPUSREG and it will never change the Ibit No other interrupt can interrupt a NMI handler If more than one NMI is requested at the same timepriority is static according to the interrupt vector address where the lowest address has highest priority
Which interrupts are non-maskable is device-dependent and not subject to configuration Non-maskableinterrupts must be enabled before they can be used Refer to the Interrupt Vector Mapping of the devicefor available NMI lines
Related Links72 Interrupt Vector Mapping
133252 Static PriorityInterrupt vectors (IVEC) are located at fixed addresses For static priority the interrupt vector addressdecides the priority within normal interrupt level where the lowest interrupt vector address has thehighest priority Refer to the Interrupt Vector Mapping of the device for available interrupt lines and theirbase address offset
Figure 13-3 Static Priority
Lowest Priority
Highest PriorityIVEC 0
IVEC x
IVEC x+1
IVEC n
Lowest Address
Highest Address
Related Links72 Interrupt Vector Mapping
133253 Round-Robin SchedulingTo avoid starvation for priority level 0 (LVL0) interrupt requests with static priority ie some interruptsmight never be served the CPUINT offers round-robin scheduling for LVL0 interrupts
ATtiny416816CPUINT - CPU Interrupt Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 113
Round-robin scheduling for LVL0 interrupt requests is enabled by writing a 1 to the Round-Robin PriorityEnable bit (LVL0RR) in the Control A register (CPUINTCTRLA)
When round-robin scheduling is enabled the interrupt vector address for the last acknowledged LVL0interrupt will have the lowest priority the next time one or more LVL0 interrupts are requested asillustrated in the figure below
Figure 13-4 Round-Robin Scheduling
IVEC x last acknowledgeinterrupt
IVEC x+1 last acknowledgeinterrupt
IVEC 0
IVEC x
IVEC x+1
IVEC n
IVEC x+2
IVEC x+1
IVEC x
IVEC 0
IVEC n
Lowest Priority
Highest Priority Lowest Priority
Highest Priority
133254 Compact Vector TableThe Compact Vector Table (CVT) is a feature to allow for writing of compact code
When CVT is enabled by writing a 1 to the CVT bit in the Control A register (CPUINTCTRLA) the vectortable contains these three interrupt vectors
1 The non-maskable interrupts (NMI) at vector address 12 The priority level 1 (LVL1) interrupt at vector address 23 All priority level 0 (LVL0) interrupts share vector address 3
This feature is most suitable for applications using a small number of interrupt generators
1333 EventsNot applicable
1334 Sleep Mode OperationNot applicable
1335 Configuration Change ProtectionThis peripheral has registers that are under Configuration Change Protection (CCP) In order to write tothese a certain key must be written to the CPUCCP register first followed by a write access to theprotected bits within four CPU instructions
It is possible to try writing to these registers any time but the values are not altered
The following registers are under CCP
ATtiny416816CPUINT - CPU Interrupt Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 114
Table 13-3 INTCTRL - Registers under Configuration Change Protection
Register Key
IVSEL in CPUINTCTRLA IOREG
CVT in CPUINTCTRLA IOREG
Related Links8571 Sequence for Write Operation to Configuration Change Protected IO Registers
ATtiny416816CPUINT - CPU Interrupt Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 115
134 Register Summary - CPUINT
Offset Name Bit Pos
0x00 CTRLA 70 IVSEL CVT LVL0RR0x01 STATUS 70 NMIEX LVL1EX LVL0EX0x02 LVL0PRI 70 LVL0PRI[70]0x03 LVL1VEC 70 LVL1VEC[70]
135 Register Description
ATtiny416816CPUINT - CPU Interrupt Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 116
1351 Control A
Name CTRLAOffset 0x00Reset 0x00Property Configuration Change Protection
Bit 7 6 5 4 3 2 1 0 IVSEL CVT LVL0RR
Access RW RW RW Reset 0 0 0
Bit 6 ndash IVSEL Interrupt Vector SelectIf boot section is defined it will be placed before application section The actual start address of theapplication section is determined by the BOOTEND FuseThis bit is protected by the Configuration Change Protection mechanismValue Description0 Interrupt vectors are placed at the start of the application section of the Flash1 Interrupt vectors are placed at the start of the boot section of the Flash
Bit 5 ndash CVT Compact Vector TableThis bit is protected by the Configuration Change Protection mechanismValue Description0 Compact Vector Table function is disabled1 Compact Vector Table function is enabled
Bit 0 ndash LVL0RR Round-Robin Priority EnableThis bit is not protected by the Configuration Change Protection mechanismValue Description0 Priority is fixed for priority level 0 interrupt requests The lowest interrupt vector address has
highest priority1 Round Robin priority scheme is enabled for priority level 0 interrupt requests
ATtiny416816CPUINT - CPU Interrupt Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 117
1352 Status
Name STATUSOffset 0x01Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 NMIEX LVL1EX LVL0EX
Access R R R Reset 0 0 0
Bit 7 ndash NMIEX Non-Maskable Interrupt ExecutingThis flag is set if a non-maskable interrupt is executing The flag is cleared when returning (RETI) fromthe interrupt handler
Bit 1 ndash LVL1EX Level 1 Interrupt ExecutingThis flag is set when a priority level 1 interrupt is executing or when the interrupt handler has beeninterrupted by an NMI The flag is cleared when returning (RETI) from the interrupt handler
Bit 0 ndash LVL0EX Level 0 Interrupt ExecutingThis flag is set when a priority level 0 interrupt is executing or when the interrupt handler has beeninterrupted by a priority level 1 interrupt or an NMI The flag is cleared when returning (RETI) from theinterrupt handler
ATtiny416816CPUINT - CPU Interrupt Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 118
1353 Interrupt Priority Level 0
Name LVL0PRIOffset 0x02Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 LVL0PRI[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash LVL0PRI[70] Interrupt Priority Level 0When Round Robin is enabled (LVL0RR bit in CPUINTCTRLA is 1) this bit field stores the vector of thelast acknowledged priority level 0 (LVL0) interrupt The stored vector will have the lowest priority next timeone or more LVL0 interrupts are pendingIf Round Robin is disabled (LVL0RR in CPUINTCTRLA is 0) the vector address based priority scheme(lowest address has highest priority) is governing the priorities of LVL0 interrupt requestsIf a system Reset is asserted the lowest interrupt vector address will have highest priority within theLVL0
ATtiny416816CPUINT - CPU Interrupt Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 119
1354 Interrupt Vector with Priority Level 1
Name LVL1VECOffset 0x03Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 LVL1VEC[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash LVL1VEC[70] Interrupt Vector with Priority Level 1This bit field contains the address of the single vector with increased priority level 1 (LVL1)If this bit field has the value 0x00 no vector has LVL1 Consequently the LVL1 interrupt is disabled
ATtiny416816CPUINT - CPU Interrupt Controller
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 120
14 EVSYS - Event System
141 Featuresbull System for direct peripheral-to-peripheral signalingbull Peripherals can directly produce use and react to peripheral eventsbull Short and guaranteed response timebull Up to six parallel Event channels available 4 asynchronous- and 2 synchronousbull Channels can be configured to have one triggering peripheral action and multiple peripheral usersbull Peripherals can directly trigger and react to Events from other peripheralsbull Events can be sent andor received by most peripherals and by softwarebull Works in active mode and standby sleep mode
142 OverviewThe Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in other peripherals (the Event Users) through Eventchannels without using the CPU It is designed to provide short and predictable response times betweenperipherals allowing for autonomous peripheral control and interaction and also for synchronized timingof actions in several peripheral modules It is thus a powerful tool for reducing the complexity size andexecution time of the software
A change of the Event Generators state is referred to as an Event and usually corresponds to one of theperipherals interrupt conditions Events can be directly forwarded to other peripherals using thededicated Event routing network The routing of each channel is configured in software including eventgeneration and use
Only one trigger from an Event generator peripheral can be routed on each channel but multiplechannels can use the same generator source Multiple peripherals can use events from the samechannel
A channel path can be either asynchronous or synchronous to the main clock The mode must beselected based on the requirements of the application
The Event System can directly connect analog and digital converters analog comparators IO port pinsthe real-time counter timercounters and the configurable custom logic peripheral Events can also begenerated from software and the peripheral clock
ATtiny416816EVSYS - Event System
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 121
1421 Block DiagramFigure 14-1 Block Diagram
Sync user xSync user 0
Sync event channel rdquokrdquo
Async event channel rdquolrdquo
Sync event channel 0
Async event channel 0
Sync source 0Sync source 1
Sync source n
Async source 0Async source 1
Async source m
SYNCSTROBE
To sync user
To async user
SYNCUSER
Async user 0Async user y
ASYNCUSERASYNCCH
SYNCCH
ASYNCSTROBE
Figure 14-2 Example of Event Source Generator User and Action
|Event
RoutingNetwork Single
Conversion
Channel SweepCompare Match
Over-Underflow
Error
Event Generator Event User
Event Source Event Action
Event Action Selection
TimerCounter ADC
Note 1 For an overview of peripherals supporting Events refer the Block Diagram of the device2 For a list of Event Generators refer to the Channel n Generator Selection registers
(EVSYSSYNCCH and EVSYSASYNCCH)3 For a list of Event Users refer to the User Channel n Input Selection registers
(EVSYSSYNCUSER and EVSYSASYNCUSER)
Related Links
ATtiny416816EVSYS - Event System
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 122
3 Block Diagram1454 SYNCCH1453 ASYNCCH1456 SYNCUSER1455 ASYNCUSER
1422 Signal Description
Internal Event SignalingThe Event signaling can either happen synchronously to the main clock (CLK_MAIN) or asynchronouslyto it
Depending on the underlying event the Event signal can be a pulse with a duration of 1 clock cycle or alevel signal (similar to a status flag)
Event Output to Pin
Signal Type Description
EVOUT[20] Digital output Event output
Related Links14232 IO Lines1021 Block Diagram - CLKCTRL
1423 System DependenciesIn order to use this peripheral other parts of the system must be configured correctly as described below
Table 14-1 EVSYS System Dependencies
Dependency Applicable Peripheral
Clocks Yes CLKCTRL
IO Lines and Connections Yes PORTMUX
Interrupts No -
Events Yes EVSYS
Debug Yes UPDI
Related Links14231 Clocks1435 Debug Operation
14231 ClocksThe EVSYS uses the peripheral clock for IO registers and software events When set up correctly therouting network can be used also in sleep modes without any clock Software Events will not work insleep modes where the peripheral clock is halted
Related Links10 CLKCTRL - Clock Controller
ATtiny416816EVSYS - Event System
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 123
14232 IO LinesThe EVSYS can output three event channels asynchronously on pins The output signals are calledEVOUT[20]
1 Configure which event channel (one of SYNCCH[10] or ASYNCCH[30]) is output on which theEVOUTn by writing to EVSYSASYNCUSER10 EVSYSASYNCUSER9 or EVSYSASYNCUSER8respectively
2 Optional configure the pin properties using the PORT peripheral3 Enable the pin output by writing 1 to the respective EVOUTn bit in the Control A register of the
PORTMUX peripheral (PORTMUXCTRLA)
Related Links15 PORTMUX - Port Multiplexer16 PORT - IO Pin Configuration1455 ASYNCUSER
143 Functional Description
1431 InitializationBefore enabling Events within the device the Event Users Multiplexer and Event Channels must beconfigured
Related Links14321 Event User Multiplexer Setup14322 Event System Channel
1432 Operation
14321 Event User Multiplexer SetupThe Event User multiplexer selects the channel for an Event User Each Event User has one dedicatedEvent User multiplexer Each multiplexer is connected to the supported Event channel outputs and canbe configured to select one of these channels
Event Users which support asynchronous Events also support synchronous Events There are also EventUsers that support only synchronous Events
The Event User multiplexers are configured by writing to the corresponding registersbull Event Users supporting both synchronous and asynchronous Events are configured by writing to the
respective asynchronous User Channel Input Selection n register (EVSYSASYNCUSERn)bull The users of synchronous-only Events are configured by writing to the respective Synchronous User
Channel Input Selection n register (EVSYSSYNCUSERn)
Default setup of all user multiplexers is Off
14322 Event System ChannelAn Event channel can be connected to one of the Event generators Event channels either supportasynchronous generators or synchronous generators
The source for each asynchronous Event channel is configured by writing to the respective AsynchronousChannel n Input Selection register (EVSYSASYNCCHn)
The source for each synchronous Event channel is configured by writing to the respective SynchronousChannel n Input Selection register (EVSYSSYNCCHn)
ATtiny416816EVSYS - Event System
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 124
14323 Event GeneratorsEach Event channel can receive the Events from several Event generators For details on Eventgeneration refer to the documentation of the corresponding peripheral
For each Event channel there are several possible Event generators only one of which can be selectedat a time The Event generator trigger is selected for each channel by writing to the respective channelregisters (EVSYSASYNCCHn EVSYSSYNCCHn) By default the channels are not connected to anyEvent generator
14324 Software EventIn a Software Event the CPU will ldquostroberdquo an Event channel by inverting the current value for one systemclock cycle
A Software Event is triggered on a channel by writing a 1 to the respective Strobe bit in the appropriateChannel Strobe register
bull Software Events on asynchronous channel l are initiated by writing a 1 to the ASYNCSTROBE[l] bitin the Asynchronous Channel Strobe register (EVSYSASYNCSTROBE)
bull Software Events on synchronous channel k are initiated by writing a 1 to the SYNCSTROBE[k] bit inthe Synchronous Channel Strobe register (EVSYSSYNCSTROBE)
Software Events are no different to those produced by Event generator peripherals with respect to Eventusers when the bit is written to 1 an Event will be generated on the respective channel and receivedand processed by the Event User
1433 InterruptsNot applicable
1434 Sleep Mode OperationWhen configured the Event System will work in all sleep modes One exception are software Eventswhich require a system clock
1435 Debug OperationThis peripheral is unaffected by entering debug mode
Related Links33 UPDI - Unified Program and Debug Interface
1436 SynchronizationAsynchronous Events are synchronized and handled by the compatible Event users Event Userperipherals not compatible with asynchronous Events can only be configured to listen to synchronousEvent channels
1437 Configuration Change ProtectionNot applicable
Related Links8571 Sequence for Write Operation to Configuration Change Protected IO Registers
ATtiny416816EVSYS - Event System
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 125
144 Register Summary - EVSYS
Offset Name Bit Pos
0x00 ASYNCSTROBE 70 ASYNCSTROBE[70]0x01 SYNCSTROBE 70 SYNCSTROBE[70]0x02 ASYNCCH0 70 ASYNCCH[70]0x03 ASYNCCH1 70 ASYNCCH[70]0x04 ASYNCCH2 70 ASYNCCH[70]0x05 ASYNCCH3 70 ASYNCCH[70]0x06
0x09
Reserved
0x0A SYNCCH0 70 SYNCCH[70]0x0B SYNCCH1 70 SYNCCH[70]0x0C
0x11
Reserved
0x12 ASYNCUSER0 70 ASYNCUSER[70]
0x1C ASYNCUSER10 70 ASYNCUSER[70]0x1D
0x21
Reserved
0x22 SYNCUSER0 70 SYNCUSER[70]0x23 SYNCUSER1 70 SYNCUSER[70]
145 Register Description
ATtiny416816EVSYS - Event System
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 126
1451 Asynchronous Channel Strobe
Name ASYNCSTROBEOffset 0x00Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 ASYNCSTROBE[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash ASYNCSTROBE[70] Asynchronous Channel StrobeIf the strobe register location is written each Event channel will be inverted for one system clock cycleie a single Event is generated
ATtiny416816EVSYS - Event System
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 127
1452 Synchronous Channel Strobe
Name SYNCSTROBEOffset 0x01Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 SYNCSTROBE[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash SYNCSTROBE[70] Synchronous Channel StrobeIf the strobe register location is written each Event channel will be inverted for one system clock cycleie a single event is generated
ATtiny416816EVSYS - Event System
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 128
1453 Asynchronous Channel n Generator Selection
Name ASYNCCHOffset 0x02 + n0x01 [n=03]Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 ASYNCCH[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash ASYNCCH[70] Asynchronous Channel Generator SelectionTable 14-2 Asynchronous Channel Generator selection
Value ASYNCCH0 ASYNCCH1 ASYNCCH2 ASYNCCH3
0x00 OFF OFF OFF OFF
0x01 CCL_LUT0
0x02 CCL_LUT1
0x03 AC0_OUT
0x04 TCD0_CMPBCLR
0x05 TCD0_CMPASET
0x06 TCD0_CMPBSET
0x07 TCD0_PROGEV
0x08 RTC_OVF
0x09 RTC_CMP
0x0A PORTA_PIN0 PORTB_PIN0 PORTC_PIN0 PIT_DIV8192
0x0B PORTA_PIN1 PORTB_PIN1 PORTC_PIN1 PIT_DIV4096
0x0C PORTA_PIN2 PORTB_PIN2 PORTC_PIN2 PIT_DIV2048
0x0D PORTA_PIN3 PORTB_PIN3 PORTC_PIN3 PIT_DIV1024
0x0E PORTA_PIN4 PORTB_PIN4 PORTC_PIN4 PIT_DIV512
0x0F PORTA_PIN5 PORTB_PIN5 PORTC_PIN5 PIT_DIV256
0x10 PORTA_PIN6 PORTB_PIN6 PIT_DIV128
0x11 PORTA_PIN7 PORTB_PIN7 PIT_DIV64
0x12 UPDI -
Other - - - -
ATtiny416816EVSYS - Event System
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 129
1454 Synchronous Channel n Generator Selection
Name SYNCCHOffset 0x0A + n0x01 [n=01]Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 SYNCCH[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash SYNCCH[70] Synchronous Channel Generator SelectionTable 14-3 Synchronous Channel Generator selection
Value SYNCCH0 SYNCCH1
0x00 OFF
0x01 TCB0
0x02 TCA0_OVF_LUNF
0x03 TCA0_HUNF
0x04 TCA0_CMP0
0x05 TCA0_CMP1
0x06 TCA0_CMP2
0x07 PORTC_PIN0 -
0x08 PORTC_PIN1 PORTB_PIN0
0x09 PORTC_PIN2 PORTB_PIN1
0x0A PORTC_PIN3 PORTB_PIN2
0x0B PORTC_PIN4 PORTB_PIN3
0x0C PORTC_PIN5 PORTB_PIN4
0x0D PORTA_PIN0 PORTB_PIN5
0x0E PORTA_PIN1 PORTB_PIN6
0x0F PORTA_PIN2 PORTB_PIN7
0x10 PORTA_PIN3
0x11 PORTA_PIN4 -
0x12 PORTA_PIN5 -
0x13 PORTA_PIN6 -
0x14 PORTA_PIN7 -
Other - -
ATtiny416816EVSYS - Event System
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 130
1455 Asynchronous User Channel n Input Selection
Name ASYNCUSEROffset 0x12 + n0x01 [n=010]Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 ASYNCUSER[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash ASYNCUSER[70] Asynchronous User Channel SelectionTable 14-4 User Multiplexer Numbers
USERn User Multiplexer Description
n=0 TCB0 TimerCounter B 0
n=1 ADC0 ADC 0
n=2 CCL_LUT0EV0 CCL LUT0 Event 0
n=3 CCL_LUT1EV0 CCL LUT1 Event 0
n=4 CCL_LUT0EV1 CCL LUT0 Event 1
n=5 CCL_LUT1EV1 CCL LUT1 Event 1
n=6 TCD0_EV0 Timer Counter D 0 Event 0
n=7 TCD0_EV1 Timer Counter D 0 Event 1
n=8 EVOUT0 Event OUT 0
n=9 EVOUT1 Event OUT 1
n=10 EVOUT2 Event OUT 2
Value Description0x0 OFF0x1 SYNCCH00x2 SYNCCH10x3 ASYNCCH00x4 ASYNCCH10x5 ASYNCCH20x6 ASYNCCH3
ATtiny416816EVSYS - Event System
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 131
1456 Synchronous User Channel n Input Selection
Name SYNCUSEROffset 0x22 + n0x01 [n=01]Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 SYNCUSER[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash SYNCUSER[70] Synchronous User Channel SelectionTable 14-5 User Multiplexer Numbers
USERn User Multiplexer Description
n=0 TCA0 TimerCounter A
n=1 USART0 USART
Value Name0x0 OFF0x1 SYNCCH00x2 SYNCCH1
ATtiny416816EVSYS - Event System
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 132
15 PORTMUX - Port Multiplexer
151 OverviewThe Port Multiplexer (PORTMUX) can either enable or disable functionality of pins or change betweendefault and alternative pin positions This depends on the actual pin and property and is described indetail in the PORTMUX register map
For available pins and functionalities refer to the Multiplexed Signals table
Related Links5 IO Multiplexing and Considerations
ATtiny416816PORTMUX - Port Multiplexer
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 133
152 Register Summary - PORTMUX
Offset Name Bit Pos
0x00 CTRLA 70 LUT1 LUT0 EVOUT2 EVOUT1 EVOUT00x01 CTRLB 70 TWI0 SPI0 USART00x02 CTRLC 70 TCA05 TCA04 TCA03 TCA02 TCA01 TCA000x03 CTRLD 70 TCB0
153 Register Description
ATtiny416816PORTMUX - Port Multiplexer
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 134
1531 Control A
Name CTRLAOffset 0x00Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 LUT1 LUT0 EVOUT2 EVOUT1 EVOUT0
Access RW RW RW RW RW Reset 0 0 0 0 0
Bit 5 ndash LUT1 CCL LUT 1 outputWrite this bit to 1 to select alternative pin location for CCL LUT 1
Bit 4 ndash LUT0 CCL LUT 0 outputWrite this bit to 1 to select alternative pin location for CCL LUT 0
Bit 2 ndash EVOUT2 Event Output 2Write this bit to 1 to enable event output 2
Bit 1 ndash EVOUT1 Event Output 1Write this bit to 1 to enable event output 1
Bit 0 ndash EVOUT0 Event Output 0Write this bit to 1 to enable event output 0
ATtiny416816PORTMUX - Port Multiplexer
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 135
1532 Control B
Name CTRLBOffset 0x01Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 TWI0 SPI0 USART0
Access RW RW RW Reset 0 0 0
Bit 4 ndash TWI0 TWI 0 communicationWrite this bit to 1 to select alternative communication pins for TWI 0
Bit 2 ndash SPI0 SPI 0 communicationWrite this bit to 1 to select alternative communication pins for SPI 0
Bit 0 ndash USART0 USART 0 communicationWrite this bit to 1 to select alternative communication pins for USART 0
ATtiny416816PORTMUX - Port Multiplexer
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 136
1533 Control C
Name CTRLCOffset 0x02Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 TCA05 TCA04 TCA03 TCA02 TCA01 TCA00
Access RW RW RW RW RW RW Reset 0 0 0 0 0 0
Bit 5 ndash TCA05 TCA0 Waveform output 5Write this bit to 1 to select alternative output pin for TCA0 waveform output 5 in split modeNot applicable when TCA in normal mode
Bit 4 ndash TCA04 TCA0 Waveform output 4Write this bit to 1 to select alternative output pin for TCA0 waveform output 4 in split modeNot applicable when TCA in normal mode
Bit 3 ndash TCA03 TCA0 Waveform output 3Write this bit to 1 to select alternative output pin for TCA0 waveform output 3 in split modeNot applicable when TCA in normal mode
Bit 2 ndash TCA02 TCA0 Waveform output 2Write this bit to 1 to select alternative output pin for TCA0 waveform output 2In Split Mode this bit controls output from low-byte compare channel 2
Bit 1 ndash TCA01 TCA0 Waveform output 1Write this bit to 1 to select alternative output pin for TCA0 waveform output 1In Split Mode this bit controls output from low-byte compare channel 1
Bit 0 ndash TCA00 TCA0 Waveform output 0Write this bit to 1 to select alternative output pin for TCA0 waveform output 0In Split Mode this bit controls output from low-byte compare channel 0
ATtiny416816PORTMUX - Port Multiplexer
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 137
1534 Control D
Name CTRLDOffset 0x03Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 TCB0
Access RW Reset 0
Bit 0 ndash TCB0 TCB0 outputWrite this bit to 1 to select alternative output pin for 16-bit timercounter B 0
ATtiny416816PORTMUX - Port Multiplexer
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 138
16 PORT - IO Pin Configuration
161 Featuresbull General purpose input and output pins with individual configurationbull Output driver with configurable inverted IO and pullupbull Input with interrupts and events
ndash Sense both edgesndash Sense rising edgesndash Sense falling edgesndash Sense low level
bull Asynchronous pin change sensing that can wake the device from all sleep modesbull Efficient and safe access to PORT pins
ndash Hardware read-modify-write through dedicated toggleclearset registersndash Mapping of often-used PORT registers into bit-accessible IO memory space (Virtual Ports)
162 OverviewThe IO pins of the device are controlled by instances of the PORT peripheral registers This device hasthe following instances of the IO Pin Configuration (PORT) PORTA PORTB and PORTC
Refer to the IO Multiplexing table to see which pins are controlled by what instance of PORT The offsetsof the PORT instances and of the corresponding Virtual PORT instances are listed in the Peripherals andArchitecture section
Each of the port pins has a corresponding bit in the Data Direction (PORTDIR) and Data Output Value(PORTOUT) registers to enable that pin as an output and to define the output state For example pinPA3 is controlled by DIR[3] and OUT[3] of the PORTA instance
The Data Input Value (PORTIN) is set as the input value of a PORT pin with resynchronization to theMain Clock To reduce power consumption these input synchronizers are not clocked if the Input SenseConfiguration bit field (ISC) in PORTPINnCTRL is INPUT_DISABLE The value of the pin can always beread whether the pin is configured as input or output
The PORT also supports synchronous and asynchronous input sensing with interrupts for selectable pinchange conditions Asynchronous pin-change sensing means that a pin change can wake the devicefrom all sleep modes including the modes where no clocks are running
All pin functions are configurable individually per pin The pins have hardware read-modify-write (RMW)functionality for safe and correct change of drive value andor pull resistor configuration The direction ofone port pin can be changed without unintentionally changing the direction of any other pin
The PORT pin configuration also controls input and output selection of other device functions
Related Links5 IO Multiplexing and Considerations7 Peripherals and Architecture
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 139
1621 Block DiagramFigure 16-1 PORT Block Diagram
DQ
R
DQ
R
Synchronizer
D Q
R
DIRn
OUTn
INn
Pxn
D Q
R
Input Disable
Digital Input Asynchronous event
Invert Enable
Pullup enable
Input Disable Override
OUT Override
DIR Override
Analog inputoutput
Synchronized input
1622 Signal Description
Signal Type Description
EXTINT Digital input External interrupt - available on all IO pins
Related Links5 IO Multiplexing and Considerations
1623 System DependenciesIn order to use this peripheral other parts of the system must be configured correctly as described below
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 140
Table 16-1 PORT System Dependencies
Dependency Applicable Peripheral
Clocks Yes CLKCTRL
IO Lines and Connections No -
Interrupts Yes CPUINT
Events Yes EVSYS
Debug No -
Related Links16234 Events16231 Clocks16233 Interrupts
16231 ClocksThis peripheral depends on the peripheral clock
16232 IO Lines and ConnectionsNot applicable
16233 InterruptsUsing the interrupts of this peripheral requires the Interrupt Controller to be configured first
Related Links13 CPUINT - CPU Interrupt Controller1633 Interrupts873 SREG
16234 EventsThe events of this peripheral are connected to the Event System
Related Links14 EVSYS - Event System
16235 Debug OperationThis peripheral is unaffected by entering debug mode
163 Functional Description
1631 InitializationAfter Reset all standard function device IO pads are connected to the PORT with outputs tri-stated andinput buffers enabled even if there is no clock running
For best power consumption disable the input of unused pins and pins that are used as analog inputs oroutputs
Specific pins such as those used for connecting a debugger may be configured differently as requiredby their special function
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 141
1632 Operation
16321 Basic FunctionsEach IO pin Pxn can be controlled by the registers in PORT x Each pin group x has its own set of PORTregisters the base address of the register set for pin n is at the byte address PORT + 0x10 + Theindex within that register set is n
To use pin number n as an output only write bit n of the PORTDIR register to 1 This can also be doneby writing bit n in the PORTDIRSET register to 1 - this will avoid disturbing the configuration of otherpins in that group The nth bit in the PORTOUT register must be written to the desired output value
Similarly writing a PORTOUTSET bit to 1 will set the corresponding bit in the PORTOUT register to 1Writing a bit in PORTOUTCLR to 1 will clear that bit in PORTOUT to zero Writing a bit inPORTOUTTGL or PORTIN to 1 will toggle that bit in PORTOUT
To use pin n as an input bit n in the PORTDIR register must be written to 0 to disable the output driverThis can also be done by writing bit n in the PORTDIRCLR register to 1 - this will avoid disturbing theconfiguration of other pins in that group The input value can be read from bit n in register PORTIN aslong as the ISC bit is not set to INPUT_DISABLE
Writing a bit to 1 in PORTDIRTGL will toggle that bit in PORTDIR and toggle the direction of thecorresponding pin
16322 Virtual PortsThe Virtual Port registers map the most frequently used regular Port registers into the bit-accessible IOspace Writing to the Virtual Port registers has the same effect as writing to the regular registers butallows for memory-specific instructions such as bit-manipulation instructions which are not valid for theextended IO memory space where the regular Port registers resideTable 16-2 Virtual Port Mapping
Regular Port Register Mapped to Virtual Port Register
PORTDIR VPORTDIR
PORTOUT VPORTOUT
PORTIN VPORTIN
PORTINTFLAG VPORTINTFLAG
Related Links166 Register Summary - VPORT5 IO Multiplexing and Considerations7 Peripherals and Architecture
16323 Pin ConfigurationThe Pin n Configuration register (PORTPINnCTRL) is used to configure inverted IO pullup and inputsensing of a pin
All input and output on the respective pin n can be inverted by writing a 1 to the Inverted IO Enable bit(INVEN) in PORTPINnCTRL
Toggling the INVEN bit causes an edge on the pin which can be detected by all peripherals using thispin and is seen by interrupts or Events if enabled
Pullup of pin n is enabled by writing a 1 to the Pullup Enable bit (PULLUPEN) in PORTPINnCTRL
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 142
Changes of the signal on a pin can trigger an interrupt The exact conditions are defined by writing to theInputSense bit field (ISC) in PORTPINnCTRL
When setting or changing interrupt settings take these points into accountbull If an INVEN bit is toggled in the same cycle as the interrupt setting the edge caused by the inversion
toggling may not cause an interrupt requestbull If an input is disabled while synchronizing an interrupt that interrupt may be requested on re-
enabling the input even if it is re-enabled with a different interrupt settingbull If the interrupt setting is changed while synchronizing an interrupt that interrupt may not be
acceptedbull Only few pins support full asynchronous interrupt detection see IO Multiplexing and Considerations
These limitations apply for waking the system from sleep
Interrupt Type Fully Asynchronous Pins Other Pins
BOTHEDGES will wake system will wake system
RISING will wake system will not wake system
FALLING will wake system will not wake system
LEVEL will wake system will wake system
Related Links5 IO Multiplexing and Considerations
1633 InterruptsTable 16-3 Available Interrupt Vectors and Sources
Offset Name Vector Description Conditions
0x00 PORTx PORT A B C interrupt INTn in PORTINTFLAGS is raised as configured by ISC bit inPORTPINnCTRL
Each PORT pin n can be configured as an interrupt source Each interrupt can be individually enabled ordisabled by writing to ISC in PORTPINCTRL
When an interrupt condition occurs the corresponding Interrupt Flag is set in the Interrupt Flags registerof the peripheral (peripheralINTFLAGS)
An interrupt request is generated when the corresponding interrupt is enabled and the Interrupt Flag isset The interrupt request remains active until the Interrupt Flag is cleared See the peripheralsINTFLAGS register for details on how to clear Interrupt Flags
Asynchronous Sensing Pin PropertiesTable 16-4 Behavior Comparison of FullyPartly Asynchronous Sense Pin
Property Synchronous or Partly Asynchronous SenseSupport
Full Asynchronous SenseSupport
Minimum pulse widthto trigger interrupt
Minimum one system clock cycle Less than a system clockcycle
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 143
continuedProperty Synchronous or Partly Asynchronous Sense
SupportFull Asynchronous SenseSupport
Waking the devicefrom sleep
From all interrupt sense configurations from sleepmodes with Main Clock running Only fromBOTHEDGES or LEVEL interrupt senseconfiguration from sleep modes with Main Clockstopped
From all interrupt senseconfigurations from all sleepmodes
Interrupt dead time No new interrupt for three cycles after theprevious
No limitation
Minimum Wakeuppulse length
Value on pad must be kept until the system clockhas restarted
No limitation
Related Links8 AVR CPU873 SREG
1634 Sleep Mode OperationWith the exception of interrupts and input synchronization all pin configurations are independent of sleepmode Peripherals connected to the Ports can be affected by sleep modes described in the respectiveperipherals documentation
The PORT peripheral will always use the Main Clock Input synchronization will halt when this clockstops
1635 SynchronizationNot applicable
1636 Configuration Change ProtectionNot applicable
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 144
164 Register Summary - PORT
Offset Name Bit Pos
0x00 DIR 70 DIR[70]0x01 DIRSET 70 DIRSET[70]0x02 DIRCLR 70 DIRCLR[70]0x03 DIRTGL 70 DIRTGL[70]0x04 OUT 70 OUT[70]0x05 OUTSET 70 OUTSET[70]0x06 OUTCLR 70 OUTCLR[70]0x07 OUTTGL 70 OUTTGL[70]0x08 IN 70 IN[70]0x09 INTFLAGS 70 INT[70]0x0A
0x0F
Reserved
0x10 PIN0CTRL 70 INVEN PULLUPEN ISC[20]0x11 PIN1CTRL 70 INVEN PULLUPEN ISC[20]0x12 PIN2CTRL 70 INVEN PULLUPEN ISC[20]0x13 PIN3CTRL 70 INVEN PULLUPEN ISC[20]0x14 PIN4CTRL 70 INVEN PULLUPEN ISC[20]0x15 PIN5CTRL 70 INVEN PULLUPEN ISC[20]0x16 PIN6CTRL 70 INVEN PULLUPEN ISC[20]0x17 PIN7CTRL 70 INVEN PULLUPEN ISC[20]
165 Register Description - Ports
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 145
1651 Data Direction
Name DIROffset 0x00Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 DIR[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash DIR[70] Data DirectionThis bit field selects the data direction for the individual pins n of the PortWriting a 1 to PORTDIR[n] configures and enables pin n as output pinWriting a 0 to PORTDIR[n] configures pin n as input pin It can be configured by writing to the ISC bit inPORTPINnCTRL
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 146
1652 Data Direction Set
Name DIRSETOffset 0x01Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 DIRSET[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash DIRSET[70] Data Direction SetThis bit field can be used instead of a read-modify-write to set individual pins as outputWriting a 1 to DIRSET[n] will set the corresponding PORTDIR[n] bitReading this bit field will always return the value of PORTDIR
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 147
1653 Data Direction Clear
Name DIRCLROffset 0x02Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 DIRCLR[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash DIRCLR[70] Data Direction ClearThis register can be used instead of a read-modify-write to configure individual pins as inputWriting a 1 to DIRCLR[n] will clear the corresponding bit in PORTDIRReading this bit field will always return the value of PORTDIR
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 148
1654 Data Direction Toggle
Name DIRTGLOffset 0x03Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 DIRTGL[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash DIRTGL[70] Data Direction ToggleThis bit field can be used instead of a read-modify-write to toggle the direction of individual pinsWriting a 1 to DIRTGL[n] will toggle the corresponding bit in PORTDIRReading this bit field will always return the value of PORTDIR
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 149
1655 Output Value
Name OUTOffset 0x04Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 OUT[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash OUT[70] Output ValueThis bit field defines the data output value for the individual pins n of the portIf OUT[n] is written to 1 pin n is driven highIf OUT[n] is written to 0 pin n is driven lowIn order to have any effect the pin direction must be configured as output
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 150
1656 Output Value Set
Name OUTSETOffset 0x05Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 OUTSET[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash OUTSET[70] Output Value SetThis bit field can be used instead of a read-modify-write to set the output value of individual pins to 1Writing a 1 to OUTSET[n] will set the corresponding bit in PORTOUTReading this bit field will always return the value of PORTOUT
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 151
1657 Output Value Clear
Name OUTCLROffset 0x06Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 OUTCLR[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash OUTCLR[70] Output Value ClearThis register can be used instead of a read-modify-write to clear the output value of individual pins to 0Writing a 1 to OUTCLR[n] will clear the corresponding bit in PORTOUTReading this bit field will always return the value of PORTOUT
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 152
1658 Output Value Toggle
Name OUTTGLOffset 0x07Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 OUTTGL[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash OUTTGL[70] Output Value ToggleThis register can be used instead of a read-modify-write to toggle the output value of individual pinsWriting a 1 to OUTTGL[n] will toggle the corresponding bit in PORTOUTReading this bit field will always return the value of PORTOUT
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 153
1659 Input Value
Name INOffset 0x08Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 IN[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash IN[70] Input ValueThis register shows the value present on the pins if the digital input driver is enabled IN[n] shows thevalue of pin n of the Port The input is not sampled and cannot be read if the digital input buffers aredisabledWriting to a bit of PORTIN will toggle the corresponding bit in PORTOUT
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 154
16510 Interrupt Flags
Name INTFLAGSOffset 0x09Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 INT[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash INT[70] Interrupt Pin FlagThe INT Flag is set when a pin changestate matches the pins input sense configurationWriting a 1 to a flags bit location will clear the flagFor enabling and executing the interrupt refer to ISC bit description in PORTPINnCTRL
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 155
16511 Pin n Control
Name PINCTRLOffset 0x10 + n0x01 [n=07]Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 INVEN PULLUPEN ISC[20]
Access RW RW RW RW RW Reset 0 0 0 0 0
Bit 7 ndash INVEN Inverted IO EnableValue Description0 IO on pin n not inverted1 IO on pin n inverted
Bit 3 ndash PULLUPEN Pullup EnableValue Description0 Pullup disabled for pin n1 Pullup enabled for pin n
Bits 20 ndash ISC[20] InputSense ConfigurationThese bits configure the input and sense configuration of pin n The sense configuration determines howa port interrupt can be triggered If the input buffer is disabled the input cannot be read in the IN registerValue Name Description0x0 INTDISABLE Interrupt disabled but input buffer enabled0x1 BOTHEDGES Sense both edges0x2 RISING Sense rising edge0x3 FALLING Sense falling edge0x4 INPUT_DISABLE Digital input buffer disabled0x5 LEVEL Sense low levelother - Reserved
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 156
166 Register Summary - VPORT
Offset Name Bit Pos
0x00 DIR 70 DIR[70]0x01 OUT 70 OUT[70]0x02 IN 70 IN[70]0x03 INTFLAGS 70 INT[70]
167 Register Description - Virtual Ports
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 157
1671 Data Direction
Name DIROffset 0x00Reset 0x00Property -
Writing to the Virtual Port registers has the same effect as writing to the regular registers but allows formemory-specific instructions such as bit-manipulation instructions which are not valid for the extendedIO memory space where the regular Port registers reside
Bit 7 6 5 4 3 2 1 0 DIR[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash DIR[70] Data DirectionThis bit field selects the data direction for the individual pins in the Port
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 158
1672 Output Value
Name OUTOffset 0x01Reset 0x00Property -
Writing to the Virtual Port registers has the same effect as writing to the regular registers but allows formemory-specific instructions such as bit-manipulation instructions which are not valid for the extendedIO memory space where the regular Port registers reside
Bit 7 6 5 4 3 2 1 0 OUT[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash OUT[70] Output ValueThis bit field selects the data output value for the individual pins in the Port
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 159
1673 Input Value
Name INOffset 0x02Reset 0x00Property -
Writing to the Virtual Port registers has the same effect as writing to the regular registers but allows formemory-specific instructions such as bit-manipulation instructions which are not valid for the extendedIO memory space where the regular Port registers reside
Bit 7 6 5 4 3 2 1 0 IN[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash IN[70] Input ValueThis bit field holds the value present on the pins if the digital input buffer is enabledWriting to a bit of VPORTIN will toggle the corresponding bit in VPORTOUT
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 160
1674 Interrupt Flag
Name INTFLAGSOffset 0x03Reset 0x00Property -
Writing to the Virtual Port registers has the same effect as writing to the regular registers but allows formemory-specific instructions such as bit-manipulation instructions which are not valid for the extendedIO memory space where the regular Port registers residew
Bit 7 6 5 4 3 2 1 0 INT[70]
Access R R R R R R R R Reset 0 0 0 0 0 0 0 0
Bits 70 ndash INT[70] Interrupt Pin FlagThe INT flag is set when a pin changestate matches the pins input sense configuration and the pin isconfigured as source for port interruptWriting a 1 to this flags bit location will clear the flagFor enabling and executing the interrupt refer to PORT_PINnCTRLISC
ATtiny416816PORT - IO Pin Configuration
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 161
17 BOD - Brownout Detector
171 Featuresbull Brownout detection - monitors the power supply to avoid operation below a programmable levelbull Three modes
ndash Enabledndash Sampledndash Disabled
bull Separate selection of mode for Active mode and sleep modesbull Voltage level monitor (VLM) with interruptbull Programmable VLM level relative to the BOD level
172 OverviewThe Brownout Detector (BOD) monitors the power supply and compares the voltage with twoprogrammable brownout threshold levels the brownout threshold level defines when to generate a ResetA voltage level monitor (VLM) monitors the power supply and compares it to a threshold higher than theBOD threshold The VLM can then generate an interrupt request as an early warning when the supplyvoltage is about to drop below the VLM threshold The VLM threshold level is expressed in percentageabove the BOD threshold level
The BOD is mainly controlled by fuses The mode used in Standby sleep mode and Power Down sleepmode can be altered in normal program execution The VLM part of the BOD is controlled by IO registersas well
When activated The BOD can operate in Enabled mode where the BOD is continuously active and inSampled mode where the BOD is activated briefly at a given period to check the supply voltage level
ATtiny416816BOD - Brownout Detector
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 162
1721 Block DiagramFigure 17-1 BOD Block Diagram
+
-
+
-
Bandgap
Bandgap
BOD level and
calibration
VLM interrupt level
Brownout detection
VDD
VLM interruptdetection
1722 System DependenciesIn order to use this peripheral other parts of the system must be configured correctly as described below
Table 17-1 BOD System Dependencies
Dependency Applicable Peripheral
Clocks Yes CLKCTRL
IO Lines and Connections No -
Interrupts Yes CPUINT
Events Yes EVSYS
Debug Yes UPDI
Related Links17221 Clocks17225 Debug Operation17223 Interrupts17224 Events
17221 ClocksThe BOD uses the 32KHz oscillator (OSCULP32K) as clock source for CLK_BOD
ATtiny416816BOD - Brownout Detector
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 163
17222 IO Lines and ConnectionsNot applicable
17223 InterruptsUsing the interrupts of this peripheral requires the Interrupt Controller to be configured first
Related Links13 CPUINT - CPU Interrupt Controller873 SREG1732 Interrupts
17224 EventsNot applicable
17225 Debug OperationThis peripheral is unaffected by entering debug mode
The VLM interrupt will not be executed if the CPU is halted in debug mode
If the peripheral is configured to require periodical service by the CPU through interrupts or similarimproper operation or data loss may result during halted debugging
173 Functional Description
1731 InitializationThe BOD settings are loaded from fuses during reset The BOD level and operating mode in Active andIdle sleep mode are set by fuses and cannot be changed by the CPU The operating mode in Standbyand Power Down sleep mode is loaded from fuses and can be changed by software
The Voltage Level Monitor function can be enabled by writing a 1 to the VLM Interrupt Enable bit(VLMIE) in the Interrupt Control register (BODINTCTRL) The VLM interrupt is configured by writing theVLM Configuration bits (VLMCFG) in BODINTCTRL An interrupt is requested when the supply voltagecrosses the VLM threshold either from above from below or from any direction
The VLM functionality will follow the BOD mode If the BOD is turned off the VLM will not be enabledeven if the VLMIE is 1 If the BOD is using sampled mode the VLM will also be sampled When enablingVLM interrupt the interrupt flag will always be set if VLMCFG equals 0x2 and may be set if VLMCFG isconfigured to 0x0 or 0x1
The VLM threshold is defined by writing the VLM Level bits (VLMLVL) in the Control A register(BODVLMCTRLA)
If the BODVLM is enabled in sampled mode only VLMCFG=0x1 (crossing threshold from above) inBODINTCTRL will trigger an interrupt
1732 InterruptsTable 17-2 Available Interrupt Vectors and Sources
Offset Name Vector Description Conditions
0x00 VLM Voltage Level Monitor Supply voltage crossing the VLM threshold as configured byVLMCFG in BODINTCTRL
ATtiny416816BOD - Brownout Detector
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 164
When an interrupt condition occurs the corresponding Interrupt Flag is set in the Interrupt Flags registerof the peripheral (peripheralINTFLAGS)
An interrupt source is enabled or disabled by writing to the corresponding enable bit in the peripheralsInterrupt Control register (peripheralINTCTRL)
An interrupt request is generated when the corresponding interrupt source is enabled and the InterruptFlag is set The interrupt request remains active until the Interrupt Flag is cleared See the peripheralsINTFLAGS register for details on how to clear Interrupt Flags
Related Links8 AVR CPU873 SREG
1733 Sleep Mode OperationThere are two separate fuses defining the BOD configuration in different sleep modes One fuse definesthe mode used in Active mode and Idle sleep mode (ACTIVE in FUSEBODCFG) and is written to theACTIVE bits in the Control A register (BODCTRLA) The second fuse (SLEEP in FUSEBODCFG)selects the mode used in Standby sleep mode and Power Down sleep mode and is loaded into theSLEEP bits in the Control A register (BODCTRLA)
The operating mode in Active mode and Idle sleep mode (ie ACTIVE in BODCTRLA) cannot be alteredby software The operating mode in Standby sleep mode and Power Down sleep mode can be altered bywriting to the SLEEP bits in the Control A register (BODCTRLA)
When the device is going into Standby sleep mode or Power Down sleep mode the BOD will changeoperation mode as defined by SLEEP in BODCTRLA When the device is waking up from Standby orPower Down sleep mode the BOD will operate in the mode defined by the ACTIVE bit field inBODCTRLA
1734 SynchronizationNot applicable
1735 Configuration Change ProtectionThis peripheral has registers that are under Configuration Change Protection (CCP) In order to write tothese a certain key must be written to the CPUCCP register first followed by a write access to theprotected bits within four CPU instructions
It is possible to try writing to these registers any time but the values are not altered
The following registers are under CCP
Table 17-3 Registers under Configuration Change Protection
Register Key
SLEEP in BODCTRLA IOREG
Related Links8571 Sequence for Write Operation to Configuration Change Protected IO Registers
ATtiny416816BOD - Brownout Detector
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 165
174 Register Summary - BOD
Offset Name Bit Pos
0x00 CTRLA 70 SAMPFREQ ACTIVE[10] SLEEP[10]0x01 CTRLB 70 LVL[20]0x02
0x07
Reserved
0x08 VLMCTRLA 70 VLMLVL[10]0x09 INTCTRL 70 VLMCFG[10] VLMIE0x0A INTFLAGS 70 VLMIF0x0B STATUS 70 VLMS
175 Register Description
ATtiny416816BOD - Brownout Detector
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 166
1751 Control A
Name CTRLAOffset 0x00Reset Loaded from fuseProperty Configuration Change Protection
Bit 7 6 5 4 3 2 1 0 SAMPFREQ ACTIVE[10] SLEEP[10]
Access R R R R R R RW RW Reset 0 0 0 x x x x x
Bit 4 ndash SAMPFREQ Sample FrequencyThis bit selects the BOD sample frequencyThe Reset value is loaded from the SAMPFREQ bit in FUSEBODCFGThis bit is under ConfigurationChange Protection (CCP)Value Description0x0 Sample frequency is 1kHz0x1 Sample frequency is 125Hz
Bits 32 ndash ACTIVE[10] ActiveThese bits selects the BOD operation mode when the device is in active or idle modeThe Reset value is loaded from the ACTIVE bits in FUSEBODCFGThese bits are not underConfiguration Change Protection (CCP)Value Description0x0 Disabled0x1 Enabled0x2 Sampled0x3 Enabled with wake-up halted until BOD is ready
Bits 10 ndash SLEEP[10] SleepThese bits select the BOD operation mode when the device is in standby or power-down sleep modeThese bits are under Configuration Change Protection (CCP)The Reset value is loaded from the SLEEP bits in FUSEBODCFGValue Description0x0 Disabled0x1 Enabled0x2 Sampled0x3 Reserved
ATtiny416816BOD - Brownout Detector
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 167
1752 Control B
Name CTRLBOffset 0x01Reset Loaded from fuseProperty -
Bit 7 6 5 4 3 2 1 0 LVL[20]
Access R R R R R R R R Reset 0 0 0 0 0 x x x
Bits 20 ndash LVL[20] BOD LevelThese bits select the BOD threshold levelThe Reset value is loaded from the BOD Level bits (LVL) in the BOD Configuration Fuse(FUSEBODCFG)Value Name Description0x0 BODLEVEL0 18V0x2 BODLEVEL2 26V0x7 BODLEVEL7 42V
Note bull Values in the description are typical valuesbull Refer to the BOD and POR Characteristics in Electrical Characteristics for maximum and minimum
values
ATtiny416816BOD - Brownout Detector
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 168
1753 VLM Control A
Name VLMCTRLAOffset 0x08Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 VLMLVL[10]
Access R R R R R R RW RW Reset 0 0 0 0 0 0 0 0
Bits 10 ndash VLMLVL[10] VLM LevelThese bit select the Voltage Level Monitor threshold relative to the BOD threshold (LVL in BODCTRLB)Value Description0x0 VLM threshold 5 above BOD threshold0x1 VLM threshold 15 above BOD threshold0x2 VLM threshold 25 above BOD thresholdother Reserved
ATtiny416816BOD - Brownout Detector
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 169
1754 Interrupt Control
Name INTCTRLOffset 0x09Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 VLMCFG[10] VLMIE
Access R R R R R RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 21 ndash VLMCFG[10] VLM ConfigurationThese bits select which incidents will trigger a VLM interruptValue Description0x0 Voltage crosses VLM threshold from above0x1 Voltage crosses VLM threshold from below0x2 Either direction is triggering an interrupt requestOther Reserved
Bit 0 ndash VLMIE VLM Interrupt EnableWriting a 1 to this bit enables the Voltage Level Monitor (VLM) interrupt
ATtiny416816BOD - Brownout Detector
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 170
1755 VLM Interrupt Flags
Name INTFLAGSOffset 0x0AReset 0x00Property -
Bit 7 6 5 4 3 2 1 0 VLMIF
Access R R R R R R R RW Reset 0 0 0 0 0 0 0 0
Bit 0 ndash VLMIF VLM Interrupt FlagThis flag is set when a trigger from the VLM is given as configured by the VLMCFG bit in theBODINTCTRL register The flag is only updated when the BOD is enabled
ATtiny416816BOD - Brownout Detector
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 171
1756 VLM Status
Name STATUSOffset 0x0BReset 0x00Property -
Bit 7 6 5 4 3 2 1 0 VLMS
Access R R R R R R R R Reset 0 0 0 0 0 0 0 0
Bit 0 ndash VLMS VLM StatusThis bit is only valid when the bod is enabledValue Description0 The voltage is above the VLM threshold level1 The voltage is below the VLM threshold level
ATtiny416816BOD - Brownout Detector
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 172
18 VREF - Voltage Reference
181 Featuresbull programmable voltage reference sources
ndash One for each ADC peripheralndash One for each AC and DAC peripheral
bull Each reference source supports five different voltagesndash 055Vndash 11Vndash 15Vndash 25Vndash 43V
182 OverviewThe Voltage Reference peripheral (VREF) provides control registers for the voltage reference sourcesused by several peripherals The user can select the reference voltages for the ADC0 by writing to theADC0 Reference Select bit field (ADC0REFSEL) in the Control A register (VREFCTRLA) and for bothAC0 and DAC0 by writing to the DAC0 and AC0 Reference Select bit field DAC0REFSEL inVREFCTRLA
A voltage reference source is enabled automatically when requested by a peripheral The user canenable the reference voltage sources (and thus override the automatic disabling of unused sources) bywriting to the respective Force Enable bit (ADC0REFEN DAC0REFEN) in the Control B register(VREFCTRLB) This may be desirable to decrease start-up time at the cost of increased powerconsumption
1821 Block DiagramFigure 18-1 Block Diagram VREF
Reference se lect
Bandgap ReferenceGenerator
InternalReferenceBUF
11V15V25V43V
055V
Reference enable
Reference request
Bandgapenable
183 Functional Description
ATtiny416816VREF - Voltage Reference
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 173
1831 InitializationThe default configuration will enable the respective source when the ADC0 AC0 or DAC0 is requesting areference voltage The default reference voltages are 055V but can be configured by writing to therespective Reference Select bit field (ADC0REFSEL DAC0REFSEL) in the Control A register(VREFCTRLA)
ATtiny416816VREF - Voltage Reference
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 174
184 Register Summary - VREF
Offset Name Bit Pos
0x00 CTRLA 70 ADC0REFSEL[20] DAC0REFSEL[20]0x01 CTRLB 70 ADC0REFEN DAC0REFEN
185 Register Description
ATtiny416816VREF - Voltage Reference
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 175
1851 Control A
Name CTRLAOffset 0x00Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 ADC0REFSEL[20] DAC0REFSEL[20]
Access RW RW RW RW RW RW Reset 0 0 0 0 0 0
Bits 64 ndash ADC0REFSEL[20] ADC0 Reference SelectThese bits select the reference voltage for the ADC0Value Description0x0 055V0x1 11V0x2 25V0x3 43V0x4 15Vother Reserved
Bits 20 ndash DAC0REFSEL[20] DAC0 and AC0 Reference SelectThese bits select reference voltage for the DAC0 and AC0Value Description0x0 055V0x1 11V0x2 25V0x3 43V0x4 15Vother Reserved
ATtiny416816VREF - Voltage Reference
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 176
1852 Control B
Name CTRLBOffset 0x01Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 ADC0REFEN DAC0REFEN
Access RW RW Reset 0 0
Bit 1 ndash ADC0REFEN ADC0 Reference Force EnableWriting a 1 to this bit forces the voltage reference for the ADC0 to be running even if it not requestedWriting a 0 to this bit allows to automatic enabledisable of the reference source by the peripheral
Bit 0 ndash DAC0REFEN DAC0 and AC0 Reference Force EnableWriting a 1 to this bit forces the voltage reference for the DAC0 and AC0 to be running even if it notrequestedWriting a 0 to this bit allows to automatic enabledisable of the reference source by the peripheral
ATtiny416816VREF - Voltage Reference
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 177
19 WDT - Watchdog Timer
191 Featuresbull Issues a System Reset if the Watchdog Timer is not cleared before its timeout periodbull Operating asynchronously from system clock using an independent oscillatorbull Using the 1KHz output of the 32KHz Ultra Low Power oscillator (OSCULP32K)bull 11 selectable timeout periods from 8ms to 8sbull Two operation modes
ndash Normal Modendash Window Mode
bull Configuration lock to prevent unwanted changesbull Closed period timer activation after first WDT instruction for easy setup
192 OverviewThe Watchdog Timer (WDT) is a system function for monitoring correct program operation It allows torecover from situations such as runaway or deadlocked code by issuing a Reset When enabled theWDT is a constantly running timer configured to a predefined timeout period If the WDT is not resetwithin the timeout period it will issue a System Reset The WDT is reset by executing the WDR (WatchdogTimer Reset) instruction from software
The WDT has two modes of operation Normal mode and Window mode The settings in the Control Aregister (WDTCTRLA) determine the mode of operation
A window mode allows to define a time slot or window inside the timeout period during which the WDTmust be reset If the WDT is reset outside this window either too early or too late a System Reset will beissued Compared to the normal mode the window mode can also catch situations where a code errorcauses constant WDR execution
When enabled the WDT will run in active mode and all sleep modes It is asynchronous ie running froma CPU-independent clock source For this reason it will continue to operate and be able to issue aSystem Reset even if the main clock fails
The Configuration Change Protection mechanism ensures that the WDT settings cannot be changed byaccident For increased safety a configuration for locking the WDT settings is also available
Related Links857 CCP - Configuration Change Protection
ATtiny416816WDT - Watchdog Timer
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 178
1921 Block DiagramFigure 19-1 WDT Block Diagram
COUNT
=
=
Inside closed window
Enable open window and clear count
CLK_WDT
WDR(instruction)
SystemReset
CTRLA
CTRLA
WINDOW
PERIOD
1922 Signal DescriptionNot applicable
1923 System DependenciesIn order to use this peripheral other parts of the system must be configured correctly as described below
Table 19-1 WDT System Dependencies
Dependency Applicable Peripheral
Clocks Yes CLKCTRL
IO Lines and Connections No -
Interrupts No -
Events No -
Debug Yes UPDI
Related Links19231 Clocks19235 Debug Operation
19231 ClocksA 1KHz oscillator clock (CLK_WDT_OSC) is sourced from the internal ultra-low-power oscillatorOSCULP32K Due to the ultra-low-power design the oscillator is not very accurate and so the exacttime-out period may vary from device to device This variation must be kept in mind when designingsoftware that uses the WDT to ensure that the time-out periods used are valid for all devices
The counter clock CLK_WDT_OSC is asynchronous to the system clock Due to this asynchronicitywriting to WDT control register will require synchronization between the clock domains
Related Links34 Electrical Characteristics
ATtiny416816WDT - Watchdog Timer
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 179
19232 IO Lines and ConnectionsNot applicable
19233 InterruptsNot applicable
19234 EventsNot applicable
19235 Debug OperationWhen run-time debugging this peripheral will continue normal operation Halting the CPU in debuggingmode will halt normal operation of the peripheral
When halting the CPU in debug mode the WDT counter is reset
when starting the CPU again and the WDT was operating in window mode the first closed windowtimeout period will be disabled and a normal mode timeout period is executed
Related Links19322 Window Mode
193 Functional Description
1931 Initializationbull The WDT is enabled when a non-zero value is written to the Period bits (PERIOD) in the Control A
register (WDTCTRLA)bull Optional Write a non-zero value to the Window bits (WINDOW) in WDTCTRLA to enable window
mode operation
All bits in the Control A register and the Lock bit (LOCK) in the Status register (WDTSTATUS) are writeprotected by the Configuration Change Protection mechanism
The Reset value of WDTCTRLA is defined by a fuse (FUSEWDTCFG) so the WDT can be enabled atboot time If this is the case the LOCK bit in WDTSTATUS is set at boot time
Related Links194 Register Summary - WDT
1932 Operation
19321 Normal ModeIn normal mode operation a single timeout period is set for the WDT If the WDT is not reset fromsoftware using the WDR any time before the timeout occurs the WDT will issue a System Reset
A new WDT timeout period will be started each time the WDT is reset by WDR
There are 11 possible WDT timeout periods (TOWDT) selectable from 8ms to 8s by writing to the Periodbit field (PERIOD) in the Control A register (WDTCTRLA)
ATtiny416816WDT - Watchdog Timer
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 180
Figure 19-2 Normal Mode Operation
t [ms]
WDT Count
5 10 15 20 25 30 35
Timely WDT Reset (WDR)
TOWDT
WDT TimeoutSystem Reset
TO WDT = 16msHere
Normal mode is enabled as long as the WINDOW bit field in the Control A register (WDTCTRLA) is 0x0
Related Links194 Register Summary - WDT
19322 Window ModeIn window mode operation the WDT uses two different timeout periods a closed window timeout period(TOWDTW) and the normal timeout period (TOWDT)
The closed window timeout period defines a duration from 8ms to 8s where the WDT cannot be reset Ifthe WDT is reset during this period the WDT will issue a System Reset
The normal WDT timeout period which is also 8ms to 8s defines the duration of the open period duringwhich the WDT can (and should) be reset The open period will always follow the closed period so thetotal duration of the timeout period is the sum of the closed window and the open window timeout periods
When enabling window mode or when going out of debug mode the first closed period is activated afterthe first WDR instruction
If a second WDR is issued while a previous WDR is being synchronized the second one will be ignored
Figure 19-3 Window Mode Operation
t [ms]
WDT Count
5 10 15 20 25 30 35
Timely WDT Reset (WDR)
Clo
sed
TOWDTW
Ope
n
TOWDT
System ResetWDR too early
TOWDTW =TOWDT = 8msHere
The window mode is enabled by writing a non-zero value to the WINDOW bit field in the Control Aregister (WDTCTRLA) and disabled by writing WINDOW=0x0
ATtiny416816WDT - Watchdog Timer
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 181
19323 Configuration Protection and LockThe WDT provides two security mechanisms to avoid unintentional changes to the WDT settings
The first mechanism is the Configuration Change Protection mechanism employing a timed writeprocedure for changing the WDT control registers
The second mechanism locks the configuration by writing a 1 to the LOCK bit in the Status register(WDTSTATUS) When this bit is 1 the Control A register (WDTCTRLA) cannot be changedConsequently the WDT cannot be disabled from software
LOCK in WDTSTATUS can only be written to 1 It can only be cleared in debug mode
If the WDT configuration is loaded from fuses LOCK is automatically set in WDTSTATUS
Related Links857 CCP - Configuration Change Protection
1933 EventsNot applicable
1934 InterruptsNot applicable
1935 Sleep Mode OperationThe WDT will continue to operate in any sleep mode where the source clock is active
1936 SynchronizationDue to asynchronicity between the main clock domain and the peripheral clock domain the Control Aregister (WDTCTRLA) is synchronized when written The Synchronization Busy flag (SYNCBUSY) in theStatus register (WDTSTATUS) indicates if there is an ongoing synchronization
Writing to WDTCTRLA while SYNCBUSY=1 is not allowed
The following registers are synchronized when writtenbull PERIOD bits in Control A register (WDTCTRLA)bull Window Period bits (WINDOW) in WDTCTRLA
The WDR instruction will need 2 to 3 cycles of the WDT clock in order to be synchronized Issuing a newWDR instruction while a WDR instruction is being synchronized will be ignored
1937 Configuration Change ProtectionThis peripheral has registers that are under Configuration Change Protection (CCP) In order to write tothese a certain key must be written to the CPUCCP register first followed by a write access to theprotected bits within four CPU instructions
It is possible to try writing to these registers any time but the values are not altered
The following registers are under CCP
Table 19-2 WDT - Registers under Configuration Change Protection
Register Key
WDTCTRLA IOREG
LOCK bit in WDTSTATUS IOREG
ATtiny416816WDT - Watchdog Timer
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 182
List of bitsregisters protected by CCP
bull Period bits in Control A register (CTRLAPERIOD)bull Window Period bits in Control A register (CTRLAWINDOW)bull Lock bit in Status register (STATUSLOCK)
Related Links857 CCP - Configuration Change Protection8571 Sequence for Write Operation to Configuration Change Protected IO Registers871 CCP
ATtiny416816WDT - Watchdog Timer
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 183
194 Register Summary - WDT
Offset Name Bit Pos
0x00 CTRLA 70 WINDOW[30] PERIOD[30]0x01 STATUS 70 LOCK SYNCBUSY
195 Register Description
ATtiny416816WDT - Watchdog Timer
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 184
1951 Control A
Name CTRLAOffset 0x00Reset From FUSEWDTCFGProperty Configuration Change Protection
Bit 7 6 5 4 3 2 1 0 WINDOW[30] PERIOD[30]
Access RW RW RW RW RW RW RW RW Reset x x x x x x x x
Bits 74 ndash WINDOW[30] WindowWriting a non-zero value to these bits enables the window mode and selects the according duration ofthe closed periodThe bits are optionally lock protected
bull If LOCK bit in WDTSTATUS is 1 all bits are change protected (Access = R)bull If LOCK bit in WDTSTATUS is 0 all bits can be changed (Access = RW)
Value Name Description0x0 OFF -0x1 8CLK 0008s0x2 16CLK 0016s0x3 32CLK 0032s0x4 64CLK 0064s0x5 128CLK 0128s0x6 256CLK 0256s0x7 512CLK 0512s0x8 1KCLK 1024s0x9 2KCLK 2048s0xA 4KCLK 4096s0xB 8KCLK 8192sother - Reserved
Bits 30 ndash PERIOD[30] PeriodWriting a non-zero value to this bit enables the WDT and selects the according timeout period in normalmode In window mode these bits select the duration of the open windowThe bits are optionally lock protected
bull If LOCK in WDTSTATUS is 1 all bits are change protected (Access = R)bull If LOCK in WDTSTATUS is 0 all bits can be changed (Access = RW)
Value Name Description0x0 OFF -0x1 8CLK 0008s0x2 16CLK 0016s0x3 32CLK 0032s0x4 64CLK 0064s0x5 128CLK 0128s
ATtiny416816WDT - Watchdog Timer
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 185
Value Name Description0x6 256CLK 0256s0x7 512CLK 0512s0x8 1KCLK 10s0x9 2KCLK 20s0xA 4KCLK 41s0xB 8KCLK 82sother - Reserved
ATtiny416816WDT - Watchdog Timer
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 186
1952 Status
Name STATUSOffset 0x01Reset 0x00Property Configuration Change Protection
Bit 7 6 5 4 3 2 1 0 LOCK SYNCBUSY
Access RW R Reset 0 0
Bit 7 ndash LOCK LockWriting this bit to 1 write protects the WDTCTRLA registerIt is only possible to write this bit to 1 This bit can only be cleared in debugIf the PERIOD bits in WDTCTRLA are different from zero after boot code Lock will automatically be setThis bit is under Configuration Change Protection (CCP)
Bit 0 ndash SYNCBUSY Synchronization BusyThis bit is set after writing to the WDTCTRLA register while the data is being synchronized from thesystem clock domain to the WDT clock domainThis bit is cleared by system after the synchronization is finishedThis bit is not under Configuration Change Protection (CCP)Related Links1936 Synchronization1937 Configuration Change Protection
ATtiny416816WDT - Watchdog Timer
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 187
20 TCA - 16-bit TimerCounter Type A
201 Featuresbull 16-bit timercounterbull Three compare channelsbull Double buffered timer period settingbull Double buffered compare channelsbull Waveform generation
ndash Frequency generationndash Single-slope PWM (pulse width modulation)ndash Dual-slope PWM
bull Count on eventbull Timer overflow interruptseventsbull One compare match per compare channelbull Two 8-bit timercounters in Split Mode
202 OverviewThe flexible 16-bit PWM TimerCounter type A (TCA) provides accurate program execution timingfrequency and waveform generation and command execution
A TCA consists of a base counter and a set of compare channels The base counter can be used to countclock cycles or events or let events control how it counts clock cycles It has direction control and periodsetting that can be used for timing The compare channels can be used together with the base counter todo compare match control frequency generation and pulse width waveform modulation
Depending on the mode of operation the counter is cleared reloaded incremented or decremented ateach timercounter clock or event input
A timercounter can be clocked and timed from the peripheral clock with optional prescaling or from theevent system The event system can also be used for direction control or to synchronize operations
By default the TCA is a 16-bit timercounter The timerCounter has a Split mode feature that splits it intotwo 8-bit timercounters with three compare channels each
A block diagram of the 16-bit timercounter with closely related peripheral modules (in grey) is shownbelow
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 188
Figure 20-1 16-bit Timercounter and Closely Related Peripherals
CounterControl Logic
Timer Period
TimerCounterBase Counter Prescaler
EventSystem
CLK_PER
POR
TS
Comparator
Buffer
Compare Channel 2Compare Channel 1
Compare Channel 0
WaveformGeneration
This device provides one instance of the TCA peripheral TCA0
2021 Block DiagramThe below figure shows a detailed block diagram of the timercounter
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 189
Figure 20-2 TimerCounter Block DiagramBase Counter
Compare(Unit x = ABC)
Counter
=
CMPn
CMPnBUF
WaveformGeneration
BV
=
PERB
PER
CNT
BV
= 0
countclear
directionload
Control Logic
EVCTRL
CTRLA
OVFUNF(INT Req)
TOP
match CMPn(INT Req)
Control Logic
Clock Select
ev
UPD
ATE
BOTTOM
WOn Out
EventSelect
The counter register (CNT) period registers with buffer (PER and PERBUF) and compare registers withbuffers (CMPx and CMPBUFx) are 16-bit registers All buffer registers have a buffer valid (BV) flag thatindicates when the buffer contains a new value
During normal operation the counter value is continuously compared to zero and the period (PER) valueto determine whether the counter has reached TOP or BOTTOM
The counter value is also compared to the CMPx registers These comparisons can be used to generateinterrupt requests The waveform generator modes use these comparisons to set the waveform period orpulse width
A prescaled peripheral clock and events from the event system can be used to control the counter
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 190
Figure 20-3 TimerCounter Clock Logic
CKSEL
CNTEI
CLK_PER
event
Event SystemPrescaler
CNT
(Encoding)EVACTCLK_TCA
2022 Signal Description
Signal Description(1) Type
WO[20] Digital output Waveform output
WO[53] Digital output Waveform output - Split mode only
Note 1 Refer to the IO Multiplexing and Considerations section to see the availability of WOn on pins
2023 System DependenciesIn order to use this peripheral other parts of the system must be configured correctly as described below
Table 20-1 TCA System Dependencies
Dependency Applicable Peripheral
Clocks Yes CLKCTRL
IO Lines and Connections Yes WO[50]
Interrupts Yes CPUINT
Events Yes EVSYS
Debug Yes UPDI
Related Links20231 Clocks20235 Debug Operation20233 Interrupts20234 Events
20231 ClocksThis peripheral uses the system clock CLK_PER and has its own prescaler
Related Links10 CLKCTRL - Clock Controller
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 191
20232 IO Lines and ConnectionsUsing the IO lines of the peripheral requires configuration of the IO pins
Related Links5 IO Multiplexing and Considerations16 PORT - IO Pin Configuration
20233 InterruptsUsing the interrupts of this peripheral requires the Interrupt Controller to be configured first
Related Links13 CPUINT - CPU Interrupt Controller873 SREG2035 Interrupts
20234 EventsThe events of this peripheral are connected to the Event System
Related Links14 EVSYS - Event System
20235 Debug OperationWhen run-time debugging this peripheral will continue normal operation Halting the CPU in debuggingmode will halt normal operation of the peripheral
This peripheral can be forced to operate with halted CPU by writing a 1 to the Debug Run bit (DBGRUN)in the Debug Control register of the peripheral (peripheralDBGCTRL)
Related Links33 UPDI - Unified Program and Debug Interface
203 Functional Description
2031 DefinitionsThe following definitions are used throughout the documentation
Table 20-2 TimerCounter Definitions
Name Description
BOTTOM The counter reaches BOTTOM when it becomes zero
MAX The counter reaches MAXimum when it becomes all ones
TOP The counter reaches TOP when it becomes equal to the highest value in the countsequence
UPDATE The update condition is met when the timercounter reaches BOTTOM or TOP depending onthe waveform generator mode
CNT Counter register value
CMP Compare register value
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 192
In general the term ldquotimerrdquo is used when the timercounter is counting periodic clock ticks The termldquocounterrdquo is used when the input signal has sporadic or irregular ticks
2032 InitializationTo start using the timercounter in a basic mode follow these steps
bull Write a TOP value to the Period register (TCAPER)bull Enable the peripheral by writing a 1 to the ENABLE bit in the Control A register (TCACTRLA)
The counter will start counting clock ticks according to the prescaler setting in the Clock Select bitfield (CLKSEL) in TCACTRLA
bull Optional By writing a 1 to the Enable Count on Event Input bit (CNTEI) in the Event Control register(TCAEVCTRL) Event inputs are counted instead of clock ticks
bull The counter value can be read from the Counter bit field (CNT) in the Counter register (TCACNT)
2033 Operation
20331 Normal OperationIn normal operation the counter is counting clock ticks in the direction selected by the Direction bit (DIR)in the Control E register (TCACTRLE) until it reaches TOP or BOTTOM The clock ticks are from theperipheral clock CLK_PER optionally prescaled depending on the Clock Select bit field (CLKSEL) in theControl A register (TCACTRLA)
When up-counting and TOP is reached the counter will wrap to zero at the next clock tick When down-counting the counter is reloaded with the Period register value (TCAPER) when BOTTOM is reached
Figure 20-4 Normal OperationCNT written
update
CNT
DIR
MAX
TOP
BOTTOM
It is possible to change the Counter value in the Counter register (TCACNT) when the counter is runningThe write access to TCACNT has higher priority than count clear or reload and will be immediate Thedirection of the counter can also be changed during normal operation by writing to DIR in TCACTRLE
20332 Double BufferingThe Period register value (TCAPER) and the Compare n register values (TCACMPn) are all doublebuffered (TCAPERBUF and TCACMPnBUF)
Each buffer register has a Buffer Valid flag (PERBV CMPnBV) in the Control F register (TCACTRLF)which indicates that the buffer register contains a valid ie new value that can be copied into thecorresponding Period or Compare register When the Period register and Compare n registers are usedfor a Compare operation the BV flag is set when data is written to the buffer register and cleared on anUPDATE condition This is shown for a Compare register in below
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 193
Figure 20-5 Period and Compare Double Buffering
UPDATE
write enable data write
CNT
match
EN
EN
CMPnBUF
CMPn
BV
=
Both the TCACMPn and TCACMPnBUF registers are available as IO registers This allows initializationand bypassing of the buffer register and the double buffering function
20333 Changing the PeriodThe Counter period is changed by writing a new TOP value to the Period register (TCAPER)
No Buffering If double buffering is not used any period update is immediate
Figure 20-6 Changing the Period without Buffering
CNT
MAX
BOTTOM
Counter wraparound
update
write
New TOP written toPER that is higherthan current CNT
New TOP written toPER that is lowerthan current CNT
A counter wraparound can occur in any mode of operation when up-counting without buffering This isdue to the fact that the registers TCACNT and TCAPER are continuously compared if a new TOP valueis written to TCAPER that is lower than current TCACNT the counter will wrap first before a comparematch happenedFigure 20-7 Unbuffered Dual-slope Operation
Counter wraparound
update
write
MAX
BOTTOM
CNT
New TOP written toPER that is higherthan current CNT
New TOP written toPER that is lowerthan current CNT
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 194
With Buffering When double buffering is used the buffer can be written at any time and still maintaincorrect operation The TCAPER is always updated on the UPDATE condition as shown for dual-slopeoperation in the figure below This prevents wraparound and the generation of odd waveformsFigure 20-8 Changing the Period Using Buffering
CNT
BOTTOM
MAX
update
write
New Period written toPERB that is higherthan current CNT
New Period written toPERB that is lowerthan current CNT
New PER is updatedwith PERB value
20334 Compare ChannelEach Compare Channel n continuously compares the counter value (TCACNT) with the Compare nregister (TCACMPn) If TCACNT equals TCACMPn the comparator n signals a match The match willset the Compare Channels interrupt flag at the next timer clock cycle and the optional interrupt isgenerated
The Compare n Buffer register (TCACMPnBUF) provides double buffer capability equivalent to that forthe period buffer The double buffering synchronizes the update of the TCACMPn register with the buffervalue to either the TOP or BOTTOM of the counting sequence according to the UPDATE condition Thesynchronization prevents the occurrence of odd-length non-symmetrical pulses for glitch-free output
203341 Waveform GenerationThe compare channels can be used for waveform generation on the corresponding port pins To makethe waveform visible on the connected port pin the following requirements must be fulfilled
1 A waveform generation mode must be selected by writing the WGMODE bit field in TCACTRLB2 The TCA is counting clock tick not Events (CNTEI=0 in TCAEVCTRL)3 The compare channels used must be enabled (CMPnEN=1 in TCACTRLB) This will override the
corresponding PORT pin output register An alternative pin can be selected by writing to therespective TCA Waveform Output n bit (TCA0n) in the Control C register of the Port Multiplexer(PORTMUXCTRLC)
4 The direction for the associated Port pin n must be configured as output (PORTDIR[n]=1)5 Optional Enable inverted waveform output for the associated Port pin n (INVEN=1 in PORTPINn)
203342 Frequency (FRQ) Waveform GenerationFor frequency generation the period time (T) is controlled by a TCACMPn register instead of the Periodregister (TCAPER) The waveform generation output WG is toggled on each compare match betweenthe TCACNT and TCACMPn registers
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 195
Figure 20-9 Frequency Waveform Generation
CNT
WG Output
MAX
TOP
BOTTOM
Period (T) Direction change CNT written
update
The waveform frequency (fFRQ) is defined by the following equationFRQ = fCLK_PER2 CMPn+1where N represents the prescaler divider used (CLKSEL in TCACTRLA) and fCLK_PER is the systemclock for the peripherals
The maximum frequency of the waveform generated is half of the peripheral clock frequency (fCLK_PER2)when TCACMPn is written to zero (0x0000) and no prescaling is used (N=1 CLKSEL=0x0 inTCACTRLA)
203343 Single-Slope PWM GenerationFor single-slope Pulse Width Modulation (PWM) generation the period (T) is controlled by TCAPERwhile the values of TCACMPn control the duty cycle of the WG output The figure below shows how thecounter counts from BOTTOM to TOP and then restarts from BOTTOM The waveform generator (WO)output is set at TOP and cleared on the compare match between the TCACNT and TCACMPn registers
Figure 20-10 Single-Slope Pulse Width Modulation
CNT
Output WOn
MAXTOP
CMPn
BOTTOM
Period (T) CMPn=BOTTOM CMPn=TOP updatematch
The TCAPER register defines the PWM resolution The minimum resolution is 2 bits(TCAPER=0x0003) and the maximum resolution is 16 bits (TCAPER=MAX)
The following equation calculates the exact resolution for single-slope PWM (RPWM_SS)PWM_SS = log PER+1log 2The single-slope PWM frequency (fPWM_SS) depends on the period setting (TCA_PER) the systemsperipheral clock frequency fCLK_PER the TCA prescaler (CLKSEL in TCACTRLA) It is calculated by thefollowing equation
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 196
PWM_SS = CLK_PER PER+1where N represents the prescaler divider used
203344 Dual-slope PWMFor dual-slope PWM generation the period (T) is controlled by TCAPER while the values of TCACMPncontrol the duty cycle of the WG output
The figure below shows how for dual-slope PWM the counter counts repeatedly from BOTTOM to TOPand then from TOP to BOTTOM The waveform generator output is set on BOTTOM cleared on comparematch when up-counting and set on compare match when down-counting
Figure 20-11 Dual-slope Pulse Width Modulation
MAX
TOP
BOTTOM
CNT
Waveform Output WOn
Period (T) CMPn=BOTTOM CMPn=TOP updatematch
CMPn
Using dual-slope PWM results in a lower maximum operation frequency compared to the single-slopePWM operation
The period register (TCAPER) defines the PWM resolution The minimum resolution is 2 bits(TCAPER=0x0003) and the maximum resolution is 16 bits (TCAPER=MAX)
The following equation calculate the exact resolution for dual-slope PWM (RPWM_DS)PWM_DS = log PER+1log 2The PWM frequency depends on the period setting (TCAPER) the peripheral clock frequency (fCLK_PER)and the prescaler divider used (CLKSEL in TCACTRLA) It is calculated by the following equationPWM_DS = CLK_PER2 sdot PERN represents the prescaler divider used
203345 Port Override for Waveform GenerationTo make the waveform generation available on the Port pins the corresponding Port pin direction mustbe set as output (PORTDIR[n]=1) The TCA will override the port pin values when the compare channelis enabled (CMPnEN=1 in TCACTRLB) and a waveform generation mode is selected
The figure below shows the port override for TCA The timercounter compare channel will override theport pin output value (OUT) on the corresponding port pin Enabling inverted IO on the port pin(INVEN=1 in PORTPINn) inverts the corresponding WG output
Figure 20-12 Port Override for TimerCounter Type A
Waveform
OUT
CMPnEN INVEN
WOn
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 197
20335 TimerCounter CommandsA set of commands can be issued by software to immediately change the state of the peripheral Thesecommands give direct control of the UPDATE RESTART and RESET signals A command is issued bywriting the respective value to the Command bit field (CMD) in the Control E register (TCACTRLESET)
An UPDATE command has the same effect as when an update condition occurs except that the UPDATEcommand is not affected by the state of the Lock Update bit (LUPD) in the Control E register(TCACTRLE)
The software can force a restart of the current waveform period by issuing a RESTART command In thiscase the counter direction and all compare outputs are set to zero
A RESET command will set all timercounter registers to their initial values A RESET can be issued onlywhen the timercounter is not running (ENABLE=0 in TCACTRLA)
20336 Split Mode - Two 8-Bit TimerCounters
Split Mode OverviewTo double the number of timers and PWM channels in the TCA a Split Mode is provided In this SplitMode the 16-bit timercounter acts as two separate 8-bit timers which each have three comparechannels for PWM generation The split mode will only work with single slope down count Split Modedoes not support Event action controlled operation
Split Mode Differences to Normal Modebull Count
ndash Down-count onlyndash TimerCounter counter high and low byte are independent (TCALCNT TCAHCNT)
bull Waveform generationndash Single Slope PWM only (WGMODE=SINGLESLOPE in TCACTRLB)
bull Interruptndash No change for low byte TimerCounter (TCALCNT)ndash Underflow interrupt for high byte TimerCounter (TCAHCNT)ndash No compare interrupt or flag for High-byte Compare n registers (TCAHCMPn)
bull Event actions Not compatiblebull Buffer registers and Buffer Valid flags Unusedbull Register access Byte access to all registersbull Temp register Unused 16-bit register of the Normal Mode are accessed as 8-bit TCA_H and
TCA_L respectively
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 198
Block DiagramFigure 20-13 TimerCounter Block Diagram Split Mode
Base Counter
Compare (Unit n = 012)
Counter
= 0
Control Logic
HUNF(INT Req)
BOTTOML
Compare (Unit n = 012)
Waveform Generation
LCMPn(INT Req)
WOn Out
= match
BOTTOMH
count low load low
=
Waveform Generation
match
WO[n+3] Out
= 0
count high load high
Clock Select
LUNF(INT Req)
HPER CTRLALPER
LCMPn
LCNTHCNT
HCMPn
Split Mode InitializationWhen shifting between Normal Mode and Split Mode the functionality of some registers and bits changebut their values do not For this reason disabling the peripheral (ENABLE=0 in TCACTRLA) and doing aHard Reset (CMD=RESET in TCACTRLESET) is recommended when changing the mode to avoidunexpected behavior
To start using the timercounter in basic Split Mode after a Hard Reset follow these stepsbull Enable Split Mode by writing a 1 to the Split Mode Enable bit in the Control D register (SPLITM in
TCACTRLD)bull Write a TOP value to the Period registers (TCAPER)bull Enable the peripheral by writing a 1 to the ENABLE bit in the Control A register (TCACTRLA)
The counter will start counting clock ticks according to the prescaler setting in the Clock Select bitfield (CLKSEL) in TCACTRLA
bull The counter values can be read from the Counter bit field in the Counter registers (TCACNT)
Activating Split Mode results in changes to the functionality of some registers and register bits Themodifications are described in a separate register map
Related Links
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 199
206 Register Summary - TCA in Split Mode (CTRLDSPLITM=1)
2034 EventsThe peripheral can take the following actions on an input Event
bull The counter counts positive edges of the Event signalbull The counter counts both positive and negative edges of the Event signalbull The counter counts prescaled clock cycles as long as the Event signal is highbull The counter counts prescaled clock cycles Event signal controls the direction of counting Up-count
when Event signal is low down-count when Event signal is high
The specific action is selected by writing to the Event Action bits (EVACT) in the Event Control register(TCAEVCTRL) Events as input are enabled by writing a 1 to the Enable Count on Event Input bit(CNTEI in TCAEVCTRL)
Event controlled operation is not available in Split Mode
2035 InterruptsTable 20-3 Available Interrupt Vectors and Sources in Normal Mode
Offset Name Vector Description Conditions
0x00 OVF Overflow and Compare matchinterrupt
The counter has reached its top value and wrapped tozero
0x04 CMP0 Compare channel 0 interrupt Match between the counter value and the Compare 0register
0x06 CMP1 Compare channel 1 interrupt Match between the counter value and the Compare 1register
0x08 CMP2 Compare channel 2 interrupt Match between the counter value and the Compare 2register
Table 20-4 Available Interrupt Vectors and Sources in Split Mode
Offset Name Vector Description Conditions
0x00 LUNF Low-byte Underflow interrupt Low-byte timer reaches BOTTOM
0x02 HUNF High-byte Underflow interrupt High-byte timer reaches BOTTOM
0x04 LCMP0 Compare channel 0 interrupt Match between the counter value and the low-byte ofCompare 0 register
0x06 LCMP1 Compare channel 1 interrupt Match between the counter value and the low-byte ofCompare 1 register
0x08 LCMP2 Compare channel 2 interrupt Match between the counter value and the low-byte ofthe Compare 2 register
When an interrupt condition occurs the corresponding Interrupt Flag is set in the Interrupt Flags registerof the peripheral (peripheralINTFLAGS)
An interrupt source is enabled or disabled by writing to the corresponding enable bit in the peripheralsInterrupt Control register (peripheralINTCTRL)
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 200
An interrupt request is generated when the corresponding interrupt source is enabled and the InterruptFlag is set The interrupt request remains active until the Interrupt Flag is cleared See the peripheralsINTFLAGS register for details on how to clear Interrupt Flags
Related Links8 AVR CPU873 SREG
2036 Sleep Mode OperationThe timercounter will halt operation in all sleep modes
2037 Configuration Change ProtectionNot applicable
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 201
204 Register Summary - TCA in Normal Mode (CTRLDSPLITM=0)
Offset Name Bit Pos
0x00 CTRLA 70 CLKSEL[20] ENABLE0x01 CTRLB 70 CMPnEN2 CMPnEN1 CMPnEN0 ALUPD WGMODE[20]0x02 CTRLC 70 CMP2OV CMP1OV CMP0OV0x03 CTRLD 70 SPLITM0x04 CTRLECLR 70 CMD[10] LUPD DIR0x05 CTRLESET 70 CMD[10] LUPD DIR0x06 CTRLFCLR 70 CMP2BV CMP1BV CMP0BV PERBV0x07 CTRLFSET 70 CMP2BV CMP1BV CMP0BV PERBV0x08 Reserved 0x09 EVCTRL 70 EVACT[10] CNTEI0x0A INTCTRL 70 CMP2 CMP1 CMP0 OVF0x0B INTFLAGS 70 CMP2 CMP1 CMP0 OVF0x0C
0x0D
Reserved
0x0E DBGCTRL 70 DBGRUN0x0F TEMP 70 TEMP[70]0x10
0x1F
Reserved
0x20 CNT70 CNT[70]158 CNT[158]
0x22
0x25Reserved
0x26 PER70 PER[70]158 PER[158]
0x28 CMP070 CMP[70]158 CMP[158]
0x2A CMP170 CMP[70]158 CMP[158]
0x2C CMP270 CMP[70]158 CMP[158]
0x2E
0x35Reserved
0x36 PERBUF70 PERBUF[70]158 PERBUF[158]
0x38 CMP0BUF70 CMPBUF[70]158 CMPBUF[158]
0x3A CMP1BUF70 CMPBUF[70]158 CMPBUF[158]
0x3C CMP2BUF70 CMPBUF[70]158 CMPBUF[158]
205 Register Description - Normal Mode
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 202
2051 Control A
Name CTRLAOffset 0x00Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 CLKSEL[20] ENABLE
Access RW RW RW RW Reset 0 0 0 0
Bits 31 ndash CLKSEL[20] Clock SelectThese bits select the clock frequency for the timercounterValue Name Description0x0 DIV1 fTCA = fCLK_PER10x1 DIV2 fTCA = fCLK_PER20x2 DIV4 fTCA = fCLK_PER40x3 DIV8 fTCA = fCLK_PER80x4 DIV16 fTCA = fCLK_PER160x5 DIV64 fTCA = fCLK_PER640x6 DIV256 fTCA = fCLK_PER2560x7 DIV1024 fTCA = fCLK_PER1024
Bit 0 ndash ENABLE EnableValue Description0 The peripheral is disabled1 The peripheral is enabled
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 203
2052 Control B - Normal Mode
Name CTRLBOffset 0x01Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 CMPnEN2 CMPnEN1 CMPnEN0 ALUPD WGMODE[20]
Access RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0
Bits 4 5 6 ndash CMPnEN Compare n EnableIn the FRQ or PWM waveform generation mode these bits will override the PORT output register for thecorresponding pinValue Description0 PORT output settings for the pin with WOn output respected1 PORT output settings for pin with WOn output overridden in FRQ or PWM waveform
generation mode
Bit 3 ndash ALUPD Auto Lock UpdateThe Auto Lock Update feature controls the Lock Update (LUPD) bit in the TCACTRLE register WhenALUPD is written to lsquo1rsquo LUPD will be set to lsquo1rsquo until the Buffer Valid (CMPnBV) bits of all enabled comparechannels are lsquo1rsquo This condition will clear LUPDIt will remain cleared until the next UPDATE condition where the buffer values will be transferred to theCMPn registers and LUPD will be set to lsquo1rsquo again This makes sure that CMPnBUF register values are nottransferred to the CMPn registers until all enabled compare buffers are writtenValue Description0 LUPD in TCACTRLE not altered by system1 LUPD in TCACTRLE set and cleared automatically
Bits 20 ndash WGMODE[20] Waveform Generation ModeThese bits select the waveform generation mode and control the counting sequence of the counter TOPvalue UPDATE condition interrupt condition and type of waveform that is generatedNo waveform generation is performed in the normal mode of operation For all other modes the resultfrom the waveform generator will only be directed to the PORT pins if the corresponding CMPnEN bit hasbeen set to enable this The port pin direction must be set as outputTable 20-5 Timer Waveform Generation Mode
WGMODE[20] Group Configuration Mode of Operation Top Update OVF
000 NORMAL Normal PER TOP TOP
001 FRQ Frequency CMP0 TOP TOP
010 - Reserved - - -
011 SINGLESLOPE Single-slope PWM PER BOTTOM BOTTOM
100 - Reserved - - -
101 DSTOP Dual-slope PWM PER BOTTOM TOP
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 204
continuedWGMODE[20] Group Configuration Mode of Operation Top Update OVF
110 DSBOTH Dual-slope PWM PER BOTTOM TOP and BOTTOM
111 DSBOTTOM Dual-slope PWM PER BOTTOM BOTTOM
Value Name Description0x0 NORMAL Normal operation mode0x1 FRQ Frequency mode0x3 SINGLESLOPE Single-slope PWM mode0x5 DSTOP Dual-slope PWM mode0x6 DSBOTH Dual-slope PWM mode0x7 DSBOTTOM Dual-slope PWM modeOther - Reserved
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 205
2053 Control C - Normal Mode
Name CTRLCOffset 0x02Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 CMP2OV CMP1OV CMP0OV
Access RW RW RW Reset 0 0 0
Bit 2 ndash CMP2OV Compare Output Value 2See CMP0OV
Bit 1 ndash CMP1OV Compare Output Value 1See CMP0OV
Bit 0 ndash CMP0OV Compare Output Value 0The CMPnOV bits allow direct access to the waveform generators output compare value when the timercounter is not enabled This is used to set or clear the WG output value when the timercounter is notrunning
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 206
2054 Control D
Name CTRLDOffset 0x03Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 SPLITM
Access RW Reset 0
Bit 0 ndash SPLITM Enable Split ModeThis bit sets the timercounter in split mode operation It will then work as two 8-bit timercounters Theregister map will change compared to normal 16-bit mode
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 207
2055 Control Register E Clear - Normal Mode
Name CTRLECLROffset 0x04Reset 0x00Property -
The individual status bit can be cleared by writing a one to its bit location This allows each bit to becleared without use of a read-modify-write operation on a single registerEach Status bit can be read out either by reading TCACTRLESET or TCACTRLECLR
Bit 7 6 5 4 3 2 1 0 CMD[10] LUPD DIR
Access RW RW RW RW Reset 0 0 0 0
Bits 32 ndash CMD[10] CommandThese bits are used for software control of update restart and reset of the timercounter The commandbits are always read as zeroValue Name Description0x0 NONE No command0x1 UPDATE Force update0x2 RESTART Force restart0x3 RESET Force hard Reset (ignored if TC is enabled)
Bit 1 ndash LUPD Lock UpdateLock update can be used to ensure that all buffers are valid before an update is performedValue Description0 The buffered registers are updated as soon as an UPDATE condition has occurred1 No update of the buffered registers is performed even though an UPDATE condition has
occurred
Bit 0 ndash DIR Counter DirectionNormally this bit is controlled in hardware by the waveform generation mode or by event actions but thisbit can also be changed from softwareValue Description0 The counter is counting up (incrementing)1 The counter is counting down (decrementing)
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 208
2056 Control Register E Set - Normal Mode
Name CTRLESETOffset 0x05Reset 0x00Property -
The individual status bit can be set by writing a 1 to its bit location This allows each bit to be set withoutuse of a read-modify-write operation on a single registerEach Status bit can be read out either by reading TCACTRLESET or TCACTRLECLR
Bit 7 6 5 4 3 2 1 0 CMD[10] LUPD DIR
Access RW RW RW RW Reset 0 0 0 0
Bits 32 ndash CMD[10] CommandThese bits are used for software control of update restart and reset of the timercounter The commandbits are always read as zeroValue Name Description0x0 NONE No command0x1 UPDATE Force update0x2 RESTART Force restart0x3 RESET Force hard Reset (ignored if TC is enabled)
Bit 1 ndash LUPD Lock UpdateLocking the update ensures that all buffers are valid before an update is performedValue Description0 The buffered registers are updated as soon as an UPDATE condition has occurred1 No update of the buffered registers is performed even though an UPDATE condition has
occurred
Bit 0 ndash DIR Counter DirectionNormally this bit is controlled in hardware by the waveform generation mode or by event actions but thisbit can also be changed from softwareValue Description0 The counter is counting up (incrementing)1 The counter is counting down (decrementing)
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 209
2057 Control Register F Clear
Name CTRLFCLROffset 0x06Reset 0x00Property -
The individual status bit can be cleared by writing a one to its bit location This allows each bit to becleared without use of a read-modify-write operation on a single register
Bit 7 6 5 4 3 2 1 0 CMP2BV CMP1BV CMP0BV PERBV
Access RW RW RW RW Reset 0 0 0 0
Bit 3 ndash CMP2BV Compare 2 Buffer ValidSee CMP0BV
Bit 2 ndash CMP1BV Compare 1 Buffer ValidSee CMP0BV
Bit 1 ndash CMP0BV Compare 0 Buffer ValidThe CMPnBV bits are set when a new value is written to the corresponding CMPnBUF register Thesebits are automatically cleared on an UPDATE condition
Bit 0 ndash PERBV Period Buffer ValidThis bit is set when a new value is written to the PERB register This bit is automatically cleared on anUPDATE condition
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 210
2058 Control Register F Set
Name CTRLFSETOffset 0x07Reset 0x00Property -
The individual status bit can be set by writing a one to its bit location This allows each bit to be setwithout use of a read-modify-write operation on a single register
Bit 7 6 5 4 3 2 1 0 CMP2BV CMP1BV CMP0BV PERBV
Access RW RW RW RW Reset 0 0 0 0
Bit 3 ndash CMP2BV Compare 2 Buffer ValidSee CMP0BV
Bit 2 ndash CMP1BV Compare 1 Buffer ValidSee CMP0BV
Bit 1 ndash CMP0BV Compare 0 Buffer ValidThe CMPnBV bits are set when a new value is written to the corresponding CMPnBUF register Thesebits are automatically cleared on an UPDATE condition
Bit 0 ndash PERBV Period Buffer ValidThis bit is set when a new value is written to the PERB register This bit is automatically cleared on anUPDATE condition
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 211
2059 Event Control
Name EVCTRLOffset 0x09Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 EVACT[10] CNTEI
Access RW RW RW Reset 0 0 0
Bits 21 ndash EVACT[10] Event ActionThese bits define on what type of event action the counter will increment or decrementValue Name Description0x0 EVACT_POSEDGE Count on positive edge event0x1 EVACT_ANYEDGE Count on any edge event0x2 EVACT_HIGHLVL Count on prescaled clock while event line is 10x3 EVACT_UPDOWN Count on prescaled clock Event controls count direction Up-count
when event line is 0 down-count when event line is 1
Bit 0 ndash CNTEI Enable Count on Event InputValue Description0 Counting on Event input is disabled1 Counting on Event input is enabled according to EVACT bit field
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 212
20510 Interrupt Control Register - Normal Mode
Name INTCTRLOffset 0x0AReset 0x00Property -
Bit 7 6 5 4 3 2 1 0 CMP2 CMP1 CMP0 OVF
Access RW RW RW RW Reset 0 0 0 0
Bit 6 ndash CMP2 Compare Channel 2 Interrupt EnableSee CMP0
Bit 5 ndash CMP1 Compare Channel 1 Interrupt EnableSee CMP0
Bit 4 ndash CMP0 Compare Channel 0 Interrupt EnableWriting CMPn bit to 1 enables compare interrupt from channel n
Bit 0 ndash OVF Timer OverflowUnderflow Interrupt EnableWriting OVF bit to 1 enables overflow interrupt
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 213
20511 Interrupt Flag Register - Normal Mode
Name INTFLAGSOffset 0x0BReset 0x00Property -
The individual status bit can be cleared by writing a 1e to its bit location This allows each bit to be setwithout use of a read-modify-write operation on a single register
Bit 7 6 5 4 3 2 1 0 CMP2 CMP1 CMP0 OVF
Access RW RW RW RW Reset 0 0 0 0
Bit 6 ndash CMP2 Compare Channel 2 Interrupt FlagSee CMP0 flag description
Bit 5 ndash CMP1 Compare Channel 1 Interrupt FlagSee CMP0 flag description
Bit 4 ndash CMP0 Compare Channel 0 Interrupt FlagThe compare interrupt flag (CMPn) is set on a compare match on the corresponding compare channelFor all modes of operation the CMPn flag will be set when a compare match occurs between the countregister (CNT) and the corresponding compare register (CMPn) The CMPn flag will not be clearedautomatically and has to be cleared by software This is done by writing a one to its bit location
Bit 0 ndash OVF OverflowUnderflow Interrupt FlagThis flag is set either on a TOP (overflow) or BOTTOM (underflow) condition depending on theWGMODE setting OVF is not automatically cleared and needs to be cleared by software This is done bywriting a one to its bit location
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 214
20512 Debug Control Register
Name DBGCTRLOffset 0x0EReset 0x00Property -
Bit 7 6 5 4 3 2 1 0 DBGRUN
Access RW Reset 0
Bit 0 ndash DBGRUN Run in DebugValue Description0 The peripheral is halted in break debug mode and ignores events1 The peripheral will continue to run in break debug mode when the CPU is halted
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 215
20513 Temporary bits for 16-bit Access
Name TEMPOffset 0x0FReset 0x00Property -
The Temporary register is used by the CPU for single-cycle 16-bit access to the 16-bit registers of thisperipheral It can also be read and written by software See also 856 Accessing 16-bit Registers Thereis one common Temporary register for all the 16-bit registers of this peripheral
Bit 7 6 5 4 3 2 1 0 TEMP[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash TEMP[70] Temporary Bits for 16-bit Access
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 216
20514 Counter Register - Normal Mode
Name CNTOffset 0x20Reset 0x00Property -
The TCACNTL and TCACNTH register pair represents the 16-bit value TCACNT The low byte [70](suffix L) is accessible at the original offset The high byte [158] (suffix H) can be accessed at offset+ 0x01 For more details on reading and writing 16-bit registers refer to 856 Accessing 16-bit Registers
CPU and UPDI write access has priority over internal updates of the register
Bit 15 14 13 12 11 10 9 8 CNT[158]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0 CNT[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 158 ndash CNT[158] Counter high byteThese bits hold the MSB of the 16-bit counter register
Bits 70 ndash CNT[70] Counter low byteThese bits hold the LSB of the 16-bit counter register
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 217
20515 Period Register - Normal Mode
Name PEROffset 0x26Reset 0xFFFFProperty -
TCAPER contains the 16-bit TOP value in the timercounter
The TCAPERL and TCAPERH register pair represents the 16-bit value TCAPER The low byte [70](suffix L) is accessible at the original offset The high byte [158] (suffix H) can be accessed at offset+ 0x01 For more details on reading and writing 16-bit registers refer to 856 Accessing 16-bit Registers
Bit 15 14 13 12 11 10 9 8 PER[158]
Access RW RW RW RW RW RW RW RW Reset 1 1 1 1 1 1 1 1
Bit 7 6 5 4 3 2 1 0 PER[70]
Access RW RW RW RW RW RW RW RW Reset 1 1 1 1 1 1 1 1
Bits 158 ndash PER[158] Periodic high byteThese bits hold the MSB of the 16-bit period register
Bits 70 ndash PER[70] Periodic low byteThese bits hold the LSB of the 16-bit period register
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 218
20516 Compare n Register - Normal Mode
Name CMPnOffset 0x28 + n0x02 [n=02]Reset 0x00Property -
This register is continuously compared to the counter value Normally the outputs from the comparatorsare then used for generating waveforms
TCACMPn registers are updated with the buffer value from their corresponding CMPnBUF register whenan UPDATE condition occurs
The TCACMPnL and TCACMPnH register pair represents the 16-bit value TCACMPn The low byte[70] (suffix L) is accessible at the original offset The high byte [158] (suffix H) can be accessed at offset+ 0x01 For more details on reading and writing 16-bit registers refer to 856 Accessing 16-bit Registers
Bit 15 14 13 12 11 10 9 8 CMP[158]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0 CMP[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 158 ndash CMP[158] Compare high byteThese bits hold the MSB of the 16-bit compare register
Bits 70 ndash CMP[70] Compare low byteThese bits hold the LSB of the 16-bit compare register
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 219
20517 Period Buffer Register
Name PERBUFOffset 0x36Reset 0xFFFFProperty -
This register serves as the buffer for the period register (TCAPER) Accessing this register using theCPU or UPDI will affect the PERBV flag
The TCAPERBUFL and TCAPERBUFH register pair represents the 16-bit value TCAPERBUF The lowbyte [70] (suffix L) is accessible at the original offset The high byte [158] (suffix H) can be accessed atoffset + 0x01 For more details on reading and writing 16-bit registers refer to 856 Accessing 16-bitRegisters
Bit 15 14 13 12 11 10 9 8 PERBUF[158]
Access RW RW RW RW RW RW RW RW Reset 1 1 1 1 1 1 1 1
Bit 7 6 5 4 3 2 1 0 PERBUF[70]
Access RW RW RW RW RW RW RW RW Reset 1 1 1 1 1 1 1 1
Bits 158 ndash PERBUF[158] Period Buffer high byteThese bits hold the MSB of the 16-bit period buffer register
Bits 70 ndash PERBUF[70] Period Buffer low byteThese bits hold the LSB of the 16-bit period buffer register
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 220
20518 Compare n Buffer Register
Name CMPBUFOffset 0x38 + n0x02 [n=02]Reset 0x00Property -
This register serves as the buffer for the associated compare registers (TCACMPn) Accessing any ofthese registers using the CPU or UPDI will affect the corresponding CMPnBV status bit
The TCACMPnBUFL and TCACMPnBUFH register pair represents the 16-bit value TCACMPnBUFThe low byte [70] (suffix L) is accessible at the original offset The high byte [158] (suffix H) can beaccessed at offset + 0x01 For more details on reading and writing 16-bit registers refer to 856 Accessing 16-bit Registers
Bit 15 14 13 12 11 10 9 8 CMPBUF[158]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0 CMPBUF[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 158 ndash CMPBUF[158] Compare high byteThese bits hold the MSB of the 16-bit compare buffer register
Bits 70 ndash CMPBUF[70] Compare low byteThese bits hold the LSB of the 16-bit compare buffer register
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 221
206 Register Summary - TCA in Split Mode (CTRLDSPLITM=1)
Offset Name Bit Pos
0x00 CTRLA 70 CLKSEL[20] ENABLE0x01 CTRLB 70 HCMP2EN HCMP1EN HCMP0EN LCMP2EN LCMP1EN LCMP0EN0x02 CTRLC 70 HCMP2OV HCMP1OV HCMP0OV LCMP2OV LCMP1OV LCMP0OV0x03 CTRLD 70 SPLITM0x04 CTRLECLR 70 CMD[10] 0x05 CTRLESET 70 CMD[10] 0x06
0x09
Reserved
0x0A INTCTRL 70 LCMP2 LCMP1 LCMP0 HUNF LUNF0x0B INTFLAGS 70 LCMP2 LCMP1 LCMP0 HUNF LUNF0x0C
0x0D
Reserved
0x0E DBGCTRL 70 DBGRUN0x0F
0x1F
Reserved
0x20 LCNT 70 LCNT[70]0x21 HCNT 70 HCNT[70]0x22
0x25
Reserved
0x26 LPER 70 LPER[70]0x27 HPER 70 HPER[70]0x28 LCMP0 70 LCMP[70]0x29 HCMP0 70 HCMP[70]0x2A LCMP1 70 LCMP[70]0x2B HCMP1 70 HCMP[70]0x2C LCMP2 70 LCMP[70]0x2D HCMP2 70 HCMP[70]
207 Register Description - Split Mode
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 222
2071 Control A
Name CTRLAOffset 0x00Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 CLKSEL[20] ENABLE
Access RW RW RW RW Reset 0 0 0 0
Bits 31 ndash CLKSEL[20] Clock SelectThese bits select the clock frequency for the timercounterValue Name Description0x0 DIV1 fTCA = fCLK_PER10x1 DIV2 fTCA = fCLK_PER20x2 DIV4 fTCA = fCLK_PER40x3 DIV8 fTCA = fCLK_PER80x4 DIV16 fTCA = fCLK_PER160x5 DIV64 fTCA = fCLK_PER640x6 DIV256 fTCA = fCLK_PER2560x7 DIV1024 fTCA = fCLK_PER1024
Bit 0 ndash ENABLE EnableValue Description0 The peripheral is disabled1 The peripheral is enabled
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 223
2072 Control B - Split Mode
Name CTRLBOffset 0x01Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 HCMP2EN HCMP1EN HCMP0EN LCMP2EN LCMP1EN LCMP0EN
Access RW RW RW RW RW RW Reset 0 0 0 0 0 0
Bit 6 ndash HCMP2EN High-byte Compare 2 EnableSee LCMP0EN
Bit 5 ndash HCMP1EN High-byte Compare 1 EnableSee LCMP0EN
Bit 4 ndash HCMP0EN High-byte Compare 0 EnableSee LCMP0EN
Bit 2 ndash LCMP2EN Low-byte Compare 2 EnableSee LCMP0EN
Bit 1 ndash LCMP1EN Low-byte Compare 1 EnableSee LCMP0EN
Bit 0 ndash LCMP0EN Low-byte Compare 0 EnableSetting the LCMPnENHCMPnEN bits in the FRQ or PWM waveform generation mode of operation willoverride the port output register for the corresponding WOn pin
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 224
2073 Control C - Split Mode
Name CTRLCOffset 0x02Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 HCMP2OV HCMP1OV HCMP0OV LCMP2OV LCMP1OV LCMP0OV
Access RW RW RW RW RW RW Reset 0 0 0 0 0 0
Bit 6 ndash HCMP2OV High-byte Compare 2 Output ValueSee LCMP0OV
Bit 5 ndash HCMP1OV High-byte Compare 1 Output ValueSee LCMP0OV
Bit 4 ndash HCMP0OV High-byte Compare 0 Output ValueSee LCMP0OV
Bit 2 ndash LCMP2OV Low-byte Compare 2 Output ValueSee LCMP0OV
Bit 1 ndash LCMP1OV Low-byte Compare 1 Output ValueSee LCMP0OV
Bit 0 ndash LCMP0OV Low-byte Compare 0 Output ValueThe LCMPnOVHCMPn bits allow direct access to the waveform generators output compare value whenthe timercounter is not enabled This is used to set or clear the WOn output value when the timercounteris not running
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 225
2074 Control D
Name CTRLDOffset 0x03Reset 0x00Property -
Bit 7 6 5 4 3 2 1 0 SPLITM
Access RW Reset 0
Bit 0 ndash SPLITM Enable Split ModeThis bit sets the timercounter in split mode operation It will then work as two 8-bit timercounters Theregister map will change compared to normal 16-bit mode
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 226
2075 Control Register E Clear - Split Mode
Name CTRLECLROffset 0x04Reset 0x00Property -
The individual status bit can be cleared by writing a 1 to its bit location This allows each bit to be clearedwithout use of a read-modify-write operation on a single registerEach Status bit can be read out either by reading TCACTRLESET or TCACTRLECLR
Bit 7 6 5 4 3 2 1 0 CMD[10]
Access RW RW Reset 0 0
Bits 32 ndash CMD[10] CommandThese bits are used for software control of update restart and reset of the timercounter The commandbits are always read as zeroValue Name Description0x0 NONE No command0x1 UPDATE Force update0x2 RESTART Force restart0x3 RESET Force hard Reset (ignored if TC is enabled)
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 227
2076 Control Register E Set - Split Mode
Name CTRLESETOffset 0x05Reset 0x00Property -
The individual status bit can be set by writing a 1 to its bit location This allows each bit to be set withoutuse of a read-modify-write operation on a single registerEach Status bit can be read out either by reading TCACTRLESET or TCACTRLECLR
Bit 7 6 5 4 3 2 1 0 CMD[10]
Access RW RW Reset 0 0
Bits 32 ndash CMD[10] CommandThese bits are used for software control of update restart and reset of the timercounter The commandbits are always read as zeroValue Name Description0x0 NONE No command0x1 UPDATE Force update0x2 RESTART Force restart0x3 RESET Force hard Reset (ignored if TC is enabled)
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 228
2077 Interrupt Control Register - Split Mode
Name INTCTRLOffset 0x0AReset 0x00Property -
Bit 7 6 5 4 3 2 1 0 LCMP2 LCMP1 LCMP0 HUNF LUNF
Access RW RW RW RW RW Reset 0 0 0 0 0
Bit 6 ndash LCMP2 Low-byte Compare Channel 0 Interrupt EnableSee LCMP0
Bit 5 ndash LCMP1 Low-byte Compare Channel 1 Interrupt EnableSee LCMP0
Bit 4 ndash LCMP0 Low-byte Compare Channel 0 Interrupt EnableWriting LCMPn bit to 1 enables low-byte compare interrupt from channel n
Bit 1 ndash HUNF High-byte Underflow Interrupt EnableWriting HUNF bit to 1 enables high-byte underflow interrupt
Bit 0 ndash LUNF Low-byte Underflow Interrupt EnableWriting HUNF bit to 1 enables low-byte underflow interrupt
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 229
2078 Interrupt Flag Register - Split Mode
Name INTFLAGSOffset 0x0BReset 0x00Property -
The individual status bit can be cleared by writing a lsquo1rsquo to its bit location This allows each bit to be setwithout use of a read-modify-write operation on a single register
Bit 7 6 5 4 3 2 1 0 LCMP2 LCMP1 LCMP0 HUNF LUNF
Access RW RW RW RW RW Reset 0 0 0 0 0
Bit 6 ndash LCMP2 Low-byte Compare Channel 0 Interrupt FlagSee LCMP0 flag description
Bit 5 ndash LCMP1 Low-byte Compare Channel 0 Interrupt FlagSee LCMP0 flag description
Bit 4 ndash LCMP0 Low-byte Compare Channel 0 Interrupt FlagThe compare interrupt flag (LCMPn) is set on a compare match on the corresponding compare channelFor all modes of operation the LCMPn flag will be set when a compare match occurs between the Low-byte count register (LCNT) and the corresponding compare register (LCMPn) The LCMPn flag will not becleared automatically and has to be cleared by software This is done by writing a lsquo1rsquo to its bit location
Bit 1 ndash HUNF High-byte Underflow Interrupt FlagThis flag is set on a high-byte timer BOTTOM (underflow) condition HUNF is not automatically clearedand needs to be cleared by software This is done by writing a lsquo1rsquo to its bit location
Bit 0 ndash LUNF Low-byte Underflow Interrupt FlagThis flag is set on a low-byte timer BOTTOM (underflow) condition LUNF is not automatically cleared andneeds to be cleared by software This is done by writing a lsquo1rsquo to its bit location
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 230
2079 Debug Control Register
Name DBGCTRLOffset 0x0EReset 0x00Property -
Bit 7 6 5 4 3 2 1 0 DBGRUN
Access RW Reset 0
Bit 0 ndash DBGRUN Run in DebugValue Description0 The peripheral is halted in break debug mode and ignores events1 The peripheral will continue to run in break debug mode when the CPU is halted
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 231
20710 Low-byte Timer Counter Register - Split Mode
Name LCNTOffset 0x20Reset 0x00Property -
TCALCNT contains the counter value in low-byte timer CPU and UPDI write access has priority overcount clear or reload of the counter
Bit 7 6 5 4 3 2 1 0 LCNT[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash LCNT[70] Counter value for low-byte timerThese bits define the counter value of the low-byte timer
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 232
20711 High-byte Timer Counter Register - Split Mode
Name HCNTOffset 0x21Reset 0x00Property -
TCAHCNT contains the counter value in high-byte timer CPU and UPDI write access has priority overcount clear or reload of the counter
Bit 7 6 5 4 3 2 1 0 HCNT[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash HCNT[70] Counter value for high-byte timerThese bits define the counter value in high-byte timer
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 233
20712 Low-byte Timer Period Register - Split Mode
Name LPEROffset 0x26Reset 0x00Property -
The TCALPER register contains the TOP value of low-byte timer
Bit 7 6 5 4 3 2 1 0 LPER[70]
Access RW RW RW RW RW RW RW RW Reset 1 1 1 1 1 1 1 1
Bits 70 ndash LPER[70] Period value low-byte timerThese bits hold the TOP value of low-byte timer
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 234
20713 High-byte Period Register - Split Mode
Name HPEROffset 0x27Reset 0x00Property -
The TCAHPER register contains the TOP value of high-byte timer
Bit 7 6 5 4 3 2 1 0 HPER[70]
Access RW RW RW RW RW RW RW RW Reset 1 1 1 1 1 1 1 1
Bits 70 ndash HPER[70] Period value high-byte timerThese bits hold the TOP value of high-byte timer
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 235
20714 Compare Register n for low-byte Timer - Split Mode
Name LCMPOffset 0x28 + n0x02 [n=02]Reset 0x00Property -
The TCALCMPn register represents the compare value of compare channel n for low-byte Timer Thisregister is continuously compared to the counter value of low-byte timer LCNT Normally the outputsfrom the comparators are then used for generating waveforms
Bit 7 6 5 4 3 2 1 0 LCMP[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash LCMP[70] Compare value of channel nThese bits hold the compare value of channel n that is compared to LCNT
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 236
20715 High-byte Compare Register n - Split Mode
Name HCMPOffset 0x29 + n0x02 [n=02]Reset 0x00Property -
The TCAHCMPn register represents the compare value of compare channel n for high-byte Timer Thisregister is continuously compared to the counter value of high-byte timer HCNT Normally the outputsfrom the comparators are then used for generating waveforms
Bit 7 6 5 4 3 2 1 0 HCMP[70]
Access RW RW RW RW RW RW RW RW Reset 0 0 0 0 0 0 0 0
Bits 70 ndash HCMP[70] Compare value of channel nThese bits hold the compare value of channel n that is compared to HCNT
ATtiny416816TCA - 16-bit TimerCounter Type A
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 237
21 TCB - 16-bit TimerCounter Type B
211 Featuresbull 16-bit counter operation modes
ndash Periodic interruptndash Timeout checkndash Input capture
bull On eventbull Frequency measurementbull Pulse width measurementbull Frequency and pulse width measurement
ndash Single shotndash 8-bit Pulse Width Modulation (PWM)
bull Noise canceler on event inputbull Optional Operation synchronous with TCA0
212 OverviewThe capabilities of the 16-bit TimerCounter type B (TCB) include frequency and waveform generationand input capture on Event with time and frequency measurement of digital signals The TCB consists ofa base counter and control logic which can be set in one of eight different modes each mode providingunique functionality The base counter is clocked by the peripheral clock with optional prescaling
2121 Block DiagramFigure 21-1 TimerCounter Type B Block Diagram
ATtiny416816TCB - 16-bit TimerCounter Type B
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 238
Counter
=
CNT
= 0
countclear Control
EVCTRL
CTRLA
IF(INT Req)
TOP
ClockSelect
BOTTOM
Edge Select CTRLB Mode
CCMP
Output controland
logicAsynchronous
Synchronousoutput
Asynchronousoutput
Mode Output enable initial value
CLK_PER
LogicEvent System
TCB
DIV2
CLK_TCA
21211 Noise CancelerThe noise canceler improves noise immunity by using a simple digital filter scheme When the noise filteris enabled the peripheral monitors the event channel and keeps a record of the last four observedsamples If four consecutive samples are equal the input is considered to be stable and the signal is fedto the edge detector
When enabled the noise canceler introduces an additional delay of four system clock cycles between achange applied to the input and the update of the input compare register
The noise canceler uses the system clock and is therefore not affected by the prescaler
2122 Signal Description
Signal Description Type
WO Digital asynchronous output Waveform Output
Related Links5 IO Multiplexing and Considerations
2123 System DependenciesIn order to use this peripheral other parts of the system must be configured correctly as described below
Table 21-1 TCB System Dependencies
Dependency Applicable Peripheral
Clocks Yes CLKCTRL
IO Lines and Connections Yes WO
Interrupts Yes CPUINT
ATtiny416816TCB - 16-bit TimerCounter Type B
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 239
continuedDependency Applicable Peripheral
Events Yes EVSYS
Debug Yes UPDI
Related Links21231 Clocks21235 Debug Operation21233 Interrupts21234 Events
21231 ClocksThis peripheral uses the systems peripheral clock CLK_PER The peripheral has its own local prescaleror can be configured to run off the prescaled clock signal of the Timer Counter type A (TCA)
Related Links10 CLKCTRL - Clock Controller
21232 IO Lines and ConnectionsUsing the IO lines of the peripheral requires configuration of the IO pins
Related Links5 IO Multiplexing and Considerations16 PORT - IO Pin Configuration
21233 InterruptsUsing the interrupts of this peripheral requires the Interrupt Controller to be configured first
Related Links13 CPUINT - CPU Interrupt Controller873 SREG2135 Interrupts
21234 EventsThe events of this peripheral are connected to the Event System
Related Links14 EVSYS - Event System
21235 Debug OperationWhen the CPU is halted in debug mode this peripheral will halt normal operation This peripheral can beforced to continue operation during debugging
This peripheral can be forced to operate with halted CPU by writing a 1 to the Debug Run bit (DBGRUN)in the Debug Control register of the peripheral (peripheralDBGCTRL)
Related Links33 UPDI - Unified Program and Debug Interface
ATtiny416816TCB - 16-bit TimerCounter Type B
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 240
213 Functional Description
2131 DefinitionsThe following definitions are used throughout the documentation
Table 21-2 TimerCounter Definitions
Name Description
BOTTOM The counter reaches BOTTOM when it becomes zero
MAX The counter reaches MAXimum when it becomes all ones
TOP The counter reaches TOP when it becomes equal to the highest value in the countsequence
UPDATE The update condition is met when the timercounter reaches BOTTOM or TOP depending onthe waveform generator mode
CNT Counter register value
CCMP CaptureCompare register value
In general the term ldquotimerrdquo is used when the timercounter is counting periodic clock ticks The termldquocounterrdquo is used when the input signal has sporadic or irregular ticks
2132 InitializationBy default the TCB is in Periodic Interrupt mode Follow these steps to start using it
bull Write a TOP value to the CompareCapture register (TCBCCMP)bull Enable the counter by writing a 1 to the ENABLE bit in the Control A register (TCBCTRLA)
The counter will start counting clock ticks according to the prescaler setting in the Clock Select bitfield (CLKSEL in TCBCTRLA)
bull The counter value can be read from the Count register (TCBCNT) The peripheral will generate aninterrupt when the CNT value reaches TOP
2133 Operation
21331 ModesThe timer can be configured to run in one of the eight different modes listed below The event pulseneeds to be longer than one system clock cycle in order to guarantee edge detection
213311 Periodic Interrupt ModeIn the periodic interrupt mode the counter counts to the capture value and restarts from zero Interrupt isgenerated when counter is equal to TOP If TOP is updated to a value lower than count the counter willcontinue until MAX and wrap around without generating an interrupt
Figure 21-2 Periodic Interrupt Mode
ATtiny416816TCB - 16-bit TimerCounter Type B
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 241
BOTTOM
MAX
Interrupt
TOP
TOP changed to a value lower than CNT
CNT
Counter wraps around
213312 Timeout Check ModeIn this mode the counter counts to MAX and wraps around On the first edge the counter is restarted andon the second edge the counter is stopped If the count register (TCBCNT) reaches TOP before thesecond edge an interrupt will be generated In freeze state the counter will restart on a new edgeReading count (TCBCNT) or comparecapture (TCBCCMP) register or writing run bit (RUN inTCBSTATUS) in freeze state will have no effectFigure 21-3 Timeout Check Mode
CNT
BOTTOM
MAX
ldquo Interruptrdquo
TOP
TOP changed to a valuelower than CNT
Counter wrapsaround
Event Input
Edge detector
213313 Input Capture on Event ModeThe counter will count from BOTTOM to MAX continuously When an event is detected the counter valuewill be transferred to the CompareCapture register (TCBCCMP) and interrupt is generated The modulehas an edge detector which can be configured to trigger count capture on either rising or falling edges
The figure below shows the input capture unit configured to capture on falling edge on the event inputsignal The interrupt flag is automatically cleared after the high byte of the capture register has been read
Figure 21-4 Input Capture on Event
ATtiny416816TCB - 16-bit TimerCounter Type B
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 242
CNT
MAX
BOTTOM
Interrupt
W rap aroundCopy CN T to CCMP
and in terrup tCopy CN T to CCMP
and in terrup t
Event Input
Edge detector
It is recommended to write zero to the TCBCNT register when entering this mode from any other mode
213314 Input Capture Frequency Measurement ModeIn this mode the TCB captures the counter value and restarts on either a positive or negative edge of theevent input signal
The interrupt flag is automatically cleared after the high byte of the CompareCapture register(TCBCCMP) has been read and an interrupt request is generated
The figure below illustrates this mode when configured to act on rising edge
Figure 21-5 Input Capture Frequency Measurement
CNT
MAX
BOTTOM
Interrupt
Copy CNT to CCMPinterrupt and restart
Copy CNT to CCMPinterrupt and restart
Copy CNT to CCMPinterrupt and restart
Event Input
Edge detector
ATtiny416816TCB - 16-bit TimerCounter Type B
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 243
213315 Input Capture Pulse Width Measurement ModeThe input capture pulse width measurement will restart the counter on a positive edge and capture on thenext falling edge before an interrupt request is generated The interrupt flag is automatically cleared whenthe high byte of the capture register is read The timer will automatically switch between rising and fallingedge detection but a minimum edge separation of two clock cycles is required for correct behavior
Figure 21-6 Input Capture Pulse Width Measurement
CNT
MAX
BOTTOM
Interrupt
Resta rtcounter
Copy CN T to CCMPand in terrup t
Resta rtcounter
Copy CN T to CCMPand g ive inte rrupt
Resta rtcounter
Event Input
Edge detector
213316 Input Capture Frequency and Pulse Width Measurement ModeIn this mode the timer will start counting when a positive edge is detected on the even input signal Onthe following falling edge the count value is captured The counter stops when the second rising edge ofthe event input signal is detected This will also set the interrupt flag
Reading the capture will clear the interrupt flag When the capture register is read or the interrupt flag iscleared the TC is ready for a new capture sequence The counter register should therefor be read beforethe capture register as this is reset to zero at the next positive edge
ATtiny416816TCB - 16-bit TimerCounter Type B
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 244
Figure 21-7 Input Capture Frequency and Pulse Width Measurement
CNT
MAX
BOTTOM
Interrupt
Startcounter
Copy CNT toCCMP
Stop counter andinterrupt
CPU reads the
Ignore tillCapture is read
Trigger nextcapture sequence
Event Input
Edge detector
CCMP register
213317 Single Shot ModeThis mode can be used to generate a pulse with a duration that is defined by the Compare register(TCBCCMP) every time a rising or falling edge is observed on a connected event channel
When the counter is stopped the output pin is driven to low If an event is detected on the connectedevent channel the timer will reset and start counting from zero to TOP while driving its output high TheRUN bit in the Status register can be read to see if the counter is counting or not When the counterregister reaches the CCMP register value counter will stop and the output pin will go low for at least oneprescaler cycle If a new event arrives during this time that event will be ignored The following figureshows an example waveform There is a two clock cycle delay from when the event is received until theoutput is set high If the ASYNC bit in TCBCTRLB is written to 1 an asynchronous edge detector isused for input events to give immediate action When the EDGE bit of the TCBEVCTRL register is writtento 1 any edge can trigger the start of counter If the EDGE bit is 0 only positive edges will trigger thestart
The counter will start as soon as the module is enabled even without triggering event This is preventedby writing TOP to the counter register
Similar behavior is seen if the EDGE bit in the TCBEVCTRL register is 1 while the module is enabledWriting TOP to the Counter register prevents this as well
It is not recommended to change configuration while the module is enabled
Figure 21-8 Single-Shot Mode
ATtiny416816TCB - 16-bit TimerCounter Type B
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 245
CNT
TOP
BOTTOMInterrupt
Event startscounter
Counter reachesTOP value
Output
Ignored Ignored
Event startscounter
Counter reachesTOP value
Edge detector
If the ASYNC bit in TCBCTRLB is 0 the event pulse needs to be longer than one system clock cycle inorder to guarantee edge detection
213318 8-bit PWM ModeThis timer can also be configured to run in 8-bit PWM mode where each of the register pairs in the 16-bitcomparecapture register (TCBCCMPH and TCBCCMPL) are used as individual compare registers Thecounter will continuously count from zero to CCMPL and the output will be set at BOTTOM and clearedwhen the counter reaches CCMPH
When this peripheral is enabled and in PWM mode changing the value of the comparecapture registerwill change the output but the transition may output invalid values It is hence recommended to
1 Disable the peripheral2 Write comparecapture register to CCMPH CCMPL3 Write 0x0000 to count register4 Re-enable the module
CCMPH is the number of cycles for which the output will be driven high CCMPL+1 is the period of theoutput pulse
Output of the module for different capture register values are explained below
bull CCMPL = 0 Output = 0bull CCMPL = 0xFF
bull CCMPH = 0 Output = 0bull 0 lt CCMPH le 0xFF Output = 1 for CCMPH cycles low for the rest of the period
bull For 0 lt CCMPL lt 0xFFbull CCMPH = 0 Output = 0bull If 0 lt CCMPH le CCL Output = 1 for CCMPH cycles low for the restbull CCMPH = CCMPL + 1 Output = 1
ATtiny416816TCB - 16-bit TimerCounter Type B
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 246
Figure 21-9 8-bit PWM Mode
CNT
CCMPL
BOTTOM
Interrupt
(CNT == CCMPL) andoutput goes high
(CNT == CCMPH) andoutput goes low
Output
CCMPH
21332 OutputIf ASYNC in TCBCTRLB is written to 0 (1) the output pin is driven synchronously (asynchronously) tothe TCB clock The bits CCMPINIT CCMPEN and CNTMODE in TCBCTRLB control how thesynchronous output is driven The bits CCMPINIT CCMPEN and CNTMODE in TCBCTRLB control howthe synchronous output is driven The different configurations and their impact on the output is listen inthe table below
Table 21-3 Synchronous Output
CNTMODE Output CTRLB=rsquo0rsquoCCMPEN=1
Output CTRLB=rsquo1rsquoCCMPEN=1
Single shot mode Output high when counter startsand output low when counterstops
Output high when event arrivesand output low when counterstops
8-bit PWM mode PWM mode output PWM mode output
Modes except single shot andPWM
Bit CCMPINIT in TCBCTRLB Bit CCMPINIT in TCBCTRLB
21333 Noise CancelerThe noise canceler improves noise immunity by using a simple digital filter scheme When the noise filteris enabled the peripheral monitors the event channel and keeps a record of the last four observedsamples If four consecutive samples are equal the input is considered to be stable and the signal is fedto the edge detector
When enabled the noise canceler introduces an additional delay of four system clock cycles between achange applied to the input and the update of the input compare register
The noise canceler uses the system clock and is therefore not affected by the prescaler
21334 Synchronized with TCA0The TCB can be configured to use the clock (CLK_TCA) of the TimerCounter type A (TCA0) by writing0x2 to the Clock Select bit field (CLKSEL) in the Control A register (TCBCTRLA) In this setting the TCBwill count either on the prescaled clock signal from TCA0 which is configured by CLKSEL in TCACTRLA
ATtiny416816TCB - 16-bit TimerCounter Type B
copy 2019 Microchip Technology Inc Complete Datasheet DS40001913B-page 247