0:09
hello and welcome to controllers Tech
0:13
this is the sixth video in the SDM 32
0:16
timer series and today we will continue
0:18
with another application of the timer
0:22
in the previous video we saw how the
0:24
master timer can control the start of
0:26
the counter of the slave timer by using
0:29
the slave mode along with the trigger
0:32
there was however a restriction
0:35
the slave counter could start only when
0:37
the master counter overflows
0:40
today we will see how the master timer
0:42
can issue a trigger signal when it
0:44
reaches a predefined value and by making
0:46
use of this feature we will generate a
0:49
three-phase pwm signal
0:51
basically the signal will be generated
0:54
when the counter reaches 33 of its value
0:58
this is the point where the timer 2 will
1:00
start counting and it will also generate
1:03
a signal when it reaches 33 percent of
1:07
then the timer 3 will start counting
1:10
since all the timers will have the same
1:13
frequency and Duty we will be able to
1:15
generate three pwm signals which will be
1:18
120 degrees out of phase with each other
1:22
here you can see the internal trigger
1:24
connection which you can find in the
1:26
reference Manual of your controller
1:29
this is the table for
1:34
you can see the timer 2 can be
1:36
controlled by timer 1 by using the itr0
1:41
similarly the timer 3 can be controlled
1:44
by the timer 2 by using the itr1 signal
1:48
this table might be different for your
1:50
controller so you must look in the
1:52
reference Manual of your controller
1:55
this is the picture I took from one of
1:59
here you can see how this whole system
2:03
basically the timer one will generate a
2:06
pwm signal and when the counter reaches
2:09
the 33 percent of its value its output
2:11
compare signal will go high
2:14
this is where the itr0 signal will be
2:17
issued and the timer 2 will start
2:19
counting from this point
2:22
when the timer 2's counter reaches 33 of
2:25
its value its output compare signal will
2:29
and this is the point where the timer 2
2:32
will generate the itr1 signal and the
2:35
timer 3 will start counting from this
2:38
let's start the cube IDE and create a
2:45
I am using the nucleo
2:51
give some name to the project and click
2:57
let's set up the clocks first
3:00
I am selecting the external Crystal to
3:04
the board has eight megahertz Crystal on
3:06
it and I want to run the system at 90
3:11
I am choosing 90 because that's the
3:14
maximum clock at which the APB one time
3:18
and I want both the APB buses to run at
3:21
the same frequency so that we could use
3:23
the same configuration for all three
3:26
let's configure the timers now
3:29
timer 1 is going to be the master for
3:33
here we will generate the pwm signal on
3:38
also output compare with no output on
3:41
channel 2 as this will be used for the
3:45
let's configure the pwm frequency and
3:48
duty cycle the timer is running at 90
3:51
megahertz so a prescaler of 90 will
3:54
bring down the frequency to 1 megahertz
3:57
then the auto reload of 10 000 will
4:00
further reduce the frequency to 100
4:03
now for the trigger event selection we
4:06
will go with the output compare for
4:08
Channel 2. this oc2 ref is used as the
4:12
trigger signal and it will trigger the
4:15
here I am setting the pwm signal duty
4:22
for the output compare change the mode
4:24
to active level on Match
4:27
this will basically activate the signal
4:29
once the counter value matches the
4:33
and this compare value we will set it at
4:35
33 of the auto reload value
4:39
this is it for the timer one let's
4:41
configure the timer 2 now
4:45
timer 2 will act as a slave for timer 1
4:47
and master for timer 3. we will use the
4:51
trigger mode so that the counter starts
4:53
counting once the itr0 signal is
4:56
received by the timer
4:58
the rest of the configuration is exactly
5:00
the same as the timer 1.
5:02
so basically the timer 2 counter will
5:05
start upon receiving the signal from the
5:07
timer 1. once the counter reaches 33 of
5:11
the auto reload value the output compare
5:14
signal will go high which will generate
5:19
and now we will configure the time of 3
5:21
which is a slave to the timer 2 and can
5:24
be controlled by using the itr1 trigger
5:28
we don't need to generate the output
5:30
compare for timer 3 and the rest of the
5:32
configuration is the same as that of the
5:36
here these three pwm output pins are
5:39
connected to the logic analyzer
5:42
let's save the project to generate the
5:50
there is not much in the coding part we
5:53
just have to start the pwm for channel 1
5:55
and output compare for Channel 2.
6:14
we will only enable the pwm for timer 3
6:17
as we have not set the output compare
6:21
that's it for the code part let's build
6:24
and Flash it to the board
6:44
I am using the logic analyzer to see the
6:50
let me reset the board once
6:55
we will start at the first Rising edge
6:57
of the timer 1 output
7:15
I am setting two more markers for the
7:27
now in the measurement set the first
7:32
you can see the timestamps of the other
7:34
markers compared to the first one
7:37
note that all three pwm have the same
7:40
frequency of 100 Hertz so the period is
7:45
now you can see the second pwm starts at
7:48
3.3 milliseconds and the third one
7:51
starts at 6.6 milliseconds
7:55
if you convert this time to angles you
7:57
could observe the 120 degrees phase
8:00
difference between these waves
8:03
this phase difference will remain
8:05
constant so if you add more markers
8:08
anywhere on the waves you could still
8:10
see the same time difference between
8:25
so we saw how to generate a three-phase
8:28
pwm signal using the timer
8:30
synchronization technique
8:32
I hope you understood the process
8:35
I will continue the timer series and in
8:38
the next video we will see how to
8:40
Cascade the timers so that we can make
8:42
two 16-bit timers to behave as a single
8:50
the link to download the code is in the
8:54
leave comments in case of any doubt keep
8:57
watching and have a nice day ahead