0:12
this is the ninth video in the SDM 32
0:15
timer series and today we will cover the
0:20
one pulse mode is used to generate a
0:22
pulse of a programmable length in
0:24
response to an external event
0:27
the pulse can start as soon as the input
0:29
trigger arrives or after a programmable
0:33
I have here a PDF explaining the
0:35
different modes of stm32 timers and here
0:39
is the one pulse mode
0:41
I will leave the link to the PDF in the
0:43
description of the video
0:45
as mentioned here the capture compare
0:48
registers value defines the pulse start
0:50
time and the auto reload value defines
0:55
so basically the effective pulse width
0:58
is the difference between the auto
1:00
reload and the CCR values
1:03
we can also program the output to be a
1:06
single pulse or a continuous pulse train
1:09
started by a single trigger
1:11
there is also a retricorable option
1:14
where the pulse width will simply extend
1:16
if a new trigger arrives before the
1:18
output pulse goes low
1:20
we will cover everything shown here in
1:24
let's see this in working and we will
1:26
start by creating a new project in the
1:31
I am using stm32f446re
1:36
give some name to the project and click
1:40
first of all I am selecting the external
1:43
Crystal for the clock
1:45
the board has 8 megahertz Crystal on it
1:47
and let's run the system at 90 megahertz
1:51
this will keep both the APB clocks at
1:54
the same 90 megahertz frequency and we
1:57
don't have to worry about which timer is
1:58
connected to which APB bus
2:01
let's configure the timer now
2:04
I am using timer 1 for this application
2:07
select the slave mode as the trigger
2:11
in trigger mode the counter starts at a
2:14
rising edge of the trigger but it does
2:17
the trigger source is set to
2:20
ti2fp2 that is the channel 2 of the
2:24
I am selecting Channel 2 for the trigger
2:26
because I am going to use Channel 1 for
2:30
you can see the pin pa9 has been
2:32
selected as the channel 2 pin and this
2:35
pin will be used as the input signal
2:38
set Channel 1 in the output compare mode
2:42
the pin pa8 will be used as the output
2:45
pin for the timer and here we will
2:47
measure the one pulse generated by the
2:51
make sure to enable the one pulse mode
2:55
now we will configure the timer's
2:58
since the APB timer clock is at 90
3:01
megahertz a prescaler of 90 will bring
3:04
the clock down to 1 megahertz
3:07
now the counter is counting at 1
3:09
megahertz so each count will take one
3:13
I am setting the auto reload to 50 000
3:16
so the counter period will be 50
3:20
this is also going to be the maximum
3:22
pulse width if we keep the capture
3:24
compare register at minimum
3:27
the trigger polarity for the input
3:29
signal is set to a rising Edge
3:32
we will change the mode of the output
3:34
compare later in the code the pulse is
3:37
basically the start time for the
3:39
generated pulse and I am keeping it at
3:41
10 000 that means 10 milliseconds
3:44
I have set the auto reload value to 50
3:48
000 which represents 50 milliseconds
3:51
this makes the effective pulse width of
3:53
40 milliseconds for the output signal
3:58
that's all we need to set up in the cube
4:01
MX click save to generate the project
4:04
let's see the connection first
4:07
here the black wire is connected to the
4:09
pin pa9 which is the input pin and is
4:13
connected to the button
4:15
the other end of the button is connected
4:17
to the 3.3 volt pin on the board
4:20
so if I press the button the pin pa9
4:23
will be pulled High to 3.3 volt and the
4:26
timer will recognize this as the trigger
4:28
signal the blue wire is connected to the
4:31
pin pa8 which is the output pin on
4:34
Channel 1 and is connected to the logic
4:36
analyzer where we will monitor the
4:41
go to the timer initialization function
4:45
here in the output compare mode open the
4:48
Declaration of the predefined mode
4:51
out of the listed modes choose the pwm2
4:56
this configuration is not available in
4:59
Cube MX so we need to manually do it
5:02
now in the main function start the timer
5:05
in the one pulse mode
5:09
I am using timer 1 channel 1.
5:14
let's build and run the code now
5:20
we will see the result in the logic
5:38
you can see whenever I am pressing the
5:40
button there is a pulse being generated
5:45
if you see the pulse width it is
5:47
approximately 40 milliseconds
5:50
this is as per the setup we did for the
5:54
we set the pulse start to 10
5:55
milliseconds and auto reload to 50
5:58
milliseconds and the width is the
6:00
difference between them that is 40
6:04
now let's see how to generate multiple
6:06
pulses with a single trigger
6:09
here in the timer configuration the
6:12
repetition counter was zero and this
6:14
would generate only one pulse
6:17
now let's assume that I want to generate
6:21
to do that I need to update the value 7
6:25
let's see how this is working
6:42
you can see when I am pressing the
6:44
button multiple pulses are being
6:51
there are a total of eight pulses each
6:54
having the width of 40 milliseconds
7:03
let's say if we want to generate the
7:05
pulse with a software trigger instead of
7:09
for this purpose we will use the
7:12
internal trigger mechanism between the
7:17
open the reference Manual of your
7:19
controller and search for the internal
7:23
here you can see the timer 1 can be the
7:26
slave to all these timers
7:28
and if I want to use the timer 2 as the
7:31
master I have to use the itr1 signal to
7:36
let's configure the timer too now
7:40
here I am selecting the clock source as
7:44
the timer 2 is also running at 90
7:46
megahertz and using the prescaler of 90
7:49
will bring down its clock to 1 megahertz
7:52
since the pulse width is set to 40
7:54
milliseconds in timer 1 I am going to
7:57
choose the trigger period higher than
8:00
the auto reload value of 60 000 will
8:03
generate the trigger every 60
8:06
set the trigger event selection to
8:10
now in the timer 1 we will set the
8:12
trigger source to itr1
8:15
you can see the channel 2 pin pa9 has
8:18
been disabled since the trigger has been
8:21
changed to internal now
8:23
the rest of the configuration is
8:27
let's generate the project now
8:31
here the repetition counter has been
8:35
and let's change this to the pwm2 mode
8:41
we also need to start the timer too so
8:44
that it can generate the trigger
8:54
let's build and run the project now
9:05
here you can see the pulse is high for
9:08
40 milliseconds and then low for 20
9:12
the timer 2 is generating the trigger
9:14
every 60 milliseconds and therefore we
9:17
see the pulse being low for 20
9:20
so we saw how to use the one pulse mode
9:22
with single and multiple pulses and also
9:25
how to use the software trigger to
9:27
generate the pulse now we will see the
9:30
retriguable one pulse mode
9:33
in order to use the retreigurable mode
9:35
the timer must be set in the reset and
9:38
Trigger mode combined
9:40
but this option is not available in the
9:45
actually the retriggerable mode is not
9:47
available in many controllers and
9:49
therefore I am going to use the F750
9:52
Discovery board for this purpose
10:01
I am going to use the same clock here so
10:04
that the configuration would remain the
10:13
here you see the combined reset trigger
10:16
mode it is available
10:18
the trigger source is selected as
10:21
the channel 1 is being used as the
10:26
enable the one pulse mode
10:29
here you can see the two pins for timer
10:33
I am going to use another pin for
10:35
channel 2 that is the PIN pc7
10:38
this is because I have this pin
10:40
available for connection
10:42
here pc7 is going to be the input pin
10:45
for channel 2 and pb4 is going to be the
10:50
since the clock is the same I am keeping
10:53
the same configuration
10:55
make sure to keep the pulse 0 for a
10:58
triggerable mode to work
11:00
for the output compare select the mode
11:03
as retriguable one pulse mode 2.
11:06
that's it for the configuration click
11:08
save to generate the project
11:11
I forgot to select an output pin so
11:14
let's select the pin PA 0.
11:17
the trigger signal will be provided by
11:21
let's see the connection I made for this
11:25
the black wire is connected between the
11:27
pin PA 0 and the timer input pin pc7
11:32
the blue wire is connected to the timer
11:35
output pin pb4 and to the logic analyzer
11:39
in the main function start the timer in
11:45
now in the while loop we will toggle the
11:54
the total time before the pin goes high
11:56
again is 40 milliseconds also keep in
12:00
mind that the pulse width is set to 50
12:02
milliseconds so the trigger will happen
12:04
before the pulse goes low
12:06
and if the retriggerable mode works the
12:09
pulse width will be extended
12:11
let's build and run this
12:14
here you can see the pulse remain high
12:16
and never goes back to low
12:19
this means the retreigurable mode is
12:23
let's change this delay so that the
12:26
trigger will take place every 60
12:29
our pulse width is 50 milliseconds so
12:32
now we should see the pulse going low
12:37
here you can see the pulse is high for
12:40
50 milliseconds and low for 12
12:43
the extra two milliseconds could be due
12:46
to whole processing time
12:52
let's change this to a total of 45
13:00
now the pulse is again being extended
13:03
because the trigger is happening before
13:06
if we try something similar without the
13:09
retriguable option being selected this
13:13
the pulse extends only when the
13:15
retriguable option is enabled
13:17
this is it for the video
13:19
I hope you understood the different
13:21
configuration is the one pulse mode
13:24
I will continue the timer series with
13:26
other modes in the upcoming videos
13:29
you can download the code from the link
13:33
leave comments in case of any doubt
13:36
keep watching and have a nice day ahead