Forums » Req. New WJ2(ESP32) Features »
Faster execution
Added by Johan Henning about 2 years ago
Is it possible to increase the scheduling speed of FreeRTOS? For example to 10000 Hz (100 us)?
Can this be an extra option in the target setup block?
Replies (8)
RE: Faster execution - Added by Parth Maheshwari (พาร์ท) about 2 years ago
Hi Johan,
We will look deeply into this in the future. For now, the solution is to use the timer interrupt block. We have tested this and worked it down to the micro-second level.
Hope that helps.
Sincere regards,
Parth
RE: Faster execution - Added by Parth Maheshwari (พาร์ท) about 2 years ago
Hello Parth,
Thanks for your reply. It is great that the timer interrupt block has such a high timing resolution. I will give it a try.
But, in my option, for simple / beginning users which might not be familiar with dealing with interrupts it would be great if the RTOS tick frequency could be selected in the target setup block. I think it is now by default 10 ms (am I right?), options for 1 and 0.1 ms would be nice. Of course the RTOS overhead is increasing when using higher tick frequencies, but – depending on the application – this can be ok.
What happens in the current version if I set the sample time to a frequency higher than that of the RTOS (for example 0.00001 s)? Do I get an warning/error message?
Another question: Do you want me to put the other suggestions that I have sent via emails in the helpdesk system?
Regards,
Johan
RE: Faster execution - Added by Parth Maheshwari (พาร์ท) about 2 years ago
Hi Johan,
FreeRTOS tick rate is set 1kHz (1ms) in Waijung 2. In earlier ESP IDF versions, an error used to pop up when tick rate went below 1ms but we haven't tested with the current ESP IDF version yet. Also, this error is from ESP IDF itself, not Waijung 2.
Please give me some time to test other tick rates, and I will get back to you.
Regarding the suggestions, all the related problems that you encounter with Waijung 2 or ESP32, please post it here: https://support.aimagin.com/projects/support/boards/9
Any suggestions for new feature additions, please post it here: https://support.aimagin.com/projects/support/boards/10
Thank you.
Sincere regards,
Parth
RE: Faster execution - Added by Parth Maheshwari (พาร์ท) about 2 years ago
Hi Johan,
I have tested with lower tick rates than 1ms and it does not work. An error message is currently not thrown, but after talking to you we realized that we should include a popup error when the user selects a sample time lower than 1ms. This will help save the user time.
Currently, the way to know that a sample time lower than 1ms does not work in the "Deploy to Hardware" mode (other than the fact that the target hardware will not function as intended) is through a serial monitor. In External Mode, an error will be thrown in the Simulink diagnostic viewer when we try to establish a communication channel between Simulink and the target through the "Connect" button in the Simulink control panel.
Thank you for your suggestion, please let me know what you think of the timer interrupt block if you give it a try.
Sincere regards,
Parth
RE: Faster execution - Added by Johan Henning about 2 years ago
Hello Parth,
Thanks for testing this. I will try the timer interrupt block for fast responses.
Is the 1 ms a limitation of Simulink? According to what I have read a tick time of 100us should be possible in freeRTOS, although the RTOS overhead will be quite high then.
It would be nice to have the possibility to set the tick time in the target setup block. For some applications 1 ms is quite high and not necessary (it will lower the performance in a calculation-intensive system) and in those cases 10 or even 100 msec would be nice. If the system has to be very responsive 0.5 ms, 0.2 or even 0.1 ms would be nice.
Regards,
johan.
P.S. I read somewhere:
Q: for my application I need a task with 100us period time. Is it possible in FreeRTOS/OpenRTOS to define the tick time in us range? Is the minimal tick time 1 ms (portTICKPERIODMS = 1) ?
A: The minimum tick period is 1 only if you make use of the portTICKRATEMS or portMSTOTICKS macros (which the demo applications do)
RE: Faster execution - Added by Parth Maheshwari (พาร์ท) about 2 years ago
Hi Johan,
The 1 ms is a limitation of the ESP IDF itself, not Simulink.
We are going to test what you have read, please give us some time and I will keep you updated.
Sincere regards,
Parth
RE: Faster execution - Added by martin van beek about 2 years ago
Hi Parth,
Can you give us an update about this FreeRTOS timing?
Is the only way to execute code faster than 1 millisecond, using a timer interrupt function?
Or should I generate Simulink code with any timestep of my choice, compile and link the generated code to a separate timer interrupt project.
Hopefully you can help us with a simple solution.
Best regards,
Martin.
RE: Faster execution - Added by Parth Maheshwari (พาร์ท) almost 2 years ago
Hi Martin and Johan,
Thank you for your patience.
We have looked into this and the conclusion is - it is not possible to change the FreeRTOS tickrate to run below 1 ms.
It can be manually changed to go below 1ms, but it will be changed back to default (10ms) by the ESP IDF build system when building the project.
The only remaining way to change it is by modifying FreeRTOS source files. However, if changed, several libraries provided by ESP-IDF including WiFi, websockets, Bluetooth, SDmmc (sdcard), etc will fail since those are implemented using FreeRTOS functions and macros.
Hence, at the moment, the only way to execute code faster than 1ms will be to add a timer interrupt block, put all the blocks which you need to run in higher sample rate in to a function call subsystem, and connect it to the timer interrupt block.
Hope this helps.
Sincere regards,
Parth