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

PIC24EP512 - Reduce clock speed when sleeping [CLOSED]

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



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PIC24EP512 - Reduce clock speed when sleeping [CLOSED]
PostPosted: Sun Nov 29, 2020 7:27 pm     Reply with quote

Device: PIC24EP51GP806
Compiler: 5.026

Good evening,

Just thought of something.... when my circuit is running, the PIC uses the following for clocking:

#define XTAL_FREQ 29491200
#define SYS_CLOCK 129024000

After so many minutes of inactivity, the PIC goes to sleep.

Would it help to reduce power consumption when sleeping if the PIC reverted to its slowest internal clock (LPRC) just before going to sleep? Then immediately after waking up, it reverts back to its external clock?

When going to sleep, this is what I have:

Code:


   // Stop the watchdog timer
   setup_wdt( WDT_OFF );

   // Disable all peripherral power
   #byte PMD1 = getenv("byte:PMD1")
   #byte PMD2 = getenv("byte:PMD2")
   #byte PMD3 = getenv("byte:PMD3")
   #byte PMD4 = getenv("byte:PMD4")
   #byte PMD5 = getenv("byte:PMD5")
   #byte PMD6 = getenv("byte:PMD6")
   #byte PMD7 = getenv("byte:PMD7")

   PMD1 = 0xFF;
   PMD2 = 0xFF;
   PMD3 = 0xFF;
   PMD4 = 0xFF;
   PMD5 = 0xFF;
   PMD6 = 0xFF;
   PMD7 = 0xFF;

   #byte NVMCON=getenv("SFR:NVMCON");
   #bit NVMSIDL=NVMCON.12;
   NVMSIDL=TRUE;

   #byte RCON = getenv("SFR:RCON")
   #bit VREGS = RCON.8
   #bit VREGSF = RCON.11
   VREGS  = FALSE;
   VREGSF = FALSE;

   #byte OSCCON = getenv("SFR:OSCCON");
   #bit LPOSCEN = OSCCON.1;
   LPOSCEN = FALSE;

   #bit UART1_WAKE=getenv("BIT:U1MODE.WAKE")
   UART1_WAKE = TRUE;

   // Sleep NOW
   sleep( SLEEP_FULL );

   //------------------------- UNIT IS NOW SLEEPING -------------------------

   // Unit can wake-up on external interrupts or UART data

   //---------------------------- UNIT IS WAKING-UP --------------------------

   // Wake-up - wait a few cycles
   delay_cycles( 10 );

   // Clear RAM **don't set any variables above this line**
   #zero_ram
   // Continue code from here



If my clocking question above is valid and would help, then what should I be using just before the sleep() to revert to the slowest internal clock and what should I use to revert back to my standard external clock?

All I want is to reduce power consumption to the minimum while still being able to wake-up the device on external hardware interrupts. This all works fine, I'm now into the nitty gritty details of what else I can do to reduce power consumption and I think the oscillator may be something to look into...

I know it may sound trivial, I've never attempted this. I will go read on it in the mean time.

Thanks!

Ben


Last edited by benoitstjean on Mon Nov 30, 2020 9:42 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Mon Nov 30, 2020 1:16 am     Reply with quote

No.
When the chip is fully asleep, the clock is stopped.
Where slowing the clock is useful, is if instead of going fully to sleep, you
keep some peripherals awake. So an 'idle' mode as opposed to 'sleep full'.

Though you are waking on serial events, the UART is not 'clocked' to do this.
This is why the first byte is not genuinely 'received' when doing this.
benoitstjean



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Mon Nov 30, 2020 7:07 am     Reply with quote

Thanks for the reply. Yeah, finally did a bit of reading last night and saw this from document DS70580C page 7-28:

In Sleep mode, all clock sources (Primary Oscillator, Internal FRC and LPRC
Oscillator) are shut down, with the exception of the low-power secondary
oscillator. The low-power secondary oscillator can be active in Sleep mode if the
Secondary Oscillator Enable bit (LPOSCEN) is set in the Oscillator Control
register (OSCCON<1>).


So in my code excerpt, is there anything else I should disable in order to minimize current draw or is this as low-power as it can be (from the MCU's perspective) when <full sleep> is used? Are the lines of code all necessarry or does the <full sleep> take care of that and I can remove some lines?

For the UART not being 'clocked', I was aware but thanks for the pointer.... in all honesty, it's not that big of a deal because to wake-up the unit, all I have to do is text the modem anything and it'll wake-up the unit. Once I get the wake-up response, then it's fine until it goes back to sleep.

I would guess that if I was to go in idle mode instead of full sleep mode, the current draw would be more but then I'd be able to get the UART data... I think I'd rather stick to full sleep and be able to wake-up the unit on garbage data. I realize that anyone texting the unit will wake it up but I don't seem to be getting that many random SMS so it's not much of a concern.

Thanks.

Ben
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Mon Nov 30, 2020 7:44 am     Reply with quote

There are other things you are not showing that matter for the consumption.
Ensuring no line on the chip is floating. Ensuring every external peripheral
is in it's lowest power state. These both affect how much the unit will draw.
benoitstjean



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Mon Nov 30, 2020 7:58 am     Reply with quote

Oh yeah for sure, I didn't go into details, it was more from the PIC's perspective... I have sensors on there, a modem etc. These have their own low-power modes.

Thanks!

Ben
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Mon Nov 30, 2020 8:16 am     Reply with quote

If they don't use every pin, ensuring that the unused PIC pins are not
floating is also critical, and if the 'low power' modes of the external chips
leave any pins undriven, the same comment for these pins.
benoitstjean



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Mon Nov 30, 2020 8:26 am     Reply with quote

Hmmm... I don't have that many unused pins left but since the circuit is already done, can I set them to high-z in code or should I attempt to solder like a 10K resistor to GND?
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Mon Nov 30, 2020 9:17 am     Reply with quote

Neither.
Make sure the code pulls them either up or down. The point is they do
not want to be 'Hi-Z'. This is what they are if they are left unused, and in this
state, if a little bit of RF arrives at them, they can float into the transition
region (between 'high' and 'low'), and if this happens extra current will
be drawn by the PIC.
Every unused pin, should be explicitly driven either high or low in the code.
benoitstjean



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Mon Nov 30, 2020 9:26 am     Reply with quote

ah ok... fair enough. So I can just say output_low( PIN_x )...
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Mon Nov 30, 2020 9:29 am     Reply with quote

Yes.
benoitstjean



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Mon Nov 30, 2020 9:41 am     Reply with quote

You rock! Thanks!

Ben
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