How do I read the timer tick since the processor has started, like an arduino millisecond tick with millis()? I'm reading the timer section:
https://docs.espressif.com/projects/esp ... timer.html
This seems an overkill when I'm only reading the time tick to determine whether something has occurred long enough in the past.
Thanks.
BTW, I found the xTaskCreate() function that I was looking for in another post
Timer tick
Re: Timer tick
Use esp_timer_get_time() https://docs.espressif.com/projects/esp ... rrent-time
Re: Timer tick
Thanks. I found it after reading a lot of Google search results. If I want to do a delay, is there a convenience function like the delay() in arduino? I'm using a while loop with the vTaskDelay. What should be the minimal delay for vTaskDelay call? If I am in the main program, can I still use vTaskDelay?
Re: Timer tick
vTaskDelay() should work as a simple delay. vTaskDelay() essentially blocks the calling task (thread) for a specified number of FreeRTOS ticks. However, since its resolution is FreeRTOS ticks, you should not expect the delay to be high resolution or high accuracy (i.e., the exact delay interval that occurs may be affected by other factors such as higher priority tasks).zliudr wrote: If I want to do a delay, is there a convenience function like the delay() in arduino? I'm using a while loop with the vTaskDelay.
Do you mean app_main()? If so, then yes, app_main() is a function that is simply called from the main task (thread) which in turn is created automatically on startup.zliudr wrote:If I am in the main program, can I still use vTaskDelay?
The unit of delay used in vTaskDelay() is in terms of FreeRTOS ticks. The FreeRTOS tick frequency is set by default to 100Hz, meaning a tick will occur every 1ms. Therefore calling vTaskDelay(1) will block the calling task by 1ms. Note that you can change the FreeRTOS tick frequency using menuconfig.zliudr wrote:What should be the minimal delay for vTaskDelay call?
You can also use the pdMS_TO_TICKS() macro which will convert a delay interval in ms to the equivalent of FreeRTOS ticks. For example, calling vTaskDelay(pdMS_TO_TICKS(1500)) to delay for 1500ms will be equivalent to calling vTaskDelay(150).
Re: Timer tick
Thank you! If the FreeRTOS tick 1ms, then it is 1000 Hz, not 100 Hz, right? Or do you mean tick is 10ms each so 100 Hz is correct? I read your example of the macro and think I should just go with the pdMS_TO_TICKS().
BTW, do you know how long does it take to switch between tasks? I want to be able to adjust the tick but don't want it too quick and cpu just keep switching tasks and not doing actual work. If I remember correctly, it takes a 80386 4us to switch task
BTW, do you know how long does it take to switch between tasks? I want to be able to adjust the tick but don't want it too quick and cpu just keep switching tasks and not doing actual work. If I remember correctly, it takes a 80386 4us to switch task
Re: Timer tick
Yep, I meant 10ms. My badzliudr wrote: Thank you! If the FreeRTOS tick 1ms, then it is 1000 Hz, not 100 Hz, right? Or do you mean tick is 10ms each so 100 Hz is correct? I read your example of the macro and think I should just go with the pdMS_TO_TICKS().
Im not too sure about how long it tasks to switch tasks, but from a simple test, a task switching due to vTaskDelay() takes approx 2300 CPU cycles, which at 160MHz CPU will be approx 14us. But in general, you shouldn't expect precise time from using vTaskDelay(). If you require precise time keeping, I suggest you use a hardware timer instead.zliudr wrote: BTW, do you know how long does it take to switch between tasks? I want to be able to adjust the tick but don't want it too quick and cpu just keep switching tasks and not doing actual work. If I remember correctly, it takes a 80386 4us to switch task
Re: Timer tick
No problem Dazz. I'm not concerned with accuracy, just heuristic method to wait for UART response instead of checking every cpu cycle. I read somewhere about 100 ticks per second but the whole esp-idf document is over 1600 pages long. You guys have made an extremely impressive platform, to say the least. It's just massive amount of knowledge I need to absorb. Does espressif provide any engineering consulting service so I can talk with a developer? I am potentially interested in paying for help at a good price. I can speak both English and Mandarin. PM me.
Who is online
Users browsing this forum: No registered users and 109 guests