MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
PWT: Pulse Width Timer

Overview

The MCUXpresso SDK provides a driver for the Pulse Width Timer (PWT) of MCUXpresso SDK devices.

Function groups

The PWT driver supports capture or measure the pulse width mapping on its input channels. The counter of PWT has two selectable clock sources, Timer clock and alternative clock. PWT module supports programmable positive or negative pulse edges, and programmable interrupt generation upon pulse width values or counter overflow.

Initialization and deinitialization

The function PWT_Init() initializes the PWT with specified configurations. The function PWT_GetDefaultConfig() gets the default configurations. The initialization function configures the PWT for the requested register update mode for register with buffers.

The function PWT_Deinit() disables the PWT counter and turns off the module clock.

Reset

The function PWT_Reset() is built into PWT as a mechanism used to reset/restart the pulse width timer.

Status

Provides functions to get and clear the PWT status.

Interrupt

Provides functions to enable/disable PWT interrupts and get current enabled interrupts.

Start & Stop timer

The function PWT_StartTimer() starts the PWT time counter.

The function PWT_StopTimer() stops the PWT time counter.

GetInterrupt

Provides functions to generate Overflow/Pulse Width Data Ready Interrupt.

Get Timer value

The function PWT_GetCurrentTimerCount() is set to read the current counter value.

The function PWT_ReadPositivePulseWidth() is set to read the positive pulse width.

The function PWT_ReadNegativePulseWidth() is set to read the negative pulse width.

PWT Operations

Input capture operations

The input capture operations sets up an channel for input capture.

The function EdgeCapture can be used to measure the pulse width of a signal. A channel is used during capture with the input signal coming through a channel n. The capture edge for each channel, and any filter value to be used when processing the input signal.

Typical use case

PWT measure

This is an example code to measure the pulse width:

Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/pwt

Data Structures

struct  pwt_config_t
 PWT configuration structure. More...
 

Macros

#define FSL_PWT_DRIVER_VERSION   (MAKE_VERSION(2, 0, 1))
 Version 2.0.1.
 

Enumerations

enum  pwt_clock_source_t {
  kPWT_TimerClock = 0U,
  kPWT_AlternativeClock
}
 PWT clock source selection. More...
 
enum  pwt_clock_prescale_t {
  kPWT_Prescale_Divide_1 = 0U,
  kPWT_Prescale_Divide_2,
  kPWT_Prescale_Divide_4,
  kPWT_Prescale_Divide_8,
  kPWT_Prescale_Divide_16,
  kPWT_Prescale_Divide_32,
  kPWT_Prescale_Divide_64,
  kPWT_Prescale_Divide_128
}
 PWT prescaler factor selection for clock source. More...
 
enum  pwt_input_edge_t {
  kPWT_StartFall_CaptureFall_Edge = 0U,
  kPWT_StartRise_CaptureRiseAndFall_Edge,
  kPWT_StartFall_CaptureRiseAndFall_Edge,
  kPWT_StartRise_CaptureRise_Edge
}
 PWT Input Edge. More...
 
enum  pwt_input_select_t {
  kPWT_InputPort_0 = 0U,
  kPWT_InputPort_1,
  kPWT_InputPort_2,
  kPWT_InputPort_3
}
 PWT input port selection. More...
 
enum  pwt_interrupt_enable_t {
  kPWT_ModuleInterruptEnable = PWT_R1_PWTIE_MASK,
  kPWT_PulseWidthReadyInterruptEnable = PWT_R1_PRDYIE_MASK,
  kPWT_CounterOverflowInterruptEnable = PWT_R1_POVIE_MASK
}
 List of PWT interrupts. More...
 
enum  pwt_status_flags_t {
  kPWT_CounterOverflowFlag = PWT_R1_PWTOV_MASK,
  kPWT_PulseWidthValidFlag = PWT_R1_PWTRDY_MASK
}
 List of PWT flags. More...
 

Functions

static uint16_t PWT_GetCurrentTimerCount (PWT_Type *base)
 Reads the current counter value. More...
 
static uint16_t PWT_ReadPositivePulseWidth (PWT_Type *base)
 Reads the positive pulse width. More...
 
static uint16_t PWT_ReadNegativePulseWidth (PWT_Type *base)
 Reads the negative pulse width. More...
 
static void PWT_Reset (PWT_Type *base)
 Performs a software reset on the PWT module. More...
 

Initialization and deinitialization

void PWT_Init (PWT_Type *base, const pwt_config_t *config)
 Ungates the PWT clock and configures the peripheral for basic operation. More...
 
void PWT_Deinit (PWT_Type *base)
 Gates the PWT clock. More...
 
void PWT_GetDefaultConfig (pwt_config_t *config)
 Fills in the PWT configuration structure with the default settings. More...
 

Interrupt Interface

static void PWT_EnableInterrupts (PWT_Type *base, uint32_t mask)
 Enables the selected PWT interrupts. More...
 
static void PWT_DisableInterrupts (PWT_Type *base, uint32_t mask)
 Disables the selected PWT interrupts. More...
 
static uint32_t PWT_GetEnabledInterrupts (PWT_Type *base)
 Gets the enabled PWT interrupts. More...
 

Status Interface

static uint32_t PWT_GetStatusFlags (PWT_Type *base)
 Gets the PWT status flags. More...
 
static void PWT_ClearStatusFlags (PWT_Type *base, uint32_t mask)
 Clears the PWT status flags. More...
 

Timer Start and Stop

static void PWT_StartTimer (PWT_Type *base)
 Starts the PWT counter. More...
 
static void PWT_StopTimer (PWT_Type *base)
 Stops the PWT counter. More...
 

Data Structure Documentation

struct pwt_config_t

This structure holds the configuration settings for the PWT peripheral. To initialize this structure to reasonable defaults, call the PWT_GetDefaultConfig() function and pass a pointer to the configuration structure instance.

The configuration structure can be made constant so as to reside in flash.

Data Fields

pwt_clock_source_t clockSource
 Clock source for the counter.
 
pwt_clock_prescale_t prescale
 Pre-scaler to divide down the clock.
 
pwt_input_select_t inputSelect
 PWT Pulse input port selection.
 
pwt_input_edge_t edge
 PWT Input Edge.
 

Enumeration Type Documentation

Enumerator
kPWT_TimerClock 

The Timer clock is used as the clock source of PWT counter.

kPWT_AlternativeClock 

Alternative clock is used as the clock source of PWT counter.

Enumerator
kPWT_Prescale_Divide_1 

PWT clock divided by 1.

kPWT_Prescale_Divide_2 

PWT clock divided by 2.

kPWT_Prescale_Divide_4 

PWT clock divided by 4.

kPWT_Prescale_Divide_8 

PWT clock divided by 8.

kPWT_Prescale_Divide_16 

PWT clock divided by 16.

kPWT_Prescale_Divide_32 

PWT clock divided by 32.

kPWT_Prescale_Divide_64 

PWT clock divided by 64.

kPWT_Prescale_Divide_128 

PWT clock divided by 128.

Enumerator
kPWT_StartFall_CaptureFall_Edge 

The first falling-edge starts the pulse width measurement, and on all the subsequent falling edges, the pulse width is captured.

kPWT_StartRise_CaptureRiseAndFall_Edge 

The first rising edge starts the pulse width measurement, and on all the subsequent rising and falling edges, the pulse width is captured.

kPWT_StartFall_CaptureRiseAndFall_Edge 

The first falling edge starts the pulse width measurement, and on all the subsequent rising and falling edges, the pulse width is captured.

kPWT_StartRise_CaptureRise_Edge 

The first-rising edge starts the pulse width measurement, and on all the subsequent rising edges, the pulse width is captured.

Enumerator
kPWT_InputPort_0 

PWT input comes from PWTIN[0].

kPWT_InputPort_1 

PWT input comes from PWTIN[1].

kPWT_InputPort_2 

PWT input comes from PWTIN[2].

kPWT_InputPort_3 

PWT input comes from PWTIN[3].

Enumerator
kPWT_ModuleInterruptEnable 

Module Interrupt.

kPWT_PulseWidthReadyInterruptEnable 

Pulse width data ready interrupt.

kPWT_CounterOverflowInterruptEnable 

Counter overflow interrupt.

Enumerator
kPWT_CounterOverflowFlag 

Counter overflow flag.

kPWT_PulseWidthValidFlag 

Pulse width valid flag.

Function Documentation

void PWT_Init ( PWT_Type *  base,
const pwt_config_t config 
)
Note
This API should be called at the beginning of the application using the PWT driver.
Parameters
basePWT peripheral base address
configPointer to the user configuration structure.
void PWT_Deinit ( PWT_Type *  base)
Parameters
basePWT peripheral base address
void PWT_GetDefaultConfig ( pwt_config_t config)

The default values are:

* config->clockSource = kPWT_TimerClock;
* config->prescale = kPWT_Prescale_Divide_1;
* config->inputSelect = kPWT_InputPort_0;
*
Parameters
configPointer to the user configuration structure.
static void PWT_EnableInterrupts ( PWT_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
basePWT peripheral base address
maskThe interrupts to enable. This is a logical OR of members of the enumeration pwt_interrupt_enable_t
static void PWT_DisableInterrupts ( PWT_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
basePWT peripheral base address
maskThe interrupts to enable. This is a logical OR of members of the enumeration pwt_interrupt_enable_t
static uint32_t PWT_GetEnabledInterrupts ( PWT_Type *  base)
inlinestatic
Parameters
basePWT peripheral base address
Returns
The enabled interrupts. This is the logical OR of members of the enumeration pwt_interrupt_enable_t
static uint32_t PWT_GetStatusFlags ( PWT_Type *  base)
inlinestatic
Parameters
basePWT peripheral base address
Returns
The status flags. This is the logical OR of members of the enumeration pwt_status_flags_t
static void PWT_ClearStatusFlags ( PWT_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
basePWT peripheral base address
maskThe status flags to clear. This is a logical OR of members of the enumeration pwt_status_flags_t
static void PWT_StartTimer ( PWT_Type *  base)
inlinestatic
Parameters
basePWT peripheral base address
static void PWT_StopTimer ( PWT_Type *  base)
inlinestatic
Parameters
basePWT peripheral base address
static uint16_t PWT_GetCurrentTimerCount ( PWT_Type *  base)
inlinestatic

This function returns the timer counting value

Parameters
basePWT peripheral base address
Returns
Current 16-bit timer counter value
static uint16_t PWT_ReadPositivePulseWidth ( PWT_Type *  base)
inlinestatic

This function reads the low and high registers and returns the 16-bit positive pulse width

Parameters
basePWT peripheral base address.
Returns
The 16-bit positive pulse width.
static uint16_t PWT_ReadNegativePulseWidth ( PWT_Type *  base)
inlinestatic

This function reads the low and high registers and returns the 16-bit negative pulse width

Parameters
basePWT peripheral base address.
Returns
The 16-bit negative pulse width.
static void PWT_Reset ( PWT_Type *  base)
inlinestatic
Parameters
basePWT peripheral base address