Skip to content

Commit 5bd7662

Browse files
committed
Invert Pk and Ik if needed
1 parent 157d1de commit 5bd7662

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/SparkFun_SiT5358.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ bool SfeSiT5358Driver::setFrequencyByBiasMillis(double bias, double Pk, double I
275275

276276
double clockInterval_s = 1.0 / freq; // Convert freq to interval in seconds
277277

278+
// bias (RXClkBias, milliseconds) is the error term we are trying to drive to zero
278279
double biasInClocks = bias / 1000.0; // Convert bias from millis to seconds
279280
biasInClocks /= clockInterval_s; // Convert bias to clock cycles
280281

@@ -293,11 +294,17 @@ bool SfeSiT5358Driver::setFrequencyByBiasMillis(double bias, double Pk, double I
293294
biasInClocks = 0.0 - maxChangeInClocks;
294295
}
295296

297+
// If RxClkBias is positive, we need to reduce the oscillator frequency by making
298+
// the frequency control word more negative. Both Pk and Ik must be negative.
299+
if (Pk > 0.0)
300+
(Pk *= -1.0);
301+
if (Ik > 0.0)
302+
(Ik *= -1.0);
296303
double P = biasInClocks * Pk;
297304
double dI = biasInClocks * Ik;
298-
I += dI;
305+
I += dI; // Add the delta to the integral
299306

300-
return setFrequencyHz(P + I);
307+
return setFrequencyHz(P + I); // Set the frequency to proportional plus integral
301308
}
302309

303310
/// @brief Convert the 4-bit pull range into text

src/SparkFun_SiT5358.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,6 @@ class SfeSiT5358Driver
191191
void setMaxFrequencyChangePPB(double ppb);
192192

193193

194-
/// @brief Set the frequency according to the GNSS receiver clock bias in milliseconds
195-
/// @param bias the GNSS RX clock bias in milliseconds
196-
/// @return true if the write is successful
197-
/// Note: the frequency change will be limited by: the pull range capabilities of the device;
198-
/// and the setMaxFrequencyChangePPB. Call getFrequencyHz to read the frequency set.
199-
bool setFrequencyByBiasMillis(double bias);
200-
201-
202194
/// @brief Set the frequency according to the GNSS receiver clock bias in milliseconds
203195
/// @param bias the GNSS RX clock bias in milliseconds
204196
/// @param Pk the Proportional term

0 commit comments

Comments
 (0)