Author Topic: PIC24F Deep sleep with external clock  (Read 4489 times)

0 Members and 1 Guest are viewing this topic.

Offline aurmerTopic starter

  • Regular Contributor
  • *
  • Posts: 84
  • Country: us
  • Insert text here.
PIC24F Deep sleep with external clock
« on: November 08, 2016, 12:24:57 pm »
What is the best practice for setting up an mcu to use a backup battery (CR2032) to maintain proper date and time while unplugged, but also keep an external clock source powered as well? Does it matter if the clock source voltage drops due to switching to a new power source on main power failure? I imagine some clock sources have detailed specs for a whole voltage range, but what I have found are ones which just state the single Vdd value it is specced for.

Attached are some simple schematics to illustrate what I am considering.

Components:
PIC24
3.3V External clk source
Lower Voltage 1.8V External clk source

My homework that I've done:
Vbat low power mode (w/ RTCC) is what I am going to use when the device is unplugged.
Pin 34 SCLKI - clock input for secondary oscillator 32KiHz. This is my RTCC clock configuration. Not using the whole SOSC circuit, but just receiving the clock input.
SCLKI input buffer type undefined. This is where I expected to find out how high of a voltage I need my clock signal to reach.
Digital Input buffer types and their "logic high" thresholds.
PIC24 Internal logic is controlled by internal Vregs. Normally 1.8V, but for deep sleep mode, the 1.2V regulator inside the chip powers the RTCC. Does this mean that I can put 1.8V in at all times, even when Vdd = 3.3V? Datasheet is not clear on any page I have read.
If I just asked the wrong question, shame on me for asking before I was ready for help. Please be kind and direct me to a resource which will teach me the question I SHOULD be asking. Thank you.
 

Offline Kilrah

  • Supporter
  • ****
  • Posts: 1852
  • Country: ch
Re: PIC24F Deep sleep with external clock
« Reply #1 on: November 08, 2016, 12:41:19 pm »
First question is... why?
There's a perfectly good internal oscillator that can run with just a crystal without having to even get into this.
 

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 2145
  • Country: fi
  • Embedded SW/HW.
Re: PIC24F Deep sleep with external clock
« Reply #2 on: November 08, 2016, 12:54:19 pm »
The PIC24F has an option to use an external 32.768kHz crystal with the internal oscillator. The PIC24F draws current around 1uA when the 32kHz crystal is enabled and the device is in [deep] sleep mode.
 

Offline aurmerTopic starter

  • Regular Contributor
  • *
  • Posts: 84
  • Country: us
  • Insert text here.
Re: PIC24F Deep sleep with external clock
« Reply #3 on: November 08, 2016, 01:04:07 pm »
Good question, but I don't think it changes my overall question. Let's say I go with laying out my own crystal and load caps.

When I go from Vdd = 3.3V operation to Vbat = 2V operation, will that effect the frequency of the internal oscillator + external crystal?

I chose a completely packaged oscillator to avoid any concerns about designing the circuit "properly" (the IC is more reliable than my design), and I don't see how the problem is any different. You are suggesting that I just power the oscillator through the PIC24, but it still raises my question of will the change in voltage source affect the frequency in any meaningful way.



For that matter, while you bring up my selection of oscillator, is 5ppm the tightest that they can cut these 32KiHz xtals? I can't find any specced tighter.

EDIT: And thank you, I recognize that your suggestion is they way microchip designed it to be used. I am just trying to make sure I am fully understanding the theory of operation, and what the consequences are for going into deep sleep.
« Last Edit: November 08, 2016, 01:06:53 pm by zetharx »
If I just asked the wrong question, shame on me for asking before I was ready for help. Please be kind and direct me to a resource which will teach me the question I SHOULD be asking. Thank you.
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16607
  • Country: us
  • DavidH
Re: PIC24F Deep sleep with external clock
« Reply #4 on: November 08, 2016, 01:35:59 pm »
When the oscillator supply voltage changes, the various junction capacitances change so there is an effect on oscillator frequency but it is minor.  If this is a significant source of error, then regulate the voltage to the oscillator.

If the 32 kHz crystal oscillator tolerance is not good enough, then calibrate it.  This could be done externally with a trimmer capacitor or with a digital correction factor saved in non-volatile memory.

If you are considering precision levels where either of the above are an issue, then the crystal oscillator should be temperature compensated anyway.
 

Offline Kilrah

  • Supporter
  • ****
  • Posts: 1852
  • Country: ch
Re: PIC24F Deep sleep with external clock
« Reply #5 on: November 08, 2016, 01:57:21 pm »
Good question, but I don't think it changes my overall question. Let's say I go with laying out my own crystal and load caps.

When I go from Vdd = 3.3V operation to Vbat = 2V operation, will that effect the frequency of the internal oscillator + external crystal?

The thing is that PIC is precisely designed to be used that way, there wouldn't be a mechanism to switch from main power to VBAT if it didn't work!
 

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 2145
  • Country: fi
  • Embedded SW/HW.
Re: PIC24F Deep sleep with external clock
« Reply #6 on: November 08, 2016, 02:21:13 pm »
When the oscillator supply voltage changes, the various junction capacitances change so there is an effect on oscillator frequency but it is minor.  If this is a significant source of error, then regulate the voltage to the oscillator.

If the 32 kHz crystal oscillator tolerance is not good enough, then calibrate it.  This could be done externally with a trimmer capacitor or with a digital correction factor saved in non-volatile memory.

