ESP32-S3 hardware timer interrupt doesn't work stable

markelov69
Posts: 2
Joined: Sat May 28, 2022 9:44 am

ESP32-S3 hardware timer interrupt doesn't work stable

Postby markelov69 » Sat May 28, 2022 9:54 am

Hi, everyone.
I have timer and 1 tcp server task.
The problem is:
Image

My timer interrupt code for debug is:

Code: Untitled.c Select all


static bool IRAM_ATTR timer_group_isr_callback(void *args)
{
BaseType_t high_task_awoken = pdFALSE;

gpio_set_level(GPIO_NUM_48, 1);
gpio_set_level(GPIO_NUM_48, 0);

return high_task_awoken == pdTRUE; // return whether we need to yield at the end of ISR
}
Timer init code is:

Code: Untitled.c Select all


static void example_tg_timer_init(int group, int timer, bool auto_reload, int timer_interval_sec)
{
/* Select and initialize basic parameters of the timer */
timer_config_t config = {
.divider = TIMER_DIVIDER,
.counter_dir = TIMER_COUNT_UP,
.counter_en = TIMER_PAUSE,
.alarm_en = TIMER_ALARM_EN,
.auto_reload = auto_reload,
}; // default clock source is APB
timer_init(group, timer, &config);

/* Timer's counter will initially start from value below.
Also, if auto_reload is set, this value will be automatically reload on alarm */
timer_set_counter_value(group, timer, 0);

/* Configure the alarm value and the interrupt on alarm. */
timer_set_alarm_value(group, timer, timer_interval_sec);
timer_enable_intr(group, timer);

example_timer_info_t *timer_info = calloc(1, sizeof(example_timer_info_t));
timer_info->timer_group = group;
timer_info->timer_idx = timer;
timer_info->auto_reload = auto_reload;
timer_info->alarm_interval = timer_interval_sec;
timer_isr_callback_add(group, timer, timer_group_isr_callback, timer_info, 0);


timer_start(group, timer);
}

// ....

example_tg_timer_init(TIMER_GROUP_1, TIMER_1, true, (1814 / 2));
What can i do, to make timer interrupts work stable?

username
Posts: 593
Joined: Thu May 03, 2018 1:18 pm

Re: ESP32-S3 hardware timer interrupt doesn't work stable

Postby username » Sun May 29, 2022 4:58 am

I tired your code on my ESP32-S3, it was missing some parts like:

#define TIMER_DIVIDER (16) // Hardware timer clock divider

typedef struct {
int timer_group;
int timer_idx;
int alarm_interval;
bool auto_reload;
} example_timer_info_t;

But it worked fine for me.

Attach0.jpg
Attach0.jpg (757.67 KiB) Viewed 4862 times

markelov69
Posts: 2
Joined: Sat May 28, 2022 9:44 am

Re: ESP32-S3 hardware timer interrupt doesn't work stable

Postby markelov69 » Sun May 29, 2022 9:24 am

I use

Code: Untitled.c Select all

#define TIMER_DIVIDER         (2)  //  Hardware timer clock divider
To reply my issue you need to add some task, not only timer, in my case it tcp_server.

Code: Untitled.c Select all

xTaskCreate(tcp_server_task, "tcp_server", 4096, NULL, 1, NULL);
And when it start to receive data through wi-fi i see unstable interrupts.

username
Posts: 593
Joined: Thu May 03, 2018 1:18 pm

Re: ESP32-S3 hardware timer interrupt doesn't work stable

Postby username » Mon May 30, 2022 2:19 am

To reply my issue you need to add some task, not only timer, in my case it tcp_server.
Yes, I did that. you did not mention you were doing other things. So sounds like the problem lies there.

Sprite
Espressif staff
Espressif staff
Posts: 10596
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32-S3 hardware timer interrupt doesn't work stable

Postby Sprite » Mon May 30, 2022 2:54 am

Could you try starting a task pinned to core 1 and initializing the timer interrupt there? Possibly your timer is pre-empted by WiFi interrupts at some point.

Weizzh
Posts: 19
Joined: Mon Nov 22, 2021 9:32 am

Re: ESP32-S3 hardware timer interrupt doesn't work stable

Postby Weizzh » Tue Sep 20, 2022 6:08 am

Hi,is it possible that a timer ISR operations are pre-empted by WiFi interrupts?
I have faced an identical problem: when wifi is working, especially transmitting data package(about 5kB/package) through mqtt, the timer isr sometimes misses.
Could you try starting a task pinned to core 1 and initializing the timer interrupt there? Possibly your timer is pre-empted by WiFi interrupts at some point.

Sprite
Espressif staff
Espressif staff
Posts: 10596
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32-S3 hardware timer interrupt doesn't work stable

Postby Sprite » Wed Sep 21, 2022 2:34 am

Yes, it's possible for WiFi to pre-empt other interrupts.

Who is online

Users browsing this forum: ChatGPT-User and 7 guests