Hello, welcome back.
In this lesson, we're going to see how to configure a task to execute periodically.
Now we said tasks execute based on the time quanta that is set in the configuration of the art Toscano,
whether it is 10 milliseconds, five milliseconds, etc..
What this means is that each task in a state where the tasks have the same priority, each task would
execute for this amount of time.
And then once this amount of time is exhausted, the next task would execute and then the next one and
then you come back to the the first one again.
This time, what if what if we want a task to execute, see?
Every 50 milliseconds, you don't want to execute for this long, but you wanted to execute 150 milliseconds,
pass the statement out different.
Remember, we're not saying you wanted to execute for 50 milliseconds, but you wanted to execute every
15 milliseconds, in a sense, wanted to be parodic, wanted to execute at a fixed frequency.
Wandy task to start executing at a fixed frequency.
We're going to see how to achieve that, using our using a function that we shall work with here, this
function as part of the delay function.
It's similar to the the delay function we saw earlier.
This function is called the task delay until function.
So you're basically saying delay until this amount of time.
So without talking much, I'm going to go ahead to make a copy of project number 10 over here.
I'll copy number 10 or paste over here and I'll call this eleven and then I'll call this executing tasks
periodically.
OK, and it's opened, I'm going to close these ones here.
When pundits call over here, so over here in that seat over here.
OK, so what are we going to do?
Is we going to nominate Blue to execute periodically?
In this new project, I'm going to delay I'm going to delete this feature delay if I'm right, and I'm
going to come to blue here and inside blue, I'm going to have a number of local variables because it's
simply I this is, um.
Do we need.
I hear.
We don't need our loop, so we can we can forget about I am going to create a ticker tape.
Remember, we created a static type variable, which is just an integer type.
If you go deeper, you realize of what you intended to underscore.
So for readability sake, this has been given to the tick tock, just like we created our own we created
a task profile here, which is also you intended to underscore t so I'm going to create a tick time
variable.
It's also a bit like tick tock, tick, tick type over here.
Let's go to you and then I call this X last.
Wake up or last week time, the last time he was awake, essentially, and then I'm going to grab this
this bit here.
Remember, the functions that delay or the block functions require you to pass takes as an argument.
Because of that, we have this macro that allows us to convert our time to Tick's.
OK, this time I'm going to call this.
Spirit.
And then 500 M is a past 500 here, so we would want this function or this task to execute every five
hundred milliseconds.
OK, so now we're going to see gets us the current take account.
So I'll see over here X to ask.
Get to take account.
Like this, and it's going to be stored in this variable, right, once that is done, we're going to
come over here.
Our function v task to lay onto V task delayed until it takes two arguments.
It takes to the last wake up time and then the period.
OK, so we're going to see if your task is the name of the function V task delay until.
The first argument is the address of this rebel and the reason we passed the outrace of this rebel rather
than simply to develop, was that last week up time is going to be updated automatically.
So this variable is going to be updated after then after execution when this line executes the new last
week.
Time would be stored in this variable.
So it's not going to be the old one that we read from here.
OK, so the next argument is the period XP right over here.
Right.
So let's build and see the click over here to build.
And then quicker to get onto the boat.
Number 11 here.
Then OK.
Switch.
Then let's see, so blue is the one expected to execute periodically.
Let's see.
We place this in blue.
OK, so let's run and see.
Blue.
OK, so every 500 blue kicks in its rich ones.
Right.
So this is it.
So in some applications, you require a task to execute with a precise period or precise frequency.
This is one of the ways to achieve that.
Another way to achieve that, of course, would be to create a hardware interrupt using a timer.
Because with a hardware timer, you can come a time to arm, to create and interrupt every 500 times
or 50 times or 100 times, right.
But in an amateur system, if you need an artist's version of that, you can use the V task delay until
function over here.
So this all there is and I'll show you the next lesson of the.