Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


Synchronise Labjack and PC clock

  • Please log in to reply
1 reply to this topic

#1 Lucas Pereira

Lucas Pereira
  • Members
  • 8 posts

Posted 12 June 2013 - 04:15 AM

Hi, I'm here again with another question regarding clocks. I am now using two systems to measure energy consumption, one of them is a commercial solution and is using the system clock (i.e. the times in the readings from this solution are in synch with the system time). The other is a labjack U6 scanning 50Hz current and voltage at 8 kHz and I am calculating the time based on the number of samples (pretty much, every 8000 samples I add a new second to my clock). So, my first attempt was using the SleepMode and wait until I get the 8000 samples for each channel, however I noticed that just after a couple of ours, 5 hours or so, my clock was 1 second ahead of the system clock (although the started with the same value). After careful inspection I believe that the only reason for this is that sometimes the laback gets the 8000 samples in less than one second, thus after a while my application clock advances faster. Because of this I made a second attempt, this time using No Wait mode and putting the thread to sleep 1000 milliseconds before reading the next buffer, still, I have the same problem... because the labjack clock is faster than the system clock and sometimes after 1000 milliseconds I get more than the expected 8000 samples. Note: I have also tried to drop to samples above 8000, but this lead my system having a considerable delay compared to the system clock. My question is, what is the best option for this? I know from a previous post (https://forums.labja...?showtopic=6171) that the labjack clock is pretty accurate, +/- 30us per second, and now I was thinking that I could use the sleep mode and at the same time consider the number of milliseconds gone since the scan started. I would then put the thread to sleep by the difference between 1000 milliseconds and the milliseconds gone since scan started. Before I implement this, (in Java using the Java UD driver) I wanted to know is this is feasible or if there is a way better way to do this... Thanks in advance Best, Lucas

#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 12 June 2013 - 02:10 PM

Whether you use SLEEP or NONE wait mode to read the data affects the timing and structure of your program, but does not affect the timing of when the U6 collects data. If the U6 is streaming 8 kscans/second, it does so continuously according to its own clock. I assume by system clock you mean the OS time from your PC? So assume the U6 clock is 30 ppm faster than the PC clock. That is 30us faster, so in 5 hours the U6 would be 0.54 seconds ahead of the PC clock. So the fact that you found the U6 to be ~1 second ahead after 5 hours seems reasonable. So if you want to synchronize the U6 data with the PC clock, you need to occasionally skip/delete some scans if the U6 is ahead, or add dummy scans if the U6 is behind. The best way depends on your desired structure for your program. One typical structure is letting the U6 control timing. That is, you define the U6 clock as correct. You would then have a loop that does SLEEP type reads of 8000 scans. Thus the loop would execute once per second as defined by the U6 clock. Another structure is letting the PC control timing. You would then have a loop that does a NONE type read once per second as defined by the PC clock, using some sort of software interval timer to control the loop iteration time (note that you need an interval timer, not just a sleep/pause/delay). Each read would read about 8000 scans, but the exact number would vary due to: - Clock difference between the U6 and the PC. - Data is moved from the U6 to the PC in chunks, not 1 scan at a time.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users