Temperature Recorder with eZ430-F2013

From Texas Instruments Wiki
Jump to: navigation, search
eZ430-F2013 Temperature Recorder

Office temperature is often a source of contention. After a complaint is made, it may take hours for someone to show up and by then, the temperature has changed. But traditional temperature recorders are expensive and rare. The Texas Instruments (TI) MSP430F2013 in the eZ430-F2013 development kit can work as a low cost ($20) temperature recorder.


Operation

Measuring Temperature

Plugging a modified MSP-EZ430D board, the size of a quarter, into a LiON battery flashes the green LED three times over 40 seconds letting you know the battery is good and the part is working. Then it begins writing the temperature to FLASH. Put the battery and microprocessor in a draft-free container like a pill holder, with the starting time and date. FLASH memory holds 281, run-length encoded records with a byte counter for the 8.02 seconds time intervals. Unlikely, it could be filled in 38 minutes to a maximum of 6.5 days. One office test ran 4 days and still had free FLASH remaining.

Stopping

When FLASH is full, it lights the LED and removing the battery leaves the temperature data in FLASH. To flush the current run-length buffers, change the temperature over a minute by holding it in your closed hand or putting it in a cool space for a minute.

Temperature Report

Reporting the temperature requires plugging the MSP-EZ430D target board into the MSP-EZ430U debugging interface and using the IAR Embedded Workbench Integrated Development Environment (IDE) to transfer the time and temperature data to a log file. This log file is loaded into a spreadsheet to plot the results.


Schematic

  Schematic-Temp Sensor.PNG

Project User's Guide

Install eZ430-F2013 Kit

Using the CDROM in the kit, install the software and plug in the MSPEZ430U USB debugging device. Windows will prompt to install the USB device driver.

Configure IAR Workbench

Plug in the USB debugging device and start the IAR Embedded Workbench. Click on “Create new project” and enter a name for the pop-up and “Save As” field. After it starts, highlight the project name and use the “Project” pull-down for “Options.” These options setup the IAR system to work.

  1. General Options -> Target -> MSP430x2xx Family -> MSP430F2013 – establishes the memory and interface map and generated code.
  2. General Options -> Library Options -> Printf -> Small
  3. Stack/Heap -> Override default -> Stack size = 80 – nominal stack to support printing the results.
  4. C/C++ compiler -> Optimization -> Size = “High (Maximum optimization)” – needed to keep code as small as possible when resetting the MSP-EZ430D target board.
  5. Linker -> List -> Generate linker listing -> Segment map -> Module map – protects the recorded time and temperature data.
  6. Debugger -> Setup -> “FET Debugger” – to enable USB
  7. Debugger -> FET Debugger -> “Retain unchanged memory”
  8. Debugger -> Connection -> TI USB FET – sets the USB device interface.
  9. Add a “file” to the project with the source code for “temp_recorder.c”. You can load it from:

Source Code

“Rebuild” the code and enter “debug” mode with the USB debugger plugged in. Then under “View” select “Terminal I/O” which is used to display the data. You can close the source file window and disassembly windows and expand the “Terminal I/O” window. Before dumping the data, use “Debug” and select “Logging” to “Set Terminal I/O Log File.” This file will hold the saved data. Use the file options to save the log file where you can find it easily. Once you exit the debugger, you are ready to dump the time and temperature data.

Dump the Time-Temperature

  1. If the LED is ON, the FLASH is full so remove the MSP-EZ430D board from the battery and install it on the USB debugger.
  2. If the LED is off, you may want to flush the last temperature values from RAM to FLASH by holding the MSP-EZ430D and battery in your hand for a minute. The change in temperature will write the last values to FLASH. Then move the MSP-EZ430D to the USB debugger.
  3. Start the IAR Embedded Workbench and “Open the Existing Workspace” project.
  4. Select the project and check the “FET Debugger” option to make sure it is on “Retain unchanged memory.”
  5. Enter Debug mode and verify the “Terminal I/O” window is up and “Log file: On”.
  6. Hit the three arrow “Go” control and watch the time and temperature display on the terminal window.

Each line has an “interval” counter, a comma and “temperature” in 10ths of a degree Fahrenheit. Let it run until it stops. Then exit the debugger. Until you refresh the FLASH memory, the data will remain in the MSP-EZ430D.

Reporting Time-Temperature

Using a spreadsheet, load the comma separated values from the Terminal I/O log file. Every pair of lines has an interval counter and the same temperature. The time counter is how many 8.02 second timer intervals for that temperature.
For example:

  1. 0,776
  2. 10,776
  3. 10,768
  4. 15,768

The first temperature interval lasted to 10*8.02 seconds, 80.2 seconds at 76.6F. The second time interval started at 80.2 seconds to 15*8.02 or 120.3 seconds at 76.8F.
Once you have the data in a spreadsheet, use the starting time from the slip of paper and calculate the remaining time values from the offsets and divide the temperature by 10 to degrees Fahrenheit. This will give you two columns with time and temperature to plot the data.
For example:


ExamplePlot.PNG

This example shows the temperature plotted from room temperature to a thermos of boiling hot water. Cold water was added to bring the temperature down and then the watertight container was removed back to room temperature. Meanwhile, the thermos was drained and ice from the freezer put in the thermos and the container put back in the thermos. Eventually the ice began melting, I pulled the temperature recorder out to add more water and put it back in. Finally, it was left on the table to warm.

Reset Recorder

To reuse the temperature recorder for other measurements, modify the project option, FET Debugger, to “Erase main and Information memory.” Then entering debug mode will reload the code and reset the FLASH for the next temperature measurement.

Room Temperature Graph

The following graph was recorded from 10:00 AM Monday morning to 10:00 AM Friday morning at my desk. The initial drop in temperature came because I had carried the unit in a pocket but it rapidly cooled off once plugged into the battery. The office temperature problem was the system wasn’t turned on until 8:00 AM instead of an hour before the official work hours. With the data, we contacted facilities and since then, the morning office temperatures have improved:

RoomTempGraphExample.PNG


Builder's Guide

Principles of Operation

The MSP430F2013 has a 16-bit ADC with a built-in temperature sensor but it needs a 32.687 kHz watch crystal to keep accurate time. The 16-bit RISC processor has 2 kB of FLASH and 256 B of RAM. The FLASH memory holds both the software and data.

Hardware Modifications

A proof of concept, this is not designed for mass market production but something anyone could on their own. The schematics and physical MSP-EZ430D drawings came from the Texas Instruments documentation and are used to show the modifications needed.

Adding the Xtal

The first step is to add a watch crystal to the MSP-EZ430D.
  Schematic-Temp Sensor.PNG

The VCC needs to between 3.6-2.2 VDC. The 2.2 VDC lower limit is needed to support writing to FLASH. The watch crystal with grounded case needs to go on pins P12, P13 and P14.

TargetBoardF2013.PNG 

The board sketch shows the typical placement of the watch crystal. This location minimizes the height. Although the prototype was not conformal coated, it is recommended if going into a condensing environment.


The following photo shows the watch crystal installed on the MSP-EZ430D:
  EZ430D.PNG

LiON Battery - 2032

Any 3-3.6 VDC battery can provide power for the MSP430F2013. In our example, a bead of epoxy spackling is used to hold the B+ and ground wires as a low cost connector. A paper washer separates the epoxy from the connector during the cure.
  EZ430Dmodified.PNG

The wire loop is cut, a piece of heat-shrink is put over the ground wire and a solder bead i.e. put on each end. Bend the wire leads 90 degrees at the connector and put a drop of clear epoxy to hold. Finally, a 1/2-inch piece of clear heat shrink holds the homemade connector to the battery.

Note that the MSP-EZ430D can work connected to the USB debugger interface. However, this potentially exposes it to laptop heat and the USB debugger is temperature limited to 80C.


  TempSense.PNG

Software

The software consists of a main routine that handles initialization and later, printing the results. The watchdog timer is configured as an interval timer driven by the watch crystal and it initiates all measurements. The SD16 interrupts update the RAM cached, with the run-length encoded time and temperature records.

