On Wed, Apr 9, 2014 at 2:08 AM, Hal Murray <hmur...@megapathdsl.net> wrote:

>
> hol...@hotmail.com said:
> > I'm not sure how the Arduino environment handles interrupts,  but in C
> you
> > need to declare any variables altered by an interrupt as "volatile" so
> that
> > 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
> inter-process
> 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
> the
> 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.

Orin.
_______________________________________________
time-nuts mailing list -- time-nuts@febo.com
To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
and follow the instructions there.

Reply via email to