MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
PDB: Programmable Delay Block

Overview

The MCUXpresso SDK provides a peripheral driver for the Programmable Delay Block (PDB) module of MCUXpresso SDK devices.

The PDB driver includes a basic PDB counter, trigger generators for ADC, DAC, and pulse-out.

The basic PDB counter can be used as a general programmable timer with an interrupt. The counter increases automatically with the divided clock signal after it is triggered to start by an external trigger input or the software trigger. There are "milestones" for the output trigger event. When the counter is equal to any of these "milestones", the corresponding trigger is generated and sent out to other modules. These "milestones" are for the following events.

The "milestone" values have a flexible load mode. To call the APIs to set these value is equivalent to writing data to their buffer. The loading event occurs as the load mode describes. This design ensures that all "milestones" can be updated at the same time.

Typical use case

Working as basic PDB counter with a PDB interrupt.

int main(void)
{
// ...
EnableIRQ(DEMO_PDB_IRQ_ID);
// ...
// Configures the PDB counter.
PDB_GetDefaultConfig(&pdbConfigStruct);
PDB_Init(DEMO_PDB_INSTANCE, &pdbConfigStruct);
// Configures the delay interrupt.
PDB_SetModulusValue(DEMO_PDB_INSTANCE, 1000U);
PDB_SetCounterDelayValue(DEMO_PDB_INSTANCE, 1000U); // The available delay value is less than or equal to the modulus value.
PDB_DoLoadValues(DEMO_PDB_INSTANCE);
while (1)
{
// ...
g_PdbDelayInterruptFlag = false;
PDB_DoSoftwareTrigger(DEMO_PDB_INSTANCE);
while (!g_PdbDelayInterruptFlag)
{
}
}
}
void DEMO_PDB_IRQ_HANDLER_FUNC(void)
{
// ...
g_PdbDelayInterruptFlag = true;
}

Working with an additional trigger. The ADC trigger is used as an example.

void DEMO_PDB_IRQ_HANDLER_FUNC(void)
{
g_PdbDelayInterruptCounter++;
g_PdbDelayInterruptFlag = true;
}
void DEMO_PDB_InitADC(void)
{
adc16_config_t adc16ConfigStruct;
adc16_channel_config_t adc16ChannelConfigStruct;
ADC16_GetDefaultConfig(&adc16ConfigStruct);
ADC16_Init(DEMO_PDB_ADC_INSTANCE, &adc16ConfigStruct);
#if defined(FSL_FEATURE_ADC16_HAS_CALIBRATION) && FSL_FEATURE_ADC16_HAS_CALIBRATION
ADC16_EnableHardwareTrigger(DEMO_PDB_ADC_INSTANCE, false);
ADC16_DoAutoCalibration(DEMO_PDB_ADC_INSTANCE);
#endif /* FSL_FEATURE_ADC16_HAS_CALIBRATION */
ADC16_EnableHardwareTrigger(DEMO_PDB_ADC_INSTANCE, true);
adc16ChannelConfigStruct.channelNumber = DEMO_PDB_ADC_USER_CHANNEL;
adc16ChannelConfigStruct.enableInterruptOnConversionCompleted = true; /* Enable the interrupt. */
#if defined(FSL_FEATURE_ADC16_HAS_DIFF_MODE) && FSL_FEATURE_ADC16_HAS_DIFF_MODE
adc16ChannelConfigStruct.enableDifferentialConversion = false;
#endif /* FSL_FEATURE_ADC16_HAS_DIFF_MODE */
ADC16_SetChannelConfig(DEMO_PDB_ADC_INSTANCE, DEMO_PDB_ADC_CHANNEL_GROUP, &adc16ChannelConfigStruct);
}
void DEMO_PDB_ADC_IRQ_HANDLER_FUNCTION(void)
{
uint32_t tmp32;
tmp32 = ADC16_GetChannelConversionValue(DEMO_PDB_ADC_INSTANCE, DEMO_PDB_ADC_CHANNEL_GROUP); /* Read to clear COCO flag. */
g_AdcInterruptCounter++;
g_AdcInterruptFlag = true;
}
int main(void)
{
// ...
EnableIRQ(DEMO_PDB_IRQ_ID);
EnableIRQ(DEMO_PDB_ADC_IRQ_ID);
// ...
// Configures the PDB counter.
PDB_GetDefaultConfig(&pdbConfigStruct);
PDB_Init(DEMO_PDB_INSTANCE, &pdbConfigStruct);
// Configures the delay interrupt.
PDB_SetModulusValue(DEMO_PDB_INSTANCE, 1000U);
PDB_SetCounterDelayValue(DEMO_PDB_INSTANCE, 1000U); // The available delay value is less than or equal to the modulus value.
// Configures the ADC pre-trigger.
pdbAdcPreTriggerConfigStruct.enablePreTriggerMask = 1U << DEMO_PDB_ADC_PRETRIGGER_CHANNEL;
pdbAdcPreTriggerConfigStruct.enableOutputMask = 1U << DEMO_PDB_ADC_PRETRIGGER_CHANNEL;
pdbAdcPreTriggerConfigStruct.enableBackToBackOperationMask = 0U;
PDB_SetADCPreTriggerConfig(DEMO_PDB_INSTANCE, DEMO_PDB_ADC_TRIGGER_CHANNEL, &pdbAdcPreTriggerConfigStruct);
PDB_SetADCPreTriggerDelayValue(DEMO_PDB_INSTANCE,
DEMO_PDB_ADC_TRIGGER_CHANNEL, DEMO_PDB_ADC_PRETRIGGER_CHANNEL, 200U);
// The available pre-trigger delay value is less than or equal to the modulus value.
PDB_DoLoadValues(DEMO_PDB_INSTANCE);
// Configures the ADC.
DEMO_PDB_InitADC();
while (1)
{
g_PdbDelayInterruptFlag = false;
g_AdcInterruptFlag = false;
PDB_DoSoftwareTrigger(DEMO_PDB_INSTANCE);
while ((!g_PdbDelayInterruptFlag) || (!g_AdcInterruptFlag))
{
}
// ...
}
}

