Delegates Welcome back.
So in this lesson we're going to learn how to use multiple ADC channels.
We did DMA I'm going to stun my Cuban mix and in this project I'm going to use to ADC Chanos.
So I come over here create a new project I click and then I select my board.
That's the discovery board then it's this one here for than it is this a double click to choose
so once that is done I come over here.
Claire or pins and this time I'm going to use channel 1 and Channel 2 so I can right click a one here
and set it as a DC one input one and then a P2 as ADC 1 input 2.
Once that is done we'll leave the clock configuration the same which the default setting now come to
the configurations stop and then click under analogue here will click ADC 1 and then we come to parameter
certain Mr said the ADC and this time we can reduce our ADC quick by providing a pre-schooler divide
of 8 and then we can keep the resolution the same.
And in this project what we want is we want to use the continuous mode.
So I'm going to enable continuous mode here and I'm going to enable DMA here and I'm going to enables
con mode as well like this enable.
Then once that is done we come here and then because we've got two channels we said the number of conversions
to two and then once we set a number of conversions to two you see the number of ranks have increased
here.
If I'm to set the number of conversions to 1 their rank will be just one rank.
So because we are using to Chanos we said the number of conversions here to 2 like this.
So I'm going to said the rank number one for China number one and then rank number two when set it to
China number two like this and I'm going to say the sampling time to for eighty cycles.
Green said this to four psychos as well.
And then this is all there is to it.
So remember if you have any questions as usual just send me a message or leave in the form.
Once that is done we come to DME settings because we using DME and don't worry about using DME.
Here we're going to treat the DME module on its own right to when we get here what we have to do is
add DMA and when we add we select we select ADC 1 cos that's the only peripheral we've initialized and
we want to check the data with size.
This one here says half would fit.
So let's just set it to a word which is 32 bit data size.
What we want is one in a circular manner so that when is stores India in the memory of course up to
the top.
So we change here to a circular circular mode.
Then once that is done actually this there isn't much to do.
Just click OK.
Then we generate the project click over here to generate the code and then I'll give my project a name.
I'll call this ADC Kimi
and then I'll select my two chain which they call you visioned version 5 and I click Okay over here
and then it generates the code and then once it's done I click over here to open the project and then
the project is open.
So like I do always I'm just going to rebuild everything by clicking here.
I just explained this a bit
right.
Zero errors to a is.
So once this is done remember we assigned our PINs PSU and we use in p a one in P two we can verify
that here.
P1 appear to be a 1 is our ADC Channel 1 and Pier 2 so our ADC Channel 2.
So what we're going to do is we're going to create an array of size 2 to store the resource of both
the channels which come here in demand at TFR I'm going to come here I'll put it here make it global
and I'm going to use you into 32 underscore T and I'm going to call it sense of value this time it's
it's an array with size 2 and right here we need just one line of code to start the ADC and stock conversion
and it is it is called a D.C. start DMA and we can double click here to see the parameters of this function
and we can see the parameters.
It says here is the ADC type typedef the ADC Hondo and then this one here is way to store the resource.
This one here is the length.
Like it says the length of data to be transferred from ADC pair forward to memory and P data here is
the disk the destination buffer address and then the handler.
Okay so I'm just going to come here and our ADC handle has been declared to us H A ADC 1.
I just copy this and then bring it here.
Would it embossed Amberson sign like this.
And then the reader would just created to store the resource.
I put it here and we looking for two resorts.
So I put you here and that's all we need to do.
So what I've done here in my setup is of connected to potential meters to one to be a one and another
one to two.
So I'm going to download onto my board and then go to the debug view and see whether indeed the changes
occur as I turn my potential meter.
So before I do that actually I'll just come to my debugger here and set this to reset and run like this
and then okay and then okay.
Then I click here to reboot
and then I download onto my board so to test the code I'll just click over here to go to the debugger
what I'm going to do is I'm going to add this to the watch window by double click in right click to
watch window 1.
Then I'll expand this and then I'll disable hexadecimal display like this.
And once they start I'm going to click here to run the code and we'll see what happens.
So currently I've position both potential meter to the opposite direction which would give the lowest
value.
So I'm going to run the code and I'm going to turn to potential meter to the other end of the to the
other end which will give the maximum value of the potential meter.
And that would in effect give the maximum voltage reading to the ADC so I'll click here to run and as
I said there's the lowest value so I'm going to turn one potential meter as you can see it's showing
the highest value so I'm going to change this channel to the highest finally as well just by turning
the knob to the opposite direction.
And as you can see it's also changed by others.
So this is how we enable the ADC with DMA capability.
And this is the best way to use multi-channel ADC by enabling them in this way that we've done.
If you want to use five channels you can use the same method we just showed.
Just by going through what we did.
If you use in five channels you're going to have five rungs and you're going to go through five set
of configurations.
Over here over here if we are to use five channels then things like this.
This would change to five and when we get to rank we would have to set a rank of five different channels
and the rest.
This side remains the same too.
This is all there is to it.
If you have any questions or you need more explanation don't hesitate to send me a message.
Now see you in the next.