1
00:00:02,700 --> 00:00:03,420
Hello fellas.

2
00:00:03,450 --> 00:00:04,230
Welcome back.

3
00:00:04,230 --> 00:00:12,000
So in this third lesson of the ATC section we're going to look at how to use timers to trigger ATC conversions

4
00:00:12,290 --> 00:00:14,610
Lenton all time as in the previous section.

5
00:00:14,730 --> 00:00:21,890
So I think there's the right time to combine time is an 86 to make really good applications and using

6
00:00:21,930 --> 00:00:28,410
time to trigger ATC conversion becomes very important when you are doing something that requires precise

7
00:00:28,500 --> 00:00:29,460
sampling.

8
00:00:29,460 --> 00:00:35,290
You can actually set a timer to request the conversion from the ATC based on the period you set.

9
00:00:35,300 --> 00:00:40,550
So if you don't understand what I just said don't worry we are going to demonstrate that now.

10
00:00:40,570 --> 00:00:43,550
So let's go to Cuba mix and create our new project.

11
00:00:43,560 --> 00:00:45,450
This is the old project where we left off.

12
00:00:45,480 --> 00:00:48,110
I'll just come to my Cuba makes is right over here.

13
00:00:49,770 --> 00:00:58,030
And I'm just going to close this and I'm going to minimize this and come to file new when I select my

14
00:00:58,030 --> 00:01:06,770
board and my board is disco board and it's an F4 and it's this one over here

15
00:01:09,910 --> 00:01:12,170
what I want is of course Claire opens

16
00:01:14,980 --> 00:01:21,080
and like we're doing in this section my ATC channel is the ATC autonomous view which is connected to

17
00:01:21,080 --> 00:01:28,040
my PSU and this in this particular lesson we want to additionally initialize a time to work with it.

18
00:01:28,400 --> 00:01:34,220
So let's just use time to provide a clock source using the internal clock as the clock source for time

19
00:01:34,220 --> 00:01:35,140
or two.

20
00:01:35,150 --> 00:01:41,270
So once this is done we can go to the configurations top to continue configuration click over here and

21
00:01:41,270 --> 00:01:47,090
then I start with the ATC and what I'm going to do is I'm just going to leave the resolution the same

22
00:01:47,540 --> 00:01:56,000
and I'll come over here ATC regular conversion this under the section now select external trigger conversion

23
00:01:56,000 --> 00:02:02,450
source and this is where I select my timer and like we chose over there we chose time of two and we

24
00:02:02,450 --> 00:02:07,010
use it use in the out event that's the default.

25
00:02:07,130 --> 00:02:09,450
So we're using time to alter event.

26
00:02:09,740 --> 00:02:16,400
And like we realized before we realized keeping the default three cycles makes the thing free.

27
00:02:16,460 --> 00:02:20,210
So let's just choose fairly normal cycle.

28
00:02:20,270 --> 00:02:23,970
This is 56 cycle for sampling time so fifty six plus twelve.

29
00:02:24,140 --> 00:02:28,680
I just do something less I'll choose eighty four cycles here.

30
00:02:28,770 --> 00:02:29,090
Right.

31
00:02:29,090 --> 00:02:37,490
Moving on so the only in we've made just to recap we kept the pre-school up I'll do everything the same.

32
00:02:37,490 --> 00:02:43,190
You can reduce the clock size of the ATC here by choosing a different pre-schooler if you want.

33
00:02:43,220 --> 00:02:44,450
I'm keeping it to the default.

34
00:02:44,450 --> 00:02:46,800
I'm keeping the resolution to the default.

35
00:02:46,880 --> 00:02:52,430
The only thing I change or what is required for time a trigger is to select the extend or treat our

36
00:02:52,430 --> 00:02:58,170
source and then the type of the source so I've chosen time to trigger out event.

37
00:02:58,260 --> 00:03:03,080
Yeah cause we're using timer too in its default trigger mode right.

38
00:03:03,110 --> 00:03:03,650
Moving on.

39
00:03:04,340 --> 00:03:05,330
So yeah.

40
00:03:05,390 --> 00:03:09,610
And then finally for the ATC we have to enable the interrupt for the ADC.

41
00:03:09,620 --> 00:03:13,710
So I just come over here and take here to enable my click OK.

42
00:03:13,880 --> 00:03:16,710
Next let's go to the timer settings.

43
00:03:16,720 --> 00:03:17,800
I'll click over here.

44
00:03:17,810 --> 00:03:23,150
Time to show us we know by default our time a speed our time clock soars.

45
00:03:23,150 --> 00:03:30,500
The internal clock soars twice the time of which forty eight megahertz so to bring the unit into into

46
00:03:30,500 --> 00:03:36,320
milliseconds we have to divide it by forty eight thousand because I explained that already in the time

47
00:03:36,320 --> 00:03:44,420
of videos as we said forty eight megahertz implies forty eight million cycles per second.

48
00:03:44,420 --> 00:03:48,610
Therefore how many cycles do we need to get a millisecond.

49
00:03:48,670 --> 00:03:51,500
And that's just forty eight thousand.

50
00:03:51,500 --> 00:03:57,220
So if I put forty eight thousand here as a preschooler then my time or units becomes milliseconds.

51
00:03:57,240 --> 00:04:00,680
And over here the count period becomes this sampling period.

52
00:04:00,680 --> 00:04:02,030
Or if your ADC.

53
00:04:02,030 --> 00:04:06,670
So if you are trying to sample a particular signal you put a sampling rate here.

54
00:04:06,710 --> 00:04:13,540
So let's say we want to sample our ADC at let's say 50 milliseconds.

55
00:04:13,700 --> 00:04:19,070
So I'm just going to put 50 here and you can convert this to frequency one or about 50 milliseconds