Data Structures

struct  pdb_config_t
 PDB module configuration. More...
 
struct  pdb_adc_pretrigger_config_t
 PDB ADC Pre-trigger configuration. More...
 
struct  pdb_dac_trigger_config_t
 PDB DAC trigger configuration. More...
 

Enumerations

enum  _pdb_status_flags {
  kPDB_LoadOKFlag = PDB_SC_LDOK_MASK,
  kPDB_DelayEventFlag = PDB_SC_PDBIF_MASK
}
 PDB flags. More...
 
enum  _pdb_adc_pretrigger_flags {
  kPDB_ADCPreTriggerChannel0Flag = PDB_S_CF(1U << 0),
  kPDB_ADCPreTriggerChannel1Flag = PDB_S_CF(1U << 1),
  kPDB_ADCPreTriggerChannel0ErrorFlag = PDB_S_ERR(1U << 0),
  kPDB_ADCPreTriggerChannel1ErrorFlag = PDB_S_ERR(1U << 1)
}
 PDB ADC PreTrigger channel flags. More...
 
enum  _pdb_interrupt_enable {
  kPDB_SequenceErrorInterruptEnable = PDB_SC_PDBEIE_MASK,
  kPDB_DelayInterruptEnable = PDB_SC_PDBIE_MASK
}
 PDB buffer interrupts. More...
 
enum  pdb_load_value_mode_t {
  kPDB_LoadValueImmediately = 0U,
  kPDB_LoadValueOnCounterOverflow = 1U,
  kPDB_LoadValueOnTriggerInput = 2U,
  kPDB_LoadValueOnCounterOverflowOrTriggerInput = 3U
}
 PDB load value mode. More...
 
enum  pdb_prescaler_divider_t {
  kPDB_PrescalerDivider1 = 0U,
  kPDB_PrescalerDivider2 = 1U,
  kPDB_PrescalerDivider4 = 2U,
  kPDB_PrescalerDivider8 = 3U,
  kPDB_PrescalerDivider16 = 4U,
  kPDB_PrescalerDivider32 = 5U,
  kPDB_PrescalerDivider64 = 6U,
  kPDB_PrescalerDivider128 = 7U
}
 Prescaler divider. More...
 
