主题中讨论的其他器件:SysConfig
尊敬的 TI 团队:
请告诉我如何创建1秒的周期性计时器。
在 timx_timer_mode_periodic_standby 中、"DL_Timer_setLoadValue (timer_0_inst、count);DL_TimerG_startCounter (timer_0_inst);"会创建500ms 的周期计时器吗? 我测试的内容看起来不是这样的。
(在我的代码中,每次计时器进入时,我都会减小一个变量(值=5*60*2=5min),但当我运行程序时,变量很快变为零,看起来计时器非常快,而不是每轮500ms)
请帮我解决这个问题。
谢谢!
/* ((32KHz / (32+1)) * 0.5s) = 45 - 1 = 495 due to N+1 ticks */ #define TIMER_500_MILLISECONDS_TICKS (495) /* ((32KHz / (32+1)) * 0.05s) = 50 - 1 = 49 due to N+1 ticks */ #define TIMER_50_MILLISECONDS_TICKS (49) void TIMER_0_INST_IRQHandler(void) { static uint32_t count = TIMER_500_MILLISECONDS_TICKS; switch (DL_TimerG_getPendingInterrupt(TIMER_0_INST)) { case DL_TIMER_IIDX_ZERO: /* * Counter stopped to avoid a conflict with the timer reading * the LOAD value while it's being set */ DL_TimerG_stopCounter(TIMER_0_INST); /* * Count progressively gets smaller in 0.05 s increments until * reset with 0.5s */ if (count > (TIMER_500_MILLISECONDS_TICKS / 5)) { count = count - TIMER_50_MILLISECONDS_TICKS; } else { count = TIMER_500_MILLISECONDS_TICKS; } DL_Timer_setLoadValue(TIMER_0_INST, count); /* * By default, this should load the new count value and count down * from there (CVAE = 0) */ DL_TimerG_startCounter(TIMER_0_INST); DL_GPIO_togglePins(GPIO_LEDS_PORT, (GPIO_LEDS_USER_LED_1_PIN | GPIO_LEDS_USER_TEST_PIN)); break; default: break; } }