FreeRTOS time anomalie?
FreeRTOS time anomalie?
My program measures the exact time between two events (interrupts) with microsecond accuracy. Every 17.8 seconds the measurements are distorted by several hundred microseconds. Has anyone encountered such behavior of FreeRTOS?
-
MicroController
- Posts: 2661
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: FreeRTOS time anomalie?
At 240MHz, the 32 bit CPU cycle counter overflows every 17.89 seconds. Coincidence?
-
dmitrij999
- Posts: 100
- Joined: Sat Mar 02, 2019 8:06 pm
Re: FreeRTOS time anomalie?
What kind of timer for microseconds checking you use?
If it's the hardware timer, then it could be interrupts priorities: systick timer may have the highest interrupt priority.
What's the original purpose to account microseconds?
For flow counter I used PCNT
If it's the hardware timer, then it could be interrupts priorities: systick timer may have the highest interrupt priority.
What's the original purpose to account microseconds?
For flow counter I used PCNT
Re: FreeRTOS time anomalie?
At 240MHz, the 32 bit CPU cycle counter overflows every 17.89 seconds. Coincidence?
This is obvious. Common place
Last edited by enGaryN on Sun Aug 03, 2025 1:15 pm, edited 1 time in total.
Re: FreeRTOS time anomalie?
What kind of timer for microseconds checking you use?
If it's the hardware timer, then it could be interrupts priorities: systick timer may have the highest interrupt priority.
What's the original purpose to account microseconds?
For flow counter I used PCNT
I use esp_timer_get_time() function.
Original purpose is soft PLL for incoming periodic sequence.
Can PCNT provide microsecond (~10us) accuracy?
-
MicroController
- Posts: 2661
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: FreeRTOS time anomalie?
Do you need to match only the frequency or also the phase?
Phase (the exact time beetwen local and remote periodic events) is a fundamentally important and is the main goal of measurements
-
dmitrij999
- Posts: 100
- Joined: Sat Mar 02, 2019 8:06 pm
Re: FreeRTOS time anomalie?
That's the reasonI use esp_timer_get_time() function.
esp_timer is driven the software way within FreeRTOS, so due to some hardware spinlocks FreeRTOS scheduler may be locked.
I used PCNT for pulse counting.
For your purpose i'd advise you to check with hardware timer, I think it's the high-accuracy timer so it allows to account microseconds.
Re: FreeRTOS time anomalie?
That's the reason.I use esp_timer_get_time() function.
You're right.
I found a simple intermediate solution:
using cpu_hal_get_cycle_count() function (paired with _set_) instead of esp_timer_get_time()
Thanks everyone!
UPD: hardware timer also works well
Who is online
Users browsing this forum: Baidu [Spider], Bing [Bot], Google [Bot], PerplexityBot, Semrush [Bot] and 7 guests