enum  pdb_divider_multiplication_factor_t {
  kPDB_DividerMultiplicationFactor1 = 0U,
  kPDB_DividerMultiplicationFactor10 = 1U,
  kPDB_DividerMultiplicationFactor20 = 2U,
  kPDB_DividerMultiplicationFactor40 = 3U
}
 Multiplication factor select for prescaler. More...
 
enum  pdb_trigger_input_source_t {
  kPDB_TriggerInput0 = 0U,
  kPDB_TriggerInput1 = 1U,
  kPDB_TriggerInput2 = 2U,
  kPDB_TriggerInput3 = 3U,
  kPDB_TriggerInput4 = 4U,
  kPDB_TriggerInput5 = 5U,
  kPDB_TriggerInput6 = 6U,
  kPDB_TriggerInput7 = 7U,
  kPDB_TriggerInput8 = 8U,
  kPDB_TriggerInput9 = 9U,
  kPDB_TriggerInput10 = 10U,
  kPDB_TriggerInput11 = 11U,
  kPDB_TriggerInput12 = 12U,
  kPDB_TriggerInput13 = 13U,
  kPDB_TriggerInput14 = 14U,
  kPDB_TriggerSoftware = 15U
}
 Trigger input source. More...
 

Driver version

#define FSL_PDB_DRIVER_VERSION   (MAKE_VERSION(2, 0, 1))
 PDB driver version 2.0.1. More...
 

Initialization

void PDB_Init (PDB_Type *base, const pdb_config_t *config)
 Initializes the PDB module. More...
 
void PDB_Deinit (PDB_Type *base)
 De-initializes the PDB module. More...
 
void PDB_GetDefaultConfig (pdb_config_t *config)
 Initializes the PDB user configuration structure. More...
 
static void PDB_Enable (PDB_Type *base, bool enable)
 Enables the PDB module. More...
 

Basic Counter

static void PDB_DoSoftwareTrigger (PDB_Type *base)
 Triggers the PDB counter by software. More...
 
static void PDB_DoLoadValues (PDB_Type *base)
 Loads the counter values. More...
 
static void PDB_EnableDMA (PDB_Type *base, bool enable)
 Enables the DMA for the PDB module. More...
 
static void PDB_EnableInterrupts (PDB_Type *base, uint32_t mask)
 Enables the interrupts for the PDB module. More...
 
static void PDB_DisableInterrupts (PDB_Type *base, uint32_t mask)
 Disables the interrupts for the PDB module. More...
 
static uint32_t PDB_GetStatusFlags (PDB_Type *base)
 Gets the status flags of the PDB module. More...
 
static void PDB_ClearStatusFlags (PDB_Type *base, uint32_t mask)
 Clears the status flags of the PDB module. More...
 
static void PDB_SetModulusValue (PDB_Type *base, uint32_t value)
 Specifies the counter period. More...
 
static uint32_t PDB_GetCounterValue (PDB_Type *base)
 Gets the PDB counter's current value. More...
 
static void PDB_SetCounterDelayValue (PDB_Type *base, uint32_t value)
 Sets the value for the PDB counter delay event. More...
 

ADC Pre-trigger

static void PDB_SetADCPreTriggerConfig (PDB_Type *base, uint32_t channel, pdb_adc_pretrigger_config_t *config)
 Configures the ADC pre-trigger in the PDB module. More...
 
static void PDB_SetADCPreTriggerDelayValue (PDB_Type *base, uint32_t channel, uint32_t preChannel, uint32_t value)
 Sets the value for the ADC pre-trigger delay event. More...
 
static uint32_t PDB_GetADCPreTriggerStatusFlags (PDB_Type *base, uint32_t channel)
 Gets the ADC pre-trigger's status flags. More...
 
static void PDB_ClearADCPreTriggerStatusFlags (PDB_Type *base, uint32_t channel, uint32_t mask)
 Clears the ADC pre-trigger status flags. More...
 

DAC Interval Trigger

void PDB_SetDACTriggerConfig (PDB_Type *base, uint32_t channel, pdb_dac_trigger_config_t *config)
 Configures the DAC trigger in the PDB module. More...
 
static void PDB_SetDACTriggerIntervalValue (PDB_Type *base, uint32_t channel, uint32_t value)
 Sets the value for the DAC interval event. More...
 

