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 CCS Technical Support

#int_lowvolt 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

#int_lowvolt Help
PostPosted: Mon Feb 02, 2004 8:20 pm     Reply with quote

Hi,

I am coding a PIC18F452 at 20Mhz to use the low voltage detect module thru interrupt.

My code:

Code:

#int_lowvolt
void Low_voltageDetect_isr()  // low voltage detect interrupt routine
{
   lvdetect = 1;
}

void init_chip() {   // Initialize the MCU Chip

   // configure LVD interrupt before enabling
   LVDCONbits.LVDLN = 10;     // set LVD limits to 3.6Vmin ~ 3.82Vmax
   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);

   setup_timer_0(RTCC_INTERNAL | RTCC_DIV_16);     // 20M/(4*16*65536)
   setup_timer_2(T2_DIV_BY_16,250,10);    // 8.0mSec. interupt intervals
   setup_timer_3(T3_INTERNAL | T3_DIV_BY_1);   // 13.2mSec. timer overflow

   enable_interrupts(int_lowvolt);  // Enable LVD interrupt
   enable_interrupts(int_timer0);   // Enable timer0 interrupt

   enable_interrupts(GLOBAL);       // Enable Global interrupt
}

main()
{
   init_chip();      // Initialize the MCU Chip

   while (TRUE)
   {
      // this routine is only a demo for low voltage detect
      if (lvdetect)
      {
         lvdetect = 0;
         buzzSound();
      }
   }
}



to simulate the effect, I have a variable power supply when I lower the power to 3.7Volts... the buzzer will sound to simply notify me that a low voltage interrupt occur. But when I restore the power back to 5.0Volts, the buzzer won't turn off?

Is their something wrong with the code? Need help on this....

Thanx
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

Need to clear the interrupt flag condition?
PostPosted: Tue Feb 03, 2004 2:37 am     Reply with quote

Maybe this is way out in left field, not having worked with the part and all. Shouldn't you clear the lowvolt detect flag at the very end of the ISR.

Code:

#int_lowvolt
void Low_voltageDetect_isr()  // low voltage detect interrupt routine
{
   lvdetect = 1;
   PIR2bits.LVDIF = 0;  /* --> you already defined this */
}


This is normal procedure for other interrupts, otherwise since your flag is set it will always keep triggering the ISR.

Hope it helps.
chingB



Joined: 29 Dec 2003
Posts: 81

View user's profile Send private message

Re: Need to clear the interrupt flag condition?
PostPosted: Tue Feb 03, 2004 3:28 am     Reply with quote

languer wrote:
Maybe this is way out in left field, not having worked with the part and all. Shouldn't you clear the lowvolt detect flag at the very end of the ISR.

Code:

#int_lowvolt
void Low_voltageDetect_isr()  // low voltage detect interrupt routine
{
   lvdetect = 1;
   PIR2bits.LVDIF = 0;  /* --> you already defined this */
}


This is normal procedure for other interrupts, otherwise since your flag is set it will always keep triggering the ISR.

Hope it helps.


Do you have any idea or a sample code snippet on how I can disable the LVD module most of the time, and only enabled ocassionally to do the voltage check? This is a method to reduce current consumption.

Thnx
SteveS



Joined: 27 Oct 2003
Posts: 126

View user's profile Send private message

PostPosted: Tue Feb 03, 2004 6:08 am     Reply with quote

I believe the compiler should reset the flag for you in the code it generates.

However the 18F452 is rated down to 4.2V and you are taking it to 3.7V. You can't be sure it is still running right at that point. You may want to switch to the LF version which can run down to 2.0V in particular oscillator modes. That may not be your problem, but you should be aware of it anyway. You can set the setpoint higher of course.

Don't know offhand about disabling it most of the time. If you need to take action due to power supply loss you may want to consider a diode-capacitor feeding the VCC for the micro and a comparator on the supply voltage feeding an interrupt. Microchip has some very low power comparators. The diode protected cap will run the micro for a time after the supply fails.

EDIT:
actually the internal comparator can be referenced off an external voltage so the extra comparator wouldn't be needed.

- SteveS
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