ST AN4112 Application note

AN4112

Application note

Using STM32F05xx analog comparators in application cases

Introduction

This document describes six application cases of the two analog comparators embedded in the ultra-low power STM32F05xx 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 available in Project\STM32F0xx_StdPeriph_Examples\COMP within the STM32F0xx_StdPeriph_Lib package.

Please note that this document is not intended to replace the comparator section in the product reference manual RM0091 (for STM32F05xx ).

The peripheral power consumption should be consulted in the device datasheets.

Table 1.

Applicable products

 

 

Type

Part numbers

 

 

Microcontrollers

STM32F05xx

 

 

 

June 2012

Doc ID 023195 Rev 1

1/17

www.st.com

Contents

AN4112

 

 

Contents

1

Analog voltage monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. 4

2

Analog watchdog during Stop mode . . . . . . . . . . . . . . . . . . . . . . . . . . . .

7

3

Pulse width measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

9

4

PWM signal control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

11

5

Capacitance measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

12

6

Brightness control using a light dependent resistor

 

 

(LDR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

14

7

Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

16

2/17

Doc ID 023195 Rev 1

AN4112

List of figures

 

 

List of figures

Figure 1. Sensor output connection to COMP2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Figure 2. Power consumption in an analog voltage monitoring application . . . . . . . . . . . . . . . . . . . . . 5 Figure 3. COMP2 configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Figure 4. Analog comparators combined in window mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Figure 5. Analog watchdog during Stop mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Figure 6. COMP2 with output redirection feature. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Figure 7. Pulse width measurement: COMP2 output redirection to timer . . . . . . . . . . . . . . . . . . . . . 10 Figure 8. PWM signal control: COMP2 output redirection to timer . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Figure 9. RC network connection for capacitance measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Figure 10. Capacitance measurement using COMP2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Figure 11. Connecting an LDR resistor to an STM32F05xx device . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Figure 12. Comparator output behavior versus light intensity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

Doc ID 023195 Rev 1

3/17

Analog voltage monitoring

AN4112

 

 

 

1

Analog voltage monitoring

 

 

The STM32F05xx 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.5 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 where the analog input voltage (sensor output)

 

needs to be measured as soon as a pre-defined threshold is exceeded.

 

 

In the STM32F05xx devices, analog comparators are useful for monitoring the analog input

 

voltage and powering-on the ADC when 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, VREFINT, which is still

 

powered-on in Stop mode. Once VREFINT is disabled, 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.

The 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 STM32F05xx 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

 

!NALOG

 

 

 

 

34- & XX

 

 

 

 

 

 

3ENSOR

VOLTAGE

!MPLIFIER

 

!$#?#( ?

 

&ILTER

 

 

 

#/-0 ?).0

 

 

 

 

 

 

 

-3 6

1.ADC_CH1: AC channel 1

COMP2_INP: comparator 2 non-inverting input

2.Only if required.

4/17

Doc ID 023195 Rev 1

ST AN4112 Application note

AN4112

Analog voltage monitoring

 

 

Figure 2. Power consumption in an analog voltage monitoring application

)NPUTPANALOG VOLTAGE

!NALOG THRESHOLD

4IME

-#5#STATE

3 34/0 MODE

2 25. MODE

3

2

3

2

3

2

3

 

 

 

 

 

 

4IME

-#5#CURRENTUCONSUMPTION

&EWWM!

&EWW !

4IME

AI

The input analog voltage can be connected to PA1 for COMP1 or PA3 for COMP2. The

analog threshold can be provided internally through VREFINT and its submultiples or via an external pin through PA0 or PA5 for COMP1 or PA2 or PA5 for COMP2. DAC channel 1

(DAC_OUT) cannot be used in such application cases since the DAC channel is powered off in Stop mode. COMPx wakes up the device from Stop mode through external interrupt lines (EXTI lines 21 and 22).

Figure 3 shows the available configurations for inverting and non-inverting inputs.

Doc ID 023195 Rev 1

5/17

Analog voltage monitoring

 

AN4112

Figure 3. COMP2 configuration

 

 

 

7AKEUP

 

 

%84) LINE

0!

)NPUTPVOLTAGE

#/-0

 

 

 

 

0!

 

#/-0 /54

0!

 

 

$!#?/54

 

 

!NALOG THRESHOLD

62%&).4

 

MULTIPLEISOURCES

 

 

62%&).4

 

 

62%&).4

 

 

62%&).4

 

 

-3 6

 

1. DAC_OUT: DAC channel 1 output

 

 

VREFINT: Internal reference voltage

 

 

COMP2OUT: comparator 2 output (internal output)

 

When the device enters Stop mode, only COMP2 and the internal reference voltage,

 

VREFINT, remain powered on.

 

Note:

Refer to the device datasheet for power consumption values.

6/17

Doc ID 023195 Rev 1

Loading...
+ 11 hidden pages