PDA

View Full Version : Low Voltage Detection



Srigopal007
- 5th January 2005, 16:52
Hi everyone, I was having a few problem with the low voltage detection mechanism and not sure if it is my software which is causing the problem or if it is the hardware. I just want to make sure that my chip has not gone bad. I am using the pic18f6720 as the pic of choice and it has the LOW VOLTAGE DETECTION feature in this chip. here is what I have in my code. please let me know if I am doing something wrong.

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''
'here is what the datasheet says to do :
1: Write the value to the LVDL3:LVDL0 bits (LVDCON registers) which selects the trip voltage.

2:Ensure the LVD interrupts are disabled (the LVDIE bit is cleared or the GIE bit is cleared

3: enable the LVD module (set the LVDEN bit in the LVDCON register

4: Wait for the LVD module to stablize (the IRVST bit to become set

5: Clear the LVD interrupt flag, which may have falsely become set, until the LVD module has stabilize (clear the LVDIF bit)

6: Enable the LVD interrupt (Set the LVDIE and the GIE bits)

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''

here is what I have done

'since I want the trip voltage to be as high as possible to allow enough time for the processor to save all the necessary values of the variable in use, I have selected the trip voltage to be V = 4.64V.

LVDCON = %00111110 'STEPS 1 through 4 is satisfied

'clearing the LVDIF flag which may have falsely become set.
LDVIF = 0
LVDIE = 1

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''

my question is I am not sure if simply saying LVDIF = 0 and LVDIE = 1 will clear the flag and set the interrupt for the Low Voltage Detect module. Or do I really need to WRITE directly to the PIR2 and PIE2 registers. Please correct me if I am confused. thanks in advace for anyone offering to help.

Bruce
- 5th January 2005, 18:29
Steps 1-4 are not satisfied by this;

> LVDCON = %00111110 'STEPS 1 through 4 is satisfied

LVDCON = %00001110 ' Set LVDL3:LVDL0 bits for 4.64V trip
LVDIE = 0 ' LVD interrupt disabled
LVDEN = 1 ' Enable LVD module

WHILE IRVST = 0
WEND ' Wait for stable Vref

' Steps 1-4 done above. Steps 5-6 are below.

LVDIF = 0 ' Clear int LVD flag
LVDIE = 1 ' Enable LVD int
GIE = 1 ' Enable global ints

I would make sure my voltage levels were stable & above my LVD trip point first.

> I am not sure if simply saying LVDIF = 0 and LVDIE = 1 will clear > the flag and set the interrupt or do I really need to WRITE
> directly to the PIR2 and PIE2 registers

If you have LVDIF & LVDIE defined as PIR2.2 & PIE2.2 something like this;

SYMBOL LVDIE = PIE2.2
SYMBOL LVDIF = PIR2.2

then yes, you can write to them like this;

LVDIF = 0
LVDIE = 1

In this case, you are writing directly to LVDIF & LVDIE in the PIR2 and PIE2 registers.

Internal registers & bits within these registers, are defined in device specific header files. For the PIC18F6720, these should be in a file named P18F6720.INC in your MPLAB directory.

It looks something like this;

LVDCON EQU H'0FD2' ; Register address
IRVST EQU H'0005' ; Bit #5
LVDEN EQU H'0004' ; Bit #4, etc,,,

Using assembler, you could set/clear bits like this

@ BSF LVDCON, LVDEN
@ BCF LVDCON, LVDEN

With PBP, you need tell it where LVDEN is located in register LVDCON. Something like this;

SYMBOL LVDEN = LVDCON.4

Now you can use LVDEN = 0, etc,,,

Note: Remember your Brown-Out reset config fuse settings too. If you have brown-out reset enabled, and it's set higher than what you set your trip point for with LVD, you might not get what you're expecting.