loading
Picture of Digital Frequency Counter




First of all, if you like this project, please vote for me in the Hurricane Laser Competition and the LED Contest!

Have you ever needed to find out how quickly something is oscillating? For things like hamster wheels and ocean waves, this is easy. You just count how many times the wheel goes around in a certain amount of time, then do some math, and you have the frequency. But what if you're dealing with something a little less tangible like audio waves or electronic signals? That's where digital electronics saves the day.

This Instructable will show you how to build a digital frequency counter capable of measuring events up to 250kHz and will attempt to explain some of the electronics theory behind it. The project costs about $30US, assuming you already have all the tools and equipment required.

This is actually my term project in a Digital Electronics course at the University of Oregon. It's intended as an addition to my term project from the winter term, which was a Function Generator I also posted to this site.
 
Remove these adsRemove these ads by Signing Up

Step 1: Description

Picture of Description
A frequency counter is a device that measures a periodic signal and determines its frequency in Hertz (Hz or s-1). But how does it do it? If you were trying to determine the frequency of a wheel manually, you might follow this operation:
1. Mark a spot on the wheel, then let it spin.
2. Start a timer.
3. Count how many times the spot on the wheel reaches the top.
4. Stop the timer.
5. Divide the number of rotations by the amount of time that passed while you were counting.

The result of the division would be the frequency of rotation of the wheel. This build actually follows the same steps, but it does all the operations automatically, repetitively, and it doesn't actually do any math. The math is built into the way the frequency counter counts.

This frequency counter actually follows these steps:
1. Generate a stable, known, reference time period.
2. Count the number of periods of the signal you're measuring.
3. At the end of the reference time period, display the number of counts and reset the count to zero.

These steps can be completed very quickly and repetitively using digital electronics methods. It's a very "dumb" process. The accuracy of the output frequency depends wholly on the accuracy of the reference time period and the speed of the counting chips. Using quartz crystal oscillators, we can generate reference periods with an error of about 20ppm, or 0.002%. Digital electronics can typically handle up to 30MHz signals, so this project is actually quite accurate.

The key to keeping any math out of the device is to make the reference periods base ten (decimal). Digital electronics is all base two (binary) so we need some chips that let us do some decimal conversion. What would be really nice is to just have a 1 second reference period. Then we could just count the number of pulses from the measurement in one second and display that and we'd automatically have Hz. That's actually what's going on.

But there are only three digits for display. How do we keep the display from rolling over? Let's say we have a frequency of 1,234Hz that we want to measure. If we counted for one second, the display would show 234 since it would roll over once. That's no good. But what if we only count for 1/10th of a second? Then we would get a count of 123 since 1234Hz * 0.1s = 123.4 (the .4 gets rounded, digital only deals in integers). If we KNOW we're only counting for a tenth of a second, we just multiply this count by 10 to get 1230Hz. This works for higher frequencies too. If you know the order of magnitude of the reference period, you can just do some easy 10^n multiplication and get a three-significant-digit result.

Step 2: Parts

Picture of Parts
Here are all the parts you need for this project.

The schematic is attached below in PDF form and as the original EagleCAD 6.2.0 file.


Quantity Description Mouser Part Number
1 7805 +5V Voltage Regulator 863-MC7805CTG
1 LM311 high speed comparator -
1 7404 Inverter gate 771-74HC04N
1 7402 NOR gate 771-NF02N602
5 4518 Dual BCD Counter 595-CD4518BE
1 74151 8-to-1 Multiplexer 771-74HC151N
1 7474 Dual D-FlipFlop 595-SN74LS74AN
4 4511 BCD to 7-Segment Decoder 771-74HC4511N
1 100kHz Crystal Oscillator 520-ECS-100-12.5-13X
2 100pF Ceramic Capacitor 594-S101K29SL0N6TK5R
1 3-Digit 7-Segment Display 696-LDT-C512RI
1 1-Digit 7-Segment Display 859-LTS-4301JG
2 SPDT Momentary Push Switch 688-SPPH430200
6 1k Resistor -
1 47k Resistor -
2 1M Resistor -
1 Protoboard (at least 8x11 cm) -
1 40 Conductor Ribbon Cable w/ connector -

Step 3: Description of Parts

