Skip to content

Commit 3ef10f1

Browse files
committed
Update the default P and I terms by TCXO type
1 parent fa48f74 commit 3ef10f1

File tree

8 files changed

+50
-5
lines changed

8 files changed

+50
-5
lines changed

Firmware/GNSSDO_Firmware/Begin.ino

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,15 @@ void beginTCXO(TwoWire *i2cBus)
524524

525525
if (!myTCXO->begin(*i2cBus, SFE_GNSSDO_OSC_STP3593LF))
526526
return;
527+
528+
if (settings.lastSeenTCXO != SFE_GNSSDO_OSC_STP3593LF)
529+
{
530+
// Update the default P and I terms to match a new oscillator
531+
settings.lastSeenTCXO = SFE_GNSSDO_OSC_STP3593LF;
532+
settings.Pk = myTCXO->getDefaultFrequencyByBiasPTerm();
533+
settings.Ik = myTCXO->getDefaultFrequencyByBiasITerm();
534+
recordSystemSettings();
535+
}
527536

528537
systemPrintln("Using STP3593LF OCXO");
529538
}
@@ -534,6 +543,15 @@ void beginTCXO(TwoWire *i2cBus)
534543
if (!myTCXO->begin(*i2cBus, SFE_GNSSDO_OSC_SIT5811))
535544
return;
536545

546+
if (settings.lastSeenTCXO != SFE_GNSSDO_OSC_SIT5811)
547+
{
548+
// Update the default P and I terms to match a new oscillator
549+
settings.lastSeenTCXO = SFE_GNSSDO_OSC_SIT5811;
550+
settings.Pk = myTCXO->getDefaultFrequencyByBiasPTerm();
551+
settings.Ik = myTCXO->getDefaultFrequencyByBiasITerm();
552+
recordSystemSettings();
553+
}
554+
537555
systemPrintln("Using SiT5811 OCXO");
538556
}
539557
else if (presentSIT5358)
@@ -543,6 +561,15 @@ void beginTCXO(TwoWire *i2cBus)
543561
if (!myTCXO->begin(*i2cBus, SFE_GNSSDO_OSC_SIT5358))
544562
return;
545563

564+
if (settings.lastSeenTCXO != SFE_GNSSDO_OSC_SIT5358)
565+
{
566+
// Update the default P and I terms to match a new oscillator
567+
settings.lastSeenTCXO = SFE_GNSSDO_OSC_SIT5358;
568+
settings.Pk = myTCXO->getDefaultFrequencyByBiasPTerm();
569+
settings.Ik = myTCXO->getDefaultFrequencyByBiasITerm();
570+
recordSystemSettings();
571+
}
572+
546573
systemPrintln("Using SiT5358 TCXO");
547574
}
548575
else

Firmware/GNSSDO_Firmware/GNSSDO_TCXO.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class GNSSDO_TCXO
2424

2525
// Save the frequency control word - if supported
2626
virtual bool saveFrequencyControlValue(void);
27+
28+
// Get the default P and I terms - for the default settings
29+
virtual double getDefaultFrequencyByBiasPTerm(void);
30+
virtual double getDefaultFrequencyByBiasITerm(void);
2731
};
2832

2933
#endif // /__SFE_GNSSDO_TCXO__

Firmware/GNSSDO_Firmware/NVM.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ void recordSystemSettingsToFile(File *settingsFile)
9696
settingsFile->printf("%s=%d\r\n", "rxClkBiasLimitCount", settings.rxClkBiasLimitCount);
9797
settingsFile->printf("%s=%0.3e\r\n", "Pk", settings.Pk);
9898
settingsFile->printf("%s=%0.3e\r\n", "Ik", settings.Ik);
99+
settingsFile->printf("%s=%d\r\n", "lastSeenTCXO", settings.lastSeenTCXO);
99100
settingsFile->printf("%s=%d\r\n", "preferNonCompositeGPSBias", settings.preferNonCompositeGPSBias);
100101
settingsFile->printf("%s=%d\r\n", "preferNonCompositeGalileoBias", settings.preferNonCompositeGalileoBias);
101102
settingsFile->printf("%s=%d\r\n", "enableTCPServer", settings.enableTCPServer);
@@ -365,6 +366,8 @@ bool parseLine(char *str, Settings *settings)
365366
settings->Pk = d;
366367
else if (strcmp(settingName, "Ik") == 0)
367368
settings->Ik = d;
369+
else if (strcmp(settingName, "lastSeenTCXO") == 0)
370+
settings->lastSeenTCXO = d;
368371
else if (strcmp(settingName, "preferNonCompositeGPSBias") == 0)
369372
settings->preferNonCompositeGPSBias = d;
370373
else if (strcmp(settingName, "preferNonCompositeGalileoBias") == 0)

