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:如何创建周期计时器

Guru**** 2384830 points
Other Parts Discussed in Thread: SYSCONFIG
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1356172/mspm0l1105-how-to-create-a-peroidic-timer

器件型号:MSPM0L1105
主题中讨论的其他器件: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;
}
}

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Jonas:

    如果您将 CCS 与 SysConfig 一起使用、则设置起来很简单。  以下代码示例将超时设置为1秒:

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

    这有助于回答您的问题吗?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Dennis、

    您可以查看我们的代码源吗?  

    e2e.ti.com/.../7120.mspm0l1105_5F00_fw_5F00_ccs.zip

    我将 CCS 与 SysConfig 一起使用、并将计时器导入文件设置为"周期为500ms、零事件为周期性"。

    这是否意味着我们的 TIMER_0_INST_IRQHandler 将在我的代码中每500ms 进入一次、但从我们的测试来看、它不会这样。

    请告诉我如何修改我们的代码。

    感谢您的帮助!

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Jonas:

    是的、计时器将每500ms 中断一次。 我不确定您为什么要停止和启动计时器。  它被配置为"周期性"、因此您无需管理计时器。  如果您尝试生成1秒的周期性计时器、请在 SysConfig 中将配置文件更改为自定义、并选择1秒的计时器周期。