Picture of Description of Parts
If you've ever worked with electronics before, it's likely you'll already know the functions of many of the parts required, so I'll just go over the more complicated bits.

LM311 Comparator
Comparators are similar to analog op-amps, but instead of being used as amplifiers (negative feedback), they are used to make a very fast decision about whether one voltage is bigger than another (positive feedback). Comparators usually have either an "open collector" and "open emitter". The LM311 has both. This just means the comparator controls an internal transistor, the voltages to which can be user selected. For this project, we hold the collector at +5 through a pullup resistor, and set the emitter to ground. This generates a TTL signal. The comparison operation is as follows:
If pin 2 > pin 3, then output = HIGH
If pin 2 < pin 3, then output = LOW

7404 Inverter
Inverters are digital logic gates that convert a "True" condition to a "False" condition. For TTL, +5V is generally "True" or HIGH, and 0V is "False" or LOW. An inverter simply negates the truth of its input.
A Q
0 1
1 0


7402 NOR Gate
NOR gates are OR gates with an inverted output. An OR gate adds two bits together, A + B = Q. It adds in the logical NON-ALGEBRAIC sense, as in 1 + 1 = 1. If A is true OR B is true, then at least one of them is true.
A B Q
0 0 1
0 1 0
1 0 0
1 1 0

4518 BCD Counter
Counters do exactly what you think they do. When you input a series of pulses to a counter input, the outputs reflect the number of pulses the input has received. All digital counters count in binary, but they can have different limits for their maximum count. A standard 4bit counter counts from 0 to 15 (0000 to 1111 in binary). A BCD (Binary Coded Decimal) counter is intended for math involving decimal (base ten), so they only count from 0 to 9 (0000 to 1001). This obviously wastes bit capacity, but it makes certain things easier. Inputting a constant frequency into a counter results in the division of the frequency. A one-bit counter will divide the input frequency by 2. A 4 bit counter can divide the input frequency by 16. A BCD counter divides the input frequency by 10.

74151 Multiplexer
These are used to select between up to 8 input lines. A thee bit address is fed to the multiplexer, which selects the desired input. Then whatever signal is on the selected input appears at the output. They are the digital equivalent of an 8 position rotary switch.

7474 D-Flip Flop
These are almost infinitely useful in digital electronics. In fact, many components can be decomposed into a combination of D-Flip Flops. They are, in essence, a one bit counter. An input is given on D and the FF does nothing until a clock pulse is given, then the FF places the input value on the output Q. That's it. They are used as a one bit memory for this reason. 1. Input bit to be stored, 2. command storage, 3. stored bit appears on output until overwritten. The two FFs in this project are used as a sort of "shift register", which propagates a single command bit along a line of D-FFs.

4511 BCD to 7-Segment
This chip converts a binary coded decimal address (from the counters) into a pattern that correctly lights up a 7-segment decimal display. It takes a TON of logic gates to do this, so having it all on one chip is really nice. These also come equipped with several neat features such as a BLINK pin and a LATCH pin. Blink shuts off the outputs when the blink pin is held low. This is used to very quickly turn the displays on and off at low duty cycle to conserve power (they draw about .6A at continuous on, and get quite hot). Latch is used to capture the counts of the BCD counters and hold that number until the next latch command. This is so we only see the final count instead of 0,1,2,3,4...final count,0,1,2... etc.

100kHz Crystal Oscillator
This is what enables the frequency counter to get an accurate measurement. We have to compare the thing we're measuring to SOMETHING. Crystal oscillators are highly precise, with typical frequency errors of 20-40 ppm. That means this crystal would lose about 15 minutes after 1 year of operation. They're not perfect, but for this project, they're actually kind of overkill. But they're also cheap, cheap, cheap. They operate on the piezoelectric effect. When they receive a voltage, they physically expand very slightly (on the order of nanometers). Then when they contract due to their own elasticity, they generate a new voltage. Since the expansion oscillation is 90 degrees out of phase with the voltage oscillation, we can use it in combination with some capacitors to get an oscillation that is 180 degrees out of phase with the driving voltage. When this condition is met, positive feedback ensues and we get a stable oscillation. The crystal's shape and mass ensures that it oscillates at exactly 100kHz. Manufacturers make crystals in thousands of different frequencies, 100kHz is just convenient for this project.

