1
00:00:02,350 --> 00:00:09,550
In this lesson we're going to demonstrate how to create an input capture firmware using the Cuban mix.

2
00:00:09,560 --> 00:00:15,410
For those of you who are not familiar with input capture input capture is used to capture the timestamp

3
00:00:15,740 --> 00:00:17,580
or final clearance of event.

4
00:00:17,690 --> 00:00:25,090
Let's say you want to capture the such time erase an edge or a fallen off a digital sensor or curse.

5
00:00:25,110 --> 00:00:32,770
Use inputs capture for such a case and I'm going to demonstrate how to quickly do input capture with

6
00:00:32,970 --> 00:00:34,670
timers using a Cuban mix.

7
00:00:34,670 --> 00:00:39,920
And if you want to learn more about input capture and then you want to you want further elaboration

8
00:00:40,040 --> 00:00:41,210
do send me a message.

9
00:00:41,210 --> 00:00:42,040
So let's kick off.

10
00:00:42,110 --> 00:00:48,230
Let's just use the the items provided on the Discovery board which is a button in the LCD to demonstrate

11
00:00:48,260 --> 00:00:49,510
this experiment as well.

12
00:00:49,670 --> 00:00:56,450
So I'll come to my Cuban mics and create a new project so I just minimize this and then I'll come over

13
00:00:56,450 --> 00:00:58,120
here for our new project.

14
00:00:58,130 --> 00:01:07,580
I have the f 4 and this is my microcontroller and what I want to do is I want to connect the push button

15
00:01:07,640 --> 00:01:15,410
of the discovery board to an input capture timer so that whenever I press that push button the the timestamp

16
00:01:15,410 --> 00:01:18,380
of the event is stored so you can.

17
00:01:18,380 --> 00:01:24,500
You can think of this as the exact time a particular event external event occurs.

18
00:01:24,500 --> 00:01:29,790
This is actually how we program things like ultrasonic sensor or in the case of the ultrasonic sensor.

19
00:01:29,900 --> 00:01:37,220
You want to detect exactly when the signal bounces back and it's detected and I have a tutorial of programming

20
00:01:37,250 --> 00:01:39,390
ultrasonic sensor on cortex.

21
00:01:39,410 --> 00:01:45,230
Dot com you can check that article out input capture is used to detect deal care and social events and

22
00:01:45,230 --> 00:01:49,670
it becomes very useful when you're doing signal processing and when you're doing things that require

23
00:01:49,670 --> 00:01:51,820
high accuracy and all of that.

24
00:01:51,900 --> 00:01:59,660
So moving on I've just Claire pains by clicking over here and what I want to do is connect my push button

25
00:01:59,690 --> 00:02:03,280
which is connected to key issue to a particular time.

26
00:02:03,320 --> 00:02:09,500
So I could just click here like this and I've got options to connect it to time to channel one or a

27
00:02:09,500 --> 00:02:11,310
time or five channel one.

28
00:02:11,570 --> 00:02:17,840
I'd just like the timer to turn a one over here and as you can see like I said when you see this orange

29
00:02:17,840 --> 00:02:21,000
color it means the configuration is incomplete.

30
00:02:21,050 --> 00:02:23,060
We have to complete somewhere else.

31
00:02:23,060 --> 00:02:29,680
So I have to go to timer two and continue the configuration.

32
00:02:29,820 --> 00:02:35,360
What I want to do is enable Channel 1 Cause this one is Channel One as an input capture direct mode

33
00:02:35,720 --> 00:02:41,370
like this so once that is done we need to come to the configuration tab over here and click on timer

34
00:02:41,390 --> 00:02:47,220
to to set a timer configuration and what we want is we want to set it time pre-schooler like we did

35
00:02:47,220 --> 00:02:52,230
in the other examples to the millisecond unit and to do that I'm going to put forty eight thousand here

36
00:02:53,300 --> 00:02:59,790
and once I do that I'm going to set the time count more as an up counter and account period I'm going

37
00:02:59,790 --> 00:03:06,600
to plan on enormous time contribution here meaning a one day time I count for five hundred seconds before

38
00:03:06,630 --> 00:03:07,460
it reloads.

39
00:03:07,470 --> 00:03:11,940
So this the size of my time just like a day has 24 hours.

40
00:03:11,940 --> 00:03:15,600
My time has five hundred five hundred seconds.

41
00:03:15,600 --> 00:03:19,680
So after 500 seconds the time I reset.

42
00:03:19,680 --> 00:03:25,740
So yeah once that's set we have to come over here for polarity set and do we want to detect a rising

43
00:03:25,830 --> 00:03:30,230
edge or the fallen edge of both edges of the signal.

