Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
PDB Peripheral driver

Overview

This section describes the programming interface of the PDB Peripheral driver. The PDB peripheral driver configures the PDB (Programmable Delay Block). It handles the triggers for ADC and DAC and pulse out to the CMP and the PDB counter.

PDB Driver model building

There is one main PDB counter for all triggers. When the indicated external trigger input arrives, the PDB counter launches and is increased by setting clock. The counter trigger milestones for ADC and DAC pulse out to the CMP and the PDB counter and wait for the PDB counter. Once the PDB counter hits each milestone, also called the critical delay value, the corresponding event is triggered and the trigger signal is sent out to trigger other peripherals. Therefore, the PDB module is a collector and manager of triggers.

PDB Initialization

The core feature of the PDB module is a programmable timer/counter. Additional features enable and set the milestone for the corresponding trigger. Therefore, the PDB module is first initialized as a programmable timer. To initialize the PDB driver, a configuration structure of the of "pdb_user_config_t" type is required and should store an available configuration. The API of the PDB_DRV_StructInitUserConfigForSoftTrigger() function provides a configuration which the PDB can use. However, this configuration is not sufficient for user-specific use cases. The user should provide a configuration suitable for the application requirements. Call the API of PDB_DRV_Init() function to initialize the PDB timer/counter.

All triggers share the same counter. However, the DAC trigger does not share the same counting circle with other triggers. When the DAC's internal circle ends, the trigger is generated and the internal circle restarts.

The basic timing/counting step is set when initializing the main PDB counter:

The basic timing/counting step = F_BusClkHz / pdb_timer_config_t.clkPreDiv / pdb_timer_config_t.clkPreMultFactor

The F_BusClkHz is the frequency of bus clock in Hertz. The "clkPreDiv" and "clkPreMultFactor" are in the pdb_timer_config_t structure. All triggering milestones are based on this step.

PDB Call diagram

Four kinds of typical use cases are designed for the PDB module.

These are the examples to initialize and configure the PDB driver for typical use cases.

Normal Timer/Counter:

// pdb_test_normal_timer.c //
#include "pdb_test.h"
static volatile uint32_t gPdbIntCounter = 0U;
static volatile uint32_t gPdbInstance = 0U;
static void PDB_ISR_Counter(void);
void PDB_TEST_NormalTimer(uint32_t instance)
{
pdb_timer_config_t PdbTimerConfig;
PdbTimerConfig.seqErrIntEnable = false;
PdbTimerConfig.clkPreDiv = kPdbClkPreDivBy8;
PdbTimerConfig.triggerInput = kPdbSoftTrigger;
PdbTimerConfig.continuousModeEnable = true;
PdbTimerConfig.dmaEnable = false;
PdbTimerConfig.intEnable = true;
PDB_DRV_Init(instance, &PdbTimerConfig);
PDB_DRV_SetTimerModulusValue(instance, 0xFFFU);
gPdbIntCounter = 0U;
gPdbInstance = instance;
PDB_TEST_InstallCallback(instance, PDB_ISR_Counter);
while (gPdbIntCounter < 20U) {}
PRINTF("PDB Timer's delay interrupt generated.\r\n");
PDB_DRV_Deinit(instance);
PRINTF("OK.\r\n");
}
static void PDB_ISR_Counter(void)
{
if (gPdbIntCounter >= 0xFFFFU)
{
gPdbIntCounter = 0U;
}
else
{
gPdbIntCounter++;
}
}

Trigger for ADC module:

#include "pdb_test.h"
// pdb_test_adc_trigger.c //
void PDB_TEST_AdcPreTrigger(uint32_t instance)
{
pdb_timer_config_t PdbTimerConfig;
pdb_adc_pretrigger_config_t PdbAdcPreTriggerConfig;
PdbTimerConfig.seqErrIntEnable = false;
PdbTimerConfig.clkPreDiv = kPdbClkPreDivBy8;
PdbTimerConfig.triggerInput = kPdbSoftTrigger;
PdbTimerConfig.continuousModeEnable = false;
PdbTimerConfig.dmaEnable = false;
PdbTimerConfig.intEnable = false;
PDB_DRV_Init(instance, &PdbTimerConfig);
PdbAdcPreTriggerConfig.adcPreTriggerIdx = 0U;
PdbAdcPreTriggerConfig.preTriggerEnable = true;
PdbAdcPreTriggerConfig.preTriggerOutputEnable = true;
PdbAdcPreTriggerConfig.preTriggerBackToBackEnable = false;
PDB_DRV_ConfigAdcPreTrigger(instance, 0U, &PdbAdcPreTriggerConfig);
PDB_DRV_SetTimerModulusValue(instance, 0xFFFU);
PDB_DRV_SetAdcPreTriggerDelayValue(instance, 0U, 0U, 0xFFU);
while (1U != PDB_DRV_GetAdcPreTriggerFlags(instance, 0U, 1U)) {}
PRINTF("PDB ADC PreTrigger generated.\r\n");
PDB_DRV_Deinit(instance);
PRINTF("OK.\r\n");
}

