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.

[参考译文] TM4C123GH6PM:计时器0子计时器 B

Guru**** 2513185 points


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

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1331478/tm4c123gh6pm-timer-0-subtimer-b

器件型号:TM4C123GH6PM

您好!

我不熟悉 TMC4C123GH6PM 和使用 Launchpad。

我了解了 Timer0子计时器 A 用于生成所需频率和占空比的用法。

同样、我尝试使用 Timer0子计时器 B 进行频率生成、但即使花了几个小时也没能成功。

我请求就这个问题提供帮助。  

/* -----------------------          Include Files       --------------------- */
#include <stdint.h>                     // Library of Standard Integer Types
#include <stdbool.h>                    // Library of Standard Boolean Types
#include "inc/tm4c123gh6pm.h"           // Definitions for interrupt and register assignments on Tiva C
#include "inc/hw_memmap.h"              // Macros defining the memory map of the Tiva C Series device
#include "inc/hw_types.h"               // Defines common types and macros
#include "driverlib/sysctl.h"           // Defines and macros for System Control API of DriverLib
#include "driverlib/interrupt.h"        // Defines and macros for NVIC Controller API of DriverLib
#include "driverlib/gpio.h"             // Defines and macros for GPIO API of DriverLib
#include "driverlib/timer.h"            // Defines and macros for Timer API of driverLib

/* -----------------------      Global Variables        --------------------- */
uint32_t ui32Period;                    // Variable to store the period to be inputted to Timer0
uint32_t ui32IntFrequency = 0x00000009; // Variable to determine the Blinking Frequency of LEDs

/* -----------------------      Function Prototypes     --------------------- */
void Timer0AIntHandler(void);            // The prototype of the ISR for Timer0 Interrupt
void Timer0BIntHandler(void);            // The prototype of the ISR for Timer0 Interrupt


/* -----------------------          Main Program        --------------------- */
int main(void){
    // Set the System clock to 80MHz and enable the clock for peripheral Port F and Timer0
    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);



    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

    // Set the PF1, PF2, PF3 as output and configure Timer0 to run in periodic mode
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,  GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 );



    TimerConfigure(TIMER0_BASE, TIMER_CFG_A_PERIODIC);
    TimerConfigure(TIMER0_BASE, TIMER_CFG_B_PERIODIC);

    //TIMER0

    //TIMER0A
    // Calculate the Time period for 50% duty cycle while switching at "ui32IntFreqency" Hz.
    ui32Period = (SysCtlClockGet() / ui32IntFrequency) / 2;
    // Load the Timer with the calculated period.
    TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period - 1);

    //TIMER0B
    // Calculate the Time period for 50% duty cycle while switching at "ui32IntFreqency" Hz.
    ui32Period = (SysCtlClockGet() / ui32IntFrequency) / 2;
    // Load the Timer with the calculated period.
    TimerLoadSet(TIMER0_BASE, TIMER_B, ui32Period - 1);

    // Enable the Interrupt specific vector associated with Timer0A
    IntEnable(INT_TIMER0A);
    // Enables a specific event within the timer to generate an interrupt
    TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

    // Enable the Interrupt specific vector associated with Timer0A
    IntEnable(INT_TIMER0B);
    // Enables a specific event within the timer to generate an interrupt
    TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT);

    // FOR ALL TIMERS
    // Master interrupt enable API for all interrupts
    IntMasterEnable();
    // Enable the Timer
    TimerEnable(TIMER0_BASE, TIMER_A);
    TimerEnable(TIMER0_BASE, TIMER_B);

    while (1);
}

/* -----------------------      Function Definition     --------------------- */
void Timer0AIntHandler(void)
{   // The ISR for Timer0 Interrupt Handling
    // Clear the timer interrupt
    TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    // Read the current state of the GPIO pin and write back the opposite state
    if (GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1)){
        // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0);
        GPIOPinWrite(GPIO_PORTF_BASE,  GPIO_PIN_1,0);
    } else{
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_PIN_1);
    }
}


void Timer0BIntHandler(void)
{   // The ISR for Timer0 Interrupt Handling
    // Clear the timer interrupt
    TimerIntClear(TIMER0_BASE, TIMER_TIMB_TIMEOUT);
    // Read the current state of the GPIO pin and write back the opposite state
    if (GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2)){
        // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0);
        GPIOPinWrite(GPIO_PORTF_BASE,  GPIO_PIN_2,0);
    } else{
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
    }
}

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

    > TimerConfigure (TIMER0_BASE、TIMER_CFG_A_PERIOD);
    > TimerConfigure (TIMER0_BASE、TIMER_CFG_B_PERIOD);

    复位时、Timer0A 配置为32位定时器、但 Timer0B (有效)不存在。 要将计时器分为2个16位计时器、您需要类似

    TimerConfigure (TIMER0_BASE、TIMER_CFG_SPLIT_PAIR |TIMER_CFG_A_PERIOD |TIMER_CFG_B_PERIOD);

    ----------------

    这样做之后、您将注意到80M/9/2不能写入16位。 您需要应用预分频值(GPTMTxPR、8位宽)来获取范围内的加载值。 [请参阅数据表(SPMS376E)表11-5]。

    我在这里没有列出我的所有材料、但我希望 TivaWare 示例套件中有一个适用的示例。

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

    您好!  

    感谢您的快速响应。 我将尝试此操作并更新。

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

    您好!

    非常感谢。 它在工作。

    非常好的帮助。

    此致、

    拉维