Pulse-Out Trigger

static void PDB_EnablePulseOutTrigger (PDB_Type *base, uint32_t channelMask, bool enable)
 Enables the pulse out trigger channels. More...
 
static void PDB_SetPulseOutTriggerDelayValue (PDB_Type *base, uint32_t channel, uint32_t value1, uint32_t value2)
 Sets event values for the pulse out trigger. More...
 

Data Structure Documentation

struct pdb_config_t

Data Fields

pdb_load_value_mode_t loadValueMode
 Select the load value mode. More...
 
pdb_prescaler_divider_t prescalerDivider
 Select the prescaler divider. More...
 
pdb_divider_multiplication_factor_t dividerMultiplicationFactor
 Multiplication factor select for prescaler. More...
 
pdb_trigger_input_source_t triggerInputSource
 Select the trigger input source. More...
 
bool enableContinuousMode
 Enable the PDB operation in Continuous mode. More...
 

Field Documentation

pdb_load_value_mode_t pdb_config_t::loadValueMode
pdb_prescaler_divider_t pdb_config_t::prescalerDivider
pdb_divider_multiplication_factor_t pdb_config_t::dividerMultiplicationFactor
pdb_trigger_input_source_t pdb_config_t::triggerInputSource
bool pdb_config_t::enableContinuousMode
struct pdb_adc_pretrigger_config_t

Data Fields

uint32_t enablePreTriggerMask
 PDB Channel Pre-trigger Enable. More...
 
uint32_t enableOutputMask
 PDB Channel Pre-trigger Output Select. More...
 
uint32_t enableBackToBackOperationMask
 PDB Channel pre-trigger Back-to-Back Operation Enable. More...
 

Field Documentation

uint32_t pdb_adc_pretrigger_config_t::enablePreTriggerMask
uint32_t pdb_adc_pretrigger_config_t::enableOutputMask

PDB channel's corresponding pre-trigger asserts when the counter reaches the channel delay register.

uint32_t pdb_adc_pretrigger_config_t::enableBackToBackOperationMask

Back-to-back operation enables the ADC conversions complete to trigger the next PDB channel pre-trigger and trigger output, so that the ADC conversions can be triggered on next set of configuration and results registers.

struct pdb_dac_trigger_config_t

Data Fields

bool enableExternalTriggerInput
 Enables the external trigger for DAC interval counter. More...
 
bool enableIntervalTrigger
 Enables the DAC interval trigger. More...
 

Field Documentation

bool pdb_dac_trigger_config_t::enableExternalTriggerInput
bool pdb_dac_trigger_config_t::enableIntervalTrigger

Macro Definition Documentation

#define FSL_PDB_DRIVER_VERSION   (MAKE_VERSION(2, 0, 1))

Enumeration Type Documentation

Enumerator
kPDB_LoadOKFlag 

This flag is automatically cleared when the values in buffers are loaded into the internal registers after the LDOK bit is set or the PDBEN is cleared.

kPDB_DelayEventFlag 

PDB timer delay event flag.

Enumerator
kPDB_ADCPreTriggerChannel0Flag 

Pre-trigger 0 flag.

kPDB_ADCPreTriggerChannel1Flag 

Pre-trigger 1 flag.

kPDB_ADCPreTriggerChannel0ErrorFlag 

Pre-trigger 0 Error.

kPDB_ADCPreTriggerChannel1ErrorFlag 

Pre-trigger 1 Error.

Enumerator
kPDB_SequenceErrorInterruptEnable 

PDB sequence error interrupt enable.

kPDB_DelayInterruptEnable 

PDB delay interrupt enable.

Selects the mode to load the internal values after doing the load operation (write 1 to PDBx_SC[LDOK]). These values are for the following operations.

  • PDB counter (PDBx_MOD, PDBx_IDLY)
  • ADC trigger (PDBx_CHnDLYm)
  • DAC trigger (PDBx_DACINTx)
  • CMP trigger (PDBx_POyDLY)
Enumerator
kPDB_LoadValueImmediately 

Load immediately after 1 is written to LDOK.

kPDB_LoadValueOnCounterOverflow 

Load when the PDB counter overflows (reaches the MOD register value).

