Author Topic: I can't use HLVD for PIC 18F2550. HELP!  (Read 2562 times)

0 Members and 1 Guest are viewing this topic.

Offline diegoterc3

  • Regular Contributor
  • *
  • Posts: 62
  • Country: pe
I can't use HLVD for PIC 18F2550. HELP!
« on: October 08, 2013, 06:48:38 pm »
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)
 {
 
 }
 }
 
 

Offline RjSa

  • Contributor
  • Posts: 21
  • Country: ve
Re: I can't use HLVD for PIC 18F2550. HELP!
« Reply #1 on: October 08, 2013, 08:16:18 pm »
It seems you are following the steps correctly. Let me run it and ill let you know because I dont use C18 that much.
 

Offline Jon Chandler

  • Frequent Contributor
  • **
  • Posts: 545
    • Throw Away PIC
Re: I can't use HLVD for PIC 18F2550. HELP!
« Reply #2 on: October 08, 2013, 08:36:13 pm »
Here are the steps I followed to use the HLVD module.  The article talks about the steps needed when using Swordfish Basic, but the register settings should be the same.
 

Offline RjSa

  • Contributor
  • Posts: 21
  • Country: ve
Re: I can't use HLVD for PIC 18F2550. HELP!
« Reply #3 on: October 09, 2013, 02:09:15 am »
I just test it on the bench and it works as its suposed to work. Check your circuit connections, pic and/or programmer because there is no error in your code.

The only thing I found was some extra code (delete the text in bold). I assume this was an error when you copy/paste since It wont compile with that extra code:

void high_int (void){_asm goto high_int_handler _endasm} #pragma code
« Last Edit: October 09, 2013, 02:40:51 am by RjSa »
 

Offline diegoterc3

  • Regular Contributor
  • *
  • Posts: 62
  • Country: pe
Re: I can't use HLVD for PIC 18F2550. HELP!
« Reply #4 on: October 10, 2013, 08:08:41 am »
Thank  you so much for your answers, I will need to buy another source and do it all over again saddly but since it has worked for one of you, it should work for me as well.

Muchas gracias!
 

Offline RjSa

  • Contributor
  • Posts: 21
  • Country: ve
Re: I can't use HLVD for PIC 18F2550. HELP!
« Reply #5 on: October 10, 2013, 03:14:23 pm »
Have you checked the voltage and connections? What is the schematic you are using? I suggest you do this before you start replacing your equipment.

Maybe you can post some pictures of your circuit so we can help you a bit further.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf