#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
uint16_t	x;

//------------------------------------------------------------------------------
ISR (TIMER0_OVF_vect)				//Obsluha prerusenia TCO - 8,16ms
{
	PORTD ^= (1<<PORTD7);			//test osciloskop
	if (x == 10) {
		x = 0;
		if(OCR0A == 0xFF) OCR0A = 0; 
		else OCR0A++;
	}
	else x++;
}
//------------------------------------------------------------------------------
int main (void) {
	
	wdt_enable(WDTO_500MS);		//povolenie WDT 0,5sec
	DDRD |= (1<<DDD6); 			//Enable OC0A (PD6) Output
	DDRD |= (1<<DDD7);			//nastavenie vystup pre osciloskop
	 
	//TC0 - PWM Phase Correct mode
	TCCR0B |= (1<<CS02); 		//Set prescaler 256 (8,16ms)
	TCCR0A |= (1<<WGM00); 		//Set Phase Correct PWM mode
	TIFR0 |= 1<<TOV0;			//Clear TOV0 flag
//	TIMSK0 |= 1<<TOIE0;			//Enable Timer0 overflow interrupt
//	TCCR0A |= (1<<COM0A1); 		//Clear OC0A on Compare Match when up-counting.
								//Set OC0A on Compare Match when down-counting.
	TCCR0A |= (1<<COM0A1)|(1<<COM0A0);	//Set OC0A on Compare Match when up-counting.
										//Clear OC0A on Compare Match when down-counting.
	OCR0A = 100;	 			//Set (255-100)*2=310*0,016us=4,96ms

	sei();
	while(1) { 
		wdt_reset();
	}
}
//------------------------------------------------------------------------------

