# GPS accurate to microseconds

Hi everyone,

I'm doing a project for school where I need to calculate the phase difference between two sine waves. I am using a zero cross detector as an input to an Arduino to detect the zero crossings. Due to the nature of the project, I would ideally be using GPS to determine when the zero crossings happen. I have come across the TinyGPS library but because I need accuracy in the microseconds I cannot use it as it only goes to 100ths of seconds. Does anyone know of a way to either modify TinyGPS to give microsecond data or another library which already gives microseconds?

Thanks for any help.

I think the 1Hz output from the GPS is what you should be looking at - the text-based NMEA is always going to suffer from unpredictable latencies.

I don't see where GPS data would have anything to do, or be useful, with measuring the phase difference between two sine waves?

retrolefty:
I don't see where GPS data would have anything to do, or be useful, with measuring the phase difference between two sine waves?

Presumably the sine waves are remote from each other?

There is a universal tendency here not to explain the full situation.

Paul__B:

retrolefty:
I don't see where GPS data would have anything to do, or be useful, with measuring the phase difference between two sine waves?

Presumably the sine waves are remote from each other?

There is a universal tendency here not to explain the full situation.

I guess that could be one case. Interested to see if that is the case for this poster?

The GPS is used to put a time stamp on each zero cross. Because both waves are 60Hz, knowing the time difference for when they each cross zero will allow me to calculate the difference in degrees. It is essentially a Phasor Measurement Unit used in power systems.

That's besides the point of this post though. The problem I am having is reading the GPS to a microsecond accuracy. The GPS receiver I have is accurate to 1us itself so i'm assuming it is possible.

spkeeper20:
The GPS is used to put a time stamp on each zero cross. Because both waves are 60Hz, knowing the time difference for when they each cross zero will allow me to calculate the difference in degrees. It is essentially a Phasor Measurement Unit used in power systems.

That's besides the point of this post though. The problem I am having is reading the GPS to a microsecond accuracy. The GPS receiver I have is accurate to 1us itself so i'm assuming it is possible.

Still seems over complex. Why can't you just measure the time between the two zero crossings, timing it with say the micros(); function?

Lefty

Still seems over complex. Why can't you just measure the time between the two zero crossings, timing it with say the micros(); function?

[/quote]

In industry they use GPS so that's the way my professor wants me to implement it unfortunately.

spkeeper20:
Still seems over complex. Why can't you just measure the time between the two zero crossings, timing it with say the micros(); function?

In industry they use GPS so that's the way my professor wants me to implement it unfortunately.
[/quote]

In what industry? Phase measurements are made all the time without GPS. Not saying you can't use the GPS as a triggering element to start a measurement, but it doesn't add any advantage as the accuracy of the measurement will be the function of time base accuracy being used to time the difference between the GPS signal and a zero crossing.

retrolefty:

spkeeper20:
Still seems over complex. Why can't you just measure the time between the two zero crossings, timing it with say the micros(); function?

In industry they use GPS so that's the way my professor wants me to implement it unfortunately.

In what industry? Phase measurements are made all the time without GPS. Not saying you can't use the GPS as a triggering element to start a measurement, but it doesn't add any advantage as the accuracy of the measurement will be the function of time base accuracy being used to time the difference between the GPS signal and a zero crossing.
[/quote]

Power systems and SMART grid technology. GPS gives a standard time source so multiple devices can be synced to the same clock.

Power systems and SMART grid technology. GPS gives a standard time source so multiple devices can be synced to the same clock.

Those are two totally different tasks are they not?

1. A means to synchronize real time clocks for remote networked devices.
2. Measurement of phase difference between two 60Hz signals.

Lefty

spkeeper20:
Hi everyone,

I'm doing a project for school where I need to calculate the phase difference between two sine waves. I am using a zero cross detector as an input to an Arduino to detect the zero crossings. Due to the nature of the project, I would ideally be using GPS to determine when the zero crossings happen.

