A few additions to David Kelly's code:
inline uint32_t timer32_now(void)
{
int8_t sreg;
union {
struct {
uint16_t lo, hi;
} w;
uint32_t l;
uint8_t b[4]; // <------ added: access as bytes
} temp;
sreg = SREG;
cli();
temp.w.lo = TCNT1;
temp.w.hi = hiword_time;
// --------- if TOV1 gets set here, temp will not need any
correction, this is indicated by temp.w.lo close to 0xFFFF
// check for unserved Timer1 Overflow
if( TIFR & (1<<TOV1) )
if (temp.b[0] < 128) // <-----------added: check if temp is
wrapped around
temp.w.hi++; // do what hasn't yet been done in
SIG_OVERFLOW1
SREG = sreg;
return( temp.l );
}
------------------------------------
I think that the code from Galen Seitz works too.
It is more simple, but the exact sampletime of the clock will vary a little.
Since you chose prescaler=1 you might need the higher precision. I don't
know.
_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list