PIC32MZ tutorial -- Core Timer

  Core Timer is a very popular feature of PIC32 since it is a 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().

  

unsigned int __attribute__((nomips16)) ReadCoreTimer(void)
{
unsigned int timer; // get the count reg
asm volatile("mfc0 %0, $9" : "=r"(timer)); return timer;
} void CoreT_DelayMs(unsigned int delayMs)
{
unsigned int delayStart; delayStart = ReadCoreTimer(); while ((ReadCoreTimer() - delayStart) < (delayMs * CORE_TIMER_MILLISECONDS));
}
上一篇:循序渐进学.Net Core Web Api开发系列【9】:常用的数据库操作


下一篇:循序渐进学.Net Core Web Api开发系列【8】:访问数据库(基本功能)