I am trying to implement an OS-functionality to my project. The main aim is that Task1 runs every 100 microseconds, Task2 runs every 1 millisecond, Task3 runs every 10 milliseconds and atlast Task4 runs every 100 ms.
I have read through a lot of topics such as Interrupts etc., however me being a newbie, I am quite not sure on how to implement it.
Does anyone have an idea on how this functionality could be implemented?
I have already tried using millis(), however I am not getting any result if my task duration is 100 ms or lesser. With millis(), I am only able to run my task every 1 second.
You can easily get sub 100 ms timing using millis() and there is always micros() available if you need it
Please post a full example of the sketch where only 1 second timing is possible. So far we know nothing about what your tasks are doing or even what Arduino board you are using
If you don't want to implement this functionality yourself you could look at RTOS on the ESP32. However, what you want could, as has already been pointed out, be achieved using millis() or micros(). It gets complicated if you want to protect against one task running into the time slice belonging to the next task.
This the code that I have written for 2 tasks, Ideally the cursor() should run every 1 ms and updatemenu() should run every 10 ms. But at this moment, both run every 1 second.
"Every 100us" is pretty aggressive for most microcontrollers. a 16MHz AVR will take ~10us just to do the context switch between two processes (save all the register state of one, restore the state of the other.)
There are several existing multitasking libraries for the assorted Arduinos, ranging from quick hacks to full-fledged RTOS implementations; have you looked at any of those?
That is interesting! However, I am working on a Portenta Machine Control board with an STM32 processor. So, I do believe that I can achieve such timings.
However, could you suggest me some libraries for the Portenta Machine Control board, that could help me with the Task-scheduling or even implementing RTOS?
I have already implemented the code(it works with lower timer frames), however my main question was on how to create a much effective Task-scheduling system/OS. The code I have uploaded(with some minor tweaks) does fulfill the functionality, but I am quite skeptical of its performance when I would try to add further components.
So, to rephrase my question, What is the best possible/effective way to implement this functionality?
I am trying to implement an OS-functionality to my project. The main aim is that Task1 runs every 100 microseconds, Task2 runs every 1 millisecond, Task3 runs every 10 milliseconds and atlast Task4 runs every 100 ms.