View previous topic :: View next topic |
Author |
Message |
chingB
Joined: 29 Dec 2003 Posts: 81
|
LVD Help |
Posted: Mon Apr 19, 2004 2:39 am |
|
|
Hi,
I'd like to have your commnets regarding the code below for a low voltage detect and the schmeatics also.
schematics:
Code:
Code: |
#include <18F452.H> // Target PIC Microcontroller IC
#fuses HS,NOPROTECT,NOWDT,NOLVP,PUT // PIC MCU Configuration
#use delay(clock=20000000) // 20MHz Crystal clock speed
unsigned char LVDCON;
#locate LVDCON=0x0FD2
struct {
unsigned char LVDLN:4;
unsigned char LVDEN:1;
unsigned char IRVST:1;
} LVDCONbits ;
#locate LVDCONbits=0x0FD2
unsigned char PIR2;
#locate PIR2=0x0FA1
struct {
unsigned char CCP2IF:1;
unsigned char TMR3IF:1;
unsigned char LVDIF :1;
unsigned char BCLIF :1;
unsigned char EEIF :1;
} PIR2bits ;
#locate PIR2bits=0x0FA1
int1 glLVDdetect = 0;
#int_lowvolt
void Low_voltageDetect_isr() // low voltage detect interrupt routine
{
glLVDdetect = 1;
while (PIR2bits.LVDIF) // check if LVDIF is set
PIR2bits.LVDIF = 0; // set LVDIF to zero
}
void init_chip() { // Initialize the MCU Chip
delay_ms(2000);
// configure LVD interrupt before enabling
//LVDCONbits.LVDLN = 12; // set LVD limits to 3.8Vmin ~ 4.03Vmax
LVDCONbits.LVDLN = 15; // external analog input
LVDCONbits.LVDEN = 1; // enable/powers up the LVD circuit
while (!LVDCONbits.IRVST); // wait for LVD circuitry to stabilized?
PIR2bits.LVDIF = 0; // clear LVD interrupt before enabling
setup_adc_ports(NO_ANALOGS);
output_low(PIN_A0);
output_high(PIN_E0);
enable_interrupts(int_lowvolt); // enable LVD interrupt
enable_interrupts(GLOBAL); // Enable Global interrupt
}
main()
{
init_chip();
while (TRUE)
{
if (glLVDdetect) // check if low voltage occured
{
//BattManageOFF(); // battery backup is use
glLVDdetect = 0; // reset lvdDetect flag
output_low(PIN_E0);
//i8lvdtimeout = 0; // reset lvdtimeout
//i1LVDtmrf = 1; // set lvdtmrf flag
//LCD_DISPLAY(1,2,"Low Voltage ");
}
}
}
|
My problem I can't make the LVD work using an external trip point but if I use the code above using the built-in trip point the code works... my monitroing LED at PIN_E0 will lit.
This is only a test for my final schematics which includes a battery management circuit.
I need your help on this...
Thnx |
|
|
chingB
Joined: 29 Dec 2003 Posts: 81
|
|
Posted: Mon Apr 19, 2004 5:33 pm |
|
|
Hi,
Anyone who can help on this...
Thnx |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Mon Apr 19, 2004 6:02 pm |
|
|
I can't see your schematics. The picture doesn't load. |
|
|
Guest
|
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Mon Apr 19, 2004 6:40 pm |
|
|
I get this:
Quote: |
We have detected a hotlinking error. Hotlinking is when you link to images or NON html files on 100freemb.com from another host. Hotlinking is not allowed for our FREE Accounts. Hotlinking is allowed for our paid accounts. Your account can be upgraded in the user section when you have logged in.
|
|
|
|
chingB
Joined: 29 Dec 2003 Posts: 81
|
|
Posted: Mon Apr 19, 2004 8:11 pm |
|
|
Haplo wrote: | I get this:
Quote: |
We have detected a hotlinking error. Hotlinking is when you link to images or NON html files on 100freemb.com from another host. Hotlinking is not allowed for our FREE Accounts. Hotlinking is allowed for our paid accounts. Your account can be upgraded in the user section when you have logged in.
|
|
Here is the schemaics:
|
|
|
|