set_clock script function to set camera date / time - General Discussion and Assistance - CHDK Forum  

set_clock script function to set camera date / time

  • 16 Replies
  • 5983 Views
*

Offline reyalp

  • ******
  • 14117
set_clock script function to set camera date / time
« on: 16 / August / 2020, 02:25:27 »
Advertisements
In 5552 I added a lua function set_clock to set the camera date / time.

syntax is
set_clock(year, month, day, hour, minute, second)

Values are integers and all are required.

Values are all exactly as they would appear in the camera clock: 4 digit year, month and day numbers start at 1. It is not aware of DST, the displayed time after setting is the values set, regardless of the DST setting.

If you want to set just one value, for example to set one hour forward, you could do something like
Code: [Select]
t=os.date('*t') -- current date / time as table
set_clock(t.year,t.month,t.day,t.hour + 1, t.min, t.sec)

If you want to set it from a timestamp value, you can pass the timestamp as the second parameter of os.date and use it as above. For example, to set 10 seconds ahead, you could do
Code: [Select]
t=os.date('*t', os.time() + 10)
set_clock(t.year,t.month,t.day,t.hour, t.min, t.sec)
This is a safer than manipulating individual values, since you don't have to worry about days / hours etc going out of range.

It uses the SetDate eventproc. Advantage of having it built in is that it avoids the need to call registration event procs which can have negative side effects. Additionally, it takes care of updating tick_count_offset for DNG subsec time.

The CHDK code doesn't do any validation, so if you decide to set it to 25:99 hours on Feb 30, you get whatever the camera OS does this that.

I called it set_clock because it's not symmetric with any of the various get date/time functions.

From my testing, it updates the RTC, so the set time will be kept even if the camera shuts down abnormally after the set (discussion in https://chdk.setepontos.com/index.php?topic=13856.msg143971#msg143971)

edit:
Corrected code examples to use set_clock(). Thanks Mlapse for catching the typo.

edit:
In 5553, I fixed a bug that caused seconds to be set to the minute value  :-[
« Last Edit: 16 / August / 2020, 20:30:04 by reyalp »
Don't forget what the H stands for.

*

Offline Caefix

  • *****
  • 947
  • Sorry, busy deleting test shots...
Re: set_clock script function to set camera date / time
« Reply #1 on: 19 / August / 2020, 15:22:32 »
A ptp function to sync cams´ with computers´ clock could be useful, at least for rigs with cams with outdated battery.  8)
All lifetime is a loan from eternity.

*

Offline reyalp

  • ******
  • 14117
Re: set_clock script function to set camera date / time
« Reply #2 on: 19 / August / 2020, 16:20:47 »
A ptp function to sync cams´ with computers´ clock could be useful, at least for rigs with cams with outdated battery.  8)

Code: [Select]
!require'extras/synctime'.sync()
If the camera is showing the "set time" prompt, you still need to click SET to close the menu.

I'll probably move this out of extras and make it a command now that it doesn't depend on eventprocs.
Don't forget what the H stands for.

*

Offline Mlapse

  • *****
  • 584
  • S95 S110
Re: set_clock script function to set camera date / time
« Reply #3 on: 25 / August / 2020, 03:34:57 »
I did a 10 day test with reboot every day and it does exacly what is says on the tin, thanks reyalp.

I found out that the reboot takes up 22 seconds

So i reset the time to -60 seconds before reboot (2 sec sleep)
the result in the log is -58 seconds when the script starts reboot, 5 sec before script becomes active again.
It is consistant, so that is a good thing.
But I feel there is still something wrong, because of the CHDK delay to start large SD cards. 5 seconds loss seems not enough..but i'll leave that for now.

I'm still convinced that the RTC is more accurate than OS clock. If that is true setting RTC with set_clock will not solve the floating time of OS clock...it just makes it less visible
« Last Edit: 25 / August / 2020, 05:09:25 by Mlapse »
frustration is a key ingredient in progress


*

Offline reyalp

  • ******
  • 14117
Re: set_clock script function to set camera date / time
« Reply #4 on: 25 / August / 2020, 13:34:59 »
I'm still convinced that the RTC is more accurate than OS clock. If that is true setting RTC with set_clock will not solve the floating time of OS clock...it just makes it less visible
In my experience, the RTCs are not very accurate. I haven't measured it carefully, but my impression is seconds per day is common. I don't know how the OS clocks differs, my cameras usually don't run that long ;)
Don't forget what the H stands for.

*

Offline Mlapse

  • *****
  • 584
  • S95 S110
