Skip to content

Commit 34f15c2

Browse files
committed
Adding support for Time Pulse Parameters
1 parent e3e9b83 commit 34f15c2

File tree

4 files changed

+200
-0
lines changed

4 files changed

+200
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
Time Pulse Parameters
3+
By: Paul Clark (PaulZC)
4+
Date: January 13th, 2021
5+
6+
License: MIT. See license file for more information but you can
7+
basically do whatever you want with this code.
8+
9+
This example shows how to change the time pulse parameters and configure the TIMEPULSE (PPS)
10+
pin to produce a 1kHz squarewave
11+
12+
Feel like supporting open source hardware?
13+
Buy a board from SparkFun!
14+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
15+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
16+
SAM-M8Q: https://www.sparkfun.com/products/15106
17+
18+
Hardware Connections:
19+
Plug a Qwiic cable into the GNSS and a BlackBoard
20+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
21+
Open the serial monitor at 115200 baud to see the output
22+
*/
23+
24+
#include <Wire.h> //Needed for I2C to GNSS
25+
26+
#include "SparkFun_u-blox_GNSS_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS
27+
SFE_UBLOX_GNSS myGNSS;
28+
29+
void setup()
30+
{
31+
Serial.begin(115200);
32+
while (!Serial)
33+
; //Wait for user to open terminal
34+
Serial.println(F("SparkFun u-blox Example"));
35+
36+
Wire.begin();
37+
38+
//myGNSS.enableDebugging(); // Uncomment this line to enable debug messages
39+
40+
if (myGNSS.begin() == false) //Connect to the u-blox module using Wire port
41+
{
42+
Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing."));
43+
while (1)
44+
;
45+
}
46+
47+
myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
48+
49+
// Create storage for the time pulse parameters
50+
UBX_CFG_TP5_data_t timePulseParameters;
51+
52+
// Get the time pulse parameters
53+
if (myGNSS.getTimePulseParameters(&timePulseParameters) == false)
54+
{
55+
Serial.println(F("getTimePulseParameters failed! Freezing..."));
56+
while (1) ; // Do nothing more
57+
}
58+
59+
timePulseParameters.tpIdx = 0; // Select the TIMEPULSE pin
60+
//timePulseParameters.tpIdx = 1; // Or we could select the TIMEPULSE2 pin instead, if the module has one
61+
62+
// We can configure the time pulse pin to produce a defined frequency or period
63+
// Here is how to set the frequency:
64+
timePulseParameters.freqPeriod = 1000; // Set the frequency/period to 1000Hz
65+
timePulseParameters.pulseLenRatio = 0x80000000; // Set the pulse ratio to 2^31 * 2^-32 to produce 50:50 mark:space
66+
67+
timePulseParameters.flags.bits.active = 1; // Make sure the active flag is set to enable the time pulse. (Set to 0 to disable.)
68+
timePulseParameters.flags.bits.isFreq = 1; // Tell the module that we want to set the frequency (not the period)
69+
timePulseParameters.flags.bits.isLength = 0; // Tell the module that pulseLenRatio is a ratio / duty cycle (2^-32) - not a length (in us)
70+
timePulseParameters.flags.bits.polarity = 0; // Tell the module that we want the falling edge at the top of second. (Set to 1 for rising edge.)
71+
72+
// Now set the time pulse parameters
73+
if (myGNSS.setTimePulseParameters(&timePulseParameters) == false)
74+
{
75+
Serial.println(F("setTimePulseParameters failed!"));
76+
}
77+
else
78+
{
79+
Serial.println(F("Success!"));
80+
}
81+
}
82+
83+
void loop()
84+
{
85+
// Nothing to do here
86+
}

src/SparkFun_u-blox_GNSS_Arduino_Library.cpp

+75
Original file line numberDiff line numberDiff line change
@@ -4252,6 +4252,81 @@ boolean SFE_UBLOX_GNSS::resetIMUalignment(uint16_t maxWait)
42524252
return (sendCommand(&packetCfg, maxWait, true) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
42534253
}
42544254

