[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [avr-gcc-list] 32-bits time
From: |
Gavin Jackson |
Subject: |
RE: [avr-gcc-list] 32-bits time |
Date: |
Thu, 13 Oct 2005 11:08:04 +1300 |
>> 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 ?
>
>1: lds r22, TCNT1L
> lds r23, TCNT1H
> lds r24, hiword_time
> lds r25, hiword_time + 1
> lds r0, TCNT1L
> cp r0, r22
> brne 1b
> ret
>
>This code work if you will use it only with flag 'SREG.I' setting.
I don't think this is going to work with the prescaler set to 1.
r22 and R0 will always be different by the time you come to doing
the cp R0, R22.
cli
lds r22, TCNT1L
lds r23, TCNT1H
lds r24, hiword_time
lds r25, hiword_time + 1
sei
will capture the time the moment the TCNT1L is read. When the low byte
of the timer is read, the high byte is latched. By disabling interrupts
you prevent the overflow of the timer changing the two bytes that make
up your hi_word time variable.
Gavin
- [avr-gcc-list] 32-bits time, Eric Pasquier, 2005/10/12
- RE: [avr-gcc-list] 32-bits time,
Gavin Jackson <=
- 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
Re: [avr-gcc-list] 32-bits time, Dmitry K., 2005/10/13
RE: [avr-gcc-list] 32-bits time, Loveny Design, 2005/10/13