i have to start with a 10% duty cycle and i have to increase it by 10% after 4 seconds, when it reaches 90% duty it has to go to 10% again. (period 100 hz 10 ms) i´m testing it in tinkercad and it doesn´t work, it oscilates between 10% and 20%. in this code i dont ask when it reaches 90% duty because it doesn´t reach 90% duty.
Can you add some comments to the timer initialization at the right place?
There remain undefined bits in the control registers which you never set nor clear.
Setting OCR1A (TOP) is not required in the ISR, may cause strange effects.
OCR1B increments beyond 2500 so that no more match is detected until it wraps around to 0.
This should toggle PB2 once with each change of the duty cycle, but it may do nothing if the waveform generator is activated for PWM. For testing purposes I'd use a different pin, not affected by the timer.
Now that you mention this: what are all the register bit names mentioned in the data sheet - bit numbers (for sbi/cbi?) or masks for integer and/or? Where is that convention documented?
Updating TCNT1 in the ISR is not required, perhaps calling for trouble. See the data sheet what the FastPWM mode does in hardware with the timer registers and output pins.
I think you need to set TCNT1 after setting OCR1A in setup(), since that is the value of TOP, not when OCR1B changes as that's not TOP. If TCNT1 happened to be >= 2500 when setup() runs, TCNT1 will be spending a while incrementing all the way round to 0xFFFF and wrapping back to 0.
BTW when setting timer registers don't just tweak some individual bits, set all the register bits to definite values - otherwise you are risking mixing your new configuration with existing configuration, which could lead to obscure failures in some circumstances you haven't seen yet.