1
00:00:00,900 --> 00:00:01,250
Hello.

2
00:00:01,260 --> 00:00:01,950
Welcome back.

3
00:00:01,950 --> 00:00:07,160
In this lesson we're going to see how to use the ADC with time trigger.

4
00:00:07,170 --> 00:00:13,140
We're going to write a program that converts the ownership temperature sense or output use in some poor

5
00:00:13,140 --> 00:00:17,320
sequence of three and timer trigger at 1 Hertz.

6
00:00:17,340 --> 00:00:18,880
Let's see how to do that.

7
00:00:18,900 --> 00:00:19,790
Come over here.

8
00:00:19,800 --> 00:00:25,850
Project create a new format for this call ADC.

9
00:00:26,060 --> 00:00:41,570
Call the time a trigger and then the project ADC timeout trigger and deploy this team 4C 1 2 3 through

10
00:00:41,620 --> 00:00:42,790
page 6 p.m..

11
00:00:43,640 --> 00:00:46,030
This over here okay.

12
00:00:46,440 --> 00:00:46,970
Then

13
00:00:50,550 --> 00:00:55,920
devices call lets you is also a startup over here.

14
00:00:56,240 --> 00:00:58,450
Device startup CRM call.

15
00:00:58,460 --> 00:00:58,930
Okay.

16
00:00:59,590 --> 00:01:00,070
Okay.

17
00:01:00,070 --> 00:01:01,480
Over here.

18
00:01:01,540 --> 00:01:03,080
I renamed this to the name of the port.

19
00:01:03,110 --> 00:01:04,150
Tim 4C.

20
00:01:04,220 --> 00:01:08,310
One two three no Trump down over here.

21
00:01:09,700 --> 00:01:16,230
BPP and then target options changed us to 16.

22
00:01:16,250 --> 00:01:18,780
Then come to the back of my head dropdown.

23
00:01:18,780 --> 00:01:22,920
Still there is ICD I click over here resets and around.

24
00:01:22,920 --> 00:01:24,380
Okay okay.

25
00:01:24,460 --> 00:01:33,720
And then come over here right click a new item it's c file may that see like this so we're gonna start

26
00:01:33,720 --> 00:01:36,970
off by including our port header.

27
00:01:37,050 --> 00:01:38,880
This over here.

28
00:01:38,880 --> 00:01:41,350
Once they start we can open our main function.

29
00:01:52,390 --> 00:01:56,940
We start off by enabling clock to our our ADC as well as our timer.

30
00:01:56,980 --> 00:02:06,190
We're going to use wide timer 0 for this won't use a top a timer or a white timer so I'll a system control

31
00:02:06,370 --> 00:02:09,080
our CTC over here.

32
00:02:09,140 --> 00:02:18,330
AC DC ADC we use an ADC module 0 so we can pass your X through one over here to enable clock access.

33
00:02:18,610 --> 00:02:22,630
Once that's done we're going to use Y to time a block 0 so I'm going to say system control

34
00:02:25,390 --> 00:02:40,220
our CTC the timer over here then I'm going to pass one course when I pass this sure of X one over here.

35
00:02:40,300 --> 00:02:41,150
Once that is done

36
00:02:44,900 --> 00:02:49,920
we initialize the ADC first and then we move onto the timer.

37
00:02:49,920 --> 00:02:53,380
I'm going to start off by disabling these sample sequence at 3.

38
00:02:53,380 --> 00:02:57,280
First I'll say ADC 0

39
00:03:00,310 --> 00:03:05,770
DCT SS part 8 over here.

40
00:03:05,770 --> 00:03:08,240
Once that's done I'm going to do it.

41
00:03:08,270 --> 00:03:11,200
This year marks

42
00:03:14,680 --> 00:03:22,260
then going to pass your x F and then 3 0 0 1 2 3.

43
00:03:22,260 --> 00:03:29,590
This next line of the earmarks access is what is going to enable the the time a trigger.

44
00:03:29,730 --> 00:03:33,720
So I'll say it is a zero and then we access earmarks again.

45
00:03:33,720 --> 00:03:37,610
We could have just admitted this but it's often done.

46
00:03:38,160 --> 00:03:41,380
Earmarks and then I'm going to press your ex over here.

47
00:03:41,640 --> 00:03:42,240
5.

48
00:03:42,250 --> 00:03:46,370
Here's your 3 series after the 5 and this selected time a trigger.

49
00:03:46,500 --> 00:03:50,970
So it the new stuff in this lesson time trigger

50
00:03:59,960 --> 00:04:07,220
and once they start I'm going to get input from 10 0 0 7 ATC 0

51
00:04:11,820 --> 00:04:19,240
SS Mark's theory and then I'll pass you here and then once they start I'm going to take the chip temperature

52
00:04:19,680 --> 00:04:21,120
sets flag.

53
00:04:21,160 --> 00:04:25,540
That's the first sample so we'll see indices 0.

54
00:04:26,140 --> 00:04:28,880
Since we've got just one sample we've got to set off like that.

55
00:04:29,440 --> 00:04:36,910
So I'll say it C0 and then I'll see it SS control number three over here and then I'm going to pass

56
00:04:37,300 --> 00:04:40,050
two x three

57
00:05:03,310 --> 00:05:13,110
once that's done I'm going to enable these samples sequence of three between indices here is t ss then

58
00:05:13,140 --> 00:05:15,480
I'll post number eight here right.

