Hello.
Welcome back.
In this lesson we're going to see how to use the ADC with time trigger.
We're going to write a program that converts the ownership temperature sense or output use in some poor
sequence of three and timer trigger at 1 Hertz.
Let's see how to do that.
Come over here.
Project create a new format for this call ADC.
Call the time a trigger and then the project ADC timeout trigger and deploy this team 4C 1 2 3 through
page 6 p.m..
This over here okay.
Then
devices call lets you is also a startup over here.
Device startup CRM call.
Okay.
Over here.
I renamed this to the name of the port.
Tim 4C.
One two three no Trump down over here.
BPP and then target options changed us to 16.
Then come to the back of my head dropdown.
Still there is ICD I click over here resets and around.
Okay okay.
And then come over here right click a new item it's c file may that see like this so we're gonna start
off by including our port header.
This over here.
Once they start we can open our main function.
We start off by enabling clock to our our ADC as well as our timer.
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
our CTC over here.
AC DC ADC we use an ADC module 0 so we can pass your X through one over here to enable clock access.
Once that's done we're going to use Y to time a block 0 so I'm going to say system control
our CTC the timer over here then I'm going to pass one course when I pass this sure of X one over here.
Once that is done
we initialize the ADC first and then we move onto the timer.
I'm going to start off by disabling these sample sequence at 3.
First I'll say ADC 0
DCT SS part 8 over here.
Once that's done I'm going to do it.
This year marks
then going to pass your x F and then 3 0 0 1 2 3.
This next line of the earmarks access is what is going to enable the the time a trigger.
So I'll say it is a zero and then we access earmarks again.
We could have just admitted this but it's often done.
Earmarks and then I'm going to press your ex over here.
5.
Here's your 3 series after the 5 and this selected time a trigger.
So it the new stuff in this lesson time trigger
and once they start I'm going to get input from 10 0 0 7 ATC 0
SS Mark's theory and then I'll pass you here and then once they start I'm going to take the chip temperature
sets flag.
That's the first sample so we'll see indices 0.
Since we've got just one sample we've got to set off like that.
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
two x three
once that's done I'm going to enable these samples sequence of three between indices here is t ss then
I'll post number eight here right.
Once we've done this we can initialize the Y timer
gonna start off by disabling the timer before initialization can I say w timer zero control register
pass you here once that's done I'm going to select the 32 bit option by doing w timer 0 and then configuration
register cause to x 2 for
once they start going to set it to periodic mode and down counter mode so I'm gonna set a timer t in
my register gonna pass here x purity here
I'm going to set the value of the interval load register since we want 1 Hertz mean and once per second
I'm going to load sixteen million here.
So come over here and set up your time.
0.
I'll go to the timer interval load register and then I'm going to pass sixteen.
One two three.
Like this.
Once they start I'm going to select the timer trigger ADC over here in the control register by S.W.
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
to enable a timer by saying w timer zero control register
your X 01 here like this.
Once that is done we can start conversion and wait for conversion to complete a wild one over here
open close and I'll see Quark
this is 0 rice and 8
because zero.
We have to wait for conversion to complete to truly open inclusive I hear.
And then when I create a global variable here quite a temporary chart to store devalue
I
come here.
Temperature
because one forty seven minus two forty seven multiply by the KDE value which is eighty says your SS
five four three over here divided by twelve feet which is four thousand and ninety six right.
And once we've done this we've got to clear the completion flight by doing 80 C0 ISC over here and then
we pass it here
right.
Let's build and see what we have
built successfully.
We know Aero.
Let's get on our board and see our looks so let's download the code onto our board.
Click over here and it's downloaded successfully.
Point click here to go to the debug.
You okay.
And I'm going to add our global variable to the watch window double click on temperature here right
click and then out towards window one over here once they start I'm going to disable hexadecimal display
by clicking here like this.
Then I'll click here to run the code and indeed.
So this the temperature reading.
It's been converted into temperature.
It looks a bit unstable here.
We may want to add a bit of a filter to stabilize it but this is the value from our internal temperature
sensor or being converted into its temperature value here.
Right.
So we read it from the ADC and then we use in this simple equation here to convert to its temperature.
I'm going to put my hand on the MCU to see if I can influence the temperature a bit I place my hand
here
right.
So that's all there is for this lesson.
If you have any questions at all to send me a message.
And over here we're using the timer to trigger the ADC as well.
So we have the timer initialized and I'll see you later.