« Close

Datasheets and User Guides

App Notes

Software & Driver

 

19.0 RTC (T7-Pro only)

The T7-Pro has a battery-backed RTC (real-time clock) which is useful for assigning timestamps to data that is stored on the microSD card during scripting operations. Particularly in situations where the device could experience power failure or other reboots, and does not have a communication connection that can be used to determine real-time after reboot. The system time is stored in seconds since 1970, also known as the Epoch and Unix timestamp.

Remarks

As of this writing, the T7-Pro ships with a 2GB SD card, RTC, and battery/battery-holder installed.  The T7 has none of these, but does have the socket installed to hold a microSD card.

The T7-Pro RTC can be read a few different ways. Read the system time in seconds with address 61500, or get a simple calendar time representation by reading six consecutive addresses, starting with address 61510. Change the system time by writing a new timestamp (in seconds) to address 61504. To time events faster than 1 second apart, it is possible to read the CORE_TIMER, address 61520, and see how it changes from second to second. To access the core timer value in Lua scripts, use the LJ.Tick() function.

Register Listing

RTC Registers
Name Start Address Type Access
RTC_TIME_S 61500 UINT32 R
RTC_SET_TIME_S 61504 UINT32 W
RTC_SET_TIME_SNTP 61506 UINT32 W
RTC_TIME_CALENDAR 61510 UINT16 R
SNTP_UPDATE_INTERVAL 49702 UINT32 R/W
RTC_TIME_S
- Address: 61500
Read the current time in seconds since Jan, 1970, aka Epoch or Unix time. This value is calculated from the 80 MHz crystal, not the RTC 32 kHz crystal. Non-pro devices do not have a real time clock, so the reported time is either seconds since device startup or the time reported by the network time protocol over Ethernet. Pro devices have a real time clock that will be used to initialize this register at startup, the time can then be updated by NTP.
  • Data type: UINT32  (type index = 1)
  • Read-only
  • T7:
  • T4:
RTC_SET_TIME_S
- Address: 61504
Write a new timestamp to the RTC in seconds since Jan, 1970, aka Epoch or Unix timestamp.
  • Data type: UINT32  (type index = 1)
  • Write-only
  • T7:
  • T4:
RTC_SET_TIME_SNTP
- Address: 61506
Write any value to instruct the T7 to update its clock from a SNTP server. Requires that SNTP_UPDATE_INTERVAL is non-zero.
  • Data type: UINT32  (type index = 1)
  • Write-only
  • T7:
  • T4:
RTC_TIME_CALENDAR
- Address: 61510
Read six consecutive addresses of type UINT16, starting with this address. The result will be in year, month, day, hour, minute, second calendar format. i.e. [2014, 10, 21, 18, 55, 35]
  • Data type: UINT16  (type index = 0)
  • Read-only
  • T7:
  • T4:
SNTP_UPDATE_INTERVAL
- Address: 49702
Sets the SNTP retry time in seconds. A value of zero will disable SNTP(0=default). Values must be 10 or greater.
  • Data type: UINT32  (type index = 1)
  • Readable and writable
  • T7:
  • T4:

Examples

[Lua] Read the value of the RTC in a Lua script

table = {}
table[1] = 0    --year
table[2] = 0    --month
table[3] = 0    --day
table[4] = 0    --hour
table[5] = 0    --minute
table[6] = 0    --second

table, error = MB.RA(61510, 0, 6)
print(string.format("%04d/%02d/%02d %02d:%02d.%02d", table[1], table[2], table[3], table[4], table[5], table[6]))

>> 2014/10/15 18:55.22

[C/C++] Read the value of the RTC in C/C++

int LJMError;
double newValue;
LJMError = LJM_eReadAddress(handle, 61500, 1, &newValue);
printf(newValue);
//returned value of 1413398998 would correspond with Wed, 15 Oct 2014 18:49:58 GMT

4 comments

Hi everyone,

I'm having troubles using the RTC. It seems that the register RTC_TIME_S does not keep it's value or is enable to change it when I send something in RTC_SET_TIME_S.


Here's what I do :

LJM_eWriteName(handle, "RTC_SET_TIME_S", 1424350455.00);

usleep(40000);

LJM_eReadName(handle, "RTC_TIME_S", &res);

settimeofday(res);


Sometimes the value turns to 0 or the first line is enable to change it. When I tried Kipling, I was able to change it only when I sent a higher value.

Even in Kipling I couldn't reset it to 0. Is there a special way to deal with it ?

I'm working on a raspberry pi (OS : Raspbian)

Thank you !

 

There was a firmware bug causing an incorrect offset to be added to the year value. First introduced in 1.0133 and fixed in 1.0151.

ezDAQ's picture

Greetings,

Accuracy information? like 5 seconds per day.

LabJack Support's picture

The RTC is ±20ppm or ~2 seconds per day.