# Temperature Data Logger

#### Hawk1943

Joined Jul 1, 2010
7
Hi Everyone,

Basically I am a Third Year BSc Forensic Science Student, whose third year project is to observe the effects of degredation of hyaline cartilage in Porcine Hind Trotters when buried for a period of upto ten weeks to see if it is possible to determine the post mortem interval (Time Since Death)

So what I need to do is accuratly measure the soil temperature and ambient temperature for a period of around 10 weeks, as I do not wish to disturb the project in anyway I need to also store all the data. Then after 10 weeks hook it up to a serial port and download the data into hyperterminal or something similar...

The whole project therefore needs to standalone and able to run possibly from a 8 AA Battery's as I have a suitable enclosure ready that can also accomodate the PCB as I beleive that is the best option at the moment, but I have not worked out the power output yet, I beleive the voltage to be around 9.6v but as for the current I still need to sort it...

At the moment I am using a LM7805 voltage regulator which is power hungry but as I am running off a dual power supply while I am writting the code it's not a problem but when I start to run it off batteries I will need a more suitable method of producing a constant 3v & 5v supply for the entire 10 week or longer period...

I beleive using a potential divider, zener diode or other such circuits to be power hungry as well... so i'm unsure at this stage what to use...

Cash is a major issue, as the university does not have the funds available to assist me in any way... I have a £25.00 budget to get the Porcine Hind Trotters...

I plan on attaching all that I have as I am quickly running out of time, hence the reason I am asking for help...

I have I beleive a good portion of the code written out and tested but I'm struggling with the temperature sensor...

This is what I have so far connected up...

A 16F684 that should be receiving the temperature from 2off DS18B20 temperature probes... I have on order 2off FM25V02 256K F-RAM memory device...

But untill I start testing the code I am unsure if I have enough memory as Ideally I would love to record the temperature every hour but I can not see that being an option, due to memory and power constrants...

There is no requirement for a LCD, as the device will be left out in all sorts of weather...

I have untill the End of July to get the prototype tested and working... as around the third week of August I will be burying the Porcine Hind Trotters...

So far I have full RS232 communications so Putchar and Getchar work but I am unable to use printF not sure why...

There is no MAX232 device the entire code is being bit-bashed out of the PIC were running at 4800 baud...

Some of the code has been removed to enable me to concentrate purely on the DS18B20...

Any help on this would be greatly appreciated...

#### Attachments

• 288.2 KB Views: 29

#### Markd77

Joined Sep 7, 2009
2,806
Voltage regulators don't use much power when they aren't supplying current - LM78L05 is 3mA but there are better ones.
Much of the power is probably being used by the temperature sensors.
An option is to find another regulator for the sensors with an enable input so the sensors are only turned on when a measurement needs to be made.
Zener and potential divider circuits are indeed much more power hungry.

#### t06afre

Joined May 11, 2009
5,934
Here is some info on using 32.768 kHz Tuning Fork Crystal on a PIC16f690. It will also apply to your MCU.
TMR1 with external osc. at 32.768KHz generates overflow interrupt every 2 seconds. If we set TMR1 to start at 0x8000 (32768), the TMR1 will overflow every 1 second Moreover, setting TMR1 to 0x8000 requires only TMR1H = 0x80 which does not affect the clock accuracy (setting TMR1L will affect the accuracy). You can also prescaler to divide down the clock with 2 or 4, so you end up with interrupt every 4 second. A timer tick every 4 second will give 15 ticks pr minute and 900 ticks pr hour. Between this period the MCU can be in sleep and will not use much power. A 32.768KHz crystal can be lifted out of any dead digital clock.
For watch and timekeeping applications, 32.768 kHz crystals with an accuracy close to 20 ppm are common, but 20 ppm translates to a ±0.65536 Hz frequency deviation, or 51.8 seconds error per month.
This error only accounts for variation in crystal properties. Other significant sources include temperature, aging,component selection and layout. So you should perhaps order a new crystal for your project. But to get started a used one will do fine. But read the data sheet so you get the Load Capacitance and motional series resistance correct. Here is a search from Farnell in UK
http://uk.farnell.com/jsp/search/br...e=en_UK&catalogId=&prevNValues=500006+1002262

#### t06afre

Joined May 11, 2009
5,934
Voltage regulators don't use much power when they aren't supplying current - LM78L05 is 3mA but there are better ones.
Much of the power is probably being used by the temperature sensors.
An option is to find another regulator for the sensors with an enable input so the sensors are only turned on when a measurement needs to be made.
Zener and potential divider circuits are indeed much more power hungry.
I have advised the OP not to use a regulator. It is not needed and will only steal energy. All the circuits do have wide voltage range operation spec. I suggested that OP use 3 long life D size Cells.

#### Hawk1943

Joined Jul 1, 2010
7

#### Markd77

Joined Sep 7, 2009
2,806
Looks about right. You may need some capacitors too, check the oscillator section of the PIC datasheet. It might be 100pF but I haven't checked.

#### t06afre

Joined May 11, 2009
5,934
Yes it looks OK. Be sure to pick up the 32.768kHz not the 3.2768MHz type.
By the way. Here is the AN i meant to send you in my last posting. As I said this is for the 16f690, but will apply to your MCU also. If you read this. You also want to pick up two 22pF caps

#### Hawk1943

Joined Jul 1, 2010
7
Thanks for that...

I'll pop into Maplins tomorrow and grab them...

#### Hawk1943

Joined Jul 1, 2010
7
Ok...

It's in circuit...

Just need to get the code sorted to implement it...

Rich (BB code):
/* Timer 1 Initialisation */
// Timer Gate is not inverted (bit 7 = 0)
// Timer Gate not enabled (bit 6 = 0)
// Prescaller Timer Rate 1:8 (bit 5-4 = 11)
// LP Oscillator not enabled (bit 3 = 0)
// Synchronise external clock input (bit 2 = 0)
// External Clock (T1CKI - rising edge) (bit 1 = 1)
// Timer 1 - NOT STARTED (bit 0 = 0)
T1CON = 0x32;
T1CON |= 0x01; // Start Timer 1
/* WATCHDOG Timer Initialisation */
WDTCON = 0x08;  // Prescaller Rate 1:512

#### Attachments

• 178.4 KB Views: 19

#### Hawk1943

Joined Jul 1, 2010
7
Just tweaked the timer 1 Settings to the following code...

Rich (BB code):
 /* Timer 1 Initialisation */
// External Oscillator runnung at 32.768KHz
// Timer Gate is not inverted (bit 7 = 0)
// Timer Gate not enabled (bit 6 = 0)
// Prescaller Timer Rate 1:4 (bit 5-4 = 10)
// LP Oscillator enabled (bit 3 = 1)
// Synchronise external clock input (bit 2 = 0)
// External Clock from T1CKI pin - rising edge (bit 1 = 1)
// Timer 1 - NOT STARTED (bit 0 = 0)
T1CON = 0x29;
// TMR1 to start at 0x8000 (32768)
// to generate an overflow interrupt every 2 seconds
TMR1H = 0x80;
TMR1L = 0x00;
T1CON |= 0x01; // Start Timer 1
Hopefully this should now work...

** now i'm seeing a 32KHz saw tooth waveform on pins RA4 & RA5 **

#### t06afre

Joined May 11, 2009
5,934
Just a tip. In the 16f684.h file you will find these definitions for T1CON register
Rich (BB code):
/* Definitions for T1CON register */
volatile bit TMR1ON  @ ((unsigned)&T1CON*8)+0;
volatile bit TMR1CS  @ ((unsigned)&T1CON*8)+1;
volatile bit T1SYNC  @ ((unsigned)&T1CON*8)+2;
volatile bit T1OSCEN  @ ((unsigned)&T1CON*8)+3;
volatile bit T1CKPS0  @ ((unsigned)&T1CON*8)+4;
volatile bit T1CKPS1  @ ((unsigned)&T1CON*8)+5;
volatile bit TMR1GE  @ ((unsigned)&T1CON*8)+6;
volatile bit T1GINV  @ ((unsigned)&T1CON*8)+7;
So you can write like
Rich (BB code):
TMR1ON=1; // Start Timer 1
It will be compiled as BSF instructions. I think the code is more easy to follow for other by using this convention instead of writing
Rich (BB code):
T1CON |= 0x01; // Start Timer 1
Also I would also perhaps set the T1CON prescaler to 2, and skip writing TMR1H = 0x80 part. Remember you have to update TMR1H every times the timer rolls over to 0000h. But with this setting you can forget all about it.
I also see you still use 7805 circuit. That IC will drain your battery. A LM7805 has a Quiescent Current= max 8mA. A 78l05 has a Quiescent Current= max 5mA. As I said if you use 3 D cells you will NOT need any regulator. Why are you so stubborn on this point?
Also remember that fm25v02 IC is made for 3.6 volt VDD. 5 volt will kill it. If you have one free pin on your MCU you can use this to power the temp sensors. And hence conserve energy