Step 4: Play!

Picture of Play!
Once you get your parts, you should probably play with them. If you don't have a breadboard, you should definitely invest in one. Digital components are robust, it's actually pretty hard to fry them in my experience, especially these simpler chips. The one thing you should NEVER do is connect two outputs together. You don't want one chip trying to hold it's output HIGH while the other is trying to hold it's output LOW. Not only is this bad for the chips, it's logically abhorrent! You can connect all the inputs you want together, but never, ever put two outputs on the same line unless the chips have what's called a Three-State Output. But none of these chips have that, so just don't do it. Anything else is pretty much ok.

Plug your chips into power and see what they do when you give them different inputs. Test the truth table for the inverters and NOR gates. Try measuring the count after manually giving a counter a clock signal. Make sure the multiplexer works as described. You'll learn way more from playing with these components than you ever will by reading about them. If you have access to an oscilloscope and function generator, you will have a MUCH easier time examining your chips.

Off you go.

Step 5: Board Layout

Picture of Board Layout
The positioning of your chips and other components is an important detail. Finding a layout that has a good functional flow and also minimizes connection length can be tricky. The layout I used is attached below in PDF form, but feel free to choose your own. I ended up with a protoboard that was 7.5x11cm that perfectly held all of my components.

Step 6: Making Connections

This is easily the most tedious step. One of the nicest things about digital electronics is that almost no calculations are required. Each chip performs a specific task and is designed to work with just about all other types of digital electronics. However, the number of connections is much higher than most of the analog projects you'll encounter.

Use some lower gauge wire (~26AWG) to supply power to all your components first. This tacks your chips in place and allows you to test that all of them are getting good power before continuing (kind of important).

To make all the other connections, I recommend using wire wrapping techniques. Wire wrapping tools and wire are available at Radio Shack. Follow the images to get an idea of what to do. The basic idea is that we'd like to be able to make all these tiny little connections consistently and cleanly, without the use of solder. Soldering has several problems. First, you only want to apply soldering heat to sensitive ICs if it's absolutely necessary. Second, for ICs soldering is pretty much permanent. Have you ever tried to desolder an IC? You don't want to have to do that. When all the connections are made and the thing works, then you get to solder your ICs.

Step 7: Making Even More Connections

Picture of Making Even More Connections
SDC10042.JPG
SDC10037.JPG
SDC10039.JPG
Like I said, this step is highly tedious. Just keep at it. Play some music. Eventually you'll have so many wires that the back of the board almost feels furry. Don't forget to install the 2x20 pin block that will allow you to connect the ribbon cable to the mainboard. Make sure you know which pins are which, and number them on the mainboard so they sync up with the 7 segment displays. You don't want to wire everything up and realize you forgot to mirror the numbering on the backside...

Step 8: LED Display

Picture of LED Display
SDC10045.JPG
Ok, let's take a break from wiring up the back of the main board. You saved the extra pieces that you cut off of the protoboard, right?

Take the length of 40 connector ribbon cable and find a way to strip all the wires evenly. I did this by scoring both sides with a utility knife, then firmly pulling on this score mark with a flat head screw driver. With enough work, the insulator should begin to come away from the rest of the cable, leaving 40 evenly spaced, exposed wires. You need to feed these wires into a 3 x 7.5cm chunk of protoboard. To do this I had to twist all the little wires by hand, then tin them with solder to make them solid. Since the ribbon cable's wires are spaced by 0.05 inch, and the protoboard is spaced every 0.10 inch, you'll have to systematically place every other wire in one row of holes, with the other wires in the next row of holes. Doing this for 40 wires all at once is a little tricky, but it can be done. Solder them in place as soon as you can. You don't want to lose all that work.

Place the 3-digit and 1-digit 7 segment displays into the little chunk of protoboard. I left 5 holes between the large and small displays. Later I'll be putting a label in this space indicating that the small digit is an order of magnitude multiplier.

Use wire wrap to connect the displays to the ribbon cable. I decided to call the red wire on the ribbon "1", and number upward after that, with each number corresponding to the pin number of the large display. The large display has 28 pins, so the 29th wire connects to pin 1 of the small display. The small display has 10 pins, so the total number of wires required is 38. I chose to ignore the fact that there are redundant pins and unused decimal point pins at this stage. I just wanted the ribbon cable to be systematic and easy to connect.

