This circuit was built as a novel means of computer data entry, but its design has features that may be useful in other projects. You’ll learn about a unique method of position sensing, a method for high precision frequency counting on an inexpensive microcontroller, and multiplexing to reduce hardware complexity.
Computer technology has enabled some interesting hobbies. There are people who memorize many digits of pi, a transcendental number that’s now known to many decimal places because of computers. The present record for digits of pi recited from memory is at least 50,000, and it might be as high as 100,000, depending on who’s counting. There are people who use their desktop computers for creation of image parodies using Photoshop and similar image manipulation programs, such as GIMP.
Steampunk is an interesting technology-inspired culture in which devices created by today’s technology are redesigned as if they had been built in the 19th century. Steampunk aficionados covet objects such as computer keyboards that look like manual typewriters, and ornate brass works housing computer monitors. They’re always looking for antique devices to repurpose.
THE SOROBAN ABACUS
The abacus is a counting device that’s been with us for at least four millennia. Versions of this early manual adding machine have existed in most world cultures, but one of the more popular is the Japanese abacus, called a soroban, as shown in Figure 1. In this device, numbers are represented by movable beads in a modified base-5 number system.
The number of bead columns is arbitrary, but each column has four beads in a lower rank and one bead in an upper rank. Counting is done by starting with all beads low on their column, and then raising beads in the lower rank one at a time. When all four beads in the lower rank are up, you get to five by raising the single bead in the upper rank, and demoting the four lower beads to the bottom. When all beads in a column are up, signifying a nine, and you need to add one, all the beads in the column are lowered to the bottom, and a bead in the adjacent column on the left is raised.
It’s easy to add numbers on a soroban by first entering one number, then moving beads to enter the second number atop the first, starting with the rightmost column, and always carrying through towards the left. Such addition might seem complicated to someone who’s not skilled in the art, but everyone will find that it’s easy to enter a number on a soroban, even if they’re not skilled in base-5. Figure 2 illustrates entry of the number 92574.
INDUCTIVE POSITION SENSING
My eldest grandchild has a puzzle that looks a lot like one that I had when I was a child. Wooden pieces are shaped to fit into complementary holes. However, in this electronic age, the puzzle is augmented such that placing a piece in its hole will produce an appropriate sound.
When I examined this puzzle, I saw that the position sensing was done using photodiodes that respond to the absence of light when they were covered. The designer made the obvious assumption that the puzzle wouldn’t be used in the dark, so this position sensing method worked well.
A soroban with eight columns has forty beads. If we were to use this same position sensing technique, that would involve a lot of photodiodes! Also, we can expect a lot of hand motion above a soroban, so the idea of the diodes being uniformly illuminated is flawed. We need a different method if we want to sense the position of soroban beads.
Every electronics experimenter is familiar with the simple and inexpensive construction of an inductor. You just wind a coil of wire. When too many coil turns are required for the desired inductance, or when you need to make the inductance variable, you wind the coil on a magnetic core. The core material is usually made from ferrite, an oxide of iron and other elements.
Although tuned inductors use a cylinder of ferrite, a more common form of ferrite is a toroid. Toroidal ferrite is used for filters and transformers. They can be used, also, to modify the inductance of a flat inductor, as shown in Photo 1.
Movement of the ferrite core changes the inductance; and, when the inductor is part of a tuned circuit, the resonant frequency will change. The resonant frequency can be read by a frequency counter if the tuned circuit is part of an oscillator, so the core position can be read as a frequency. This is the position sensing approach I used to sense the position of the beads in the abacus.
SENSING COIL CONSTRUCTION
The sensing coil dimensions are shown in Figure 3. The ferrite toroids I used had an inside diameter of 5 mm and an outside diameter of 10 mm. They were a little snug on a type of drinking straw that I identified as an ideal, and inexpensive, carrier tube for the coils. However, I found that I could stretch the plastic straws slightly, to shrink their outside diameter, by pulling them on an appropriately sized metal rod after they were heated with a hair dryer.
The flat coils were wound on a simple jig, as shown in Photo 2. One advantage of being married is having access to unusual construction materials; in this case, the clear nail polish I used to coat the coils so they wouldn’t unwind before insertion into the carrier tubes. The coils were glued into the carrier tubes with the same nail polish.
The lower, 25-mm coils were wound as 30 turns of 38 AWG enameled copper wire, while the upper, 12.5-mm coils were wound as 40 turns of the same wire. The longer coils had a nominal resistance of about 2.7 Ω, while the shorter coils had a nominal resistance of about 2 Ω. The coils were inserted into the carrier tubes to a depth that left about 2.5 mm of empty space at the end to allow for mounting.
Photo 3 shows the carrier tubes with their embedded coils inserted into the base assembly. Also shown is the push button switch that sends the entered number values to a computer. This switch also serves as a way to initially calibrate the abacus.
I often use bare circuit boards as a construction material, since they are rigid, they are easy to cut and drill, and they allow for solder attachment of pieces. Circuit boards worked well for this application, and a mechanical drawing of the base assembly of Photo 3 is available on the Circuit Cellar article code and files webpage. Ribbon cable headers were used for connecting the coils to the circuit board. The circuit board was mounted on the underside of this base plate.
Combining the inductor with a capacitor in the resonant circuit of an oscillator allows the inductance change to be inferred by the oscillator frequency. The abacus data entry terminal uses a slight variant of the digital oscillator shown in Figure 4.
Timer0 (TMR0) on Microchip Technology PIC microcontrollers will accept an external frequency source and thereby serve as a frequency counter. The resolution of TMR0 is just 8 bits, which is too low of a resolution for most frequency counting. In 1997, Microchip Technology published an application note on a method to achieve 16-bit resolution for frequency counting using TMR0. This method is illustrated schematically in Figure 5.
The frequency source is routed through a current-limiting resistor (typically 4.7 kΩ) to the external input of the prescaler for TMR0. The prescaler input is also connected to an I/O pin that’s initially configured as an input. In that state, the frequency signal is passed to the counter unimpeded.
After a preset time, the I/O pin is set as an output at state 0. This effectively short circuits the frequency signal, so the prescaler stops incrementing. At that point, the TMR0 register has captured an 8-bit representation of the frequency. Now comes the clever part. The I/O pin is toggled while checking for an increment of the TMR0 register. At that point, we can infer the 8 bits that were in the prescaler from the complement of the number of toggles. We can then construct a 16-bit frequency value.
Figure 6 shows the circuitry for the coil multiplexer and the microcontroller. Figure 7 shows the coil connections, while Figure 8 shows the oscillator and the serial port driver. Ideally, a multiplexer is just a switch, and the open-collector transistors of the 7445 integrated circuit should just short the resonance coils to ground. Calculating from the specification sheet, however, shows that the on resistance of the transistors is about 10 Ω. This is a small value when you’re turning on a relay coil, but any resistance added to an inductor in a tuned circuit lowers the resonant “Q.”
The effect of this lower Q is that it takes the oscillator a few seconds to start. Once it’s started, it remains in oscillation while we’re switching from coil to coil. I experimented using a MOSFET, the 2N7000, as a switch, and that works much better, but 16 FETs would be needed. I decided to just have the software pause at power-up until the oscillator starts, thereby eliminating such circuit complexity.
The circuit has a display port implemented as an HD44780 standard parallel interface that’s compatible with a wide range of display types (see Photo 4). I used a 2 × 20 character vacuum fluorescent display, which is a power hog and definitely overkill for this application. I tested the circuit with a typical, inexpensive 2 × 16 LCD, and this type of display is probably a good choice. The serial interface is a DB-9 connection to a PC, and it will also interface with a Raspberry Pi (through an appropriate logic level-shifter), probably with an Arduino, or converted to a USB serial port with one of the many available converters.
Capacitors are generally precise to only about 10% of their nominal value. This low precision, combined with variance in coil construction and coil placement in the carrier tubes, means that the software must be calibrated to the hardware. This is easily done by first positioning the ferrite beads to their lower position, storing the frequency values, then repeating the process with the beads in their upper position. The software is then able to interpolate frequencies to determine the position of the ferrite beads.
Figure 9 shows the average frequency change as a function of the number of ferrite beads on a coil in the lower rank. The nominal frequency of the lower rank coils is 525 kHz when there are no ferrite beads, and 460 kHz when all four beads are present. The nominal frequency of the upper rank coils is 565 kHz when there is no ferrite bead, and 535 kHz when the single bead is present. The putative bead number as a function of the frequency change for the lower rank, as implemented in the software, is shown in Table 1. You can verify oscillation by holding an AM radio close to the coils.
The source code for the abacus data entry terminal, written in PIC Basic Professional, is available on the Circuit Cellar article code and files download webpage. Also available are hex files for using both 20 × 2 and 16 × 2 displays for those without access to this compiler. The software doesn’t require a display, so you can eliminate that from your design if you want a “bare” terminal.
The software waits for oscillator start and checks to see whether the push button was held during power-up. In that case, it prompts the user for its initial calibration routine in which all beads are first placed down, and then up, in their columns. The calibration values are stored in nonvolatile memory, so calibration is a one-time affair. The serial output is arbitrarily set at 2,400 bps, which is fast enough for a manual data entry terminal (see Photo 5).
The circuitry uses a PIC16F877, but the PIC16F877A is presumably a pin-compatible and software-compatible replacement. The only difference is in the way that the flash memory is programmed, something that should be handled automatically by selecting the proper chip in your programming software. The PIC16F877 is a recommended replacement for these microcontrollers, having a few additional functions such as a greater number of analog input channels. The PIC16F887 should work in this application, but some software changes would be needed.
The coils do generate some radio frequency interference, as holding an AM radio tuned to the proper frequency will show. In my unit, however, these signals don’t travel that far, and they are not detected on an AM radio a few feet distant.
Author’s Note: The source code for this circuit, and hex files for burning the object code directly without a need for a compiler, are available on the Circuit Cellar article code and flies webpage. Also included are the CAD files for the printed circuit board and a mechanical drawing of the coil assembly.
S. D’Souza, “Frequency Counter Using PIC16C5X,” Microchip Technology Application Note AN592, 1997, ww1.microchip.com/downloads/en/AppNotes/00592d.pdf.
Microchip Technology, “PIC16F87X: 28/40-Pin 8-Bit CMOS FLASH Microcontrollers,” DS30292D, 2013, ww1.microchip.com/downloads/en/DeviceDoc/30292D.pdf.
PUBLISHED IN CIRCUIT CELLAR MAGAZINE • APRIL 2016 #309 – Get a PDF of the issueSponsor this Article