AWARD-WINNING DESIGN: "Distinctive Excellence Prize" in the "Flash Innovations" design contest sponsored by Motorola Semiconductors
This project describes an innovative multimedia thermometer of great visual impact.
When the system is placed in a shop or mall, logos and product advertisements are a perfect complement to temperature information. For home use, photos of the kids at the beach or –should the temperature drop- in the making of Mr. Snowman are a nice gift for Grandma. Other application areas include hotels, airports, sport resorts, and tourist sites.
Despite of its rich feature set, the DVD-thermometer is an amazingly simple design that requires very few components thanks to an ingenious mechanism. And it is hundreds of dollars cheaper than the typical PC-centric solution.
The circuit is battery operated, and fits comfortably a small plastic box, located in front of an ordinary DVD-player. A switch and an infrared LED peep out of the box. The DVD-player is loaded with a disk, pre-recorded with all of the pictures corresponding to different temperatures, in a well-known order. Acting as an intelligent infrared remote control, the DVD-thermometer directs the player, selecting the scene that matches ambient temperature.
I made the DVD-thermometer at home, for the fun of doing it, with no special tools other than a soldering iron, a multimeter, a PC with ordinary CD-R burner, and the Motorola QT demo board. I submitted it to the "Flash Innovations" Design Contest sponsored by Motorola, and it won the "Distinctive Excellence Prize".
The circuit diagram is embarrassing simple: it is entirely built around a cheap 8-pin microcontroller, a digital temperature sensor and an infrared LED. The hard work is delegated to the software, which is the most important ingredient of the project.
I wrote the program in C, implementing low-power techniques, with code reuse, portability and data encapsulation in mind. As a result, all of the modules reside in separated files, ready to be ported to other applications changing only a few #define.
In the remaining part of this article I will describe how I managed to control a DVD player in order to transform it in a catchy video thermometer.
Even if you are not interested in taking temperatures, the basic techniques can be adapted for displaying any sort of data. They are worth to be added to your bag of tricks, just in case. Along the way, you can collect some very valuable, very reusable software modules, like:
- a versatile programmable pulse generator
- an I2C bus driver
- and a RECS80 remote control transmitter.
Let’s examine the building blocks of the system from the figure below.
A specialized digital temperature sensor IC measures ambient temperature, and converts it in a digital word that can be read by the microcontroller via the I2C bus. The microcontroller does not have an hardware I2C, therefore the I2C driver is implemented in software. This driver works as the foundation for the thermometer chip driver, which in turn is required by the main application firmware.
Another software module makes microcontroller’s internal 16-bit timer to work as a programmable pulse generator (PPG). These pulses are assembled by the RECS-80 remote-control encoder block, in order to drive an infrared LED connected to a port pin. The SLEEP manager module ensures that all the previous blocks are called in a timely manner and no power is wasted in between.
The infrared LED is to be placed in front of an ordinary DVD player connected to a TV screen.
The DVD player is loaded with a special disc, recorded in advance with a sequence of pictures, each showing a different temperature value. If played normally, the disc would show all the temperatures in the thermometer range, from the lowest to the highest.
When the system runs, the main program evaluates continuously ambient temperature.
If it differs from the on-screen temperature, it instructs the DVD driver to change the TV picture. The DVD driver uses the RECS-80 embedded remote control to direct the DVD player to the appropriate position. The DVD player cannot tell between a real remote control and the infrared stream it receives from the circuit.
The adjustment is repeated until the temperature seen on TV matches again ambient temperature. As there is no feedback from the DVD player telling the MCU which image it is playing, the microcontroller and the player must start from a well known temperature/picture pair. To ensure that the DVD player will always start from the first picture in the sequence, the microcontroller stops and restarts the disc during startup.
I started the design process reverse-engineering my DVD player remote control. There was no need to open it (fortunately!), because all I wanted to know was how it does encode its various keys. The market is shared among an handful of different infrared modulation schemes, and with a bit of luck the remote control will conform to one of the standards whose documentation is available on-line or on literature .
Although a scope is preferable, I started the design on a rainy weekend, and I cannot get one until Monday. Therefore I decided to use the PC sound card to analyze the signal.
I connected an infrared LED (the same I’m going to use in the final circuit) to the MIC input, in order to use it as a sort of photovoltaic sensor. I placed the remote control in front of it, as close as possible, and watched the signal with a sound editing program. The waveform suffered because of the rude measurement technique, but it was clearly discernible as one of the popular codes described in .
The good news is that the remote control of my IRRADIO DVD player conforms to the RECS80 format. The bad news is that the RECS80 waveform is difficult to encode, because it involves synthesizing pulses whose duration spans many orders of magnitude, from µS to hundreds of mS.
A complete waveform anatomy can be found in . In brief, a RECS80 code word is a sequence of short pulse bursts:
While you are still observing your remote control waveform, I suggest you to take note of the key codes involved in the DVD scene selection process. I guess there are some standard tables somewhere, but as there are only four keys to use, I found convenient to transcript their binary values watching the emitted waveform. After the start pulse, every short pause means a “0”, whereas a longer one means “1”.
Photo 1 highlights the keys of interest. The “NEXT” key skips to next scene in DVD sequence, opposite to “PREVIOUS” key which gets back to the previous one.
The “NEXT/PREVIOUS” pair is all it is needed to search for a specific picture from disc. Another couple of keys are useful during startup, because the software uses them as a sort of reset, forcing the player to always start from the first scene on DVD disc. In the case of my DVD player these keys are “STOP”, which stops disc playing, and “PLAY” that, once the disc is stopped, starts playing the disc from its beginning.
With just eight parts and a battery, the hardware can hardly be simpler. Circuit optimization is a corollary coming straight from the level of integration of its main components.
The temperature sensor IC is either a DS1621 or DS1631 (Maxim). This 8-pinner includes a complete digital temperature sensor/thermostat with I2C output. With the appropriate commands, the temperature can be read from the serial interface with a guaranteed accuracy of 0.5 °C, and a resolution of up to 0.1°C. It does not require calibration, which is advantageous because you can trust your thermometer without messing with ice and boiling water.
Its pin 3 can work as a thermostat, but this feature is unused in this application. Pins 5...7 determine the low bits of the device I2C address (up to 8 sensors can be connected in parallel on the same I2C bus); setting the connections as shown configures the device to respond at address 0x90.
The MCU is the Motorola MC68HC908QT4, a tiny 8-pin device with 4 kB of flash and 128 bytes of RAM. A nice characteristic of the QT is that all of its pins (except power) can be used as I/O, as proper reset is guaranteed by means of internal brown-out circuitry, and a flash-calibrated internal oscillator provides a reasonably stable clock source.
Timing precision is important to get correct remote control waveforms: the 1% spec for the internal oscillator is not far from the accuracy of ceramic resonators, which are commonly employed in most remote controls.
Two I/O pins serve as I2C bus data and clock. All QT pins feature programmable pull-ups, so external resistors on the I2C bus are unnecessary.
Another I/O port drives the IR LED (ports can source up to 25 mA) through a current limiting resistor. Peak current is set to 8 mA, much lower than a “real” remote control, because the device is designed to operate in close proximity of the DVD player.
Rather, excessive LED power may interfere with other IR devices in the same location, e.g. air conditioners, TVs, VCRs, DVD players and others electronics goods commonly found in homes, offices and shops.
The circuit will not add just another cable to the AV tangle: it is battery powered. Four AA cells supply a total of 6 volts. Notably, a voltage regulator is unnecessary, but if you feel uncomfortable powering chips close to their maximum tolerable voltage you can always add one. I found an electrolytic capacitor an two filter capacitors are enough to provide clean power.
A very useful feature of the QT MCU is hardware support for one-pin ICD (in-circuit debug), making an emulator unnecessary for most developers.
A QT chip programmed with a tiny user-monitor allows the user to load application programs, place breakpoints and watch variables with almost no overhead for the program running. ICD mode requires just one pin (PTA0) for data transfer, a pushbutton to keep PTA2 grounded during reset, and a trivial interface for the PC serial port: see   for a circuit schematic (compatible with the DVD-thermometer) and detailed programming explanations.
However, if this is your first project with an HC908 MCU, it is simpler to start from a part with the user monitor already programmed and known-good hardware, as the cheap M68DEMO908QT4 starter kit.
With minimal hardware, most of the hard work has to be done in software. I developed the software with the free Metrowerks Codewarrior integrated development environment. The IDE includes an assembler, ANSI-C compiler, simulator, chip programmer, in-circuit emulator/debugger, and even an automatic C-code generator named Processor Expert.
I selected C-language to make the code more reusable and flexible. By the way, I had some I2C sources coming from a previous application on a different MCU.
I like a quite formal programming style. When time allows, I do my best to write structured code, using #defines to name every constant, banning global variables, partitioning the code in “.c” modules and “.h” header files.
Source-file names reflect quite closely the elements in the block diagram, as shown in the screen capture from the IDE window (below).
The flow chart illustrates the selection algorithm. The DVD module keeps track of which image is currently displayed, starting from number 0 during initialization. If the image to be selected follows (precedes) the current one, the disk is advanced emulating the NEXT (PREVIOUS) remote control code.
The main application (main.c) includes some initialization code for port register setup and void interrupt routines. During the startup phase, it calls the initialization procedures of the DVD driver and thermometer respectively. Each driver handles its initialization hierarchically, e.g. the thermometer routine DS1621_init() calls in turn I2C_init() to initialize the I2C pins.
Once the system is up, the main control loop begins:
--> first, check if the battery has enough juice by reading LVI register.
--> If not, use the remaining energy to select the “battery low” message from the DVD pictures (I arbitrarily placed it as the last image in the sequence).
--> Otherwise get ambient temperature, subtract the lowest temperature possible to get an index that starts from zero, and use the index to select the image.
The “DVD.c” module provides the scene selection facility: for example, call: DVD_select(25) to show the 25th scene. To ensure that disk playing starts from the first scene, DVD_init() stops and restarts the player emulating the respective remote control keys.
A distinct file (remote.c) implements the RECS80 remote control encoder. To make the IR LED flash the PLAY command, just call: remote_control( KEY_PLAY )
I defined codes for the STOP, PLAY, NEXT and PREVIOUS keys. The routine can generate any other code given its binary value, and swaps automatically the toggle bit each time it is called. Each code is repeated 5 times to ensure it is received correctly.The module “DS1621.c” is the thermometer driver. It is in charge of initializing the chip registers and the I2C bus, and to make temperature readings. It carries out these operations issuing short sequences of I2C commands.
I tried to make them as easy to read as possible, but for a complete comprehension the DS1621/DS1631 datasheet –and familiarity with I2C bus concepts- is definitely necessary. If you don’t have the time to read the datasheet, just call: DS1621_temperature() to get the current temperature in °C.
If you need higher resolution, uncomment the lines in the code to get 1/10 °C readings. Notably, the software does not need to convert Celsius to Fahrenheit for use of the thermometer outside Europe: all you need is a different DVD were °F pictures replace °C temperatures!
The software emulates an I2C bus toggling two I/O pins. When speed is not a concern, software implementations like this one are perfectly adequate.
I ported the “I2C.c” code from a “bigger” processor: all it was required was to provide methods to set and clear SDA and SCL pins, to change data direction and to activate pull-ups. All of this was done with macros, so I accomplished the task in minutes. I didn’t need to adjust the waiting loop, although it can be necessary in case you port the code to very fast (or slow!) processors.
Once recompiled, the driver worked like magic providing the I2C primitives for communicating with two-wire peripherals: I2C_start, I2C_stop, I2C_tx_byte, and I2C_rx_byte.
The file, “sleep.c”, provides a function to put the processor in STOP mode for a given number of seconds. The sleep function is called from different modules, therefore I placed it in a separate file. As the delays are based on the wake-up timer, times are approximate. To have the processor take a one-minute low-power nap, just call: sleep(60);
I’m very satisfied by the RECS80 encoder implementation:it looks very clean and straightforward (see listing below). The secret is in the use of a PPG (programmable pulse generator) that works in background under interrupt control, doing all the magic transparently and allowing for a straightforward definition of the encoding scheme.
Should your DVD use an infrared code other than RECS80, implementing the new scheme shouldn’t be too difficult for the xperienced C programmer.
On the contrary, the PPG module “pulse_gen.c” is rather complex and I will describe it separately.
The usual way of generating remote-control pulses with small controllers is by bitbanging, that is flipping pins directly, in a carefully timed software loop. This solution is far from perfect, the main defects being its poor resolution and inherent dependency from code. Even touching a single line of code inside the loop can ruin completely the output waveform.
The excellent 16-bit timer module of the QT processor called for a more elegant solution than crude bitbanging. The result is the versatile programmable pulse generator (PPG) contained in the source file “pulse_gen.c”.
It can generate pulses with user-defined frequency, number of pulses and duty cycle. This is ideal to handle the 8.77 S LED flashes. The user can also specify to disable the output but keep the timing, in order to generate pauses with the same resolution, to handle the 5.06 mS, 7.6 mS and 0.12 sec gaps required by the RECS80 code.
The PPG is easy to setup and use (see listing above). It is interrupt-based and synchronizes itself for pending requests, therefore it frees the main program for other tasks while working in the background. This feature is beneficial when writing the infrared encoding routine, because leaves plenty of time to the processor to compute the pulses that come next.
I started from a working example that I created with Processor Expert, adding its PPG bean. I studied the computer-generated code in parallel with the datasheets, to get familiar with the details of the timer module, before starting to write my own code.
My incarnation of the PPG is very different from the PE code.
It requires to first set up the desired frequency and duty cycle with a call to:
The purpose of this function is to set the PWM registers, and it does not modify the PPG output. A call to ppg_set can be issued at any time, because it will automatically wait for the completion of a previous cycle should the PPG be running. The PPG is running whenever TSC_TSTOP is zero.
To start pulse generation requires a call to:
This function triggers the PPG to generate count pulses (up to 65535). The second parameter tells the PPG to toggle the output if set to 1, or to leave the output unchanged if set to 0. Setting mode to 0 is an effective way to generate pauses synchronized to the main PPG frequency instead of pulses. It that case, count specifies the pause length expressed as cycles of the PPG frequency.
It is remarkable that, if no previous requests are pending, ppg_pulses returns to the main application almost immediately.
The purpose of this function is to load a cache buffer with the pulse parameters, and to start the timer if it was not already running. It then returns to the calling application, which gets plenty of time to prepare the next pulse burst.
Successive calls to ppg_pulses join and synchronize seamlessly. This feature allows a very straightforward coding of the remote control encoding routine of Listing 2.
Once the timer runs, the waveform generation is handled by the timer overflow interrupt service routine.
It is more complex than it looks at first sight.
Timing is crucial, as a 38 kHz pulse takes only 26.3 µS, which leaves little time for counting pulses and flipping bits. The situation gets even worse when working in user monitor mode, because of the overhead involved with vector’s redirection.
At every interrupt, the handler checks the pulse ticks counter to determine if it is the last pulse.
--> If not, it decrements the counter and returns.
--> Otherwise, it checks the cache buffer to see whether more pulses are scheduled or not.
In the former case, it reloads the tick counter and sets the mode of operation for the output pin. In the latter case, it waits for the current pulse to end, testing the status of the output port pin, and resets the output mode to no-pulse generation. It finally stops the timer. Note that stopping the timer stops overflow interrupts as well.
Fortunately the user doesn’t have to known all these complex details to benefit from the PPG, which is encapsulated in a C module and can be called transparently.
The disk is an essential part of the system, as well as the images, videos, animations and sounds to be recorded on it. I will skip the artistic part of the process, focusing on the technical aspects of the procedure.
Of course, you can use your favorite video editing and recording software to burn the disk. Strictly speaking, if it can burn a disk with a sequence of images that your DVD can browse back and forth with the NEXT and PREVIOUS keys, it is OK.
I searched for the easiest way to record a test disk. A DVD burner is unnecessary. If your thermometer doesn’t require the full 4.7 GB capacity of a DVD, a common and cheap CD-R burner is sufficient.
I have used CD-RW media in order to perform different experiments recycling the same disk. In this case, you must ensure that your DVD-player can read CD-R or CD-RW disks. There are some players that can read only CD-RW media and refuse CD-R disks.
I prepared a set of 62 frames, each stored in a separate JPG file on the PC hard disk, representing a temperatures from –10°C to +50°C, plus one frame with the message “battery low”: you can download this picture set following the link at the end of this article.
Recent DVD players can play automatically JPG and MP3 files located in the root directory of a CD-R or CD-RW disk. This is definitely the easiest way to get started with the DVD-thermometer, and it is worth a try!
Unfortunately, my DVD player refused to read such a disk, so I made a second attempt recording the CD-RW disk in the Video-CD format. This method worked well.
I prepared my disk with Nero Burning Rom 5.5, a popular software for burning CD-R’s. It features a CD-R wizard that makes the process a piece of cake.
Click on the File>New menu. The “New Compilation” window appears. From the left banner, select the Video-CD format, don’t touch the defaults (except deselecting thumbnails generation if enabled) and confirm the New Compilation clicking on the “New” button.
The program continues with the familiar selection of the files to be included on the disk, with an Explorer-like directory tree interface. Drag and drop all your 62 JPG files on the new project, paying attention to the order: the first file you drop must be the first file that should appear in the final sequence.
Multiple selection and cut-&-paste work, provided that you select the original files in the right order! I suggest you to give the files a name that can be sorted alphabetically; then sort the folder by file name and do a multiple select dragging the mouse from top to bottom.
That’s it. Clicking on the “burn” icon, the program will format the disk according the Video-CD specifications, creating all the necessary support files required by the DVD-player. I recommend you to choose the lowest possible burn speed. When you’re finished, test it (manually) verifying that the DVD player can read it and that all of the images are in the correct sequence. Please ensure also that you can pass from one another just pressing the NEXT or PREV keys on the remote control.
This is also the best time to read the DVD-player's user manual, in order to discover the procedure for disabling the OSD (on-screen display), which can be annoying for this application.
The circuit is quick and easy to assemble on a piece of perf board, and requires no calibration. You can see my prototype in Photo 2. The system must work immediately after placing the disk in the player, the circuit in front of it, and switching on both the player and the thermometer.
The system impression of the DVD-thermometer is superb, with multimedia capabilities unparalleled by current thermometers. It is inexpensive too: with DVD-players prices starting at $49.99, using a DVD player as a sort of graphic front-end is reasonable. An alternative PC-based solution costs much more, consumes more power, it is a lot more complex to setup and upgrade, and immensely less fun to design!
The basic idea can be adapted to a variety of practical situations. The application as a public thermometer for hotels, malls, showrooms, stations, airports and tourist sites is straightforward.
Thermometers per se are unquestionably useful, but the multimedia impact and low cost of the DVD-thermometer prospects new uses, especially when the possibility of adding advertisements is considered.
Potential applications include talking “Please-take-a-number” displays, interactive product selectors (e.g. to select the right glue or paint, or to see how a new drill works), and colorful, dramatic displays for any sort of measurement.
You shouldn’t face any difficulty using the circuit as a building block for other projects. The “C” software it is structured and modular, in particular the PPG module performances are excellent. Its cache-based algorithm allows for an unusually straightforward implementation of the remote control encoder routine, capable to be adapted to most of the encoding schemes currently on the market. Should you write a driver for a different DVD-player brand, please e-mail it to me so that I can share it with other interested readers.
This design is also a great candidate for class experiments. It is instructive and can be used to teach many topics as theory and practice of microcontrollers, programming languages, serial (I2C) busses, sensors, remote controls, waveform generation, all the way up to the process of creating and preparing multimedia content.
Young and open minds working on simple everyday technologies can make wonders: I look forward to see what they can get out of a bit of silicon!
(Requires an ftp-enabled web browser, e.g. IE6. Alternately, please login to: ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2004/168/Ricc_Bitti_168.zip )
Sample pictures (°C scale only) used for preparing a test disc.
(Requires an ftp-enabled browser, e.g. IE6. Alternately, please login to: ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2004/168/Bitti_DVD_disk_pictures.zip )
You might want to take a look to these thermometer projects: the PC-therm and the Scriptherm
 A. N. Other, “IR Remote Control codes”, Elektor Electronics, March–April 2001
 Philips semiconductors, “SAA3004 Remote control transmitter” Data Sheet, August 1982
 Jim Sibigtroth, “User Mode Monitor Access for MC68HC908QY/QT Series MCUs”, Motorola Application Note AN2305, July 2002
 John Suchyta, “Reprogramming the M68DEMO908QT4” Motorola Application Note AN2322/D, August 2002
68HC908QT4 Microcontroller - Motorola Semiconductors Inc. http://e-www.motorola.com
DS1621 – DS1631 Digital temperature sensor - Maxim semiconductors www.maxim-ic.com
Metrowerks Codewarrior Development Studio for HC08 microcontrollers Special Edition www.metrowerks.com