Hello fellas.
Welcome back.
So in this third lesson of the ATC section we're going to look at how to use timers to trigger ATC conversions
Lenton all time as in the previous section.
So I think there's the right time to combine time is an 86 to make really good applications and using
time to trigger ATC conversion becomes very important when you are doing something that requires precise
sampling.
You can actually set a timer to request the conversion from the ATC based on the period you set.
So if you don't understand what I just said don't worry we are going to demonstrate that now.
So let's go to Cuba mix and create our new project.
This is the old project where we left off.
I'll just come to my Cuba makes is right over here.
And I'm just going to close this and I'm going to minimize this and come to file new when I select my
board and my board is disco board and it's an F4 and it's this one over here
what I want is of course Claire opens
and like we're doing in this section my ATC channel is the ATC autonomous view which is connected to
my PSU and this in this particular lesson we want to additionally initialize a time to work with it.
So let's just use time to provide a clock source using the internal clock as the clock source for time
or two.
So once this is done we can go to the configurations top to continue configuration click over here and
then I start with the ATC and what I'm going to do is I'm just going to leave the resolution the same
and I'll come over here ATC regular conversion this under the section now select external trigger conversion
source and this is where I select my timer and like we chose over there we chose time of two and we
use it use in the out event that's the default.
So we're using time to alter event.
And like we realized before we realized keeping the default three cycles makes the thing free.
So let's just choose fairly normal cycle.
This is 56 cycle for sampling time so fifty six plus twelve.
I just do something less I'll choose eighty four cycles here.
Right.
Moving on so the only in we've made just to recap we kept the pre-school up I'll do everything the same.
You can reduce the clock size of the ATC here by choosing a different pre-schooler if you want.
I'm keeping it to the default.
I'm keeping the resolution to the default.
The only thing I change or what is required for time a trigger is to select the extend or treat our
source and then the type of the source so I've chosen time to trigger out event.
Yeah cause we're using timer too in its default trigger mode right.
Moving on.
So yeah.
And then finally for the ATC we have to enable the interrupt for the ADC.
So I just come over here and take here to enable my click OK.
Next let's go to the timer settings.
I'll click over here.
Time to show us we know by default our time a speed our time clock soars.
The internal clock soars twice the time of which forty eight megahertz so to bring the unit into into
milliseconds we have to divide it by forty eight thousand because I explained that already in the time
of videos as we said forty eight megahertz implies forty eight million cycles per second.
Therefore how many cycles do we need to get a millisecond.
And that's just forty eight thousand.
So if I put forty eight thousand here as a preschooler then my time or units becomes milliseconds.
And over here the count period becomes this sampling period.
Or if your ADC.
So if you are trying to sample a particular signal you put a sampling rate here.
So let's say we want to sample our ADC at let's say 50 milliseconds.
So I'm just going to put 50 here and you can convert this to frequency one or about 50 milliseconds
would give us the sampling frequency so once that is done you don't need to configure anything else.
We just click OK then generated the code so we could bring the timer down to millisecond unit and then
we set our sampling period.
Now we click OK they would come to the code generation.
Then I give my project and then ADC time trigger it is a time I trigger and then I select my two chain
as the call you vision five click.
By here and then it generates the code.
Once that is done I click to open my projects like this
then like I always do I'll just rebuild everything.
Then I would just update my.
Come over here click here and then take care.
OK then ok I'll expand here and inspect my code.
Now open may not see right.
Moving on.
So before we we able to get the ADC conversion when first nature started timer and the ADC.
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.
That's the name of the API.
This this function takes the time a handler as its arguments and we have the time a handler defined
up there it is h t I m too cautious time of two and which starts at a time on the stage.
Next we have to study ADC and I can see how ADC starts and this time we want to stop the ADC would interrupt.
Remember we take the box to allow ADC Globo interrupt.
Therefore we have to use to start to interrupt API and I select this and then I just put the argument
here which is the ADC handler
like this.
And once we have this actually we have to create a global variable like we did before to start our is
the conversion Valley in to on this coyotes Central Valley.
So because we are using interrupt we have to use a callback function to implement what happens when
the interrupt Cass to find a particular callback function use with the adc can just come over here and
then select the ADC module to see I'll just expand here and it's called Hall ADC conversion complete
callback should be somewhere here this one here so we can read about it it says regular conversion completes
callback in a non blocking mode pointer to ADC thus yeah blah blah blah we know this we did this with
the the would it time a callback so we just copy this and then we redefine it without the weak key word
I just put us here I just put it somewhere down here just keep this here and what I'm going to do is
I'm just going to stall my ADC I'm just going to store the value of the ADC conversion in my variable
here I'm going to see sense of I do it cause whole ADC get for you and this function takes the ADC handles
its arguments so I just put her ADC 1 and then it's fine.
So what's going to happen is every 50 milliseconds the funding of the ADC is screened to be collected
and stored in the in the sense of value variable we've declared in our experiment we are using their
potential meta.
So this really doesn't demonstrate the the effect of what we are doing here but you can imagine you
had a sense or like a temperature sensor or a heart rate you've designed a heart rate hardware and you
want to acquire the heartbeat every 10 milliseconds automatically every 10 milliseconds it will sample
it into the particular array or data structure that you've defined to store that type of data by no
example.
It's just going to be taken to the potential meta value and storing it in this variable here.
So I'm going to rebuild my project and then download onto my board.
So really this the limits of this experiment.
So as time goes on I'll find another sensor that actually requires precise sampling rate and then we'll
demonstrate to verify that indeed our system is something that's 50 milliseconds but this is how to
initialize and deploy timeout triggered a DC conversion.
If you have any questions or you need further elaboration do send me a message and I will see you in
the next lesson.