1
00:00:04,050 --> 00:00:04,560
Hello.

2
00:00:04,620 --> 00:00:10,620
Welcome to the timeless section in this section we shall learn how to create time up for more applications

3
00:00:10,620 --> 00:00:12,370
using the Cuban mix.

4
00:00:12,390 --> 00:00:19,840
So let's start by creating a delay with time to create a project that uses time to create delays.

5
00:00:20,030 --> 00:00:24,960
And that's the most basic application of time is to create accurate delays.

6
00:00:25,000 --> 00:00:30,000
So let's see how we're going to go about that using a Cuban mix click over here to create a new project

7
00:00:31,790 --> 00:00:33,670
and select my board.

8
00:00:33,680 --> 00:00:36,870
My board is DST and threats to this country report.

9
00:00:37,040 --> 00:00:45,340
An F for board and this my particular microcontroller DoubleClick and then it opens and well what I

10
00:00:45,340 --> 00:00:50,800
want to do is first and foremost clear pin out and then I'll click yes over here.

11
00:00:50,980 --> 00:00:57,730
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

12
00:00:57,760 --> 00:01:04,240
timeout to him going to click time to show once we select our time I we have to enable a clock source

13
00:01:04,240 --> 00:01:09,760
that a timer and I want to use internal clocks also just come over here disrupt our menu select the

14
00:01:09,780 --> 00:01:16,090
internal clock to run the experiment How about we enable the orange entity to demonstrate this.

15
00:01:16,300 --> 00:01:22,800
So I'm just going to enable PD 30 and the GPI output so this all there is to it.

16
00:01:22,900 --> 00:01:29,980
Now we can come to configuration tab to configure our timer so click over here and we need to set a

17
00:01:29,980 --> 00:01:34,300
pre-schooler for a timer in the counter mode as well as the counter period.

18
00:01:34,360 --> 00:01:38,660
So we're going to put a pre-schooler here based on the time of clock frequency.

19
00:01:38,740 --> 00:01:43,330
Let's see the clock frequency of the timer by going to the clock configuration to see the clock.

20
00:01:43,330 --> 00:01:50,140
Treat this the clock tree from the tree we can see our timer so all time a frequency is forty eight

21
00:01:50,380 --> 00:01:53,890
megahertz meaning forty eight clock cycles per second.

22
00:01:54,280 --> 00:02:00,520
So what we want to do is we want to bring our time into the millisecond unit since forty eight million

23
00:02:00,520 --> 00:02:02,560
clock cycles give us one second.

24
00:02:02,560 --> 00:02:08,290
Then we know that forty eight thousand cycles gives us one millisecond.

25
00:02:08,290 --> 00:02:14,590
So when we use this preschooler we've brought our time eye unit into millisecond unit and what we want

26
00:02:14,590 --> 00:02:20,950
is to give the the count up period and we want to set it count accurate to be one second a second at

27
00:02:20,950 --> 00:02:21,650
a time.

28
00:02:21,970 --> 00:02:24,290
And that is 1000.

29
00:02:24,370 --> 00:02:30,520
So yeah this all we need and we have to keep this one here update event time trigger selection.

30
00:02:30,520 --> 00:02:36,380
We have to select update event to keep it updating and going on and on right.

31
00:02:36,430 --> 00:02:37,570
Moving on.

32
00:02:37,570 --> 00:02:42,600
So once we've done this we have to enable the timer to interrupt so I'll just take it over here then

33
00:02:42,610 --> 00:02:44,410
I click Okay.

34
00:02:44,560 --> 00:02:47,480
Now we can generate our code a click over here.

35
00:02:47,500 --> 00:02:54,160
If my project her name and this project I'm going to call it delete M.S. meaning delay me delay s actually

36
00:02:54,520 --> 00:02:59,200
because we delay and in seconds and I'm going to choose my tool chain.

37
00:02:59,230 --> 00:03:06,730
I'm using the call and decay version 5 will select this click OK and it begins that generation process

