Need help trying to design an H-Bridge to power electromagnet
The charge-discharge voltage of the gate, is between the gate-source of the MOSFET.

You need to drive the gate of the P-MOSFET to the source voltage that, in your case is 18V to turn it off.

As you say, you are getting near 5V at the gate, so the P-MOSFETS are always conducting, and the N-MOSFETS are switching.

You are basically shorting the bridge at the PWM frequency and duty-cycle.
To confirm, measure the current consumption, even with a low output current it should be high.

Also


ATMega outputs are not meant to be used at these potential (voltage).
You don't include a resistor between the output of the ATMega and the gate, it is probably driving more current than it should.
The resistors on the leg form a voltage divider. Without drive signal, the voltage will be near \$vcc/2\$, the two transistors in one leg will conduce.


This is just a sketch

 

With this circuit the P-MOSFET gate-source will be 0V (thought pull-up resistor) and it will be non-conducting. When the NPN transistor is conducting it will pull the P-MOSFET gate-source to a low voltage (you can change the pull-down resistor to adjust this voltage).