[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Problem with timing
From: |
Juraj |
Subject: |
Re: [avr-gcc-list] Problem with timing |
Date: |
Mon, 09 Feb 2004 22:16:17 +0100 |
Hi Anton,
thanx for your solution, this helped.
Thanks also all, for answers..
Juraj.
On Fri, 2004-02-06 at 22:35, Anton Erasmus wrote:
> On 2004/02/05 at 07:19 Juraj wrote:
>
> >Hi Keith, and all!
> >
> >ms_timer is once set to 0 in definition in timer.c:
> >volatile uint32_t ms_timer = 0;
> >
> >and is incremented by one every 1 milisecond in interupt.
> >The main idea was:
> >variable ms_timer is 32bit long unsigned, so that max. value is
> >4.29497e+09.
> >4.29497e+09 miliseconds is about 49 days, and because of it, this
> >variable never overruns in my application.
> >
> >Variable ms_timer is used just as real time running in background, and
> >its value is used when needed.
> >
> >I'll try to use compare match, as wrote Andras Nagy.
> >
> >Thanks all..
> >
> >Juraj.
> >
> >
> >
> >On Tue, 2004-02-03 at 21:18, Keith Gudger wrote:
> >> Where is ms_timer set and reset to 0? Shouldn't your code be:
> >>
> >> while( ms_timer < koniec );
> >> ms_timer = 0 ;
> >> }
> >>
> >> Keith
> >>
> >>
> >> On Tue, 3 Feb 2004, Juraj wrote:
> >>
> >> > Hi all..
> >> >
> >> > Perhaps, it is trivial problem, but I cannot find the bug.
> >> > Please help.
> >> >
> >> > I have LED, connected to AVR. I want to get blinking LED, with 1:1
> >> > alternation:
> >> > LED_ON - 500ms delay - LED_OFF - 500ms delay - LED_ON ...
> >> >
> >> > Problem is - times are not always 500ms, some of periodes are shorter.
> >> >
> >> >
> >> > Thank you very much.
> >> >
> >> > Juraj.
> >> >
>
> [Code Snipped]
>
> You must protect the access to the multibyte timer variable.
>
> void ms_delay(uint16_t ms )
> {
> uint32_t koniec,tmp;
>
> ATOMIC_START();
> koniec = ms_timer;
> ATOMIC_END();
> koniec+=(uint32_t)ms;
>
> do
> {
> ATOMIC_START();
> tmp=ms_timer;
> ATOMIC_END();
> }
> while( tmp < koniec );
> }
>
> The simple implimentation for ATOMIC_START and ATOMIC_END is
> disable interrupts in ATOMIC_START and enable interrupts in ATOMIC_END.
> For some applications you might have to only disable/enable the actual timer
> interrupt
> used for the 1ms interrupt.
>
> Regards
> Anton Erasmus
>
>
--
----------------------------
email: address@hidden
address@hidden
http:// durec.szm.sk