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.

LM4F120 Configuring capture with interruption



Hello!

I'm trying to configure  Timer 2 A and pin PF4 (T2CCP0)  to work in capture mode. All i have to do is to capture 110 Hz frequency! The problem: When it runs the cmd TimerConfigure(TIMER2_BASE,TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_CAP_TIME); my stellaris get stuck in a interrupt routine called FaultISR.

Thx!

Here goes my codes

tBoolean Configura_Captura(void)
{
// T2CCP0 -> PF4 -> Timer 2 A
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeTimer(GPIO_PORTF_BASE, GPIO_PIN_4);
GPIOPinConfigure(GPIO_PF4_T2CCP0);
GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4,GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

TimerConfigure(TIMER2_BASE,TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_CAP_TIME);
TimerControlEvent(TIMER2_BASE,TIMER_A,TIMER_EVENT_POS_EDGE); //setup capture
TimerLoadSet(TIMER2_BASE,TIMER_A,0x0);

TimerIntEnable(TIMER2_BASE,TIMER_CAPA_EVENT);
TimerEnable(TIMER2_BASE,TIMER_A);

IntMasterEnable();
IntEnable(INT_TIMER2A);

return true;
}

 Interruption routine


unsigned long static atual, anterior, periodo = 0;

void Timer2AIntHandler(void)
{
TimerIntClear(TIMER2_BASE,TIMER_CAPA_EVENT); //reset capture A interrupt flag
atual = TimerValueGet(TIMER2_BASE,TIMER_A); //read the capture value
periodo = atual - anterior;
anterior = atual;
}

my inclues.h file

#ifndef _INCLUDES_H_

#define _INCLUDES_H_

#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "inc/hw_ints.h"

#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/pin_map.h"
#include "driverlib/interrupt.h"
#include "driverlib/uart.h"


#endif

my main function

int
main(void)
{

// 40 MHz system clock
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
Configura_PWM(1000,500); // Configures my PWM
Configura_Captura();

IntMasterEnable();

Toca_PWM(1000); // while(1) inside here
}

  • Hi!

    Just changed my codes. I had forgotten to enable timer 2.

    The problem now is that i got stuck in the IntDefaultHandler(void) routine when running IntEnable(INT_TIMER2A);

    void Configura_timer(void)

    {

    // T2CCP0 -> PF4 -> Timer 2 A
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeTimer(GPIO_PORTF_BASE, GPIO_PIN_4);
    GPIOPinConfigure(GPIO_PF4_T2CCP0);
    GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4,GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

    IntMasterEnable();

    // Porta PF4 como CCP0
    TimerConfigure(TIMER2_BASE,TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_CAP_TIME);
    TimerControlEvent(TIMER2_BASE,TIMER_A,TIMER_EVENT_POS_EDGE); //setup capture
    TimerLoadSet(TIMER2_BASE,TIMER_A,0x0);

    IntEnable(INT_TIMER2A);
    TimerIntEnable(TIMER2_BASE, TIMER_CAPA_EVENT);

    TimerEnable(TIMER2_BASE, TIMER_A);

    return true;

    }

  • Hi,

    You need to add your timer interrupt handler to the vector table in your startup file:

    ...

    //*****************************************************************************
    //
    // External declarations for the interrupt handlers used by the application.
    //
    //*****************************************************************************
    extern void Timer2AIntHandler(void);
    ...

    ...

    IntDefaultHandler,      // Timer 0 subtimer A
    IntDefaultHandler,      // Timer 0 subtimer B
    IntDefaultHandler,      // Timer 1 subtimer A
    IntDefaultHandler,      // Timer 1 subtimer B
    Timer2AIntHandler,      // Timer 2 subtimer A
    IntDefaultHandler,      // Timer 2 subtimer B
    IntDefaultHandler,      // Analog Comparator 0
    IntDefaultHandler,      // Analog Comparator 1
    ... 

    -David

  • David,

    Thank you so much for your answer. I just got it working. It was exactly what you just adviced me to do :)

    Frequencies are being mesured correctly now.

    Just a final doubt:

    I need to measure 110 Hz and a split pair is not good for it (count overflows).

    In order to make the same configuration for a 32 bit length timer, should i only change those following params? Or there's anything else i should do? Thx.

    // Porta PF4 como CCP0
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
    TimerConfigure(TIMER2_BASE, TIMER_CFG_B_CAP_TIME);
    TimerControlEvent(TIMER2_BASE,TIMER_B,TIMER_EVENT_POS_EDGE); //setup capture
    TimerLoadSet(TIMER2_BASE,TIMER_B,0xffffffff);

    IntMasterEnable();

    TimerIntEnable(TIMER2_BASE, TIMER_CAPB_EVENT);
    TimerEnable(TIMER2_BASE, TIMER_B);
    IntEnable(INT_WTIMER2B);
     

    interrupt being activated as follows:

    Timer2IntHandler,                      // Wide Timer 2 subtimer B

    Thx.

    Fávero Santos - UTFPR