Routine – main

Entered from a power-on reset, RAM is zeroed and all interfaces are in their default state. Main converts the watchdog timer into a watch crystal driven, interval timer running at the slowest possible rate, 8.02 seconds per interrupt. The main routine finds the free FLASH memory after the code and checks to see if it is unused. If it is unused, it enables the DCO timer for FLASH memory writes. Finally, it enables the LED for the first time interval and goes into LM3, low power, sleep mode. The interrupt service routine will flash the LED three times as it completes initialization. If the FLASH memory has been written, it begins printing out the run-length encoded time and temperature values. This requires the USB debugger to be plugged in and the Terminal I/O window open and logging the results.

Routine – wdt_vector

The watchdog ISR initially loads a five element, Gaussian filter array with the temperature measurements. As each entry is read, the LED changes, flipping from ON-to-OFF and back. This generates three 8.02-second LED flashes indicating the battery and processor are working. Once the first FLASH word is written, the flashing stops. The watchdog timer works as an interval timer and calls routine start_adc to measure the built-in temperature sensor. Once the ADC measurement is started, it dismisses the interrupt and goes back to LPM3 sleep while the SD16 works.

Routine – sd16_vector

This routine gets the temperature reading and then measures the “zero” value. The “zero” value is subtracted from the temperature measurement and then it is scaled by shifting and the random, low order three bits removed.

Routine – gaussian

This routine adds each new temperature to a five cell, Gaussian filter. This filter smooths the data yet preserves the local peaks. It essentially extends the resolution as close to the thermal noise range as possible. The results are then sent to routine flash.

Routine – flash

The flash routine maintains three run-length encoding buffers. These hold the current lowest, middle and highest temperature values with a byte counter for how many samples came in with each value. Any value that matches the current low, middle or high temperatures simply increment the run-length counter.

When the byte counter is ready to wrap, the buffer is written to the next free FLASH memory word as a byte counter and byte temperature value. Should a new low temperature arrive, the current high temperature buffer is scheduled for FLASH write; the middle becomes the new high; the former low becomes the new middle; and the new low starts a new low record. It shifts the run-length buffers up and writes the former hot record. A new high temperature shifts the run-length buffers down and writes the former cold record.

Errata

  1. The initial calibration of 32F in an ice water batch was done with the USB adapter on an extended USB cable. Subsequent tests on battery power reports the ice water bath at 28F. This suggests calibration may need code to deal with different voltage levels.
  2. One USB FET Debugger was destroyed by high temperature in a steam filled thermos. The last recorded temperature was 158F.
  3. The MSP430F2013 survived a 100C, boiling-water-filled thermos on battery power.
  4. The LiON batteries have a narrower operational temperature range than the MSP430F2013 but the power drain is so low that this does not seem to matter.
  5. The Digitally Controlled Oscillator is used to generate the 256 kHz needed to write to flash. It isn’t clear if this can be turned on and off at will.
  6. By accident, FLASH was once written using the 32.687 kHz clock. The specifications say it should not be done but we don’t know what the effects would be nor do we know the power required to write to flash.
  7. When the FLASH is full, the LED turns solid green but this wastes battery power. A better approach would be to flash the LED but that takes code and reduces the available memory. Batteries are cheap compared to the data.
  8. The current print routine library takes FLASH memory and can be replaced by a lower footprint software interface. However, this would require a more complex output reader like a photo-diode detector on a serial line.


Project Files

Temperature Recorder Source Code

Bill of Materials


  BOM.PNG

The homebrew, epoxy connector can be replaced by a Mill-MAX, single-row, .050” grid interconnect, Allied Electronics part 900-2000, $5.18, enough for 10 cells.

The heat-shrink, coin cell holder could be replaced by a coin cell specific holder. Typical prices are ~$1.00 each from Allied Electronics but need to be matched to the specific coin cell and end packaging.

A water tight, metal pill fob with internal ¾” diameter, 19.5 mm, is available from local pharmacies for about $5.00 for (See [1] ). Even without a little sandpaper trimming, it will fit but a smaller than 20 mm diameter button cell will be needed.