I used to be not too long ago engaged on an experiment for a brand new design and was utilizing a perform generator. Though new perform turbines have fairly good frequency tolerance specs, I wanted one thing with extra accuracy and precision. The way in which to get extra accuracy in frequency turbines, arbitrary waveform turbines, and frequency counters is to make use of the ten MHz reference enter offered on many of those check devices. Not having such a reference, and having been not too long ago taking part in with the Arduino Nano, I made a decision it might be attention-grabbing to see if one may very well be constructed across the Nano.
Determine 1 exhibits the primary elements of this straightforward and cheap, “no calibration required” design. The frequency is generated by a ten MHz voltage-controlled crystal oscillator (VCXO). This oscillator generates a frequency round 10 MHz with cheap tolerance but additionally has a frequency alter pin that enables for an adjustment up or down. The trick to getting a extra exact and correct 10 MHz sign is to search out the best adjustment for the VCXO and to readjust it because the VCXO drifts as a consequence of varied components. Let’s check out the best way to perform this.
Determine 1 The primary elements of a easy frequency generator with no calibration required.
A GPS module can ship a really correct 1 pulse-per-second sign (1PPS). This pulse seems to be like a ~100 ms pulse each second. Even in cheap modules, this sign is usually correct within the vary of some tens of nanoseconds. That is the design’s exterior reference for the era of an correct 10 MHz sign. The 1PPS sign is linked to the Arduino Nano at an I/O line able to producing an interrupt. The design additionally has a 32-bit counter that may be learn and reset by the Nano. The 32-bit counter is linked to the output of the VCXO, so it counts the variety of VCXO cycles since its final reset. The final main piece is to that is how we alter the VCXO.
The Nano doesn’t have a DAC however because it seems, one of many easy capabilities of the Nano is controlling its pulse-width modulation (PWM) strains that are meant for use as an adjustable DC output voltage (after filtering). A easy set of calls will output a 5V PWM sign at a hard and fast frequency. The PWMs have an 8-bit adjustment vary, so if you would like a 2.5V output, you’ll set the PWM to 128 (50% responsibility cycle). (Be aware, for this set of calls, the Nano makes use of a frequency of round 500 Hz, though that is solely vital to the filter design.) So, the primary thought is to make use of a PWM output from the Nano, filter it to get a comparatively ripple free DC degree, and apply this to the VCXO’s alter pin. This is able to work, however the challenge is that we might solely have 255 discrete ranges that it may very well be set to which will not be sufficient. Let’s take a deeper have a look at this.
The VCXO I selected for the challenge is a Taitien TSEAACSANF-10.000000. It has an preliminary frequency tolerance of two ppm and a most adjustment vary, known as “pull vary”, of roughly ±12 ppm utilizing 0.5 to 2.5 volts on the alter pin. So, if we used the total 255 steps of the PWM, we might be capable of alter the VCXO with a decision of about (2*12/255 ≈ 0.1 ppm). This didn’t appear to be a lot of an enchancment in ppm accuracy, so I got here up with the concept of utilizing two PWMs: one for coarse alter and one for positive alter. To maintain the design easy, I opted to make use of resistors solely and no op amps. This portion of the circuit could be seen in Determine 2 (there are additionally 2 filter caps proven which we are going to focus on later).
Determine 2 Course and positive adjustment to the PWM strains which can be meant for use as an adjustable DC output voltage.
Basically what you see is an averaging circuit with 2 kΩ of resistance within the coarse portion of the circuit and 270 kΩ within the positive portion. The ultimate 2 kΩ resistor is used to divide the voltage down because the adjustment pin, as a reminder, this takes 2.5V max. The VCXO adjustment voltage could also be solved simply utilizing superposition and is roughly equal to Equation 1.
VCXO adjustment voltage = 9.76×10-3 x PWMCOARSE + 144×10-6 x PWMFINE (Eq. 1)
The place PWMCOARSE and PWMFINE can vary in worth from 0 to 255. This circuit is typically known as a passive averaging circuit, as described by Millman’s theorem. Now, making the output voltage to the VCXO alter pin monotonic utilizing each PWMs is impractical because the precision of the resistors would have to be very excessive. That is solved by selecting resistor values that enable for a positive PWM adjustment to regulate with a spread overlapping the next coarse vary.
Let me give an instance: the resistor values proven in Determine 2 enable for the coarse PWM sign to maneuver about 9.8 mV with every step. The positive PWM sign strikes about 0.14 mV per step or roughly 36 mV over its full vary. Subsequently, for the reason that positive adjustment vary is bigger than the coarse adjustment step measurement, there’s at all times loads of overlap.
Determine 3 exhibits a few the coarse ranges and the way the positive worth overlaps are configured. Within the later dialogue of the adjustment algorithm, I’ll clarify how this overlap is used. (Be aware, the 2 100uF caps in Determine 2 had the values chosen to maintain the ripple from the PWM waveform under the 0.14 mV positive step measurement. To assist within the filtering, the code will increase the PWM frequency to roughly 31 kHz.)
Determine 3 Diagram illustrating positive adjustment vary and coarse adjustment step measurement overlaps.
Placing all this collectively, the operation goes one thing like this: after power-up, the Arduino Nano units the coarse and positive PWMs to an preliminary worth (someplace within the center), after which waits till it senses the 1PPS sign coming in from the GPS module. Then, on the interrupt of the following 1PPS sign, the Nano resets the 32-bit counter. The counter then begins counting the cycles from the VCXO. Upon receiving the next 1PPS interrupt, the Nano captures and reads the 32-bit counter, which needs to be a rely of 10,000,000. If the rely is lower than 10,000,000, it adjusts the positive PWM worth up. If the positive PWM worth is at 255 earlier than adjustment, the coarse PWM worth is incremented and the positive PWM worth is ready to 127 (within the center). If the rely is larger than 10,000,000, it adjusts the positive PWM worth down. If the positive PWM worth is at 0 earlier than adjustment, the coarse PWM worth is decremented and the positive PWM worth is ready to 127 (within the center). You possibly can see that the overlap of the positive changes with a couple of coarse worth makes this algorithm secure from trying to find an applicable worth, albeit considerably inefficient when it comes to search pace.
That is really the primary stage of adjustment. If we solely measured one second of counts, we couldn’t get greater than 0.1 ppm accuracy. So, the second stage of code permits the 32-bit counter to build up for 10 seconds by ready till it has seen 10 interrupts. Now the rely can go as much as 100,000,000 and we are able to alter to rise up to the 0.01 ppm vary (or 10 ppb). These first two levels are used to shut in on the goal 10 MHz a bit quicker. A 3rd, and steady working stage, counts for 100 seconds, ready for 100 interrupts, earlier than studying the counter. This will get us to an anticipated rely of 1,000,000,000 which permits for an adjustment to 1 ppb. However what can the PWMs really alter to? As said earlier than, the positive PWM strikes by roughly 0.14 mV per step and the VCXO alter by about +/-12 ppm over 0.5 to 2.5 V. Subsequently, every positive step strikes the frequency by round (2*12 ppm*(0.14mv/2.0V) ) ≈ 0.0017 ppm or, 1.7 ppb. So, it seems we’ve sufficient adjustment to get about ±1 ppb. There may be extra to this as could be seen within the code, however that is the essence of the hunt for a exact and correct 10 MHz. (It needs to be famous at this level, the Arduino Nano really has a 16 bit PWM however the most frequency is so low that the required filter would have a really lengthy settling time; too lengthy for this utility.)
As for efficiency, the Nano outputs varied statistics on the LCD and I usually have a imply frequency of 10,000,000.00, a imply error of 0.01 Hz, and a typical deviation of this imply of 0.1 ppb. So, it holds the frequency shut to some elements per billion. That is about two orders of magnitude higher than my perform generator can obtain with an exterior reference.
Now turning to the schematic. The PWM averaging circuit could be seen feeding the adjustment voltage to the VCXO (which is the one system powered by the three.3V supply of the Nano). The circuit after the VCXO is used to sq. up the clipped sine wave of the VCXO output. This squared up, and buffered, sign is the ten MHz sq. wave going not solely to the counter however, to the exterior BNC connectors. Two of the BNC connectors provide a TTL sign. One other is configured with 2 inverter gates and a 33Ω resistor to create a roughly 50Ω output. A fourth BNC connector provides a buffered 1PPS sign to be used by exterior units.
Beneath the Nano is the GPS module. These could be discovered on the internet for round $10 to $12 for the module and antenna. The PCB is proven in Determine 4 and Determine 5.
Determine 4 PCB of GPS disciplined 10 MHz supply.
Determine 5 Picture of GPS disciplined oscillator PCB linked in package deal.
In the midst of the schematic is the 32-bit counter (Determine 1). This 74LV8154 (~$1) really has two 16-bit counters that may be configured to a 32-bit counter. The counter design permits for studying the 32 bits of counter in 4 particular person bytes by addressing the bytes. This requires 4 handle strains and I ran brief on I/O on the Nano so a 74LS139 is used to translate 2 strains from the Nano into the 4 strains wanted on the counter.
The LCD proven in Determine 6 is a typical I2C, 20 character by 4 line LCD. On the backside of the schematic is an easy linear energy provide utilizing a 12V AC/DC adapter and regulating to 8V to energy the Nano and 5V for varied elements of the circuitry. I used a linear provide to guarantee a quiet Vcc airplane. Lastly, there are 2 LEDs. One inexperienced LED shows the 1PPS sign. A second, bi-color LED that’s inexperienced when the system has locked tightly to the specified 10 MHz, crimson if not locked but, and alternating crimson/inexperienced if the system is in holdover. Holdover is a state through which present settings are maintained throughout lack of the 1PPS sign. To detect lack of the 1PPS sign, I enlisted the watchdog timer (WDT). As a substitute of utilizing the WDT to detect dangerous executing code points, I set the WDT timeout to 2 seconds and pet (reset) it contained in the 1PPS interrupt routine. If the system doesn’t get a 1PPS interrupt, the WDT isn’t petted.
Determine 6 Accomplished GPS disciplined oscillator in package deal with LCD.
The code for the Nano was written in C utilizing the Arduino IDE. The code is basically pushed by the 1PPS interrupt which shortly responds by locking within the 32-bit counter worth (a perform of the 74LV8154), clearing the counter, and setting a reset flag. You will have found out that we’re lacking some a part of the following rely as a result of we’re capturing the counter register after which clearing it, permitting it to begin counting from 0 once more. (There may be some finite time between the seize and the clear.) That is true, so the firmware compensates for this latency by including an offset worth to the uncooked counter worth. It turns on the market are 16 lacking counts. This has been verified two methods: first, by measuring the time between the seize register sign and the clear register sign on an oscilloscope. Second, I ran a variety of exams with out adjusting the VCXO, utilizing 1 second and 100 second captures which have been adjusted by a latency offset worth. The 1 second captures have been repeated 100 occasions and added up. If the latency offset is right, the summed up 1 second values (which now include 100 latency offsets), ought to equal the 100 second captured studying (which comprises 1 latency offset). Within the working code, the lacking 16 rely is added again in on each learn of the counter.
The primary loop within the code (the Arduino growth system at all times runs the traditional C “Essential” as a loop) waits for an interrupt flag to be set and when set, it reads the worth of the locked in registers of the 74LV8154. Subsequent, it checks to see if it’s a “cheap” studying and never corrupted (differing from 10 MHz by greater than 12 ppm). Whether it is dangerous it’s tossed. Whether it is good, it processes the worth in a small boxcar averager. This common is then used to regulate the PWM’s up or down as described above. It then decides what stage it’s in. The primary stage runs 1 second counts and adjusts the VCXO. This shortly will get us within the ballpark for PWM settings. This stage runs for 20 seconds. The second stage takes 10 second readings of the rely to fine-tune the PWM settings. That is set to run for five passes or, 50 seconds. The final stage runs 100 second readings and is run repeatedly thereafter, making continuous changes to carry the frequency as temperature or different parameters change the frequency.
Within the final stage, LEDs are set as wanted and statistics are taken after every studying. These statistics could be seen on the LCD and a number of pages (Determine 7) are viewable utilizing the circuit’s pushbutton which is debounced in the primary loop. Statistics embody instantaneous frequency, common frequency, present ppb error, ppb common error, ppb error commonplace deviation, variety of good readings, variety of dangerous readings, time of steady lock, max frequency seen, minimal frequency seen, and PWM coarse and positive settings.
Determine 7 Statistics on LCD taken after every studying.
Full challenge data for this may be discovered at, the open-source website: https: https://www.thingiverse.com/factor:5188330 (or you’ll be able to search thingiverse.com for “DamianB2”).
Venture data consists of full KiCad challenge with schematic, PCB, and PCBA BOM. Additionally included is a full meeting BOM, Arduino supply code, 3D print information for the enclosure, hyperlink to 3D print information for the GPS module enclosure, art work for the nameplates, varied notes, and so on.
A final thought: a few of you might have seen that, whereas designing the GPS disciplined oscillator (GPSDO), we’ve inadvertently created the essence of a reasonably good frequency counter. We’ll examine this within the subsequent installment.
Damian Bonicatto is an skilled hands-on design engineer with intensive background in analysis, growth, design, implementation and testing of modern {hardware} and firmware throughout a number of industries.
Associated Content material