![]() |
David Cook ROBOT ROOM™ |
|
| home | projects | contact | copyright & disclaimer | books | links | ||
|
Digital Numeric LED Displays Tachometer (RPMs), Temperature, and Counter
|
![]() Back and Front of Tachometer Printed Circuit Board Except for the sensors, the 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 test 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. ![]() Optical Tachometer In tachometer mode, the RPM (revolutions per minute) of a wheel or motor shaft are measured.
The surface to be measured can vary from a full 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. (My lovely and supportive wife wants everyone to know that she shot this 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:
![]() Light Detector 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). The dash ('-') at the right side of the display indicates that brightness is being displayed. The dash doesn't represent a minus. ![]() ![]() Light Minimum and Dark Maximum 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. Any time the knobs change by more than a few values, the displays automatically switches over to show the value being adjusted.
![]() 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. ![]() Counter 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. Over 16 million (24-bit number) counts can be retained before rolling over. However, values greater than a million are displayed as 999,999. ![]() Counter Reset Counting continues in the background, even when other information is being displayed (such as temperature or tach). Pressing a button
on the board while the counter is displayed resets the counter to zero. |
![]() Temperature in Celsius 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.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. |
![]() Before I knew that the Steinhart & Hart equation existed, I tried to determine the formula myself using the table on the back of the part (271-110) I used. Of course, I didn't figure out the formula, but I did notice that the rate of change between values was in error in the printed table. The Shack made an oops! 90 Celsius should be 1.266, not 1.366. |
![]() Temperature in Fahrenheit If Fahrenheit is preferred, the thermistor's voltage drop is looked up in a different 256-element table to convert it. ![]() Numeric LED Test 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. 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. |
![]() Software Version 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. ![]() 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). 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. Second Generation A few months after this was created, out came my second-generation board. |