1.12 Getting Started with HLVD

1.12 Introduction

Author: Namrata Dalvi, Microchip technology Inc.

Many PIC® microcontrollers have a High/Low-Voltage Detect (HLVD) module that can be used to monitor the device voltage (VDD) and inform the user through an interrupt signal when the supply voltage drops below the specified threshold (i.e., trip point) or exceeds the trip point. This is a programmable circuit that allows the user to set the device voltage trip point and the direction of change from the trip point: positive going (exceeding the trip point), negative going (falling below the trip point) or both. This feature is useful in battery monitoring applications.

This technical brief describes the HLVD peripheral in detail. It also covers the following use cases:

  • Monitoring battery discharge
  • Detection of USB-power attach or detach

1.12.1 Relevant Devices

The following PIC® microcontroller families are equipped with the HLVD module:

  • PIC18-Q10
  • PIC18-K40
  • PIC18-K42
  • PIC18-K83

1.12.2 General Overview

The HLVD is a necessary power supply monitoring feature in numerous battery-powered applications, where the supply voltage of a microcontroller may fall below the specified threshold level and require battery replacement or recharging for the uninterrupted operation of the microcontroller. The HLVD feature is capable of monitoring the supply voltage of a microcontroller which is directly powered by a battery power source. The HLVD-based voltage monitoring circuitry has several advantages over an ADC-based voltage monitoring circuit, as listed below:

  1. The microcontroller PORT pins are not required to implement the supply voltage monitor.
  2. This module does not require external components, and hence no excess power consumption by the external circuitry.
  3. The HLVD module uses an internal bandgap reference and draws a typical of 22 µA when enabled. It can be disabled except when needed to reduce even this tiny current draw.
  4. It can generate an interrupt when VDD is below or above the selected trip point (depending on how it is configured).
    Note:
    1. The HLVD can only be used to measure the supply voltage of the microcontroller (i.e., VDD), so it cannot be used to monitor a battery supplying power through a voltage regulator.
    2. There are 16 steps over the measurement range with manufacturing tolerances on the bandgap reference and internal resistive voltage divider. The trip point settings shown below in Table 1-32 are available for a PIC18-Q10 family of devices. The trip point settings depend on the device used. Refer to the device data sheet for more details.

1.12.3 Block Diagram

The HLVD module’s block diagram is shown in the figure below.

Figure 1-106. HLVD Block Diagram

The HLVD can be software-enabled through the HLVDEN bit. Each time the HLVD module is enabled, the HLVDRDY bit can be used to detect when the module is stable and ready to use. The HLVDINTH and HLVDINTL bits of the HLVDCON0 register determine the overall operation of the module. When INTH is set, the module monitors for rise in VDD above the trip point set by the SEL bits. When INTL is set, the module monitors for drop in VDD below the trip point set by the SEL bits. When both the INTH and INTL bits are set, any changes above or below the trip point set by the SEL bits can be monitored. The OUT bit can be read to determine if the voltage is greater than or less than the selected trip point. If the supply voltage is below the set point, then the HLVDOUT bit will be set and, if the supply voltage is above the set point, the OUT bit will be cleared.

1.12.4 Detailed Operation

When the HLVD module is enabled, a comparator inside the HLVD module uses an internally generated voltage reference as the set point. The set point is compared with the trip point, where each node in the resistor divider represents a trip point voltage. The trip point voltage is the voltage level at which the device detects a high or low voltage event, depending on the configuration of the module. When the supply voltage is equal to the trip point, the voltage tapped from the resistor array is equal to the internal reference voltage generated by the voltage reference module. The comparator then generates an interrupt signal by setting the HLVDIF bit. The trip point voltage is software programmable to any of the 16 values. The trip point is selected by programming the SEL bits.

Table 1-32. HLVD Trip Point Settings
Sr. No. HLVDSEL Trip Point Voltage (V)
Min. Typ. Max.
1 HLVDSEL=b’0000’ 1.81 1.90 1.90
2 HLVDSEL=b’0001’ 2.00 2.10 2.12
3 HLVDSEL=b’0010’ 2.20 2.25 2.33
4 HLVDSEL=b’0011’ 2.40 2.50 2.54
5 HLVDSEL=b’0100’ 2.50 2.60 2.65
6 HLVDSEL=b’0101’ 2.70 2.75 2.86
7 HLVDSEL=b’0110’ 2.80 2.90 2.97
8 HLVDSEL=b’0111’ 3.00 3.15 3.18
9 HLVDSEL=b’1000’ 3.30 3.35 3.50
10 HLVDSEL=b’1001’ 3.50 3.60 3.71
11 HLVDSEL=b’1010’ 3.60 3.75 3.82
12 HLVDSEL=b’1011’ 3.80 4.00 4.03
13 HLVDSEL=b’1100’ 4.00 4.20 4.24
14 HLVDSEL=b’1101’ 4.20 4.35 4.45
15 HLVDSEL=b’1110’ 4.50 4.65 4.77
Note: Refer to the device data sheet for the typical Trip Point Voltage (V) settings and to the MPLAB® Code Configurator (MCC) configuration GUI of the HLVD peripheral for minimum and maximum Trip Point Voltage (V) settings.

1.12.4.1 Operation with Various Supply Voltages

The allowable operating voltage of the microcontroller should be considered in determining the low-level threshold that needs to be set. For instance, the PIC18-Q10 microcontrollers can operate up to 1.8V so all the voltage thresholds mentioned in Table 1-32 can be used. Some 8-bit PIC microcontrollers can operate up to 2.3V while others can operate up to 2V.

Note: The maximum allowed clock speed is a function of the supply voltage. The LF versions of the PIC microcontrollers can operate down to 2V at a maximum clock speed of 4 MHz.

Refer to the device data sheet to confirm the operating voltage range and maximum clock speed with respect to the operating voltage.

1.12.4.2 Operation of the Module in Various Sleep Modes

If enabled, the HLVD module can operate during various Power-Down modes such as Idle, Doze and Sleep mode. If the device voltage crosses the trip point, the HLVDIF bit will be set and the device will wake up from the Power-Down mode (i.e., Doze/Idle/Sleep). The device execution will continue from the interrupt vector address if interrupts have been globally enabled.

1.12.4.3 Current Consumption

When enabled, the HLVD module draws a typical current of 22 µA in the PIC18-Q10 devices. Refer to the Electrical Specifications section of the device data sheet for details on the current consumption.

1.12.4.4 HLVD Start-up Time

If the HLVD module is disabled to lower the device current consumption, the reference voltage used by the HLVD circuit will require time to become stable before a low or high-voltage condition can be reliably detected. This FVR start-up time (TFVRST), is typically 25 µs for the PIC18-Q10 devices. The HLVD interrupt flag is not enabled until TFVRST has expired and a stable reference voltage has been reached.

Note: The FVR start-up time (TFVRST), may vary with the PIC microcontroller family. Refer to the device data sheet to confirm the start-up time.

1.12.5 Applications