Skip to content

Commit fd54852

Browse files
committed
Tested with the emulator
1 parent cd07cc5 commit fd54852

File tree

8 files changed

+107
-444
lines changed

8 files changed

+107
-444
lines changed

examples/Example01_AlternateAddress/Example01_AlternateAddress.ino

+4-8
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,20 @@ void setup()
3131
Wire.begin(); // Begin the I2C bus
3232

3333
bool begun;
34-
begun = myOCXO.begin(Wire, 0x50); // Initialize the STP3593LF - using a custom bus and address
35-
begun = myOCXO.begin(0x50); // This is also possible. It defaults to Wire
36-
begun = myOCXO.begin(); // This is also possible. It defaults to Wire and address 0x50
34+
begun = myOCXO.begin(Wire, 0x70); // Initialize the STP3593LF - using a custom bus and address
35+
begun = myOCXO.begin(0x70); // This is also possible. It defaults to Wire
36+
begun = myOCXO.begin(); // This is also possible. It defaults to Wire and address 0x70
3737

3838
if (!begun)
3939
{
4040
Serial.println("STP3593LF not detected! Please check the address and try again...");
4141
while (1); // Do nothing more
4242
}
4343

44-
// Read the frequency control word - should be zero initially
44+
// Read the frequency control word - should be ~500000 initially?
4545
int64_t fcw = myOCXO.getFrequencyControlWord();
4646
Serial.print("The frequency control word is: ");
4747
Serial.println(fcw);
48-
49-
// Read the available (clipped) pull range
50-
double pullAvailable = myOCXO.getMaxPullAvailable();
51-
Serial.printf("Maximum frequency pull is: %e\r\n", pullAvailable);
5248
}
5349

5450
void loop()

examples/Example04_setFrequencyByBiasMillis/Example04_setFrequencyByBiasMillis.ino renamed to examples/Example02_setFrequencyByBiasMillis/Example02_setFrequencyByBiasMillis.ino

+9-31
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,17 @@
1010
SparkFun code, firmware, and software is released under the MIT License.
1111
Please see LICENSE.md for further details.
1212
13-
Consider the STP3593LFAI-KYG33IV-10.000000:
14-
The operating temperature range is Industrial, -40 to 85°C (option "I").
15-
LVCMOS output (option "-").
16-
Frequency stability +/-1ppb (option "Y").
17-
It is DCOCXO with a configurable I2C address (option "G").
18-
Supply voltage 3.3V (option "33").
19-
Pin 1 is Output Enable (option "I"). (No software OE control).
20-
The pull range limit is 3.125ppm (option "V").
21-
Base frequency is 10.000000MHz.
22-
2313
Consider this example:
24-
* The OCXO frequency has not yet been changed. It is running at the default 10.000000 MHz.
25-
* 10.000000 MHZ is the library default base frequency. But we could set it with setBaseFrequencyHz(10000000.0)
26-
* The available pull range is read during begin.
2714
* The mosaic-T manual states that the oscillator frequency should be changed by no more than 3ppb per second.
2815
* We tell the library this using setMaxFrequencyChangePPB(3.0)
2916
* The GNSS RxClkBias reports that receiver time is ahead of system time by 200 nanoseconds (+200ns).
3017
* We instruct the library to change the frequency using setFrequencyByBiasMillis(200.0e-6)
31-
* The OCXO clock period is 100ns.
18+
* The OCXO clock period is ~100ns.
3219
* The 200ns bias corresponds to 2 clock cycles.
33-
* To remove that bias in one second, the oscillator frequency would need to be reduced to 9.999998 MHz.
20+
* To remove that bias in one second, the oscillator frequency would need to be reduced to 9999998 Hz.
3421
* That is a change of 2 parts in 10000000, or 0.2ppm, or 200ppb.
3522
* The frequency change will be limited to 3ppb.
36-
* Since the STP3593LF maximum Pull Range is 800ppm, and the Pull Register is 39-bit signed, 3ppb corresponds to 1030792 LSB.
37-
* The firmware writes the value -1030792 to the Frequency Control Register, reducing the frequency to 9.99999997 MHz.
38-
* getFrequencyHz will return 9999999.97
23+
* Since the resolution of the frequency control word is 8E-13, the frequency control word should decrease by 3750
3924
4025
*/
4126

