[time-nuts] First success with very simple, very low cost GPSDO, under $8
orin.eman at gmail.com
Wed Apr 9 12:39:30 EDT 2014
On Wed, Apr 9, 2014 at 2:08 AM, Hal Murray <hmurray at megapathdsl.net> wrote:
> holrum at hotmail.com said:
> > I'm not sure how the Arduino environment handles interrupts, but in C
> > need to declare any variables altered by an interrupt as "volatile" so
> > the compiler optimization routines know not to assume they contain known
> > values.
> Good point.
> > Also any code that accesses them needs to do so with interrupts turned
> > off... otherwise you can wind up with corrupted values.
> Not quite. That may be the simplest way, but you can also use
> communications type tricks. The classic for a two byte counter is to read
> high-low-high and try again if the high values don't match. That assumes
> interrupt routine updates low then (maybe) high.
You have to read hardware counter registers on some PIC chips that way.
You have to read the documentation carefully to work out how to correctly
read 16bit counters on an 8 bit CPU.
The order the interrupt routine updates the counter shouldn't matter since
it's atomic as far as the mainline code is concerned.
More information about the time-nuts