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 ●...
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.
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.
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.
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.
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.
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.
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.
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.
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: ●...
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...
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.
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...
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.
Need help?
Do you have a question about the AN3248 and is the answer not in the manual?
Questions and answers