PIC32MZ tutorial -- Core Timer
Core Timer is a very popular feature of PIC32 since it isa piece of the MIPS M4K core itself and is common to all MIPS processors. Most RTOS's timer are based on core timer. This timer has a fixed prescaler 1:2, and it is a 32-bit timer, no need to combine with two 16-bit timer like we do with other timers (Timer2 and Timer3 or Timer4 and Timer5). At this moment I only use core timer to implement time delay. To accomplish it, I write two functions: ReadCoreTimer() and CoreT_DelayMs().
unsignedint__attribute__((nomips16))ReadCoreTimer(void){unsignedinttimer;//getthecountregasmvolatile("mfc0%0,$9":"=r"(timer));returntimer;}voidCoreT_DelayMs(unsignedintdelayMs){unsignedintdelayStart;delayStart=ReadCoreTimer();while((ReadCoreTimer()-delayStart)<(delayMs*CORE_TIMER_MILLISECONDS));}