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
|
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...
|
|
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.
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.
|
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
-
base | PWT peripheral base address |
config | Pointer to the user configuration structure. |
void PWT_Deinit |
( |
PWT_Type * |
base | ) |
|
- Parameters
-
base | PWT peripheral base address |
The default values are:
- Parameters
-
config | Pointer to the user configuration structure. |
static void PWT_EnableInterrupts |
( |
PWT_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | PWT peripheral base address |
mask | The 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
-
base | PWT peripheral base address |
mask | The 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
-
base | PWT 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
-
base | PWT 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
-
base | PWT peripheral base address |
mask | The 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
-
base | PWT peripheral base address |
static void PWT_StopTimer |
( |
PWT_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | PWT peripheral base address |
static uint16_t PWT_GetCurrentTimerCount |
( |
PWT_Type * |
base | ) |
|
|
inlinestatic |
This function returns the timer counting value
- Parameters
-
base | PWT 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
-
base | PWT 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
-
base | PWT peripheral base address. |
- Returns
- The 16-bit negative pulse width.
static void PWT_Reset |
( |
PWT_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | PWT peripheral base address |