Step 9: Put it All Together

Picture of Put it All Together
So, you're done making all your connections? Ha. I doubt it. A nice thing about digital electronics is that it doesn't really matter. Connect it to power!

No sparks? Good. Does it work? That's what I thought. Do you have access to an oscilloscope? No? Hrm. I suggest going through the schematic and using a continuity tester to make absolutely sure you've made all the necessary connections. If you've got an oscilloscope, it's relatively easy to find where signals are being lost.

In all likelihood you will at least have a few numbers displaying zero correctly. Use the working numbers to find and fix your errors in the other numbers.

If you suspect your clock isn't working, connect an led from Pin 6 of IC5 to Ground. It should blink each second. If it does, then all the other clocks must be fine. If it isn't blinking, then try to find bad connections in your cascaded counters.

Step 10: Function Testing

Picture of Function Testing
SDC10055.JPG
SDC10063.JPG
Whew, hopefully that troubleshooting went better for you than it did for me.

Now it's time to hook up the signal input to some sort of function generator. You should have some way of telling if the frequency counter is doing its job well. Ironically, you'll need a frequency counter for that. If you don't have access to a function generator that displays frequency, then you'll need to find some other way to determine the accuracy of your frequency counter. You may be able to use your computer to generate a known frequency, for example.

When I tested the accuracy of my counter with a laboratory function generator, I found that all the measurements were more or less spot on. The frequency counter worked exactly as I expected. Except for the the highest order of magnitude. I found that, when measuring frequencies higher than about 100kHz, the count is too low by 10% or so. The reason for this has to do with the use of a 100kHz crystal as the reference signal. There is a shift register in the frequency counter that performs two operations, one right after the other. This is done to prevent the counters from being erased before the counts can be latched to the 7-segment display encoders. However, it causes a very slight delay on the order of two clock pulses. When measuring high frequencies, this delay becomes significant, while low frequencies are still measured quite accurately.

This can be fixed extremely easily, I was just to lazy to do it. You're welcome to try though. Instead of a 100kHz crystal, use a 1MHz crystal. Then use the extra BCD counter (remember, we only used half of a dual BCD counter earlier) to divide that by 10. This will make the time delay an order of magnitude shorter, resulting in a 1% error at high frequencies rather than a 10% error.

Step 11: Installing the Frequency Counter into a Function Generator

Picture of Installing the Frequency Counter into a Function Generator
SDC10056.JPG
SDC10058.JPG
The whole point of this project for me was to install the frequency counter into the function generator I made, so that I'd have an actual function generator of reasonable quality that I could use for my electronics projects. That meant finding room inside the already packed ATX power supply case I had used. I had to push wires out of the way, make sure nothing would short, and fit the frequency counter board into the cavity above the function generator's board. Then I had to tap into the +12v and ground lines to power the frequency counter's 5v regulator. Then I connected the high impedance signal output of the function generator to the signal input of the frequency counter. When this was tested, it worked just fine.

Then I had to cut into the ATX power supply case with a Dremel tool to make rectangular openings for the LED display. This was pretty tricky, and quite messy. If you're doing the same thing, I highly recommend cutting this hole before painting and installing knobs and buttons into the casing.

I also needed to drill holes for the screws that would hold the display in place, as well as holes for the two momentary buttons that control order of magnitude and latch override.

Once you install the frequency counter into some kind of housing, the project is complete!

Thanks for reading this Instructable, and watch out for my next one, which I'm in the process of building: An Arduino powered, sonic position sensor equipped carpet rover!
MarkC37yesterday
I'm trying to design a frequency counter that measures beats. I have a band pass filter that will pass the frequencies of two musical notes. When not equal, they will pulsate. The signal will fluctuate between almost quiet to audible. Can this be counted by your device? I imagine a device that has a sort if squelch control that the user turns until the count looks probable. Is your counter's sensitivity adjustable like that?
trickx189 months ago

