STM32 ADC MULTI CHANNEL without DMA || HAL || Poll

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello everyone welcome to controllers tech first of all i would like to thank all those who are helping me by donating on the website your generosity keeps me inspired i have started a membership program with this channel anyone interested can join the membership by clicking the join button below the video let's get into the video now well this is yet another video on adc and today i will again cover the multi-channels part i have already covered the multi-channel using dma but there was a problem with the while loop that it never gets executed this happens because dmr interrupts triggers very frequently and that's why the program never enters the while loop many users requested a way to use multiple channels without dma and that's what we are going to cover today so let's start by creating the project in cube id first i am using stm32f446re controller give some name to the project and click finish here is our cube mx i am selecting the external crystal for the clock let's accept the clock first i have eight megahertz crystal and i want the system to run at maximum clock i am going to select three channels of adc one channel zero channel one and the temperature sensor select the scan mode since we are using multiple channels also select the continuous conversion mode i am not going to use any dma i am using three channels so select three now set the ranks and sampling time according to your requirement that's all for the adc setup you can see that the two pins got selected for the respective channels [Music] i am also going to use dac and then feed the output from pin pa4 to the adc channel 0. select software trigger so it only triggers when we want that's all for the cube mx click save to generate the project [Music] here is our main file let's go to the adc init function first i am going to copy the configuration for these three channels and comment them out here so that they can't be configured in the beginning of the program also change the number of conversions to 1. now let's write the function to select adc channel 0. here i am going to paste only the channel 0 part you can see the adc channel 0 and the sampling time now we will write another function for selecting channel 1. and here we will only write the channel one related part also make sure that rank is set to one [Music] and now finally the temperature sensor channel and paste the related code here also change the rank to 1. [Music] next i am going to define an array to store the adc values these two variables will be used in d-a-c and these are for the temperature sensor in the while loop first of all i am going to assign a value to the variable so that we can feed it to the dac now increment the value if value is greater than 3.3 the reset it to zero we will use set value to set the value to the d-a-c i am using channel 1 and data alignment is to the right now start the dac now for the adc first of all i am going to select channel 0. start the adc poll for the conversion to finish get the adc value and finally stop the adc i am going to repeat the same steps in other channels also this is the statement to get the temperature and let's add one second delay here let's build it seems like we have some errors i forgot to declare the adc config type def just copy it in all the adc select functions so we don't have any errors now let's debug this i want to show you the connection before starting the debugger so here the orange wire is connected between the output from d-a-c to the a-d-c channel zero and the a-d-c channel one is connected to the ground i have added the variables in the live expression you can see here var represents the dac value which is incrementing every second and adc channel 0 is also similar to this value channel 0 is grounded and that's why the value is almost zero now i am connecting the channel 1 to 3.3 volts and you can see the adc is now reading the maximum value also the temperature is constant and the other adc values are not affecting it the multiple channel works pretty good without the dmr2 the advantage of this method is you can read the channels at any point in the code all you need to do is write this part and you are good to go this is it for the video i hope this solves the problem of dma with the multiple channels you can download the code from the link in the description keep watching and have a nice day ahead
Info
Channel: Controllers Tech
Views: 10,571
Rating: undefined out of 5
Keywords: stm32, stm32f4, f103, discovery, nucleo, adc, multi, channel, multiple, dma, nodma, without, poll, conversion, dac, trigger, output, software
Id: 5l-b6lsubBE
Channel Id: undefined
Length: 9min 22sec (562 seconds)
Published: Sat Jan 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.