Simple and cheap temperature logger: v2.1 [UPDATE: EEPROM in BOM corrected (SST25WF080) ]

Hi everyone!

It’s been too long since the last update. But it’s there! The last version of the temperature logger, the hardware and the source code.

USB-Temperature-Logger---Component-side

USB-Temperature-Logger---Battery-side

The changes since the last version:

Hardware

  • New footprint for the PIC18F26J50, easier to solder.
  • Only 0603 or bigger resistors/capacitors.
  • The serial EEPROM is now a SST25WF080, still 8Mb, but easier to source.
  • Some components price-optimized (USB connector, switch, 3.3V reg).

Software

  • Each logger can get a number, shown in the mass storage device drive name: simply add an asterisk (*) followed by the number you want to assign to the logger (between 0 and 65535) in the config.txt file (after the logging period), save the file and format the logger.
  • Bug fixes in the FAT12 functions, but the logging space is still limited to the half of the EEPROM.
  • Other bug fixes (month and year change, added robustness). The memory and the EEPROM are now scanned when you plug the logger back, to get the last data and reconstruct the filesystem in the case of a battery failure.

Temperature Logger 2.1: Schematics and basic BOM

The Altium files

The source code (based on Microchip Applications libraries -Device – Mass Storage – SD Card data logger- MPLABX)

I also made a program/debug adapter (especially useful for debugging):

USB-Temperature-Logger-Programming-tool

USB-Temperature-Logger-Programming-tool1This is the “office” version of my previous peg-adapter 😉

A lot of people were asking me if I was selling these loggers. Unfortunately, no. The design and functionalities are sexy, but I don’t have the capacity to launch a production on my own. And if I had do make only a small batch, the price would be totally uncompetitive.

A big thanks for all the people who donated a little something to motivate me!! (or to help me be more ashamed of the lack of updates)

All the contents (except the parts of Microchip’s code in the source) are under the Creative commons license, Attribution – Share Alike – Non Commercial.

Creative Commons License
Simple temperature logger: v2.1 by Jean Wlodarski is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

Advertisements

Designing a simple and cheap temperature logger. Part 7: Schematics, PCB and source code.

I decided to publish all this project under Creative Commons license (Attribution, Derivatives, Non commercial, ShareAlike). The source code contains a FAT12 filesystem that can be reused to make custom flash drives for other projects.

USB Temperature Logger

(PCB version 1.2, hence the misaligned 3.3V regulator to include a diode. Corrected in the V2.0)

USB Temperature Logger 2

USB Temp Logger Schematics

You’ll find the schematics here: Simple USB temperature logger schematics

The Altium files (including a routed PCB) there: Simple USB temperature logger Altium files

The source code (based on Microchip Applications libraries -Device – Mass Storage – SD Card data logger- MPLABX): Simple USB temperature logger source code

The source code could be improved to increase the robustness of the logger (especially in the case of battery power failure while on logging mode). The PCB allows the monitoring of the battery voltage, it just needs to be implemented in the firmware.

I hope my work will be useful to someone!

Don’t hesitate to contact me (mail in the About section) for questions or comments!

Designing a simple and cheap temperature logger. Part 6: Video!!

I just finished developing my USB temperature logger and shot a video showing how it works. Here are the key figures:

  • Up to two months of logging with a single coin cell battery.
  • 30 000 timestamped temperature measurements.
  • Logging period from every 5 seconds to every 24 hours.
  • 0.5°C accuracy, 0.06°C resolution.
  • No driver, no software and no admin rights needed!
  • Compatible with any computer with USB port.
  • Automatic time synchronization with the computer.
  • Low cost design.

When plugged to a computer’s USB port, the logger appears as a normal USB drive. The temperature logging period is changed by editing a config.txt file. When this file is saved, the logger reads the periodicity (in seconds), synchronizes its clock to the computer’s date and time and starts to flash the LED to indicate it’s ready to log. Once removed from USB, the logging is started by pushing the button (the LED blinks three times). For every temperature measurement, the LED flashes.

Once plugged back to USB, the file DATA.CSV will contain all the temperature measurements and the corresponding date and time, TAB separated.

A future development could include a Li-Ion USB rechargeable battery, battery life monitoring, low power – long period logging mode.

If you’re interested by this project, don’t hesitate to contact me. Share if you like it!

Measuring small currents in battery-powered systems

This is a simple method for measuring small currents (μA/nA).

I wanted to see how much current my temperature logger is consuming while in various sleep modes for the various components on the board. I have a good multimeter but unfortunately, its smallest DC current range is 400mA. Even if the burden voltage isn’t that big, it’s impossible to measure anything below 10μA.

