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

Wake result from Deep Sleep on PIC24FJ128GA204
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
JamesW



Joined: 23 Apr 2007
Posts: 91
Location: Rochester, England

View user's profile Send private message Visit poster's website

PostPosted: Mon Sep 17, 2018 11:45 am     Reply with quote

OK - I am moving forwards, albeit in a somewhat fumbling manner !

With a bit of tinkering to my main() I've got it to a stage where it reliably restarts from deep sleep for both the EXT0 or the RTCC - albeit with a repeated command at the start of main (without this it won't start 50% of the time).

I've moved all the RS232 debug to the other side of the hardware initialisation, for neatness and this seemed to sort out the lack of wake from the RTC.

Also I've added in the check for the DSBOR - which it appears sometimes occurs (not sure why at the moment!).

If I press the INT0 button approx less than 2 seconds after it has gone to sleep, I wake fine and get the DSWAKE flag set to tell me that it was int0.

If I wait approx 5 seconds, I get a DSBOR on startup

If I wait longer then 10 seconds then I get an unknown wake as previously.

When the RTCC wakes me, I always get an unknown wake (never a brownout)

Code:

void main()
{
   
   UI_8 OldTimer2 = 0, OldSeconds=0;
   UI_8 TestCounter = 0;
   UI_16 RConRegister = 0, DSWakeReg = 0, DSConRegister = 0;
   
   DSWakeReg = DEEP_SLEEP_WAKE_REG;
   RConRegister = RCON_REG;
   DSConRegister = DSCON_REG;

   /* CLEAR DSCON REG ANYWAY */
   DSCON_REG = 0;
   DSCON_REG = 0; /* WILL NOT BOOT RELIABLY WITHOUT THIS REPEATED */
 
   /* CLEAR THIS BIT */
   DEEP_SLEEP_WAKE_BIT = 0;

   clear_interrupt(INT_EXT0);
   clear_interrupt(INT_RTC);
   
   /* INITIALISE THE PIC */
   Setup_PIC();
   
   
   delay_ms(100); /* DELAY TO ALLOW THE UART TO WAKE */
   
   /* CHECK FOR DEEP SLEEP BROWNOUT */
   if (bit_test(DSConRegister,1) == TRUE)
   {
      fprintf(DEBUG_PORT,"\r\nDEEP SLEEP BOR OCCURRED");
   }

     /* STAGE 1 - READ THE DEEP SLEEP BIT */
   if (bit_test( RConRegister, 10) == TRUE)
   {
      fprintf(DEBUG_PORT,"\r\nDEEP SLEEP DSWAKE:%04X RCON:%04X INT0:%u RTCC:%u",DSWakeReg, RConRegister, DEEP_SLEEP_INT0_BIT, DEEP_SLEEP_RTCC_BIT);
     
      switch(DSWakeReg)
      {
         case 4:
         { 
            fprintf(DEBUG_PORT,"\r\nMCLR FROM DEEP SLEEP:%04X",DSWakeReg);
            break;
         }
         case 8:
         {
            fprintf(DEBUG_PORT,"\r\nRTC ALARM FROM DEEP SLEEP:%04X",DSWakeReg);
            break;
         } 
         case 16:
         {
            fprintf(DEBUG_PORT,"\r\nDEEP SLEEP WATCHDOG TIMER:%04X",DSWakeReg);
            break;
         }     
         case 128:
         {
            fprintf(DEBUG_PORT,"\r\nDEEP SLEEP FAULT:%04X",DSWakeReg);
            break;
         }     
         case 256:
         {
            fprintf(DEBUG_PORT,"\r\nWAKE BUTTON FROM DEEP SLEEP:%04X",DSWakeReg);
            break;
         }     
         default:
         {
            fprintf(DEBUG_PORT,"\r\n UNKNOWN WAKE FROM DEEP SLEEP:%04X",DSWakeReg);
            break;
         }
      } /* END WAKE CAUSE */
   }/* END WOKE FROM DEEP SLEEP */   
   else
   {
      delay_ms(100);
      fprintf(DEBUG_PORT,"\r\n\r\nNOT WOKEN FROM DEEP SLEEP:%04X",DSWakeReg);
   }



The debug screen events below are in this order, and I've coloured them for ease of reading.

First Wake - press INT0 1 second after SLEEPING appears on screen
Second Wake - press INT0 1 second after SLEEPING appears on screen
Third Wake - press INT0 15 second after SLEEPING appears on screen
Fourth Wake - unit slept for 60 seconds and woke on RTCC
Fifth Wake - press INT0 1 second after SLEEPING appears on screen

The above results are completely repeatable, and I repeated the first after the RTCC wake to prove it.

If anyone can work out what is going on here, I'll be impressed

Quote:

TICK:9 POWER BUT:1
TICK:10 POWER BUT:1
STARTING SLEEP

SLEEPING
DEEP SLEEP DSWAKE:0100 RCON:0403 INT0:1 RTCC:0
WAKE BUTTON FROM DEEP SLEEP:0100
TICK:1 POWER BUT:1
TICK:2 POWER BUT:1
TICK:3 POWER BUT:1
TICK:4 POWER BUT:1
TICK:5 POWER BUT:1
TICK:6 POWER BUT:1
TICK:7 POWER BUT:1
TICK:8 POWER BUT:1
TICK:9 POWER BUT:1
TICK:10 POWER BUT:1
STARTING SLEEP


SLEEPINGÿ
DEEP SLEEP BOR OCCURRED
DEEP SLEEP DSWAKE:0000 RCON:0403 INT0:0 RTCC:0
UNKNOWN WAKE FROM DEEP SLEEP:0000
TICK:1 POWER BUT:1
TICK:2 POWER BUT:1
TICK:3 POWER BUT:1
TICK:4 POWER BUT:1
TICK:5 POWER BUT:1
TICK:6 POWER BUT:1
TICK:7 POWER BUT:1
TICK:8 POWER BUT:1
TICK:9 POWER BUT:1
TICK:10 POWER BUT:1
STARTING SLEEP


SLEEPING¿û
DEEP SLEEP DSWAKE:0000 RCON:0403 INT0:0 RTCC:0
UNKNOWN WAKE FROM DEEP SLEEP:0000
TICK:1 POWER BUT:1
TICK:2 POWER BUT:1
TICK:3 POWER BUT:1
TICK:4 POWER BUT:1
TICK:5 POWER BUT:1
TICK:6 POWER BUT:1
TICK:7 POWER BUT:1
TICK:8 POWER BUT:1
TICK:9 POWER BUT:1
TICK:10 POWER BUT:1
STARTING SLEEP


SLEEPING··¿¿ÿ
DEEP SLEEP DSWAKE:0000 RCON:0403 INT0:0 RTCC:0
UNKNOWN WAKE FROM DEEP SLEEP:0000
TICK:1 POWER BUT:1
TICK:2 POWER BUT:1
TICK:3 POWER BUT:1
TICK:4 POWER BUT:1
TICK:5 POWER BUT:1
TICK:6 POWER BUT:1
TICK:7 POWER BUT:1
TICK:8 POWER BUT:1
TICK:9 POWER BUT:1
TICK:10 POWER BUT:1
STARTING SLEEP


SLEEPING
DEEP SLEEP DSWAKE:0100 RCON:0403 INT0:1 RTCC:0
WAKE BUTTON FROM DEEP SLEEP:0100
TICK:1 POWER BUT:1
TICK:2 POWER BUT:1
TICK:3 POWER BUT:1
TICK:4 POWER BUT:1
TICK:5 POWER BUT:1
TICK:6 POWER BUT:1

JamesW



Joined: 23 Apr 2007
Posts: 91
Location: Rochester, England

View user's profile Send private message Visit poster's website

PostPosted: Mon Sep 17, 2018 11:49 am     Reply with quote

And after a triple check, without these two lines in the code it won't reliably start up and frequently locks up taking about 820uA and the only way to recover is a hardware reset!

With this as a single line it won't start reliably either!!!

Code:

   /* CLEAR DSCON REG ANYWAY */
   DSCON_REG = 0;
   DSCON_REG = 0; /* WILL NOT BOOT RELIABLY WITHOUT THIS REPEATED */
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Sep 17, 2018 12:31 pm     Reply with quote

Yes, it's the release bit. The DSEN bit clears itself, but release remains set. However there is no mention of having to clear it twice!. Looks like a hardware issue here...

As a comment, how are you clocking the RTCC?. If you are using the secondary oscillator, this section applies:

Quote:

This means that keeping the SOSC running after
waking up requires the SOSCEN bit to be set before
clearing RELEASE.
JamesW



Joined: 23 Apr 2007
Posts: 91
Location: Rochester, England

View user's profile Send private message Visit poster's website

PostPosted: Tue Sep 18, 2018 5:33 am     Reply with quote

I am running the RTC on the internal oscillator (SOSC pins are I/O but not connected).

setup as below.

Code:

   /* TURN ON AND RESET THE CLOCK */
   setup_rtc(RTC_ENABLE|RTC_CLOCK_INT , 0);
   


You were right - clearing the release bit (albeit twice does work).

Now we delve into the depths - investigating the brownout issue.

I originally set this up using the PIC 24Wizard - which doesn't always worry about fuse settings - and the explicit declaration that I didn't want Deep sleep brownout wasn't stated.

So now I amend my fuse settings to the following - to turn off DSWDT and also the DSBROWNOUT


Code:

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOJTAG                   //JTAG disabled
#FUSES CKSFSM                   //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NODEBUG
#FUSES IESO
#FUSES SOSC_DIG
#FUSES LVR
#FUSES WINDIS
#FUSES NOWDT//WDT_NOSL
#FUSES CKSNOFSM
#FUSES NODSWDT  /* NO DEEP SLEEP WATCHDOG */
#FUSES NODSBOR  /* NO DEEP SLEEP BROWNOUT */
#FUSES DS_SW    /* DEEP SLEEP PERMITTED   */
#FUSES DSWDTCK_LPRC



This is where it gets interesting. With NODSBOR declared, the unit goes to sleep and it I wake it within 10 seconds or so it wakes up. (Still doesn't detect the wake source)

If however I wait longer than about 30 seconds, and then press the INT1 button, the current increases to about 360uA and nothing happens - however the hardware reset button on MCLR doesn't reset the processr, and I am unable to reprogram it with the CCS programmer or anything until I physically power cycle the processor. (Holding my reset button down does increase the current to 434uA, but releasing it it returns to 360uA and nothing happens!)

(Putting NODSBOR back to DSBOR means it then wakes up as previously)

Any ideas?

Can anyone explain how DSBOR works please, as I'm not entirely sure what to make of the datasheet on this as it just has electrical characteristics (and two of them).
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Tue Sep 18, 2018 12:02 pm     Reply with quote

One thing definitely applies. That the brownout was triggering implies the supply voltage is dubious. A PIC with a dubious supply can give all sorts of problems. It sounds as if your supply is decaying after you go to sleep. How is your supply derived and controlled?.
JamesW



Joined: 23 Apr 2007
Posts: 91
Location: Rochester, England

View user's profile Send private message Visit poster's website

PostPosted: Thu Sep 20, 2018 11:14 am     Reply with quote

Found it! In order to debug what the deep sleep current of the processor was and get it as low as possible, I fitted a jumper link to to the VCC supply of the processor. This meant I could wire in an ammeter in series with the processor at this point. Despite it only being 4" away from the processor - this was sufficient to cause the brownout on wakeup! removing the ammeter and refitting the link solved the problem

As an aside - with the RTCC running on the internal RC oscillator, and wake set for RTCC or INT0 - the current it is actually drawing is about 78uA. Which does seem quite a bit higher than that quoted on the datasheet. Any ideas?

Thanks for all the help

James
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Thu Sep 20, 2018 11:54 am     Reply with quote

Smile
The brownout was the clue.

Are any pins driving anything?.
Remember that the ultimate low current requires the PIC to not be driving anything. All pins set to inputs, or if outputs set to drive to the voltage that draws no current from the PIC.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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