AVR Timer: CTC mode

Discussions on the software and hardware for Atmel's STK standard.

Moderator: phalanx

Post Reply
Athul
Posts: 13
Joined: Thu Apr 07, 2016 1:00 am

AVR Timer: CTC mode

Post by Athul » Sat Nov 24, 2018 9:20 am

I learing AVR programming,

I have made a code to toggle AVR pin at an interval using interrupts

Here' the code

Code: Select all

#include <avr/io.h>
#include <avr/interrupt.h>

// initialize timer, interrupt and variable
void timer1_init()
{
    // set up timer with prescaler = 64 and CTC mode
    TCCR1B |= (1 << WGM12)|(1 << CS11)|(1 << CS10);

    TIMSK1 |= (1 << OCIE1B);        // Output Compare B Match Interrupt Enable
    // initialize counter
    TCNT1 = 0;

    // initialize compare value
    OCR1B = 7812;
    sei();
}


ISR(TIMER1_COMPB_vect) { 
    PORTC ^= (1 << 0);
}

int main(void)
{
    // connect led to pin PC0
    DDRC = 0XFF;

    // initialize timer
    timer1_init();

    // loop forever
    while(1)
    {

    }
}
But pin is not toggling? Why?

Post Reply