MrDEB
Well-Known Member
testing HLVD code
looking at the HLVD block diagram on page 244 of the 18F2420 data sheet, the resistor ladder is connected to Vdd so using this code the LED1 should come on when the voltage drops below 2.79-3.04. No other connections for external voltage measurement as the block diagram is for external trip point voltage.
I feel I don't have the registers set right so I need some help if possible?
Thinking of removing the 330 ohm resistor I have tied to Vdd seeing how when the voltage drops below 2.89 typical voltage I don't have enough to power the LED anyway but need some expert advice on the code.
looking at the HLVD block diagram on page 244 of the 18F2420 data sheet, the resistor ladder is connected to Vdd so using this code the LED1 should come on when the voltage drops below 2.79-3.04. No other connections for external voltage measurement as the block diagram is for external trip point voltage.
I feel I don't have the registers set right so I need some help if possible?
Thinking of removing the 330 ohm resistor I have tied to Vdd seeing how when the voltage drops below 2.89 typical voltage I don't have enough to power the LED anyway but need some expert advice on the code.
Code:
{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 1/7/2013 *
* Version : 1.0 *
* Notes : *
* : *
*****************************************************************************
}
Device = 18f2420
Clock = 8
//Config OSC=HS
Include "InternalOscillator.bas"
Include "utils.bas"
Include "convert.bas"
Dim led1 As PORTC.5
HLVDCON=%00110110 // 2.74-3.04 volts trip
HLVDCON.bits(5)=1 // voltage detect flag
HLVDCON.bits(4)=1 // voltage detect enable bit
HLVDCON.bits(3)=0 // bits 3-0 = range
HLVDCON.bits(2)=1
HLVDCON.bits(1)=1
HLVDCON.bits(0)=0 // set for 2.74 - 3.04
PIE2.bits(2)=0 //HLVDIE
INTCON.bits(7)=1 //GIE/GIEH bit
INTCON.bits(6)=1 //PEIE/GIEL BIT
output(led1)
WHILE TRUE
If HLVDCON.bits(5)=0 // voltage below 3.04 - 2.79
then led1 = 0 // low is when voltage is LOW
else led1 =1 // voltage detect flag
HLVDCON.bits(5)=1 // voltage detect flag
endif
wend