Chapter 2. API Reference
To pause the timer at any time, call timer_pause(). To resume it, call timer_start().
To reconfigure the timer, you can call timer_init(). This function is described in Section Timer Initialization.
You can also reconfigure the timer by using dedicated functions to change individual settings:
Set-
ting
Dedicated
Function
Description
Di-
vider
timer_set_divider()Change the rate of ticking. To avoid unpredictable results, the timer should be paused
when changing the divider. If the timer is running, timer_set_divider() pauses
it, change the setting, and start the timer again.
Mode timer_set_counter_mode()Set if the counter should be incrementing or decrementing
Auto
Reload
timer_set_auto_reload()Set if the initial counter value should be reloaded on the timer’s alarm
Alarms To set an alarm, call the function timer_set_alarm_value() and then enable the alarm us-
ing timer_set_alarm(). The alarm can also be enabled during the timer initialization stage, when
timer_init() is called.
After the alarm is enabled, and the timer reaches the alarm value, the following two actions can occur depending on
the configuration:
• An interrupt will be triggered if previously configured. See Section Interrupts on how to configure interrupts.
• When auto_reload is enabled, the timer’s counter will automatically be reloaded to start
counting again from a previously configured value. This value should be set in advance with
timer_set_counter_value().
Note:
• If an alarm value is set and the timer has already reached this value, the alarm is triggered immediately.
• Once triggered, the alarm is disabled automatically and needs to be re-enabled to trigger again.
To check the specified alarm value, call timer_get_alarm_value().
Interrupts Registration of an interrupt callback for a specific timer can be done by calling
timer_isr_callback_add() and passing in the group ID, timer ID, callback handler and user data.
The callback handler will be invoked in ISR context, so user shouldn’t put any blocking API in the callback
function. The benefit of using interrupt callback instead of precessing interrupt from scratch is, you don’t have
to deal with interrupt status check and clean stuffs, they are all addressed before the callback got run in driver’s
default interrupt handler.
For more information on how to use interrupts, please see the application example below.
Application Example
The 64-bit hardware timer example: peripherals/timer_group.
API Reference
Header File
• components/driver/include/driver/timer.h
Espressif Systems 240
Submit Document Feedback
Release v4.4