59
00:05:15,510 --> 00:05:18,190
Once we've done this we can initialize the Y timer

60
00:05:24,760 --> 00:05:33,810
gonna start off by disabling the timer before initialization can I say w timer zero control register

61
00:05:34,730 --> 00:05:45,400
pass you here once that's done I'm going to select the 32 bit option by doing w timer 0 and then configuration

62
00:05:45,400 --> 00:05:51,460
register cause to x 2 for

63
00:05:57,260 --> 00:06:07,340
once they start going to set it to periodic mode and down counter mode so I'm gonna set a timer t in

64
00:06:07,400 --> 00:06:12,560
my register gonna pass here x purity here

65
00:06:23,980 --> 00:06:31,390
I'm going to set the value of the interval load register since we want 1 Hertz mean and once per second

66
00:06:31,870 --> 00:06:34,540
I'm going to load sixteen million here.

67
00:06:34,790 --> 00:06:36,610
So come over here and set up your time.

68
00:06:38,530 --> 00:06:39,580
0.

69
00:06:39,730 --> 00:06:45,610
I'll go to the timer interval load register and then I'm going to pass sixteen.

70
00:06:45,610 --> 00:06:46,540
One two three.

71
00:06:46,540 --> 00:06:47,830
One two three.

72
00:06:48,130 --> 00:06:49,190
Like this.

73
00:06:49,390 --> 00:06:56,500
Once they start I'm going to select the timer trigger ADC over here in the control register by S.W.

74
00:06:56,500 --> 00:07:07,670
time I 0 CTO and I'll come over here and pass 0 x to 0 and then I'm going to enable a timer a going

75
00:07:07,680 --> 00:07:12,820
to enable a timer by saying w timer zero control register

76
00:07:15,490 --> 00:07:20,500
your X 01 here like this.

77
00:07:20,500 --> 00:07:26,800
Once that is done we can start conversion and wait for conversion to complete a wild one over here

78
00:07:33,730 --> 00:07:36,960
open close and I'll see Quark

79
00:07:40,770 --> 00:07:45,260
this is 0 rice and 8

80
00:07:48,540 --> 00:07:51,640
because zero.

81
00:07:52,310 --> 00:07:56,290
We have to wait for conversion to complete to truly open inclusive I hear.

82
00:07:56,560 --> 00:08:03,380
And then when I create a global variable here quite a temporary chart to store devalue

83
00:08:06,630 --> 00:08:08,360
I

84
00:08:11,200 --> 00:08:11,830
come here.

85
00:08:11,870 --> 00:08:12,490
Temperature

86
00:08:15,660 --> 00:08:26,910
because one forty seven minus two forty seven multiply by the KDE value which is eighty says your SS

87
00:08:26,910 --> 00:08:38,150
five four three over here divided by twelve feet which is four thousand and ninety six right.

88
00:08:38,170 --> 00:08:47,350
And once we've done this we've got to clear the completion flight by doing 80 C0 ISC over here and then

89
00:08:47,440 --> 00:08:48,520
we pass it here

90
00:09:01,920 --> 00:09:02,220
right.

91
00:09:02,310 --> 00:09:03,570
Let's build and see what we have

92
00:09:06,500 --> 00:09:07,490
built successfully.

93
00:09:07,490 --> 00:09:08,180
We know Aero.

94
00:09:08,300 --> 00:09:14,200
Let's get on our board and see our looks so let's download the code onto our board.

95
00:09:14,250 --> 00:09:17,860
Click over here and it's downloaded successfully.

96
00:09:17,950 --> 00:09:19,440
Point click here to go to the debug.

97
00:09:19,470 --> 00:09:29,030
You okay.

98
00:09:30,020 --> 00:09:36,400
And I'm going to add our global variable to the watch window double click on temperature here right

99
00:09:36,430 --> 00:09:46,000
click and then out towards window one over here once they start I'm going to disable hexadecimal display

100
00:09:46,030 --> 00:09:47,980
by clicking here like this.

101
00:09:48,130 --> 00:09:53,580
Then I'll click here to run the code and indeed.

102
00:09:53,770 --> 00:09:55,510
So this the temperature reading.

103
00:09:55,600 --> 00:09:57,610
It's been converted into temperature.

104
00:09:57,670 --> 00:09:59,480
It looks a bit unstable here.

105
00:09:59,560 --> 00:10:06,670
We may want to add a bit of a filter to stabilize it but this is the value from our internal temperature

106
00:10:06,670 --> 00:10:11,600
sensor or being converted into its temperature value here.

107
00:10:11,680 --> 00:10:11,980
Right.

108
00:10:12,010 --> 00:10:18,410
So we read it from the ADC and then we use in this simple equation here to convert to its temperature.

109
00:10:18,460 --> 00:10:23,950
I'm going to put my hand on the MCU to see if I can influence the temperature a bit I place my hand

110
00:10:23,950 --> 00:10:24,280
here

111
00:10:31,810 --> 00:10:32,210
right.

112
00:10:32,780 --> 00:10:34,190
So that's all there is for this lesson.

113
00:10:34,190 --> 00:10:37,440
If you have any questions at all to send me a message.

114
00:10:37,620 --> 00:10:41,080
And over here we're using the timer to trigger the ADC as well.

115
00:10:41,090 --> 00:10:44,960
So we have the timer initialized and I'll see you later.
