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

18F26K20 + int_rda + sleep problem

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



Joined: 18 Aug 2011
Posts: 8

View user's profile Send private message

18F26K20 + int_rda + sleep problem
PostPosted: Thu Aug 18, 2011 3:07 pm     Reply with quote

Hi,

I'm using compiler version 4.114 and a PIC18F26K20.

I have a small program with the objective of waking up the PIC from its sleep via serial interrupt (rda).

I have tried to use both sleep modes, idle and deep. I'm able to achieve success with idle mode, but I'm incapable of waking up the PIC once it gets into deep sleep.

I'm controlling the sleep mode by connecting pin C3 to logic 1 or 0 and using the hardware pins for the serial communication.

The code is the following:

Code:

#include "18F26K20.h"

#fuses HS, NOWDT, NOPROTECT, NOLVP

#use delay(clock=20000000)
#use rs232(uart1, baud=9600, stream = PC)

short sleep_mode;


void piscaLed(int pino, int atraso){

   output_high(pino);
   delay_ms(atraso);
   output_low(pino);
   delay_ms(atraso);

}


#int_rda
void serial_isr(){

   char c;
   
   c = fgetc(PC);
   fprintf(PC,"%c",c);
   
   if(input(pin_c3)==0)
      sleep_mode = FALSE; 
   
   if(input(pin_c3)==1)
      sleep_mode = TRUE;   
 
}

void main()

   
   sleep_mode=FALSE;
 
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL); 

   while(TRUE){
   
      if(sleep_mode){
     
         //sleep(SLEEP_IDLE);    //It works well with this line instead of the bottom one
         sleep(SLEEP_FULL);
         
      }

      delay_ms(1);
      fprintf(PC,"\n\r");
      fprintf(PC,"NOT SLEEPING");
      fprintf(PC,"\n\r");
      piscaLed(PIN_A4,500);
     
   }
       

}


Does anyone has any idea why serial interrupt cannot wake the PIC when it is in deep sleep?

Best wishes

planmas
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 18, 2011 6:54 pm     Reply with quote

It won't wake-up in sleep mode because the main oscillator is shut down
and the UART receiver needs a clock to run its internal circuits. It works
in Idle mode because in that mode the PIC's oscillator is still running.

More info:
http://www.ccsinfo.com/forum/viewtopic.php?t=31308
http://www.ccsinfo.com/forum/viewtopic.php?t=36125
http://www.ccsinfo.com/forum/viewtopic.php?t=36728


However, there is another way to do it. Read this section in the 18F26K20
data sheet. There are several more paragraphs besides this:
Quote:

18.3.3 AUTO-WAKE-UP ON BREAK

During Sleep mode, all clocks to the EUSART are
suspended. Because of this, the Baud Rate Generator
is inactive and a proper character reception cannot be
performed. The Auto-Wake-up feature allows the
controller to wake-up due to activity on the RX/DT line.
This feature is available only in Asynchronous mode.
planmas



Joined: 18 Aug 2011
Posts: 8

View user's profile Send private message

PostPosted: Fri Aug 19, 2011 4:53 am     Reply with quote

Thank you for the reply.

Quote:
It won't wake-up in sleep mode because the main oscillator is shut down


It confirms what I was thinking.

I will explore the AUTO-WAKE-UP ON BREAK section of the datasheet and more paragraphs.

I will post my results in the next couple of days in order to try to help anyone with the same problem.

Thank you once again.

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