STM32 Nucleo - Keil 5 IDE with CubeMX: Tutorial 3 - ADC Single mode multi-channel

STM32 Nucleo - Keil 5 IDE with CubeMX: Tutorial 3 - ADC Single mode multi-channel

SUBTITLE'S INFO:

Language: English

Type: Robot

Number of phrases: 228

Number of words: 1737

Number of symbols: 6942

DOWNLOAD SUBTITLES:

DOWNLOAD AUDIO AND VIDEO:

SUBTITLES:

Subtitles generated by robot
00:00
hello again one this is Mohammed Jakub and this is another video on the nuclear love for tutorial series another this video I'm gonna show you how to use a DC a single conversion mode so ABC single convergent is the most basic one to use and what it does is that whenever you wanna read an analog input you trigger to the ADC will convert the value and we'll go to sleep as opposed to a DC continuous mode that will continuously convert an acquired data so that's what I'm going to show you today and in my demo I have two
00:30
analog and boots I'm using this some joystick it has got two analogs the X and y-axis so I'm going to be using these two so now let's go to cuba mix and set up a new project another cuba mix as usual click on your project and select the right board so let's go to board selector nuclear 64 pins or alistair of 401 r e so this one and this is the board pen out by default
01:01
I'm just gonna clear all the Pens and set them up manually again so go to pin out and clear pan out and yes first thing I want to enable as I want enable my LED so it's own PA 5 assisted to unload output and I might also want to enable my push buttons on PC 13 and set it to GPIO input and now to the important part so I need to enable my ADC inputs I'm getting is a DC 1 for
01:31
both of the channels I'm gonna enable channel 0 and channel 1 and keep in mind here we can only do one at a time because if you look at the ADC diagram you can see that we can have up to 16 analog inputs so up to 16 channels from 0 to 15 and we can use one of the three ADCs on the board because if you're looking qmx you see that you have oh no that's not the discovery board so what the nuclear there is only a single ADC and you have 16 analog inputs and you
02:03
know you only allowed to use this ADC so you have to select one of the channels until the ADC to convert the value and this one can take only a single input so what we're gonna do in today's demo is that I'll first do a single channel so channel zero and then I'll show you how to change how to swap between channels and the code okay and if you didn't quite get what I'm saying here don't worry much I'll definitely clear up when we get to the code so now let's carry on let's go to configuration I'm gonna configure our
02:35
ADC so these are the ADC parameters the most important one perhaps is the resolution so I wanna start up with 8 bits of resolution if you don't know what 80 stories illusion mean just watch a couple of 5 minutes videos they will explain all about a DC's resolution but 8 bits the range will be from 0 to 255 and 10 bits from 0 to 100 to 3 and so on and I'm not using continuous mode conversion I'll skip all of those number of conversion I'll leave it to one and
03:08
from group the rank you can see that channel 0 will be converted first I might want to increase the sampling time cycles as well to perhaps twenty eight cycles because this one requires at least 11 clock cycles I'm gonna set this to 28 and click OK so that's all we need to do here we're ready to generate the source code so click on generate source code icon here and give the project a name going to call an ADC single video
03:40
ID only store it to this location select your IDE mdk-arm v5 and click OK ok and once the source code is generated click on open project and this will take you straight to your Q micro vision IDE and now let's start writing the code so I want to define variable to store my ADC values and so I'm gonna define an unsigned 32-bit variable ADC a DC voltage arrow for
04:10
channel 0 an ADC value 1 for channel 1 ok so the reason why I defined unstarted two-bit is the ADC get value return and unsigned 32-bit value so that's why I defined those this way a next thing I want to do is I need to start the ADC in here so hull ADC start now this one takes a single parameter the ADC handle type def and you would see a handle tab if defined at the top by Q of X so this is the handle table for ADC one it's called each ADC
04:43
one I use ampersand sign because it requires a pointer to that and then I will wait for the end of convergence so how Paul sorry led see Paul for conversion and this function takes two parameters the ADC handle type def a pointer to that and a timeout I'm just gonna give it five millisecond should be more than enough and I'll put the F condition if this one is okay then I'm gonna read the ADC values so because
05:15
this function returned a whole status type death if you go to the to finish and you'll see that this function returns this one and this type disc can be either ok or arrow so I'll check if this one is equal to okay then I'm gonna proceed so this one is equal to hell okay then I'm gonna proceed and get the ADC value and you get the ADC value of the function called hull ADC get value this one and this one takes a single parameter the ADC handle time diff again
05:47
okay and it returns the ADC rate value I'm gonna store it in my first channel variable so a dc-10 I named it above yeah so I'm gonna use this to store the value and I'll put a little delay here so how delay perhaps just 50 milliseconds okay and that's it so this is for a single channel so let me compile it load it to the board and we'll test this and then we'll come back and add the second channel we'll order to the board and all
06:20
jump into the debugging mode so click on this icon to go to debug mode I don't hear I need to add my variable to the watch memory to be able to see them so I'm all using a dc-10 so I'm just gonna add this to watch one Anna has been added here so I'm gonna remove the hex display I want to see it in decimal and we can start the code oh okay so I can get I'm getting one two five this is the middle value now if I
06:53
change it right or left you can see the value increasing maximum two two five five and then decreasing if I'm over to the other side decreasing down to zero so yeah walking perfectly and now let me show you how to read from multiple channels so now if you go down to the ADC settings you can see on the channel configuration that channel zero is selected so what I want to do is I want to be able to swap between channel 0 and channel 1 to read two channels to do this I need to call
07:24
this function in my main what does variable that store the configuration but this variable is now defined locally so I won't be able to call it in the vein what I would need to do at first is to take this and define it to globally in status I'm gonna define it outside the main function so that everyone can see it now I can I need to call this in here to change channel so so after I get the first channel converted s config dot channel I want to
08:02
change this to a DC to channel one instead okay and then I'll call the function to implement those consideration similar to the configuration function here I could have bought those and as well but this by default don't change I set them once and they will stay on this variable so I need to call a DC config channel to implement this okay now the channel change from channel 0 to channel 1 all I need to do is to
08:33
call in this part of the code again so this one will start the ADC again after I change the channel wait for the end of conversion and get the value but now I need to store it in variable number 1 because this one is for channel 1 so I need to copy these settings again back to the top because after the delay will get get back in here and the channel will remain channel 1 so I need to return it back to channel 0 so this one gonna be back to channel 0 and that should be it so let's compile the code load it to the board and we're gonna test and the
09:05
debugging mode again and on the debugging mode I just need to add the other variable to watch memory I've already added channel 0 variable by need to add channel 1 variable 2 so add to watch 1 and similarly I'm gonna remove the hex display and I'll start the code so good both of them start about 1 to 5 in the middle so I'm gonna change the first one first one is similarly goes from 0 to 255 and now the second channel
09:36
as well so goes down to 0 and goes maximum when I scroll it up or goes to 255 so well perfect both of them are working perfectly except the middle value here is 132 but this is just down to the calibration of the some joystick okay okay cool but all I want to show you today if you enjoyed this video I want to see more videos like this don't forget to Like and subscribe thanks I'll see you next time bye

DOWNLOAD SUBTITLES: