MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
QTMR Peripheral and Driver Overview

Peripheral feature and how this peripheral works

QTMR module is a timer system with 4 identical independent 16-bit counter channels. Each channel has two input nodes and its own output signal. One module has 4 input pins (input pin 0 ~ input pin 3), the input pin signals are shared by all channels' input nodes in this module.

Features

How this peripheral works

  1. Select clock source for primary input and secondary input and config necessary input attributes.
  2. Config count mode with length, direction, times, compare, load and perload attributes.
  3. Config output signal work mode and cooperation mode.
  4. Enable channel to start count, it can generate output signal (OFLAG) and interrupt/dma request.

How this driver are designed to make this peripheral works

The qtmr driver provides the structure qtmr_channel_config_t which contain several sub-structures and other member to cover all feature of one qtmr channel. The QTMR_Init() function takes the argument in type of qtmr_channel_config_t to complete the initialization of the channel. Since QTMR is very flexible and cannot give the commonly used configuration, these sub-structures are only used to facilitate the understanding of the module and will not provide function APIs to take them as parameters. Base on the sub-structures and other behaviors of QTMR module, the qtmr driver also be divided into several basic function groups.

How to use this driver

Typical Use Case

  1. Count mode with trigger a periodic interrupt In this typical use case, the counter will count the rising edges of the IP bus clock divider by 2. And generate compare interrupts when channel count to u16Comp1 value.
    * qtmr_config_t sQtmrConfig = {0};
    * qtmr_channel_config_t sChannelConfig;
    * sQtmrConfig.psChannelConfig[0] = &sChannelConfig;
    * uint16_t interrupt_period;
    * QTMR_GetChannelDefaultConfig(&sChannelConfig);
    * sChannelConfig.u16Comp1 = interrupt_period;
    * QTMR_Init(DEMO_QTMR_BASEADDR, &sChannelConfig);
    *
  2. Triggered count mode to capture PWM pulse width In this typical use case, the counter will start count the rising edges of the IP bus clock divider by 2 on first secondary input (secondary input connect to kQTMR_InputPin0) rising edge. And generate input edge flag on first secondary input falling edge. Then DMA will read the PWM pulse width from CAPT register. (Need enable DMA and configure DMA channel trigger source in application codes )
    * qtmr_config_t sQtmrConfig = {0};
    * qtmr_channel_config_t sChannelConfig;
    * sQtmrConfig.psChannelConfig[0] = &sChannelConfig;
    * QTMR_GetChannelDefaultConfig(&sChannelConfig);
    * sChannelConfig.sInputConfig.eSecondarySourceCaptureMode = kQTMR_SecondarySrcCaptureFallingEdge;
    * sChannelConfig.sCountConfig.eCountMode =
    * kQTMR_CountPrimarySrcRiseEdgeSecondarySrcRiseEdgeTrigWithReInit;
    * QTMR_Init(QTMR, &sChannelConfig);
    *
  3. Triggered count mode to short the PWM pulse width In this typical use case, the counter will start count the rising edges of the IP bus clock divider by 2 on the first secondary input (PWM output connect to kQTMR_InputPin0) rising edge. The channel output will clear on this init, and set until the counter compare event(compare value should short than PWM pulse width), then the output will clear on the next secondary input falling edge. This case makes QTMR channel output to be a PWM signal with a shorter pulse width.
    * qtmr_config_t sQtmrConfig = {0};
    * qtmr_channel_config_t sChannelConfig;
    * sQtmrConfig.psChannelConfig[0] = &sChannelConfig;
    * uint16_t delay_period;
    * QTMR_GetChannelDefaultConfig(&sChannelConfig);
    * sChannelConfig.sCountConfig.eCountMode =
    * sChannelConfig.u16Comp1 = delay_period;
    * QTMR_Init(QTMR, &sChannelConfig);
    *
  4. PWM mode with variable frequency and pulse width In this typical use case, the channel output yields a pulse-width modulated (PWM) signal whose frequency and pulse width is determined by the values programmed into the COMP1 and COMP2 registers, and the input clock frequency. When interrupts generated by the channel compare2 event, use can write new values for both CMPLD1 and CMPLD2 according to the next pulse width and frequency.
    * qtmr_config_t sQtmrConfig = {0};
    * qtmr_channel_config_t sChannelConfig;
    * sQtmrConfig.psChannelConfig[0] = &sChannelConfig;
    * uint16_t pulse_width;
    * uint16_t pwm_period;
    * QTMR_GetChannelDefaultConfig(&sChannelConfig);
    * sChannelConfig.u16Comp1Preload = pulse_width;
    * sChannelConfig.u16Comp2Preload = pwm_period - pulse_width;
    * sChannelConfig.sCountConfig.eCountPreload1 = kQTMR_CountPreloadOnComp2CompareEvent;
    * sChannelConfig.sCountConfig.eCountPreload2 = kQTMR_CountPreloadOnComp1CompareEvent;
    * sChannelConfig.sOutputConfig.bEnableSwForceOutput = true;
    * sChannelConfig.sOutputConfig.bEnableOutputPin = true;
    * QTMR_Init(QTMR, &sChannelConfig);
    *