Sensing and Control for hobbyists and schools: Counters

Page contents...

    Introduction to counters
    Reading, displaying a changing windspeed
    Good 1-Wire counter modules
    Repairing an old Dallas counter module

Introduction to counters

Counters are small bits of electronics that have many applications in sensing and control, for instance in checking how fast a shaft is turning.

There are many variations on the theme, but they all have at least one digital input, and they all have a way to be connected to a computer.

Inside the counter are some electronics to keep track of a number. The number you get when you first apply power varies, and you don't want to get too concerned about that. (Powering it up often zeros the counter. Also, there are often ways to "hold" a number with battery backup for the main power.) The important thing is that once power has been applied, the number held in the counter goes up by 1 each time the input to the counter changes. Also, the computer connected to the counter has a way of seeing what the number is whenever the computer wants that number.

Well. Sort of. I said the number goes up by 1 each time the input changes. More typically, the number goes up whenever the input goes from "0" to "1" (a "positive edge"), or, in the case of other counters, whenever the input goes from "1" to "0" (a "negative edge")

Also... what happens when the number in the counter gets "too big"? In most cases, it just goes back to zero, like the odometer of a car.

There are all sorts of refinements on these themes, but the basics explained above will cover a lot of your needs.

Reading, displaying a changing windspeed

A little digression here.

Lets suppose you have something on the roof that spins around in the wind. You've attached a magnet to the shaft of your anemometer, and put a reed switch near the magnet, and connected the simple circuit that feeds a whole lot of 1's and 0's to a counter when the wind blows.

If you like having a difficult life, you can do all sorts of fancy things to try to check the counter once a minute. You then look up what the reading was a minute ago, subtract that from the reading now, and then try to plot that number as an indication of the windspeed.

First problem: On a still or nearly day, you'll see no "blip", or very little

Second problem: How much space, vertically, should you set aside for where the line will go on a really windy day? What happens if it gets windier than you've provided for. It's those record days that are most interesting, so you certainly don't want to merely "chop off" the too high lines!

There's a better way.

The x axis of your graph is still time. Pick yourself a counter that only goes up to 255 before going back to zero, and set aside 260 pixels vertically.

From time to time, it doesn't have to be particularly regularly, check the counter's current value, and plot that at the corresponding x/y position on the graph.

When there is no wind, you'll get a nice, horizontal, line. Its height on the y axis is unimportant.

If you have a mild breeze, your line will slowly rise. Eventually, it will get near the top of the space you've set aside, but don't worry! Shortly after that, it will "magically" jump down to the bottom of the space again, and then carry on gently rising.

If you have a strong breeze, the situation will be similar, but the line will be rising more rapidly.

With just a little practice, you'll soon be able to "read" such graphs without even having to think much about it. The steeper the line, the stronger the wind.

And, oh yes, by the way, you've just had your first calculus lesson. That wasn't so awful, was it?

Good 1-Wire counter modules

In a moment, we reach some sad news. Before that, if you are "up for" a somewhat complex answer, I can point you to a page about using the hardware counter inside Atmega Arduinos. (I suspect other Arduinos have similar facilities, but I know that you can use a counter in an Atmega)

When this page was created, I said "If you are using the Dallas 1-Wire LAN for your sensing and control, you can buy a DS2423 dual counter module for that from www.hobby-boards.com. Both counter inputs are available."

Sadly, Dallas (now DalSemi) have not, at 5/16, been producing the (excellent) chip for some time now, nor have they produced a replacement, as far as I know. And Hobby Boards was, sad for us... probably a relief for the man who worked so hard for us, closed its doors early in 2016.

I have written a small tribute to Hobby Boards and Eric Vickery, if you are interested in the history, or perhaps some information on a used module you somehow obtained.

There was another good counter module available from AAG. I believe the part number is TAI8585KIT. That incorporates a reed switch, but I imagine you could get at the relevant connections if you wanted to solder in a different switch. The switch feeds both counter inputs. At 5/16, I believe they've been "gone away" for some time too. Sigh.

Click here for lots of stuff about the 1-Wire (aka Microlan) system.

Repairing an old Dallas counter module

The counter module sold with the Dallas / AAG rain gauge was (c. 2000), and for all I know, still is, known to fail due to a capacitor on the board failing. If it fails, it often runs the battery flat before you know it.

