I was trying to follow the documentation on https://labjack.com/support/datasheets/t-series/communication/stream-mode#system-clock for converting STREAM_START_TIME_STAMP to a calendar time and I'm fairly confused it has to say.
I'm trying to setup a triggered stream and correlate the STREAM_START_TIME_STAMP to my system's calendar time. I'm streaming the CORE_TIMER register to try to correlate but it looks like it's overflowing/resetting very quickly and I'm struggling to find a consistent way to make it correlate with my system's start time (especially because I don't know exactly when the stream is triggered).
Are there any good examples of doing this in any language?
Unfortunately, we do not have any programming examples for this. The STREAM_START_TIMESTAMP corresponds to the start time of the first stream scan. The overall timestamp implementation will depend on how you want to handle some aspects like NTP updates and how much drift you can tolerate. The main requirements are as follows:
// If true the core timer rolls. The next value is CoreFreq/ScanRate + lastCoreTimerVal - 232
if (232 - 1 - CoreFreq/ScanRate < lastCoreTimerVal)
With all of that, you synchronize the core timer and adjust CORE_TIMER timestamps based on the value you synchronize. For example, if we are at the start of stream and correlate the CORE_TIMER value of 123456 to local time 8:00:00.00 (h:mm:ss h=hour m=minute s=second) and the STREAM_START_TIMESTAMP reading is 120000, we can say the first scan started 3456 ticks before our system timestamp or 3456/40000000 = 86.4 microseconds before our system timestamp. The first scan timestamp would then be 7:59:59.9999136. If the scanRate is 1000, the second scan should happen about 1000 microseconds later at 8:00:00.0009136, or we could calculate the CORE_TIMER value that it should be (40000000/1000 = 40000, so the CORE_TIMER value should be 120000 + 40000 = 160000). The CORE_TIMER value for each scan should always track according to the stream start timestamp, so in the example you would have CORE_TIMER of 120000, 160000, 200000, 240000, etc. till the value rolls. The rest of the implementation is a matter of when or where you want to synchronize the CORE_TIMER to the system timestamp as given in requirement 3 above. You could just synchronize once at the start of stream, but you would have increasing clock drift the longer you stream.