kPDB_LoadValueOnTriggerInput 

Load a trigger input event is detected.

kPDB_LoadValueOnCounterOverflowOrTriggerInput 

Load either when the PDB counter overflows or a trigger input is detected.

Counting uses the peripheral clock divided by multiplication factor selected by times of MULT.

Enumerator
kPDB_PrescalerDivider1 

Divider x1.

kPDB_PrescalerDivider2 

Divider x2.

kPDB_PrescalerDivider4 

Divider x4.

kPDB_PrescalerDivider8 

Divider x8.

kPDB_PrescalerDivider16 

Divider x16.

kPDB_PrescalerDivider32 

Divider x32.

kPDB_PrescalerDivider64 

Divider x64.

kPDB_PrescalerDivider128 

Divider x128.

Selects the multiplication factor of the prescaler divider for the counter clock.

Enumerator
kPDB_DividerMultiplicationFactor1 

Multiplication factor is 1.

kPDB_DividerMultiplicationFactor10 

Multiplication factor is 10.

kPDB_DividerMultiplicationFactor20 

Multiplication factor is 20.

kPDB_DividerMultiplicationFactor40 

Multiplication factor is 40.

Selects the trigger input source for the PDB. The trigger input source can be internal or external (EXTRG pin), or the software trigger. See chip configuration details for the actual PDB input trigger connections.

Enumerator
kPDB_TriggerInput0 

Trigger-In 0.

kPDB_TriggerInput1 

Trigger-In 1.

kPDB_TriggerInput2 

Trigger-In 2.

kPDB_TriggerInput3 

Trigger-In 3.

kPDB_TriggerInput4 

Trigger-In 4.

kPDB_TriggerInput5 

Trigger-In 5.

kPDB_TriggerInput6 

Trigger-In 6.

kPDB_TriggerInput7 

Trigger-In 7.

kPDB_TriggerInput8 

Trigger-In 8.

kPDB_TriggerInput9 

Trigger-In 9.

kPDB_TriggerInput10 

Trigger-In 10.

kPDB_TriggerInput11 

Trigger-In 11.

kPDB_TriggerInput12 

Trigger-In 12.

kPDB_TriggerInput13 

Trigger-In 13.

kPDB_TriggerInput14 

Trigger-In 14.

kPDB_TriggerSoftware 

Trigger-In 15, software trigger.

Function Documentation

void PDB_Init ( PDB_Type *  base,
const pdb_config_t config 
)

This function initializes the PDB module. The operations included are as follows.

  • Enable the clock for PDB instance.
  • Configure the PDB module.
  • Enable the PDB module.
Parameters
basePDB peripheral base address.
configPointer to the configuration structure. See "pdb_config_t".
void PDB_Deinit ( PDB_Type *  base)
Parameters
basePDB peripheral base address.
void PDB_GetDefaultConfig ( pdb_config_t config)

This function initializes the user configuration structure to a default value. The default values are as follows.

* config->loadValueMode = kPDB_LoadValueImmediately;
* config->prescalerDivider = kPDB_PrescalerDivider1;
* config->dividerMultiplicationFactor = kPDB_DividerMultiplicationFactor1;
* config->triggerInputSource = kPDB_TriggerSoftware;
* config->enableContinuousMode = false;
*
Parameters
configPointer to configuration structure. See "pdb_config_t".
static void PDB_Enable ( PDB_Type *  base,
bool  enable 
)
inlinestatic
Parameters
basePDB peripheral base address.
enableEnable the module or not.
static void PDB_DoSoftwareTrigger ( PDB_Type *  base)
inlinestatic
Parameters
basePDB peripheral base address.
static void PDB_DoLoadValues ( PDB_Type *  base)
inlinestatic

This function loads the counter values from the internal buffer. See "pdb_load_value_mode_t" about PDB's load mode.

