0:09
hello and welcome to controller Tech
0:12
this is the eighth video in the stdm 32
0:15
ADC Series in today's video we will
0:18
cover the ADC injected channels we will
0:22
see the difference between the regular
0:24
channels and injected channels how to
0:26
configure the injected channels and what
0:29
are different work modes in injected
0:32
channels I am using the same h750 based
0:35
custom development board for this
0:37
tutorial which you can purchase from the
0:41
store here I have already created a new
0:46
video this is basically a multiple
0:48
Channel reading with circular dma
0:51
mode here you can see four different ADC
0:54
channels have been configured just like
0:56
we did in the previous videos of this
1:00
The Continuous conversion mode is
1:02
enabled so the conversion for the
1:04
sequence of four channels will continue
1:06
as soon as the first sequence is
1:08
finished the dma is enabled in the
1:12
mode I have configured four channels in
1:15
the regular mode and the sampling time
1:18
for all the channels is set to
1:20
maximum I have also set the pin pa1 as
1:24
the output so that we can measure the
1:26
conversion rate for these
1:28
channels here in the main function we
1:30
start the ADC in the dma mode once the
1:34
conversion for all four channels is
1:36
finished an interrupt will trigger and
1:38
the conversion complete call back will
1:41
called inside this call back we will
1:46
pa1 this will give us the time taken by
1:49
these four conversions to
1:51
finish since we are using dma a cortex
1:54
M7 based processor we are relocating the
1:57
buffer to a separate Ram the relocation
2:00
is defined in the flash script file and
2:03
the mpu is already configured in the
2:06
MX I have already covered all this in
2:11
video all right we will first test this
2:14
part so that we can see the conversion
2:16
time for these channels in the
2:19
mode I am going to measure the pin
2:21
toggling time on the logic
2:24
analyzer let's run the debugger now here
2:28
you can see the data from 4 channels is
2:30
being shown in the live
2:32
expression let's capture the pin p A1 on
2:37
analyzer you can see the pin remains
2:40
high and low for approx 1.02
2:44
milliseconds this time remains almost
2:48
tole so we can deduce that the total
2:51
time taken by ADC to convert four
2:53
channels along with the dma to transfer
2:56
the data is around 1.02 milliseconds
3:00
remember this time as we will compare it
3:03
with when we enable the injected
3:05
channels now let's see the ADC injected
3:09
channels before we configure the
3:12
injected channels let's understand what
3:14
it is here I have the reference Manual
3:18
of f 446 re and I have highlighted the
3:21
important points regarding the injected
3:24
channels as mentioned here the regular
3:27
group can have up to 16 conversions
3:30
whereas the injected group can have up
3:33
channels this number can vary depending
3:35
on the microcontroller so do check the
3:38
manual of your controller the single
3:41
conversion mode works in the similar way
3:43
for both regular and injected mode we
3:45
can convert the group of channels once
3:48
the regular channels can be used in The
3:51
Continuous conversion mode whereas the
3:53
injected channels cannot be converted
3:56
continuously although there is an
3:58
exception when the inject channels are
4:00
being used in the auto injection mode we
4:04
will see this in a while when we will
4:06
cover the auto injection mode Let's see
4:09
the types of injections we have the
4:13
first one is the triggered
4:15
injection as the name suggests in this
4:18
mode the conversion is started either by
4:20
the software or by the external trigger
4:23
in triggered injection mode if the
4:25
injected conversion starts while the
4:27
regular conversion is going on the
4:29
regular conversion is reset and the
4:31
injected channels are converted once
4:35
then the regular conversion is resumed
4:37
from the channel where it was
4:39
interrupted but if it is the other way
4:41
around the regular event occurs during
4:44
an injected conversion the injected
4:46
conversion is not interrupted and the
4:49
regular sequence is executed at the end
4:53
sequence basically the injected channels
4:55
have higher priority and it can
4:57
interrupt the regular conversion
5:00
sequence the next mode is auto
5:03
injection in this mode the injected
5:06
group is converted at the end of the
5:08
regular group we have discussed above
5:11
that the injected group can be converted
5:13
continuously in this mode Let's assume
5:17
that we have six regular channels in the
5:19
continuous conversion mode along with
5:21
three injected channels in Auto
5:23
injection mode the six regular channels
5:27
will be converted first and then the
5:29
three injected channels will be
5:32
converted this sequence of conversion
5:35
forever so basically we will be
5:38
converting a total of nine
5:40
channels although the interrupts will
5:42
trigger separately for the regular group
5:45
and the injected group we will see
5:48
working of both modes now let's
5:51
configure the cube MX again I am going
5:54
to enable two more ADC channels which we
5:57
will use with the injected mode
6:00
the channel 18 needs to be manually
6:03
enabled from here now scroll down to the
6:06
injected conversion mode and enable the
6:11
conversions the number of channels are
6:13
going to be two we will use the
6:16
triggered mode first and the trigger
6:18
source is going to be the timer one
6:20
trigger out event this is when the
6:23
discontinuous mode is used for the
6:26
channels let's configure the ranks for
6:30
channels I am setting rank one for
6:32
channel 18 and rank two for channel
6:36
19 both channels are configured with
6:39
least sampling time that is 1.5
6:42
Cycles we will use the injected
6:45
conversion in interrupt mode so let's
6:47
enable the ADC interrupt in the nvic tab
6:51
we have configured the timer one as the
6:53
external trigger source so let's
6:55
configure the timer one now let's set
6:59
the internal clock as the clock source
7:01
for the timer one the timer one is
7:04
connected to the apb2 bus which is
7:09
MHz we have already discussed this
7:11
configuration in the previous video so I
7:14
will cover it in short this time I am
7:17
going to use the prescaler of
7:19
2,400 along with the auto reload of
7:23
1,000 this will bring down the timer
7:25
clock to 100 htz so the trigger time
7:30
milliseconds set the trigger event
7:32
selection to update event let's also set
7:35
the pin pa2 as output so that we can
7:38
measure the trigger duration on the
7:40
scope that is all we need for now click
7:43
save to generate the project let's
7:46
define a new array to store 2 16bit Data
7:51
inside the main function we will start
7:53
the timer one in base mode then start
7:56
the ADC injected conversions in the
7:58
interruptor mode once the conversion is
8:01
finished an interrupt will trigger and
8:04
the injected conversion complete call
8:06
back will be called inside this call
8:09
back we will first set the pin
8:11
pa2 then we will read both the injected
8:14
channels and store the converted values
8:17
in the array we defined the injected
8:20
channels have separate data registers
8:22
for each rank therefore we can read them
8:25
in sequence and still get the results
8:29
this is one of the major advantages it
8:31
has over the regular channels where
8:33
there is only one data register for all
8:35
the ranks and hence we need to use the
8:40
channels finally reset the pin
8:43
pa2 this will give us an idea about how
8:46
frequently the call back is being called
8:49
and how much time is taken to read the
8:52
values all right let's build and debug
8:55
the project now I have already added
8:59
both the arrays in the live expression
9:01
let's run the debugger now you can see
9:04
the injected channels are updating very
9:07
frequently and we are getting the data
9:11
channels now I am going to vary the
9:13
potentiometer on channel 18 and you can
9:18
varying now I am varying the
9:20
potentiometer connected to Channel
9:23
19 so the data is updating fine and the
9:26
injected channels are responding to both
9:30
omers let's see the pin toggling on the
9:34
analyzer before we start the capture
9:37
note that the high and low time for the
9:39
pin pa1 is around 1.02
9:43
milliseconds all right we have the
9:45
toggling data for both the pins now the
9:48
spikes in the second row indicate the
9:50
points where the injected conversion was
9:53
done you can see the high and low time
9:56
for the pin pa1 is the same as what we
9:58
got without the injected channels that
10:03
milliseconds but this changes when it
10:05
crosses with the injected
10:07
Channel now the time is 1.05
10:11
milliseconds you can see it again at
10:14
this point the low time for the pin Pi 1
10:18
milliseconds on the other hand the
10:21
duration between the spikes is 10
10:24
milliseconds the timer one trigger
10:26
updates every 10 milliseconds therefore
10:28
the in injected conversion takes place
10:32
milliseconds you can see this time is
10:34
constant between each Spike therefore
10:36
the injected conversions take place at a
10:39
constant rate if we zoom into the spike
10:42
we can see that the pin remains high for
10:47
NS this is the time taken by the MCU to
10:50
read both channels before resetting the
10:52
pin again because of the injected
10:55
conversion triggering every 10
10:57
milliseconds we see the conversion time
10:59
for the regular channels getting
11:01
increased once every 10
11:03
milliseconds this proves that the
11:05
injected conversion is prioritized over
11:07
the regular conversion hence the
11:09
duration for the regular conversion is
11:12
increased so we saw two advantages the
11:15
injected channels have over the regular
11:18
channels first the injected channels are
11:22
prioritized therefore it can interrupt
11:24
the regular channels in
11:26
operation second the injected can
11:29
versions of separate data registers for
11:31
all the four ranks therefore we can read
11:34
the values for individual ranks while
11:38
channels we have seen how the triggered
11:40
mode works for the injected
11:43
conversions now we will see the auto
11:46
injection mode let's change the injected
11:49
conversion modes to Auto
11:52
injection you can see that all the
11:54
triggers have been disabled
11:56
automatically we have discussed it
11:58
earlier in Auto injection mode the
12:01
injected group is converted at the end
12:03
of the regular group also the injected
12:06
group can be converted continuously but
12:09
the triggers are not allowed in this
12:11
mode that is all click save to generate
12:14
the project again the code will remain
12:17
the same so just build and debug the
12:20
project again here the live Expressions
12:23
show the similar Behavior we have the
12:26
data from all six potentiometers and it
12:30
varying but how this data is being
12:32
obtained can be found in the logic
12:35
analyzer let's capture the pin toggling
12:38
data again you can see that the spike is
12:42
now at the end of each toggle of the pin
12:45
pa1 this means that the injected
12:48
channels are converting at the end of
12:51
channels the toggle indicates that the
12:54
regular channel has finished conversion
12:56
and the Callback is also served
12:59
immediately after the toble you can see
13:01
two spikes in the pin
13:04
pa2 these are because we are converting
13:06
two injected channels and therefore the
13:08
interrupt is being called
13:10
twice so this is how the auto injection
13:14
works the injected channels are
13:17
converted after the regular
13:19
channels if there are a total of 16
13:22
regular channels and four injected
13:24
channels using the auto injection mode
13:26
we can convert a total of 20 channels
13:30
if the continuous conversion mode is
13:32
enabled these 20 channels will convert
13:35
continuously that is it for the video I
13:39
hope you understood how to use the
13:40
injected conversion how it is different
13:43
from the regular conversion and what are
13:45
the advantages of using it you can
13:48
download the project from the link in
13:51
description leave comments in case of
13:54
any doubt keep watching and have a nice