44
00:03:30,240 --> 00:03:35,250
I choose the raisin edge here I mean as soon as I press the button it's going to be detected and I have

45
00:03:35,250 --> 00:03:41,160
to make sure the I see selection over here is direct and the pre-schooler division no division and I

46
00:03:41,160 --> 00:03:48,330
can add a low pass filter here with a value 10 the maximum value over here is you to 15 that's the maximum

47
00:03:48,330 --> 00:03:49,160
15.

48
00:03:49,400 --> 00:03:55,980
So then I have to set these parameters and yet so once this is done we move on to these other settings

49
00:03:56,070 --> 00:03:59,790
are going to erupt over here for a time or two so I'm just going to click here to enable.

50
00:03:59,880 --> 00:04:07,180
Once we've done that I think we can go ahead and generate our code I'll click over her give my project

51
00:04:07,180 --> 00:04:15,800
a name I call it input capture and then select my I.D. to call you vision 5 click Okay.

52
00:04:17,940 --> 00:04:21,030
Once that is done I open the project like this.

53
00:04:24,370 --> 00:04:30,000
And I can just expand and inspect and I'll just do it to bind everything.

54
00:04:33,080 --> 00:04:41,600
And it's done rebuilding and before I move on I'll just I want to just update my debug here to reset

55
00:04:41,660 --> 00:04:43,030
and run.

56
00:04:43,100 --> 00:04:45,850
Okay and then okay.

57
00:04:45,920 --> 00:04:52,250
So what I want is like like we did before in the other example we want to start the input copter timer

58
00:04:52,400 --> 00:04:54,370
and this time we want to start it.

59
00:04:54,380 --> 00:04:56,520
We interrupt not just start.

60
00:04:56,570 --> 00:05:02,000
So I'm just going to come over here to Main and I'm going to come to the function stop to look for the

61
00:05:02,060 --> 00:05:08,510
particular function for there and I'll just click the time I hear the timer module here to see the list

62
00:05:08,510 --> 00:05:14,220
of API stuff with a timer and this one here gives me the entire list.

63
00:05:14,450 --> 00:05:18,550
What I want is the timer inputs capture start which interrupts.

64
00:05:19,010 --> 00:05:26,060
So it's overhead time ISIS starts interrupt so I just click it to see it and then I just copy this and

65
00:05:26,060 --> 00:05:32,670
go and call this function in my main file or copy it like this.

66
00:05:32,660 --> 00:05:36,140
Then take it to mean then come over here.

67
00:05:36,170 --> 00:05:45,500
Then what I want to do is this is a pointer to my time a structure score.

68
00:05:45,840 --> 00:05:54,530
HDI and to us is defined upstairs here up here like this and the channel this China one.

69
00:05:54,700 --> 00:05:56,350
So I could just come over here.

70
00:05:57,900 --> 00:06:06,460
It's a time on the school channel 1 and then we've started the interrupt next where we have to do it.

71
00:06:06,480 --> 00:06:10,160
We have to declare the callback function for the interrupt.

72
00:06:10,290 --> 00:06:11,630
Meaning what code.

73
00:06:11,670 --> 00:06:16,140
What instructions do we want to run when the event occurs.

74
00:06:16,140 --> 00:06:22,110
So we have to create a callback function for this and then declare the piece of code in that function.

75
00:06:22,830 --> 00:06:30,700
Let's do that now so we can come back here and still look for the inputs capture callback whole.

76
00:06:32,260 --> 00:06:35,050
This is a hard time I cup to call back.

77
00:06:35,060 --> 00:06:38,900
We can just click over here and then copy it.

78
00:06:38,910 --> 00:06:40,290
This is how we treat callbacks.

79
00:06:40,290 --> 00:06:42,560
We copy it and then would declare the same.

80
00:06:42,570 --> 00:06:47,520
We write the same implementation without the weak object here.

81
00:06:47,610 --> 00:06:52,980
So I'm just going to copy this and take it to my main file and place it down here somewhere.

82
00:06:57,020 --> 00:07:01,090
Just put it over here and then delete the week for her.

83
00:07:01,250 --> 00:07:06,420
So in our callback function we can get the timestamp by using the whole time I get.

84
00:07:06,440 --> 00:07:15,010
Counter API and this one is basically on the score on the score or a timer.

85
00:07:15,120 --> 00:07:15,590
I am

86
00:07:19,130 --> 00:07:25,460
gets count to this one here like this and it takes time out and starts here as an argument which is

87
00:07:25,570 --> 00:07:29,450
H I T N H T I am sorry.

88
00:07:29,930 --> 00:07:35,690
This one here returns the young timestamp which is an integer or want to do is start a timestamp in

89
00:07:35,690 --> 00:07:36,170
a variable.

