[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [avr-gcc-list] 32-bits time
From: |
Loveny Design |
Subject: |
RE: [avr-gcc-list] 32-bits time |
Date: |
Thu, 13 Oct 2005 09:14:40 +1000 |
Hi Eric,
It's the TCNT1 rollover you want to avoid, rather than the interrupt. You
could either stop the timer while accessing the register, or simply check
for overflow as follows :-
inline uint32_t timer32_now(void)
{
uint16_t tempL, tempH;
do
{
tempL=TCNT1;
tempH=hiword_time;
} while (TCNT1 < tempL);
return (((uint32_t)(tempH)<<16) + tempL);
}
Regards,
Jon
-----Original Message-----
From: address@hidden
[mailto:address@hidden Behalf Of
Eric Pasquier
Sent: Thursday, 13 October 2005 6:22 AM
To: address@hidden
Subject: [avr-gcc-list] 32-bits time
Dear All,
I have implemented a 32-bits time information using the code below.
Timer1 is incremented using internal clock, prescaler=1;
SIG_OVERFLOW interrupt is used to increment a variable used to complete the
16-bits of Timer1.
In fact, the code below have the following problem: if the call is made
exactly when the counter overflow, TCNT1 (tempL) is equal to zero, but
hiword_time (tempH) is pending to be incremented, leading to an error (time
is returning in the past).
Does anybody has a solution ?
I was thinking testing the interrupt flag during the critical section.
Is TCNT1=0 the only case possible ?
Eric.
static uint16_t hiword_time;
//================================================
// timer32_now
// Retrieve the current time from the global clock in Timer1,
// disabling interrupts to avoid stomping on the TEMP register.
//------------------------------------------------
inline uint32_t timer32_now(void)
{
int8_t sreg;
uint16_t tempL, tempH;
sreg=SREG;
cli();
tempL=TCNT1;
tempH=hiword_time;
SREG=sreg;
return (((uint32_t)(tempH)<<16) + tempL);
}
//================================================
// SIG_OVERFLOW1
//------------------------------------------------
SIGNAL( SIG_OVERFLOW1 )
{
hiword_time++;
}
- [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