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));
}

 

相关文章:

  • 2021-05-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2021-05-16
  • 2021-12-06
  • 2021-09-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-14
相关资源
相似解决方案