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

PIC18F26J50 Deep Sleep Problem

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



Joined: 16 May 2006
Posts: 95

View user's profile Send private message

PIC18F26J50 Deep Sleep Problem
PostPosted: Wed Sep 09, 2020 8:28 am     Reply with quote

Anyone using the deep sleep feature? The MCU switches to Deep sleep mode but then I can't wake it up

In the datasheet it said it could be awakened with RTC alarm, but I couldn't run it.

This is my code

Code:
#include <18F26J50.h>
//#device ADC=10   
#fuses INTRC_PLL,NOWDT,PLL2,CPUDIV2,RTCOSC_T1
#use delay(clock=24M)

rtc_time_t time;

void main(void)
{
   
   setup_oscillator(OSC_PLL_ON);                   
   setup_timer_1(T1_EXTERNAL| T1_DIV_BY_1 );
                                   
    setup_rtc(RTC_ENABLE , 0);
    time.tm_year = 20;   
    time.tm_mon = 5;                                               
    time.tm_mday = 21;                                                   
    time.tm_wday = 4;                                               
    time.tm_hour = 16;                                                                           
    time.tm_min = 30;                                       
    time.tm_sec = 0;                                         
    rtc_write(&time);

   
   setup_rtc_alarm(RTC_ALARM_ENABLE, RTC_ALARM_10_SECONDS, 0);
   time.tm_year = 20;
   time.tm_mon = 5;
   time.tm_mday = 21;
   time.tm_wday = 4;
   time.tm_hour = 16;
   time.tm_min = 30;
   time.tm_sec = 0;
   rtc_alarm_write(&time);
   
   
   
   clear_interrupt(INT_RTC);
   enable_interrupts(INT_RTC);
   enable_interrupts(GLOBAL);
   


   while (TRUE)
   {

                                                                     
     output_low(PIN_B0); //not used
     output_low(PIN_B1); //not used
     output_low(PIN_B6); //not used
     output_low(PIN_B7); //not used
     sleep(DEEP_SLEEP);
     delay_cycles(1); //Instruction pre-fetched - NOP
   
     output_high(PIN_B3);
     delay_ms(200);
     output_low(PIN_B3);
     delay_ms(100);
     clear_interrupt(INT_RTC);                                         
                                                                                                                                                   
      }//while
}//main
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Wed Sep 09, 2020 10:21 am     Reply with quote

The default clock source for the RTCC module is an external 32K
oscillator. I can't see where you are switching it to use the T1 source?.
On the external oscillator it won't say running in deep sleep mode.
respected



Joined: 16 May 2006
Posts: 95

View user's profile Send private message

PostPosted: Wed Sep 09, 2020 10:47 am     Reply with quote

Ttelmah wrote:

I can't see where you are switching it to use the T1 source?

what do you mean? I don't understand


Code:
setup_timer_1(T1_EXTERNAL| T1_DIV_BY_1 );
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Wed Sep 09, 2020 10:49 am     Reply with quote

That sets up timer 1, but your RTCC is not being set to use this....
respected



Joined: 16 May 2006
Posts: 95

View user's profile Send private message

PostPosted: Wed Sep 09, 2020 2:10 pm     Reply with quote

How can i use?

I use RTCOSC_T1, setup_timer_1(T1_EXTERNAL| T1_DIV_BY_1 );

Isn't it enough for this ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Thu Sep 10, 2020 12:53 am     Reply with quote

OK. Yes. I did not see this fuse.

The chips I've used have this setting in software, and it has to be done
as part of the RTC setup.

Series of problems.
You must _never_ enable an interrupt without having
a handler present for it. This will result in the chip crashing or hanging.
You don't need to enable this interrupt at all. Get rid of these lines.

Second problem the alarm mask. This is a repeated cause of many issues.
It is completely 'non intuitive'. As you have it configured, the alarm will
only happen once, when the alarm time matches the clock time to
the nearest ten seconds. To have the RTC alarm repeat every ten seconds
requires the ALARMRPT value to be set. Setting it to 0, as you have, means
the alarm will not repeat...

The waking from deep sleep with the RTC is setup with:

sleep(DEEP_SLEEP | WAKE_FROM_RTCC);
respected



Joined: 16 May 2006
Posts: 95

View user's profile Send private message

PostPosted: Thu Sep 10, 2020 6:33 am     Reply with quote

I tried. But unfortunately the result is the same.

Code:
#include <18F26J50.h>
//#device ADC=10   
#fuses INTRC_PLL,NOWDT,PLL2,CPUDIV2,RTCOSC_T1
#use delay(clock=24M)

rtc_time_t time;



//!#INT_RTC
//!void RTC_isr(void)
//!{
//!
//!}



void main(void)
{
   
   setup_oscillator(OSC_PLL_ON);                   
   setup_timer_1(T1_EXTERNAL| T1_DIV_BY_1 );
                                   
    setup_rtc(RTC_ENABLE , 0);
    time.tm_year = 20;   
    time.tm_mon = 5;                                               
    time.tm_mday = 21;                                                   
    time.tm_wday = 4;                                               
    time.tm_hour = 16;                                                                           
    time.tm_min = 30;                                       
    time.tm_sec = 0;                                         
    rtc_write(&time);

   
   setup_rtc_alarm(RTC_ALARM_ENABLE, RTC_ALARM_10_SECONDS, 10);
   time.tm_year = 20;
   time.tm_mon = 5;
   time.tm_mday = 21;
   time.tm_wday = 4;
   time.tm_hour = 16;
   time.tm_min = 30;
   time.tm_sec = 10;
   rtc_alarm_write(&time);
   
   
   
//!   clear_interrupt(INT_RTC);
//!   enable_interrupts(INT_RTC);
//!   enable_interrupts(GLOBAL);
   


   while (TRUE)
   {
     output_high(PIN_B2);
     delay_ms(200);
     output_low(PIN_B2);
     delay_ms(100);
                                                                     
     output_low(PIN_B0); //not used
     output_low(PIN_B1); //not used
     output_low(PIN_B6); //not used
     output_low(PIN_B7); //not used
   
     sleep(DEEP_SLEEP | WAKE_FROM_RTCC);
     delay_cycles(1); //Instruction pre-fetched - NOP
   
     output_high(PIN_B3);
     delay_ms(200);
     output_low(PIN_B3);
     delay_ms(100);
                                           
                                                                                                                                                   
      }//while
}//main
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Thu Sep 10, 2020 7:37 am     Reply with quote

I think you are missing a key point.

Deep sleep, is not like normal sleep. The chip will _not_ continue executing
code after this. It restarts. You have to test 'restart_cause' to find that
the chip has waked up from deep sleep mode, rather than being reset.

Quote:

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.


Basically the chip powers off. The RAM is probably lost, the registers are
lost. All that remains running is the selected peripheral, and a small
amount of dedicated RAM (DSGPR0 & 1).

The chip is never going to get to your delay code after the sleep.
It's going to reset....
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