S32K148-lptmr配置

S32K148自带的定时器,配置非常简单,有时候我会用它做任务周期,配置一个1ms定时器中断一次

 

 初始化函数:

void LPTMR_init(void)
{
    LPTMR_DRV_Init(INST_LPTMR1, &lpTmr1_config0, 0);
    LPTMR_DRV_StartCounter(INST_LPTMR1);

    INT_SYS_InstallHandler(LPTMR0_IRQn, &Lptmr_ms_ISR, 0);
    INT_SYS_EnableIRQ(LPTMR0_IRQn);
}

还有一个中断函数:

void Lptmr_ms_ISR(void) //1ms一次中断计数
    {     
          task_1ms();
          counter_5ms++;
          counter_10ms++;
          counter_100ms++;
          counter_250ms++;
          counter_500ms++;
          counter_1000ms++;
   
           LPTMR_DRV_ClearCompareFlag(INST_LPTMR1);
    }

不知道这种方法作为任务周期有没有不合理的地方,希望大佬们提出。

posted @ 2022-09-23 10:47  涛哥nihao  阅读(403)  评论(0)    收藏  举报