1
00:00:01,580 --> 00:00:08,690
We are going to demonstrate how to program the outputs compare going to demonstrate the output to compare

2
00:00:08,690 --> 00:00:09,800
functionality.

3
00:00:09,800 --> 00:00:15,530
What we're going to do is we're going to initialize all our four entities and we're going to let them

4
00:00:16,070 --> 00:00:19,730
go on and on a specific times using outputs compare.

5
00:00:20,180 --> 00:00:25,850
And for those of you who are not familiar with output compare output compare the ability to trigger

6
00:00:25,880 --> 00:00:29,170
an output based on a particular timestamp.

7
00:00:29,270 --> 00:00:35,180
And we're not going to be using if else in the state is going to be that event will result in a hardware

8
00:00:35,180 --> 00:00:38,400
interrupt also known as outputs compare interrupt.

9
00:00:38,480 --> 00:00:40,960
So we're going to set a particular timestamp.

10
00:00:41,090 --> 00:00:47,660
We're going to say red should be should come on after 50 milliseconds Irene should come on after 30

11
00:00:47,660 --> 00:00:53,800
milliseconds Quinn should come on after let's say 100 milliseconds and the cycle continues.

12
00:00:53,960 --> 00:01:00,350
And this this is turned on and off using hardware interrupts anyway if you need more information on

13
00:01:00,380 --> 00:01:03,740
output compared to drugs just in their message or legal questions below.

14
00:01:04,010 --> 00:01:10,760
So we're going to demonstrate that now and I'm going to come to Cuba makes and I'm going to create a

15
00:01:10,760 --> 00:01:12,930
new project.

16
00:01:13,570 --> 00:01:14,960
I'll come over here.

17
00:01:14,950 --> 00:01:19,670
You project and I select my board.

18
00:01:19,670 --> 00:01:29,830
The board is that disco board that's the f 4 and this is my board over here and once it's generated

19
00:01:29,860 --> 00:01:36,850
what I want to do is clear all pins I click over here to clear the pins and what I want is I'm going

20
00:01:36,850 --> 00:01:44,560
to initialize my abilities to work with a timer so I know my entities are connected to PD 12 13 14 and

21
00:01:44,560 --> 00:01:53,420
15 I just click over here and set it to output compare I can set it to timer for Channel 1 cost us the

22
00:01:53,430 --> 00:01:59,080
timer it's got access to and I click this this one is connected to time off for Channel 2 so I just

23
00:01:59,080 --> 00:02:00,320
use that time I trust.

24
00:02:00,730 --> 00:02:08,530
So if the if the particular GPA pin had no access to the time a module wouldn't have been able to use

25
00:02:08,530 --> 00:02:14,830
the output compared in this case so I click this and this yellow marks means the initialization of this

26
00:02:14,920 --> 00:02:22,330
is incomplete that that is why it's not green mean and it requires further initialization of configuration

27
00:02:22,690 --> 00:02:23,590
before we complete.

28
00:02:23,590 --> 00:02:29,860
So to do that I'm just going to come over here to the time a module which time this time or force or

29
00:02:29,860 --> 00:02:38,870
click time of four over here and what I want is to enable the channel one as an output to compare like

30
00:02:39,090 --> 00:02:46,010
this and then to enable channel to us all to compare as well.

31
00:02:46,010 --> 00:02:54,780
Same for Channel 3 Channel 4 and what I want is to provide a clock source here I'm going to use the

32
00:02:54,780 --> 00:02:56,660
internal clock here.

33
00:02:56,670 --> 00:02:58,680
Now I'm set I'm set.

34
00:02:58,680 --> 00:02:59,670
What I have to do next.

35
00:02:59,670 --> 00:03:07,880
Of course is to enable mighty Barker or select overhead and choose the serial wire and I'm set to know

36
00:03:07,910 --> 00:03:14,750
what I have to do is go and configure my time on the pre scalar value in the period or the frequency

37
00:03:14,780 --> 00:03:15,900
of the timer.

38
00:03:16,040 --> 00:03:22,660
So to do the I've just come to configuration and I would just keep my default clock set in here.

39
00:03:22,700 --> 00:03:25,930
So now we have to configure our timer and to do that.

40
00:03:25,960 --> 00:03:32,000
We just click over here and like we did before we have to set a pre-schooler of the timer currently

41
00:03:32,000 --> 00:03:38,150
the timer is in the second unit we want to bring the unit into milliseconds to do that.

42
00:03:38,390 --> 00:03:46,130
We know our timer clock is forty eight megahertz from the clock tree over here as we can see is 48.

43
00:03:46,130 --> 00:03:52,070
So to bring this down to milliseconds we have to divide it by four thousand eight hundred

44
00:03:54,370 --> 00:04:03,860
configuration timer so I put four thousand eight hundred here like this and we want our counter period

45
00:04:03,890 --> 00:04:06,290
to be one second.

46
00:04:06,350 --> 00:04:08,000
So I put 1000 here.

47
00:04:08,000 --> 00:04:12,500
If you don't understand the origins of of these numbers do send me a message or leave your question

48
00:04:12,500 --> 00:04:12,830
below.

49
00:04:13,190 --> 00:04:17,030
And after that we wonder countermove to be up count mode.

50
00:04:17,030 --> 00:04:20,270
And now we have to configure each channel over here.

51
00:04:20,300 --> 00:04:24,250
I've configured them already I have output to compare Channel 1.

52
00:04:24,470 --> 00:04:28,530
And I wonder more to be toggle on much select toggle on March.

53
00:04:28,550 --> 00:04:35,570
And the power should be 200 m M.S. meaning I want this particular channel to toggle every one fifth

54
00:04:35,630 --> 00:04:37,970
of a second every one fifth of it.

55
00:04:37,970 --> 00:04:44,440
Second I want this channel to toggle and four channel to every half a second because I've got 500 here.

56
00:04:44,730 --> 00:04:48,020
And remember a second is equal to 1000.

57
00:04:48,080 --> 00:04:55,160
So every half a second I want Channel 2 to Tokyo and every 3 fourth of a second I want to channel 3

58
00:04:55,160 --> 00:04:59,010
to toggle and I want Channel 4 to toggle every second.

59
00:04:59,120 --> 00:05:05,090
So each channel you changed a mode to toggle on March and then you set the pulse rate so there's the

60
00:05:05,090 --> 00:05:07,100
pulse rate of each channel.

61
00:05:07,630 --> 00:05:11,510
So once that is done we move on to the next configuration.

62
00:05:11,510 --> 00:05:18,970
We can leave everything else the same click okay here and it's all set.

63
00:05:19,030 --> 00:05:26,350
Next what we have to do is generate our code and I'll just come over here and click to generate and

64
00:05:27,190 --> 00:05:39,310
I'll give my project a name timer on the score article compare my school output compare and then I'll

65
00:05:39,310 --> 00:05:45,580
choose my two chain which is to call in decay version 5 I'll select this here and everything else is

66
00:05:45,580 --> 00:05:51,880
the same so click okay and it generates and then it's done and then I'll click over here to vote in

67
00:05:51,880 --> 00:05:58,110
the project and once it is open I will just rebuild to bind everything

68
00:06:02,240 --> 00:06:10,050
and once I start I'll just set my debugger to run on reset just by clicking over here then taking this

69
00:06:10,050 --> 00:06:11,170
here.

70
00:06:11,370 --> 00:06:12,440
Okay then.

71
00:06:12,450 --> 00:06:19,290
Okay so I just explained this this one here and check the main file and the only thing I have to do

72
00:06:19,290 --> 00:06:25,920
here is at the time of Chanos and I set my sights on it would kick in and do its work.

73
00:06:26,100 --> 00:06:33,440
What I want to do is I want to come to functions and see which particular function I need for this so

74
00:06:33,530 --> 00:06:37,970
I'll click over here to see all the options I've got for this particular module.

75
00:06:38,190 --> 00:06:43,760
So let's see what we need in order to be able to start on the output compare.

76
00:06:43,770 --> 00:06:46,040
We need this particular API here.

77
00:06:46,080 --> 00:06:48,800
Hall time output to compare starts.

78
00:06:48,840 --> 00:06:51,220
Let's double click and see what it takes.

79
00:06:51,600 --> 00:06:55,000
As you can see these documents the various parameters here.

80
00:06:55,110 --> 00:06:57,060
It takes the time I know.

81
00:06:57,130 --> 00:07:00,960
And then it takes it points to the timer structure.

82
00:07:01,050 --> 00:07:04,170
So this one here takes appointed to the timer structure.

83
00:07:04,200 --> 00:07:11,380
This takes the time which I know so let's just copy this function and go and customize it to start our

84
00:07:11,380 --> 00:07:18,090
article with compare to put us here and of course I'll delete this.

85
00:07:18,090 --> 00:07:21,360
We already know our time up on the structure.

86
00:07:21,360 --> 00:07:25,260
Is this defined over here as h t n h in 4.

87
00:07:25,280 --> 00:07:29,300
I just copy this and then I'll bring it here like we saw it.

88
00:07:29,360 --> 00:07:34,090
It takes this argument with Ampersand sign like this.

89
00:07:34,100 --> 00:07:35,040
I don't believe this.

90
00:07:35,070 --> 00:07:38,580
And then no one can put the China no overhead

91
00:07:41,430 --> 00:07:45,750
I can just say time on a school China one.

92
00:07:46,180 --> 00:07:53,760
Then I've started China one I can copy and paste for the other three put is this for this and I could

93
00:07:53,760 --> 00:07:56,840
just change this too.

94
00:07:57,210 --> 00:08:03,930
And in fact that's all we need to do we just need to start out the timer and we don't need to do anything

95
00:08:03,930 --> 00:08:04,160
else.

96
00:08:04,170 --> 00:08:09,740
Let's deal with the code and download on top board and we're building No.

97
00:08:09,860 --> 00:08:17,880
And as you can see the LCD is Blinken in the sequence we programmed the pose is blinking in the time

98
00:08:17,880 --> 00:08:20,210
period we give each the D.

99
00:08:20,280 --> 00:08:26,250
So this is the use of output compare this how easy it is to create such code in this example we just

100
00:08:26,250 --> 00:08:33,120
use an LCD as output but like I said if you want to understand details of this how output compare works

101
00:08:33,480 --> 00:08:38,750
the internals just send me a message or just leave your question below this.

102
00:08:38,780 --> 00:08:45,750
This course is he had to teach you how to rapidly use the SDR SDM Cuban mix to prototype your work and

103
00:08:45,760 --> 00:08:51,390
suggest generates code with it we don't go into the details of the pair for development but if that

104
00:08:51,390 --> 00:08:54,750
is something you are interested in I'm always willing to help.

105
00:08:54,810 --> 00:08:56,460
I'll see you in the next lesson.
