Author | Eur van Andel, Copyright © 2003..2008, all rights reserved. |
Adapted-by | Rob Hamerling |
Compiler | 2.4l |
This Interrupt Service Routine updates the variable seconds about once per second. The precision is 0.2 ppm, the accuracy depends on the Xtal used.
http://www.romanblack.com/one_sec.htm http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
This is the Bresenham Line Algorithm, invented at IBM in 1962, which gets an accurate end result by summing the small errors resulting of taking discrete steps and correcting when the error gets too large. This means that individual second lengths may show some jitter, but that long-term timekeeping is accurate. Original assembler by Roman Black. . At 20 MHz, so 200ns/clock, so 5 000 000 clocks/second Rhe RTC has three bytes: bres_hi, bres_mid, bres_lo timer 0 runs on internal clock speed and interrupts on overflow every timer 0 interrupt decreases bres_mid by one. The 5 000 000 value is added when bres_hi en bres_mid are zero note that remainder is added to bres_lo, which can overflow in bres_mid this keeps clock count accurate, although interrupts happen every 256 clock counts the ISR subtracts 1 from the mid byte. It first checks the mid byte for zero and borrows a bit from bres_hi if needed. . Required PIC settings: T0CON_PSA = 1 T0CON_PS = 0 T0CON_T0CS = 0 -- Timer0 on instruction cycle clock
No dependency found
const _rtc_cycles_per_second = (target_clock / 4)
const byte _rtc_mid = _rtc_cycles_per_second % 65536 / 256
var volatile byte _rtc_bres_hi = _rtc_hi
var volatile byte seconds
var volatile byte _rtc_bres_lo = _rtc_lo
const byte _rtc_lo = _rtc_cycles_per_second % 256
var volatile byte _rtc_bres_mid = _rtc_mid
const byte _rtc_hi = _rtc_cycles_per_second / 65536
const _rtc_cycles_per_second = (target_clock / 4)
No documentation found
const byte _rtc_mid = _rtc_cycles_per_second % 65536 / 256
No documentation found
var volatile byte _rtc_bres_hi = _rtc_hi
\
var volatile byte seconds
global variable updated by ISR
var volatile byte _rtc_bres_lo = _rtc_lo
/
const byte _rtc_lo = _rtc_cycles_per_second % 256
No documentation found
var volatile byte _rtc_bres_mid = _rtc_mid
> init 3-byte counter
const byte _rtc_hi = _rtc_cycles_per_second / 65536
No documentation found
RTC()
No documentation found
16f876a | 16f876a_rtc_lcd.jal |
16f876a | 16f876a_rtc_timeset.jal |
16f877a | 16f877a_rtc_timeset.jal |
16f877a | 16f877a_rtc_lcd.jal |
16f886 | 16f886_rtc_lcd_20mhz.jal |
16f886 | 16f886_rtc_lcd_4mhz.jal |
16f886 | 16f886_rtc_lcd_125khz.jal |