Easy, excessive accuracy/precision/decision frequency counter

0
35


In my earlier design concept, a design for a easy GPS disciplined oscillator (GPSDO) 10 MHz reference was introduced. A observe on the finish of that article describes the belief {that a} frequency counter may very well be derived by easy modifications 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 completely different outputs. Many components of the software program will even be stored or barely modified. 

Determine 1 Fundamental block diagram of the GPS enabled frequency counter.

Determine 2 reveals the detailed design of the frequency counter. Evaluating this schematic to the earlier GPSDO schematic, you possibly can see the modifications. Together with the removing of the VCXO circuitry, you will note 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 handle 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 relationship at the least 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 offers the enter sign most sensitivity. The capacitor and resistors are chosen to permit indicators from a little bit over 10 mHz to 80 MHz to go to the Schmitt inverter. The 80 MHz max was recognized as a result of 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 out there 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 indicators the 74LV8154 to clear the counter. The code then waits for the following 1PPS interrupt and, when acquired, the Nano indicators 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 related and share a whole lot 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 many others. One massive change is that we not want to regulate PWMs as they aren’t 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 confer 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 reveals 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 beneath 1 Hz the place the sine wave minimal climbs. The utmost enter voltage is 5 Vpp. As for precision, it usually reads frequency with a normal deviation 0.01 Hz (with 100 second gate time). Determine 5 reveals 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 mission, there was a web page exhibiting a histogram of the readings. This labored for that mission because the frequency and the vary of the frequency was identified a priori, whereas on this frequency counter mission there isn’t a 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 characteristic was eliminated.

(A observe on commonplace deviation: engineers oftentimes assume commonplace deviation implies a traditional distribution. That isn’t true. A normal deviation calculation doesn’t assume any specific distribution.  On this specific case, the deviation I usually see is a distribution skewed to at least one facet—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 important digits. Freq, 1/f (interval), Fmean, and Fstd conform (principally) with commonplace mathematical guidelines for important 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 may be an exception to the conformity of great digits. That’s, the 1/f (interval) displayed when measuring low frequencies…underneath 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 important digits. This appears like it might be much less complicated to the consumer.

Vigilant readers could have noticed a seemingly inconsistent design difficulty. 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 after 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 difficulty, 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 have to 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 matches properly on my bench.

Full mission data for this may be discovered at, the open-source website: https://www.thingiverse.com/factor:5180568 (or you possibly can search thingiverse.com for “DamianB2”).

Venture data contains full KiCad mission 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, paintings for the nameplates, numerous notes, and many others.

Damian Bonicatto is a consulting engineer with many years of expertise in embedded {hardware}, firmware and system design. He holds 30 patents.

Phoenix Bonicatto is a contract author.

Associated Content material



LEAVE A REPLY

Please enter your comment!
Please enter your name here