I am a beginner at AVR and programming. I am using ATtiny461 and asked to make code to use timer in PWM and CTC mode and use interrupts and pin toggle, this code worked for me with normal timer and toggle but I don't know how to make it work with CTC and PWM:
#include <avr/io.h>
#include <avr/interrupt.h>
//Init PD6 pin as output
void InitPort(void)
{
PORTB&=~(1<<PB1);//initial value 0
DDRB|=(1<<PB1);
}
//Initialize Timer0
void InitTimer0(void)
{
//Enable Timer0 overflow Interrupt
TIMSK|=(1<<TOIE0);
//Set Initial Timer value
TCNT1=5;
}
void StartTimer0(void)
{
//Set prescaller 64 and start timer
TCCR0B|=(1<<CS01)|(1<<CS00);
//Enable global interrupts
sei();
}
//Timer0 Overflow ISR
ISR(TIMER0_OVF_vect)
{
//Reset Initial Timer value
TCNT1=5;
//toggle PD6 pin
PINB=(1<<PB1);
}
int main(void)
{
InitPort();
InitTimer0();
StartTimer0();
while(1)
{
//doing nothing
}
}
and I know those commands for setting fast PWM and CTC:
TCCR1D |= (0<<WGM10)|(0<<WGM11);
TCCR1A |= (1<<PWM1A)|(1<<COM1A0)|(0<<COM1A1);