GPS (Synchronize Clock with a GPS Device)

The GPS instruction is used to keep the datalogger clock synchronized with a GPS device.

Syntax

GPS (GPSArray, ComPort, TimeOffset, MaxTimeDiff, NMEAStrings)

Remarks

This instruction is used along with a GPS device to set the datalogger's clock. This instruction will also provide information such as location (latitude/longitude) and speed, and store NMEA sentences from the GPS device.

The resolution of accuracy for the clock set is 10 microseconds. The clock set relies on information from the GPRMC sentence. If this sentence is not returned a clock set will not occur.

If the datalogger is programmed to use the PPS signal for synchronization, the only ComPort that can be used is COMU1 (the hardware does not support a PPS signal on other ports). The datalogger sets its clock approximately 200 microseconds behind the GPS clock (as indicated by the PPS signal). This means that the first measurement in the main scan will start about 300 microseconds behind GPS time. Synchronization of measurements between dataloggers of the same speed will be typically +/- 10 microseconds.

Some GPS devices do not have a PPS output or output only a 3 V signal on the PPS line input. GPS devices with 3 V signals or no PPS signal can be used to sync the datalogger clock by negating the COM port parameter. This causes time to be sync’d using only the data contained in the NMEA sentences. Keep in mind, however, that this type of time syncing does not have the accuracy and precision that can be obtained when using the PPS line, since there can be some delay in the reception and parsing of the NMEA sentences.

By default, the instruction expects the GPS unit to be set up at 38400 baud, outputting the GPRMC and GPGGA sentences once per second. The datalogger expects the start of the second to coincide with the rising edge of the PPS signal. If there is no PPS signal or if the required sentences come out at less than once per second the datalogger will not update its clock. The datalogger will wait on 10 good responses from the GPS before using the data stream.

GPS units with lower baud rates can be used with the GPS instruction but the baud rate has to be set for the relevant COM port it is to be connected to either in the datalogger settings or by including a SetStatus command after the BeginProg instruction in the program.

Baud rates below 2400 bps will not work as the GPS unit will not be able to transmit the two GPS sentences once per second reliably. Similar problems can be encountered even at higher baud rates if too many optional GPS strings are selected to be output.

Parameters

GPSArray (GPS Array)

The variable in which to store the information returned by the GPS. Fifteen values are returned. If this array is not dimensioned to 15, values will be stored to fill the array and no error will be returned. If no values are available, NAN will be returned. The values in this array are updated only when the GPS instruction is executed.

NOTE: Beginning with operating system 9, the GPSArray may be declared as type Double to support higher-precision latitude and longitude.

The following values are returned by the GPS:

  • Array(1): Latitude, degrees
  • Array(2): Latitude, minutes
  • Array(3): Longitude, degrees
  • Array(4): Longitude, minutes
  • Array(5): Speed over ground, knots
  • Array(6): Course over ground, degrees
  • Array(7): Magnetic variation (positive = East, negative = West)
  • Array(8): Fix Quality (0 = invalid, 1 = GPS, 2 = differential GPS, 6 = estimated)
  • Array(9): Number of Satellites
  • Array(10): Altitude, meters
  • Array(11): Time into the current second (in microseconds) when the PPS low to high transition occurred. Once the clock is set a fixed value of 990000 will be returned.
  • Array(12): Time since the datalogger last saw a valid GPRMC sentence, timed at the instant the GPS instruction runs. Typically this value will be about one second. If this value is seen to be consistently above one second and/or increasing this indicates the GPS unit has lost sight of enough satellites to give a good output or the GPS unit is disconnected or powered off.
  • Array(13): GPSReady. Indicates whether the datalogger has seen a number of good GPRMC strings, all received within a reasonable time of the PPS signal. A value of ten indicates 10 good responses have been received. Only when the counter is at ten will the datalogger use the GPS time to set the datalogger clock. If a GPRMC string comes out in the wrong time frame or if it is invalid in any way, the GPS Ready value is reset to zero.
  • Array(14): Maximum time adjustment since the datalogger program started, milliseconds (10 msec resolution). Can be set to 0 manually or under program control.
  • Array(15): Number of times clock has been changed since the datalogger program started. This can be set to 0 manually or under program control.