As I’m not lucky enough to own one of Dave Jones’ μCurrent I tried to find an other method. I inspired myself of a Microchip App note (AN1416).

The idea is to power a circuit with a charged capacitor and measure the discharge time, thus the current:

I = C*(Vd/t)

Where I is the current(A), C the capacity(F), Vd the voltage drop(V) and t, the time (s).

The method can be easily set up on a breadboard and it’s ideal for measuring small currents that don’t change over time (typically, microcontroller’s sleep modes):

 

Measuring small currentsIt’s better to use a nomally-opened switch, so a push on it will disconnect the power supply and allow the capacitor to discharge.

 

Measuring small currents breadboardIn my setup, I’m using a LM317 voltage regulator to have 3,00V (coin cell battery voltage) at the Vd point when my microcontroller is connected and the switch closed.

At the same time I open the circuit with the switch, I start a timer and usually stop it when the capacitor voltage dropped 0,2V  (2,8V at the capacitor)

For example, with a capacitor of 6600uF (measured), a Vd of 0,2 Volts and 50 seconds to reach it:

I=6600*(0,2/50) = 26,4μA

The value of the capacitor can be adjusted, so you don’t need to wait too long when dealing with nA currents. ex:

Vd=0,1V ; C=10uF ; t=30s : I=33nA

And so on..

To make sure the capacitor internal leakage is not affecting the measure too much, repeat it with no load connected to see how fast the current is dropping. It also allows you the see if the voltmeter impedance isn’t too high.

As soon as I get my temperature logger new PCB, I’ll measure the current in sleep / deep sleep mode for the PIC18F26J50, the EEPROM, the temperature sensor and I’ll post them here.

Designing a simple and cheap temperature logger. Part 5: New prototype PCB.

It has options to be powered by a Li-Ion battery (rechargeable via the USB port, with a MCP73831), as well as by a CR2032 coin cell. There’s an other option for the 1,8V EEPROM SDO line pull-up voltage adaptation.

All the options are selectable by fitting or not 0 Ohm resistors and adding the dedicated components.

In the Li-Ion version, it’s supposed to fit into a case like that (but with a hole for a button and a LED). It’s 19mm x 40mm.

The blue connector is the ICSP program port. I designed it to be “off-snappable”, as it’s connected only by three bits of PCB, where the signals pass.

USB Temperature Logger - Prototype 2 - Face

 

USB Temperature Logger - Prototype 2 - Back

NB: Some of my 3D models aren’t exact (like the battery socket, the 3D model is SMT instead of the through hole I have)

 

Here, an other PCB, Li-Ion only. Just for fun, I wanted to see how small the PCB (19mm x 38mm) can be routed with the components on the same face. On the bottom, there’s only a contact-style connector for ICSP:

Mini USB Temperature Logger - Prototype 3 - Face

 

Mini USB Temperature Logger - Prototype 3 - Back

The components names couldn’t fit on the top side, so I put them on the bottom.

The PCB could maybe get even smaller with a smaller 3,3V regulator, in a SOT23 package instead of the SOT223. The 32,768KHz crystal could also use a smaller package. But here, I hit the limits of the 2 layers, 6mil/6mil routing and I’m not sure some tracks won’t interfere each other.

The prototype on the first two images is the one I’ll be using to continue the software development.

Designing a simple and cheap temperature logger. Part 3: Open collector, FATs and de-debugging.

I had at last some time to work on the project. The prototype PCB is (at least, electrically) functional.

I started with making the TMP102 temperature sensor work. Nothing to say in particular, it’s just an other I2C-small-package-sensor. Or rather SMBus, but apart from the minimum speed clock requirements on the SMBus, the two protocols are alike.

On boot-up, the sensor gets configured and put to shutdown mode. Then, I use the “One Shot conversion” feature. When the right command is sent, the sensor starts a one-time temperature acquisition and returns to shutdown state, allowing to save as much as energy as possible.

The precision of the sensor is typically 0.5°C over its standard temperature range (-25°C to +85°C, the one I’ll be using) and the resolution is 0,0625°C (the LSB).

The temperature results are read on two bytes (12bits resolution). The first byte is the number before the comma, 2’s complemented for negative temperatures. The second byte contains the number after the comma. It has to be multiplied by 0.0625°C to get the real number.

I thought that a two digits after the comma precision should be enough (ie. by rounding), and instead of wasting CPU time with multiplication, I just made a string array containing all the results:

Temp_Precision[34]=”00061319253138445056636975818894″

Then, when the second temperature byte is read (Temp1byte), I just have to index the array with it (after a 4-bit shift, because it comes left-aligned). “TempASCII” is a string containing the temperature value:

TempASCII[i] = ',';
TempASCII[i+1] = Temp_Precision[Temp1byte*2];
TempASCII[i+2] = Temp_Precision[Temp1byte*2+1];

Which gives the following numbers vs. the original 0,0625-stepped ones, in °C:

The array could of course contain all the non-rounded numbers:

Temp_Precision[64]="0000062512501875250031253750437550005625625068757500812587509375"
TempASCII[i] = ',';
TempASCII[i+1] = Temp_Precision[Temp1byte*4];
TempASCII[i+2] = Temp_Precision[Temp1byte*4+1];
TempASCII[i+3] = Temp_Precision[Temp1byte*4+2];
TempASCII[i+4] = Temp_Precision[Temp1byte*4+3];

And so on. Useful trick instead of making a 0,0625 multiplication.

As said in earlier posts, I want to store the temperature readings in an Atmel AT25DF081 EEPROM. I chose it because it has a big capacity (8Mb) and a really low voltage supply value (1,8V). It connects via SPI to the microcontroller.

Now, with the great help of Microchip and its PICs I/Os being configurated as “Analog inputs” on startup and read as “0” when one forgets to set the right registers (ADCON0 & ADCON1), I had the great chance to spend two days measuring the EEPROM SPI link. Who would know the Analog ports “ANx” were also on the PORTB, and not only on the PORTA with ‘A’, as anolog? I know, RTFM.

During my investigations of the now perfectly working SPI, I could notice that the serial output pin of the memory (SDO) wasn’t an open collector, as I thought. It’s a pity it’s written nowhere in the Atmel’s datasheet. The Maximum input voltage of “3,8V”, Voh min of “Vcc-0,2” and no value for Voh max leave some room for imagination.

Well, the PIC seems to recognize the 1,8V SDO high state as high, even at higher speed, so it’s not such a big concern. A diode between the pin and the PIC will increase the EEPROM Voh to approx 2,5V (even if it also increases the EEPROM Vol of 0,6V). It could be an optional component on the final PCB design, replaced by a 0 Ohm resistor if the tests show no logical state decoding problem.

On the software page:

I took an example app from the Microchip’s USB libraries called “USB SD Card data logger”. It’s supposed to be an application for a logger with a SD card, being able to write on the card a value from a potentiometer.

It’s using the files SD-SPI.c and .h to access the SD Card, part of the Microchip’s MDD Filesystem. I started with these files and re-wrote them to make the project work with my EEPROM. Of course, that’s where the problems started..

On the filesystem, the default sector size is 512 bytes. As the PIC has to buffer the sector it’s writing to or reading from, there must be the same amount of memory allocated to the buffer as the size of the sector.  With the PIC18F26J50 I’m using, it cannot be bigger as 512 bytes.

The AT25DF081 EEPROM is organized into 256 bytes program pages. As they are smaller than the sector, it’s not a problem (I’m just making an address shift when the PIC wants to write more than 256 bytes). Reading is even easier, as there’s no page limit (it can be read starting form 0x000000 till 0x0FFFFF, the address counter on the EEPROM increments itself).

It gets complicated when you notice that the EEPROM’s erasing granularity doesn’t match the writing one. The smallest block to be erased is 4KB (then, 32KB, 64KB and 1MB) which means that to change even only one bit, all the 4KB must be read, erased and re-programmed.

AT25DF081 Memory space diagram

For now, I’m using only the first 512 Bytes of each 4KB page, but it limits the available space to 256 sectors of 512 bytes. That’s 128KB. Minus the space required for the filesystem and the sector for the logger configuration file, that leaves roughly 120KB of storage for the temperature measurements. Each of them will be something like “12/12/2011;23:59:59;127,00←↓” which is 28 Bytes. Divide 120KB by 28B, you get more or less a 40 000 temperature-acquisitions-worth-logger. Could be better and the idea of wasting 90% of my EEPROM is bad.

So, what exactly do we have to store in the EEPROM?

  • The FAT12 or 16 filesystem (3 or 4 sectors)
  • The configuration file (1 or 2 sector)
  • The temperature data

The FAT and the configuration file must be accessed often and must be user, computer-OS and PIC modifiable. But, the temperature data will only be written directly by the PIC and then only read by the user when the logging is over. The only modifications they (or rather the file containing them) will be subject to, are adding new measurements or erasing all the data for a new logging round. All that done by the PIC, which has direct access the the EEPROM.

I’ll need to modify the Microchip’s MMD filesystem routines to be able to directly write into a reserved block for the temp. measurements on the EEPROM. Plus, make the appropriate modifications in the FAT to allow a computer OS to read them, without being able to modify anything on the reserved block.