@@ -64,31 +49,24 @@ void setup()
6449
while (1); // Do nothing more
6550
}
6651

67-
myOCXO.setBaseFrequencyHz(10000000.0); // Pass the oscillator base frequency into the driver
68-
69-
Serial.print("Base frequency set to ");
70-
Serial.print(myOCXO.getBaseFrequencyHz());
71-
Serial.println(" Hz");
72-
7352
myOCXO.setMaxFrequencyChangePPB(3.0); // Set the maximum frequency change in PPB
7453

7554
Serial.print("Maximum frequency change set to ");
7655
Serial.print(myOCXO.getMaxFrequencyChangePPB());
7756
Serial.println(" PPB");
7857

79-
Serial.print("Frequency control word should be 0. It is ");
80-
Serial.println(myOCXO.getFrequencyControlWord());
58+
uint32_t controlWord = myOCXO.getFrequencyControlWord();
59+
Serial.print("Frequency control word is currently ");
60+
Serial.println(controlWord);
8161

8262
Serial.println("Applying a clock bias of +200ns");
8363
// Set the frequency by clock bias (+200ns, +200e-6ms)
8464
// For this test, set the P term to 1.0 and the I term to 0.0
8565
myOCXO.setFrequencyByBiasMillis(200.0e-6, 1.0, 0.0);
8666

87-
Serial.print("Frequency should be 9999999.97 Hz. It is ");
88-
Serial.print(myOCXO.getFrequencyHz());
89-
Serial.println(" Hz");
90-
91-
Serial.print("Frequency control word should be -1030792. It is ");
67+
Serial.print("Frequency control word should be ");
68+
Serial.print(controlWord - 3750); // See notes above
69+
Serial.print(". It is ");
9270
Serial.println(myOCXO.getFrequencyControlWord());
9371
}
9472

examples/Example02_setFrequencyHz/Example02_setFrequencyHz.ino

-57
This file was deleted.

examples/Example03_IllegalFrequency/Example03_IllegalFrequency.ino

-73
This file was deleted.

examples/STP3593LF_Emulator/STP3593LF_Emulator.ino

+18-34
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,31 @@
99
1010
Note: This code doesn't update the registerAddress correctly - on ESP32 (3.0.1).
1111
registerAddress is only updated _after_ the registers have been read...
12-
SfeSTP3593LFDriver::begin() calls readClipRegister() and readRegisters()
13-
twice, to ensure registerAddress points at 0x00 and 0x0C correctly.
1412
1513
*/
1614

1715
#include <Wire.h>
1816

19-
#define I2C_DEV_ADDR 0x50
17+
#define I2C_DEV_ADDR 0x70
2018

21-
// Emulate registers 0x00 (DCXO Clip) to 0x0E (DCXO LSW) (16-bit, MSB first)
22-
#define CLIP 0x00 // Change to (e.g.) 0x08 to emulate 200ppm clip range.
23-
#define NUM_REG_BYTES (15*2)
24-
volatile uint8_t registerBytes[NUM_REG_BYTES];
19+
// Emulate a single 32-bit register for reading and writing
20+
// Although, in reality, data is read from 0x41 and written to 0xA0
21+
#define NUM_REG_BYTES (4)
22+
volatile uint8_t registerBytes[NUM_REG_BYTES] = { 0x00, 0x07, 0xA1, 0x20 }; // Default to 500000 (MSB first)
2523
volatile uint8_t registerAddress = 0;
2624

2725
// On Request:
28-
// Write bytes from registerBytes, starting at registerAddress * 2
26+
// Write bytes from registerBytes
2927
void requestHandler()
3028
{
31-
int i = registerAddress * 2;
32-
for (; i < NUM_REG_BYTES; i++)
29+
// Ignore registerAddress
30+
for (int i = 0; i < NUM_REG_BYTES; i++)
3331
Wire.write(registerBytes[i]);
3432
}
3533

