Hello! I've been cracking my head for some time to configure the HLVD module right, but for some reason I can't seem to get it working.
I can't see what I am doing wrong. I asked about it on the Microchip Forum and I got no answer
The program is supposed to bright a LED when HLVDCONbits.IRVST is ready to make an interruption then I am powering down the voltage below the trip point (4.3V) and when this happens it is supposed to bright another LED.
In reallity what happens is that I power up the circuit and nothing happens I've waited for over 10 mins for HLVDCONbits.IRVST but nothing happens. Then I unplug the circuit and the first LED brights but since the voltage is powering down the second LED brights instantly. I need to work at 48MHz because another application and that is why I put the trip point at 4.3V.
I tested ir with another source and the same thing happens. It seems that the module needs to sense a voltage variation to get ready or maybe my code is wrong. Please let me see my mistake. Thank you in advance.
Here is my code (sorry my comments are in spanish).
#include <reset.h>
#pragma config WDT=OFF, LVP=OFF, FOSC=XTPLL_XT, PLLDIV=1, CPUDIV=OSC1_PLL2
void high_int_handler (void); //Para la interrupcion
#pragma code high_interrupt = 0x08
void high_int (void){_asm goto high_int_handler _endasm}#pragma code
#pragma interrupt high_int_handler
void high_int_handler (void)
{
if (PIR2bits.HLVDIF)
{
HLVDCONbits.HLVDEN = 0;
PIR2bits.HLVDIF=0; // Bandera de interrupción del modulo HLVD
PORTB=0xFF;
PIE2bits.LVDIE = 0;
}
}
void main(void)
{
TRISA=0xFF;
TRISB=0x00;
PORTB=0x00;
TRISC=0x00;
PORTC=0x00;
// HLVDCONbits.IRVST; //1 HLVD listo! | 0 HLVD aún en proceso de encendido
HLVDCONbits.HLVDEN=0; //Apagar modulo HLVD
HLVDCONbits.HLVDL3=1;
HLVDCONbits.HLVDL2=1;
HLVDCONbits.HLVDL1=0;
HLVDCONbits.HLVDL0=1;
// HLVDL3:HLVDL0 = 1011 Referencia de 3.90V
// HLVDL3:HLVDL0 = 1100 Referencia de 4.11V
// HLVDL3:HLVDL0 = 1101 Referencia de 4.33V
// HLVDL3:HLVDL0 = 1110 Referencia de 4.59V
// HLVDL3:HLVDL0 = 1111 Referencia externa por RA5
HLVDCONbits.VDIRMAG=0; //Interrupción cuando el voltage cae a menos que el punto configurado
HLVDCONbits.HLVDEN=1; //Encender modulo HLVD
PIR2bits.HLVDIF=0; // Bandera de interrupción del modulo HLVD
while(HLVDCONbits.IRVST==0); //Espera hasta que el modulo de alta/baja tensión este listo
PORTC=0xFF;
PIE2bits.HLVDIE=1; //Habilitar la interrupción de detección de alta/baja tensión
IPR2bits.HLVDIP=1; //Hacer la interrupcion de HLVD de alta prioridad
RCONbits.IPEN = 1; //Habilitar prioridad de interrupciones
INTCONbits.GIE=1; //Habilita todas las interrupciones de alta prioridad
while(1)
{
}
}