time measurement error in (xTaskGetTickCount() * portTICK_PERIOD_MS)

chromebin
Posts: 77
Joined: Wed Feb 07, 2018 3:53 pm

time measurement error in (xTaskGetTickCount() * portTICK_PERIOD_MS)

Postby chromebin » Fri Aug 30, 2019 5:27 pm

Simple question: what could affect the result of this code?

Code: Select all

    uint32_t FreeRTOS::getTimeSinceStart() {
        return (uint32_t) (xTaskGetTickCount() * portTICK_PERIOD_MS);
    }
I have 2 projects and one sees time passing about 20% faster than the other.

I am asking because no matter what I configure in menuconfig/sdkconfig, my understanding is that the above should not change.
Last edited by chromebin on Fri Aug 30, 2019 7:30 pm, edited 1 time in total.

chromebin
Posts: 77
Joined: Wed Feb 07, 2018 3:53 pm

Re: time measurement error in (xTaskGetTickCount() * portTICK_PERIOD_MS)

Postby chromebin » Fri Aug 30, 2019 7:16 pm

To avoid sdkconfig related issues I recreated those files from scratch. The only differences between the projects:

- 80MHz vs 40MHz CPU base frequency
- 240MHz vs 160MHz CPU clock frequency
- 80MHz vs 40MHz SSPI flash frequency

It is the slower CPU that trails behind the faster CPU (but nowhere near the difference in their clock speeds), and is the one that reports both runtimes.

I have now more data, and I now no longer see a fixed relation between measurements. Instead there is a difference that initially seems linear and grows to about 6 seconds in 35 seconds. Thereafter the difference apparently remains stable (continuing 6 seconds). After the moment of transtion (at t=35s) the slower CPU has less to do, and the system timer seems to function as expected.

So, could a task that hogs the CPU affect the system timer??

chromebin
Posts: 77
Joined: Wed Feb 07, 2018 3:53 pm

Re: time measurement error in (xTaskGetTickCount() * portTICK_PERIOD_MS)

Postby chromebin » Fri Aug 30, 2019 7:29 pm

So now I inserted a delay to avoid CPU hogging in the worst case scenario, and surprisingly I'm back to a relation where one CPU/project sees time passing 11..18% faster than the other.

Weird.

chromebin
Posts: 77
Joined: Wed Feb 07, 2018 3:53 pm

Re: time measurement error in (xTaskGetTickCount() * portTICK_PERIOD_MS)

Postby chromebin » Sat Aug 31, 2019 4:53 pm

About interrupts: everything is handled using FreeRTOS, except for a post-SPI transfer interrupt, active for 2us (on the slower project). Both projects/devices use SPI-transfers using spi_device_transmit().

In other words, I see no reason for xTaskGetTickCount() to vary. Totally unexpected.

I'll be implementing a hardware timer to resolve the problem.

Edit: using esp_timer_get_time() instead.

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

Re: time measurement error in (xTaskGetTickCount() * portTICK_PERIOD_MS)

Postby ESP_Sprite » Mon Sep 02, 2019 8:27 am

Interesting error, I'm wondering if there's something wrong with the power saving or something... Have you already created an issue for this on Github?


Who is online

Users browsing this forum: No registered users and 77 guests