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

Sleep and waking up

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



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

Sleep and waking up
PostPosted: Sat Jun 21, 2008 1:54 am     Reply with quote

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.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sat Jun 21, 2008 10:48 am     Reply with quote

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
Ttelmah
Guest







PostPosted: Sat Jun 21, 2008 2:39 pm     Reply with quote

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