4255+
//Get the time pulse parameters using UBX_CFG_TP5
4256+
boolean SFE_UBLOX_GNSS::getTimePulseParameters(UBX_CFG_TP5_data_t *data, uint16_t maxWait)
4257+
{
4258+
if (data == NULL) // Check if the user forgot to include the data pointer
4259+
return (false); // Bail
4260+
4261+
packetCfg.cls = UBX_CLASS_CFG;
4262+
packetCfg.id = UBX_CFG_TP5;
4263+
packetCfg.len = 0;
4264+
packetCfg.startingSpot = 0;
4265+
4266+
if (sendCommand(&packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK
4267+
return (false);
4268+
4269+
// Extract the data
4270+
data->tpIdx = extractByte(&packetCfg, 0);
4271+
data->version = extractByte(&packetCfg, 1);
4272+
data->antCableDelay = extractSignedInt(&packetCfg, 4);
4273+
data->rfGroupDelay = extractSignedInt(&packetCfg, 6);
4274+
data->freqPeriod = extractLong(&packetCfg, 8);
4275+
data->freqPeriodLock = extractLong(&packetCfg, 12);
4276+
data->pulseLenRatio = extractLong(&packetCfg, 16);
4277+
data->pulseLenRatioLock = extractLong(&packetCfg, 20);
4278+
data->userConfigDelay = extractSignedLong(&packetCfg, 24);
4279+
data->flags.all = extractLong(&packetCfg, 28);
4280+
4281+
return(true);
4282+
}
4283+
4284+
//Set the time pulse parameters using UBX_CFG_TP5
4285+
boolean SFE_UBLOX_GNSS::setTimePulseParameters(UBX_CFG_TP5_data_t *data, uint16_t maxWait)
4286+
{
4287+
if (data == NULL) // Check if the user forgot to include the data pointer
4288+
return (false); // Bail
4289+
4290+
packetCfg.cls = UBX_CLASS_CFG;
4291+
packetCfg.id = UBX_CFG_TP5;
4292+
packetCfg.len = UBX_CFG_TP5_LEN;
4293+
packetCfg.startingSpot = 0;
4294+
4295+
// Insert the data
4296+
payloadCfg[0] = data->tpIdx;
4297+
payloadCfg[1] = data->version;
4298+
payloadCfg[4] = data->antCableDelay & 0xFF; // Little Endian
4299+
payloadCfg[5] = data->antCableDelay >> 8;
4300+
payloadCfg[6] = data->rfGroupDelay & 0xFF; // Little Endian
4301+
payloadCfg[7] = data->rfGroupDelay >> 8;
4302+
payloadCfg[8] = data->freqPeriod & 0xFF; // Little Endian
4303+
payloadCfg[9] = (data->freqPeriod >> 8) & 0xFF;
4304+
payloadCfg[10] = (data->freqPeriod >> 16) & 0xFF;
4305+
payloadCfg[11] = (data->freqPeriod >> 24) & 0xFF;
4306+
payloadCfg[12] = data->freqPeriodLock & 0xFF; // Little Endian
4307+
payloadCfg[13] = (data->freqPeriodLock >> 8) & 0xFF;
4308+
payloadCfg[14] = (data->freqPeriodLock >> 16) & 0xFF;
4309+
payloadCfg[15] = (data->freqPeriodLock >> 24) & 0xFF;
4310+
payloadCfg[16] = data->pulseLenRatio & 0xFF; // Little Endian
4311+
payloadCfg[17] = (data->pulseLenRatio >> 8) & 0xFF;
4312+
payloadCfg[18] = (data->pulseLenRatio >> 16) & 0xFF;
4313+
payloadCfg[19] = (data->pulseLenRatio >> 24) & 0xFF;
4314+
payloadCfg[20] = data->pulseLenRatioLock & 0xFF; // Little Endian
4315+
payloadCfg[21] = (data->pulseLenRatioLock >> 8) & 0xFF;
4316+
payloadCfg[22] = (data->pulseLenRatioLock >> 16) & 0xFF;
4317+
payloadCfg[23] = (data->pulseLenRatioLock >> 24) & 0xFF;
4318+
payloadCfg[24] = data->userConfigDelay & 0xFF; // Little Endian
4319+
payloadCfg[25] = (data->userConfigDelay >> 8) & 0xFF;
4320+
payloadCfg[26] = (data->userConfigDelay >> 16) & 0xFF;
4321+
payloadCfg[27] = (data->userConfigDelay >> 24) & 0xFF;
4322+
payloadCfg[28] = data->flags.all & 0xFF; // Little Endian
4323+
payloadCfg[29] = (data->flags.all >> 8) & 0xFF;
4324+
payloadCfg[30] = (data->flags.all >> 16) & 0xFF;
4325+
payloadCfg[31] = (data->flags.all >> 24) & 0xFF;
4326+
4327+
return (sendCommand(&packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
4328+
}
4329+
42554330
// CONFIGURATION INTERFACE (protocol v27 and above)
42564331

42574332
//Form 32-bit key from group/id/size

src/SparkFun_u-blox_GNSS_Arduino_Library.h

+4
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,10 @@ class SFE_UBLOX_GNSS
645645
//Reset ESF automatic IMU-mount alignment
646646
boolean resetIMUalignment(uint16_t maxWait = defaultMaxWait);
647647

648+
//Configure Time Pulse Parameters
649+
boolean getTimePulseParameters(UBX_CFG_TP5_data_t *data = NULL, uint16_t maxWait = defaultMaxWait); // Get the time pulse parameters using UBX_CFG_TP5
650+
boolean setTimePulseParameters(UBX_CFG_TP5_data_t *data = NULL, uint16_t maxWait = defaultMaxWait); // Set the time pulse parameters using UBX_CFG_TP5
651+
648652
//General configuration (used only on protocol v27 and higher - ie, ZED-F9P)
649653

650654
//It is probably safe to assume that users of the ZED-F9P will be using I2C / Qwiic.

src/u-blox_structs.h

+35
Original file line numberDiff line numberDiff line change
@@ -1789,4 +1789,39 @@ typedef struct
17891789
UBX_HNR_INS_data_t *callbackData;
17901790
} UBX_HNR_INS_t;
17911791

1792+
// UBX-CFG-TP5 (0x06 0x31): Time pulse parameters
1793+
const uint16_t UBX_CFG_TP5_LEN = 32;
1794+
1795+
typedef struct
1796+
{
1797+
uint8_t tpIdx; // Time pulse selection (0 = TIMEPULSE, 1 = TIMEPULSE2)
1798+
uint8_t version; // Message version (0x01 for this version)
1799+
uint8_t reserved1[2];
1800+
int16_t antCableDelay; // Antenna cable delay: ns
1801+
int16_t rfGroupDelay; // RF group delay: ns
1802+
uint32_t freqPeriod; // Frequency or period time, depending on setting of bit 'isFreq': Hz_or_us
1803+
uint32_t freqPeriodLock; // Frequency or period time when locked to GNSS time, only used if 'lockedOtherSet' is set: Hz_or_us
1804+
uint32_t pulseLenRatio; // Pulse length or duty cycle, depending on 'isLength': us_or_2^-32
1805+
uint32_t pulseLenRatioLock; // Pulse length or duty cycle when locked to GNSS time, only used if 'lockedOtherSet' is set: us_or_2^-32
1806+
int32_t userConfigDelay; // User-configurable time pulse delay: ns
1807+
union
1808+
{
1809+
uint32_t all;
1810+
struct
1811+
{
1812+
uint32_t active : 1; // If set enable time pulse; if pin assigned to another function, other function takes precedence.
1813+
uint32_t lockGnssFreq : 1; // If set, synchronize time pulse to GNSS as soon as GNSS time is valid. If not set, or before GNSS time is valid, use local clock.
1814+
uint32_t lockedOtherSet : 1; // If set the receiver switches between the timepulse settings given by 'freqPeriodLocked' & 'pulseLenLocked' and those given by 'freqPeriod' & 'pulseLen'.
1815+
uint32_t isFreq : 1; // If set 'freqPeriodLock' and 'freqPeriod' are interpreted as frequency, otherwise interpreted as period.
1816+
uint32_t isLength : 1; // If set 'pulseLenRatioLock' and 'pulseLenRatio' interpreted as pulse length, otherwise interpreted as duty cycle.
1817+
uint32_t alignToTow : 1; // Align pulse to top of second (period time must be integer fraction of 1s). Also set 'lockGnssFreq' to use this feature.
1818+
uint32_t polarity : 1; // Pulse polarity: 0: falling edge at top of second; 1: rising edge at top of second
1819+
uint32_t gridUtcGnss : 4; // Timegrid to use: 0: UTC; 1: GPS; 2: GLONASS; 3: BeiDou; 4: Galileo
1820+
uint32_t syncMode : 3; // Sync Manager lock mode to use:
1821+
// 0: switch to 'freqPeriodLock' and 'pulseLenRatioLock' as soon as Sync Manager has an accurate time, never switch back to 'freqPeriod' and 'pulseLenRatio'
1822+
// 1: switch to 'freqPeriodLock' and 'pulseLenRatioLock' as soon as Sync Manager has an accurate time, and switch back to 'freqPeriod' and 'pulseLenRatio' as soon as time gets inaccurate
1823+
} bits;
1824+
} flags;
1825+
} UBX_CFG_TP5_data_t;
1826+
17921827
#endif

0 commit comments

Comments
 (0)