3634
// On Receive:
3735
// Copy the first incoming byte into registerAddress (see notes above)
38-
// Copy the remaining bytes into registerBytes, starting at registerAddress * 2
36+
// Copy the remaining bytes into registerBytes
3937
void receiveHandler(int len)
4038
{
4139
int count = -1;
@@ -48,8 +46,9 @@ void receiveHandler(int len)
4846
registerAddress = b;
4947
break;
5048
default:
51-
if (((registerAddress * 2) + count) < NUM_REG_BYTES)
52-
registerBytes[((registerAddress * 2) + count)] = b;
49+
// Ignore registerAddress
50+
if (count < NUM_REG_BYTES)
51+
registerBytes[count] = b;
5352
break;
5453
}
5554
count++;
@@ -58,11 +57,6 @@ void receiveHandler(int len)
5857

5958
void setup()
6059
{
61-
// Initialize the register bytes
62-
for (int i = 0; i < NUM_REG_BYTES; i++)
63-
registerBytes[i] = 0;
64-
registerBytes[0] = CLIP; // Store in OCXO Clip MSB
65-
6660
delay(1000); // Allow time for the microcontroller to start up
6761

6862
Serial.begin(115200); // Begin the Serial console
@@ -85,23 +79,13 @@ void loop()
8579
{
8680
lastPrint = millis();
8781

88-
// Extract the 39-bit Frequency Control Word
89-
uint64_t freqControl = ((uint64_t)registerBytes[28]) >> 1;
90-
freqControl |= ((uint64_t)registerBytes[27]) << 7;
91-
freqControl |= ((uint64_t)registerBytes[26]) << 15;
92-
freqControl |= ((uint64_t)registerBytes[25]) << 23;
93-
freqControl |= ((uint64_t)registerBytes[24]) << 31;
94-
if (freqControl & 0x0000004000000000) // Correct two's complement
95-
freqControl |= 0xFFFFFFC000000000;
82+
// Extract the Frequency Control Word
83+
uint32_t freqControl = ((uint32_t)registerBytes[0]) << 24;
84+
freqControl |= ((uint32_t)registerBytes[1]) << 16;
85+
freqControl |= ((uint32_t)registerBytes[2]) << 8;
86+
freqControl |= ((uint32_t)registerBytes[3]) << 0;
9687

97-
union // Avoid any ambiguity when converting uint64_t to int64_t
98-
{
99-
uint64_t unsigned64;
100-
int64_t signed64;
101-
} unsignedSigned64;
102-
unsignedSigned64.unsigned64 = freqControl;
103-
10488
Serial.print("Frequency control is ");
105-
Serial.println(unsignedSigned64.signed64);
89+
Serial.println(freqControl);
10690
}
10791
}

keywords.txt

+2-6
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,15 @@ SfeSTP3593LFArdI2C KEYWORD1
1313
#######################################
1414

1515
begin KEYWORD2
16-
readClipRegister KEYWORD2
17-
readRegisters KEYWORD2
16+
readFrequencyControlWord KEYWORD2
1817
getFrequencyControlWord KEYWORD2
1918
setFrequencyControlWord KEYWORD2
20-
getPullRangeClip KEYWORD2
21-
getMaxPullRange KEYWORD2
2219
getBaseFrequencyHz KEYWORD2
2320
setBaseFrequencyHz KEYWORD2
24-
getFrequencyHz KEYWORD2
25-
setFrequencyHz KEYWORD2
2621
getMaxFrequencyChangePPB KEYWORD2
2722
setMaxFrequencyChangePPB KEYWORD2
2823
setFrequencyByBiasMillis KEYWORD2
24+
saveFrequencyControlValue KEYWORD2
2925

3026
#######################################
3127
# Constants (LITERAL1)

0 commit comments

Comments
 (0)