90
00:07:36,170 --> 00:07:39,560
So I'm going to declare a global variable here.

91
00:07:39,740 --> 00:07:47,090
I'm going to declare that you intend to follow it over you into that to underscore t volatile and I'll

92
00:07:47,090 --> 00:07:48,260
call this timestamp

93
00:07:53,230 --> 00:07:58,390
and what I'm going to do is I'm going to assign a timestamp going to start a return value in the timestamp

94
00:07:59,290 --> 00:08:01,240
just gonna see timestamp

95
00:08:04,590 --> 00:08:08,300
because this like this we are not quite complete.

96
00:08:08,300 --> 00:08:13,940
The problem with this callback function is the works with all timers as you can see from the name it

97
00:08:13,940 --> 00:08:20,180
didn't indicate what I'm using time or module one two three four five works with over time.

98
00:08:20,330 --> 00:08:27,290
So one other thing we have to do is we have to tell this function to verify if the if the event is occurring

99
00:08:27,350 --> 00:08:34,100
at the time or two and then if that is the case then gets the timestamp story to know variable to do

100
00:08:34,100 --> 00:08:43,790
that we can use a simple if clause if we know the time or instance if h t i m we're not a timer instance

101
00:08:44,010 --> 00:08:57,910
and then instance because time to do this now we get a timestamp we started timestamp here right.

102
00:08:57,940 --> 00:09:03,760
So anytime you press the button you would store the timestamp the timestamp basically is the time at

103
00:09:03,790 --> 00:09:09,340
which the events occurred or we might want to do also is to put a counter variable here and count any

104
00:09:09,360 --> 00:09:15,430
time we pressed a button should tell us which press that button was and then issued increment.

105
00:09:15,430 --> 00:09:21,230
So I can just pull you in 32 32 on the school put you in.

106
00:09:21,250 --> 00:09:27,500
To underscore t auto counter here.

107
00:09:27,500 --> 00:09:28,130
So this one.

108
00:09:28,130 --> 00:09:30,440
Tell us the number of times you press the button.

109
00:09:30,440 --> 00:09:36,800
Every time we press is just going to grant you increment this.

110
00:09:36,820 --> 00:09:39,230
So I have to put this in a block.

111
00:09:39,230 --> 00:09:39,490
Now

112
00:09:44,850 --> 00:09:46,560
then like this.

113
00:09:46,560 --> 00:09:48,950
So yeah our code looks complete.

114
00:09:48,960 --> 00:09:54,920
We compile when when we press the button the timestamp is going to be stored in this for Apple.

115
00:09:55,050 --> 00:09:57,770
This ball is going to store the number of count.

116
00:09:57,810 --> 00:10:00,710
Remember the time is going to be moving forward.

117
00:10:00,720 --> 00:10:03,270
Let's rebuild and test on our board.

118
00:10:03,420 --> 00:10:14,190
See I download onto my board and then I just run the debugger and what I want to do is pull my global

119
00:10:14,190 --> 00:10:20,480
variables in a watch window or right click over here at this to watch window one then to the counter

120
00:10:20,490 --> 00:10:22,940
variable to watch window one as well.

121
00:10:26,160 --> 00:10:28,460
Has to watch window one as well.

122
00:10:28,490 --> 00:10:41,130
I'm going to run the code let's see I'm going to disable hexadecimal few here the code is running and

123
00:10:41,130 --> 00:10:48,730
I'm going to press my button magic and see as I press the button this recorded a time which are pressed

124
00:10:48,730 --> 00:10:51,930
a button and then press the wires.

125
00:10:52,010 --> 00:10:53,660
So that time is still moving forward.

126
00:10:53,660 --> 00:10:54,710
Let's see.

127
00:10:54,710 --> 00:10:59,120
I'll press my button again and press twice this time.

128
00:10:59,130 --> 00:11:02,540
Remember the arrow of time moves forward.

129
00:11:02,540 --> 00:11:04,010
We are not resetting the time yet.

130
00:11:04,050 --> 00:11:05,530
Time is still moving forward.

131
00:11:05,550 --> 00:11:08,580
It's going to reload when it's reached.

132
00:11:08,580 --> 00:11:10,130
Five hundred seconds.

133
00:11:10,140 --> 00:11:12,330
Like we said we know what time my set is.

134
00:11:12,330 --> 00:11:14,100
So I'm going to press again.

135
00:11:14,430 --> 00:11:20,910
Press again I can press and you can see our low pass filter is work into.

136
00:11:20,940 --> 00:11:21,400
Yeah.

137
00:11:21,420 --> 00:11:23,940
There is no deep answer to this is good.

138
00:11:23,940 --> 00:11:30,660
So this is how we we create an input capture timer using a Cuban makes.
