How to tune period for MOSFET IRF3205 with gate driver optocoupler PC817?
If the top fet is turned on, then the source is at 20V but the gate is only at 12V - clearly this won't work. Turn off time will be slow as you are discharging the gate charge through a 2k resistor.
Use a half bridge mosfet driver like a IR2110 or easier still, use an integrated half bridge like a L298 (there are better choices, but this is what sprang to mind). No optocouplers needed.
I'd also suggest you use the pwm feature of the AVR timers