0:09
hello and welcome to controllers Tech I
0:13
have decided to continue the SDM 32
0:16
timer series and I will try to cover as
0:18
many timer functions as possible I have
0:21
already made a few videos in the past
0:24
which are available in the SDM 32 timer
0:26
playlist and this video will continue
0:29
that series with few more coming in the
0:32
weeks so far we have seen how to use pwm
0:36
input capture and encoder mode in the
0:40
timers this video will cover how to
0:44
timers there will be more videos coming
0:46
under the topic timer synchronization
0:49
and each of them will focus on only one
0:52
operation so today's video will cover
0:55
how to use the master timer to start the
0:57
slave timer this can help you to avoid
1:00
delay between the timer
1:03
outputs for example if you want to send
1:06
the different pwm signals to different
1:09
inputs of a device but they must all
1:11
start at the same time using the
1:14
traditional method will have some delay
1:16
between these signals as each statement
1:21
execute today's video will cover this
1:24
issue and how we can use the timer
1:26
feature to avoid this delay all right
1:29
right let's start the cube idid and
1:34
project I will explain the requirements
1:36
as we go along with the
1:38
video I am using the SDM 32f 446 re
1:44
controller give some name to the project
1:48
finish I am enabling the external
1:51
Crystal to provide the clock to the SDM
1:53
32 board the board has 8 MHz Crystal on
1:57
it and lets run the system at a Max
2:03
frequency now before we proceed further
2:06
let me show you how we can achieve this
2:09
here you can see a diagram for
2:11
triggering the timer 2 with the update
2:15
one basically when the counter of the
2:17
master timer that is timer one overflows
2:21
an update event will be
2:23
generated with this update event the
2:26
slave timer that is timer 2 counter will
2:30
counting remember that the slave counter
2:33
does not reset to zero before counting
2:35
starts it will just resume the counter
2:39
paused this is called the trigger mode
2:42
when the timer is used as a slave timer
2:45
now the question is which timer will
2:49
counting to understand this you need to
2:52
open the reference Manual of your
2:54
controller and search for the internal
3:04
here is one connection table but this is
3:07
not what I am looking for this is the
3:10
one I need as it has the timers I am
3:12
going to work with the First Column is
3:15
the slave timer and the rest of the
3:17
columns represent the signal sent by the
3:19
corresponding Master timer for example
3:23
if timer 2 is used as the slave then
3:26
timer 1 can be used as the master and
3:29
the signal sent by the timer 1 will be
3:32
it0 similarly timer 3 can also be
3:35
controlled by the timer one using the
3:38
it0 but if you want to control the timer
3:41
3 with timer 2 then you need to use the
3:44
itr1 signal also I am going to use the
3:48
pwm output to monitor the timers working
3:51
so we need to also see the clocks the
3:53
timers are running at here in the clock
3:56
diagram you can see the apb2 timer clock
3:59
is running at 180 MHz whereas the apd1
4:05
MHz this is the picture from the F 446
4:09
re data sheet and here it is mentioned
4:12
that the timer 2 is connected to apb1
4:15
bus whereas the timer 1 connected to the
4:19
bus this means the timer 2 will by
4:22
default run at 180 MHz and timer 1 will
4:28
MHz we will further divide these clocks
4:30
to reduce them all right let's set up
4:34
the timers now timer one is the master
4:37
timer so I am only enabling the pwm
4:41
output on channel one the clock is at
4:44
180 MHz so we will bring it down to 100
4:48
HZ using the prescaler and auto reload
4:51
value as shown in the
4:53
formula there is no particular
4:55
requirement for the frequency just set
5:00
next in the trigger event selection
5:04
event this will generate the update
5:07
event flag whenever the counter
5:09
overflows in the pwm section set the
5:13
duty cycle so that we can see the output
5:17
oscilloscope I am setting it to 300 with
5:20
ARA being thousand the duty will be
5:24
30% here I am choosing the channel
5:26
polarity to be low so the output will be
5:30
inverted I am doing this so that we can
5:32
see details more clearly on the
5:35
scope this is it for the master setup
5:38
let's set the slave timer now here in
5:41
the slave mode select the trigger mode
5:44
and the trigger sour is it
5:47
r0 as I have already explained the
5:50
trigger mode allows the master timer to
5:52
control the start of the slave timer it0
5:56
is the trigger signal used by the timer
5:58
one to control roll the timer to to see
6:02
how the slave timer behaves we will also
6:04
enable the pwm output for the timer
6:08
2 here we have the pin pa0 as the timer
6:11
2 pwm pin and pa8 as the timer 1 pwm
6:18
pin I am entering a random value here as
6:21
the pwm is not the priority for us here
6:25
you can see the trigger mode is selected
6:27
as the slave controller
6:30
just give some random value to the pulse
6:33
also at last I am keeping the channel
6:36
polarity low so this is it for the cube
6:39
MX setup click save to generate the
6:43
project in the main function we will
6:46
just enable the pwm for both the timers
6:49
so that we can observe the outputs of
6:53
timers I am starting the pwm for the
7:01
let's also give some delay between them
7:04
so if the slave mode doesn't work you
7:07
can clearly see the timer 2's output
7:14
one let's build and Flash the program to
7:24
board here I have connected the timer
7:27
one to Channel Zero and Tim Tim 2's
7:30
output to the channel
7:32
one here you can see the output of both
7:35
the timers let me reset the board to see
7:38
what happens in the beginning here you
7:41
can see the timer 2's output goes low
7:44
but the pwm doesn't start actually pwm
7:48
is working it's just that the counter
7:51
was initialized to zero and it's not
7:53
counting up the counter is blocked and
7:56
this is why the pwm output is always Z Z
8:00
now this is the part where the timer 1
8:02
pwm starts its counter was also
8:05
initialized with zero the counter counts
8:09
up and overflows at this point once the
8:12
counter overflows an update event is
8:15
generated which triggers the counter of
8:17
the timer 2 and the timer 2's counter
8:20
counting finally you can see the pwm W
8:24
form of the timer 2 so we can see how
8:27
the timer 2's counter was blocked until
8:30
the timer one generated an update event
8:33
now let me quickly show the output of
8:35
this same configuration without the
8:39
used you can see the rest of the
8:42
configuration is the same we will keep
8:45
the code unchanged let's just flash it
8:49
board here you can see the output the
8:51
timer 2os pwm actually started way
8:55
before the timer one this is how we
8:58
programmed our timers and without the
9:00
slave mode triggering it shows the
9:02
output in that way so we saw the effect
9:05
of using the slave mode with trigger
9:07
mode and how it delays the counter until
9:10
the master generates an update
9:12
event let's take this further and this
9:15
time we will start three slave timers
9:19
Master as you can see in the picture the
9:22
timers two three and four can be
9:25
controlled by the master timer one using
9:28
the same signal it R Zer we will simply
9:31
set up the timers three and four just
9:34
like we did for the timer two I am
9:37
enabling the pwm for both of these
10:00
that's it for the setup let's generate
10:02
the code now in the main file we will
10:06
start the pwm for all four
10:09
timers I am starting the slave timers
10:12
first each with the delay of 500
10:15
milliseconds since the timers are
10:17
working in the slave mode all three of
10:20
them will start at the same time after
10:22
the Overflow occurs in the timer one
10:25
let's build and Flash the code I forgot
10:29
to change the channel polarity for the
10:31
timer 3 and four let me do that
10:56
quickly here you can see all three time
10:59
timers have been enabled but their
11:02
blocked when the Overflow occurred in
11:05
the timer one an update event was
11:07
generated and all the three timers
11:09
started counting up you can think of
11:12
this as the parallel synchronization of
11:15
timers we can also synchronize them in
11:22
series if you take a look at the table
11:25
you can see here that the timer 3 can be
11:27
controlled by the timer 2 using the it1
11:31
signal and timer 4 can be controlled by
11:34
the timer 3 using the it2 signal so in
11:39
the timer 2 setup we will enable the
11:41
trigger event as the update event now
11:44
for timer 3 change the trigger source to
11:48
R1 also enable the trigger event for the
11:51
timer 3 changed the trigger source for
11:56
R2 we have cascaded them in the ser
11:59
series and the next timer will only
12:01
start once the previous timer has
12:03
generated the update event the code will
12:06
remain the same let's build and Flash it
12:16
board all right we can clearly see a
12:19
little different output than the
12:21
previous case here is the Overflow of
12:24
the timer one and timer 2 starts
12:26
counting after that this is where the
12:29
timer 2 overflows and timer three starts
12:32
after that again timer 4 starts after
12:36
the Overflow in the timer three keeping
12:39
the channel polarity low is not giving a
12:41
clear picture about this let me change
12:44
the polarity to high and we will see the
13:08
now you can visualize it in a better way
13:11
now that we have the proper polarity let
13:13
me explain how the pwm signal is
13:17
generated I have already explained it in
13:19
the previous tutorial about pwm but I am
13:23
explaining again here we have the auto
13:26
reload value and the pulse which is all
13:29
also a capture compare value basically
13:32
the counter counts up until it reaches
13:34
the capture compare value the output
13:37
remains high and after the capture
13:39
compare value the output remains low
13:42
till it reaches the auto reload value
13:45
this is where the Overflow occurs and
13:48
the counter reset back to
13:53
zero zero marker is where the Overflow
13:57
occurs in the timer one timer 2 starts
14:00
after this moment and Marker 1 indicates
14:03
the point where the Overflow occurs in
14:05
the timer 2 marker 2 indicates the point
14:08
where the Overflow occurs in the timer
14:11
three you can see the timer three and
14:13
four basically have the same wave form
14:16
even as for the timing this is because
14:19
both of these timers are running at 50%
14:21
duty cycle so when the Overflow occurs
14:24
for timer three the counter resets to
14:27
zero this is the point where the update
14:29
event is generated and the timer 4 also
14:32
starts counting up both timers will
14:35
count up at the same speed and hence you
14:40
waveform I hope you understood how the
14:42
master timer can control the start of
14:46
timers we will continue this timer
14:48
Series where we will cover different
14:50
functionalities of Master and slave
14:53
timers the next video will cover how to
14:56
generate 3 pwm signals with 100 120°
15:01
shift this is it for the
15:03
video you can download the code from the
15:07
description leave comments in case of
15:10
any doubt keep watching and have a nice