Hardware timers

The ESP8266 has one of these, HardwareTimer, which can be programmed to trigger when a pre-programmed interval has elapsed. The callback handler is executed in an interrupt context so is restricted on what it can do.

The timer is appropriate where accurate and short timing is required.

The API for hardware (and Software timer queues timers) is identical, implemented using a CallbackTimer class template for best performance.

Note

Applies to Esp8266 architecture only.

As with all Callback timers, the HardwareTimer can be one-shot or repeating.

With the Esp8266 a one-shot timer will repeat after it has been triggered, but only after the timer counter wraps around. The Esp8266 only has 23 bits of resolution so with a clock divider of 16 this will happen after about 1.7s.

Because the Esp8266 lacks any proper PWM hardware the timer latency is critical. Adding any additional code to the callback is therefore left to the programmer.

group hardware_timer

Hardware callback timer.

Typedefs

template<hw_timer_clkdiv_t clkdiv = TIMER_CLKDIV_16, HardwareTimerMode mode = eHWT_NonMaskable>
using HardwareTimer1 = CallbackTimer<Timer1Api<clkdiv, mode>>

Hardware Timer class template with selectable divider and interrupt mode.

using HardwareTimer = HardwareTimer1<>

Default hardware Timer class.

Enums

enum HardwareTimerMode

Hardware Timer interrupt mode.

Values:

enumerator eHWT_Maskable
enumerator eHWT_NonMaskable

Variables

static uint8_t state
static TickType interval
template<hw_timer_clkdiv_t clkdiv, HardwareTimerMode mode>
class Timer1Api : public CallbackTimerApi<Timer1Api<clkdiv, mode>>
#include <HardwareTimer.h>

Class template for Timer1 API.

Note

Provides low-level interface for timer access