RE: [AVR-Chat] Delay
2004-03-22 by Dave Hylands
I used the following code for GCC on a 16-MHz Mega-8. It seems to work
fine for me. I also used the same code on an 8-MHz Mega-16, but setting
TCNT0 to 131 (125000 counts/sec and 256 - 125 = 131)
gTickCount gets incremented once every millisecond.
volatile uns16 gTickCount = 0;
/***********************************************************************
****/
/**
* Timer 0 interrupt handler
*/
SIGNAL(SIG_OVERFLOW0) /* signal handler for tcnt0 overflow
interrupt */
{
gTickCount++;
// We want our timer tick to interrupt once a millisecond.
// If we use 16 MHz/64 then we get 250000 counts/second. So setting
// things up to overflow after 250 will give us 1000
overflows/second
//
// 256 - 250 = 6
TCNT0 = 6;
} // Timer 0 Overflow
/***********************************************************************
****/
/**
* InitTimer
*/
void InitTimer( void )
{
TCCR0 = ( 0 << CS02 ) | ( 1 << CS01 ) | ( 1 << CS00 ); // Divide by
64
TCNT0 = 0;
// Enable Timer 0 interrupt
timer_enable_int( BV( TOIE0 ));
sei();
} // InitTimerShow quoted textHide quoted text
> -----Original Message----- > From: Larry Barello [mailto:yahoo@barello.net] > Sent: Monday, March 22, 2004 1:35 PM > To: AVR-Chat@yahoogroups.com > Subject: RE: [AVR-Chat] Delay > > > What compiler? What CPU clock speed? What CPU clock speed > does the compiler think you are using? > > -----Original Message----- > From: ereihani > > > HI! > For making delays I use delay_ms(). > But this doesn't work be cause when I use delay_ms(1000) for > 1 s delay i get about 8s delay. I used Timer 0 but it did't > work too! I first made 250us.Then in a for loop for 4 times i > made 1ms then 1s. But I had the same problem! Please guide me. > Regards: > Ehsan Reihani > > > > > Yahoo! Groups Links > > > > > > >