Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 00:32 25 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : (MM/DM) Unix time for data logging

Author Message
DuinoMiteMegaAn
Senior Member

Joined: 17/11/2011
Location: Australia
Posts: 231
Posted: 02:03pm 13 Dec 2011
Copy link to clipboard 
Print this post

(MM/DM) Unix time for elapse time data logging.

A quick search for any Unix algorithms for GW-Basic on
the Internet brings up almost nothing.

Time / date stamping of data should be done with a "elapse time"
reference instead of a time / date reference. Unix time - the time
in seconds from 1970 is the "almost" perfect choice.

Note: In 2038 Unix 32 bit counter will rollover!

Note: In the Maximite/DuinoMite there is a millisecond timer but
the "long term" accuracy and rollover are in question?

Note: I am planning to use a precision RTC that refreshes the PIC32 RTC
for precise datalogging.

Anyone on this board seen any GW-Basic algorithms for converting to/from
a time/date stamp to Unix time?
 
ksdesigns

Senior Member

Joined: 25/06/2011
Location: United States
Posts: 143
Posted: 04:29pm 13 Dec 2011
Copy link to clipboard 
Print this post

I have been working on a sleep command using the pic32 internal rtcc alarm interrupt
you can set it to wake up as far as once a year .
On the DuinoMite-Mega running with 12v in the current draw is about 80ma and in sleep mode, drops to about 8ma .

Anyway if you have a external precision RTC you can use it to calibrate the internal RTCC i would like to see what the long term drift of the internal RTCC..

ken
 
DuinoMiteMegaAn
Senior Member

Joined: 17/11/2011
Location: Australia
Posts: 231
Posted: 05:10pm 13 Dec 2011
Copy link to clipboard 
Print this post

Anyway if you have a external precision RTC you can use it to calibrate the internal RTCC i would like to see what the long term drift of the internal RTCC..


The internal RTCC, I believe, uses the "32768 hz watch crystal" which is no better than +- 20 PPM. (Greater than -+10 minutes per year) If this "watch crystal" is
exposed to anything other than ambient temperature, this +-10 minute error will increase/decreased dramatically. Of course, you could calibrate the RTCC,
with expensive equipment, for better accuracy but what would the calibration temperature be when you are using it for data logging where the
ambient temperatures varies a lot? You need a +- 2 ppm temperature controlled oscillator precision RTC - Maxim-IC DS3231 which is code compatible with
the DS1307. The drift would only be +-1 minute per year under large temperature extremes! Having this precision RTC with the flexible power savings
on the Duinomite would be the perfect data logging choice.
Note: You need to use only a 3.3 VDC RTC (Not +5 VDC) for the DuinoMite Mega if you are using the Lipo power source for data logging!

BTW ... Olimex could easily produce a DS3231 UEXT board. This SMD SOIC16 only chip is $7.0 USD (expensive) but it is well worth it.

There are, on the internet, two breakout boards containing the DS3231. One is from
Macetech US (ChronoDot) and the other is from Love Electronics UK. Both of them
cost about ~ $15 USD which I believe is outrageous! I got both of them working
on the DuinoMite Mega. Edited by DuinoMiteMegaAn 2011-12-15
 
DuinoMiteMegaAn
Senior Member

Joined: 17/11/2011
Location: Australia
Posts: 231
Posted: 12:03pm 14 Dec 2011
Copy link to clipboard 
Print this post

i would like to see what the long term drift of the internal RTCC..


Just take the board out of ambient temperature and you will see.
Of course, set the clock to a known good reference.

Again, has anyone seen an Unix time algorithm in GW-Basic?
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6097
Posted: 02:02am 15 Dec 2011
Copy link to clipboard 
Print this post

  DuinoMiteMegaAn said  

Again, has anyone seen an Unix time algorithm in GW-Basic?

Apart from the 2038 problem which I hope I am still around to see,
MM Basic integer numbers are +/- 16777100 without loss of accuracy.