Before I go further, let me make clear that another issue isn't as related as you might think. Elsewhere you can learn about 1-Wire devices being powered either "parasitically" or separately. The counter module we are discussing is parasitically powered. The battery does not provide power for the device's operation; the battery merely makes the device's memory non-volatile.

The counter will still work if you remove the capacitor, and, if discharged, the battery. It will no longer be able to remember the previous count after a period of being disconnected from the network, but it will count properly. I suspect you could replace the capacitor and battery with replacements and regain full functionality.

To perform the surgery:

First, you will need to remove the waterproofing in places. It doesn't stick to what it is on very badly. If you can "pinch" a it of it in your needlenoses, and pull it away from the board, you can then cut it the distended piece, and open a way into the rest of the job.

Turn the counter module so that the wires are coming out of the edge on your right, and the battery (12mm diameter cylinder) is on the side you are NOT looking at. From now on, "down" will, as it often does, however illogically, refer to towards you.

On the left hand edge (LHE) of the device, there is "something" under the waterproofing. This is the reed switch, and it is fragile. You have been warned!

7mm from the right hand edge (RHE) and near the bottom edge (BE) you will see that there's a 4mm x 2mm device under the waterproofing. (I won't keep repeating "under the waterproofing from here on. AND... when I saw something is 4mm x 2mm, I will take care to give the left-and-right dimension first.)

Leave that one (7mm from RHE) alone! A little further left and up, center at 13mm from RHE, 6mm from BE, there's a 2mm x 4mm surface mount device (SMD). This is the presumed-failed capacitor. If you want to be thorough and "good", you could replace it. Tantalum capacitors were recommended, 0.01uf.

Now.. the "battery" (I'll use the more accurate "cell" from here onward.) The simple answer: Assume it is dead; isolate as explained below.

Turn the board over so that the cell is facing you and the board's wires are coming out to your left.

The side of the cell closest to the board and the sides of the cell are connected to +ve. The side of the cell facing you, and the little metallic strap you can probably see connecting about 11mm from the LHE, 5mm from the BE. This is the connection to 0v. I leave it to you to measure the cell's voltage if you wish to.

To disconnect the cell, you only need to snip through the easily accessible little metallic strap which connect the top of the cell to the pcb.

By the way: The reed switch is wired to both the counter inputs on the chip. This is good, as your software can look at either for the rainfall. It is bad, though, if you want to use the two counters in the chip for two different pulse trains. If you like a challenge, you may succeed in cutting he trace between the legs of the SMD. If you want to try....

Turn the board over again, non-cell side, wires coming out to your right. 20mm from the RHE, 8mm from the top is a 4mm x 4mm SMD. The upper right hand corner pin is "1", the pins, as usual, are numbered counter-clockwise around the chip. Pin 5 (middle, bottom edge) is the input for Page 15's counter, and pin 6 (bottom right corner) is the input for Page 14. It is easiest, in hardware terms, to leave the on-board reed switch connected to pin 5, and to "liberate" pin 6 for your own use.

Click this to search this site without using forms, or just use......
powered by FreeFind
Site search Web search
The search engine merely looks for the words you type, so....
*    Spell them properly.
*    Don't bother with "How do I get rich?" That will merely return pages with "how", "do", "I"....

Please also note that I have two other sites, and that this search will not include them. They have their own search buttons.
My site at Arunet.
My oldest site. (It's at Compuserve).
Ad from page's editor: Yes.. I do enjoy compiling these things for you... hope they are helpful. However.. this doesn't pay my bills!!! If you find this stuff useful, (and you run an MS-DOS or Windows PC) please visit my freeware and shareware page, download something, and circulate it for me? At least (please) send an 'I liked the parallel port use page, and I'm from (country/ state)' email? (No... I don't do spam) Links on your page to this page would also be appreciated!
Click here to visit editor's freeware, shareware page.

Other projects

This is just one of the guides I have published on the net. Please visit any of the following that relate to interests you have....

Delphi Tutorials
Pascal programming tutorials
Electronics for hobbyists and schools
Main Home Page

Here is how you can contact this page's author, Tom Boyd.

Index of sensing and control pages (From there you can also go to other help from the editor of this page.)

-- Page ends --