According to the Datasheet (always READ the Datasheet) Table 22-4 External Clock Timing Requirements, on Page 268 of DS39564A the maximum xtal speed in HS mode is 25MHz.
If you need to run at 40MHz, either (a) fit a 10MHz xtal and run 4xPLL (datasheet section 2.5), or (b) input 40MHz from a external oscillator with the PIC in EC or ECIO mode (Datasheet section 2.4).
Bookmarks