View previous topic :: View next topic |
Author |
Message |
RobS
Joined: 29 Jan 2005 Posts: 10
|
Low Voltage Detect interrupt |
Posted: Wed Sep 28, 2005 4:52 pm |
|
|
I'm using the PIC18LF870/18LF8722. CCS Ver 3.23. I want to use #int_lowvolt interrupt to write to internal EE when VDD falls below a certain value. Do any fuses need to be set? What is a good way to set the LVDCON register bits?
thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 29, 2005 3:53 pm |
|
|
Here is a Low Voltage Detect test program for the 18F452.
If you use a variable DC power supply which is initially set
at 5.0v, and you slowly reduce the voltage to 4.60v, at that
point you will get this displayed:
Quote: |
Low voltage
Low voltage
Low voltage
Low voltage
Low voltage
|
When you adjust the voltage above 4.60v, the messages will stop.
Initially, I had some code to print "AAAAA" to let me know it was
running, but I didn't need that in the final version, so it's commented out.
Also note that for your PIC, you have the ability to trigger on "above"
or "below" the LVD voltage. An extra parameter may be used to
select this in the setup_low_voltage() function. See notes in code, below.
Code: | #include <18F452.h>
#fuses XT,NOWDT,PUT, BORV27,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#byte LVDCON = 0xFD2
#bit IRVST_BIT = LVDCON.5
#byte PIR2 = 0xFA1
#bit LVDIF_BIT = PIR2.2
int8 lvd_flag;
#int_lowvolt
void lvd_isr(void)
{
lvd_flag = TRUE;
disable_interrupts(INT_LOWVOLT);
}
int8 wait_for_lvd_to_stabilize(void)
{
int16 timeout_count;
timeout_count = 0xFFFF; // Many milliseconds
while(timeout_count--)
{
if(IRVST_BIT)
return(TRUE);
}
return(FALSE);
}
//====================================
void main(void)
{
printf("Start\n\r");
setup_low_volt_detect(LVD_46);
//setup_low_volt_detect(LVD_46 | LVD_TRIGGER_BELOW); //For 18F8722
if(wait_for_lvd_to_stabilize() == FALSE)
{
printf("Low Voltage Detect module didn't stabilize\n\r");
while(1); // Wait here forever
}
LVDIF_BIT = 0; // Clear the LVD interrupt flag
enable_interrupts(INT_LOWVOLT);
enable_interrupts(GLOBAL);
while(1)
{
if(lvd_flag == TRUE)
{
printf("\n\rLow voltage\n\r");
lvd_flag = FALSE;
LVDIF_BIT = 0; // Clear the LVD interrupt flag
enable_interrupts(INT_LOWVOLT);
}
// delay_ms(500);
// printf("A");
}
} |
|
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Fri Sep 30, 2005 10:15 am |
|
|
Is setup_low_volt_detect ( ) a built in CCS function? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Sep 30, 2005 10:27 am |
|
|
Yes, it's in the current manual. |
|
|
Pulsartomi
Joined: 26 May 2010 Posts: 17
|
|
Posted: Mon Jun 07, 2010 4:20 am |
|
|
For 18f46j11 there is no low voltage interrupt defined. What should I do if I want to use this interrupt to clear the HLVDIF flag, and want to go to sleep mode? I can watch this flag with a bit test, and if it set maybe there is an event, but since there is no low voltage interrupt defined for this device, I really don't know what will happen. Please help |
|
|
Pulsartomi
Joined: 26 May 2010 Posts: 17
|
|
Posted: Mon Jun 07, 2010 7:11 am |
|
|
Managed to do without interrupt, just with watching the LVDIF flag.
Code: | if(bit_test(PIR2,2)==1) shutdown(); |
|
|
|
hayee
Joined: 05 Sep 2007 Posts: 252
|
|
Posted: Mon Aug 15, 2011 12:22 am |
|
|
I want to shutdown the microcontroller if LVD detects a particular voltage level. How to tell the microcontroller for shutdown? |
|
|
hayee
Joined: 05 Sep 2007 Posts: 252
|
|
Posted: Mon Aug 15, 2011 11:42 pm |
|
|
Code: | if(bit_test(PIR2,2)==1) shutdown(); |
What i have to do/write for shutdown routine as the above poster uses this function for shutdown the microcontroller. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 16, 2011 1:40 pm |
|
|
Quote: | I want to shutdown the microcontroller |
What do you mean by "shutdown" ? Do you mean Sleep mode ?
Probably.
Well, his shutdown() routine will set the i/o pins in whatever way he
wants them to be during sleep mode. It will also turn off all modules
that use power (and that are not automatically turned off in sleep mode)
such as the Comparator and Vref. Also disable interrupts if you don't want
to wake-up from sleep by interrupts. Etc. After doing all that, he will
execute the sleep() function. |
|
|
|