That's fine if you mean use local real time measurements to determine the phase difference, and then use a GPS-derived timestamp to record when the result was collected. Using GPS itself as a clock source for measuring real time intervals with microsecond resolution does not seem sensible.

In industry they use GPS so that's the way my professor wants me to implement it unfortunately.

You are going about it all wrong. GPS modules for consumer use ARE NOT the same as GPS time sources! I think your prof is setting you up to see if you are smart enough to figure that out.

You need a consumer module with 1 second output. Some under \$20 will have this tyied to a blinking LED...
Use this one second pulse to determine the accuracy if your Arduino Xtal in setup() then use the internal timer(s) for your measurements of phase shift. Because you have a measured known frequency from your GPS marker pulse, you can skew (adjust) any small time differences between the two time sources.

Ray

You need a consumer module with 1 second output. Some under \$20 will have this tyied to a blinking LED...
Use this one second pulse to determine the accuracy if your Arduino Xtal in setup() then use the internal timer(s) for your measurements of phase shift. Because you have a measured known frequency from your GPS marker pulse, you can skew (adjust) any small time differences between the two time sources.

So your saying to make sure the Arduino clock is synced to the 1 pulse per second on the GPS and then use the Arduino clock to time stamp each zero crossing?

I appreciate all of this help about how to go about it, but is there no way to just read the time given by the GPS into microseconds?

but is there no way to just read the time given by the GPS into microseconds?

Consider that the GPS is sending at 9600 BAUD.
How can you possibly receive a character-base stream, parse it, and set variables in a microsecond?

The microsecond stamp is to timestamp the serial data, Lat/Lon/etc., for calculation purposes - not for time base use. The satellites do not send the raw data in the format the GPS puts out, it is the GPS module that creates the sentence structure filling in the metadata and data from internal registers in the module.

In a perfect world, that 1 second pulse edge could be able to phase-lock the quartz clock, but from a software project, my belief is just run a few thousand averages of the timing pulse against the internal clock in the setup() section. You may wish to include a push-button to force execution of the comparison if you are in an environment where the temperature is changing.

Ray

Its not usually possible to phase lock the crystal oscillator in a Micro with an external referance, because theres no provision
to electronically alter the frequency of the oscillator.
You could however use an external VCXO something like this
http://www.maximintegrated.com/app-notes/index.mvp/id/2097
to provide an external clock input to the Arduino and use the Arduino as a software PLL to control
the VCXO, using a PWM output into a low pass filter, which is fed to the tuning input of the VCXO.
The only tricky part is getting the damping factor right, so that the VCXO doesnt hunt.

Well, my surmise was correct.

This is about comparing phase in geographically distant locations - i.e., different substations.

Two related questions for the OP ...

How many microseconds does it take for the GPS signal to get from the satellite to your receiver?
How many microseconds difference is there between the signals from the nearest and farthest satellite?

And just out of curiosity (for anyone who knows) am I right to think phase differences place restrictions on the design of long distance electricity networks?. I suspect you couldn't have a direct AC link from Florida to New York and another indirect AC link from Florida to New York via Denver?

...R

AC power transmission?
Pah!
Old-school - Edison's revenge!

If the two stations are remote you can use the GPS units to get a time stamp accurate to the accuracy of the system clock as the two recievers will get their pulse per second (PPS) within 10's of nanoseconds. One way to sync the two units up is to use the PPS line (make sure the GPS unit you are using has a PPS available) to drive an interrupt on both Arduinos.

When the PPS interrupt gets triggered you immediately set the system clock to 0 and record the time stamp from the GPS. Then when you get an interrupt from the zero-crossing detector immediately store the value of the system clock. When you broadcast the data packet to the central station you send both the time stamp from when the PPS signal was received and the value of the system clock. It is a good idea to send the timestamp from when the PPS was received in case you missed a PPS signal.

Now think about the "required" microsecond timing accuracy when you are measuring the time difference between 60 Hz signals, I think you are a little overkill. Whether you need micro or millisecond resolution you still need a way to synch the remote clocks and the PPS from a GPS seems more than adequate for your application.