Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Setting timer0 on Atmega48

2011-09-24 by Philippe Habib

This should be a simple thing but I'm having trouble getting it to work.  

I want a regular interrupt every 10ms while using the internal 8Mhz oscillator.  I'm using AVR studio with the default (GCC?) compiler.

Can someone let me know what I'm doing wrong?

I try to set the various timer registers like this:

	TCCR0A = 0x00;
	TCCR0B = 0x05;
	TCNT0 = 177;
	TIMSK = 0x01;

What I'm hoping for here is a timer that will use the div1024 start at 177 and set off the timer int when it overflows at 255.

Then I turn on interrupts

        SEI();


Here is my ISR:

#if __GCC__
SIGNAL(SIG_OVERFLOW0)
#else
#pragma vector=TIMER0_OVF_vect
__interrupt void TIMER0_OVF(void)
#endif
{
	uccounter++;
	TCNT0 = 177;	// reset the timer
	return;
}




uccounter is a global unsigned char.  I just use it to toggle a port when its 0.

Am I missing something and is there a library call that makes setting all this easier?

Thanks.

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.