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.

[参考译文] TM4C129ENCPDT:定时器处于捕捉模式

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

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1231330/tm4c129encpdt-timer-in-capture-mode

器件型号:TM4C129ENCPDT
主题中讨论的其他器件:EK-TM4C1294XL

您好!

我正在尝试在捕获模式下配置 timer4。我预期在上升沿或下降沿有中断。但无法获得中断、有人能帮我解决这个问题吗?  

SysCtlClockFreqSet ((SYSCTL_XTAL_25MHz | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480)、120000000);

//启用定时器4的外设和 GPIO 端口 M
SysCtlPeripheralEnable (SYSCTL_Periph_TIMER4);
SysCtlPeripheralEnable (SYSCTL_Periph_GPIOM);

//将 GPIO 端口 M 引脚4配置为计时器4A 捕捉输入
GPIOPinTypeTimer (GPIO_PORTM_BASE、GPIO_PIN_4);
GPIOPinConfigure (GPIO_PM4_T4CCP0);

//将计时器4A 配置为捕获计时器
TimerConfigure (TIMER4_BASE、TIMER_CFG_A_CAP_TIME_UP);

//设置计时器4A 的装载值
TimerLoadSet (TIMER4_BASE、TIMER_A、0xFFFF);

//在下降沿启用计时器4A 捕获事件
TimerControlEvent (TIMER4_BASE、TIMER_A、TIMER_EVENT_POS_EDGE);

//为定时器4A 捕获事件注册中断处理程序
TimerIntRegister (TIMER4_BASE、TIMER_CAPA_EVENT、Timer4ACaptureIntHandler);

//启用计时器4A 捕获事件中断
TimerIntEnable (TIMER4_BASE、TIMER_CAPA_EVENT);

//启用计时器4A
TimerEnable (TIMER4_BASE、TIMER_A);

//回调函数

空 Timer4ACaptureIntHandler (void)
{
//清除计时器4A 捕获事件中断
TimerIntClear (TIMER4_BASE、TIMER_CAPA_EVENT);
计数++;

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

    您好!

     首先、正如我在 时钟配置中看到的 SYSCTL_CFG_VCO_480、您似乎正在使用旧版本的 TivaWare。 请下载最新的 TivaWare 版本、因为其中包含使用 Timer0计算输入高相位的示例。 此示例可在 C:\ti\TivaWare_C_Series-2.2.0.295\examples\boards\ek-tm4c1294xl\timer_edge_capture 中找到。

    我想 我也看到了两个问题。 您正在尝试使用 Timer4模块的 TIMER_A。 但是您可以调用:

    TimerConfigure (TIMER4_BASE、TIMER_CFG_A_CAP_TIME_UP);

    而不是:

    TimerConfigure (TIMER4_BASE、TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP);

    其次、我没有看到您调用 IntEnable (INT_TIMER4A);

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

    尊敬的 Charles:

    感谢您的答复。我已尝试解决提到的问题、但仍未得到任何答复。 我也尝试了最新的库和它的示例,在相同的情况下仍然一样。在这个设置中,我配置了一个 pwm0和 timer0从示例,并为捕获引脚提供了 PWM 输出。 您能帮助我解决这个问题吗? 我的目标是从下降沿的捕获事件中获取计数。

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

    您好!

     请看一下这个例子。 它对我有用。 只是一个头儿,星期一是美国的公众假期,我的答复将会推迟。  

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/fpu.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/timer.h"
    #include "driverlib/gpio.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/rom.h"
    #include "driverlib/rom_map.h"
    #include "utils/ustdlib.h"
    #include "driverlib/uart.h"
    #include "utils/uartstdio.h"
    
    uint32_t g_ui32SysClock;
    
    uint32_t g_ui32IntCount = 0;
    
    uint32_t g_intFlag = 0;
    
    void
    InitConsole(void)
    {
    	// Enable GPIO port A which is used for UART0 pins.
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    
    	// Enable UART0 so that we can configure the clock.
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    
    
    	GPIOPinConfigure(GPIO_PA0_U0RX);
    	GPIOPinConfigure(GPIO_PA1_U0TX);
    
    	// Use the internal 16MHz oscillator as the UART clock source.
    	UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    
    
    	// Select the alternate (UART) function for these pins.
    	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
    	// Initialize the UART for console I/O.
    	UARTStdioConfig(0, 115200, 16000000);
    }
    
    // The interrupt handler for timer 4.
    
    void
    Timer4IntHandler(void)
    {
    	// Clear the timer interrupt.
    	TimerIntClear(TIMER4_BASE, TIMER_CAPA_MATCH);
    
    	g_ui32IntCount+=5;
    
    	g_intFlag = 1;
    
    	// The timer is automatically stopped when it reaches the match value so re-enable it here.
    	TimerEnable(TIMER4_BASE, TIMER_A);
    }
    
    
    int
    main(void)
    {
    
    
    	g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
    			SYSCTL_OSC_MAIN |
    			SYSCTL_USE_PLL |
    			SYSCTL_CFG_VCO_480), 120000000);
    
    	// UART Func Call
    	InitConsole();
    
    	UARTprintf("Timer Input Edge Example\n");
    
    	// Enable Timer4 & GPIOM
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4);
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM);
    
    	// Configure PM0 as the CCP0(Timer A) pin for timer 4.
    	GPIOPinTypeTimer(GPIO_PORTM_BASE, GPIO_PIN_4);
    	GPIOPinConfigure(GPIO_PM4_T4CCP0);
    
    	// Enable processor interrupts.
    	IntMasterEnable();
    
    	// Configure the timers in edge count mode.
    	TimerConfigure(TIMER4_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_COUNT_UP));
    	TimerControlEvent(TIMER4_BASE, TIMER_A, TIMER_EVENT_POS_EDGE);
    	TimerLoadSet(TIMER4_BASE, TIMER_A,6);
    
    	// Set match to 15 so that after 5 postive edges detected, generate a match interrupt
    	TimerMatchSet(TIMER4_BASE, TIMER_A,5);
    
    	// Setup the interrupt for the edge capture timer.  Note that we
    	// use the capture match interrupt and NOT the timeout interrupt!
    	IntEnable(INT_TIMER4A);
    	TimerIntEnable(TIMER4_BASE, TIMER_CAPA_MATCH);
    
    	// Timer Moudle(Timer A & Timer B) Clock Source Set
    	TimerClockSourceSet(TIMER4_BASE, TIMER_CLOCK_SYSTEM);  // TIMER_CLOCK_PIOSC or  TIMER_CLOCK_SYSTEM
    
    	// Enable the timer.
    	TimerEnable(TIMER4_BASE, TIMER_A);
    
    	// At this point, the timer will count up every time a negative  edge is detected on the relevant pin .
    	while (1)
    	{
    		if (g_intFlag == 1) {
    			UARTprintf("%d Positive edges detected\n", g_ui32IntCount);
    			g_intFlag =0;
    		}
    
    	}
    }

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

    尊敬的 Charles:

    感谢您的答复。请让我检查一下您分享的代码、并告知您。 如果我需要修改代码,我需要  把它转换成一个计数器,当一个事件发生时,它可以计数,比如说下降沿可能检测到,我需要得到计数。