Firmware/GNSSDO_Firmware/STP3593LF_OCXO.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class GNSSDO_STP3593LF : GNSSDO_TCXO
2424

2525
// Save the frequency control word - if supported
2626
bool saveFrequencyControlValue(void);
27+
28+
// Get the default P and I terms - for the default settings
29+
double getDefaultFrequencyByBiasPTerm(void) { return (1.0 / 6.25); }
30+
double getDefaultFrequencyByBiasITerm(void) { return ((1.0 / 6.25) / 150.0); }
2731
};
2832

2933
#endif // /__SFE_GNSSDO_STP3593LF_TCXO__

Firmware/GNSSDO_Firmware/STP3593LF_OCXO.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ bool GNSSDO_STP3593LF::begin(TwoWire &wirePort, const uint8_t &address)
1010

1111
// Don't restore the frequency control word with the saved value from settings.
1212
// Assume saveFrequencyControlValue has done its job and that the control word
13-
// has already been restored.
13+
// has already been restored by the OCXO.
1414

1515
return true;
1616
}

Firmware/GNSSDO_Firmware/SiT5358_TCXO.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class GNSSDO_SIT5358 : GNSSDO_TCXO
2424

2525
// Save the frequency control word - if supported
2626
bool saveFrequencyControlValue(void);
27+
28+
// Get the default P and I terms - for the default settings
29+
double getDefaultFrequencyByBiasPTerm(void) { return 0.63; }
30+
double getDefaultFrequencyByBiasITerm(void) { return 0.151; }
2731
};
2832

2933
#endif // /__SFE_GNSSDO_SIT5358_TCXO__

Firmware/GNSSDO_Firmware/SiT5811_OCXO.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class GNSSDO_SIT5811 : GNSSDO_TCXO
2424

2525
// Save the frequency control word - if supported
2626
bool saveFrequencyControlValue(void);
27+
28+
// Get the default P and I terms - for the default settings - TODO
29+
double getDefaultFrequencyByBiasPTerm(void) { return 0.5; }
30+
double getDefaultFrequencyByBiasITerm(void) { return 0.1; }
2731
};
2832

2933
#endif // /__SFE_GNSSDO_SIT5811_TCXO__

Firmware/GNSSDO_Firmware/settings.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,9 @@ typedef struct
284284
double rxClkBiasInitialLimit_ms = 1.0e-3; // Consider the clock bias 'bad' when > this many ms. Default: 1.0us (1.0e-3ms)
285285
double rxClkBiasLockLimit_ms = 10.0e-6; // Consider the clock locked when the bias is <= this many ms. Default: 10.0ns (10.0e-6ms)
286286
int rxClkBiasLimitCount = 3; // Consider the clock locked when the bias is <= rxClkBiasLockLimit_ms for this many successive readings. Default: 3
287-
// The default values for Pk and Ik come from very approximate Ziegler-Nichols tuning of the SiT5358:
288-
// oscillation starts when Pk is ~1.4; with a period of ~5 seconds.
289-
double Pk = 0.63; // PI P term
290-
double Ik = 0.151; // PI I term
287+
double Pk = 0.63; // PI P term (default for the SiT5358 - updated if needed by beginTCXO)
288+
double Ik = 0.151; // PI I term (default for the SiT5358 - updated if needed by beginTCXO)
289+
uint8_t lastSeenTCXO = 0; // Use this to identify a change of oscillator (by its I2C address)
291290
bool preferNonCompositeGPSBias = false; // Prefer non-composite GPS bias - if available. Mutex with preferNonCompositeGalileoBias
292291
bool preferNonCompositeGalileoBias = false; // Prefer non-composite Galileo bias - if available. Mutex with preferNonCompositeGPSBias
293292
bool enableTCPServer = false; // Enable and configure mosaic-T IPS1 for TCP2way for the ESP32 console

0 commit comments

Comments
 (0)