Hello, fellas.
Welcome back.
In a section, we're going to learn how to create a D.C. project using the Cube remix.
In this very first lesson, we shall learn how to do a single ADC conversion.
So click over here to create a new project.
And then I'll select my board.
My board is the disco board and it's an F for board.
And this one here is my particular microcontroller.
DoubleClick to choose it.
I just explained to her what I'm going to do, so I'm going to clear the pin out by clicking over her.
And then everything is cleared now for my particular school board of court, just one ADC off court,
just a DC one where I'm going to do it.
So I'm going to come to a DC one and I've got the option to choose from the sixteen channels available.
So I'm just going to start with Channel Zero over here.
So like this in its chosen Channel Zero for me, once that is done, I'll just set my debugger and then
go to configuration to configure the ADC.
Click over here my depolarize the zero wire and once that is done, I just leave the clock configuration
to the default setting and I'll come to configuration over here and then click here.
ATC one for this example, we don't need a lot of changes actually.
So I just click, OK.
Now now generates the code.
Come over here and I'll give my project a name.
I'll call it ADC Single Conversion.
And then I select my two chain, which is the column Decay.
Now click, OK, it's January 10.
And it's finished generates I'll just click over here to open a project.
Right.
It's opened.
So what I want to do is click here to build the whole project.
Once that is done, I can update my D-Box set in.
I just click over here into this box here.
Okay.
And then open, what I want to do is start my ADC and start conversion.
And when it finishes the conversion, I want to store the value in a variable which we will create later.
So let's do that now.
So just start the ADC.
We need to use the ADC Start API and we can find the function here by clicking here and selecting the
ADC module.
Here we get a list of API is available to us.
And this one here called How API Stuff.
How ADC Start.
This one here.
It is you start so it can click here.
This one here can read about it here says and it enables ADC starts conversion of regular channels.
And what parameter does it take?
It takes a pointer to the ADC handler structure.
So we just copy this function.
Bring it to Main.
And then we start the ADC back, put in her.
And then we just couldn't use the ADC handler, which is already declared here by Cuba, makes for us.
So we just copy this.
This is the argument of this function.
Let's keep it in here like this.
Put a semicolon.
Now, I've started it, ADC.
So what I want to do next is to pull for conversion, to get a conversion.
We have to use the ADC pull for conversion API.
And it's here.
This one here, how ABC political conversion, so we can take a look at it.
And it takes to document one is the ADC handler and then the other one is the time out.
So I'm just going to copy this as well.
And then poor for conversion.
Copy this.
Take it to my main function.
Put it here and then I'm going to replace this with the NTC one.
I'm going to give it time out of.
In fact, we can give a time out of something as little as one millisecond and put a semicolon there.
So once we've bought for conversion, we have to wait for it to convert.
And we've given a time or two for a millisecond after this, we can use the whole ADC gets conversion,
which is here.
Get value, the ladies, he gets value less, click it and see what he says.
Gets the converted value from data register off regular Chernow's in the parameter pointer to the ADC
handler.
What does a return and returns the converted value to can come over here.
We copy this.
Then we come over here.
Then then we can say.
Get value from the ADC handler like this.
What we want is to keep all of this in the wild.
And this one here returns the ADC file.
So what I'm going to do is I'm going to create a global variable out here, up here to store the ADC
value Grinch and make you into 32 on the school team, sense of value and sense of values going to half
the ADC value.
So I can come over here and see sense of value because all ADC gets value.
And with this, we get the ADC value stored in this global variable for us.
So we can just rebuild, download onto our board and then go to the debug view and put this in a watch
window to see DADT value.
So what I'm going to do is I'm going to connect an analog source to my ADC channel, which is B is you.
What I've got here is a standard potential meta.
I'm going to connect the middle leg of the potential meta to be issue the left leg to ground in the
right like two plus five vote, and then I'm going to turn that potential meta.
And we expect to see the analog value right here to change as I turn the potential meta.
So let's do that now.
And remember, if there's anything you do not understand, send me a message or leave it in the comments
section.
So I click to rebuild my project.
Then once that is done, I'll just click over here to download onto my board.
And once it is done, download it, I can click here to go to the DeBacker.
What you want to do is double click, right, click on the sense of value variable and then to watch
when to want to appear here.
Once it appears we can right.
Click over here to disable the hexadecimal display like this.
And then I'm going to click here to run my code.
And so this the middle value of my current potential meetup position, I'm going to rotate my potential
with me to now, as you can see, I've rotated it to the on the other end of it.
And the value is almost zero now if rotated to the opposite direction.
So, yeah, this is a DC single single conversion mode.
As you can see, it's working.
Are fruitage headed to the other end again and the value down.
So this is it.
And the next lesson, we shall run another ADC application for continuous conversion.
And I see you in the next lesson.