Espressif Systems ESP32 Technical Reference Manual page 99

Hide thumbs Also See for ESP32:
Table of Contents

Advertisement

8. 64-bit Timers
8.1 Introduction
There are four general-purpose timers embedded in the ESP32. They are all 64-bit generic timers based on
16-bit prescalers and 64-bit auto-reload-capable up/downcounters.
The ESP32 contains two timer modules, each containing two timers. The two timers in a block are indicated by
an
x
in TIMGn_Tx; the blocks themselves are indicated by an n.
The timers feature:
• A 16-bit clock prescaler, from 2 to 65536
• A 64-bit time-base counter
• Configurable up/down time-base counter: incrementing or decrementing
• Halt and resume of time-base counter
• Auto-reload at alarm
• Software-controlled instant reload
• Level and edge interrupt generation
8.2 Functional Description
8.2.1 16-bit Prescaler
Each timer uses the APB clock (APB_CLK, normally 80 MHz) as the basic clock. This clock is then divided down
by a 16-bit precaler which generates the time-base counter clock (TB_clk). Every cycle of TB_clk causes the
time-base counter to increment or decrement by one. The timer must be disabled (TIMGn_Tx_EN is cleared)
before changing the prescaler divisor which is configured by TIMGn_Tx_DIVIDER register; changing it on an
enabled timer can lead to unpredictable results. The prescaler can divide the APB clock by a factor from 2 to
65536. Specifically, when TIMGn_Tx_DIVIDER is either 1 or 2, the clock divisor is 2; when TIMGn_Tx_DIVIDER is
0, the clock divisor is 65536. Any other value will cause the clock to be divided by exactly that value.
8.2.2 64-bit Time-base Counter
The 64-bit time-base counter can be configured to count either up or down, dependent on whether
TIMGn_Tx_INCREASE is set or cleared, respectively. It supports both auto-reload and software instant reload.
An alarm event can be set to trigger when the counter reaches a value specified by software.
Counting can be enabled and disabled by setting and clearing TIMGn_Tx_EN. Clearing this bit essentially freezes
the counter, causing it to neither count up nor count down, but instead retain its value until TIMGn_Tx_EN is set
again. Reloading the counter when TIMGn_Tx_EN is cleared will change its value, but counting will not be
resumed until TIMGn_Tx_EN is set.
Software can set a new counter value by setting registers TIMGn_Tx_LOAD_LO and TIMGn_Tx_LOAD_HI to the
intended new value. The hardware will ignore these register settings until a reload; a reload will cause the
contents of these registers to be copied to the counter itself. A reload event can be triggered by an alarm
(auto-reload at alarm) or by software (software instant reload). To enable auto-reload at alarm, the register
Espressif Systems
98
ESP32 Technical Reference Manual V1.0
8 64-BIT TIMERS

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32 and is the answer not in the manual?

Questions and answers

Table of Contents

Save PDF