Using STM32L1 analog comparators in application cases
Introduction
This document describes six application cases of the two analog comparators embedded in
the ultra low power STM32L1 product line. The application cases are:
●Analog voltage monitoring
●Analog watchdog during Stop mode
●Pulse width measurement
●Pulse width modulation (PWM) signal control
●Capacitance measurement
●Brightness control using a light dependent resistor (LDR)
The six application cases demonstrate the usefulness of analog comparators and show how
they are integrated with other peripherals, for example, the digital-to-analog-converter (DAC)
and timers.
To ensure a quick start, four application cases presented in this document are implemented
in C language and are available in Project\STM32L1xx_StdPeriph_Examples\COMP within
the STM32L1xx_StdPeriph_Lib package.
Please note that this document is not intended to replace the routing interface (RI) and
comparator sections in the product reference manual RM0038 (for STM32L1xx Ultra Low
Power devices).
The peripheral power consumption should be consulted in the device datasheets.
Ultra low power STM32L1 devices embed a 12-bit analog-to-digital converter (ADC) which
is very fast with a sampling rate of 1 Msample/s. However, with a 1.45 mA typical
consumption, it can jeopardize battery life time if left powered-on continuously. It is therefore
recommended to use analog comparators in application cases when analog input voltage
(sensor output) needs to be measured as soon as a pre-defined threshold is exceeded.
In STM32L1 devices, analog comparators are useful for monitoring the analog input voltage
and powering on the ADC when it is required. While monitoring the analog voltage, the
device can enter Stop mode at the same time that both comparators are still powered on.
Consequently, better consumption is achieved and power is saved.
Note:Analog comparators are powered by the internal reference voltage, V
powered on in Stop mode, and can be disabled by configuration. Once V
the comparators can no longer be used.
In an analog voltage monitoring application, where the sensor output voltage is lower than
the threshold, the MCU remains in Stop mode thereby saving power. As soon as the sensor
output exceeds the threshold, the MCU is woken up, the ADC is powered on, and the analog
input voltage is measured. When the sensor output is under the threshold, the MCU reenters Stop mode.
Average power consumption is dramatically reduced when compared with an application
that continuously measures the analog voltage whatever the input value.
Figure 1 shows how to connect a sensor output (temperature sensor, pressure sensor,
pyroelectric infrared detector, photodiode sensor) to an STM32L1 device in an analog
voltage monitoring application using comparator 2 (COMP2). COMP2 monitors the analog
voltage in Stop mode while the ADC measures it in Run mode.
Figure 1.Sensor output connection to COMP2
REFINT
REFINT
, which is still
is disabled,
1. Legend for Figure 1
ADC_CHx: AC channel x
COMP2_INP: comparator 2 non-inverting input
2. Only if required.
4/17Doc ID 17758 Rev 3
AN3248Analog voltage monitoring
Ai18734
Sensor
Analog
voltage
Amplifier
(2)
Filter
(2)
COMP1_INP/
ADC_CHx
(1)
STM32L1 device
SRSRS
RS
Input analog voltage
Analog threshold
Time
MCU state
Time
Time
MCU current consumption
Few mA
Few μA
ai17492
Figure 2 shows how to connect a sensor output to an STM32L1 device using comparator 1
(COMP1). COMP1 shares the same inputs as the ADC which reduces the number of
required pins. Nevertheless, the threshold is fixed to V
REFINT
.
Figure 2.Sensor output connection to COMP1
1. Legend for Figure 2
COMP1_INP/ADC CHx: comparator 1 non-inverting input shared with ADC channel x
2. Only if required.
Figure 3 shows the gain in power consumption in an analog monitoring application.
Figure 3.Power consumption in an analog voltage monitoring application
1. Legend for Figure 3
S: Stop mode
R: Run mode
The input analog voltage can be connected either to PB4 or PB5. The analog threshold can
be provided internally through V
PB3. DAC channel 1 and channel 2 (DAC_OUT1 and DAC_OUT2 respectively) cannot be
used in such application cases since the DAC channels are powered off in Stop mode.
and its submultiples or via an external pin through
REFINT
Doc ID 17758 Rev 35/17
Analog voltage monitoringAN3248
-
+
ai17493
GR6
GR6
PB4
PB5
Input voltage
COMP2
Wakeup
EXTI line 22
CMP2OUT
Analog threshold:
multiple sources
PB3
1/4 V
REFINT
1/2 V
REFINT
3/4 V
REFINT
V
REFINT
DAC_OUT2
DAC_OUT1
COMP2 wakes up the device from Stop mode through external interrupt line 22 (EXTI line
22).
Figure 4 shows the available configurations for inverting and non inverting inputs.
Figure 4.COMP2 configuration
1. Legend for Figure 4
DAC_OUT1: DAC channel 1 output
DAC_OUT2: DAC channel 2 output
V
: Internal reference voltage
REFINT
CMP2OUT: Comparator 2 output (internal output)
When the device enters Stop mode, only COMP2 and the internal reference voltage,
V
, remain powered on.
REFINT
Note:1Refer to the device datasheet for power consumption values.
2In High-density devices, pins PB6 and PB7 can be used also as COMP2 non-inverting
inputs.
3If the analog threshold corresponds to the internal reference voltage, V
REFINT
(1.22 V),
COMP1 can be used instead of COMP2 since it consumes much less power. In this case,
the input analog voltage can be connected to any channel among the 24 ADC channels.
6/17Doc ID 17758 Rev 3
Loading...
+ 11 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.