How to create a 38 Khz pulse with arduino using timer or PWM?

I don't have any experience with the Mega, but it looks like it has quite a few timers knocking about. It seems like it should be possible to take one of the unused timers and Have it toggle one of the OCxn pins.

Take a look at the timer section in the data sheet, and also have a look here AVR Timers – CTC Mode | maxEmbedded for more information on having a timer toggle a pin in the background purely through hardware.

Just make sure you don't tread on anything else that is using a particular timer, or there might be issues.