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.

改写定时器计数值问题



请教一下:设置了定时器中断,但想中断程序之外,即另一个子程序中改写定时器的计数值(非初始值,是当前值),从而使定时器从新的计数值往下递减,该怎样实现?

  • 1.另一个子程序最好还是放在中断中判断

    2.如果非要写的话,在修改定时器计数值的时候停止定时器中断,修改后恢复中断。

  • 谢谢您的回答,很有参考价值。请问改写计数器的值是用这个语句:HWREG(TIMER0_BASE + TIMER_O_TAV) = ****吗?

  • 这样也可以。这是直接操作底层的地址了,建议你用库函数试试,这么搞,容易搞乱。

  • 你好,

    关于如何改写定时器的计算timer你可以参考API驱动库,不要直接操作底层计算器。

    API文档见SDK目录下C:\ti\TivaWare_C_Series-2.1.0.12573\docs

    SW-TM4C-DRL-UG-2.1.0.12573.pdf

    第550页:

    TimerLoadSet
    Sets the timer load value.
    Prototype:
    void
    TimerLoadSet(uint32_t ui32Base,
    uint32_t ui32Timer,
    uint32_t ui32Value)
    February 07, 2014 549
    Timer
    Parameters:
    ui32Base is the base address of the timer module.
    ui32Timer specifies the timer(s) to adjust; must be one of TIMER_A, TIMER_B, or
    TIMER_BOTH. Only TIMER_A should be used when the timer is configured for full-width
    operation.
    ui32Value is the load value.
    Description:
    This function configures the timer load value; if the timer is running then the value is immediately
    loaded into the timer.
    Note:
    This function can be used for both full- and half-width modes of 16/32-bit timers and for halfwidth
    modes of 32/64-bit timers. Use TimerLoadSet64() for full-width modes of 32/64-bit timers.
    Returns:
    None.