That equates to 20/06/1969 19:41:40 to 14/07/1970 04:18:20
Not a lot of use.....

I tried an experiment and using today's date going from normal to unix and back again puts you out by around 20 seconds.

I will do some tests using other options and report back when I have time.

I think the best option is to keep whole days and part days separate.

Jim
VK7JH
MMedit   MMBasic Help
 
DuinoMiteMegaAn
Senior Member

Joined: 17/11/2011
Location: Australia
Posts: 231
Posted: 03:55am 15 Dec 2011
Copy link to clipboard 
Print this post

Here is an unix algorithm, I got from the Internet and converted to MMBasic.
I believe MMBasic forces an error of 16 seconds.

What the author did was to shift the seconds base from 1970 to 2000.
Then he added (SECONDS_FROM_1970_TO_2000) 946684800 seconds to make it unix time.
Maybe we could shift the time base to 2010?

Test code only - possible bugs!
Note: Leap seconds not accounted for?

10 'Code by JeeLabs http://news.jeelabs.org/code/
20 'Released to the public domain! Enjoy!
30 ' - Thanks Jean C Wippler!
40 'RTClib.cpp was modified from a C++ lib. to MMBasic by DuinoMiteMegaAndy
50 'https://github.com/adafruit/RTClib
60 '
70 '--------UNIX_R1.bas----------------------------
80 '--------Unix time utilities for elapse time data logging --------------
90 'Manual prompt input year/month/day/hours/minutes/seconds
100 'Generates Unix time (in seconds since year 1970) for data logging
110 '
120 '
130 'Author: Hacker - DuinoMiteMegaAndy
140 'Date: 27/11/2011
150 'Version: Rev. 1.0b
160 'MMBasic Firmware: 2.7 DuinoMite Mega
170 'Platform: Win XP/SP3
180 '
190 '
200 ' --------------Code Begin--------------------
210 SECONDS_PER_DAY = 86400
220 SECONDS_FROM_1970_TO_2000 = 946684800
230 '
240 '
250 'Number of days since 2000/01/01, valid for 2001..2099
260 DATA 0,31,28,31,30,31,30,31,31,30,31,30,31
270 DIM days(13) '12 months
280 INPUT "Year yyyy"; Year
290 INPUT "Month 1-12"; Month
300 INPUT "Day 1-31"; Day
310 TempD = 0
320 IF year >= 2000 THEN year = year - 2000
330 FOR I=0 TO 12 'put data in days array
340 READ Days(I)
350 '? "days ",days(I) 'data in array
360 NEXT I
370 IF Month >= 1 OR Month <= 12 THEN GOSUB 530
380 '? " total days before leap year ",tempD
390 IF (Month > 2 AND Year MOD 4 = 0) THEN tempD = tempD + 1 'leap year?
400 '? " total days after leap year ",tempD
410 day_total = tempD
420 day_total = FIX(day_total + (365 * Year) + (Year + 3) / 4 - 1)
430 ? "Number of days since 2000/01/01 ",day_total
440 INPUT "Hour 0-23 ";Hour
450 INPUT "Minute 0-59 ";Minute
460 INPUT "Second 0-59 ";Second
470 Unix_Time = day_total * 24
471 ? " Unix Time hours ": ? FORMAT$(Unix_Time,"%10.1f")
472 Unix_Time = Unix_Time + hour
473 ? " Unix Time + hours ": ? FORMAT$(Unix_Time,"%10.1f")
474 Unix_Time = Unix_Time * 60
475 ? " Unix Time Minutes ": ? FORMAT$(Unix_Time,"%10.1f")
476 Unix_Time = Unix_Time + minutes
477 ? " Unix Time +Minutes ":? FORMAT$(Unix_Time,"%10.1f")
478 Unix_Time = Unix_Time * 60
479 ? " Unix Time Seconds ": ? FORMAT$(Unix_Time,"%10.1f")
480 Unix_Time = Unix_Time + seconds
481 ? " Unix Time +Seconds From Year 2000 on 1/1 ": ? FORMAT$(Unix_Time,"%10.1f")
482 Unix_Time = Unix_Time + 946684800
490 ? "Unix Time Seconds From Year 1970 on 1/1 ": ? FORMAT$(Unix_Time,"%10.1f")
500 '
510 END
520 '
530 FOR I=1 TO Month - 1
540 tempD = days(I) + tempD
550 '? "array add ",tempD
560 NEXT I
570 tempD = tempD + day
580 RETURN
590 '
600 '
610 END