56
00:04:19,110 --> 00:04:25,200
would give us the sampling frequency so once that is done you don't need to configure anything else.

57
00:04:25,220 --> 00:04:33,020
We just click OK then generated the code so we could bring the timer down to millisecond unit and then

58
00:04:33,020 --> 00:04:35,650
we set our sampling period.

59
00:04:35,670 --> 00:04:39,810
Now we click OK they would come to the code generation.

60
00:04:39,950 --> 00:04:49,840
Then I give my project and then ADC time trigger it is a time I trigger and then I select my two chain

61
00:04:49,840 --> 00:04:52,990
as the call you vision five click.

62
00:04:53,030 --> 00:04:56,080
By here and then it generates the code.

63
00:04:56,080 --> 00:04:59,820
Once that is done I click to open my projects like this

64
00:05:03,870 --> 00:05:06,690
then like I always do I'll just rebuild everything.

65
00:05:09,190 --> 00:05:11,380
Then I would just update my.

66
00:05:11,450 --> 00:05:17,030
Come over here click here and then take care.

67
00:05:17,660 --> 00:05:22,320
OK then ok I'll expand here and inspect my code.

68
00:05:22,410 --> 00:05:25,100
Now open may not see right.

69
00:05:25,120 --> 00:05:25,640
Moving on.

70
00:05:26,780 --> 00:05:33,170
So before we we able to get the ADC conversion when first nature started timer and the ADC.

71
00:05:33,320 --> 00:05:42,800
So I'm going to come over here and the main function I'm going to see how T I N for timer base starts.

72
00:05:42,890 --> 00:05:47,400
That's the name of the API.

73
00:05:47,460 --> 00:05:54,300
This this function takes the time a handler as its arguments and we have the time a handler defined

74
00:05:54,320 --> 00:06:02,380
up there it is h t I m too cautious time of two and which starts at a time on the stage.

75
00:06:02,390 --> 00:06:14,860
Next we have to study ADC and I can see how ADC starts and this time we want to stop the ADC would interrupt.

76
00:06:14,860 --> 00:06:19,180
Remember we take the box to allow ADC Globo interrupt.

77
00:06:19,180 --> 00:06:26,770
Therefore we have to use to start to interrupt API and I select this and then I just put the argument

78
00:06:26,770 --> 00:06:28,860
here which is the ADC handler

79
00:06:32,090 --> 00:06:33,180
like this.

80
00:06:33,350 --> 00:06:38,780
And once we have this actually we have to create a global variable like we did before to start our is

81
00:06:38,780 --> 00:06:43,390
the conversion Valley in to on this coyotes Central Valley.

82
00:06:43,640 --> 00:06:49,730
So because we are using interrupt we have to use a callback function to implement what happens when

83
00:06:49,730 --> 00:06:55,820
the interrupt Cass to find a particular callback function use with the adc can just come over here and

84
00:06:55,820 --> 00:07:03,440
then select the ADC module to see I'll just expand here and it's called Hall ADC conversion complete

85
00:07:03,770 --> 00:07:12,530
callback should be somewhere here this one here so we can read about it it says regular conversion completes

86
00:07:12,530 --> 00:07:19,250
callback in a non blocking mode pointer to ADC thus yeah blah blah blah we know this we did this with

87
00:07:19,250 --> 00:07:26,790
the the would it time a callback so we just copy this and then we redefine it without the weak key word

88
00:07:27,030 --> 00:07:35,830
I just put us here I just put it somewhere down here just keep this here and what I'm going to do is

89
00:07:35,890 --> 00:07:41,740
I'm just going to stall my ADC I'm just going to store the value of the ADC conversion in my variable

90
00:07:41,740 --> 00:07:48,660
here I'm going to see sense of I do it cause whole ADC get for you and this function takes the ADC handles

91
00:07:48,760 --> 00:07:53,940
its arguments so I just put her ADC 1 and then it's fine.

92
00:07:54,040 --> 00:07:59,770
So what's going to happen is every 50 milliseconds the funding of the ADC is screened to be collected

93
00:07:59,770 --> 00:08:06,390
and stored in the in the sense of value variable we've declared in our experiment we are using their

94
00:08:06,400 --> 00:08:07,420
potential meta.

95
00:08:07,450 --> 00:08:13,210
So this really doesn't demonstrate the the effect of what we are doing here but you can imagine you

96
00:08:13,210 --> 00:08:19,390
had a sense or like a temperature sensor or a heart rate you've designed a heart rate hardware and you

97
00:08:19,390 --> 00:08:25,600
want to acquire the heartbeat every 10 milliseconds automatically every 10 milliseconds it will sample

98
00:08:25,600 --> 00:08:32,860
it into the particular array or data structure that you've defined to store that type of data by no

99
00:08:32,860 --> 00:08:33,510
example.

100
00:08:34,360 --> 00:08:39,790
It's just going to be taken to the potential meta value and storing it in this variable here.

101
00:08:39,880 --> 00:08:45,520
So I'm going to rebuild my project and then download onto my board.

102
00:08:45,610 --> 00:08:48,930
So really this the limits of this experiment.

103
00:08:49,330 --> 00:08:55,200
So as time goes on I'll find another sensor that actually requires precise sampling rate and then we'll

104
00:08:55,210 --> 00:09:01,390
demonstrate to verify that indeed our system is something that's 50 milliseconds but this is how to

105
00:09:01,390 --> 00:09:05,460
initialize and deploy timeout triggered a DC conversion.

106
00:09:05,470 --> 00:09:11,290
If you have any questions or you need further elaboration do send me a message and I will see you in

107
00:09:11,290 --> 00:09:12,430
the next lesson.
