Pulse width measurement
AN3248
10/19
Doc ID 17758 Rev 1
3
Pulse width measurement
In STM32L15xxx devices, the COMP2 output can be redirected to the input capture of the
embedded timers: TIM2, TIM3, TIM4, and TIM10. Redirecting the COMP2 output allows a
signal width or frequency with specific low and high levels (for example, a shifted signal) to
be measured.
Figure 7
displays all the possible output redirections of the COMP2 output.
The input signal, whose signal width should be measured, is connected to any I/O of analog
switches group 6 (PB4 or PB5). The reference signal can be powered by:
●
an internal reference (V
REFINT
, 3/4 V
REFINT
, 1/2 V
REFINT
, or 1/4 V
REFINT
)
●
the built-in DAC (channel 1 or channel 2)
●
an external pin through PB3
The COMP2 output redirection is achieved through the OUTSEL[2:0] bits.
The timer input capture channel is configured to save the timer counter at both rising and
falling edges. When the input signal goes above the reference voltage, COMP2 output is at
a high level generating a rising edge on the timer input capture. When the input signal goes
under the reference voltage, COMP2 output is at low level generating a falling edge. The
elapsed time between the two consecutive events (falling then rising edge or rising then
falling edge) represents the pulse width. Hence, the pulse width measurement is performed
by simple subtraction of the counter values.
Figure 8
gives an overview of the pulse width
measurement as measured by COMP2.
Figure 7.
COMP2 with output redirection feature
1.
Legend for
Figure 7
DAC_OUT1: DAC channel 1 output
DAC_OUT2: DAC channel 2 output
V
REFINT
: Internal reference voltage
CMP2OUT: Comparator 2 output (internal output)
TIMx ICy: Timer x input capture channel y
TIMx OCREFCLR: Timer x output compare reference clear
0"
#/-0
0"
'2
'2
#-0/54
7AKEUP
%84)LINE
0"
$!#?/54
$!#?/54
62%&).4
62%&).4
62%&).4
62%&).4
)NPUTVOLTAGE
4)-)#
4)-/#2%#,2
4)-)#
4)-/#2%&#,2
4)-)#
4)-/#2%#,2
4)-)#
/543%,;=
AI
4HRESHOLD
MULTIPLESOURCES