Quite a piece of work, especially because the library linking the USB procedures to the disk is complicated. And with optimized C code, it’s quite hard to debug the program, as the code pointer is jumping around all the time (I even thought it was a problem with my debugger/compiler/program/stack)

That’s for the next episode. I’ll also try to post the two files (SD-SPI.c and .h) I modified to use the AT25DF081 with the Microchip’s MDD and I’ll say a few words about the ICD3 debugger.

Designing a simple and cheap temperature logger. Part 2

Today, we’ll see how much the logger costs and try to approximate a power budget.

First, I was really surprised of how many people were interested in this project. I guess I have to keep on working on it.

I also forgot in my specifications that the logger shouldn’t need any driver or software to operate. An important plus for the product.

I took the standard prices form Farnell.fr to have an idea of the cost of a few prototypes. It should be possible to find a cheaper place or to order some of the components directly from the manufacturer (like the microcontroller). Let’s say it’s just to have a rough idea:

USB Temp Logger Components Prices

The final price is without VAT and shipping. For the PCB, I took iTeadStudio with two temperature loggers per 5x5cm board.

Then, I checked the cost for 1000 quantity for each component and the direct-from-manufacturer prices when possible. Once again, without VAT and shipping:

USB Temp Logger Components Prices 1000 qty

As expected, it’s twice cheaper and it’s only for 1000 pieces and without bulk factory prices. Of course, it’s based on the prototype and a final product would also have a casing and some ESD/CEM protections, which adds cost. But so far, I find it cheap enough.

For the power consumption part. The only thing I can do for now is to take values from the datasheets and try to calculate/extrapolate a theoretical life on battery power.

USB Temp Logger Power Chart

The logger will be designed to be in sleep mode most of the time. The microcontroller has a “deep sleep” mode (500nA) and wakes up by setting an alarm in the real time clock module. The temperature sensor and memory also have sleep functionalities.

Depending if the pins used for the serial buses are open drain or not, there can be current flowing trough the pull-up resistors, which could increase the sleep current as could also the 1,8V regulator’s quiescent current. Adding the numbers up gives an expected sleep time of almost two years (15,5uA) with one CR2032 battery. Not bad.

The power calculation gets more speculative for the temperature acquisition. The biggest problem will be to provide the flash memory current during writes. It’s 12mA. The time needed to program one byte is 15us. There will probably be a minimum of twenty bytes to be written, which gives 300us to write one temperature point, plus 25us for the deep sleep exit time. The PIC needs 1,5ms to exit the deep sleep mode. One temperature acquisition is performed in 35ms max. Let’s base our calculation on a 100ms not-sleep time (3mA) and a 400us flash write time (14mA).

We will also suppose the battery’s voltage won’t drop too much while supplying 12mA@1.8V (1.8V plus the regulator’s drop out voltage).

To summarise (currents and times not to scale):

USB Temp Logger Current Graph

Say the temperature measurement period would be one minute (60 per hour), we need to calculate the average current per hour and divide the battery capacity (225mAh) by this result. I keep times in milliseconds, thus the 3600 000 number (milliseconds in one hour). We will use the average current during wake-on: (3mA*100ms+15mA*0.4ms)/(100ms+0.4ms) = 3.04 mA

I’m using this formula (this site has a calculator: http://oregonembedded.com/batterycalc.htm):

Battery Life Equation

(Where BATTmAh is the battery capacity, ONmA is the current consumed during wake-on time, ONms is the temperature measurement time, ONph is the number of measurements per hour and OFFmA is the current in sleep mode. The result, th, is the time the battery will be able to power the logger, in hours. Divide by 24 to have the numbre of days)

{225 / [ ( 3.04*100.4*60) + (0.0155* ( 3600000 – ( 100.4*60) ) )]/3600000}/24

≈{225/ [(18313+55707)/3600000]}/24

≈{225/0.0205}/24

≡456 days.

Hmm.. That’s a lot and I don’t think it’s true. First, we don’t take account of the battery’s voltage evolution vs. minimum voltage required to power the components (remember, 2.5V). Then, I’m sure drawing 15mA from the battery, even for a very short period of time, will affect a lot its life time.

Let’s try to be more realistic and use different numbers.

Half of the battery capacity: 110mAh

More current drawn during on-time: 6mA

That’s 180 days, a bit more realistic.

I think the only way to get a true estimation of battery life during temperature acquisition operation will be to measure the real current for the wake-on time, plus measure the battery’s voltage drop while drawing the 15mA for memory write. But that’s for the next episode…