5.1 Battery Monitoring
Monitoring the battery voltage is very important in case of battery-powered applications for safe and steady operation of the system and for protecting the battery from operating outside its safe operating area. The below section discusses how to monitor battery discharging cycles when the HLVD peripheral is used.
- Monitoring Battery Discharge:
Determining the threshold for ‘low battery’ depends on the battery chemistry and the
load drawn by the circuit. A typical discharge curve of a 1.2V battery is shown in
Figure 2. The voltage decreases slowly in the operating range of the battery but
starts to fall rapidly when the battery depletes. The challenge is to get the
maximum life from the battery but still provide a warning in time to allow any
action which is necessary before the battery is dead. The blue lines show that 90%
of the battery capacity has been used and the cell voltage at this point is about
1.19V. The red line shows that 95% of the battery capacity has been used and that
the cell voltage is about 1.1V. The cell voltage is dropping rapidly at this point.
A three-cell pack would provide 4.2V with new and unused batteries. The 90% point
would be 3.57V, and the 95% point would be 3.3V. This need to fit with the HLVD
thresholds of the device. HLVDSEL=
b'1001'
provides a trip point of 3.6V and the next setting HLVDSEL=b'1000
' provides a trip point of 3.35V. Thus, in order to provide a warning at 90% battery depletion, the HLVDSEL=b'1001
' can be used.
- Set the trip point voltage for HLVD. Set the INTL bit and enable the HLVD module. (event t1 in the figure above).
- The HLVD module will be ready after the HLVD start-up time, typically 25 uS in the PIC18-Q10 devices (t2).
- When the supply voltage goes below the trip point, the OUT bit will be set and the HLVD module will generate an interrupt for INTL (t3).
- The HLVDIF flag can be cleared in Interrupt Service Routine (ISR) and a warning can be generated for the low-voltage detect (t4) event.
The MPLAB® Code Configurator (MCC) is a free, graphical programming environment that generates seamless, easy-to-understand C code to be inserted into the project. Using an intuitive interface, it enables and configures a rich set of peripherals and functions specific to the application. The HLVD configuration in MCC for detecting low-voltage events is explained below:
- Select the HLVD module from the Device Resources tab in the MCC Configuration window.
- Select the desired HLVD trip point from the drop-down options. This will alter the values in the HLVDSEL bits of the HLVDCON1 register. The value selected here is ‘Min:3.50’ and ‘Max:3.71’.
- To detect the low-voltage drops, set the check box for enabling negative going interrupt which will set the INTL bit.
- Enable the HLVD module by checking the ‘Enable HLVD’ check box .
- If interrupts are desired, enable the HLVD interrupt by setting the ‘Enable HLVD Interrupt’ check box .
In the Interrupt Service Routine (ISR), add relevant application code to take appropriate action.
- The
HLVD_Initialize()
API can be used for initialization of the HLVD module.void HLVD_Initialize(void) { // set the HLVD_Initialize module to the options selected in the User Interface // SEL Min:3.00 Max:3.18; HLVDCON1 = 0x07; // HLVDINTL enabled; HLVDINTH disabled; HLVDEN enabled; HLVDCON0 = 0x81; PIR2bits.HLVDIF = 0; // Enable HLVD interrupt. PIE2bits.HLVDIE = 1; }
- The
HLVD_OutputStatusGet()
API can be used to determine the status of the HLVDOUT bit.bool HLVD_OutputStatusGet(void) { //return HLVD voltage status return(HLVDCON0bits.HLVDOUT);
- If the HLVD trip point has to be
changed, then the
HLVD_TripPointSetup(bool Negative_Trip,bool Positive_Trip, HLVD_TRIP_POINTS trip_points)
API can be used.void HLVD_TripPointSetup(bool Negative_Trip,bool Positive_Trip, HLVD_TRIP_POINTS trip_points) { //set Negative trip HLVDCON0bits.HLVDINTL = Negative_Trip; //set Positive trip HLVDCON0bits.HLVDINTH = Positive_Trip; // Set trip points HLVDCON1 = trip_points; }