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.
- Counter delay interrupt, which is the interrupt for the PDB module
- ADC pre-trigger to trigger the ADC conversion
- DAC interval trigger to trigger the DAC buffer and move the buffer read pointer
- Pulse-out triggers to generate a single of rising and falling edges, which can be assembled to a window.
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);
PDB_Init(DEMO_PDB_INSTANCE, &pdbConfigStruct);
while (1)
{
g_PdbDelayInterruptFlag = false;
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_Init(DEMO_PDB_ADC_INSTANCE, &adc16ConfigStruct);
#if defined(FSL_FEATURE_ADC16_HAS_CALIBRATION) && FSL_FEATURE_ADC16_HAS_CALIBRATION
#endif
adc16ChannelConfigStruct.
channelNumber = DEMO_PDB_ADC_USER_CHANNEL;
#if defined(FSL_FEATURE_ADC16_HAS_DIFF_MODE) && FSL_FEATURE_ADC16_HAS_DIFF_MODE
#endif
}
void DEMO_PDB_ADC_IRQ_HANDLER_FUNCTION(void)
{
uint32_t tmp32;
g_AdcInterruptCounter++;
g_AdcInterruptFlag = true;
}
int main(void)
{
EnableIRQ(DEMO_PDB_IRQ_ID);
EnableIRQ(DEMO_PDB_ADC_IRQ_ID);
PDB_Init(DEMO_PDB_INSTANCE, &pdbConfigStruct);
pdbAdcPreTriggerConfigStruct.enablePreTriggerMask = 1U << DEMO_PDB_ADC_PRETRIGGER_CHANNEL;
pdbAdcPreTriggerConfigStruct.enableOutputMask = 1U << DEMO_PDB_ADC_PRETRIGGER_CHANNEL;
pdbAdcPreTriggerConfigStruct.enableBackToBackOperationMask = 0U;
DEMO_PDB_ADC_TRIGGER_CHANNEL, DEMO_PDB_ADC_PRETRIGGER_CHANNEL, 200U);
DEMO_PDB_InitADC();
while (1)
{
g_PdbDelayInterruptFlag = false;
g_AdcInterruptFlag = false;
while ((!g_PdbDelayInterruptFlag) || (!g_AdcInterruptFlag))
{
}
}
}
|
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...
|
|
bool pdb_config_t::enableContinuousMode |
struct pdb_adc_pretrigger_config_t |
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 |
bool pdb_dac_trigger_config_t::enableExternalTriggerInput |
bool pdb_dac_trigger_config_t::enableIntervalTrigger |
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.
|
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
-
base | PDB peripheral base address. |
config | Pointer to the configuration structure. See "pdb_config_t". |
void PDB_Deinit |
( |
PDB_Type * |
base | ) |
|
- Parameters
-
base | PDB peripheral base address. |
This function initializes the user configuration structure to a default value. The default values are as follows.
* config->enableContinuousMode = false;
*
- Parameters
-
config | Pointer to configuration structure. See "pdb_config_t". |
static void PDB_Enable |
( |
PDB_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | PDB peripheral base address. |
enable | Enable the module or not. |
static void PDB_DoSoftwareTrigger |
( |
PDB_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | PDB 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
-
base | PDB peripheral base address. |
static void PDB_EnableDMA |
( |
PDB_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | PDB peripheral base address. |
enable | Enable the feature or not. |
static void PDB_EnableInterrupts |
( |
PDB_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | PDB peripheral base address. |
mask | Mask value for interrupts. See "_pdb_interrupt_enable". |
static void PDB_DisableInterrupts |
( |
PDB_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | PDB peripheral base address. |
mask | Mask value for interrupts. See "_pdb_interrupt_enable". |
static uint32_t PDB_GetStatusFlags |
( |
PDB_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | PDB 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
-
base | PDB peripheral base address. |
mask | Mask value of flags. See "_pdb_status_flags". |
static void PDB_SetModulusValue |
( |
PDB_Type * |
base, |
|
|
uint32_t |
value |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | PDB peripheral base address. |
value | Setting value for the modulus. 16-bit is available. |
static uint32_t PDB_GetCounterValue |
( |
PDB_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | PDB peripheral base address. |
- Returns
- PDB counter's current value.
static void PDB_SetCounterDelayValue |
( |
PDB_Type * |
base, |
|
|
uint32_t |
value |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | PDB peripheral base address. |
value | Setting value for PDB counter delay event. 16-bit is available. |
- Parameters
-
base | PDB peripheral base address. |
channel | Channel index for ADC instance. |
config | Pointer 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
-
base | PDB peripheral base address. |
channel | Channel index for ADC instance. |
preChannel | Channel group index for ADC instance. |
value | Setting value for ADC pre-trigger delay event. 16-bit is available. |
static uint32_t PDB_GetADCPreTriggerStatusFlags |
( |
PDB_Type * |
base, |
|
|
uint32_t |
channel |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | PDB peripheral base address. |
channel | Channel 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
-
base | PDB peripheral base address. |
channel | Channel index for ADC instance. |
mask | Mask value for flags. See "_pdb_adc_pretrigger_flags". |
- Parameters
-
base | PDB peripheral base address. |
channel | Channel index for DAC instance. |
config | Pointer 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
-
base | PDB peripheral base address. |
channel | Channel index for DAC instance. |
value | Setting value for the DAC interval event. |
static void PDB_EnablePulseOutTrigger |
( |
PDB_Type * |
base, |
|
|
uint32_t |
channelMask, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | PDB peripheral base address. |
channelMask | Channel mask value for multiple pulse out trigger channel. |
enable | Whether 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
-
base | PDB peripheral base address. |
channel | Channel index for pulse out trigger channel. |
value1 | Setting value for pulse out high. |
value2 | Setting value for pulse out low. |