0
votes
#define F_CPU 8000000UL
#include <avr/io.h>

/*
 * main -- Main program
 */
int main(void)
{
    /* Set OC1A pin to be an output */
    DDRD|=(1<<5);

    /* Set output compare register value */
    OCR1A = 4000;


    /* Set timer counter control registers A and B so that
     *  - mode is - clear counter on compare match
     *  - output compare match action is to toggle pin OC1A
     *  - correct clock prescale value is chosen.
     * TCCR1C can just stay as default value (0).
     */

    TCCR1A |=(1<<COM0A0) | (1<<WGM12);
    TCCR1B |= (0<<CS12) | (1<<CS11) | (1<<CS10) | (1<<WGM12) | (1<<WGM12);

    while(1){

    }
}

I have a led linked to the OC1A port, yet it never flashes, some help would be much appreciated.

I have scoured the data sheet and do not comprehend what else must be done in order to make the led flash, i am sure it would be simple for someone with any c knowledge.

1
You have absolutely no logic that I can see to actually make the LED flash (turning it on and off, etc). Start with just getting the LED lit up before playing with the timers.rost0031
@rost0031 He's trying to make the LED blink using hardware timers.user149341
Ok, I see that now. OP, are you sure the LED is not flashing so fast that you can't see it? Try turning off the timer and see if the LED is lit up by manually toggling the output.rost0031

1 Answers

0
votes

First of all, when setting registers like TCCR1A you need to simply assign the value you want to put into it, not OR the bits you want to set with what is already in there as you'll get an unwanted mix of old & new.

Then try changing this:

TCCR1A = (1 << COM1A0);    //COM1A0 in stead of COM0A0, and WGM12 is not part of TCCR1A
TCCR1B = (1 << CS11) | (1 << CS10) | (1 << WGM12);    //No need to write (0 << x) for bits you don't want set, WGM12 is part of TCCR1B

If the led is flashing too fast, increase OCR1A and/or change the prescaler (cs 10, 11 and 12)