[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [avr-gcc-list] Problem with timing
From: |
Dave Hansen |
Subject: |
RE: [avr-gcc-list] Problem with timing |
Date: |
Tue, 03 Feb 2004 15:34:35 -0500 |
From: Juraj <address@hidden>
[...]
Problem is - times are not always 500ms, some of periodes are shorter.
A couple problems with this code:
1) Access to multi-byte variable ms_timer is not atomic. You must disable
interrupts while accessing the variable in main-line code
2) You don't account for overflow in ms_timer, e.g. when ms_timer =
0xFFFFFE10, then koiec will be set to 0x00000004, and the ms_delay function
will return immediately.
Something like the following (untested) code might help:
void ms_delay(uint16_t delay)
{
uint32_t timer;
uint32_t start;
uint32_t elapsed;
cli();
start = ms_timer;
sei();
do
{
cli();
timer = ms_timer;
sei();
elapsed = timer - start;
} while (elapsed < delay);
}
HTH,
-=Dave
_________________________________________________________________
There are now three new levels of MSN Hotmail Extra Storage! Learn more.
http://join.msn.com/?pgmarket=en-us&page=hotmail/es2&ST=1
- RE: [avr-gcc-list] Problem with timing,
Dave Hansen <=