I can't use HLVD for PIC 18F2550. HELP! - Page 1
Forum section: electronics / general

author: diegoterc3
author_rank: Regular Contributor
timestamp: October 08, 2013, 06:48:38 pm
content: 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 answerThe 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_PLL2void high_int_handler (void); //Para la interrupcion#pragma code high_interrupt = 0x08void high_int (void){_asm goto high_int_handler _endasm}#pragma code#pragma interrupt high_int_handlervoid high_int_handler (void){if (PIR2bits.HLVDIF){HLVDCONbits.HLVDEN = 0;PIR2bits.HLVDIF=0; // Bandera de interrupción del modulo HLVDPORTB=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 encendidoHLVDCONbits.HLVDEN=0; //Apagar modulo HLVDHLVDCONbits.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 RA5HLVDCONbits.VDIRMAG=0; //Interrupción cuando el voltage cae a menos que el punto configuradoHLVDCONbits.HLVDEN=1; //Encender modulo HLVDPIR2bits.HLVDIF=0; // Bandera de interrupción del modulo HLVDwhile(HLVDCONbits.IRVST==0); //Espera hasta que el modulo de alta/baja tensión este listoPORTC=0xFF;PIE2bits.HLVDIE=1; //Habilitar la interrupción de detección de alta/baja tensiónIPR2bits.HLVDIP=1; //Hacer la interrupcion de HLVD de alta prioridadRCONbits.IPEN = 1; //Habilitar prioridad de interrupcionesINTCONbits.GIE=1; //Habilita todas las interrupciones de alta prioridadwhile(1){}}

author: RjSa
author_rank: Contributor
timestamp: October 08, 2013, 08:16:18 pm
content: It seems you are following the steps correctly. Let me run it and ill let you know because I dont use C18 that much.

author: Jon Chandler
author_rank: Frequent Contributor
timestamp: October 08, 2013, 08:36:13 pm
content: 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.

author: RjSa
author_rank: Contributor
timestamp: October 09, 2013, 02:09:15 am
content: 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

author: diegoterc3
author_rank: Regular Contributor
timestamp: October 10, 2013, 08:08:41 am
content: 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!

author: RjSa
author_rank: Contributor
timestamp: October 10, 2013, 03:14:23 pm
content: 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.