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

PIC18F458 - sleep - interrupts - battery

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



Joined: 07 Jul 2004
Posts: 2

View user's profile Send private message

PIC18F458 - sleep - interrupts - battery
PostPosted: Wed Jul 07, 2004 2:44 am     Reply with quote

Hi to everybody,

I have drawn near from few to the PICs and, as such, I am facing the first problems that I expose You following. My target is to make to sleep the PIC when the power supply falls and to use a battery to keep on developing some activities: particularly if in condition of battery feeding occurs an external interrupts I want to wake up the micro and to write a data in eeprom for then to return in sleep fashions. Obviously to the restoration of the power supply there is the systematic awakening. In order to resolve this last point I connect the Vcc to the pin RB1.

Someone has suggestions

Thanks in advance
Ttelmah
Guest







Re: PIC18F458 - sleep - interrupts - battery
PostPosted: Wed Jul 07, 2004 6:32 am     Reply with quote

billyboy72 wrote:
Hi to everybody,

I have drawn near from few to the PICs and, as such, I am facing the first problems that I expose You following. My target is to make to sleep the PIC when the power supply falls and to use a battery to keep on developing some activities: particularly if in condition of battery feeding occurs an external interrupts I want to wake up the micro and to write a data in eeprom for then to return in sleep fashions. Obviously to the restoration of the power supply there is the systematic awakening. In order to resolve this last point I connect the Vcc to the pin RB1.

Someone has suggestions

Thanks in advance

You need to do more than 'connect the power supply to pin RB1'. This will achieve _nothing_. The 'threshold' voltage for the logic input on this pin, changes as the supply voltage alters, so it'll never trigger. Depending on how much you need to do from detecting a power failure, you can either use the 'brownout' circuit that is inside the chip allready to trigger the code, or (preferably in terms of what can be done), add an external power monitor circuit, like the MAX671, and feed the output of this to the interrupt input. If your supply is being regulated from a higher incoming voltage, consider monitoring this incoming voltage, rather than the 5v rail, since this will give more warning when failure is about to happen.

Best Wishes
billyboy72



Joined: 07 Jul 2004
Posts: 2

View user's profile Send private message

PostPosted: Wed Jul 07, 2004 7:50 am     Reply with quote

Hi Ttelmah,

thanks for your kind suggestion, I will immediately verify the possibility to insert the suitable IC. Nevertheless I would like to add to the painted scenery in the preceding intervention that I have provided to the input PIN B1 of an opportune passive filter has for avoiding the rebounds of the power supply. Following amount carried over an example of code that reproduces the situation:
-------------------------------------------------------------------------------------
// global flag to send processor into sleep mode
short sleep_mode;
short power_down;
int poweroff;

// external interrupt when power supply is switched off
#INT_EXT1
void ext1_isr() {
if(!power_down)
{
write_eeprom(2,0x0F);
delay_us(10);
write_eeprom(1,0x0F);
delay_us(10);
printf("The processor sleep.\r\n");
++poweroff;
write_eeprom(0,poweroff);
delay_us(10);

ext_int_edge(L_TO_H);
}
else
{
write_eeprom(2,0xFF);
delay_us(10);
write_eeprom(1,0xFF);
delay_us(10);
ext_int_edge(H_TO_L);
printf("The processor run.\r\n");
}
if(!input(PIN_B0)) /
power_down=TRUE;
delay_ms(100); // debounce button
}

// main program that increments counter every second unless sleeping
void main() {
long counter;
byte sleep_status;
byte power_status;
ext_int_edge(H_TO_L); // init interrupt triggering for button press
enable_interrupts(INT_EXT1);// turn on interrupts
enable_interrupts(GLOBAL);

printf("\n\n");

counter=0; // reset the counter
while(TRUE)
{


poweroff=read_eeprom(0);
if(poweroff==255)
{
write_eeprom(0,0);
delay_us(10);
poweroff=0;
}

sleep_status=read_eeprom(1);
if(sleep_status==255)
{
sleep_mode=FALSE;
}
else
{
sleep_mode=TRUE;
}

power_status=read_eeprom(2);
if(power_status==255)
{
power_down=FALSE;
}
else
{
power_down=TRUE;
}


if(sleep_mode)
{

enable_interrupts(INT_EXT1);
ext_int_edge(L_TO_H);
sleep();
}
printf("The count value is: %5ld \r\n",counter);
counter++;
if(counter==10)//
{
counter=0;//
printf("The eeprom_poweroff value is: %d \r\n",read_eeprom(0));

}
}
}
-------------------------------------------------------------------------------------

Thanks in advance
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