This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSPM0L1105: How to create a peroidic timer

Part Number: MSPM0L1105
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;
}
}

  • Hi Jonas,

    If you are using CCS with Sysconfig this is simple to setup.  This code example sets the timeout to 1 sec:

    /*
     * Timer clock configuration to be sourced by LFCLK /  (4096 Hz)
     * timerClkFreq = (timerClkSrc / (timerClkDivRatio * (timerClkPrescale + 1)))
     *   4096 Hz = 4096 Hz / (8 * (0 + 1))
     */
    static const DL_TimerG_ClockConfig gTIMER_0ClockConfig = {
        .clockSel    = DL_TIMER_CLOCK_LFCLK,
        .divideRatio = DL_TIMER_CLOCK_DIVIDE_8,
        .prescale    = 0U,
    };
    
    /*
     * Timer load value (where the counter starts from) is calculated as (timerPeriod * timerClockFreq) - 1
     * TIMER_0_INST_LOAD_VALUE = (1s * 4096 Hz) - 1
     */
    static const DL_TimerG_TimerConfig gTIMER_0TimerConfig = {
        .period     = TIMER_0_INST_LOAD_VALUE,
        .timerMode  = DL_TIMER_TIMER_MODE_PERIODIC,
        .startTimer = DL_TIMER_STOP,
    };
    
    SYSCONFIG_WEAK void SYSCFG_DL_TIMER_0_init(void) {
    
        DL_TimerG_setClockConfig(TIMER_0_INST,
            (DL_TimerG_ClockConfig *) &gTIMER_0ClockConfig);
    
        DL_TimerG_initTimerMode(TIMER_0_INST,
            (DL_TimerG_TimerConfig *) &gTIMER_0TimerConfig);
        DL_TimerG_enableInterrupt(TIMER_0_INST , DL_TIMERG_INTERRUPT_ZERO_EVENT);
        DL_TimerG_enableClock(TIMER_0_INST);
    }

    Does this help answer your question?

  • Hi Dennis,

    Could you check our code source? 

    7120.mspm0l1105_fw_ccs.zip

    I am using CCS with Sysconfig and set TImer porfiles as "Periodic with 500ms Period and Zero Event".

    Does it mean our TIMER_0_INST_IRQHandler will enter every 500ms in my code, but from our test it doent' look like that.

    Please tell me how to modify our code.

    Thanks for your help!

  • Hi Jonas,

    Yes, the timer will interrupt every 500ms. I'm not sure why you are stopping and starting the timer.  It is configured as "periodic" so you don't need to manage the timer.  If you are trying to generate a 1 second periodic timer, in sysconfig, change the profile to custom and select a timer period of 1 sec.