Other Parts Discussed in Thread: SYSCONFIG
Dear Ti team,
Please tell me how to create a 1 second periodic timer.
From example, timx_timer_mode_periodic_standby, Does "DL_Timer_setLoadValue(TIMER_0_INST, count); DL_TimerG_startCounter(TIMER_0_INST);" would create a 500ms periodic timer? What I test looks not like that.
(In my code, I decrease a variable (value = 5*60*2 = 5min) everytime when this timer comes in, but when I run my program the variable becomes to zero very quickly, looks like the timer is very quick, not 500ms per round)
Please help me to clairy this issue.
Thanks!
/* ((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;
}
}