please help me :( i need frequency counter circuit. it is my final project in signal spectra subject. frequency counter w/o using PIC :( please help me

boycecat10 months ago

would it be possible to modify this to measure a low frequency (50Hz) accurately? I am guessing any rounding errors would be more of a problem? Thank you

laserjocky (author)  boycecat9 months ago

Sorry for the slow reply. For this you could increase the counting time to 10 seconds to gain some accuracy in the form of a tenths place. You would need to modify the circuit. There's already an extra BCD counter on the board so it would be a matter of wiring it up to generate a 10 second reference period.

hi all of my friend i get very good article on digital frequency meter at the link

http://www.nbcafe.in/digital-frequency-meter-by-pi...

they write very elaboretly which is very helpful you may see that.

laserjocky (author)  dalexdisuja1 year ago

Thanks for the link! Of course, I wasn't allowed to use anything near the complexity of a micro controller for this project. If you want to do things easily, use an MC. If you want to understand how something works, start at the lowest level.

nigelj1 year ago

this might sound silly.....but how to use it for measuring audio from microphone?

laserjocky (author)  nigelj1 year ago

This counter can really only handle a single frequency. There may be a way to measure a string of short pulses from a mic, but if you're trying to separate out individual frequencies then you'll need something much more complicated than this build.

What this counter would do on its own when given a microphone input is count half the number of times the audio wave crossed over zero. There wouldn't be a way to determine which frequency components were contributing to the final count.

Can you suggest me a circuit that can measure frequency of sound produced in real world environment? like human voice, tuning fork etc?Is it difficult to do? I have come across many such circuits but none of them specify if it will work with real world sounds.

laserjocky (author)  nigelj1 year ago

This build might be able to handle a tuning fork input because it is a single frequency. But a human voice is composed of many frequencies mixed together with different amplitudes for each. In order to decompose these frequencies you will need a circuit that performs a Fourier analysis. Fourier analysis is a pretty complicated thing for a homebuilt circuit to do accurately. It's probably best to use a computer running Fast Fourier Transform software. That would tell you exactly how much of each frequency was included in your sound wave.

If all you want is to find the lowest frequency component (the fundamental frequency) of a human voice, then you might be able to get away with placing a low-pass filter on the front end of this circuit. Or even better, if you can find a very low bandwidth band-pass circuit whose center frequency can be adjusted, you could sweep the center frequency back and forth until you selected out a single frequency of the human voice. The output of the band-pass would be fed to the counter. But band pass filters aren't perfect, they just lower the amplitude of frequencies outside their set range, and those low amplitude waves could still affect the counter.

Ok final idea: You could make a circuit that contains several band pass filters with different ranges, say one that passes 10-100Hz, 100-500Hz, 500-1kHz, 1kHz-5kHz, etc, etc. Then you would need a circuit on each output that determined the amplitude of the waves. Like an op-amp going to a diode-capacitor-resistor circuit that fed into an analog to digital converter which converted the voltage to a pattern that lights up an LED bar or something. With this circuit you'd be able to tell roughly which frequencies were in a sound wave, but it wouldn't be very accurate.

Thanks for the input. I didnt know human voice were this complicated....anyway I'm planning to do a frequency meter ( in Hz ) using PIC and LCD to output for college project. About tuning fork......can i use mic to input tuning fork sound and measure the frequency? Also i guess it can be used for setting frequency of musical intruments right?

laserjocky (author)  nigelj1 year ago

Yes, you could use a tuning fork and mic to measure the tuning fork's frequency with this circuit, but you would need a pre-amp for the microphone. There should be plenty of simple circuits for that online. I haven't worked much with audio amplification.

Setting the frequency of musical instruments will have the same issues as the human voice. The reason instruments sound different is because each one contains it's own distinct combination of frequencies other than the fundamental you hear. When a piano plays an A, the majority frequency is 440Hz. But there are actually many overtones in the note you can't quite hear with your ear. Those overtone frequencies are what makes the piano sound different from a trumpet or guitar. Those frequencies are what would make it difficult to use this counter to measure audio frequencies. A tuning fork might be ok, but that's only because tuning forks have essentially no overtones. They are pretty much the purest sound you can get. Another instrument you might be able to measure is a flute. Flutes and tuning forks both have almost no overtones.

If you're using a PIC or other micro controller, you may be able to program it to do a fast fourier transform of an incoming wave. That's beyond what I'm able to help with, but maybe there is an instruct able about it.

Hi,
It's me again. I need your suggestion.The digital frequency meter in this instructable is able to measure upto 250 kHz.Do you know how to increase the measuring range, like in the Mhz range? I'm doing a similar project using 8051 and according to it's specs, it can measure upto 12 Mhz, but the circuit I have can do only upto 250 kHz. Do you know how I can modify the circuit to increase the measurement range?

laserjocky (author)  nigelj1 year ago

The frequency for this device isn't determined by the digital electronics I used. Digital chips usually work up to at least several MHz. You can look up the data sheets for each chip and see for yourself. 10-30MHz is pretty standard for all of these. I think (and I stress THINK) that the frequency is being limited by stray impedance in the circuit. Each wire, solder joint, IC connection, etc, acts as a very small combination of a capacitor and inductor (often called impedance, for both in general). Stray impedance is death for high frequencies. When you add up all those small impedances, the incoming signal ends up being garbled. The stray impedance of this circuit is probably huge because of the wire wrapping method.

I think the best way to improve frequency response for this circuit is to order a nice, professionally etched PCB. PCB's keep all connections in the same plane, use small wires, minimal connection length, etc, and that really does wonders for minimizing stray impedance.

FFT sounds too complicated for us to implement now but I will be incorporating that on the next version of our project ( final year project )

Thanks :)

cglaw20131 year ago
awesome
donkeyknee2 years ago
good
Unless they gave you a precision limit, it would have been funny to do a frequency to voltage converter and a voltmeter as the output...
laserjocky (author)  steveastrouk2 years ago
The thought had crossed my mind, but for this class I'm pretty sure that would have been cheating :)
nice project! and great documentation. do you think you will make a pcb for this?
laserjocky (author)  amandaghassaei2 years ago
Thanks! I probably won't be making a PCB for this project, even though it would likely improve the frequency response by a very significant amount. The biggest limitation for that in this project is probably stray inductance. EagleCAD does relatively good auto-routing for free if you want to go that route. You'd pretty much have to get the PCB etched professionally though (probably >$100) since there will be so many traces and vias.
Hi, it's always great to find someone who doesn't use microcontrollers for everything. If you want to find some ideas for simple frequency counters capable of measuring high frequencies, look there:

http://pa2ohh.com/


http://www.hanssummers.com/sfreq.html
pfred22 years ago
Not many are still making circuits like this anymore. I'm glad to see someone other than me does. I'd like to see more decoupling capacitors to improve circuit stability but the logic design looks nice.

One thing I'd never do making a circuit like this is try to complete it before powering it up. I build one section at a time, test it, debug it, and move on only when I get proper operation from the circuit section I am working on.

Your build it and hope it works method is too optimistic for me. Doing that only lands me in a place I never want to be. Trying to debug a circuit with more than the minimum of possible variables. To me that just adds up to extra work.
laserjocky (author)  pfred22 years ago
It's true, almost no one uses logic chips in this way anymore. I've seen a few others on Instructables. For me, it was just a great way to build something complex from extremely simple components. I love how modular the old digital chips are. Unfortunately, the course I made this for was mostly a theory course, and they didn't go into things like decoupling capacitors at all. I know the general idea, but do you have any pointers for me for the future? Where should they typically be added, just on the power lines near each IC?

Normally I'd agree with you about the testing. That was the method my PI taught us to use in the lab. Build and test in reasonable chunks. It's hard for me because I haven't invested in an actual oscilloscope for my home yet. I did test the essential portions of the circuit on a breadboard in the lab first, even though those have issues at high speeds, and it seemed to work ok. By the time I was actually loading chips into the protoboard, I knew the circuit pretty much by heart. It worked the first time I powered it up. I had many more issues with the analog sections of the function generator. As it happens, I had those issues with it because I took the same "build it and hope it works" method... Hmm, area for improvement noted.
switch622 years ago
Well done. It's nice to see a digital design that uses actual logic chips. Now a days it's just throw in a microprocessor and do it all in software.
Mind you micro's make the development and design simpler.
laserjocky (author)  switch622 years ago
Yeah, a microcontroller design would have actually been cheaper too. With the upper limit for frequency counting for this board, the microcontroller's clock speed wouldn't have limited it at all. But this was for a digital electronics class and we weren't allowed to use those.