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

Can't awake pic into deep sleep mode

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



Joined: 28 Jun 2012
Posts: 6

View user's profile Send private message

Can't awake pic into deep sleep mode
PostPosted: Tue Jul 03, 2012 8:16 pm     Reply with quote

Hello, I'm having problem trying to awake the pic with INT_EXT(RB0). It works when the pic is in sleep mode, but doesn't work when is in deep sleep mode. Here's the code- v4.114 -18F46J50
Code:

#include <18F46J50.h>
#fuses HSPLL,PLL5,NOWDT,NOPROTECT,NODEBUG,NOCPUDIV,NODSBOR,NODSWDT,NOWPFP,NOWPCFG,NOWPDIS,NOFCMEN,NOIESO,RTCOSC_T1
#use delay(clock=48mhz)
#use rs232(baud=9600, xmit=PIN_A3, rcv=PIN_A2,STREAM=PUER_PC)

#DEFINE LEDAMA PIN_B3
#byte intcon =4082
#byte intcon2 =4081
#byte T1CON=4045
#byte T0CON=4053
#byte HLVDCON=3973
#byte PIR2=4001
#byte WDTCON = 4032
#BYTE OSCCON = 4051
#BYTE DSCONH=3917
short int_flag=0;

#int_EXT
void INTERRUP(){
fprintf(PUER_PC,"%S\n\r","INT EXT");
 fprintf(PUER_PC,"%U\n\r",int_flag);
 output_LOW(LEDAMA);
 if  (int_flag==1)
 {int_flag=0;
 RESET_CPU();
 }
else
{int_flag=1;}
}