38
00:03:07,180 --> 00:03:13,500
and then once that is done I can click overhead to open my project and it takes a while to open.

39
00:03:13,600 --> 00:03:14,680
And here we are.

40
00:03:14,850 --> 00:03:19,330
I'll just rebuild to unify Everything Click Here.

41
00:03:19,420 --> 00:03:26,970
Then it rebuilds and before I move on I'll just update my debugger here to reset and run.

42
00:03:27,440 --> 00:03:32,080
Press the reset button when I load new code and then I'll click Okay.

43
00:03:32,980 --> 00:03:39,970
It's open here and what we need to basically do is start our timer and we can just come here and see

44
00:03:40,480 --> 00:03:53,370
call it go on this quarter I am on the score and the score starts on that score 80.

45
00:03:53,500 --> 00:03:59,820
This function takes the timer instance assets arguments and it's all time milestones as defining this

46
00:03:59,830 --> 00:04:05,450
the time a handler sorry as its arguments and a time a handler just defined here.

47
00:04:05,710 --> 00:04:11,240
So we just need to point to the time a handler put this pulley on the Sunshine here like this.

48
00:04:11,330 --> 00:04:15,650
Then we've started our time with basically no he's fine.

49
00:04:15,690 --> 00:04:19,780
So now our time has started and it's going to reload every second.

50
00:04:19,980 --> 00:04:27,120
Now what we want to do is we want to implement the callback function that should run whenever this time

51
00:04:27,150 --> 00:04:28,370
comes to 1.

52
00:04:28,380 --> 00:04:30,430
One second just like we set it.

53
00:04:30,450 --> 00:04:33,000
We said that time to reload every second.

54
00:04:33,000 --> 00:04:38,280
Now we have to implement the callback function and a callback function is going to contain the code

55
00:04:38,330 --> 00:04:40,170
that will run every second.

56
00:04:40,170 --> 00:04:42,360
So that's our delay is going to occur.

57
00:04:42,420 --> 00:04:46,290
We're going to put the LCD toggle in that function.

58
00:04:46,620 --> 00:04:49,620
So then we create a delay like the show.

59
00:04:49,770 --> 00:04:58,640
Let's move on and the API we need in order to perform this is known as the period elapsed API to quickly

60
00:04:58,640 --> 00:04:59,090
find it.

61
00:04:59,090 --> 00:05:03,350
We can come over here and we can jump straight to where we can find it.

62
00:05:03,380 --> 00:05:11,060
So click the timeout model here and our search for how time a period and lots and I'll just open this

63
00:05:11,060 --> 00:05:16,040
up a bit this one this one we're looking for.

64
00:05:16,070 --> 00:05:17,090
So we just copy this.

65
00:05:17,090 --> 00:05:22,090
This is our time a callback function period.

66
00:05:22,090 --> 00:05:27,660
The last callback a copy of this and then I implemented with the weak keyword.

67
00:05:28,010 --> 00:05:31,830
So I just put this here like this and I can clean this.

68
00:05:32,090 --> 00:05:34,580
And in fact I can take all of this.

69
00:05:34,720 --> 00:05:38,090
And in this one here now I can talk it my elegy.

70
00:05:38,090 --> 00:05:47,420
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

71
00:05:47,420 --> 00:05:48,200
to talk to.

72
00:05:48,230 --> 00:05:52,900
This one takes first before the court and then the pain as GPI.

73
00:05:53,420 --> 00:05:59,980
On the school pain on the school 13 4 0 0 0 range LTE.

74
00:06:00,040 --> 00:06:00,800
So I've reviewed

75
00:06:04,000 --> 00:06:12,060
and then download onto my board and as you can see the orange reality is totally.

76
00:06:12,200 --> 00:06:19,490
So this how to create simple delays using a timer in the next lesson we show you should take a look

77
00:06:19,490 --> 00:06:23,480
at more applications of the timer and then I'll see you in the next lesson yet.
