[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;
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] 32-bits time, Eric Pasquier, 2005/10/12
- RE: [avr-gcc-list] 32-bits time, Gavin Jackson, 2005/10/12
- RE: [avr-gcc-list] 32-bits time, Eric Pasquier, 2005/10/12
- Re: [avr-gcc-list] 32-bits time, Galen Seitz, 2005/10/12
- Re: [avr-gcc-list] 32-bits time, Eric Pasquier, 2005/10/13
- [avr-gcc-list] After ATMega, Eric Pasquier, 2005/10/13
- Re: [avr-gcc-list] After ATMega, Galen Seitz, 2005/10/13
- Re: [avr-gcc-list] After ATMega, Patrick Blanchard, 2005/10/13
- RE: [avr-gcc-list] After ATMega, Trampas, 2005/10/13
- RE: [avr-gcc-list] After ATMega, Patrick Blanchard, 2005/10/13