void main() {
 
set_tris_B(1);
setup_oscillator(OSC_PLL_ON);
setup_adc (ADC_OFF);
setup_comparator (NC_NC_NC_NC);
SETUP_WDT (WDT_OFF);
port_b_pullups (FALSE);
setup_timer_1(T1_EXTERNAL);
setup_rtc(RTC_ENABLE | RTC_OUTPUT_SECONDS, 0x00);
ext_int_edge( H_TO_L ); //edge select bit-falling -->lose power
int_flag=0;
enable_interrupts(INT_EXT);
clear_interrupt(INT_ext);
enable_interrupts(GLOBAL);
   
while(true){

if (int_flag==1){
   clear_interrupt(INT_ext);//flear flag
   ext_int_edge( L_TO_H );//edge select -->get power back>rising
   fprintf(PUER_PC,"%S\n\r","go sleep");
 
   #ASM   //put the pic into deep sleep mode(it doesn't work, can't awake it)

  BSF WDTCON, 7 //Setting the REGSLP- WDTCON<7>
  BCF OSCCON, 7 //Clearing the IDLEN bit -OSCCON<7>
  BCF INTCON, 7 //Clearing the GIE bit
  BSF DSCONH, 7 //Setting the DSEN bit (DSCONH<7>)
  sleep //Executing the SLEEP instruction immediately after
  nop

  #endasm

  //SLEEP();   //put the pic in sleep mode(it works, the pic awakes)
  //while(1);
  }
 else
 {   //blinks led when is not into sleep mode
 output_HIGH(LEDAMA);
 DELAY_MS(500);
 output_LOW(LEDAMA);
 DELAY_MS(500);
 
 }
javierpic



Joined: 28 Jun 2012
Posts: 6

View user's profile Send private message

clarification
PostPosted: Tue Jul 03, 2012 8:19 pm     Reply with quote

in the #asm part is BSF INTCON, 7 //set the GIE bit -- so the interruption is active but still doesn't work
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 03, 2012 11:13 pm     Reply with quote

Quote:
I'm having problem trying to awake the pic with INT_EXT(RB0).

Here is sample code for Deep Sleep wake-up caused by an interrupt on
the INT0 pin. This example is for an 18F24J11, so I haven't tested it with
your PIC and I don't guarantee it will work. But it might. Try to do it this way:
http://www.ccsinfo.com/forum/viewtopic.php?t=45578&start=16


Quote:
#byte intcon =4082
#byte intcon2 =4081
#byte T1CON=4045
#byte T0CON=4053
#byte HLVDCON=3973
#byte PIR2=4001
#byte WDTCON = 4032
#BYTE OSCCON = 4051
#BYTE DSCONH=3917

Don't do this. No one knows what these numbers mean. The PIC data
sheet uses Hex. Everyone in the PIC world uses Hex. You should too.
javierpic



Joined: 28 Jun 2012
Posts: 6

View user's profile Send private message

PostPosted: Fri Jul 06, 2012 3:40 pm     Reply with quote

Thanks a lot PCM programmer, I still can't get the pic to jump to the Ext interruption after entering into deep sleep mode (works in sleep mode). The weird thing is after trying different things, the pic wakes up without going to the interruption and starts after this RELEASE=0 statement, that is actually the only addition I made to the code...any ideas? Here's the last code:
Code:

#include <18F46J50.h>
#fuses HSPLL,PLL5,NOWDT,NOPROTECT,NODEBUG,NOCPUDIV,NODSBOR,NODSWDT,NOWPFP,NOWPCFG,NOWPDIS,NOFCMEN,NOIESO,RTCOSC_T1
#use delay(clock=48mhz)
#use rs232(baud=9600, xmit=PIN_A3, rcv=PIN_A2,STREAM=PUER_PC)

#DEFINE LEDAMA PIN_B3
#byte intcon =0XFF2
#byte intcon2 =0XFF1
#byte T1CON=0XFCD
#byte T0CON=0XFD5
#byte HLVDCON=0XF85
#byte PIR2=0XFA1
#byte WDTCON =0XFC0
#BYTE OSCCON =0XFD3
#BYTE DSCONH=0XF4D
#BYTE DSCONL=0XF4C
#BYTE DSWAKEH=0XF4B
#BYTE DSWAKEL=0XF4A
#BIT IDLEN=OSCCON.7
#BIT REGSLP=WDTCON.7
#BIT DSEN=DSCONH.7
#BIT DSINTO=DSWAKEH.0
#bit DS_WAKEUP_BIT=WDTCON.3
#bit RELEASE =DSCONL.0
short int_flag=0;

#int_EXT
void INTERRUP(){
 fprintf(PUER_PC,"%S\n\r","INT EXT");
 fprintf(PUER_PC,"%U\n\r",int_flag);
 output_LOW(LEDAMA);
 if  (int_flag==1)
 {int_flag=0;
 RESET_CPU();
 }
else
{int_flag=1;}
}


void main() {
setup_oscillator(OSC_PLL_ON);
RELEASE=0;
set_tris_B(1);
DELAY_MS(100);
 fprintf(PUER_PC,"%S\n\r","REF 1");
setup_adc (ADC_OFF);
setup_comparator (NC_NC_NC_NC);
SETUP_WDT (WDT_OFF);
port_b_pullups (FALSE);
setup_timer_1(T1_EXTERNAL);
setup_rtc(RTC_ENABLE | RTC_OUTPUT_SECONDS, 0x00);
ext_int_edge( H_TO_L ); //edge select bit-falling -->lose power
int_flag=0;
fprintf(PUER_PC,"%S\n\r","REF 2");
enable_interrupts(INT_EXT);
clear_interrupt(INT_ext);
enable_interrupts(GLOBAL);

    fprintf(PUER_PC,"%S\n\r","REF 3");
while(true){

if (int_flag==1){
   clear_interrupt(INT_ext);//flear flag
   ext_int_edge( L_TO_H );//edge select -->get power back>rising
   fprintf(PUER_PC,"%S\n\r","go sleep");
 
   #ASM   //put the pic into deep sleep mode(it doesn't work, doens't go to interruption )

  BSF WDTCON, 7 //Setting the REGSLP- WDTCON<7>
  BCF OSCCON, 7 //Clearing the IDLEN bit -OSCCON<7>

  BSF DSCONH, 7 //Setting the DSEN bit (DSCONH<7>)
  sleep //Executing the SLEEP instruction immediately after
  nop

  #endasm

 // SLEEP();   //put the pic in sleep mode(it works, the pic awakes and goes to the interruption)
 // while(1);
  }
 else
 {   //blinks led when is not into sleep mode
 output_HIGH(LEDAMA);
 DELAY_MS(500);
 output_LOW(LEDAMA);
 DELAY_MS(500);
 }
}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 06, 2012 4:18 pm     Reply with quote

The 18F46J50 data sheet doesn't say the PIC will go to the interrupt
routine upon wake-up. It says it will do a power-on reset:
Quote:

4.6 Deep Sleep Mode

When a wake event occurs in Deep Sleep mode (by
MCLR Reset, RTCC alarm, INT0 interrupt, ULPWU or
DSWDT), the device will exit Deep Sleep mode and
perform a Power-on Reset (POR). When the device is
released from Reset, code execution will resume at the
device’s Reset vector.
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