Generating 40kHz square wave

PWM uses a timer that if you change PWM speed will affect some other operations.
OTOH if you use a timer to drive a very short interrupt, the effect will be less to none.
Worst case, your square wave edge will be off a few usecs but that is the case with PWM.
Best case, you make it work both ways just to see which is more accurate.