Sorry, just to be clear I was talking to the OP. I think you suggested only setting the direction during the initialization.
Yes, but there are a few problems in programm structure too.
I've simulated it with AVR Studio 7.
In fast PWM mode the OC1A Pin is high for one clock cycle, while OCR1A is set to 0.
That's the cause why I would not use fast pwm in a solution when possible.
If that peak is a Problem you have to switch off the pin, when set OCR1A to 0.
When the Controller runs with 8MHz clock, the PWM has a frequency of 250 000kHz.
Only to reduce flicker, that makes no sense.
Additional You have only 32 dimm steps with a 16Bit Counter.
In this solution the LED only should to be dimmed up and down.
Possibly it's no problem if the LED is'n completly off.
My suggestion is to count a variable up and down and write it into OCR1A.
So the Timer 1 wouldn't be disturbed while his operation.
e.g.
uint8_t i;
...
...
for(i=0,i<32,i++) //dimms up in 32 second's
{
OCR1A=i;
_delay_ms(1000);
}
for(i=31,i<32,i--) //dimms down until i is overflown =255
{
OCR1A=i;
_delay_ms(1000);
}
So You never have to change timer parameters in main loop.
The proper way should be to implement the dimming routine into a timer interrupt, because the controller wasn't blocked only for waiting.
But that's dependent of the application the OP want to create.