Parameters
basePDB peripheral base address.
static void PDB_EnableDMA ( PDB_Type *  base,
bool  enable 
)
inlinestatic
Parameters
basePDB peripheral base address.
enableEnable the feature or not.
static void PDB_EnableInterrupts ( PDB_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
basePDB peripheral base address.
maskMask value for interrupts. See "_pdb_interrupt_enable".
static void PDB_DisableInterrupts ( PDB_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
basePDB peripheral base address.
maskMask value for interrupts. See "_pdb_interrupt_enable".
static uint32_t PDB_GetStatusFlags ( PDB_Type *  base)
inlinestatic
Parameters
basePDB peripheral base address.
Returns
Mask value for asserted flags. See "_pdb_status_flags".
static void PDB_ClearStatusFlags ( PDB_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
basePDB peripheral base address.
maskMask value of flags. See "_pdb_status_flags".
static void PDB_SetModulusValue ( PDB_Type *  base,
uint32_t  value 
)
inlinestatic
Parameters
basePDB peripheral base address.
valueSetting value for the modulus. 16-bit is available.
static uint32_t PDB_GetCounterValue ( PDB_Type *  base)
inlinestatic
Parameters
basePDB peripheral base address.
Returns
PDB counter's current value.
static void PDB_SetCounterDelayValue ( PDB_Type *  base,
uint32_t  value 
)
inlinestatic
Parameters
basePDB peripheral base address.
valueSetting value for PDB counter delay event. 16-bit is available.
static void PDB_SetADCPreTriggerConfig ( PDB_Type *  base,
uint32_t  channel,
pdb_adc_pretrigger_config_t config 
)
inlinestatic
Parameters
basePDB peripheral base address.
channelChannel index for ADC instance.
configPointer to the configuration structure. See "pdb_adc_pretrigger_config_t".
static void PDB_SetADCPreTriggerDelayValue ( PDB_Type *  base,
uint32_t  channel,
uint32_t  preChannel,
uint32_t  value 
)
inlinestatic

This function sets the value for ADC pre-trigger delay event. It specifies the delay value for the channel's corresponding pre-trigger. The pre-trigger asserts when the PDB counter is equal to the set value.

Parameters
basePDB peripheral base address.
channelChannel index for ADC instance.
preChannelChannel group index for ADC instance.
valueSetting value for ADC pre-trigger delay event. 16-bit is available.
static uint32_t PDB_GetADCPreTriggerStatusFlags ( PDB_Type *  base,
uint32_t  channel 
)
inlinestatic
Parameters
basePDB peripheral base address.
channelChannel index for ADC instance.
Returns
Mask value for asserted flags. See "_pdb_adc_pretrigger_flags".
static void PDB_ClearADCPreTriggerStatusFlags ( PDB_Type *  base,
uint32_t  channel,
uint32_t  mask 
)
inlinestatic
Parameters
basePDB peripheral base address.
channelChannel index for ADC instance.
maskMask value for flags. See "_pdb_adc_pretrigger_flags".
void PDB_SetDACTriggerConfig ( PDB_Type *  base,
uint32_t  channel,
pdb_dac_trigger_config_t config 
)
Parameters
basePDB peripheral base address.
channelChannel index for DAC instance.
configPointer to the configuration structure. See "pdb_dac_trigger_config_t".
static void PDB_SetDACTriggerIntervalValue ( PDB_Type *  base,
uint32_t  channel,
uint32_t  value 
)
inlinestatic

This fucntion sets the value for DAC interval event. DAC interval trigger triggers the DAC module to update the buffer when the DAC interval counter is equal to the set value.

Parameters
basePDB peripheral base address.
channelChannel index for DAC instance.
valueSetting value for the DAC interval event.
static void PDB_EnablePulseOutTrigger ( PDB_Type *  base,
uint32_t  channelMask,
bool  enable 
)
inlinestatic
Parameters
basePDB peripheral base address.
channelMaskChannel mask value for multiple pulse out trigger channel.
enableWhether the feature is enabled or not.
static void PDB_SetPulseOutTriggerDelayValue ( PDB_Type *  base,
uint32_t  channel,
uint32_t  value1,
uint32_t  value2 
)
inlinestatic

This function is used to set event values for the pulse output trigger. These pulse output trigger delay values specify the delay for the PDB Pulse-out. Pulse-out goes high when the PDB counter is equal to the pulse output high value (value1). Pulse-out goes low when the PDB counter is equal to the pulse output low value (value2).

Parameters
basePDB peripheral base address.
channelChannel index for pulse out trigger channel.
value1Setting value for pulse out high.
value2Setting value for pulse out low.