On Raptor and G400HDR using the latest firmware I am experiencing clock skew in the order of 1-3 seconds per minute. What am I doing wrong, this functions fine on the CobraII and Hydra boards with minimal skew.
Results
Test Duration: 00:05:52.0010000
Reference Time: 10/30/2013 00:37:55
Onboard RTC Time: 10/30/2013 00:37:54
Local Clock Time: 10/30/2013 00:38:02
Difference Local Clock - Onboard RTC: 00:00:08.0858125
Difference Local Clock - Reference Clock: 00:00:07.0868125
Difference Reference Clock - Onboard RTC: 00:00:00.9990000
Test Program
public partial class Program
{
public static GT.Timer t;
public static DateTime teststart;
public static RTC_DS1307 reftime;
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
Register SCKC_CR = new Register(0xFFFFFE50);
uint r = SCKC_CR.Read();
if (r != 14)
{
SCKC_CR.SetBits(0x02 | 0x04 | 0x08); //enable OSC32EN, OSC32BYP, OSCSEL
}
Thread.Sleep(500);
Debug.Print("Register SCKC_CR Value: " + SCKC_CR.Read().ToString()); //make certain registers are set correctly
reftime = new RTC_DS1307();
Debug.Print("Program Started");
Debug.Print("System Boot Time Before System Time Set: " + DateTime.Now.ToString());
DateTime settimeto = reftime.GetDateTime();
Debug.Print("Set this time to RTC from Reference Clock: " + settimeto.ToString());
RealTimeClock.SetTime(settimeto);
DateTime rtctime = RealTimeClock.GetTime();
teststart = settimeto;
Debug.Print("Onboard RTC after setting time to Reference Clock: " + rtctime.ToString());
Microsoft.SPOT.Hardware.Utility.SetLocalTime(settimeto);
Debug.Print("Local Board Time after Setting from Reference Clock: " + DateTime.Now);
t = new GT.Timer(60000);
t.Tick += new GT.Timer.TickEventHandler(Tick);
t.Start();
}
void Tick(GT.Timer timer)
{
t.Stop();
try
{
DateTime rtc = RealTimeClock.GetTime();
DateTime local = DateTime.Now;
DateTime reference = reftime.GetDateTime();
TimeSpan onboardrtc_localclock = local - rtc;
TimeSpan ref_onboardrtc = reference - rtc;
TimeSpan ref_localclock = local - reference;
TimeSpan duration = rtc - teststart;
Debug.Print("***********************************************************");
Debug.Print("Test Duration: " + duration.ToString());
Debug.Print("Reference Time: " + reference.ToString());
Debug.Print("Onboard RTC Time: " + rtc.ToString());
Debug.Print("Local Clock Time: " + local.ToString());
Debug.Print("Difference Local Clock - Onboard RTC: " + onboardrtc_localclock.ToString());
Debug.Print("Difference Local Clock - Reference Clock: " + ref_localclock.ToString());
Debug.Print("Difference Reference Clock - Onboard RTC: " + ref_onboardrtc.ToString());
Debug.Print("***********************************************************");
}
catch(Exception e)
{
Debug.Print("Error has occurred " + e.Message);
}
t.Start();
}
}
The time grows by 1-3 seconds per minute and is not consistent for example at minute one it is 1:02 and minute two it is 2:05 etc… but this varies but test.
Results of almost 5 hours of running.
Test Duration: 04:43:13.0010000
Reference Time: 10/30/2013 18:16:12
Onboard RTC Time: 10/30/2013 18:16:09
Local Clock Time: 10/30/2013 18:22:56
Difference Local Clock - Onboard RTC: 00:06:47.7778750
Difference Local Clock - Reference Clock: 00:06:44.7788750
Difference Reference Clock - Onboard RTC: 00:00:02.9990000
At this moment, we cannot run the test that you are running as, if I am not mistaken, you are using an outside RTC device to compare to the Raptor? We do not currently have access to this module.
We ran another test to compare the time but it was not quite how your test was. We simply set up a Raptor with a button and had the timer output the time every second for one hour and 25 minutes and compared it against a Galaxy S2’s stopwatch and we did not see any time differential.
However, the test that we ran did not include the register modification that your testing code showed. Why did you access this particular register: Register SCKC_CR = new Register(0xFFFFFE50);?
Here is test program without external dependancies and register access for you to run, after about an hour the netmf clock is 1 minute and 25 seconds off.
Test Duration: 00:58:35.0010000
Onboard RTC Time: 10/30/2013 12:58:35
Local Clock Time: 10/30/2013 13:00:00
Difference Local Clock - Onboard RTC: 00:01:25.1645313
Difference Local Clock - Test Start: 01:00:00.1655313
Difference Test Start - Onboard RTC: -00:58:35.0010000
public partial class Program
{
public static GT.Timer t;
public static DateTime teststart;
void ProgramStarted()
{
Debug.Print("Program Started");
Debug.Print("System Boot Time Before System Time Set: " + DateTime.Now.ToString());
DateTime settimeto = new DateTime(2013, 10, 30, 12, 0, 0);
Debug.Print("Set this time to RTC from settimeto variable: " + settimeto.ToString());
RealTimeClock.SetTime(settimeto);
DateTime rtctime = RealTimeClock.GetTime();
teststart = settimeto;
Debug.Print("Onboard RTC after setting time to Reference Clock: " + rtctime.ToString());
Microsoft.SPOT.Hardware.Utility.SetLocalTime(settimeto);
Debug.Print("Local Board Time after Setting from Reference Clock: " + DateTime.Now);
t = new GT.Timer(300000);
t.Tick += new GT.Timer.TickEventHandler(Tick);
t.Start();
}
void Tick(GT.Timer timer)
{
t.Stop();
try
{
DateTime rtc = RealTimeClock.GetTime();
DateTime local = DateTime.Now;
TimeSpan onboardrtc_localclock = local - rtc;
TimeSpan ts_onboardrtc = teststart - rtc;
TimeSpan ts_localclock = local - teststart;
TimeSpan duration = rtc - teststart;
Debug.Print("***********************************************************");
Debug.Print("Test Duration: " + duration.ToString());
Debug.Print("Onboard RTC Time: " + rtc.ToString());
Debug.Print("Local Clock Time: " + local.ToString());
Debug.Print("Difference Local Clock - Onboard RTC: " + onboardrtc_localclock.ToString());
Debug.Print("Difference Local Clock - Test Start: " + ts_localclock.ToString());
Debug.Print("Difference Test Start - Onboard RTC: " + ts_onboardrtc.ToString());
Debug.Print("***********************************************************");
}
catch(Exception e)
{
Debug.Print("Error has occured " + e.Message);
}
t.Start();
}
}
Even if RTC is off, it would be really impossible to be that much off. Ater4 all this is called a real time clock
Can you do this the easy way and use a simple while loop where you read the clock every one second and print to the output? And then compare that to a stopwatch on your phone? After one minute and after one hour?
After 1 minute of running
DateTime = 01:00
RTC = 00:58
After 1 hour of running
DateTime = 01:01:24
RTC = 00:59:57
@ Brett
According to the datasheet for the processor(SAM9x35) the chip has an internal slow clock oscillator which is on by default and I wanted to be sure that I was using the external oscillator that seems to be on the board.
RCEN: Internal 32 kHz RC Oscillator
0: 32 kHz RC oscillator is disabled.
1: 32 kHz RC oscillator is enabled.
OSC32EN: 32768 Hz Oscillator
0: 32768 Hz oscillator is disabled.
1: 32768 Hz oscillator is enabled.
OSC32BYP: 32768Hz Oscillator Bypass
0: 32768 Hz oscillator is not bypassed.
1: 32768 Hz oscillator is bypassed, accept an external slow clock on XIN32.