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.

Problem into the interrupt while using time capture



I am using lm4f120. I set the timer0 to capture a input signal. I set a load value and match value, but it can not get into the interrupt even when I enabled the timer int and int master...

the code is below:

	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	//Config the timer
	TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_COUNT);
	//Config B6 as T0CCP0
	GPIOPinConfigure(GPIO_PB6_T0CCP0);
	GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_6);
	//Event ctl
	TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_NEG_EDGE);
	//Load set
	TimerLoadSet(TIMER0_BASE, TIMER_A, 99);
	TimerMatchSet(TIMER0_BASE, TIMER_A, 50);


	//Timer int enable
	TimerIntRegister(TIMER0_BASE, TIMER_A, left);
	TimerIntEnable(TIMER0_BASE, TIMER_CAPA_MATCH);
	IntEnable(INT_TIMER0A);
	IntMasterEnable();
	//TimerIntRegister(TIMER1_BASE, TIMER_B, LightLed);
	//Timer enable
	TimerEnable(TIMER0_BASE, TIMER_A);

left is the int function i wrote.

  • Hello Wen,

    What is the System Clock configured as for the TM4C123 and what is the input toggle rate?

    Regards

    Amit

  • SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_OSC | SYSCTL_XTAL_16MHZ |
    		SYSCTL_OSC_MAIN);

    3.2MHz, and the input frequency is much lower, <1kHz

  • I tried to get the timer's value, which decreased from the load value to the "match value+1" or "match value +2", which is very strange.

  • Hello Jeff,

    The value of the timer will decrease as it is in down count mode. I will need to run the code on my side to see why it is not generating an interrupt.

    Can you share the interrupt routine as well.

    Regards

    Amit

  • It's nice of you!

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/gpio.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/pin_map.h"
    #include "utils/uartstdio.h"
    #include "driverlib/pwm.h"
    #include "driverlib/timer.h"
    #include "inc/hw_ints.h"
    #include "driverlib/interrupt.h"
    
    void LightLed(void);
    void left(void)
    {
    	TimerIntClear(TIMER1_BASE, TIMER_CAPA_MATCH);//clear the interrupt
    	UARTprintf("\nhello world!\n");
    }
    
    //*****************************************************************************
    //To init the motor's pins, start to output after the func been called 
    //!!!must called after the ServoInit
    //*****************************************************************************
    void ACMotorInit(void)
    {
    	
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    	//Config the timer
    	TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_COUNT);
    	//Config B6 as T0CCP0
    	GPIOPinConfigure(GPIO_PB6_T0CCP0);
    	GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_6);
    	//Event ctl
    	TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_NEG_EDGE);
    	//Load set
    	TimerLoadSet(TIMER0_BASE, TIMER_A, 99);
    	TimerMatchSet(TIMER0_BASE, TIMER_A, 50);
    
    
    	//Timer int enable
    	TimerIntRegister(TIMER0_BASE, TIMER_A, left);
    	TimerIntEnable(TIMER0_BASE, TIMER_CAPA_MATCH);
    	IntEnable(INT_TIMER0A);
    	IntMasterEnable();
    	//TimerIntRegister(TIMER1_BASE, TIMER_B, LightLed);
    	//Timer enable
    	TimerEnable(TIMER0_BASE, TIMER_A);
    }
    

    It's quiet simple. thanks

  • Hello Wen

    The issue in the Interrupt Handler

    TimerIntClear(TIMER1_BASE, TIMER_CAPA_MATCH)

    is clearing into TIMER1 while the TIMER0 is being used... After correcting the base address the Interrupt is working fine.

    Regards

    Amit

  • You're unbelievable!!!