I am using this circuit to control a 24V fan at a frequency of 31kHz (MCU - 72 MHz, Prescaler - 9, Counter period - 255):

The scheme works. But I want to add an optocoupler to the circuit, I did it like this:

It's work to. But the fan speed is maximum when duty cycle more than 30%. If I set duty cycle less than 30%, the fan speed decreases. I tried lowering the frequency to 15kHz, 4kHz, 1kHz but it's not help. Perhaps I made the diagram incorrectly?

