Not too bad !
In fact, this code is the best one as the overflow can occur AFTER the read of TCNT1, so incrementing "upper" is a bad solution.

Thanks a lot to every one.
Eric.


----- Original Message ----- From: "Galen Seitz" <[EMAIL PROTECTED]>
To: <avr-gcc-list@nongnu.org>; "Eric Pasquier" <[EMAIL PROTECTED]>
Sent: Thursday, October 13, 2005 1:22 AM
Subject: Re: [avr-gcc-list] 32-bits time



What about something like this:

uint16_t upper, lower;
uint32_t time;

cli();
lower = TCNT1;
upper = hiword_time;
// Force lower bytes to max value if a timer overflow interrupt is pending.
// This assumes the latency on the overflow flag is less than the time it
// takes to execute the previous two statements.
if (timer1 overflow)
  lower = 0xffff;
time = upper<<16 | lower;
sei();


galen




_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to