Proper way of implementation of elapsed time

Hi all,

I’m building a project (advanced kitchen timer) where code is stuck over time.
I’m curious if I am implementing the timer functions efficiently.

When the user turns the rotary knob I increase/decrease the timer value to the timer_task by sending an event to the lcd queue from the rotary ISR:

xQueueSendFromISR( lcd_event_queue, &event, NULL );	

This way timer_task sees someone is increment or decrement the time and because I do not want to fight against de decrementing timer I first start a one-shot 3sec software timer and send a notification to the backlight task to light up the LCD:

xTimerStart(LcdTimerHndl3Sec, 0);
if (!backlightison)
	xTaskNotify( TaskBacklightHandle, 1, eSetValueWithOverwrite );
	backlightison = true;

The 3sec timer callback starts the 1sec timer that sends decrementing 1sec events to lcd_task:

static void vLcdTimerCallback3SecExpired(TimerHandle_t pxTimer) {

	xTimerStart(LcdTimerHndl1Sec, 0);

static void vLcdTimerCallback1SecExpired(TimerHandle_t pxTimer) {
	lcd_event_t event = { 0 };
	event.ucMessageID = 77;
	event.ucValue = 3;
	//non-blocking here!!	
	xQueueSend( lcd_event_queue, ( void * ) &event, 0); 

Eventually my code stuck, not entirely sure if it is because of this, but nesting software timers seems a bit tricky to me.
Can I always be sure timer events arrive and are handled?
Because this way of programming has a lot of assumptions

Is it good practice to do something like this:

static void vLcdTimerCallback3SecExpired(TimerHandle_t pxTimer) {

	while( xTimerStart(LcdTimerHndl1Sec, 0) != pdPASS );

Hello @sprucify,

I’m not able to fully understand your application based on your description. Can you elaborate one what tasks you have, what tasks these code blocks correspond to, and where the code is getting stuck?

Can you break in debugger and see what your code is doing when it appears stuck?

Timer callbacks run in timer task context. So as long as timer task gets a chance to run, your callbacks should fire. What is the timer task priority (i.e. value of configTIMER_TASK_PRIORITY) in your case? Usually timer task is set to the highest priority.

The only reasonxTimerStart will fail is because timer command queue is full. The timer command queue will not get empty if you repeatedly keep trying in a while loop. So, no, it is not right and you should remove the while loop.

You can look here for timer documentation: FreeRTOS - This page lists the FreeRTOS software time API functions, including source code functions to create timers, start timers, delete timers, reset timers, etc.