Hello I have some problems to understand how to bind a Timer to a Pin and because of that my code isn't running…
#include <avr/io.h>
void init_PWM(void)
{
TCCR0A|=(1<<WGM00)|(1<<WGM01)|(1<<COM0A1)|(1<<CS00);
//Set OC0 PIN as output. It is PB3 on ATmega16 ATmega32
DDRB|=(1<<PB7);
}
void setPWM(uint8_t duty)
{
OCR0A = duty;
}
void main (void)
{
uint8_t brightness = 0;
init_PWM();
for (brightness=0; brightness<=255; brightness++)
{
setPWM(brightness);
_delay_ms(100);
}
}
My problem is how to assign the timer to PB7?
My goal is blinking LED on PB7 with FastPWM Mode.
Best Answer
Ok I can see a few problems with this code (Im assuming this is your datasheet):
Refer to this example, its for the Atmega128 and uses a 16 bit timer. The frequency is 120Hz and my CPU clock speed is 16MHz. Therefore by using the formula I ended up with a TOP (16665) and my prescaler was 8 I believe.