timers and carrier signals

Hi there,

I'm currently doing tests on creating carrier signals with timers. For this, i initialy want to create a rectangular signal which changes state of OC1A pin (digital pin 9 on arduino) once every second. I read the chapter timers in datasheet of atmega168 but it's a little bit... confusing to read, so i'm not sure where my error is.

I'm working on a arduino duemilanove, 16 MHz with atmega168.

Code so far:

void setup(){
  // reset settings of Timer/Counter register 1
  TCCR1A &= ~((1<

What should happen is that Timer/Counter 1 (TCNT1) should be increased every clock/1024 ticks. TCNT should be cleared when it reaches 15624 (= OCR1A, CTC mode) and the output pin OC1A should be toggled. So it should be toggled 16.000.000/1024/15624=1 times per second if i calculated right.

However, OC1A seems never to change to HIGH. Where is my error in thinking? And is there some real good tutorial on timers somewhere?

Thanks in advance for answers, Kc

The way you set the timer registers seems inconsistent to me.

For example:

TCCR1A &= ~((1<

sets 4 bits of TCCR1A to zero, whereas

TCCR1B &= ~((0<

sets only 3 bits to zero (WGM12,CS12,CS10) and the bits WGM13,CS11 are left UNCHANGED!

Clearing bits:

TCCR1A &= ~(1<

Setting bits:

TCCR1A |= (1<

ay, you're completely right. typical case of copy&paste error, i forgot to exchange the zeros by ones to reset the bits i wanted. seems it was a little bit too late last night :P

i also forgot to set pin 9 as output pin. new code:

void setup(){
  // set pin 9 as output
  // reset settings of Timer/Counter register 1
  TCCR1A &= ~((1<

now it's working. thanks :)