In case anyone else is interested.
The initial setup
The interrupt handler
The initial setup
Code:
HLVDCONbits.HLVDEN = 0; // Disable HLDV
HLVDCONbits.HLVDL = 0b1101; // Set point 3.13V
HLVDCONbits.VDIRMAG = 0; // Interrupt when voltage drops
PIR2bits.HLVDIF = 0; // Clear the HLVD interrupt flag
HLVDCONbits.HLVDEN = 1; // Enable HLDV
RCONbits.IPEN = 1;
INTCONbits.GIEH = 1; // Enable general interrupts high
PIE2bits.HLVDIE = 1; // Enable l
Code:
void interrupt high_priority interrupts_highPriority(void) {
if (PIR2bits.HLVDIF == 1) {
PIR2bits.HLVDIF = 0;
if (HLVDCONbits.VDIRMAG == 0) // A low voltage interrupt was triggered
{
LATAbits.LA2 = 1;
INTCONbits.GIEH = 0; // Disable general interrupts high
PIE2bits.HLVDIE = 0; // Disable low voltage detect interrupt
HLVDCONbits.HLVDEN = 0; // Disable HLDV
HLVDCONbits.HLVDL = 0b1101; // Set point 3.13V
HLVDCONbits.VDIRMAG = 1; // Interrupt when voltage drops
PIR2bits.HLVDIF = 0; // Clear the HLVD interrupt flag
HLVDCONbits.HLVDEN = 1; // Enable HLDV
INTCONbits.GIEH = 1; // Enable general interrupts high
PIE2bits.HLVDIE = 1; // Enable low voltage detect interrupt
} else {
LATAbits.LA2 = 0;
INTCONbits.GIEH = 0; // Disable general interrupts high
PIE2bits.HLVDIE = 0; // Disable low voltage detect interrupt
HLVDCONbits.HLVDEN = 0; // Disable HLDV
HLVDCONbits.HLVDL = 0b1101; // Set point 3.13V
HLVDCONbits.VDIRMAG = 0; // Interrupt when voltage drops
PIR2bits.HLVDIF = 0; // Clear the HLVD interrupt flag
HLVDCONbits.HLVDEN = 1; // Enable HLDV
INTCONbits.GIEH = 1; // Enable general interrupts high
PIE2bits.HLVDIE = 1; // Enable low voltage detect interrupt
}
}
}
Last edited: