Shop OBEX P1 Docs P2 Docs Learn Events
Attempting to write thermocouple data to SDCard every ?4hrs — Parallax Forums

Attempting to write thermocouple data to SDCard every ?4hrs

msiriwardenamsiriwardena Posts: 301
edited 2013-12-16 15:14 in Propeller 1
I am trying to write Data from 3 thermocouples to the SDCard every 3 to 4 hrs every day.
RTC 1307 is also incorporated inti this project to keep real time.

I got all of them to work also to write Data to the SDCard.At present it wites the Data every 2-3 seconds no matter
how I change the Repeat loop in the SDCard.
I have tried to place IF conditions ex. IF Hour== 16 or Hour ==19 and minute ==0 and secs ==0 etc.
I also tried embedded loop and "quit" still I cannot get it right.

I appreciate some Help.

P.S : archive project is attached

Thanks,

Siri.

Comments

  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2013-12-13 13:44
    I haven't opened your spin code, but there are several ways to do this.

    You seem to be depending on Hours, Minutes, and Seconds.... With 32bit integers, you could just have a loop read a wait count of 4 hours entirely in seconds.

    You could use the RTC to set the time and date only at power up, and have that converted to UnixTime seconds for running the loop. That would eliminate the need to frequently read the RTC. It may be that your loop to read the RTC is writing every read to your SDcard.

    http://en.wikipedia.org/wiki/Unix_time

    The only disadvantage is that all your time stamps will be in Unix Time (which is in seconds) unless you convert the time to hours, seconds, and minutes to write to the SDcard.

    By using Unix Time, the code becomes a lot cleaner and it works extremely well with a 32bit system.
  • JonnyMacJonnyMac Posts: 9,107
    edited 2013-12-13 14:01
    If the readings need to happen at a specific time of day the RTC is helpful. As values from the RTC are returned in BCD format you can convert the current time to a long like this (pseudo-code):
    pub make_timecode | tc
    
      tc := 0
    
      tc.byte[2] := read_rtc(hours)
      tc.byte[1] := read_rtc(minute)
      tc.byte[0] := read_rtc(seconds)
    
      return tc
    


    Now you can do a simple comparison
    if (make_timecode == $12_30_00)
        ' do something
        ' delay at least 1 second to move past this timecode
    

    This would run the code in the if construct when the time was 12:30AM.
  • msiriwardenamsiriwardena Posts: 301
    edited 2013-12-14 08:28
    @JonnyMac

    Thanks for the help.I have a RTC because I need the Temps logged every 12,6,18 & 24hrs - daily for about a year - to figure out the daily,monthly variations of the Temp in the water in 3 wells.
    I tried your solution - it worked except -the temps were recoded for about i min. from the starting hour.- so I skipped the seconds and added a waitcnt hust over one minute
    to the loop.I am yesting it right now.
    Hope this will solve the issue.

    Thanks again,

    Siri
  • JonnyMacJonnyMac Posts: 9,107
    edited 2013-12-14 09:25
    If you use the seconds field then you only need to ensure your datalogging element consumes more than one second. Pretty easy.
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2013-12-14 14:44
    Hi Siri;

    I have to ask?

    Since you are taking only one measurements every 4 hours which results in less than 8K longs in a year you could save this in the EEPROM. This would alleviate the need for the SD-Card.

    Also, using a DS18B20+ is much easier to do than a thermocouple. This only needs a pair of wires and outputs digitally and provides 1/2 degree C accuracy.

    Duane J
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-12-15 13:04
    One simple way to do the logging every 4 hours is to use another byte variable, hour0 as follows.
    [FONT=courier new]   repeat
         if hour0 <> RTC.Bcd2int(hour1) / 4
           hour0 := RTC.Bcd2int(hour1) / 4
           ' and so on with SD card[/FONT]
    

    hour0 takes on integer values from 0 to 5 thru the day and changes every 4 hours, and it is the changeover that triggers the SD logging.
  • msiriwardenamsiriwardena Posts: 301
    edited 2013-12-15 15:33
    @jonnyMac - Thanks for your help - the issue is solved.
    @Duane - I looked at the DS18B20 - this not suitable for the project as the temps are read in well water that about 20 ft deep.
    @ Tracy - I will give it try - for learning purpose.

    Thanks to all

    Siri
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2013-12-15 16:31
    Hi Siri;
    @Duane - I looked at the DS18B20 - this not suitable for the project as the temps are read in well water that about 20 ft deep.
    Exactly. I have done this with thermocouple and solid state sensors. They all must be protected from contact with the water. I havn't used the DS18B20+ yet but have extensively used the LM34 and LM35 in the analog world.

    If you are using thermocouple you need to seal the measurement end so it doesn't come in contact with water. The dissimilar metals form a little electrochemical battery which can affect the reading. I take the small metal eraser protector on Pentel Mechanical Pencils and fill it with silicone rubber then push the thermocouple into it.
    Plastic pen caps would also work well for you as the temperatures are low.

    The DS18B20+'s TO-92 package also fits into the Pentel eraser cap to.

    BTW, does your thermocouple circuit have "Cold Junction Compensation"? You can't get long term accuracy without it. The solid state sensors don't need it.

    Duane J
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-12-16 10:58
    @ Duane, Siri is using the MAX31855, which is a nice chip that has the cold junction compensation and scaling built in, SPI. I agree 100% about insulating the thermocouple, for reasons of AC noise pickup in addition to the galvanic effect.

    @ Siri, for the record, here's yet another way to do the timing...
    [SIZE=1][FONT=courier new]  repeat
        repeat until RTC.Bcd2int(hour1) // 4    ' stay here until int hour1>0
        repeat while RTC.BCD2int(hour1) // 4    ' stay here until int hour1=0
           ' SD card code goes here, then back to timing
    [/FONT][/SIZE]
    
    It only drops through to the SD card code when hour1 transitions from 5 to 0.

    It can be simplified even further if the interval is 1,2, 3 or 6 hours...
    [SIZE=1][FONT=courier new]  repeat
        repeat until hour1 // 6    ' stay here until hour1>0
        repeat while hour1 // 6    ' stay here until hour1=0
           ' SD card code goes here, then back to timing
    [/FONT][/SIZE]
    
    It does not need Bcd2int conversion, due to the curious mathematical fact that an integer mod those values is the same whether the hour is represented as a straight integer or as BCD.
  • msiriwardenamsiriwardena Posts: 301
    edited 2013-12-16 13:48
    @ Tracy - Thanks for the code.

    Siri
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2013-12-16 15:14
    Hi Siri;

    Take a look at the reference design for the MAX31855PMB1.

    Duane J
Sign In or Register to comment.