RTC Not running while sleeping

Status
Not open for further replies.

lokker

Member
Hi everyone.
I'm working on a project and I'm using the Snooze library to put my Teensy 3.2 on sleep mode. I am using the RTC module to wake it up and I am doing some testing.
What I have found so far is that the RTC module is not running while the Teensy is sleeping.
Basically I am powering my project from a 5V power supply. I have soldered the small crystal for the RTC module. I am using USB to debug my project
and most importantly I am writing sleeping time in the EEPROM to check what was stored when it went to sleep and what is the current time before sleeping.
So basically I have noticed that the difference between when it goes to sleep and it wakes up is of a few seconds due to my project running and not 10 minutes like
it should be. Because if I put it to sleep at 20.00 then when it wakes up the current time should be greater than 20.10 at most but it isn't. It's just a couple of seconds later
due to other code running before the time is printed on my laptop. So why is this happening? Anyone has got an idea?
Thanks
 
Posting a simplified working sample showing the issue in a sketch could help.

The RTC runs even when not powered when powered by 3V on the VBat pin. Is the VBat pin powered? On wakeup it seems an RTC call to get current time would be needed. The on chip time will stop during sleep as that is driven by running code.
 
Posting a simplified working sample showing the issue in a sketch could help.

The RTC runs even when not powered when powered by 3V on the VBat pin. Is the VBat pin powered? On wakeup it seems an RTC call to get current time would be needed. The on chip time will stop during sleep as that is driven by running code.

Hi, I will post a snippet of code. I find your answer a bit confusing, maybe you got a typo there. Anyway no I don't have the VBat pin powered. I'm only using the power from the Vin pin. What do you mean by an RTC call to get the current time would be needed? I do that already. Also what on chip time are you referring to? Isn't the RTC the only on chip time? Thank you
 
The RTC is separate from the system time. You need to apply a 3v power source to Vbattery and ground to keep it powered when the main board is asleep or not powered at all. Otherwise, it gets reset if you just power the Teensy without providing separate power to the RTC.

In addition, on a Teensy 3.2 (and earlier 3.0/3.1), you need to solder a 32.768kHz 12.5 pF crystal to the special two holes in the board for the crystal. On the Teensy 3.5/3.6, you don't need the crystal, because a crystal was added to the design. The Teensy LC does not have a separate RTC that is powered independently.

IIRC, when you program a Teensy, one of the things that is done is set the RTC to the current time of the computer. So if it is powered, it will keep the time. One of the non-rechargeable coin batteries can be use to power the RTC for several years.
 
The RTC is separate from the system time. You need to apply a 3v power source to Vbattery and ground to keep it powered when the main board is asleep or not powered at all. Otherwise, it gets reset if you just power the Teensy without providing separate power to the RTC.

In addition, on a Teensy 3.2 (and earlier 3.0/3.1), you need to solder a 32.768kHz 12.5 pF crystal to the special two holes in the board for the crystal. On the Teensy 3.5/3.6, you don't need the crystal, because a crystal was added to the design. The Teensy LC does not have a separate RTC that is powered independently.

IIRC, when you program a Teensy, one of the things that is done is set the RTC to the current time of the computer. So if it is powered, it will keep the time. One of the non-rechargeable coin batteries can be use to power the RTC for several years.

Thank you. I'll try that and let all of you know here. I did solder the crystal already.
By the way, it's funny that on the Teensy official webpage is says "The Teensy 3.x RTC will work without a battery, but to retain the time and date while power is off, of course you must also add a 3V battery." which to me means it should work without the battery so even if it goes to sleep because technically the power is still on. Regardless I'll test it out and see if that's the problem. Thanks for the help.
 
May not be 'funny' - if part of sleep power saving cuts power to the part that works under power when running normally - that is powered down that would be in the manual and make sense. That is what the VBat pin and separate circuitry is for.
 
Solved the problem.

It wasn't the 3V coin battery. It is not necessary for the RTC to run. Hence the Teensy official webpage was stating the right.

All I had to do was making sure that I called the "setSyncProvider(getTimeFunction)" in the loop before everything. Yes I did call this function in the setup() but it wasn't working when the Teensy would go to sleep and then wake up.
This is probably because when the Teensy goes to sleep and starts to run the code from the loop it looses some of the previous configurations.
I believe this has all to do with the Snooze library. They should really mention what registers or configs gets lost when the Teensy goes to sleep.
I've been experiencing some bugs that I have managed to solve but not thanks to the official guide on the Snooze GitHub.
 
