PIC24F Deep sleep with external clock - Page 1
Forum section: electronics / general

author: aurmer
author_rank: Regular Contributor
timestamp: November 08, 2016, 12:24:57 pm
content: 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:PIC243.3V External clk sourceLower Voltage 1.8V External clk sourceMy 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.

author: Kilrah
author_rank: Unknown
timestamp: November 08, 2016, 12:41:19 pm
content: 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.

author: Kalvin
author_rank: Super Contributor
timestamp: November 08, 2016, 12:54:19 pm
content: 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  sleep mode.

author: aurmer
author_rank: Regular Contributor
timestamp: November 08, 2016, 01:04:07 pm
content: 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.

author: David Hess
author_rank: Super Contributor
timestamp: November 08, 2016, 01:35:59 pm
content: 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.

author: Kilrah
author_rank: Unknown
timestamp: November 08, 2016, 01:57:21 pm
content: Quote from: zetharx on November 08, 2016, 01:04:07 pmThe 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!

author: Kalvin
author_rank: Super Contributor
timestamp: November 08, 2016, 02:21:13 pm
content: Quote from: David Hess on November 08, 2016, 01:35:59 pmThe 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.

author: aurmer
author_rank: Regular Contributor
timestamp: November 08, 2016, 02:32:06 pm
content: Quote from: Kalvin on November 08, 2016, 02:21:13 pmI 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.Quote from: David Hess on November 08, 2016, 01:35:59 pmI 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.

author: Kilrah
author_rank: Unknown
timestamp: November 08, 2016, 03:43:39 pm
content: Quote from: zetharx on November 08, 2016, 02:32:06 pmThat'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.

author: David Hess
author_rank: Super Contributor
timestamp: November 08, 2016, 06:17:55 pm
content: Quote from: zetharx on November 08, 2016, 02:32:06 pmThat 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.QuoteA 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.