We are going to demonstrate how to program the outputs compare going to demonstrate the output to compare
functionality.
What we're going to do is we're going to initialize all our four entities and we're going to let them
go on and on a specific times using outputs compare.
And for those of you who are not familiar with output compare output compare the ability to trigger
an output based on a particular timestamp.
And we're not going to be using if else in the state is going to be that event will result in a hardware
interrupt also known as outputs compare interrupt.
So we're going to set a particular timestamp.
We're going to say red should be should come on after 50 milliseconds Irene should come on after 30
milliseconds Quinn should come on after let's say 100 milliseconds and the cycle continues.
And this this is turned on and off using hardware interrupts anyway if you need more information on
output compared to drugs just in their message or legal questions below.
So we're going to demonstrate that now and I'm going to come to Cuba makes and I'm going to create a
new project.
I'll come over here.
You project and I select my board.
The board is that disco board that's the f 4 and this is my board over here and once it's generated
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
to initialize my abilities to work with a timer so I know my entities are connected to PD 12 13 14 and
15 I just click over here and set it to output compare I can set it to timer for Channel 1 cost us the
timer it's got access to and I click this this one is connected to time off for Channel 2 so I just
use that time I trust.
So if the if the particular GPA pin had no access to the time a module wouldn't have been able to use
the output compared in this case so I click this and this yellow marks means the initialization of this
is incomplete that that is why it's not green mean and it requires further initialization of configuration
before we complete.
So to do that I'm just going to come over here to the time a module which time this time or force or
click time of four over here and what I want is to enable the channel one as an output to compare like
this and then to enable channel to us all to compare as well.
Same for Channel 3 Channel 4 and what I want is to provide a clock source here I'm going to use the
internal clock here.
Now I'm set I'm set.
What I have to do next.
Of course is to enable mighty Barker or select overhead and choose the serial wire and I'm set to know
what I have to do is go and configure my time on the pre scalar value in the period or the frequency
of the timer.
So to do the I've just come to configuration and I would just keep my default clock set in here.
So now we have to configure our timer and to do that.
We just click over here and like we did before we have to set a pre-schooler of the timer currently
the timer is in the second unit we want to bring the unit into milliseconds to do that.
We know our timer clock is forty eight megahertz from the clock tree over here as we can see is 48.
So to bring this down to milliseconds we have to divide it by four thousand eight hundred
configuration timer so I put four thousand eight hundred here like this and we want our counter period
to be one second.
So I put 1000 here.
If you don't understand the origins of of these numbers do send me a message or leave your question
below.
And after that we wonder countermove to be up count mode.
And now we have to configure each channel over here.
I've configured them already I have output to compare Channel 1.
And I wonder more to be toggle on much select toggle on March.
And the power should be 200 m M.S. meaning I want this particular channel to toggle every one fifth
of a second every one fifth of it.
Second I want this channel to toggle and four channel to every half a second because I've got 500 here.
And remember a second is equal to 1000.
So every half a second I want Channel 2 to Tokyo and every 3 fourth of a second I want to channel 3
to toggle and I want Channel 4 to toggle every second.
So each channel you changed a mode to toggle on March and then you set the pulse rate so there's the
pulse rate of each channel.
So once that is done we move on to the next configuration.
We can leave everything else the same click okay here and it's all set.
Next what we have to do is generate our code and I'll just come over here and click to generate and
I'll give my project a name timer on the score article compare my school output compare and then I'll
choose my two chain which is to call in decay version 5 I'll select this here and everything else is
the same so click okay and it generates and then it's done and then I'll click over here to vote in
the project and once it is open I will just rebuild to bind everything
and once I start I'll just set my debugger to run on reset just by clicking over here then taking this
here.
Okay then.
Okay so I just explained this this one here and check the main file and the only thing I have to do
here is at the time of Chanos and I set my sights on it would kick in and do its work.
What I want to do is I want to come to functions and see which particular function I need for this so
I'll click over here to see all the options I've got for this particular module.
So let's see what we need in order to be able to start on the output compare.
We need this particular API here.
Hall time output to compare starts.
Let's double click and see what it takes.
As you can see these documents the various parameters here.
It takes the time I know.
And then it takes it points to the timer structure.
So this one here takes appointed to the timer structure.
This takes the time which I know so let's just copy this function and go and customize it to start our
article with compare to put us here and of course I'll delete this.
We already know our time up on the structure.
Is this defined over here as h t n h in 4.
I just copy this and then I'll bring it here like we saw it.
It takes this argument with Ampersand sign like this.
I don't believe this.
And then no one can put the China no overhead
I can just say time on a school China one.
Then I've started China one I can copy and paste for the other three put is this for this and I could
just change this too.
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
else.
Let's deal with the code and download on top board and we're building No.
And as you can see the LCD is Blinken in the sequence we programmed the pose is blinking in the time
period we give each the D.
So this is the use of output compare this how easy it is to create such code in this example we just
use an LCD as output but like I said if you want to understand details of this how output compare works
the internals just send me a message or just leave your question below this.
This course is he had to teach you how to rapidly use the SDR SDM Cuban mix to prototype your work and
suggest generates code with it we don't go into the details of the pair for development but if that
is something you are interested in I'm always willing to help.
I'll see you in the next lesson.