[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] Problem with timing
From: |
Juraj |
Subject: |
[avr-gcc-list] Problem with timing |
Date: |
Tue, 03 Feb 2004 20:02:33 +0100 |
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] Problem with timing,
Juraj <=