A tachometer is a device that measures rotational velocity. This is a useful tool in robotics, as the speed of the spinning wheel translates into the speed and distance that the robot travels.
Back and front of tachometer printed circuit board
Except for the sensors, the tachometer device is contained on one 4-inch by 4-inch, double-sided, homemade printed circuit board. The photodetector and temperature probe are currently installed on a solderless breadboard for easy prototyping.
The heart of the tool is a 68HC908KX8 microcontroller. This inexpensive (under $5), powerful MCU allows the device to be a combination electronic tachometer, counter, and temperature gauge. Most of the work is performed in software. (To improve performance, I should have also used a comparator chip.)
The display consists of six numeric LEDs. Each of the LEDs has eight segments, allowing numbers and some letters. Although less versatile and more current hungry than LCDs, the LEDs are bright and easy to see from even across a room.
Robot Room startup
When the device is turned on, it shows “robot” and “room” as best as it can.
Tachometer displaying rotational revolutions per minute
In tachometer mode, the RPM (revolutions per minute) of a wheel or motor shaft are measured.
Motors attached to various contrasting surfaces
The surface to be measured can vary from a half-black/half-white circle, to a dark bar, or even a white strip of paper. It doesn’t matter, as long as the light arriving at the sensor varies from bright to dim.
In practice, strips or bars end up creating fan blades, the load of which slows down the maximum speed of the motor. At slow speeds, the width of the dark or light band isn’t significant. But at high speeds (above 2,500 RPM for this device), a half white / half black circle provides more time to notice the change in states.
The upper limit is potentially 99,999.9 RPM, but it’s only been tested to 5,500 RPM so far.
Movie of a fast DC motor slowing down.
(My lovely and supportive wife wants everyone to know that she shot the above movie.)
Notice that the final number doesn’t change after the disc stops moving. That’s because the device measures the time between the start of bright pulses. Even though a human can see the disc has stopped, the electronics are waiting for another pulse.
Although it could be programmed to give up at a certain point and set the display to 0.0, it’s better to wait for a follow-up pulse so that really slow rotations (down to a tenth of an RPM) can be measured.
My original algorithm counted pulses in a 1/1000-of-a-second period and scaled up to determine RPM. It wasn’t useful below certain speeds and it always scaled in integer amounts. At a ChiBots meeting, Brian Schwartz suggested the following superior algorithm currently in use:
Years later, I perfected a hybrid algorithm for the Mill/Drill RPM tachometer.
Movies: Black bar attached to a gearhead DC motor (left). White strip of note card attached to a fairly slow DC gearhead motor (right).
In light detection mode, an ultrabright red LED emits light and a phototransistor detects the reflection.
The 68HC908KX8 microcontroller’s built-in ADC (analog-to-digital converter) converts the voltage into a digital value from 0 (darkest) to 255 (brightest).
ADC value of phototransistor
The dash ('-') at the right side of the display indicates that brightness is being displayed. The dash doesn’t represent a minus.
A pair of potentiometers allow the non-contact tachometer and counter to operate in nearly any lighting conditions against a wide variety of targets.
By adjusting the knobs, the minimum value for “light” bands and the maximum value for “dark” bands can be configured. This means there can be a “gray” zone that is ignored, which greatly improves accuracy and reduces spurious counts.
The minimum for a bright value
The maximum for a dark value
Any time the knobs change by more than a few values, the displays automatically switches over to show the value being adjusted.
Left: Seeing light. Middle: Seeing dark. Right: Seeing neither.
A pair of LEDs indicates whether the sensor currently sees light (green LED), dark (red LED), or neither (both off).
Actually, there’s a fourth case. When both LEDs are on, it means the sensor sees something that the potentiometers label both dark and light! (Light prevails.) The potentiometers have been set incorrectly, with the dark potentiometer set to a brighter value than the light potentiometer. This may lead to less accurate results because there isn’t any gray zone.
The circuit counts changes of light to dark to light again. Basically, anything that interrupts the photoreflector or photointerrupter pair can be counted. For example, a spinning disk, ribbon of components, or even waves of a hand.
Count of light to dark transitions
Over 16 million (24-bit number) counts can be retained before rolling over. However, values greater than a million are displayed as 999,999.
Movie of counting total rotations of a fast DC motor.
Years later, I created a dedicated counter device for analog and digital signals, including motor encoders.
Counting continues in the background, even when other information is being displayed (such as temperature or tach).
Counter initialized to zero
Pressing a button on the board while the counter is displayed resets the counter to zero.
A thermistor significantly changes in resistance in a consistent manner as temperature changes. The KX8’s built-in ADC converts this into a digital thermometer.
Temperature in Celsius
The value is looked up in a 256-element table to convert it to Celsius. The table is pre-calculated on a PC using the Steinhart & Hart equation.
Temperature checks are regularly performed in the background (even when the tach or counter are displayed). If the temperature passes a hard-coded value, the display automatically forces itself to show temperature to indicate the overheat condition. The original mode is restored by waiting for the temperature to cool below another hard-coded value or by pressing a button.
Movies: Temperature rising from ambient (room) because of a human touch (left). Temperature decreasing because of an ice cube (right).
Temperature in Fahrenheit
If Fahrenheit is preferred, the thermistor’s voltage drop is looked up in a different 256-element table to convert it.
Ten connections must be soldered for each of the six 8-segment numeric LEDs used in the display. Because the pins are tightly packed between resistors and the soldering is performed by hand, a few solder points may fail.
All elements lit in 6-digit 8-segment LEDs
The test mode enables all of the LEDs. The makes it easy to make sure they’re all working. It also allows peak current to be measured, which is around 400 mA!
Because the display takes so many pins and so much current, the LEDs can’t be driven directly from a microcontroller. Six, surface-mount, 74HC595 chips actually retain and power the display.
The 595 is a great 8-bit serial chip because data can be shifted in without affecting the existing output. All new data is then switched over at the same time. The 595 can also be daisy chained. In this case, 48 outputs are controlled with only three wires (data, clock, and latch).
The HC595 can supply up to 9 mA each if all eight segments are lit. The worst-case minimum voltage is 3.7 volts in common cathode mode.
One of the greatest things about modern microcontrollers is the ability to quickly modify the software stored within their integrated FLASH ROM memory. The date of the installed version of my code is displayed in year/month/day format.
FLASH software version
The KX8 is a wonderful little 8-bit microcontroller. It has 192 bytes of RAM and 8K of FLASH for programs. 13 I/O pins include 4 analog-to-digital converters (ADC) and 2 pulse-width modulators (PWM).
KX8 microcontroller
Crystal and canned oscillators are usable, but it runs at up to 8 MHz using a built-in clock generator! That’s right, program this baby and pop it into a circuit without any additional components.
Thoughtfully, the manufacturer packaged this in an old-fashioned 16-pin DIP format for hobbyists and experimenters. A robot builder’s dream. (SOIC is available for Mario.)
While developing the tach circuit, I placed the DIP in a wire-wrap socket and placed that into the PCB socket. The height of the wire-wrap socket makes the microcontroller really easy to remove by just yanking the whole thing out (wire-wrap socket and MCU) by hand instead of with a chip puller or a screwdriver. Also, pins can be accessed with a micro clip for testing.
A few months after this was created, out came my second-generation board.