So called “super loop” architecture that goes on and on.
Of course I don’t want to use any software delays.
that can be used to run the specific part of the program.
I realize that my problem is rather trivial and can be realized in several different ways but I would like to ask about the simplest possible solution, rather not using tasks.
Tasks was created specifically for dividing the program into different independent functions, so I have to ask. Why you don’t want to use tasks? I need to know this to give you the most suitable advice.
Maybe, the problem is that I don’t really understand the task concept. Probably we are looking at the problem from two different sides. For control applications (like PID control, etc.) I need the system tick of several, let’s say 10ms to give precise intervals to call the control function. Having this “base clock” I can do other different functions that should be called periodically like switch debouncing, reading analog inputs etc. To change the period of the “base clock” I simply count the timer interrupts for instance 100 times and I have 1second base for LEDs. In this concept I have two program spaces: while(1) loop for non time critical functions (like calculations) and timer driven functions for time critical functions (like control actions). That is really enough for most of embedded systems. This concept comes from low level programming that I was using first. After that I started to use C/C++ for control applications but trying to maintain the same well known structure using timers.
So I ask if this is possible to realize using Husarion framework?
I understand that first I create and run some tasks like buzzer, motors and tog. They are running in different intervals because of different sys.delay().
But what happens if I have the same value in sys.delay()?
The next question is how many tasks can I create and how are they related to 100% of uP calculations ability? Is sys.delay() “wasting” the processor power - or it is made using timers?
How can I calculate how much processor power I have left in while(true) loop?
It is possible to achieve time critical functions in hFramework, the tasks are designed for it.
Function sys.delay() stops the task for given amount of seconds, thus the full time of each loop will take is sum of code execution + loop time. Depending on code executed in each loop the time will vary.
If you want more control and regular execution of each loop, there is sys.delaySync() function. It will stop the task until the given time has passed regardless how much time did it take to execute loop.
If you want your tasks not to interfere during execution, you can set different reference time for each of your tasks.
The next question is how many tasks can I create and how are they related to 100% of uP calculations ability?
There is no fixed limit for number of tasks, but they will be limited by amount of memory they consume. Each task is consuming processor power only during operations + a bit for switching between tasks.
Is sys.delay() “wasting” the processor power - or it is made using timers?
Both sys.delay() and sys.delaySync() are based on timers, they are not blocking processor while waiting.
You could use sys.getStats() function. It prints processor usage by each running task.
Thank you very much for very detailed answers.
that potential customers can have.
Yesterday I started to use tasks in a few of examples and found them friendly and useful.
One question that arose yesterday was how to pass variables between different tasks?
using the global variable I couldn’t pass the information form one task to the other. The solution was to check the button inside the servo task, but the question - how to pass the variables - remained.
Above code is checking the button state, and switches LEDs state accordingly. Both tasks use the same bool pressed to set the LED state.
In case you are still encountering problems with servo, please post here your code.