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:
  1. static bool IRAM_ATTR timer_group_isr_callback(void *args)
  2. {
  3.     BaseType_t high_task_awoken = pdFALSE;
  4.  
  5.     gpio_set_level(GPIO_NUM_48, 1);
  6.     gpio_set_level(GPIO_NUM_48, 0);
  7.  
  8.     return high_task_awoken == pdTRUE; // return whether we need to yield at the end of ISR
  9. }
Timer init code is:
  1. static void example_tg_timer_init(int group, int timer, bool auto_reload, int timer_interval_sec)
  2. {
  3.     /* Select and initialize basic parameters of the timer */
  4.     timer_config_t config = {
  5.         .divider = TIMER_DIVIDER,
  6.         .counter_dir = TIMER_COUNT_UP,
  7.         .counter_en = TIMER_PAUSE,
  8.         .alarm_en = TIMER_ALARM_EN,
  9.         .auto_reload = auto_reload,
  10.     }; // default clock source is APB
  11.     timer_init(group, timer, &config);
  12.  
  13.     /* Timer's counter will initially start from value below.
  14.        Also, if auto_reload is set, this value will be automatically reload on alarm */
  15.     timer_set_counter_value(group, timer, 0);
  16.  
  17.     /* Configure the alarm value and the interrupt on alarm. */
  18.     timer_set_alarm_value(group, timer, timer_interval_sec);
  19.     timer_enable_intr(group, timer);
  20.    
  21.     example_timer_info_t *timer_info = calloc(1, sizeof(example_timer_info_t));
  22.     timer_info->timer_group = group;
  23.     timer_info->timer_idx = timer;
  24.     timer_info->auto_reload = auto_reload;
  25.     timer_info->alarm_interval = timer_interval_sec;
  26.     timer_isr_callback_add(group, timer, timer_group_isr_callback, timer_info, 0);
  27.    
  28.  
  29.     timer_start(group, timer);
  30. }
  31.  
  32. // ....
  33.  
  34. example_tg_timer_init(TIMER_GROUP_1, TIMER_1, true, (1814 / 2));
What can i do, to make timer interrupts work stable?

username
Posts: 534
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 4090 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
  1. #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.
  1. 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: 534
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.

ESP_Sprite
Posts: 9739
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_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.
ESP_Sprite wrote:
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.

ESP_Sprite
Posts: 9739
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_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: No registered users and 102 guests