3
\$\begingroup\$

I am using a PIC 18F46J50 microcontroller and the C18 compiler.

I want to retain some data when the controller exits deep sleep mode. I found two registers DSGPR0 and DSGPR1 for context saving but it seems only two bytes are available there.

If I wanted to save more bytes, what are my options?

I would welcome suggestions that are possible with the 8 bit PIC family.

\$\endgroup\$
3
\$\begingroup\$

To save more data than 2 bytes accross a deep sleep:

  1. Redesign the application to require only two bytes (16 bits) accross deep sleep.

  2. Use a external battery-backed CMOS RAM. These take very little power when in standby, but still retaining their contents. A small coin cell can keep the contents alive for years.

  3. Use a external EEPROM. It can be completely powered down in deep sleep mode, but this can only be done a finite number of times. If this device wakes up every second for a few ms, then this is not appropriate. If it wakes up every hour, this could work.

  4. Don't use deep sleep. Regular sleep is still very low power consumption. It stops the clocks, but doesn't power down the RAM completely.

\$\endgroup\$
0
\$\begingroup\$

In section 3.6.1 of the 18F46J50 datasheet the following is written:

Because VDDCORE could fall below the SRAM retention voltage while in Deep Sleep mode, SRAM data could be lost in Deep Sleep. Exiting Deep Sleep mode causes a POR; as a result, most Special Function Registers will reset to their default POR values

Therefore you will need to save data using the PIC's flash self-write capability or to an external SRAM or EEPROM/flash chip. Except the two registers you mention in the question there is no reliable way of storing data in the internal PIC RAM. If you choose an external chip then obviously you will need to pay attention to its power requirements.

Depending on your reason for choosing deep sleep you might be able to find a suitable low power SPI flash part. Any non-volatile external chip could have its power controlled by your PIC, e.g. by using a FET or LDO with enable control. You could power it up to save state before sleep and restore state on wakeup, just make sure you give it enough time to complete writing before powering it down again.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.