Re: set_clock script function to set camera date / time
« Reply #5 on: 25 / August / 2020, 14:09:47 »
In my experience, the RTCs are not very accurate.

I know, most my cams run about 1 minute per month too quickly.

And what I know from the data is that, depending on how dark the period is, there is a variable difference in time between RTC and OS.
On all cams I tested It is true that the OS clock runs slightly faster than the RTC
As some of you will know, when installing windows in the old days, that last minute could take more than a lunchbreak  ;)

Now, as I understand RTC is independantly running on the battery and OS is running on the system chip.

So I assume that the RTC has a non-influenced, thus stable, clock (maybe not atomic clock accurate, but consistant) while the OS clock is fluctuating because of the system reaching max load/throughput.

What do you think?
« Last Edit: 25 / August / 2020, 15:22:54 by Mlapse »
frustration is a key ingredient in progress

*

Offline reyalp

  • ******
  • 14117
Re: set_clock script function to set camera date / time
« Reply #6 on: 25 / August / 2020, 17:00:01 »
So I assume that the RTC has a non-influenced, thus stable, clock (maybe not atomic clock accurate, but consistant) while the OS clock is fluctuating because of the system reaching max load/throughput.

What do you think?
The crystals in normal cheap RTCs are significantly affected by temperature. For a random example, see the application note at https://www.nxp.com/products/peripherals-and-logic/signal-chain/real-time-clocks/rtcs-with-ic-bus/100-na-real-time-clock-calendar-with-battery-backup:PCF8523?&tab=Documentation_Tab&linkline=Application-Note
It notes that
Quote
* A clock running 1 s per day too fast has an inaccuracy of 1/(3600*24) = 11.57 ppm
* A deviation of 1 s per week means 1.65 ppm

The temperature dependence may be particularly significant for CHDK timelapse applications, because operating continuously for long periods can result in high internal temperatures that would be less common in normal usage.

There are also aging effects, which might be significant given that many CHDK cameras are used long beyond their typical consumer lifetime.

The OS clock is based on a high frequency timer on the SOC which I would expect to be fairly accurate and relatively unaffected by CPU load, but I don't really know. Canon probably doesn't have a requirement for high accuracy of the OS clock, since normal usage would be for it be powered off most of the time, and restarted frequently.
Don't forget what the H stands for.

*

Offline c_joerg

  • *****
  • 1251
Re: set_clock script function to set camera date / time
« Reply #7 on: 26 / August / 2020, 02:22:39 »
On cams with GPS. Is it possible to synchronize time with GPS time?
M100 100a, M3 121a, G9x II (1.00c), 2*G1x (101a,100e), S110 (103a), SX50 (100c), SX230 (101a), S45,
Flickr https://www.flickr.com/photos/136329431@N06/albums
YouTube https://www.youtube.com/channel/UCrTH0tHy9OYTVDzWIvXEMlw/videos?shelf_id=0&view=0&sort=dd


*

Offline Mlapse

  • *****
  • 584
  • S95 S110
Re: set_clock script function to set camera date / time
« Reply #8 on: 26 / August / 2020, 04:19:32 »
The temperature dependence may be particularly significant for CHDK timelapse applications, because operating continuously for long periods can result in high internal temperatures that would be less common in normal usage.
I've read the spec sheet but haven't done calculations on it with my data yet.
the 5 seconds per week difference between summer and winter in a 3 week run can have a few days of 20 ºC difference (32-50 ºC) at exceptional hot summer days in the run
but is usually less than 10 ºC between all runs (from the data: 31-35 januari, 32-42 ºC july)....the advantage of having it always powered is a slightly higher, but fairly stable temperature
Quote
The OS clock is based on a high frequency timer on the SOC which I would expect to be fairly accurate and relatively unaffected by CPU load, but I don't really know.
Me neither.
Since I have no realiable means to test what is the most accurate clock of the 2 I'll abandon the idea of using RTC time.
« Last Edit: 26 / August / 2020, 04:57:16 by Mlapse »
frustration is a key ingredient in progress

*

Offline reyalp

  • ******
  • 14117
Re: set_clock script function to set camera date / time
« Reply #9 on: 27 / August / 2020, 18:52:55 »
On cams with GPS. Is it possible to synchronize time with GPS time?
According to the SX260 manual, this seems to be a feature of the stock firmware (page 51 of the English version) under menu item "GPS Auto Time". It states that when this is enabled, the normal time setting UI is disable, so it's not clear how it would interact with set_clock.

If "GPS Auto Time" is turned off, one could probably get the time from the GPS propcase from script and then use set_clock
Don't forget what the H stands for.

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal