3.4.7 How Can I Implement a Delay in My Code?
If an accurate delay is required, or if there are other tasks that can be performed during the delay, then using a timer to generate an interrupt is the best way to proceed.
Microchip does not recommend using a software delay on PIC32/SAM devices as there are many variables that can affect timing such as the configuration of the L1 cache, prefetch cache, & Flash wait states. On these devices, you may choose to use a hardware timer for timing purposes.