converting time into useful format

Status
Not open for further replies.

justDIY

Active Member
I've started an ambitious project to build a data logging multi-channel temperature probe, with a VFD readout and a menu driven user interface.

I currently have a DS1307 BCD encoded serial real time clock, but I'm wondering what the best way to transform the data the clock gives me into something tangable I can use for data logging, averaging, elapsed time, etc.

since the finest time resolution I'm interested in is hours, I was thinking I could calculate the number of hours elpased since 10-1-2005 but then I began to think well, how will the program know how many days its been since that date, once the month goes by... I'd have to use a lookup table with the number of days in each month, and what happens when Feburary has the extra day every four years...

I suppose I could have a subroutine increment a counter stored on the eeprom, at the beginning of each hour it increments the value by one (checking for xx:00:00) but this count could get messed up by the user setting the clock incorrectly and then correcting it... and then what about day-light savings time where clocks here in the US move forward and back an hour with the seasons changing.

I'm not really looking for code samples, but insight from those who've already experienced this sort of thing. I'm also not really looking to produce a bullet proof commerical grade product here, just something nice and easy to use for family members as holiday gifts.

Gordon
 
It really depends greatly exactly what you want to do?, presumably the unit will be capable of downloading the data to a PC? - not much point logging the data if you can't do anthing with it afterwards!.

In that case all the clever date stuff can be done on the PC, all the logger has to do is record the start time and date, the time between samples, and then the actual data - from that the PC can easily calculate all the dates and stuff, and produce pretty graphs, or whatever you want?.

Either way, what you need is "Julian Number Routines", these produce a single number representing a day, actually the number of days that has passed since a certain specific date. They usually use a start day back a few hundred years, simply because the calendar changed then, and it's remained identical ever since.

Modern languages like Delphi (and presumably C or VB) will already include Julian date routines as part of the compiler. Implementing them on a PIC is likely to be fairly hard, because of the maths involved - but certainly possible.
 

OK ... so I was thinking along the right lines ... but I knew I didn't have to re-invent the wheel someone must have done it before.

This is my wish list:

Store for each channel

* 24 Hour Highest and Lowest Temps
* 7 Day Highest and Lowest Temps
* 30 Day Highest and Lowest Temps
* Highest and Lowest Temp Since 01/01/XX (per year)

Store overall

* Highest Temp Ever Recorded - store channel, date and time
* Lowest Temp Ever Recorded - store channel, date and time
* Running 24 Hr Average for each channel
* Running 7 Day Average for each channel
* Running 30 Day Average for each channel
* Yearly Average for each channel (store the year, the chan #, the yearly average)

The lists are arranged in priorities, from what I'd most like to accomplish to what is least important.

As far as PC connectivity, the thought has crossed my mind from time to time, but for now, I'd like to try to do everything onboard.

The way I envision it:

the data logging portion only needs to store a weeks worth of data for each temperature channel (five in all) so that is 168 hours of temperature samples (each sample would be one byte) per channel times five channels = 840 bytes just for the temperatures (my eeprom is 64 kbytes) ... this will give me data to go back an hour, a day, a week. I'll store that data so it overwrites in a loop... once 168 hours have been recorded, start over at the beginning. I suppose that will give me some tricky math to "go back" several days if the pointer is only a few hours into a loop of the samples cycle

from there, I'm sorta lost ... I haven't come up with how to store or compute the monthly and yearly datas

here is more a more in-depth write up of what I'm working with, for refrence:
https://projects.dimension-x.net/technology-and-projects/exploration-of-max1668/
 
justDIY said:
from there, I'm sorta lost ... I haven't come up with how to store or compute the monthly and yearly datas

As I mentioned above, you need Julian date routines, these provide conversion between the year, month, day and a specific integer number, plus backwards as well.

So if you want to go back 1 week, convert todays date to a Julian number, subtract 7 from it, then convert it back to the date format - this takes account of months and leap years, without you having to do any more work.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…