USB Flakey?

Posted on 2012-09-08
Last Modified: 2012-09-14
I have an inexpensive GPS receiver that I am using as a local clock driver for NTPD, the Network Time Protocol (NTP) daemon, running under Windows 7 64-bit.  NTPD is also connected, thru another computer, to 9 stratum 2 NTP servers located on the East Coast, USA.  What NTPD on this computer sees is the smoothed, best reading from the  9 NTP servers, other computers on my local network, and the GPS clock.  If NTPD's output is plotted, it looks like a straight line horizontally across the page +- ~6 milliseconds (ms) around 0 offset, which is the readings from the 9 NTP servers.  Superimposed on this is a sawtooth wave +- ~60 ms, which is the GPS driver output.  The GPS output starts about 60 ms ahead of real time, slowly descends over a little over 24 hours to ~ -60 ms below real time, varies wildly between -60 ms and +60 ms around 0 offset real time for about 2 hours, and finally settles at +60 ms offset to begin the cycle again.  You can see a plot of this data here (!271&authkey=!ABrUBy4aS7e7sME).  This sawtooth pattern continues forever, unless the computer is rebooted, in which case the GPS output restarts at +60 ms offset ahead of real time and continues its descent to -60 ms below 0 offset.  The GPS output is once every 16 seconds; i.e., 1/16 Hz.  The GPS unit sends its signal as a standard NMEA RMC ASCII string via USB to a Prolific USB-to-Serial (RS232) bridge.  The NTPD clock driver -> WAITS <- for the signal (actually the CR/LF pair at the end) at the Windows serial API and records the exact system time received.  In other words, the GPS output appears to be actually being received at the offsets shown in the plot, i.e., in a sawtooth pattern.  The question is, what is the source of the varying GPS signal received times, the USB driver or the GPS clock device?  A trace of the USB output looks like the GPS string is actually being received a few ms later every 16 seconds, but according to the USB specs, that is not possible.  USB in interrupt mode is supposed to be polling the device at exactly the same time every cycle.  The fact that a computer reboot restarts the sawtooth pattern at its apogee, and that a reboot (probably) does not affect the GPS device, seems to point to USB as the culprit.  However, a good GPS NTP clock can cost $1,000 or more; the one I have cost $35.  Does anyone know if USB does schedule its polling in interrupt mode a few ms later every scheduling interval, and then later tries to rectify its error?  Does anyone know how to fix this error, or even approach debugging it?
Question by:CElliott2
    LVL 82

    Accepted Solution

    In another recent question, the asker had to abandon use of a USB-to-Serial (RS232) bridge because he could not get the timing to be predictable.  USB is a packet/network protocol and RS232 is a character protocol.  The USB controller will collect some data, create a packet and send it.  At the receiving end, the data will be sent out the RS232 port presumably without delay.  A lot of people have had trouble with USB-to-Serial (RS232) adapters because they expect the timing to match that of a regular serial port and it doesn't.

    Author Comment

    Thanks for your comments.

    "The USB controller will collect some data, create a packet and send it."

    This is not what is occurring.  The USB device is sending the data at sub-millisecond intervals in packets of 1, or at very most, 2, bytes per packet.  An NMEA RMC ASCII string is, on average, 72 bytes long.  One would think that the GPS device would send the whole string in one packet, but the USB trace I have inidcates only 1 or occasionally 2 bytes are arriving per host polling request.

    That being said, I agree that the problem is probably the USB-to-serial bridge, but writing one's own driver is a lot of learning and work to undertake just on speculaton and guess work.
    LVL 82

    Expert Comment

    by:Dave Baldwin
    Why are you using a USB-to-serial bridge?  Is it the GPS unit that has a serial port on it?  If so, have you tried connecting to it thru a real serial port?

    Writing a USB driver virtually requires the cooperation of the chip manufacturer.  The people who have asked about it here have usually found other ways to achieve their objectives because they couldn't find enough info to do it.

    Author Comment

    "If so, have you tried connecting to it thru a real serial port?"

    Very few new mobos have RS232 ports.  But, yes, I have with an old model GPS device; the drift (sawtooth wave) was not there, but the jitter was about +- 20 ms.

    What I am looking for is a device for less than about $40 that someone can just buy, install the driver, plug in, install NTPD, and have accurate time +- about 10 ms.  The people on the NTP questions mailing list (who are all about time to the nanosecond all the time) would not be content with this, but most mortals and many companies would.  This would not be good enough for the ISPs, backbone networks, and power companies, but neither is NTPD, to hear many people tell it (because of inherent jitter in interrupt response times, etc.).

    Your idea is a good one though, and I will look into it.  Thanks for all your help.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
    Join Greg Farro and Ethan Banks from Packet Pushers ( and Greg Ross from Paessler ( for a discussion about smart network …
    This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.
    This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now