|
| 1 | +/* |
| 2 | + Displaying the TIM TP timing information for the _next_ TP time pulse |
| 3 | + (PVT provides the time of the _previous_ pulse) |
| 4 | + By: Paul Clark |
| 5 | + SparkFun Electronics |
| 6 | + Date: March 24th, 2023 |
| 7 | + License: MIT. See license file for more information. |
| 8 | +
|
| 9 | + This example shows how to query a u-blox module for the TIM TP time-pulse-of-week. |
| 10 | + This contains the timing information for the _next_ time pulse. I.e. it is output |
| 11 | + _ahead_ of time. PVT contains the time of the _previous_ pulse. |
| 12 | +
|
| 13 | + Feel like supporting open source hardware? |
| 14 | + Buy a board from SparkFun! |
| 15 | + SparkFun GPS-RTK2 - ZED-F9P (GPS-15136) https://www.sparkfun.com/products/15136 |
| 16 | + SparkFun GPS-RTK-SMA - ZED-F9P (GPS-16481) https://www.sparkfun.com/products/16481 |
| 17 | + SparkFun MAX-M10S Breakout (GPS-18037) https://www.sparkfun.com/products/18037 |
| 18 | + SparkFun ZED-F9K Breakout (GPS-18719) https://www.sparkfun.com/products/18719 |
| 19 | + SparkFun ZED-F9R Breakout (GPS-16344) https://www.sparkfun.com/products/16344 |
| 20 | +
|
| 21 | + Hardware Connections: |
| 22 | + Plug a Qwiic cable into the GNSS and a BlackBoard |
| 23 | + If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) |
| 24 | + Open the serial monitor at 115200 baud to see the output |
| 25 | +*/ |
| 26 | + |
| 27 | +#include <Wire.h> //Needed for I2C to GNSS |
| 28 | + |
| 29 | +#include <SparkFun_u-blox_GNSS_v3.h> //http://librarymanager/All#SparkFun_u-blox_GNSS_v3 |
| 30 | +SFE_UBLOX_GNSS myGNSS; |
| 31 | + |
| 32 | +void setup() |
| 33 | +{ |
| 34 | + delay(1000); |
| 35 | + |
| 36 | + Serial.begin(115200); |
| 37 | + Serial.println("SparkFun u-blox Example"); |
| 38 | + |
| 39 | + Wire.begin(); |
| 40 | + |
| 41 | + while (myGNSS.begin() == false) //Connect to the u-blox module using Wire port |
| 42 | + { |
| 43 | + Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring.")); |
| 44 | + } |
| 45 | + |
| 46 | + myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) |
| 47 | +} |
| 48 | + |
| 49 | +void loop() |
| 50 | +{ |
| 51 | +/* |
| 52 | + // Read the time pulse of week and construct the microseconds |
| 53 | + if (myGNSS.getTIMTP()) //getTIMTP will return true if new fresh data is received |
| 54 | + { |
| 55 | + uint16_t week = myGNSS.getTIMTPweek(); //Get the time base week number |
| 56 | + uint32_t towMS = myGNSS.getTIMTPtowMS(); //Get the time base pulse-of-week (ms) |
| 57 | + uint32_t towSubMS = myGNSS.getTIMTPtowSubMS(); //Read the sub-millisecond data (ms * 2^-32) |
| 58 | +
|
| 59 | + double tow = towMS; |
| 60 | + tow /= 1000.0; //Convert to seconds |
| 61 | +
|
| 62 | + double subMS = towSubMS; |
| 63 | + subMS *= pow(2.0, -32.0); //Convert to ms |
| 64 | + subMS /= 1000.0; //Convert to seconds |
| 65 | +
|
| 66 | + tow += subMS; //Construct the time of week |
| 67 | + |
| 68 | + Serial.print("TIM TP: week: "); |
| 69 | + Serial.print(week); //Print the time base week number |
| 70 | + Serial.print(" tow: "); |
| 71 | + Serial.println(tow, 6); //Print the time of week with six deimal places (i.e. show the microseconds) |
| 72 | + } |
| 73 | +*/ |
| 74 | + |
| 75 | + //getTIMTP and getPVT will return true if fresh data is available. |
| 76 | + //Note: both methods poll data from the GNSS: |
| 77 | + // getTIMTP will poll TIM TP, wait and return true when the TIM TP data arrives. |
| 78 | + // Then getPVT will poll NAV PVT, wait and return true when the NAV PVT data arrives. |
| 79 | + // The TIM TP data will then be one second old. |
| 80 | + // Because TIM TP provides the time of the _next_ time pulse and NAV PVT provides |
| 81 | + // the time of the _previous_ time pulse, the two Epochs should be the same! |
| 82 | + if (myGNSS.getTIMTP() && myGNSS.getPVT()) |
| 83 | + { |
| 84 | + // Read the time pulse of week as Unix Epoch |
| 85 | + // CAUTION! Assumes the time base is UTC and the week number is GPS |
| 86 | + uint32_t microsTP; |
| 87 | + uint32_t epochTP = myGNSS.getTIMTPAsEpoch(microsTP); //Read the next time pulse of week as Unix Epoch |
| 88 | + |
| 89 | + Serial.print("TIM TP as Epoch: "); |
| 90 | + Serial.print(epochTP); //Print the time of the next pulse |
| 91 | + Serial.print("."); |
| 92 | + if (microsTP < 100000) Serial.print("0"); //Pad the zeros if needed |
| 93 | + if (microsTP < 10000) Serial.print("0"); |
| 94 | + if (microsTP < 1000) Serial.print("0"); |
| 95 | + if (microsTP < 100) Serial.print("0"); |
| 96 | + if (microsTP < 10) Serial.print("0"); |
| 97 | + Serial.println(microsTP); |
| 98 | + |
| 99 | + // Read the PVT time of week as Unix Epoch |
| 100 | + uint32_t microsPVT; |
| 101 | + uint32_t epochPVT = myGNSS.getUnixEpoch(microsPVT); //Read the time of week as Unix Epoch |
| 102 | + |
| 103 | + Serial.print("NAV PVT as Epoch: "); |
| 104 | + Serial.print(epochPVT); //Print the time of the next pulse |
| 105 | + Serial.print("."); |
| 106 | + if (microsPVT < 100000) Serial.print("0"); //Pad the zeros if needed |
| 107 | + if (microsPVT < 10000) Serial.print("0"); |
| 108 | + if (microsPVT < 1000) Serial.print("0"); |
| 109 | + if (microsPVT < 100) Serial.print("0"); |
| 110 | + if (microsPVT < 10) Serial.print("0"); |
| 111 | + Serial.println(microsPVT); |
| 112 | + |
| 113 | + Serial.println(); |
| 114 | + } |
| 115 | +} |
0 commit comments