If you are considering precision levels where either of the above are an issue, then the crystal oscillator should be temperature compensated anyway.

The PIC24F RTCC has internal registers that can perform automatic fine-tuning. If the 32.768kHz oscillator's frequency changes when the MCU is running at 3V and 2V, just change the RTCC adjustment values accordingly when you change the power supply.
 

Offline aurmerTopic starter

  • Regular Contributor
  • *
  • Posts: 84
  • Country: us
  • Insert text here.
Re: PIC24F Deep sleep with external clock
« Reply #7 on: November 08, 2016, 02:32:06 pm »
When the oscillator supply voltage changes, the various junction capacitances change so there is an effect on oscillator frequency but it is minor.  If this is a significant source of error, then regulate the voltage to the oscillator.

If the 32 kHz crystal oscillator tolerance is not good enough, then calibrate it.  This could be done externally with a trimmer capacitor or with a digital correction factor saved in non-volatile memory.

If you are considering precision levels where either of the above are an issue, then the crystal oscillator should be temperature compensated anyway.

The PIC24F RTCC has internal registers that can perform automatic fine-tuning. If the 32.768kHz oscillator's frequency changes when the MCU is running at 3V and 2V, just change the RTCC adjustment values accordingly when you change the power supply.

I like this thinking, unfortunately, power loss to Vdd cannot be anticipated because it is never planned. Once Vdd goes dark, the code processing ceases completely. Unless I made a "short term" Vdd backup designed to give the MCU time to "plan" for the outage... it can't be done that way.

When the oscillator supply voltage changes, the various junction capacitances change so there is an effect on oscillator frequency but it is minor.  If this is a significant source of error, then regulate the voltage to the oscillator.

If the 32 kHz crystal oscillator tolerance is not good enough, then calibrate it.  This could be done externally with a trimmer capacitor or with a digital correction factor saved in non-volatile memory.

If you are considering precision levels where either of the above are an issue, then the crystal oscillator should be temperature compensated anyway.


I will continue my google search, but if you know any resources that can teach me the ins and outs of tuning a crystal, it would be much appreciated.
If I just asked the wrong question, shame on me for asking before I was ready for help. Please be kind and direct me to a resource which will teach me the question I SHOULD be asking. Thank you.
 

Offline Kilrah

  • Supporter
  • ****
  • Posts: 1852
  • Country: ch
Re: PIC24F Deep sleep with external clock
« Reply #8 on: November 08, 2016, 03:43:39 pm »
I like this thinking, unfortunately, power loss to Vdd cannot be anticipated because it is never planned. Once Vdd goes dark, the code processing ceases completely. Unless I made a "short term" Vdd backup designed to give the MCU time to "plan" for the outage... it can't be done that way.

That's not a problem, a small cap of a few uF is enough to do the job, the time needed to detect main power disconnect and run the necessary code is counted in microseconds. You'd likely have to do that anyway to "cleanly" switch to deep sleep even if you used the external oscillator you originally planned.
« Last Edit: November 08, 2016, 03:46:34 pm by Kilrah »
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16607
  • Country: us
  • DavidH
Re: PIC24F Deep sleep with external clock
« Reply #9 on: November 08, 2016, 06:17:55 pm »
The PIC24F RTCC has internal registers that can perform automatic fine-tuning. If the 32.768kHz oscillator's frequency changes when the MCU is running at 3V and 2V, just change the RTCC adjustment values accordingly when you change the power supply.

I like this thinking, unfortunately, power loss to Vdd cannot be anticipated because it is never planned. Once Vdd goes dark, the code processing ceases completely. Unless I made a "short term" Vdd backup designed to give the MCU time to "plan" for the outage... it can't be done that way.

That is how I have done it in the past.  Since the MCU oscillators were being used, it had to be powered continuously anyway so a micropower regulator supplied only the MCU and necessary support circuits.  When main power dropped, the MCU detected that, switched oscillator sources, and shutdown.  Then the 32kHz oscillator continued running and either the MCU periodically woke up to check power state or a wake on state change was used.

One reason I really like the PICs is there support for separate low and high power oscillators.

Quote
When the oscillator supply voltage changes, the various junction capacitances change so there is an effect on oscillator frequency but it is minor.  If this is a significant source of error, then regulate the voltage to the oscillator.

If the 32 kHz crystal oscillator tolerance is not good enough, then calibrate it.  This could be done externally with a trimmer capacitor or with a digital correction factor saved in non-volatile memory.

If you are considering precision levels where either of the above are an issue, then the crystal oscillator should be temperature compensated anyway.

I will continue my google search, but if you know any resources that can teach me the ins and outs of tuning a crystal, it would be much appreciated.

A 32 kHz crystal oscillator still uses an external load capacitance so either a trimmer capacitor is used or varactor tuning is implemented which also allows temperature compensation.  The problem with varactor tuning however is that varator diodes require high bias voltages so they are not suitable for low voltage circuits without extra complexity.  That makes digital calibration even if the microcontroller has to periodically wake up to measure the temperature a better solution.

If you are going to mess with type of circuit, then you should have a real frequency counter for making measurements during development.  At 32 kHz a reciprocal frequency counter will be needed to get enough resolution in a reasonable time.  Technically the PIC can make this measurement if you have an external reference source that it can use like the 1 PPS from a GPS and that is probably not a bad way to do automatic calibration.
« Last Edit: November 08, 2016, 06:20:40 pm by David Hess »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf