is there a chance a hardware timer ISR not be triggered in a busy system?

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

is there a chance a hardware timer ISR not be triggered in a busy system?

Postby Weizzh » Fri Jan 21, 2022 6:57 am

HI there.
I set a hardware timer work at 4000 hz. When the isr is triggered, I will read some gpio status to a buffer. When the buffer is full, send a messsge to a queue and then other tasks can do some data processing for example publishing these data through mqtt.
Well, the data I get is bad. I found some data lost somewhere. The isr seemes to be triggered less than 4000 times.
Is there any chance the isr not triggered because of other tasks?
I tried to set the isr to ESP_INTR_FLAG_HIGH, and this time the isr isn't triggered even once. Am I missing something?

hustenhabas
Posts: 18
Joined: Tue Sep 14, 2021 2:18 pm

Re: is there a chance a hardware timer ISR not be triggered in a busy system?

Postby hustenhabas » Fri Jan 21, 2022 8:41 pm

Hello. Ive had this problem recently and it was because I was sending the Timer ISR event to a xQueue. What I did to fix it was handling the event inside the ISR and not sending it to xQueueRecive somewhere. My timer was 104 microseconds and it worked (My project was a bitbanged uart so i needed a very precise timer interrupt).

wrong example:

Code: Select all

void timer_isr() {
	xQeueSend()
}
void task_loop() {
	xQueueRecive()
	DoStuff()
}
right example:

Code: Select all

void timer_isr() {
	DoStuff();
}
if you use a task to recive the queue events it might get suspended to run other tasks. Increasing its priority was not enogth for me

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

Re: is there a chance a hardware timer ISR not be triggered in a busy system?

Postby Weizzh » Sun Jan 23, 2022 6:11 am

Thanks. It worked.
I've changed the code from

Code: Select all

void timer_isr() {
	xQeueSend()
}
void task_loop() {
	xQueueRecive()
	DoStuff()
}
to

Code: Select all

void timer_isr()
{
	set_a_flag
}

void observer_task
{
	loop()
	{
		check the flag
		xQueueSend
		clear the flag
	}
}
void task_loop()
 {
	xQueueRecive()
	DoStuff()
}
In fact, it is not the first time xXXXfromISR() functions of freeRTOS don't work as expected.
Hope these fetures can be tested thoroughly so developers can acknowledge more details.

Who is online

Users browsing this forum: No registered users and 337 guests