MacIntoshCZ
Active Member
Hello there,
i would like use timer 2 on avr, but i probably made somewhere a mistake or avr is faulty becouse i am getting square wave about 95%duty cycle.
I already succesfully used timer 0.
I should get 100Khz square wave, 50% duty cycle, on pin 11. Thanks for help
Here is code:
void setup() {
TCCR2A = 0;
TCCR2B = 0;
TCNT2 = 0;
TCCR2A |= (1 << WGM20) | (1 << WGM21);
TCCR2B |= (1 << WGM22);
TIMSK2 |= 1;
TCCR2A |= (1 << COM2A1);
TCCR2A |= (1 << COM2B1);
OCR2A |= 160;
OCR2B |= 80;
pinMode(3, OUTPUT);
pinMode(11, OUTPUT);
TCCR2B |= (1 << CS20);
interrupts();
}
void loop() {
}
i would like use timer 2 on avr, but i probably made somewhere a mistake or avr is faulty becouse i am getting square wave about 95%duty cycle.
I already succesfully used timer 0.
I should get 100Khz square wave, 50% duty cycle, on pin 11. Thanks for help
Here is code:
void setup() {
TCCR2A = 0;
TCCR2B = 0;
TCNT2 = 0;
TCCR2A |= (1 << WGM20) | (1 << WGM21);
TCCR2B |= (1 << WGM22);
TIMSK2 |= 1;
TCCR2A |= (1 << COM2A1);
TCCR2A |= (1 << COM2B1);
OCR2A |= 160;
OCR2B |= 80;
pinMode(3, OUTPUT);
pinMode(11, OUTPUT);
TCCR2B |= (1 << CS20);
interrupts();
}
void loop() {
}