I believe this has all to do with the Snooze library. They should really mention what registers or configs gets lost when the Teensy goes to sleep.
I've been experiencing some bugs that I have managed to solve but not thanks to the official guide on the Snooze GitHub.
Com'on, Duff is a guy like you and me. I hope, you made some pull requests to duff's library to improve the library, if you really found some bugs in it.
 
Posting a simplified working sample showing the issue in a sketch could help.

The RTC runs even when not powered when powered by 3V on the VBat pin. Is the VBat pin powered? On wakeup it seems an RTC call to get current time would be needed. The on chip time will stop during sleep as that is driven by running code.

Solved the problem.

It wasn't the 3V coin battery. It is not necessary for the RTC to run. Hence the Teensy official webpage was stating the right.

All I had to do was making sure that I called the "setSyncProvider(getTimeFunction)" in the loop before everything. Yes I did call this function in the setup() but it wasn't working when the Teensy would go to sleep and then wake up.
This is probably because when the Teensy goes to sleep and starts to run the code from the loop it looses some of the previous configurations.
I believe this has all to do with the Snooze library. They should really mention what registers or configs gets lost when the Teensy goes to sleep.
I've been experiencing some bugs that I have managed to solve but not thanks to the official guide on the Snooze GitHub.

As noted in Post #2:: On wakeup it seems an RTC call to get current time would be needed.

First post just asked about the 3V pin - I've never done this with Snooze. The rest was speculation because there was no code to look at …

Quite right @WMXZ … Snooze is a deep exploration of places few people have traveled - except using the work by Duff. I've run it minimally - the only sure thing is putting the CPU to sleep in any fashion requires it to be returned to a functional state on Wake. The ARM MCU in Teensy powers up with most everything disabled and PJRC fixes that before entry to setup() enough to have a usable system to .begin() as desired. To get low power for SNOOZE parts of that work is undone depending on the sleep state and must be restored on wake - that is what SNOOZE library is all about - a general purpose solution to use to do anything a Teensy can do ...
 
Thanks everyone.
I wasn't in any way trying to devaluate the work done on the Snuff library. I was just criticising it some points that need improvements.

I did made an RTC call but it wasn't the one suggested as it wasn't even referenced to which call/function in particular. Regardless...

Above all I felt like there was some tension in the messages wrote to me and I wasn't trying to argue with anyone. I appreciate the work done with the Snooze library.

I will report the "bugs" in GitHub.

Wish everyone a nice Christmas.
 
Glad you got it working as needed!

The Teensy being so generally usable is why we're all here and any new use just expands the frontier and makes it even more generally usable which makes it better and more worthwhile.
 
I second that if you find a bug flag me on GitHub, if you have an account, that way I will know. I try to follow these forums the best I can but usually miss a few things here and there. I don't believe the "setSyncProvider(getTimeFunction)" issue is a bug per se because it would require me to include the "time" library in Snooze and felt rightly or wrongly I didn't want to include it. I thought the user could just as easily do this in there code but you are right the documentation is less than satisfactory:(

I can tell you from experience that good documentation is an art form in itself. For me it's the last thing I want to do even though it is probably one of the most important things we do when writing libraries. Some people are really good, me not so much. I also assume most people that write libraries for Teensy or any other platform would love to have great documentation but the reality is that we have jobs, kids, and life things that make it difficult to find time to make sure everything is perfect. But I am immensely thankful people do find time to do what they can to the benefit of all of us in these
communities.
 
I second that if you find a bug flag me on GitHub, if you have an account, that way I will know. I try to follow these forums the best I can but usually miss a few things here and there. I don't believe the "setSyncProvider(getTimeFunction)" issue is a bug per se because it would require me to include the "time" library in Snooze and felt rightly or wrongly I didn't want to include it. I thought the user could just as easily do this in there code but you are right the documentation is less than satisfactory:(

I can tell you from experience that good documentation is an art form in itself. For me it's the last thing I want to do even though it is probably one of the most important things we do when writing libraries. Some people are really good, me not so much. I also assume most people that write libraries for Teensy or any other platform would love to have great documentation but the reality is that we have jobs, kids, and life things that make it difficult to find time to make sure everything is perfect. But I am immensely thankful people do find time to do what they can to the benefit of all of us in these
communities.

Thank you so much for your comment.
I wish I could help but I don't know in depth how these Arm controllers work (I'm more familiar with PIC) and in particular how your library handles it.
I agree the timer is not a bug regarding the Snuff library. I've posted something on your github with some suggestions. Hope that can help in any way.
 
Status
Not open for further replies.
Back
Top