Data from other NMEA sentences can be stored in a numeric format. For each sentence data is stored in the array as follows:

  1. The number of values in the sentence.
  2. A simple checksum of the characters in the sentence's name, not counting the '$'. This is the sum of the 8 bit ASCII codes.
  3. The comma separated values in the sentence. If the field is non-numeric, a similar numeric checksum for the variable string as in (2) is stored. For a single character field this will be its ASCII value. If the field is vacant; i.e., back to back commas, ClosedNAN Not a number. A data word indicating a measurement or processing error. Voltage overrange, SDI-12 sensor error, and undefined mathematical results can produce NAN. is stored.

Steps 1..3 are repeated for as many different sentences that are seen by the datalogger. The GPSArray must be dimensioned large enough to store all the variables for all the sentences you need to store. The order in which the data is stored for the different NMEA sentences follows the rules for the ordering of the NMEA strings.

These values are stored in the GPS array when the GPS instruction runs, without risk of corruption caused by new data coming in when the instruction runs.

Type: Variable

ComPort (Communication Port)

The ComPort parameter is the control port pair to which the GPS device is attached. Rx is used to read in the NMEA sentences and Tx is used to monitor the PPS from the GPS. COMU1 is the only Comport that supports a PPS signal. Negate the ComPort parameter to program the datalogger to use NMEA sentences for time-syncing rather than the PPS line input (see Remarks above). Valid options are:

  • COMU1 U1/U2 (only comport that supports PPS signal)
  • -COMU1 to -COMU11 (negated comport for NMEA sentences time-syncing)
  • -COMC1 to -COMC3 (negated comport for NMEA sentences time-syncing)
  • -COMRS232 (negated comport for NMEA sentence time-syncing)

This instruction defaults to a baud rate of 38,400 bps. If the GPS device requires a different baud rate, use the SetStatus instruction in the program to override the default.

Type: Constant

TimeOffset (Time Offset)

The local time offset, in seconds, from UTC. The TimeOffset parameter is ignored if the "UTC Offset" setting in the datalogger is a value other than -1 (disabled). In other words, the UTCOffset setting in the datalogger overrides this instruction parameter. The UTCOffset setting can be found in the Settings table. For more information, see Settings Available Using SetSetting

NOTE: For the GPS() instruction, in order to use GPS coordinates without setting the datalogger clock, set the TimeOffset parameter to -1.

Type: Constant

MaxTimeDiff (Maximum Difference in Time)

The maximum difference in time (in milliseconds) between the datalogger clock and the GPS clock that will be tolerated before the clock is changed. If a negative value is entered, the clock will not be changed.

Type: Constant

NMEAStrings (NMEA Sentences)

The string array that holds the NMEA sentences. If it exists, the GPRMC sentence will reside in NMEAStrings(1), and the GPGGA sentence will reside in NMEAStrings(2). Any other sentences will reside in subsequent indexes into the array (on a first-in basis). Once an index in the array is used to store a particular sentence, that sentence will always be stored in that location when updates to the sentence are received.

The NMEA strings are updated every time a new sentence comes in as a background task, so the strings can be seen to change even if the GPS instruction is called infrequently. These strings are mainly provided for diagnostic purposes as the string can be overwritten by the background task midway through the program code accessing the string. Access to data in the standard or user configured additional messages should be using the GPSArray (see below).

Beyond the GPRMC and GPGGA sentences, you can determine the order the sentences appear in the NMEA strings by initializing the required NMEAstring to the strings “name” at the start of the program; for example NMEAStrings(3)=”$GPVTG”, otherwise the data is written in the order seen after the program starts to run.

Type: Variable Array Declared as a String

Troubleshooting

The datalogger is occasionally skipping records.

This can be caused by the GPS module losing signal and then stopping the transmission of the GPRMC sentences and the pulse per second. When this happens the datalogger will revert to normal clock operation with the inherent drift. If this is suspected, first check the "Seconds since last GPRMC" value in the GPS array, if this is greater than 2 seconds then the GPS unit is not sending GPS sentences back to the datalogger, indicating a possible hardware or reception problem. If this time appears OK but the GPS Ready value does not reach the value of 10 then the datalogger thinks the timing of the GPRMC sentences is too variable. Check that you have not configured too many output sentences from the GPS unit.