In my earlier design thought, a design for a easy GPS disciplined oscillator (GPSDO) 10 MHz reference was offered. A observe on the finish of that article describes the conclusion {that a} frequency counter may very well be derived by easy adjustments to the circuit. This text follows up by presenting a easy circuit for a frequency counter derived from the GPSDO schematic.
As proven in Determine 1, we reuse a lot of the earlier design together with the facility provide, Arduino Nano, 32-bit counter, LCD, and LEDs. Nonetheless, we take away the VCXO circuitry. We add a second pushbutton, enter sign conditioning, and create totally different outputs. Many elements of the software program will even be saved or barely modified.
Determine 1 Fundamental block diagram of the GPS enabled frequency counter.
Determine 2 exhibits the detailed design of the frequency counter. Evaluating this schematic to the earlier GPSDO schematic, you’ll be able to see the adjustments. Together with the removing of the VCXO circuitry, you will notice that the 74LS139 has been eliminated. The frequency counter design freed up some I/O ports so I didn’t want so as to add an expander to deal with the counter (74LV8154).
Determine 2 Schematic of the frequency counter.
You’ll additionally discover the addition of an analog conditioning circuit feeding the enter of the counter. To maintain the design easy, solely a Schmitt set off inverter, a cap, and a few resistors are used. This can be a well-known circuit courting not less than again to the 1975 Fairchild software observe 140. The circuit makes use of 2 resistors (R6 and R7) to bias the Schmitt set off inverter to its center-point (this works as a result of the enter is AC coupled by way of C17). Biasing to the center-point positions means the enter sign facilities on the Schmitt set off’s hysteresis. This provides the enter sign most sensitivity. The capacitor and resistors are chosen to permit alerts from a little bit over 10 mHz to 80 MHz to cross to the Schmitt inverter. The 80 MHz max was recognized attributable to some preliminary testing of the circuit. The restrict is imposed by the 74LV8154 counter as this seems to be its most counting fee (the datasheet is considerably unclear on this quantity). The ten mHz minimal is due a design choice to have a most gate time of 100 seconds. With a gate time of 100 seconds, the minimal of 1 rely will happen if the enter sign has a frequency of 1/100, or 10 mHz. (Gate occasions 1 second and 10 seconds are additionally accessible by way of the “Gate Time” pushbutton.)
The GPSDO used a push button and was learn by an ADC on the Arduino Nano (Determine 3). This frequency counter design makes use of 2 pushbuttons which are related to analog comparators to learn their states.
Determine 3 Accomplished frequency counter in 3D printed enclosure with LCD.
So, after the sign is squared up by way of the Schmitt set off, the squared-up sign is shipped to the 32-bit counter. To measure the frequency of this sign, the Arduino Nano waits for an interrupt from the 1 pulse-per-second (1PPS) sign from the GPS module (~$10). Even an affordable GPS module can ship a really correct 1PPS sign. This pulse appears like a ~100 ms pulse each second. After receiving this interrupt, the code alerts the 74LV8154 to clear the counter. The code then waits for the following 1PPS interrupt and, when acquired, the Nano alerts the counter to latch the present rely into its on-chip register after which clears the counter. The code now reads within the latched-in register information. This can be a description of a 1 second gate time operation, so the register worth is the frequency of the enter sign. If a ten second or a 100 second gate time is chosen, through the use of the “Gate Time” pushbutton, the code waits for 10 or 100 1PPS interrupts earlier than latching within the rely. The rely is then scaled by 10 or 100 to get the frequency.
Extra on the firmware; the 2 initiatives are literally fairly comparable and share a number of code. We nonetheless drive the LCD and LEDs, monitor lack of the 1PPS sign by way of a 2 second watchdog timer (WDT), rely pulses and, upon a 1PPS interrupt, learn the register within the 74LV8154, and so forth. One massive change is that we not want to regulate PWMs as they don’t seem to be used on this design. This reduces the complexity of the code and saves RAM.
Because the code for the Nano was derived from the GPSDO code, it’s once more written in C utilizing the Arduino IDE. The frequency counter code is principally pushed by the 1PPS interrupt. When a 1PPS interrupt happens, the interrupt service routine responds by locking within the 32-bit counter, clearing the counter, and setting a reset flag. The piece of code that locks within the present rely onto an onboard register within the 74LC8154 after which clears the rely to zero, takes some finite time between locking in and clearing. This implies we miss some counts. I discuss with this time because the latency. The firmware compensates for this latency by including an offset worth to the uncooked counter worth. It turns on the market 16 lacking counts. (The earlier GPSDO article explains how the 16 rely latency offset was verified.) Within the working code, the lacking 16 rely is added again in on each learn of the counter.
Let’s check out efficiency. First, Determine 4 exhibits the minimal sign versus frequency.
Determine 4 Graph of the minimal sign versus frequency.
The minimal is usually lower than 1 Vpp besides at frequencies under 1 Hz the place the sine wave minimal climbs. The utmost enter voltage is 5 Vpp. As for precision, it sometimes reads frequency with a typical deviation 0.01 Hz (with 100 second gate time). Determine 5 exhibits the LCD pages for 100 second gate time with 10 MHz enter sign.
Determine 5 Statistics on LCD with 100 second gate time with 10 MHz enter sign.
On the GPSDO venture, there was a web page exhibiting a histogram of the readings. This labored for that venture because the frequency and the vary of the frequency was identified a priori, whereas on this frequency counter venture there isn’t any data on the frequency or the vary of frequencies to show. Provided that, the quantity of RAM to retailer earlier readings wanted is restricted, in order that function was eliminated.
(A observe on customary deviation: engineers oftentimes assume customary deviation implies a traditional distribution. That’s not true. An ordinary deviation calculation doesn’t assume any specific distribution. On this specific case, the deviation I sometimes see is a distribution skewed to at least one aspect—not a traditional distribution.)
To keep away from struggling the wrath of my previous physics 101 professor, care was taken to show information utilizing mathematically right vital digits. Freq, 1/f (interval), Fmean, and Fstd conform (principally) with customary mathematical guidelines for vital digits as based mostly on the measured frequency and gate time. For instance, after taking 100 readings, Fmean will show an extra digit after the decimal place. There’s an exception to the conformity of serious digits. That’s, the 1/f (interval) displayed when measuring low frequencies…beneath 10 Hz. An instance of the exception: when utilizing an enter sign of 6 Hz and a 1 second gate time, the interval (1/f) will show 167 ms and never 100 ms as dictated by the foundations for vital digits. This seems like it might be much less complicated to the consumer.
Vigilant readers might have noticed a seemingly inconsistent design concern. I beforehand acknowledged that there are gate occasions of 1, 10, and 100 seconds. I additionally acknowledged the design is able to studying as much as 80 MHz utilizing the 32-bit counter. So, what occurs once we take a studying of an 80 MHz sign utilizing a gate time of 100 seconds? The counter ought to learn 8,000,000,000 after 100 seconds however we’re utilizing a 32-bit counter. A 32-bit counter will solely rely as much as 4,294,967,295 (232-1). To beat this concern, the code will get a counter studying (with out resetting the counter) snapshot at 50 seconds and saves this because the intermediate studying. Then, when the ultimate counter studying is taken at 100 seconds, it’s in comparison with the intermediate studying. If the ultimate studying is smaller than the intermediate studying, we all know there was a rollover within the counter. On this case, the code will add 232 to the intermediate studying to get a real counter studying. This technique provides us probably the most accuracy as we don’t must take 50 second readings and add them collectively, thereby avoiding a counter clear operation and a second offset correction.
All-in-all this frequency counter performs fairly nicely, is straightforward, requires no calibration, provides good details about the related sign, and suits properly on my bench.
Full venture data for this may be discovered at, the open-source web site: https://www.thingiverse.com/factor:5180568 (or you’ll be able to search thingiverse.com for “DamianB2”).
Challenge data consists of full KiCad venture with schematic, PCB, and PCBA BOM. Additionally included is a full meeting BOM, Arduino supply code, 3D print recordsdata for the enclosure, hyperlink to 3D print recordsdata for the GPS module enclosure, art work for the nameplates, varied notes, and so forth.
Damian Bonicatto is a consulting engineer with a long time of expertise in embedded {hardware}, firmware and system design. He holds 30 patents.
Phoenix Bonicatto is a contract author.
Associated Content material