![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Markdem
Joined: 24 Jun 2005 Posts: 206
|
Sleep and waking up |
Posted: Sat Jun 21, 2008 1:54 am |
|
|
Hi all, I am trying to put a PIC to sleep in int_rb. Problem is, it will not wake back up when the interrupt fires again. It looks like the ISR fires, as it will print "Power Fail" on the LCD. I have tried both on real hardware and in simulator, but both will not reset.
Code: |
#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,BROWNOUT,NOMCLR
#use delay(clock=48000000)
#define POWER_FAIL_SENSE_PIN PIN_B7
#include "LCD420.c"
int16 count;
int1 PF = 0, do_ISR = 0;
#int_rb
void rb_isr()
{
if(!input(POWER_FAIL_SENSE_PIN))
{
printf(lcd_putc,"\f");
lcd_gotoxy(5,2);
printf(lcd_putc,"Power Fail");
PF = 1;
sleep();
delay_cycles(1);
}
if(input(POWER_FAIL_SENSE_PIN) && PF == 1)
{
reset_cpu();
}
}
void main()
{
lcd_init();
printf(lcd_putc,"Running");
enable_interrupts(GLOBAL);
enable_interrupts(INT_RB);
while(1)
{
count++;
lcd_gotoxy(1,2);
printf(lcd_putc,"count:%Lu",count);
delay_ms(100);
}
}
|
I have also tried to set a flag inside void rb_isr(), but then the pic locks up before it prints out "Power Fail".
I have got debounce hardware on B7.
Can anyone help he out.
Thanks. |
|
![](templates/subSilver/images/spacer.gif) |
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Sat Jun 21, 2008 10:48 am |
|
|
I never tryed, but according to the datasheet, a fixed delay is required when leaving Sleep
and Idle modes. The needed delay is for Oscillator Strt-up and the PLL lock time out.
The needed delay is only of a few machines cycles, hence 10 machines cycles inside
an interrupt would be enough.
Code: |
#int_rb
void rb_isr()
{
delay_cycles(10);
if(!input(POWER_FAIL_SENSE_PIN))
{
printf(lcd_putc,"\f");
lcd_gotoxy(5,2);
printf(lcd_putc,"Power Fail");
PF = 1;
sleep();
delay_cycles(1);
}
if(input(POWER_FAIL_SENSE_PIN) && PF == 1)
{
reset_cpu();
}
}
|
Humberto |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Sat Jun 21, 2008 2:39 pm |
|
|
Inside the ISR, the interrupt flag has _not_ been cleared. If you go to sleep with an interrupt flag already set, that interrupt, cannot wake you up.
You need:
Code: |
PF = 1;
clear_interrupts(INT_RB);
sleep();
delay_cycles(1);
|
The 'clear', should be the last instruction before the interrupt.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|