[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] 32-bits time

From: Bjarne Laursen
Subject: Re: [avr-gcc-list] 32-bits time
Date: Thu, 13 Oct 2005 09:10:17 +0200
User-agent: Mozilla Thunderbird 0.7.3 (Windows/20040803)

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;
   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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]