I know the instruction time is 20/4 (assuming 20MHz clock).
So if the timer registers were larger it would count 5M timer ticks per second.
DT’s Elapsed timer works by subtracting whatever value (depending on the clock speed)
from the timer overflow value to achieve 100 interrupts (and 8 instruction timer reload) per second.
I understand the 8 instruction cycles are compensated for in the constant value that will be continually reloaded to the timer.
My position is that one doesn’t subtract the value from $FFFF, but from $0000 which is where the overflow interrupt occurs.
The way that I synced the 1Hz pulse generated by the Elapsed timer code to a GPS pulse per second output
is by connecting it to portb.0 interrupt, and only allowing the interrupt to reset the second once.
The port.0 interrupt does not look at the timer value, only resets ticks so only synchronised within 1/100th of a second.
It only takes a little over an hour for a Human to notice (looking at two flashing LEDs) for them to desynchronise.
If the constant value is incremented by one, I’m on the third hour watching it so far.
Initially I was using a crystal running the Elapsed timer, but now rubidium.
Code:
'in the ISR after time variables are incremented
‘so don’t look at this yet, execution hasn’t gone here
'
if INTCON.4 = 1 then ' check if portb.0 interrupt enabled
if INTCON.1 = 1 then ' check if portb.0 interrupt occurred
INTCON.4 = 0 ' disable portb.0 interrupt
INTCON.1 = 0 ' clear portb.0 interrupt flag
Ticks = 0 ' reset current second to gps pulse
endif
endif
‘
‘since the timer ISR was called by port.0 interrupt,
‘and not by timer overflow, any value could be in the timer.
’The Ticks are reset to extend the length of the current second.
‘We are only synchronised to within 1/100th of a second now,
‘but that’s enough for this purpose.
‘
'at the start of main program
'
'
INTCON.4 = 0 ' disable portb.0 interrupt
INTCON.1 = 0 ' clear portb.0 interrupt flag
'
INCLUDE "ElapsedTimer.bas"
'
'reset, and start the timer, etc.
‘
‘
‘when the main program has run for some seconds
‘the qualify bit can be set with a button, or auto set after some seconds have passed
‘
if qualify = 1 then ' synchronise command was qualified
OPTION_REG.6 = 1 ' interrupt on rising edge of portb.0
INTCON.1 = 0 ' clear portb.0 interrupt flag
INTCON.4 = 1 ' enable portb.0 interrupt
'
‘some audible verification the sync command was qualified
‘
ENDIF
Bookmarks