The KSDK provides a peripheral driver for the Programmable Delay Block (PDB) module of Kinetis devices.
Overview
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 time 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 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:
- 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 DPB 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
ADC16_DoAutoCalibration(DEMO_PDB_ADC_INSTANCE);
#endif
|
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:
- 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. Refer to 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.
|
void PDB_Init |
( |
PDB_Type * |
base, |
|
|
const pdb_config_t * |
config |
|
) |
| |
This function is to make the initialization for PDB module. The operations includes are:
- Enable the clock for PDB instance.
- Configure the PDB module.
- Enable the PDB module.
- Parameters
-
base | PDB peripheral base address. |
config | Pointer to configuration structure. See "pdb_config_t". |
void PDB_Deinit |
( |
PDB_Type * |
base | ) |
|
- Parameters
-
base | PDB peripheral base address. |
This function initializes the user configure structure to default value. the default value are:
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 is to load the counter values from their 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 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 is to set 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 setting value here.
- 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". |
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 | Enable the feature 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 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. |