atme128 and timers

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Folk,
I use timer0 in ATmega128

outp(0, TCNT0); // reset TCNT0
outp(6, TCCR0); // (1/8M) * 256 = 32 usec

outp((1<<TOIE0), TIMSK);

SIGNAL(SIG_OVERFLOW0) // signal hand for tcnt0 overflow interrupt
{
......
}

all is o.k.

if I do the same with timer2
and I want to use both timer0 and timer2

outp(0, TCNT2); // reset TCNT2
outp(4, TCCR2); // (1/8M) * 256 = 32 usec

outp((1<<TOIE2), TIMSK);

SIGNAL(SIG_OVERFLOW2) // signal hand for tcnt2 overflow interrupt
{
......
}

IF I WANT TO USE BOTH OF THEM
THE TIMERS DO NOT RUN

what am I wrong ?

baldo
Italy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't use ATmega103 compatibility (I want to use PORTG)
I'm using Win Avr

Regards,

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

outp((1<<TOIE2), TIMSK);

will set only the one enable, and clear any others, thus only one timer will run at a time.

If you need both you will need to use

outp(((1<<TOIE0)|(1<<TOIE2)), TIMSK);

or more correctly, since outp() is depricated:

TIMSK = (1<<TOIE0) | (1<<TOIE2);

you can alos split it when dealiing with TIMSK as a variable.

TIMSK = 1<<TOIE0;
.
.
.
TIMSK |= 1<<TOIE2;

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks a lot
anonimous friend

it works now !