Panda II RTC

I must be missing something about the RTC function. I have two fresh alkaline on the bat line producing almost the identical voltage that the line has powered and every time I reset, or the sd card resets or I power down and up it just goes back to jan 1 2009.

Any insight would be appreciated. I have read everything I could find in the forum and the errata sheet and I haven’t solved it.

First try a search of the forum :slight_smile:

The RTC and system clock are two different things. You have to set the RTC (not system clock) to the correct time first. Then each subsequent time the board is reset you read the RTC and set the system clock. This is exactly how your PC works, the RTC on the motherboard is a completely separate piece of hardware, when the PC boots it read the RTC and sets the system clock.

Code please.

You can’t “do nothing”. You need to set the time, once, then RTC will maintain it if correctly powered and operating.

Thanks for the response, but not the tone.

If you actually read the whole message you would see that I had already done all of the appropriate searches so as not to waste your valuable time.

The problem was that the code in the ‘beginners guide’ published in two different formats by GHI was incorrect. In the shorter version which I assumed would be the earliest there was a note that it was invalid and to look at the libraries which I did and sorted it out.

One of the worst things you can do if you want to promote a relatively new product is to produce a beginners guide with bad information. Just leads to frustration for the ‘newbie’ and they walk away from your offering.

As for publishing my code, I will be glad to when it is properly error trapped and commented, unlike much of the stuff on this site. The first project is a logger that reads 8 thermocouples, voltage, current and a tach and the last missing part was the RTC.

I am a ‘newbie’ to FEZ but I got my electronics tech ticket in 1968. I cut my teeth on programming with assembler in the 80’s because if you wanted something you had to build it yourself. Some of my programming was published. I hold worldwide patents.

You may be 'FEZ Masters" but if you want more ‘newbies’ to continue with FEZ you might consider lightening up a bit and pointing out that the documentation is bad.

All I wanted when I said “code please” was for you to show how you were reading and setting the RTC/system times. A small 5 line example of how you’re doing it would have helped, and clearly pointed to anyone else who read the thread what you were doing to correlate to what you were seeing. Nothing too onerous

The one thing with a lot of the code around here is that it dates quickly. There have been changes in the way many features are implemented, including massive ones from netmf 3.x to 4.0, and then 4.0 to 4.1, and along the way with the GHI SDK changes. If the author doesn’t date it by telling what SDK it was written and tested on, that can be a trap.

Here you are:

int datecheck = (Constants.ManufactureDate - Constants.InitialDate).Days;
byte[] buffer = new byte[4];
BatteryRAM.Read(0, buffer, 0, 4);
if (datecheck != (int)Utility.ExtractValueFromArray(buffer, 0, 4))
{
    Debug.Print("Backup battery dead? Setting default time value");
    Utility.InsertValueIntoArray(buffer, 0, 4, (uint)datecheck);
    BatteryRAM.Write(0, buffer, 0, 4);
    RealTimeClock.SetTime(Constants.ManufactureDate);
    Utility.SetLocalTime(Constants.ManufactureDate);
    Led.BlinkRed(2);
}
else
{
    Debug.Print("Backup battery OK");
    Utility.SetLocalTime(RealTimeClock.GetTime());
    Led.BlinkRed(3);
}
Debug.Print("RTC Time: " + RealTimeClock.GetTime().ToString());
Debug.Print("CLR Time: " + DateTime.Now.ToString());

Thanks Savvkin. Very elegant and gives me a look into battery ram usage.

I took a simpler approach from earlier Arduino work.

Utility.SetLocalTime(RealTimeClock.GetTime()); //set netmf time
while (DateTime.Now.Year < 2011) //if it is earlier than 2011
{
Thread.Sleep(200); //stop execution and flash a light
stopped.Write(true); //to force operator to run settime utility
Thread.Sleep(200);
stopped.Write(false);
}

You are welcome.

I think, checking battery backup RAM is more reliable. What if for a new chip they decide that default date should start 01.01.2011. Then (DateTime.Now.Year < 2011) will not work.

P.S. It’s more annoying to beep a piezo, than flash a led to force operator to change failed backup battery! ;D

Good point about the default date and the annoying piezos. Every time the hydro goes down I end up racing around the house and shop shutting down systems running on ups so the annoying beeping will stop.

Or you can make beep less annoying :smiley:

Cute… If I put a half dozen tester in the lab with that going off they will learn how to use the settime utility pretty quick.

That really made me laugh! Love it!