QTIMER Configuration to capture

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

QTIMER Configuration to capture

281 Views
vivekgourav
Contributor I
I am having problems with capturing input from one of the GPIO pins which has a timer connected to it.

#include
"fsl_iomuxc.h"
#include "clock_config.h"
#include "board.h"
#include "fsl_qtmr.h"
#include "pin_mux.h"

#define BOARD_QTMR_BASEADDR              TMR3
#define BOARD_QTMR_INPUT_CAPTURE_CHANNEL kQTMR_Channel_1

/* IOMUXC configuration for Quad Timer input pin */
#define IOMUXC_QTIMER_INPUT_PIN_CONFIG_MUX       0x401F814CU
#define IOMUXC_QTIMER_INPUT_PIN_CONFIG_MODE      0x1U
#define IOMUXC_QTIMER_INPUT_PIN_CONFIG_INPUT_REG 0x401F8570U
#define IOMUXC_QTIMER_INPUT_PIN_CONFIG_INPUT_DSY 0x1U
#define IOMUXC_QTIMER_INPUT_PIN_CONFIG_REG       0x401F833CU
#define IOMUXC_QTIMER_INPUT_PIN_CONFIG_ONFIELD   0x1U
#define QTMR_CounterInputPin             kQTMR_Counter1InputPin

/* Interrupt number and interrupt handler for the QTMR instance used */
#define QTMR_IRQ_ID      TMR3_IRQn
#define QTMR_IRQ_HANDLER TMR3_IRQHandler

/* QTMR Clock source divider for Ipg clock source, the value of two macros below should be aligned. */
#define QTMR_PRIMARY_SOURCE       (kQTMR_ClockDivide_4)
#define QTMR_CLOCK_SOURCE_DIVIDER (4U)
/* The frequency of the source clock after divided. */
#define QTMR_SOURCE_CLOCK (CLOCK_GetFreq(kCLOCK_IpgClk) / QTMR_CLOCK_SOURCE_DIVIDER)

volatile bool qtmrIsrFlag = false;
extern "C"{
void QTMR_IRQ_HANDLER(void)
{
    /* Clear interrupt flag.*/
    QTMR_ClearStatusFlags(BOARD_QTMR_BASEADDR, BOARD_QTMR_INPUT_CAPTURE_CHANNEL, kQTMR_EdgeFlag);

    qtmrIsrFlag = true;

    __DSB();
}
}

int main(void)
{
    qtmr_config_t qtmrConfig;
    uint32_t counterClock = 0;
    uint32_t timeCapt     = 0;
    uint32_t count        = 0;

    /* Board pin, clock, debug console init */
    BOARD_ConfigMPU();
    BOARD_InitBootPins();
    BOARD_InitBootClocks();

    QTMR_GetDefaultConfig(&qtmrConfig);

    /* Initial the input channel. */
    qtmrConfig.primarySource = QTMR_PRIMARY_SOURCE;
    QTMR_Init(BOARD_QTMR_BASEADDR, BOARD_QTMR_INPUT_CAPTURE_CHANNEL, &qtmrConfig);

    /* Set up the IOMUXC configuration for Quad Timer input pin */
 IOMUXC_SetPinMux(IOMUXC_QTIMER_INPUT_PIN_CONFIG_MUX,
                 IOMUXC_QTIMER_INPUT_PIN_CONFIG_MODE,
                 IOMUXC_QTIMER_INPUT_PIN_CONFIG_INPUT_REG,
                 IOMUXC_QTIMER_INPUT_PIN_CONFIG_INPUT_DSY,
                 IOMUXC_QTIMER_INPUT_PIN_CONFIG_REG,
                 IOMUXC_QTIMER_INPUT_PIN_CONFIG_ONFIELD);

    /* Setup the input capture */
    QTMR_SetupInputCapture(BOARD_QTMR_BASEADDR, BOARD_QTMR_INPUT_CAPTURE_CHANNEL, QTMR_CounterInputPin, false, true,
                           kQTMR_RisingEdge);

    /* Enable at the NVIC */
    EnableIRQ(QTMR_IRQ_ID);

    /* Enable timer compare interrupt */
    QTMR_EnableInterrupts(BOARD_QTMR_BASEADDR, BOARD_QTMR_INPUT_CAPTURE_CHANNEL, kQTMR_EdgeInterruptEnable);

    /* Start the input channel to count on the rising edge of the primary source clock */
    QTMR_StartTimer(BOARD_QTMR_BASEADDR, BOARD_QTMR_INPUT_CAPTURE_CHANNEL, kQTMR_PriSrcRiseEdge);

    counterClock = QTMR_SOURCE_CLOCK / 1000U;


    while (1)
    {
        /* Your application code here */
    }
}
0 Kudos
Reply
1 Reply

265 Views
EdwinHz
NXP TechSupport
NXP TechSupport

Hi @vivekgourav,

Could you specify which part number you are currently using, as well as the SDK and IDE version? Also, what kind of problems are you seeing?

We provide example codes in our SDK which you can use for reference. You should be able to find a "qtmr_inputcapture_outputpwm" example code for the MCU that you are using in their respective SDK.

BR,
Edwin.

0 Kudos
Reply