STMicroelectronics AN3248 Application Note
STMicroelectronics AN3248 Application Note

STMicroelectronics AN3248 Application Note

Stm32l15xxx analog comparators

Advertisement

Quick Links

Introduction

This document describes six application cases of the two analog comparators embedded in
the ultra low power product line STM32L15xxx. 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.
The peripheral power consumption should be consulted in the device datasheets.
January 2011
STM32L15xxx analog comparators
Doc ID 17758 Rev 1
AN3248
Application note
1/19
www.st.com

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the AN3248 and is the answer not in the manual?

Questions and answers

Summary of Contents for STMicroelectronics AN3248

  • Page 1: Introduction

    AN3248 Application note STM32L15xxx analog comparators Introduction This document describes six application cases of the two analog comparators embedded in the ultra low power product line STM32L15xxx. The application cases are: ● Analog voltage monitoring ● Analog watchdog during Stop mode ●...
  • Page 2: Table Of Contents

    Contents AN3248 Contents Introduction ............1 Analog voltage monitoring .
  • Page 3 AN3248 List of tables List of tables Table 1. Document revision history ..........18...
  • Page 4 List of figures AN3248 List of figures Figure 1. Sensor output connection to COMP2 ......... . 5 Figure 2.
  • Page 5: Analog Voltage Monitoring

    AN3248 Analog voltage monitoring Analog voltage monitoring The STM32L15xxx embeds 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.
  • Page 6: Figure 2. Sensor Output Connection To Comp1

    Analog voltage monitoring AN3248 Figure 2 shows how to connect a sensor output to an STM32L15xxx 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.
  • Page 7: Figure 4. Comp2 Configuration

    AN3248 Analog voltage monitoring The input analog voltage can be connected either to PB4 or PB5. The analog threshold can be provided internally through V and its submultiples or via an external pin through REFINT 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.
  • Page 8: Analog Watchdog During Stop Mode

    Analog watchdog during Stop mode AN3248 Analog watchdog during Stop mode The ADC in the STM32L family can be used as an analog watchdog with programmable high and low thresholds. Nevertheless, the MCU must be kept in Run mode to be able to watch analog voltage on input since the ADC is powered off in Stop mode.
  • Page 9: Figure 6. Analog Watchdog During Stop Mode

    AN3248 Analog watchdog during Stop mode In an analog watchdog application, COMP1 is configured through external interrupt line 21 (EXTI line 21) to exit the MCU from Stop mode when the analog input voltage exceeds . COMP2 is set, through EXTI line 22, to exit the MCU from Stop mode when the REFINT analog voltage goes below the lower threshold.
  • Page 10: Pulse Width Measurement

    Pulse width measurement AN3248 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.
  • Page 11: Figure 8. Pulse Width Measurement: Comp2 Output Redirection To Timer

    AN3248 Pulse width measurement Figure 8. Pulse width measurement: COMP2 output redirection to timer 1. The duration that should be measured 2. In the pulse width measurement application, COMP1 cannot be used since its output CMP1OUT (internal output) is not connected to the embedded timers.
  • Page 12: Pwm Signal Control

    PWM signal control AN3248 PWM signal control In STM32L15xxx devices, the COMP2 output can be redirected to the output compare reference clear signal (OCREFCLR) of the embedded timers: TIM2, TIM3, and TIM4 (refer Figure 7: COMP2 with output redirection feature). The possibility of redirecting the COMP2 output can be used to provide a fast response time that is independent from the system frequency when an analog event occurs.
  • Page 13: Capacitance Measurement

    AN3248 Capacitance measurement Capacitance measurement The ability to connect the COMP2 output to the input capture channels of the timers allows the capacitance value to be measured. The principle is based on measuring the charge time of a resistor-capacitor (RC) network as follows: ●...
  • Page 14: Figure 11. Capacitance Measurement Using Comp2

    Capacitance measurement AN3248 Figure 11. Capacitance measurement using COMP2 At the moment where the input voltage crosses the threshold and the COMP2 output switches to high level, the charge function is given by Equation Equation 1 ⁄ Threshold VDD 1 –...
  • Page 15 AN3248 Capacitance measurement Equation 3 ⁄ – where K is solved using Equation 4 Equation 4 × ⁄ 1-threshold Doc ID 17758 Rev 1 15/19...
  • Page 16: Brightness Control Using A Light Dependent Resistor

    Brightness control using a light dependent resistor (LDR) AN3248 Brightness control using a light dependent resistor (LDR) In some battery operated applications, the microcontroller needs to be powered if the environment is lit otherwise, it must be kept powered-off. For such applications, a light dependent resistor (LDR), whose resistance depends on light intensity, is useful to control the microcontroller state.
  • Page 17: Figure 13. Comparator Output Behavior Versus Light Intensity

    AN3248 Brightness control using a light dependent resistor (LDR) The top part of Figure 13 shows the evolution of V as a function of light variation. The selected threshold (COMP2 inverting input) defines the limit of dark/light. The bottom part of...
  • Page 18: Revision History

    Revision history AN3248 Revision history Table 1. Document revision history Date Revision Changes 10-Jan-2011 Initial release. 18/19 Doc ID 17758 Rev 1...
  • Page 19 Please Read Carefully: Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any time, without notice.

Table of Contents