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<<COM1A1) | (1<<COM1A0) | (1<<WGM11) | (1<<WGM10));
TCCR1B &= ~((0<<WGM13) | (1<<WGM12) | (1<<CS12) | (0<<CS11) | (1<<CS10));
// set compare match output A to toogle
TCCR1A |= (0<<COM1A1) | (1<<COM1A0);
// set waveform generation mode to CTC
TCCR1A |= (0<<WGM11) | (0<<WGM10);
TCCR1B |= (0<<WGM13) | (1<<WGM12);
// set clock select to clock/1024 (from prescaler)
TCCR1B |= (1<<CS12) | (0<<CS11) | (1<<CS10);
// set output compare register A to 15624
OCR1A = 15624;
}
void loop(){
}
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