Hi,
I am trying to configure the HW timer to trigger an ISR every 10 seconds. What I see instead is that the ISR gets triggered for the first time indeed after 10 seconds, but then keep getting triggered continuously until I get an 'interrupt wdt timeout' exception.
Can anyone suggest what I am doing wrong? The relevant code is below...
Thanks!
Timer initialization:
==================
#define TIMER_DIVIDER 512
#define TRK_TIMER_GROUP TIMER_GROUP_0
#define TRK_TIMER_IDX TIMER_1
uint16_t interval = 10; // seconds
timer_config_t config;
config.alarm_en = 1;
config.auto_reload = 1;
config.counter_dir = TIMER_COUNT_UP;
config.divider = TIMER_DIVIDER;
config.intr_type = TIMER_INTR_LEVEL;
config.counter_en = TIMER_PAUSE;
timer_init(TRK_TIMER_GROUP, TRK_TIMER_IDX, &config);
timer_set_counter_value(TRK_TIMER_GROUP, TRK_TIMER_IDX, 0x00000000ULL);
timer_enable_intr(TRK_TIMER_GROUP, TRK_TIMER_IDX);
timer_isr_register(TRK_TIMER_GROUP, TRK_TIMER_IDX, timerIsr, NULL, ESP_INTR_FLAG_IRAM, NULL);
timer_pause(TRK_TIMER_GROUP, TRK_TIMER_IDX);
timer_set_counter_value(TRK_TIMER_GROUP, TRK_TIMER_IDX, 0x00000000ULL);
timer_set_alarm_value(TRK_TIMER_GROUP, TRK_TIMER_IDX, interval * (TIMER_BASE_CLK / TIMER_DIVIDER));
timer_start(TRK_TIMER_GROUP, TRK_TIMER_IDX);
ISR:
=====
void IRAM_ATTR timerIsr(void *para)
{
static int i=0;
ESP_LOGI(TAG, "ISR %d", i++);
}
The result is that the ISR prints the first output to serial port after 10 seconds as desired, and then continuously spits out the next prints:
I (2342) AA: ISR 0
I (2342) AA: ISR 1
I (2342) AA: ISR 2
I (2342) AA: ISR 3
I (2342) AA: ISR 4
I (2342) AA: ISR 5
I (2342) AA: ISR 6
I (2342) AA: ISR 7
I (2342) AA: ISR 8
I (2342) AA: ISR 9
I (2342) AA: ISR 10
I (2342) AA: ISR 11
I (2342) AA: ISR 12
I (2342) AA: ISR 13
I (2342) AA: ISR 14
I (2342) AA: ISR 15
I (2342) AA: ISR 16
I (2342) AA: ISR 17
I (2342) AA: ISR 18
I (2342) AA: ISR 19
I (2342) AA: ISR 20
I (2342) AA: ISR 21
I (2342) AA: ISR 22
I (2342) AA: ISR 23
I (2342) AA: ISR 24
I (2342) AA: ISR 25
I (2342) AA: ISR 26
I (2342) AA: ISR 27
I (2342) AA: ISR 28
I (2342) AA: ISR 29
I (2342) AA: ISR 30
I (2342) AA: ISR 31
I (2342) AA: ISR 32
I (2342) AA: ISR 33
I (2342) AA: ISR 34
I (2342) AA: ISR 35
I (2342) AA: ISR 36
I (2342) AA: ISR 37
I (2342) AA: ISR 38
I (2342) AA: ISR 39
I (2342) AA: ISR 40
I (2342) AA: ISR 41
I (2342) AA: ISR 42
I (2342) AA: ISR 43
I (2342) AA: ISR 44
I (2342) AA: ISR 45
I (2342) AA: ISR 46
I (2342) AA: ISR 47
I (2342) AA: ISR 48
I (2342) AA: ISR 49
I (2342) AA: ISR 50
I (2342) AA: ISR 51
I (2342) AA: ISR 52
I (2342) AA: ISR 53
I (2342) AA: ISR 54
I (2342) AA: ISR 55
I (2342) AA: ISR 56
I (2342) AA: ISR 57
I (2342) AA: ISR 58
I (2342) AA: ISR 59
I (2342) AA: ISR 60
I (2342) AA: ISR 61
I (2342) AA: ISR 62
I (2342) AA: ISR 63
I (2342) AA: ISR 64
I (2342) AA: ISR 65
I (2342) AA: ISR 66
I (2342) AA: ISR 67
I (2342) AA: ISR 68
I (2342) AA: ISR 69
I (2342) AA: ISR 70
I (2342) AA: ISR 71
I (2342) AA: ISR 72
I (2342) AA: ISR 73
I (2342) AA: ISR 74
I (2342) AA: ISR 75
I (2342) AA: ISR 76
I (2342) AA: ISR 77
I (2342) AA: ISR 78
I (2342) AA: ISR 79
I (2342) TRGuru Meditation Error: Core 0 panic'ed (Interrupt wdt timeout on CPU0)
Register dump:
PC : 0x400836ab PS : 0x00060934 A0 : 0x800822fd A1 : 0x3ffc1010
A2 : 0x3ff40000 A3 : 0x0000004b A4 : 0x00060d21 A5 : 0x3ffc1193
A6 : 0x3ffc8028 A7 : 0x00000000 A8 : 0x0000007f A9 : 0x0000007e
A10 : 0x00000000 A11 : 0xffffffff A12 : 0x00000001 A13 : 0x3ffc1193
A14 : 0x3ffc8028 A15 : 0x00000000 SAR : 0x0000001c EXCCAUSE: 0x00000005
EXCVADDR: 0x00000000 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000
HW Timer ISR keeps triggering
Re: HW Timer ISR keeps triggering
You need to either reset the counter value or stop the timer from inside the ISR.
One option is to call either timer_set_counter_value() or timer_pause() from inside the ISR. Because these driver functions aren't in IRAM, you'll need to remove ESP_INTR_FLAG_IRAM from the call to timer_isr_register(). It's fine to have the timer ISR outside of IRAM, unless you need very precise timing that might be thrown off by SPI flash write operations (when non-IRAM interrupts are disabled).
If you need to keep the ISR in IRAM, you can write to the timer registers directly from the ISR. Take a look into the implementation of the driver functions for examples of this.
Angus
One option is to call either timer_set_counter_value() or timer_pause() from inside the ISR. Because these driver functions aren't in IRAM, you'll need to remove ESP_INTR_FLAG_IRAM from the call to timer_isr_register(). It's fine to have the timer ISR outside of IRAM, unless you need very precise timing that might be thrown off by SPI flash write operations (when non-IRAM interrupts are disabled).
If you need to keep the ISR in IRAM, you can write to the timer registers directly from the ISR. Take a look into the implementation of the driver functions for examples of this.
Angus
Re: HW Timer ISR keeps triggering
Check the example for what to do inside the isr
https://github.com/espressif/esp-idf/bl ... oup.c#L116
I think minimum is
https://github.com/espressif/esp-idf/bl ... oup.c#L116
I think minimum is
Code: Select all
TIMERG0.int_clr_timers.t1 = 1;
TIMERG0.hw_timer[timer_idx].config.alarm_en = 1;
Re: HW Timer ISR keeps triggering
WiFive wrote:Check the example for what to do inside the isr
https://github.com/espressif/esp-idf/bl ... oup.c#L116
I think minimum isCode: Select all
TIMERG0.int_clr_timers.t1 = 1; TIMERG0.hw_timer[timer_idx].config.alarm_en = 1;
This did the trick, thanks!
Who is online
Users browsing this forum: No registered users and 123 guests