Temperature Data Logger

Discussion in 'The Projects Forum' started by Hawk1943, Jul 1, 2010.

  1. Hawk1943

    Thread Starter New Member

    Jul 1, 2010
    7
    0
    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...
     
  2. Hawk1943

    Thread Starter New Member

    Jul 1, 2010
    7
    0
  3. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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

     
  5. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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.
     
  6. Hawk1943

    Thread Starter New Member

    Jul 1, 2010
    7
    0
  7. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
  8. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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
    http://ww1.microchip.com/downloads/en/AppNotes/91097A.pdf
     
  9. Hawk1943

    Thread Starter New Member

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

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

    Thread Starter New Member

    Jul 1, 2010
    7
    0
    Ok...

    It's in circuit...

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

    Code ( (Unknown Language)):
    1.  
    2. /* Timer 1 Initialisation */
    3.  // Timer Gate is not inverted (bit 7 = 0)
    4.  // Timer Gate not enabled (bit 6 = 0)
    5.  // Prescaller Timer Rate 1:8 (bit 5-4 = 11)
    6.  // LP Oscillator not enabled (bit 3 = 0)
    7.  // Synchronise external clock input (bit 2 = 0)
    8.  // External Clock (T1CKI - rising edge) (bit 1 = 1)
    9.  // Timer 1 - NOT STARTED (bit 0 = 0)
    10.  T1CON = 0x32;
    11.  T1CON |= 0x01; // Start Timer 1
    12.  /* WATCHDOG Timer Initialisation */
    13.  WDTCON = 0x08;  // Prescaller Rate 1:512
    14.  
     
  11. Hawk1943

    Thread Starter New Member

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

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

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

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Just a tip. In the 16f684.h file you will find these definitions for T1CON register
    Code ( (Unknown Language)):
    1.  
    2. /* Definitions for T1CON register */
    3. volatile bit TMR1ON  @ ((unsigned)&T1CON*8)+0;
    4. volatile bit TMR1CS  @ ((unsigned)&T1CON*8)+1;
    5. volatile bit T1SYNC  @ ((unsigned)&T1CON*8)+2;
    6. volatile bit T1OSCEN  @ ((unsigned)&T1CON*8)+3;
    7. volatile bit T1CKPS0  @ ((unsigned)&T1CON*8)+4;
    8. volatile bit T1CKPS1  @ ((unsigned)&T1CON*8)+5;
    9. volatile bit TMR1GE  @ ((unsigned)&T1CON*8)+6;
    10. volatile bit T1GINV  @ ((unsigned)&T1CON*8)+7;
    11.  
    So you can write like
    Code ( (Unknown Language)):
    1.  
    2. TMR1ON=1; // Start Timer 1
    3.  
    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
    Code ( (Unknown Language)):
    1.  
    2. T1CON |= 0x01; // Start Timer 1
    3.  
    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

     
  13. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
  14. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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: Jul 2, 2010
  15. Hawk1943

    Thread Starter New Member

    Jul 1, 2010
    7
    0
    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

    Code ( (Unknown Language)):
    1.  
    2.  write_byte(0xCC);   // Skip ROM
    3.  write_byte(0x4E);   // Write Scratchpad
    4.  write_byte(0x00);   // Write data byte TH
    5.  write_byte(0x00);   // Write data byte TL
    6.  write_byte(0x7F);   // Write data byte CONFIG
    7.  write_byte(0x4E);   // Write Scratchpad
    8.  
    Full version of code...

    Code ( (Unknown Language)):
    1.  
    2. void Read_Temperature(void)
    3. {
    4.  static char get[10];
    5.  char temp_lsb,temp_msb;
    6.  int k;
    7.  char temp_f,temp_c;
    8.  unsigned char i;
    9.  reset();   // Send reset and receive presence pulse
    10.  write_byte(0xCC);   // Skip ROM
    11.  write_byte(0x4E);   // Write Scratchpad
    12.  write_byte(0x00);   // Write data byte TH
    13.  write_byte(0x00);   // Write data byte TL
    14.  write_byte(0x7F);   // Write data byte CONFIG
    15.  write_byte(0x4E);   // Write Scratchpad
    16.  time_delay(5);   // 60uS delay
    17.  reset();   // Send reset and receive presence pulse
    18.  write_byte(0xCC);   // Skip ROM
    19.  write_byte(0xBE);   // Read ScratchPad
    20.  
    21.  for (k=0;k<9;k++)  // receive & read 9 data bytes
    22.   {
    23.   get[k]=read_byte();
    24.   }
    25.  reset();   // Send reset and receive presence pulse
    26.  write_byte(0xCC);   // Skip ROM
    27.  write_byte(0x48);   // Copy Scratchpad
    28.  DQ = 1;    // return DQ immediatly high
    29.  for (i=0; i<1; i++);   // require 10mS time_delay, while copy is in progress
    30.  
    31.  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]);
    32.  
    33.  temp_msb = get[1];   // Sign byte + lsbit
    34.  temp_lsb = get[0];   // Temp data plus lsb
    35.  if (temp_msb <= 0x80){temp_lsb = (temp_lsb/2);} // shift to get whole degree
    36.  temp_msb = temp_msb & 0x80; // mask all but the sign bit
    37.  if (temp_msb >= 0x80) {temp_lsb = (~temp_lsb)+1;} // twos complement
    38.  if (temp_msb >= 0x80) {temp_lsb = (temp_lsb/2);}// shift to get whole degree
    39.  if (temp_msb >= 0x80) {temp_lsb = ((-1)*temp_lsb);} // add sign bit
    40.  printf( "\nTempC= %d degrees C\n", (int)temp_lsb ); // print temp. C
    41.  temp_c = temp_lsb; // ready for conversion to Fahrenheit
    42.  temp_f = (((int)temp_c)* 9)/5 + 32;
    43.  printf( "\nTempF= %d degrees F\n", (int)temp_f ); // print temp. F
    44. }
    45.  
     
Loading...