zerog2k / stc_diyclock

STC DIY Clock redux (STC15F204EA, STC15W404AS, STC15W408AS)
MIT License
170 stars 67 forks source link

rough static time correction #50

Closed venustrg closed 4 years ago

venustrg commented 4 years ago

very rough time correction. if your watch is used at a relatively constant temperature and constantly goes ahead 5 seconds a month, just build with -DWITH_MONTHLY_CORR=-5 to compensate these 5 seconds. a period is calculated after which a correction of 1 second is required. not so accurate timer is used, because my STC15W404 has no enough program space to implement something like unixtime for rtc or setting adjustment value.

such a correction cannot be called precise, but it is better than nothing. it's possible to achieve decent accuracy without multiple quartz replacements.

and of course this doesn't work while running on battery/capacitor.

tested, correction works great while powered from power supply. i'm waiting for stc15w408 to add sntp sync.

zerog2k commented 4 years ago

not sure if this is helpful, but I seem to recall that you could play tricks with stc mcu's by putting functions/tables/etc into "eeprom" space - as they are addressible/executable in extended program/code space, because eeprom is extended into the address space beyond the program code space (via extended addressing?). e.g. https://github.com/zerog2k/stc_diyclock/blob/master/src/led.h#L20

zerog2k commented 4 years ago

I wonder if there is a way to do this calibration by only observing the rtc, e.g. if you decided that you need x seconds of "calibration", do this calibration on days or hours, e.g. by determining the calibration factor for 1 sec / N hours passed, and keeping track of the number of hours passed, then performing calibration?

Likewise, determining a "seconds of drift per month" may be slightly off, as there is no standard length of "month", unless we determine the calibration constant to be over an interval of precisely 30 days, etc.

venustrg commented 4 years ago

in fact, "seconds per month" is a very approximate value, especially considering the inaccuracy of the timer. this value is only used to calculate the number of seconds after which the time is adjusted for 1 second forward or backward. but adjusting this value can significantly improve the accuracy of the watch.

initially, i wanted to make the value customizable from the menu, since 4 bits still unused in rtc memory, but I did not have enough program memory for this. and the ordered stc15w408 chips haven’t arrived yet.

right now i'm satisfied with my clock accuracy. and i'm planning to add sntp sync via esp8266 after receiving stc15w408.

venustrg commented 4 years ago

chime_trigger is 3-state. 0 -- no chime/ready to beep 1 -- do chime, on/off beep 2 -- wait > 1 sec before going ready (0) state (until seconds will be > 0) it can be an enum but i just made it byte

i prefer to write if (chime_trigger) instead of if (chime_trigger != CHIME_OFF)

venustrg commented 4 years ago

chime_trigger is now enum. correction also works fine.