avr-gcc-list
[Top][All Lists]
Advanced

[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 17:38:02 +1000

> -----Original Message-----
> From: Eric Pasquier [mailto:address@hidden
> Sent: Thursday, 13 October 2005 5:13 PM
> To: Loveny Design
> Subject: Re: [avr-gcc-list] 32-bits time
>
>
> Hi Jon,
>
> No, your code doesn't work as the timer is clock with the CPU clock.
> The test (TCNT1<tempL) is "always" true ... (modulo 256).
>
> Eric
>
??? TCNT1 is 16 bits and counts up... tempL is 16 bits, so what's modulo 256
got to do with anything? In 'normal' operation TCNT1 will be a few counts
more than tempL (which is the old value of TCNT1), so TCNT1 will be greater
than tempL so the comparison will be FALSE, hence the loop will terminate.
The condition is only TRUE when rollover occurs. The only problem is making
sure the loop itself takes less time than 65536 counts.

Jon


> ----- Original Message -----
> From: "Loveny Design" <address@hidden>
> To: <address@hidden>
> Cc: "Eric Pasquier" <address@hidden>
> Sent: Thursday, October 13, 2005 1:14 AM
> Subject: RE: [avr-gcc-list] 32-bits time
>
>
> > 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




reply via email to

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