0:12
this is the seventh video in the SDM 32
0:15
timer series and today we will continue
0:18
with another application of the timer
0:21
we will see how to Cascade the timers in
0:24
series and by doing this we can combine
0:26
three 16-bit timers into a 48-bit timer
0:30
basically in Cascade the frequency of
0:33
one timer will be used as the clock for
0:37
this can be achieved by using the update
0:39
event as the master timer output signal
0:41
along with external clock mode for the
0:45
the video was going to be very long so I
0:48
have decided to split them into two
0:51
this video will basically cover the
0:53
slave timer in the external clock mode
0:56
also we will see the reset mode towards
1:00
and in the next video we will make a
1:03
48-bit counter using three timers and we
1:06
will also see its application
1:08
so let's start the cube IDE and create a
1:13
I am using the stm32f446re
1:18
give some name to the project and click
1:22
first of all I am selecting the external
1:24
Crystal to provide the clock to the MCU
1:27
the board has 8 megahertz Crystal and I
1:30
want to run the controller at 90
1:33
I am choosing 90 megahertz because I
1:36
want all the timers to have the same
1:38
clock speed and apb2 timer clock can run
1:41
at a maximum of 90 megahertz
1:44
the clock setup is done so let's start
1:47
setting the timers now
1:49
timer 1 is going to be the master timer
1:53
here I am enabling the pwm on Channel 1
1:56
so that we can see the output of timer
2:00
right now the timer clock is at 90
2:02
megahertz so the prescaler of 90 would
2:05
bring the clock down to 1 megahertz
2:08
the auto reload of 100 would further
2:10
reduce the timer frequency to 10
2:14
the trigger event should be selected as
2:18
basically when the counter will reach
2:20
the auto reload value of 100 this update
2:23
event will get triggered
2:26
and if we use the update event in
2:28
combination with the external clock mode
2:30
or gated mode the output frequency of
2:33
this timer can be used as the clock for
2:37
since the auto reload is 100 if I keep
2:40
the pulse at 40 there will be the pwm
2:43
signal with 40 duty cycle
2:46
let's quickly see what we have
2:50
the timer one output frequency will be
2:52
APB timer clock divided by the prescaler
2:55
times the auto reload value and this
2:58
will be equal to 10 kilohertz
3:04
now we will configure the timer too
3:08
let's see the internal trigger
3:12
you can find it in the reference Manual
3:16
here you can see the timer 2 can be a
3:19
slave to timer 1 and it will be
3:21
triggered by the ITR 0.
3:23
similarly the timer 3 can be triggered
3:26
by the timer 2 via the itr1 signal
3:30
let's configure the timer 2 now
3:35
the slave mode will be the external
3:37
clock mode and the trigger Source will
3:41
I am selecting the pwm on Channel 1 so
3:45
that we can see the output of this timer
3:48
now as I mentioned when the update event
3:50
is used with a combination of the
3:52
external clock mode the timer one's
3:54
output frequency will act as the input
3:56
clock for the timer too
3:59
timer 2's frequency will be equal to
4:01
input clock divided by the prescaler
4:03
times the auto reload
4:06
the timer 1 frequency is 10 kilohertz
4:08
and if we use the prescaler 1 and auto
4:11
reload of 100 the timer 2's frequency
4:20
so let's configure the prescaler as one
4:22
and the auto reload is 100.
4:25
I am keeping the pulse at 40 so the pwm
4:29
duty cycle will be 40 percent
4:32
this timer 2 is a slave to timer 1 and
4:35
master to time of three
4:37
so we also need to enable the trigger
4:40
event selection as the update event
4:43
now the timer 3 will also have the
4:45
similar configuration except that the
4:47
trigger sources from timer 2 so I tr1
4:51
timer 3 frequency will be calculated in
4:54
the similar Manner and if I use the auto
4:56
reload of 10 the frequency will be 10
5:02
now since the auto reload is set to 10 I
5:06
am keeping the pulse at 4 so that we
5:08
could get the duty cycle of 40 percent
5:13
now all three timers are set with timer
5:16
1 running at 10 kilohertz timer 2 at 100
5:20
Hertz and timer 3 at 10 Hertz
5:24
click save to generate the code
5:31
there is not much to do in the
5:33
programming part we will just start the
5:36
pwm for all three timers
5:39
all right let's build and Flash the code
5:43
I have connected the pwm pins to the
5:48
here we are getting the output from each
5:54
here you can see the timer one with 10
5:57
kilohertz frequency and 40 duty cycle
6:01
the timer 2 is running at 100 Hertz with
6:06
and timer 3 is at 10 Hertz with 40 Duty
6:11
this is as per the calculations we did
6:15
so we saw how the frequency of one timer
6:17
can be used as the clock for the second
6:21
using this we will Cascade three timers
6:24
and make a 48-bit counter so that we can
6:27
read a wide range of frequencies
6:30
this will be covered in the next video
6:34
let's take a look at the reset mode now
6:39
here I have already configured the
6:43
I have disabled timer 1 and timer 2 is
6:46
now in the master mode with pwm enabled
6:49
on Channel 1. it is being clocked by the
6:52
APB clock so the base frequency is at 90
6:56
the auto reload value of 10 000 will
6:59
reduce the clock to 9 kilohertz
7:02
also I am keeping the duty at 40 so with
7:05
the auto reload value being 10 000 this
7:08
is equivalent to 0.4 percent
7:11
here is the calculation for the timer 2
7:19
also the trigger event is set to update
7:23
now the timer 3 is the slave to timer 2
7:26
and is being used in the reset mode
7:29
in reset mode whenever the update event
7:31
is triggered it will reset the counter
7:35
the trigger signal is coming from timer
7:37
2 so it is set to itr1
7:41
as I mentioned when the update event is
7:43
used with the reset mode or trigger mode
7:46
all the timers will be clocked by the
7:48
APB clock unlike the previous case where
7:51
the frequency of the master timer served
7:53
as the clock for the slave timer
7:56
here I have set the auto reload of 1234.
8:02
the timer clock was 90 megahertz and now
8:05
it is around 73 kilohertz
8:08
the pulse is set to 300 which is
8:11
approximately 24 of the auto reload
8:15
this is it for the setup click save to
8:20
the code will remain the same just
8:23
comment out the timer 1 as it is not
8:27
let's build and Flash the code
8:30
here we are getting the pwm output for
8:37
you can see the timer 2 has the
8:39
frequency of 9 kilohertz and duty is
8:45
timer 3 has the frequency of around 73
8:48
kilohertz with the duty around 24
8:52
let's zoom in to understand what's
8:55
if you check the width of the timer 3
8:58
signal it is around 3 or 3.5
9:02
the data is a little bit inconsistent
9:05
because I can't use higher sampling rate
9:07
with this logic analyzer
9:09
but this is enough for us to understand
9:14
so the width is either 3 or 3.5
9:17
microseconds except at this point
9:21
here it is 5 microseconds
9:24
so what happened here
9:26
if you have seen my pwm video or
9:29
previous timer videos you would know
9:31
that this is the point where the
9:33
Overflow occurs in the timer too
9:35
when this happens an update event gets
9:38
triggered and the counter of timer 3
9:42
basically here the counter of timer 3
9:45
overflowed and then it started counting
9:47
up while doing so another reset signal
9:51
came and the counter resets back to zero
9:54
and again starts counting up if you
9:57
measure the time from here till the
9:59
signal goes low it will be approximately
10:01
the same as the others
10:03
this 3.5 microseconds is the actual
10:07
width of this pwm signal
10:09
we can calculate the similar thing at
10:12
any other point and it will give us the
10:14
time equal to the width of the signal
10:21
so you saw how the reset mode is used to
10:25
reset the counter of the slave timer
10:27
in this case the trigger Source was used
10:30
as the itr1 so the timer 2 was
10:33
responsible for this reset
10:35
but you can also use some external
10:37
signal to do this reset
10:40
we will see that in the upcoming videos
10:43
one more thing you notice that when
10:45
using the trigger mode the APB clock was
10:48
used as the timer clock
10:51
but if I switch it to the external clock
10:53
mode now the timer 2's frequency will be
10:56
used as the clock for timer 3.
10:58
let's quickly see the output of this
11:10
here you can see the frequency has been
11:12
reduced significantly this is because
11:15
now 9 kilohertz is being used as the
11:18
input clock rather than 90 megahertz in
11:22
so I hope this video was able to explain
11:25
the difference between the external
11:27
clock mode and the reset mode
11:30
in the next video we will use the
11:32
external clock mode and using that we
11:35
will create a 48-bit counter which will
11:37
then measure frequencies with larger
11:41
this is it for this video
11:43
the link to download the code is in the
11:47
leave comments in case of any doubt
11:51
keep watching and have a nice day ahead