0:09
hello and welcome to controllers Tech
0:12
this is the fourth video in the ADC
0:16
32 in the previous video we saw how to
0:19
read the multiple channels of the ADC
0:22
using the dma we used the dma in normal
0:25
mode therefore the dma transferred the
0:28
data only once and and then stopped in
0:31
order to fetch the conversion data from
0:33
the ADC we needed to start the ADC again
0:37
in the dma mode today we will keep
0:40
reading the multiple channels using the
0:42
dma but we will do it in the circular
0:45
mode this way we would need to start the
0:47
ADC in dma mode just once and the dma
0:51
will continue fetching the data from the
0:54
ADC I will continue where we left the
0:56
previous project let's open the cube
1:00
next to modify the previous project here
1:03
the four channels are already selected
1:05
and the scan conversion mode is also
1:08
enabled let's go to the dma section and
1:11
select the circular mode for the dma in
1:15
circular mode the dma will continue to
1:17
transfer the data from the
1:20
ADC now in the conversion data
1:22
management mode select the circular dma
1:26
we also want the ADC channels data to
1:28
get updated so so enable The Continuous
1:31
conversion modee this will allow the ADC
1:34
to start another set of conversions as
1:36
soon as the first set is finished this
1:39
way the dma will always have the updated
1:42
data to transfer from the
1:44
ADC rest of the configuration will
1:46
remain the same as we did in the
1:48
previous video Let's generate the code
1:51
for our new project before we proceed
1:55
ahead let's see the configuration needed
1:57
for the other MCU as well
2:00
here is the image showing the
2:02
configuration for f 446 re we need to
2:06
enable The Continuous conversion mode
2:08
and also the dma continuous request also
2:12
in the dma section make sure that the
2:15
dma is configured in the circular mode
2:18
the rest of the configuration is the
2:20
same as what we used in the normal dma
2:23
mode here is another image showing the
2:26
configuration for f103 C8
2:30
we just need to enable The Continuous
2:32
conversion mode as we do not have the
2:34
options for others now in the dma
2:38
section make sure that the dma is
2:40
configured in the circular mode the rest
2:42
of the configuration Remains the Same as
2:45
we used in the normal dma mode all right
2:49
let's build the project once since we
2:52
are using the dma in the circular mode
2:55
we do not need to call it again and
2:57
again we will call it only once in the
3:00
main function and it will keep fetching
3:04
automatically you can use the conversion
3:06
complete call back to process the ADC
3:09
data let's debug the project to see the
3:12
working the ADC value array is already
3:16
added to the live expression so let's
3:18
run the debugger you can see all the
3:21
values of the array are varying very
3:23
fast this means that the dma is able to
3:27
fetch the updated data on each call I am
3:30
varying perometer 3 and you can see the
3:33
variations in the third element of the
3:45
array now I am varying the potentiometer
3:48
to and you can see the changes in the
3:51
second element of the
3:56
array similarly other ADC values are
4:00
also varying as per the
4:05
potentiometers the count variable is
4:07
updating every 500 milliseconds that
4:10
means the while loop is executing at the
4:12
normal rate as well so we are able to
4:15
read the multiple ADC channels using the
4:17
circular dma mode where we just start
4:20
the ADC once and the dma continuously
4:23
fetches the updated results from each
4:26
Channel now since we are using the dma
4:28
in a cortex M7 based MCU let's also
4:32
discuss the issue of cash
4:34
coherency as per st's recommendation we
4:37
should use the cache in a cortex M7
4:41
MCU this improves the overall system
4:45
performance so let's enable the
4:47
instruction and data cache in the
4:50
configuration here when we use the cache
4:53
along with the dma we Face the issue of
4:55
cache coherency where the dma reads the
4:58
cached data instead of the actual data
5:02
to avoid this issue we can configure the
5:04
memory protection unit of the MCU and
5:09
non-cashable so let's enable the mpu in
5:13
mode I am going to relocate the ADC
5:16
value array in the ram D2 whose base
5:19
address is 30 million
5:21
hex the ADC value array is 16 bits in
5:25
size and we have a total of four
5:27
elements in it then therefore the array
5:30
size is 8 bytes in total although here
5:34
we have 32 bytes as the least possible
5:36
size so let's select it now permit all
5:40
the access and disable all the access
5:44
permissions I have already explained in
5:47
detail about the mpu configuration in
5:49
five video series you can check them out
5:52
to understand the memory protection unit
5:55
all right now the first thing we need to
5:57
do is relocate the ADC value array to
6:02
location we can use the section
6:06
so here I am relocating it to the
6:10
array now we need to Define this
6:13
location in the flash
6:15
script as I mentioned earlier I want to
6:18
relocate the buffer to the ram D2 which
6:20
actually starts at the address 30
6:23
hex therefore we will link the section
6:26
ADC array here the rest of the code
6:30
Remains the Same we are starting the ADC
6:32
in dma mode just once and then the dma
6:35
will keep transferring the updated data
6:45
channels let's build and debug the
6:49
project you can see the ADC value array
6:52
is updating as it should this means the
6:55
dma is able to fetch the updated data
7:00
one so we are able to read the multiple
7:03
channels of the ADC using the
7:05
dma we started the ADC in the dma mode
7:09
just once and then the dma was
7:11
continuously fetching the data from the
7:14
ADC the dma was even able to fetch the
7:17
updated data so there was no issue of
7:19
cache coherency while using the cortex
7:23
MCU we will continue the series and in
7:26
the next video we will see how to read
7:28
multiple Chan channels without the dma
7:31
this is it for the video I hope
7:34
everything was clear you can download
7:37
the project from the link in the
7:39
description leave comments in case of
7:41
any doubt keep watching and have a nice