#### Markd77

Joined Sep 7, 2009
2,806
I hadn't checked the datasheet on the temperature sensors and didn't realise they were such low power. 750-1000nA isn't really worth worrying about.

#### t06afre

Joined May 11, 2009
5,934
I hadn't checked the datasheet on the temperature sensors and didn't realise they were such low power. 750-1000nA isn't really worth worrying about.
I somehow missed that. No need to do anything fancy. But here is something to think about. If we use LM7805 a and assume 5mA Quiescent Current. If the device has to work for 10 weeks, or 70 days. Will that be equal to 8400mAH. you will ned a lot of AA cells to have that battery capacity

Last edited:

#### Hawk1943

Joined Jul 1, 2010
7
I also see you still use 7805 circuit. That IC will drain your battery. A LM7805 has a Quiescent Current= max 8mA. A 78l05 has a Quiescent Current= max 5mA. As I said if you use 3 D cells you will NOT need any regulator. Why are you so stubborn on this point?
Also remember that fm25v02 IC is made for 3.6 volt VDD. 5 volt will kill it. If you have one free pin on your MCU you can use this to power the temp sensors. And hence conserve energy
Don't forget that is for the current prototype not for the finished design, I still need to sort out the power supply side of things but whilst I am bench testing from a bench power supply then it's not an issue, but I would like to still like to have access to it in the final design perhaps by coupling it back up with some jumpers, so that I don't have to rely on the batteries whilst downloading the data...

Also as I have already stated I do have an 8 way AA battery compartment ready to use here, that already has an area to securly hold the PCB and protect it from the elements...

But I have an issue with the code for the DS18B20... it's just not outputting the correct data, in fact it's not outputting any data...

Can anyone have a look at my code and see where I am going wrong, only I feel I have done something silly here...

Don't think I should have written 0x00 to either TH or TL but the Maxim data sheet implies that I should, yet the data I am seeing is all zero's

Rich (BB code):
 write_byte(0xCC);   // Skip ROM
write_byte(0x00);   // Write data byte TH
write_byte(0x00);   // Write data byte TL
write_byte(0x7F);   // Write data byte CONFIG
write_byte(0x4E);   // Write Scratchpad
Full version of code...

Rich (BB code):
void Read_Temperature(void)
{
static char get[10];
char temp_lsb,temp_msb;
int k;
char temp_f,temp_c;
unsigned char i;
reset();   // Send reset and receive presence pulse
write_byte(0xCC);   // Skip ROM
write_byte(0x00);   // Write data byte TH
write_byte(0x00);   // Write data byte TL
write_byte(0x7F);   // Write data byte CONFIG
time_delay(5);   // 60uS delay
reset();   // Send reset and receive presence pulse
write_byte(0xCC);   // Skip ROM

{
}
reset();   // Send reset and receive presence pulse
write_byte(0xCC);   // Skip ROM
DQ = 1;    // return DQ immediatly high
for (i=0; i<1; i++);   // require 10mS time_delay, while copy is in progress

printf("\n ScratchPAD DATA = %X %X %X %X %X %X %X %X %X \n",get[8],get[7],get[6],get[5],get[4],get[3],get[2],get[1],get[0]);

temp_msb = get[1];   // Sign byte + lsbit
temp_lsb = get[0];   // Temp data plus lsb
if (temp_msb <= 0x80){temp_lsb = (temp_lsb/2);} // shift to get whole degree
temp_msb = temp_msb & 0x80; // mask all but the sign bit
if (temp_msb >= 0x80) {temp_lsb = (~temp_lsb)+1;} // twos complement
if (temp_msb >= 0x80) {temp_lsb = (temp_lsb/2);}// shift to get whole degree
if (temp_msb >= 0x80) {temp_lsb = ((-1)*temp_lsb);} // add sign bit
printf( "\nTempC= %d degrees C\n", (int)temp_lsb ); // print temp. C
temp_c = temp_lsb; // ready for conversion to Fahrenheit
temp_f = (((int)temp_c)* 9)/5 + 32;
printf( "\nTempF= %d degrees F\n", (int)temp_f ); // print temp. F
}

#### Attachments

• 371 bytes Views: 15
• 11.3 KB Views: 8