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

[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: Thu, 05 Feb 2004 19:19:59 +0100

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.
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > So here is part of main programm:
> > 
> > #include "timer.h"
> > 
> > int main(void) {
> > .
> > .
> >     timer0_init();
> >     while(1){
> >             LED_ON;         //sets the output 
> >             ms_delay(500);
> >             LED_OFF;        //clears the output
> >             ms_delay(500);  
> >     }
> > .
> > .
> > }
> > 
> > 
> > *******************************************************************************************
> > 
> > And here is timing module - timer.c:
> > 
> > #include <avr/timer.h>
> > #include <avr/interrupt.h>
> > #include <avr/signal.h>
> > #include <inttypes.h>
> > #include "casovac.h"
> > 
> > volatile uint32_t ms_timer = 0;
> > 
> > 
> > void timer0_init(void)
> > {
> >     timer_enable_int( BV(TOIE0) );
> >     timer0_source(CK64);
> >     TCNT0 = PRESCALE_LO;
> > }
> > 
> > 
> > SIGNAL(SIG_OVERFLOW0)                  // signal handler for tcnt0
> > overflow interrupt
> > {
> >     ms_timer++;                    // increment timer counter
> >     TCNT0 = PRESCALE_LO;   
> > }
> > 
> > 
> > void ms_delay(uint16_t ms )
> > {
> > uint32_t koniec = ms_timer + (uint32_t)ms;
> >     
> >     while( ms_timer < koniec );
> > }
> > 
> > *******************************************************************************************
> > 
> > And timer.h:
> > 
> > #define     F_CPU           8000000         
> > #define     PRESCALE_HI     64              
> > #define     PRESCALE_LO     ( 256 - ( (F_CPU/PRESCALE_HI) / 1000 ) )  
> >             
> > extern volatile uint32_t ms_timer;
> > 
> > void timer0_init(void);
> > void ms_delay(uint16_t ms );
> > 
> > *******************************************************************************************
> > 
> > 
> > 
> > 
> > -- 
> > 
> > ----------------------------
> > email:      address@hidden
> >     address@hidden
> > http://     durec.szm.sk
> > 
> > 
> > _______________________________________________
> > avr-gcc-list mailing list
> > address@hidden
> > http://www.avr1.org/mailman/listinfo/avr-gcc-list
> > 
-- 

----------------------------
email:  address@hidden
        address@hidden
http:// durec.szm.sk



reply via email to

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