mitxela.com forum
Welcome. Please log in or register.

CTC mode on timer 1
DAVID Posted: 19 Jan 2019, 08:27 PM
Avatar
I love mcus

Member
Posts: 237
Joined: 10-September 17
hi, i have use timers on the atmega328p and they have work fine, but now what i need to do is to set timer1 to ctc mode and use both TIMER1_COMPA_vect and TIMER1_COMPB_vect and then control their overflow time with OCR1A and OCR1B. So what i did was:

void setup() {
TCCR1A=0;
TCCR1B=0;
TCCR1B|=_BV(CS12)|_BV(WGM12);
TIMSK1|=_BV(OCIE1A)|_BV(OCIE1B);
OCR1A=31000;
OCR1B=500;
pinMode(13,1);
// put your setup code here, to run once:

}
ISR(TIMER1_COMPA_vect){

}
ISR(TIMER1_COMPB_vect){
digitalWrite(13,!digitalRead(13));//blink the pin 13 led
}
void loop() {
// put your main code here, to run repeatedly:

}
}

and so pin 13 blinks but it is blinking at the frequency set by OCR1A and no OCR1B so it does not matter how big or small OCR1B is, TIMER1_COMPB_vect is completely depended on OCR1A.
Any suggestions?

-------------
[top]

Sign in to post a reply.