0:12
this is the 10th video in the SDM 32
0:15
timer series and today we will see
0:17
another application of the timer in
0:21
we will see how to use the timer in the
0:25
you can use this application note
0:28
an4013 to see the timer applications
0:32
we have already covered other slave
0:34
modes which includes reset mode trigger
0:37
mode and combined reset and Trigger mode
0:39
so today we will finally see the Gated
0:43
as mentioned here in gated mode the
0:46
counter clock can be controlled by the
0:50
also both the start and stop of the
0:52
counter can be controlled
0:54
basically I am going to use a button to
0:57
control the trigger signal and the timer
0:59
will output a pwm wave
1:02
when the button is pressed the trigger
1:04
will go low this should enable the
1:06
counter and the timer will output a pwm
1:10
when the button is released the trigger
1:13
goes High the counter clock will be
1:15
disabled and so does the pwm output of
1:19
I will also cover how to automate this
1:21
process where a fixed pwm signal will be
1:25
generated at a fixed rate
1:27
we will see the connection diagram in a
1:30
while let's start the cube IDE and
1:38
stm32f446re nucleo board
1:41
give some name to the project and click
1:45
we will start with the clock first
1:48
I am selecting the external Crystal to
1:50
provide the clock for the controller
1:53
the board has 8 megahertz Crystal and I
1:56
want to run the system at maximum 180
2:03
now let's configure the timer 1 in the
2:07
select the Gated mode under the slave
2:11
since I want to use the button for the
2:13
trigger the trigger source is set to ti1
2:17
this will enable Channel 1 for the
2:19
trigger and here you can see the pin p8
2:21
has been enabled where we will connect
2:25
I am setting the trigger polarity to the
2:29
now let's configure Channel 2 for the
2:33
timer 1 is connected to apb2 bus which
2:37
is running at 180 megahertz right now
2:41
using a prescaler of 180 will bring down
2:44
the clock to 1 megahertz
2:47
the counter value of 1000 will further
2:50
reduce the clock to 1 kilohertz and this
2:52
will be the output frequency of the pwm
2:56
I am using the pwm mode 2 and I am
3:00
setting the pulse at 500 which is 50 of
3:03
the auto reload value therefore the pwm
3:06
duty cycle will be 50 percent
3:09
if you don't understand the pwm
3:11
configuration watch the pwm video in the
3:16
so this is it click save to generate the
3:21
let City Connection now
3:23
I have connected the button between the
3:26
ground pin and the pa8
3:28
the pin pa9 is connected to the logic
3:31
analyzer where we will see the pwm
3:36
let's write the code now
3:38
in the main function we will simply
3:41
start the timer in the pwm mode
3:44
I am using timer 1 and channel 2.
3:48
let's build and run the code now
3:53
we will see the output in the logic
3:56
I have connected the output of the
3:58
button to channel 1 and the pwm output
4:08
here you can see whenever the button is
4:10
pressed the output on Channel 1 goes low
4:13
and along with it we see the wave being
4:15
generated on Channel 2.
4:18
the pwm signal continues as long as the
4:21
button is pressed and when it is
4:23
released the signal also stops
4:26
if you zoom in here you can see the pwm
4:29
signal has a frequency of one kilohertz
4:31
and the duty cycle is 50 percent
4:34
this is as per the setup we did for the
4:38
so this is working well with the pwm
4:41
signal being controlled by the button
4:44
now let's say we want to automate this
4:47
process where we want to generate the
4:49
pwm signal of the same one kilohertz
4:52
frequency at some fixed rate
4:55
before we use another timer for this
4:57
let's see the MCU reference manual
5:01
here if you look for the internal
5:03
trigger connection you will find a table
5:07
I have already explained this in the
5:09
previous time of videos
5:11
here you can see that the timer 1 is a
5:14
slave to the timer 2 and it can be
5:16
controlled via the signal itr1
5:19
so we will change the trigger Source
5:25
the channel 1 pin has been disabled
5:28
since we are using the internal trigger
5:31
we will use the timer 2 to generate the
5:34
trigger signal at some fixed rate
5:37
here we will generate the pwm signal
5:41
this is because the output will be used
5:44
for the trigger signal
5:46
timer 2 is connected to the apb1 bus
5:49
which is running at 90 megahertz right
5:52
using the prescaler of 90 will bring
5:55
down the clock to 1 megahertz
5:58
the auto reload value of 100 000 will
6:01
further reduce the clock to 10 Hertz
6:04
this is the rate at which the pwm will
6:09
the trigger event is set to Output
6:11
compare of Channel 1.
6:13
I am using the pulse value of 50 000
6:16
which is half the auto reload value and
6:19
this will make the duty cycle 50 percent
6:22
this will keep the trigger signal high
6:24
and low for an equal amount of time
6:27
this is it for the setup let's generate
6:31
here in the main function we will start
6:34
the timer in pwm mode
6:36
we are using channel one of the timer 2.
6:40
let's build and Flash the code to the
6:49
here you can see the pwm being generated
7:00
the time difference between two signals
7:02
is 100 milliseconds which corresponds to
7:07
the pwm signal is still one kilohertz
7:10
that we set in the timer 1. so we
7:14
finally have a pwm signal of one
7:16
kilohertz being generated at a rate of
7:20
this is it for the video
7:22
I hope you understood how to use the
7:25
Gated mode in the timer
7:27
you can download the code from the link
7:31
leave comments in case of any doubt
7:34
keep watching and have a nice day ahead