#include <stdio.h>
#include "driver/timer.h"
#include "esp_log.h"
#define TIMER_DIVIDER 80 // 80 MHz / 80 = 1 MHz (1 tick = 1 ยตs)
#define TIMER_INTERVAL_SEC (1.0)
timer_config_t timer_config;
static const char *TAG = "TIMER";
// ๐ฅ Interrupt handler
static bool IRAM_ATTR timer_isr_callback(void *args)
{
// This runs every 1 second
Serial.println("triggered");
return true; // keep alarm active
}
static bool IRAM_ATTR timer_isr_callback_2(void *args)
{
// This runs every 1 second
Serial.println("triggered_2");
return true; // keep alarm active
}
static bool IRAM_ATTR timer_isr_callback_3(void *args)
{
// This runs every 1 second
Serial.println("triggered_3");
return true; // keep alarm active
}
static bool IRAM_ATTR timer_isr_callback_4(void *args)
{
// This runs every 1 second
Serial.println("triggered_4");
return true; // keep alarm active
}
void app_main(void)
{
timer_config_t config;
config.alarm_en = TIMER_ALARM_EN;
config.counter_en = TIMER_PAUSE;
config.counter_dir = TIMER_COUNT_UP;
config.auto_reload = TIMER_AUTORELOAD_EN;
config.divider = TIMER_DIVIDER;
config.intr_type = TIMER_INTR_LEVEL;
// ๐ง Configure timer
// ๐ง Initialize Timer Group 0, Timer 0
timer_init(TIMER_GROUP_0, TIMER_0, &config);
// ๐ Set initial counter value
timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0);
// โฑ๏ธ Set alarm value (1 second)
timer_set_alarm_value(TIMER_GROUP_0, TIMER_0, TIMER_INTERVAL_SEC * 1000000);
// ๐ Enable interrupt
timer_enable_intr(TIMER_GROUP_0, TIMER_0);
// ๐ Attach ISR callback
timer_isr_callback_add(TIMER_GROUP_0, TIMER_0, timer_isr_callback, NULL, 0);
// ๐ START TIMER (this is what you asked about)
timer_start(TIMER_GROUP_0, TIMER_0);
}
void app_main_2(void)
{
timer_config_t config;
config.alarm_en = TIMER_ALARM_EN;
config.counter_en = TIMER_PAUSE;
config.counter_dir = TIMER_COUNT_UP;
config.auto_reload = TIMER_AUTORELOAD_EN;
config.divider = TIMER_DIVIDER;
config.intr_type = TIMER_INTR_LEVEL;
// ๐ง Configure timer
// ๐ง Initialize Timer Group 0, Timer 0
timer_init(TIMER_GROUP_0, TIMER_1, &config);
// ๐ Set initial counter value
timer_set_counter_value(TIMER_GROUP_0, TIMER_1, 0);
// โฑ๏ธ Set alarm value (1 second)
timer_set_alarm_value(TIMER_GROUP_0, TIMER_1, TIMER_INTERVAL_SEC * 2000000);
// ๐ Enable interrupt
timer_enable_intr(TIMER_GROUP_0, TIMER_1);
// ๐ Attach ISR callback
timer_isr_callback_add(TIMER_GROUP_0, TIMER_1, timer_isr_callback_2, NULL, 0);
// ๐ START TIMER (this is what you asked about)
timer_start(TIMER_GROUP_0, TIMER_1);
}
void app_main_3(void)
{
timer_config_t config;
config.alarm_en = TIMER_ALARM_EN;
config.counter_en = TIMER_PAUSE;
config.counter_dir = TIMER_COUNT_UP;
config.auto_reload = TIMER_AUTORELOAD_EN;
config.divider = TIMER_DIVIDER;
config.intr_type = TIMER_INTR_LEVEL;
// ๐ง Configure timer
// ๐ง Initialize Timer Group 0, Timer 0
timer_init(TIMER_GROUP_1, TIMER_0, &config);
// ๐ Set initial counter value
timer_set_counter_value(TIMER_GROUP_1, TIMER_0, 0);
// โฑ๏ธ Set alarm value (1 second)
timer_set_alarm_value(TIMER_GROUP_1, TIMER_0, TIMER_INTERVAL_SEC * 3000000);
// ๐ Enable interrupt
timer_enable_intr(TIMER_GROUP_1, TIMER_0);
// ๐ Attach ISR callback
timer_isr_callback_add(TIMER_GROUP_1, TIMER_0, timer_isr_callback_3, NULL, 0);
// ๐ START TIMER (this is what you asked about)
timer_start(TIMER_GROUP_1, TIMER_0);
}
void app_main_4(void)
{
timer_config_t config;
config.alarm_en = TIMER_ALARM_EN;
config.counter_en = TIMER_PAUSE;
config.counter_dir = TIMER_COUNT_UP;
config.auto_reload = TIMER_AUTORELOAD_EN;
config.divider = TIMER_DIVIDER;
config.intr_type = TIMER_INTR_LEVEL;
// ๐ง Configure timer
// ๐ง Initialize Timer Group 0, Timer 0
timer_init(TIMER_GROUP_1, TIMER_1, &config);
// ๐ Set initial counter value
timer_set_counter_value(TIMER_GROUP_1, TIMER_1, 0);
// โฑ๏ธ Set alarm value (1 second)
timer_set_alarm_value(TIMER_GROUP_1, TIMER_1, TIMER_INTERVAL_SEC * 4000000);
// ๐ Enable interrupt
timer_enable_intr(TIMER_GROUP_1, TIMER_1);
// ๐ Attach ISR callback
timer_isr_callback_add(TIMER_GROUP_1, TIMER_1, timer_isr_callback_4, NULL, 0);
// ๐ START TIMER (this is what you asked about)
timer_start(TIMER_GROUP_1, TIMER_1);
}
void setup() {
app_main();
app_main_2();
app_main_3();
app_main_4();
Serial.begin(115200);
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}