# Learn Counter ICs Using an Arduino

Have you ever needed to count something? Sure, we all need to count change, count blessings, and occasionally count cards, but that's not really the kind of counting I'm talking about. In this Instructable, I will elucidate how Counting ICs operate, and show how to connect one to a microcontroller so you can see exactly how it works in a controlled way.
Remove these ads by Signing Up

## Step 1: Why Use Counting ICs?

Yes, yes, why not just use the microcontroller? Arduinos are pretty good at counting things. But what if you want a cheap hardware solution that operates with events as fast as 30MHz? That's what counting chips are for.

My work in the atom optics lab at my university has taken me through some real twists and turns. I've learned more in my two years as an intern there than I have in most of college, and it's way more rewarding than turning in homework. If you ever have the chance to work in a university laboratory, take it, no matter what. You'll never regret it. One of the things I've had to learn pretty thoroughly is electronics, since one of my duties is troubleshooting electronics and occasionally building additions and hacks to them. My most recent project brought me face to face with digital counting ICs.

The project involved using a Michelson Interferometer to compare the relative wavelengths of two lasers by counting the number of fringes of each beam when a retro-reflector cart was translated across the beam paths, thus changing the path lengths of both beams by identical amounts. Light has such a short wavelength that moving the cart even as slowly as a few centimeters per second produces fringe patterns at around 150kHz. The interferometer operation simplifies down to the relation:

λ21(N2/N1)

where λ is the wavelength of a laser, and N is the number of fringes produced by translating the cart a certain distance. So if we know one laser pretty well, we can find the wavelength of the second laser by counting their fringes. For light being measured by translating the cart over 1 meter, N is going to be around 40 million. Try counting that by hand. No, we need high speed event counting methods.

Another use would be in something like a Geiger counter. If you need to know how much radiation you've been exposed to, you can hook up a traditional Geiger counter to a counter IC and count the number of radiation events, then use the appropriate math to convert the radiation count to rads.
pterodac5 months ago

Any suggestions about interferometry and fringe patterns? I am trying to use an interferometer to find the density of a protein sample. I was planning on using a Mach-Zehner Interferometer and taking an image of the fringes. It is my understanding that I would need to record the space between the fringes. Is this correct? The idea behind it is that the density relates to index of refraction, and when one beam goes through the sample it will be phase shifted from the original beam, and when that beam and the original beam interfere it will create horizontal fringes (which it does).

laserjocky (author)  pterodac5 months ago

That sounds about right. Interferometry typically boils down to either a change in path length or a change in index of refraction. I haven't worked with Mach-Zehner (Zehnder?) setups, but from the schematic it looks useful in terms of being able to use a reference on one path to look for deviations from that reference in the other path. I'm not sure why there would be horizontal lines in the interferogram unless some angle is out of perfect alignment. If your sample is perfectly aligned and occupies a container identical to the reference, and the container is a perfect rectangular prism, I would think that no horizontal fringes would occur. As you added more protein concentration to the sample container, the entire interferogram would oscillate in brightness.

A closer look at the wiki seems to indicate that the interferometer is usually deliberately misaligned to produce fringes. If that's the case it will take some geometry to figure out what the expected path length difference should be. What is the shape of the container, what kind of index of refractions are you working with, and what is your light source?

5 months ago
Sorry, I forgot to mention: Our protein undergoes a liquid-liquid phase separation at different temperatures and concentrations. So because of that we have a horizontal concentration gradient, and therefore a horizontal index of refraction gradient. That is what causes the horizontal fringes. So we are trying to measure the density gradient with the horizontal fringes, basically. It is a pretty neat idea.
laserjocky (author)  pterodac5 months ago

That is a neat idea. There are a few conversions you'll need. Getting the index of refraction gradient shouldn't be too hard. That's geometric calculations and counting fringes produced by the interferometer, as you said earlier. More difficult will be converting the index gradient to a concentration gradient. Do you already have the data that would allow that conversion?

laserjocky (author)  laserjocky5 months ago

I just did a rough calculation and it looks like your index of refraction gradient will be roughly dn/dx = L/(t*a), where L is the wavelength of light in vacuum, t is the thickness of the sample container, and a is the distance between each horizontal fringe in your interferometer. I assumed the index gradient is constant, the incoming light is perpendicular to the container, and the container thickness doesn't vary much. Definitely do check that figure.

manicmonday1 year ago
There is a lot of blah blah blah text at the beginning of this, when I only want to find out what this instructable does. Can I use this with a reed switch to count wire turns?
laserjocky (author)  manicmonday1 year ago
yes.
TedRobotBuilder2 years ago
Nice! Do you know of a counter IC that can count up and down out to a Long, has serial out and is fairly easy to use with an Arduino? I am looking for something to count the output of a LS7183 CMOS. Thanks!
laserjocky (author)  TedRobotBuilder2 years ago
My experience with serial output is nonexistent, unfortunately. If you're having trouble finding a counter with built in serial output, you could use a Shift Register to convert parallel counter output to a serial signal, but it might take some doing.

According to the LS7183 datasheet, the 40193 counter can be used as an up/down counter, but it's 4-bit parallel.
2 years ago
Thanks for the reply! :D
crackHacker2 years ago
to be honest i came into this one thinking i would be able to count the number of ICs attached to the circuit.

love counters though great how to on them!
laserjocky (author)  crackHacker2 years ago
Ah yeah, I was being a little funny on the title, but maybe that wasn't such a good idea.
2 years ago
Oh no, I thought the same but after reading this I'll know what to expect next time.
laserjocky (author)  omnibot2 years ago
Haha, ok I've modified the title. From now on I'm going to save the bad humor for the actual instructions ;)
2 years ago
title is better! maybe you could do one on flip flops leading into this?
laserjocky (author)  crackHacker2 years ago
To be completely honest I wasn't expecting this to be on the homepage.