vTaskDelay issue bit me

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

vTaskDelay issue bit me

Postby fly135 » Fri Oct 05, 2018 5:10 pm

I call vTaskDelay for various reasons. One is to wait for a period after resetting a chip (BME280). I had an issue with the chip delivering bad calibration data. The sdk for the chip needed 2msec. Turned out that vTaskDelay(2/portTICK_PERIOD_MS) wasn't waiting long enough. After looking in the IDF I see that portTICK_PERIOD_MS is 10. So that means any msec delay < 10 is zero.

I posting this in case I got something wrong in my analysis. But also in case anyone uses vTaskDelay and doesn't realize that is won't work with lower than 10 msec delays unless you test for a result of zero in the division and make sure you at least pass a 1 to vTaskDelay.

John A

User avatar
urbanze
Posts: 301
Joined: Sat Jun 10, 2017 9:55 pm
Location: Brazil

Re: vTaskDelay issue bit me

Postby urbanze » Fri Oct 05, 2018 5:15 pm

Delay with RTOS methods is limited to FreeRTOS frequency, if freq. is 100Hz, minimum delay is 10ms and if 1000Hz (maximum freq), minimum delay is 1ms.

Check in menuconfig if rtos frequency is >=500Hz to get 2ms delay

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: vTaskDelay issue bit me

Postby chegewara » Fri Oct 05, 2018 5:39 pm

vTaskDelay is delaying by ticks number, not by ms. Like urbaze said, portTICK_PERIOD_MS is a macro to convert ms to ticks depend on Tick rate set in menuconfig.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: vTaskDelay issue bit me

Postby fly135 » Fri Oct 05, 2018 6:12 pm

Yes, I see now that you can change the tick rate. I don't need delay resolution below 10msec and suspect that upping the rate will have some impact on overall performance. I'm also try to make sense of the information returned by vTaskGetRunTimeStats. I'm printing the task scheduler uptime from TaskGetTickCount() against the total time for each task. It's appears that the percentages for each task are divided in half so that each idle task is 50%, but when looking at the code I'm not seeing how that is happening.

ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalTime

The ulRunTimeCounter for the idle task is close to equal to the uptime from TaskGetTickCount, but prints as approx 50%.

sprintf( pcWriteBuffer, "\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: vTaskDelay issue bit me

Postby chegewara » Fri Oct 05, 2018 7:18 pm

With higher tick rate value you will have bigger overhead because of more often task switching by scheduler.

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: vTaskDelay issue bit me

Postby chegewara » Sat Oct 06, 2018 5:41 am

EDIT i think i messed something between app flashes
Last edited by chegewara on Sun Oct 07, 2018 4:47 pm, edited 2 times in total.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: vTaskDelay issue bit me

Postby fly135 » Sat Oct 06, 2018 2:24 pm

That's weird. I'm using V3.1 Release. Was under the impression that delay was in ticks. Maybe I should check that.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: vTaskDelay issue bit me

Postby fly135 » Sun Oct 07, 2018 4:15 pm

I'm using v3.1 release. I put a loop in the beginning of my program calling vTaskDelay(100) and printing the time. I am getting the correct delay of 1000msec (1 sec).

Code: Select all

t:1 msec
t:1000 msec
t:2000 msec
t:3000 msec
t:4000 msec
t:5000 msec
t:6000 msec
t:7000 msec
t:8000 msec
t:9000 msec
Time is straight from "esp_timer_get_time()/1000;" Funny how it comes out exactly on the 1 sec marks.

User avatar
urbanze
Posts: 301
Joined: Sat Jun 10, 2017 9:55 pm
Location: Brazil

Re: vTaskDelay issue bit me

Postby urbanze » Sun Oct 07, 2018 4:30 pm

fly135 wrote:I'm using v3.1 release. I put a loop in the beginning of my program calling vTaskDelay(100) and printing the time. I am getting the correct delay of 1000msec (1 sec).

Code: Select all

t:1 msec
t:1000 msec
t:2000 msec
t:3000 msec
t:4000 msec
t:5000 msec
t:6000 msec
t:7000 msec
t:8000 msec
t:9000 msec
Time is straight from "esp_timer_get_time()/1000;" Funny how it comes out exactly on the 1 sec marks.
if your RTOS frequency is at 100Hz, it is correct. vTaskDelay(100) is 100 ticks and 1 tick is 10ms. Try vTaskDelay(pdMS_TO_TICKS(50)) this will delay 50ms.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: vTaskDelay issue bit me

Postby fly135 » Sun Oct 07, 2018 9:25 pm

urbanze wrote:
if your RTOS frequency is at 100Hz, it is correct. vTaskDelay(100) is 100 ticks and 1 tick is 10ms. Try vTaskDelay(pdMS_TO_TICKS(50)) this will delay 50ms.
Chegewara edited his post. So now mine doesn't really make any sense.

Who is online

Users browsing this forum: No registered users and 99 guests