Edited by DuinoMiteMegaAn 2011-12-16
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6097
Posted: 07:02am 15 Dec 2011
Copy link to clipboard 
Print this post

A couple of typos:
450 INPUT "Minute 0-59 ";Minute
460 INPUT "Second 0-59 ";Second

You Minute and second but later they gain an 's'
476 Unix_Time = Unix_Time + minutes

Even with that fixed, try entering two times one minute apart and subtract the two 'unix times' to see how many seconds there are.
You will get different answers depending on whether you use time since 200 or 1970.
Neither will be 60 seconds.

It is hard to get away from the lack of significant figures in 32bit numbers.
You have to keep the numbers to a max of 7 digits.

You CAN do integer maths but it is much easier to simply keep the whole days and the part days separate and forget about unix time.

Jim
VK7JH
MMedit   MMBasic Help
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6097
Posted: 07:31am 15 Dec 2011
Copy link to clipboard 
Print this post

Try this simple code:


100 bignumber=9999999
110 biggernumber=bignumber*100
120 nextnumber=biggernumber+1
130 print "Starting number ";format$(bignumber,"%11.0f")
140 print "Multiplied by 100 ";format$(biggernumber,"%11.0f")
150 print "adding one ";format$(nextnumber,"%11.0f")



Jim
VK7JH
MMedit   MMBasic Help
 
DuinoMiteMegaAn
Senior Member

Joined: 17/11/2011
Location: Australia
Posts: 231
Posted: 12:08pm 15 Dec 2011
Copy link to clipboard 
Print this post

It is hard to get away from the lack of significant figures in 32bit numbers.
You have to keep the numbers to a max of 7 digits.


9,999,999 <--- Max for MMBasic PIC32 32 bit


and forget about unix time.


I will just use a date/time stamp string for data logging and let PC Excel take care of the conversion.Edited by DuinoMiteMegaAn 2011-12-16
 
DuinoMiteMegaAn
Senior Member

Joined: 17/11/2011
Location: Australia
Posts: 231
Posted: 05:10pm 15 Dec 2011
Copy link to clipboard 
Print this post

@TassyJim

Explain this from my Unix simulator?

Inputs
yr 2011
mon 12
day 15

Hr. 0
min 0
sec 0

Calculated Unix time from MMBasic (in seconds)
1323907200.0

12 /15 / 2011 <---------- Calculator on Internet - "Spot ON"
Hour : Minute : Second
0 : 0 : 0

==================================================

Inputs
yr 2011
mon 12
day 16

Hr. 0
min 0
sec 0

Calculated Unix time from MMBasic (in seconds)
1323993600.0

12 /16 / 2011 <---------- Calculator on Internet - "Spot ON"
Hour : Minute : Second
0 : 0 : 0

===================================================


The moment I add any " RTC time offset" to the calculation the calculation is wrong - probably due to your 7 digit max. limit in MMBasic?

So how does both date calculations (without time offset) compute "SPOT ON" when
there are numbers larger than 7 digits in the calculation?


BTW ... From the Olimex pdf manual "limits"
The range of integers (whole numbers) than can be manipulated without loss of accuracy is ±16777100. Edited by DuinoMiteMegaAn 2011-12-18
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024