Hello.
Welcome to the timeless section in this section we shall learn how to create time up for more applications
using the Cuban mix.
So let's start by creating a delay with time to create a project that uses time to create delays.
And that's the most basic application of time is to create accurate delays.
So let's see how we're going to go about that using a Cuban mix click over here to create a new project
and select my board.
My board is DST and threats to this country report.
An F for board and this my particular microcontroller DoubleClick and then it opens and well what I
want to do is first and foremost clear pin out and then I'll click yes over here.
What I want to do is select a time a module in set time a module to provide a delay for us let's use
timeout to him going to click time to show once we select our time I we have to enable a clock source
that a timer and I want to use internal clocks also just come over here disrupt our menu select the
internal clock to run the experiment How about we enable the orange entity to demonstrate this.
So I'm just going to enable PD 30 and the GPI output so this all there is to it.
Now we can come to configuration tab to configure our timer so click over here and we need to set a
pre-schooler for a timer in the counter mode as well as the counter period.
So we're going to put a pre-schooler here based on the time of clock frequency.
Let's see the clock frequency of the timer by going to the clock configuration to see the clock.
Treat this the clock tree from the tree we can see our timer so all time a frequency is forty eight
megahertz meaning forty eight clock cycles per second.
So what we want to do is we want to bring our time into the millisecond unit since forty eight million
clock cycles give us one second.
Then we know that forty eight thousand cycles gives us one millisecond.
So when we use this preschooler we've brought our time eye unit into millisecond unit and what we want
is to give the the count up period and we want to set it count accurate to be one second a second at
a time.
And that is 1000.
So yeah this all we need and we have to keep this one here update event time trigger selection.
We have to select update event to keep it updating and going on and on right.
Moving on.
So once we've done this we have to enable the timer to interrupt so I'll just take it over here then
I click Okay.
Now we can generate our code a click over here.
If my project her name and this project I'm going to call it delete M.S. meaning delay me delay s actually
because we delay and in seconds and I'm going to choose my tool chain.
I'm using the call and decay version 5 will select this click OK and it begins that generation process
and then once that is done I can click overhead to open my project and it takes a while to open.
And here we are.
I'll just rebuild to unify Everything Click Here.
Then it rebuilds and before I move on I'll just update my debugger here to reset and run.
Press the reset button when I load new code and then I'll click Okay.
It's open here and what we need to basically do is start our timer and we can just come here and see
call it go on this quarter I am on the score and the score starts on that score 80.
This function takes the timer instance assets arguments and it's all time milestones as defining this
the time a handler sorry as its arguments and a time a handler just defined here.
So we just need to point to the time a handler put this pulley on the Sunshine here like this.
Then we've started our time with basically no he's fine.
So now our time has started and it's going to reload every second.
Now what we want to do is we want to implement the callback function that should run whenever this time
comes to 1.
One second just like we set it.
We said that time to reload every second.
Now we have to implement the callback function and a callback function is going to contain the code
that will run every second.
So that's our delay is going to occur.
We're going to put the LCD toggle in that function.
So then we create a delay like the show.
Let's move on and the API we need in order to perform this is known as the period elapsed API to quickly
find it.
We can come over here and we can jump straight to where we can find it.
So click the timeout model here and our search for how time a period and lots and I'll just open this
up a bit this one this one we're looking for.
So we just copy this.
This is our time a callback function period.
The last callback a copy of this and then I implemented with the weak keyword.
So I just put this here like this and I can clean this.
And in fact I can take all of this.
And in this one here now I can talk it my elegy.
I can see how on a school G.P. I go on a school talking little pain and then what's the pain I want
to talk to.
This one takes first before the court and then the pain as GPI.
On the school pain on the school 13 4 0 0 0 range LTE.
So I've reviewed
and then download onto my board and as you can see the orange reality is totally.
So this how to create simple delays using a timer in the next lesson we show you should take a look
at more applications of the timer and then I'll see you in the next lesson yet.