CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

LVD Help

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
chingB



Joined: 29 Dec 2003
Posts: 81

View user's profile Send private message

LVD Help
PostPosted: Mon Apr 19, 2004 2:39 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 19, 2004 5:33 pm     Reply with quote

Hi,

Anyone who can help on this...

Thnx
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Mon Apr 19, 2004 6:02 pm     Reply with quote

I can't see your schematics. The picture doesn't load.
Guest








PostPosted: Mon Apr 19, 2004 6:17 pm     Reply with quote

Haplo wrote:
I can't see your schematics. The picture doesn't load.


Schematics link:
http://mcu-pic.100freemb.com/circuits/LVD_Circuit.gif
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Mon Apr 19, 2004 6:40 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 19, 2004 8:11 pm     Reply with quote

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:

Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group