For those people who might visit this thread I will post the solution to using the HLVD module as I was able to resolve with some offline support from Darrel Taylor.
First, you need to make sure you have setup a DT_INTS-18 interrupt for the HLVD module by inclusion of this code:
Code:
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
;INT_Handler USB_Handler
INT_Handler HLVD_INT, _LowVolt, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
Then you need to insert this in your code ahead of the main loop to setup the use of the HLVD module.
Code:
' Set registers for using HLVD feature
' Step 1-Disable the module by clearing HLVDCON.4
HLVDCON.4 = 0 ' Implement Step 1
' Step2 HLVD3:HLVDL0=1101 'Set the trip point at Vdd=4.33 vdc
' Step3 HLVDCON.7=0 'Set VDIRMAG=0 to detect low voltage transition
' Step4 HLVDCON.4=1 'Enable the HLVD module
HLVDCON = %00011101 'Implements Steps 2-4
' Clear the HLVDIF interrupt flag (PIR2<2>)
PIR2.2 = 0
' Enable the HLVD interrupt
@ INT_ENABLE HLVD_INT ; enable HLVD interrupt
Then you need to create an interrupt service routine (ISR) nead the end of your code as follows:
Code:
LowVolt:
' Blink LED_RED 5X to indicate Low Battery voltage detected
For i = 0 to 4
HIGH LED_RED
Pause 500
LOW LED_RED
PAUSE 500
Next
@ INT_DISABLE HLVD_INT ; This statement very important, else code will lockup on exit
; from the ISR to main program.
' Resume Main Program
@ INT_RETURN
'------------------{ End of Interrupt Handlers }-------------------------
Hope this might help someone!
Bookmarks