Data Structures

struct  pdb_adc_pretrigger_config_t
 Defines the type of structure for configuring ADC's pre_trigger. More...
 

Functions

pdb_status_t PDB_DRV_Init (uint32_t instance, const pdb_timer_config_t *userConfigPtr)
 Initializes the PDB counter and triggers input. More...
 
pdb_status_t PDB_DRV_Deinit (uint32_t instance)
 Deinitializes the PDB module. More...
 
void PDB_DRV_SoftTriggerCmd (uint32_t instance)
 Triggers the PDB with a software trigger. More...
 
uint32_t PDB_DRV_GetTimerValue (uint32_t instance)
 Gets the current counter value in the PDB module. More...
 
bool PDB_DRV_GetTimerIntFlag (uint32_t instance)
 Gets the PDB interrupt flag. More...
 
void PDB_DRV_ClearTimerIntFlag (uint32_t instance)
 Clears the interrupt flag. More...
 
void PDB_DRV_LoadValuesCmd (uint32_t instance)
 Executes the command of loading values. More...
 
void PDB_DRV_SetTimerModulusValue (uint32_t instance, uint32_t value)
 Sets the value of timer modulus. More...
 
void PDB_DRV_SetValueForTimerInterrupt (uint32_t instance, uint32_t value)
 Sets the value for the timer interrupt. More...
 
pdb_status_t PDB_DRV_ConfigAdcPreTrigger (uint32_t instance, uint32_t chn, const pdb_adc_pretrigger_config_t *configPtr)
 Configures the ADC pre_trigger in the PDB module. More...
 
uint32_t PDB_DRV_GetAdcPreTriggerFlags (uint32_t instance, uint32_t chn, uint32_t preChnMask)
 Gets the ADC pre_trigger flag in the PDB module. More...
 
void PDB_DRV_ClearAdcPreTriggerFlags (uint32_t instance, uint32_t chn, uint32_t preChnMask)
 Clears the ADC pre_trigger flag in the PDB module. More...
 
uint32_t PDB_DRV_GetAdcPreTriggerSeqErrFlags (uint32_t instance, uint32_t chn, uint32_t preChnMask)
 Gets the ADC pre_trigger flag in the PDB module. More...
 
void PDB_DRV_ClearAdcPreTriggerSeqErrFlags (uint32_t instance, uint32_t chn, uint32_t preChnMask)
 Clears the ADC pre_trigger flag in the PDB module. More...
 
void PDB_DRV_SetAdcPreTriggerDelayValue (uint32_t instance, uint32_t chn, uint32_t preChn, uint32_t value)
 Sets the ADC pre_trigger delay value in the PDB module. More...
 
void PDB_DRV_SetCmpPulseOutEnable (uint32_t instance, uint32_t pulseChnMask, bool enable)
 Switches on/off the CMP pulse out in the PDB module. More...
 
void PDB_DRV_SetCmpPulseOutDelayForHigh (uint32_t instance, uint32_t pulseChn, uint32_t value)
 Sets the CMP pulse out delay value for high in the PDB module. More...
 
void PDB_DRV_SetCmpPulseOutDelayForLow (uint32_t instance, uint32_t pulseChn, uint32_t value)
 Sets the CMP pulse out delay value for low in the PDB module. More...
 

Variables

PDB_Type *const g_pdbBase []
 Table of base addresses for PDB instances. More...
 
const IRQn_Type g_pdbIrqId [PDB_INSTANCE_COUNT]
 Table to save PDB IRQ enumeration numbers defined in the CMSIS header file. More...
 

Data Structure Documentation

struct pdb_adc_pretrigger_config_t

Data Fields

uint32_t adcPreTriggerIdx
 Setting pre_trigger's index.
 
bool preTriggerEnable
 Enables the pre_trigger.
 
bool preTriggerOutputEnable
 Enables the pre_trigger output.
 
bool preTriggerBackToBackEnable
 Enables the back to back mode for ADC pre_trigger.
 

Function Documentation

pdb_status_t PDB_DRV_Init ( uint32_t  instance,
const pdb_timer_config_t userConfigPtr 
)

This function initializes the PDB counter and triggers the input. It resets PDB registers and enables the PDB clock. Therefore, it should be called before any other operation. After it is initialized, the PDB can act as a triggered timer, which enables other features in PDB module.

Parameters
instancePDB instance ID.
userConfigPtrPointer to the user configuration structure. See the "pdb_user_config_t".
Returns
Execution status.
pdb_status_t PDB_DRV_Deinit ( uint32_t  instance)

This function deinitializes the PDB module. Calling this function shuts down the PDB module and reduces the power consumption.

Parameters
instancePDB instance ID.
Returns
Execution status.
void PDB_DRV_SoftTriggerCmd ( uint32_t  instance)

This function triggers the PDB with a software trigger. When the PDB is set to use the software trigger as input, calling this function triggers the PDB.

Parameters
instancePDB instance ID.
uint32_t PDB_DRV_GetTimerValue ( uint32_t  instance)

This function gets the current counter value.

Parameters
instancePDB instance ID.
Returns
Current PDB counter value.
bool PDB_DRV_GetTimerIntFlag ( uint32_t  instance)

This function gets the PDB interrupt flag. It is asserted if the PDB interrupt occurs.

Parameters
instancePDB instance ID.
Returns
Assertion of indicated event.
void PDB_DRV_ClearTimerIntFlag ( uint32_t  instance)

This function clears the interrupt flag.

Parameters
instancePDB instance ID.
void PDB_DRV_LoadValuesCmd ( uint32_t  instance)

This function executes the command of loading values.

Parameters
instancePDB instance ID.
valueSetting value.
void PDB_DRV_SetTimerModulusValue ( uint32_t  instance,
uint32_t  value 
)

This function sets the value of timer modulus.

Parameters
instancePDB instance ID.
valueSetting value.
void PDB_DRV_SetValueForTimerInterrupt ( uint32_t  instance,
uint32_t  value 
)

This function sets the value for the timer interrupt.

Parameters
instancePDB instance ID.
valueSetting value.
pdb_status_t PDB_DRV_ConfigAdcPreTrigger ( uint32_t  instance,
uint32_t  chn,
const pdb_adc_pretrigger_config_t configPtr 
)

This function configures the ADC pre_trigger in the PDB module.

Parameters
instancePDB instance ID.
chnADC channel.
configPtrPointer to the user configuration structure. See the "pdb_adc_pretrigger_config_t".
Returns
Execution status.
uint32_t PDB_DRV_GetAdcPreTriggerFlags ( uint32_t  instance,
uint32_t  chn,
uint32_t  preChnMask 
)

This function gets the ADC pre_trigger flags in the PDB module.

Parameters
instancePDB instance ID.
chnADC channel.
preChnMaskADC pre_trigger channels mask.
Returns
Assertion of indicated flag.
void PDB_DRV_ClearAdcPreTriggerFlags ( uint32_t  instance,
uint32_t  chn,
uint32_t  preChnMask 
)

This function clears the ADC pre_trigger flags in the PDB module.

Parameters
instancePDB instance ID.
chnADC channel.
preChnMaskADC pre_trigger channels mask.
uint32_t PDB_DRV_GetAdcPreTriggerSeqErrFlags ( uint32_t  instance,
uint32_t  chn,
uint32_t  preChnMask 
)

This function gets the ADC pre_trigger flags in the PDB module.

Parameters
instancePDB instance ID.
chnADC channel.
preChnMaskADC pre_trigger channels mask.
Returns
Assertion of indicated flag.
void PDB_DRV_ClearAdcPreTriggerSeqErrFlags ( uint32_t  instance,
uint32_t  chn,
uint32_t  preChnMask 
)

This function clears the ADC pre_trigger sequence error flags in the PDB module.

Parameters
instancePDB instance ID.
chnADC channel.
preChnMaskADC pre_trigger channels mask.
void PDB_DRV_SetAdcPreTriggerDelayValue ( uint32_t  instance,
uint32_t  chn,
uint32_t  preChn,
uint32_t  value 
)

This function sets Set the ADC pre_trigger delay value in the PDB module.

Parameters
instancePDB instance ID.
chnADC channel.
preChnADC pre_channel.
valueSetting value.
void PDB_DRV_SetCmpPulseOutEnable ( uint32_t  instance,
uint32_t  pulseChnMask,
bool  enable 
)

This function switches the CMP pulse on/off in the PDB module.

Parameters
instancePDB instance ID.
pulseChnMaskPulse channel mask.
enableSwitcher to assert the feature.
void PDB_DRV_SetCmpPulseOutDelayForHigh ( uint32_t  instance,
uint32_t  pulseChn,
uint32_t  value 
)

This function sets the CMP pulse out delay value for high in the PDB module.

Parameters
instancePDB instance ID.
pulseChnPulse channel.
valueSetting value.
void PDB_DRV_SetCmpPulseOutDelayForLow ( uint32_t  instance,
uint32_t  pulseChn,
uint32_t  value 
)

This function sets the CMP pulse out delay value for low in the PDB module.

Parameters
instancePDB instance ID.
pulseChnPulse channel.
valueSetting value.

Variable Documentation

PDB_Type* const g_pdbBase[]
const IRQn_Type g_pdbIrqId[PDB_INSTANCE_COUNT]