PDM - Pulse Density Modulation#
Pulse Density Modulation (PDM) peripheral API.
PDM API functions provide full support for the PDM peripheral. The PDM peripheral accepts PDM bitstreams and produces PCM encoded output.
The following is an example PDM usage when interfacing to two PDM microphones:
Configure clocks and GPIO pins:
PDM_Init_TypeDef pdmInit = PDM_INIT_DEFAULT;
CMU_DPLLInit_TypeDef pllInit = CMU_DPLL_LFXO_TO_40MHZ;
CMU_OscillatorEnable(cmuOsc_LFXO, true, true);
// Lock PLL to 1,411,209 Hz to achieve 44,100 kHz PCM sampling rate
// when using 32x PDM oversampling
pllInit.frequency = 1411209;
pllInit.m = 14;
pllInit.n = 645;
CMU_DPLLLock(&pllInit);
// Setup all GPIO's.
GPIO_PinModeSet(MIC_CLK_PORT, MIC_CLK_PIN, gpioModePushPull, 0);
GPIO_PinModeSet(MIC_DATA_PORT, MIC_DATA_PIN, gpioModeInput, 0);
// Set fast slew rate on PDM mic CLK and DATA pins
GPIO_SlewrateSet(MIC_CLK_PORT, 7U, 7U);
// Enable PDM peripheral clock.
CMU_ClockEnable(cmuClock_PDM, true);
// Select PDM reference clock source and enable it.
CMU_ClockSelectSet(cmuClock_PDMREF, cmuSelect_HFRCO);
CMU_ClockEnable(cmuClock_PDMREF, true);
// Route PDM signals to correct GPIO's.
PDM->ROUTELOC0 = (PDM->ROUTELOC0 & ~_PDM_ROUTELOC0_DAT0LOC_MASK)
| (MIC_DATA_PDM_LOC << _PDM_ROUTELOC0_DAT0LOC_SHIFT);
PDM->ROUTELOC1 = MIC_CLK_PDM_LOC << _PDM_ROUTELOC1_CLKLOC_SHIFT;
PDM->ROUTEPEN |= PDM_ROUTEPEN_CLKPEN | PDM_ROUTEPEN_DAT0PEN;
Initialize and start PDM, then read PCM samples from FIFO:
PDM_Init_TypeDef init = PDM_INIT_DEFAULT;
PDM_Init(PDM, &init);
while (true) {
*pBuffer++ = PDM_Rx(PDM);
}
Modules#
Enumerations#
Configure CH1 CLK Polarity.
Configure CH0 CLK Polarity.
Configure FIFO Data valid level water-mark.
Configure PDM filter data output format.
Configure number of PDM channels.
Configure order of the PDM filter.
Functions#
De-initialize the PDM peripheral.
Initialize the PDM peripheral.
Initialize PDM registers with reset values.
Clear the PDM filter.
Flush the PDM sample FIFO.
Clear one or more pending PDM interrupts.
Disable one or more PDM interrupts.
Enable one or more PDM interrupts.
Get pending PDM interrupt flags.
Get enabled and pending PDM interrupt flags.
Set one or more pending PDM interrupts.
Read one entry from the PDM FIFO.
Start the PDM operation (start the PDM filter).
Get the PDM STATUS register.
Stop the PDM operation (stop the PDM filter).
Macros#
Default configuration for PDM.
Enumeration Documentation#
PDM_Ch1ClkPolarity_Typedef#
PDM_Ch1ClkPolarity_Typedef
Configure CH1 CLK Polarity.
Enumerator | |
---|---|
pdmCh1ClkPolarityRisingEdge | Input data clocked on rising clock edge. |
pdmCh1ClkPolarityFallingEdge | Input data clocked on falling clock edge. |
121
of file platform/emlib/inc/em_pdm.h
PDM_Ch0ClkPolarity_Typedef#
PDM_Ch0ClkPolarity_Typedef
Configure CH0 CLK Polarity.
Enumerator | |
---|---|
pdmCh0ClkPolarityRisingEdge | Input data clocked on rising clock edge. |
pdmCh0ClkPolarityFallingEdge | Input data clocked on falling clock edge. |
127
of file platform/emlib/inc/em_pdm.h
PDM_FifoValidWatermark_Typedef#
PDM_FifoValidWatermark_Typedef
Configure FIFO Data valid level water-mark.
Enumerator | |
---|---|
pdmFifoValidWatermarkOne | At least one word. |
pdmFifoValidWatermarkTwo | Two words. |
pdmFifoValidWatermarkThree | Three words. |
pdmFifoValidWatermarkFour | Four words. |
133
of file platform/emlib/inc/em_pdm.h
PDM_DataFormat_TypeDef#
PDM_DataFormat_TypeDef
Configure PDM filter data output format.
Enumerator | |
---|---|
pdmDataFormatRight16 | Right aligned 16-bit, left bits are sign extended. |
pdmDataFormatDouble16 | Pack two 16-bit samples into one 32-bit word. |
pdmDataFormatRight24 | Right aligned 24bit, left bits are sign extended. |
pdmDataFormatFull32bit | 32 bit data. |
pdmDataFormatLeft16 | Left aligned 16-bit, right bits are zeros. |
pdmDataFormatLeft24 | Left aligned 24-bit, right bits are zeros. |
pdmDataFormatRaw32bit | RAW 32 bit data from integrator. |
141
of file platform/emlib/inc/em_pdm.h
PDM_NumberOfChannels_TypeDef#
PDM_NumberOfChannels_TypeDef
Configure number of PDM channels.
Enumerator | |
---|---|
pdmNumberOfChannelsOne | Only one Channel. |
pdmNumberOfChannelsTwo | Two Channels. |
152
of file platform/emlib/inc/em_pdm.h
PDM_FilterOrder_TypeDef#
PDM_FilterOrder_TypeDef
Configure order of the PDM filter.
Enumerator | |
---|---|
pdmFilterOrderSecond | Second order filter. |
pdmFilterOrderThird | Third order filter. |
pdmFilterOrderFourth | Fourth order filter. |
pdmFilterOrderFifth | Fifth order filter. |
162
of file platform/emlib/inc/em_pdm.h
Function Documentation#
PDM_DeInit#
void PDM_DeInit (PDM_TypeDef * pdm)
De-initialize the PDM peripheral.
[in] | pdm | A pointer to the PDM peripheral register block. |
This function will stop the PDM filter and set PDM control registers to their reset values.
52
of file platform/emlib/src/em_pdm.c
PDM_Init#
void PDM_Init (PDM_TypeDef * pdm, const PDM_Init_TypeDef * init)
Initialize the PDM peripheral.
[in] | pdm | A pointer to the PDM peripheral register block. |
[in] | init | A pointer to the initialization structure used to configure the PDM. |
This function will configure basic settings in PDM according to values in the initialization data structure.
Notice that enabling of PDM clock, setup of PDM pins and setup of PRS is not covered by this function.
77
of file platform/emlib/src/em_pdm.c
PDM_Reset#
void PDM_Reset (PDM_TypeDef * pdm)
Initialize PDM registers with reset values.
[in] | pdm | A pointer to the PDM peripheral register block. |
134
of file platform/emlib/src/em_pdm.c
PDM_Clear#
void PDM_Clear (PDM_TypeDef * pdm)
Clear the PDM filter.
[in] | pdm | A pointer to the PDM peripheral register block. |
257
of file platform/emlib/inc/em_pdm.h
PDM_FifoFlush#
void PDM_FifoFlush (PDM_TypeDef * pdm)
Flush the PDM sample FIFO.
[in] | pdm | A pointer to the PDM peripheral register block. |
272
of file platform/emlib/inc/em_pdm.h
PDM_IntClear#
void PDM_IntClear (PDM_TypeDef * pdm, uint32_t flags)
Clear one or more pending PDM interrupts.
[in] | pdm | A pointer to the PDM peripheral register block. |
[in] | flags | Pending PDM interrupt sources to clear. Use one or more valid interrupt flags for the PDM module. The flags are PDM_IFC_DV, PDM_IFC_DVL, PDM_IFC_OF and PDM_IFC_UF. |
292
of file platform/emlib/inc/em_pdm.h
PDM_IntDisable#
void PDM_IntDisable (PDM_TypeDef * pdm, uint32_t flags)
Disable one or more PDM interrupts.
[in] | pdm | A pointer to the PDM peripheral register block. |
[in] | flags | PDM interrupt sources to disable. Use one or more valid interrupt flags for the PDM module. The flags are PDM_IEN_DV, PDM_IEN_DVL, PDM_IEN_OF and PDM_IEN_UF. |
313
of file platform/emlib/inc/em_pdm.h
PDM_IntEnable#
void PDM_IntEnable (PDM_TypeDef * pdm, uint32_t flags)
Enable one or more PDM interrupts.
[in] | pdm | A pointer to the PDM peripheral register block. |
[in] | flags | PDM interrupt sources to enable. Use one or more valid interrupt flags for the PDM module. The flags are PDM_IEN_DV, PDM_IEN_DVL, PDM_IEN_OF and PDM_IEN_UF. |
Note
Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. To ignore a pending interrupt, consider using PDM_IntClear() prior to enabling the interrupt.
335
of file platform/emlib/inc/em_pdm.h
PDM_IntGet#
uint32_t PDM_IntGet (PDM_TypeDef * pdm)
Get pending PDM interrupt flags.
[in] | pdm | A pointer to the PDM peripheral register block. |
Note
Event bits are not cleared by the use of this function.
Returns
PDM interrupt sources pending. Returns one or more valid interrupt flags for PDM module. The flags are PDM_IF_DV, PDM_IF_DVL, PDM_IF_OF and PDM_IF_UF.
355
of file platform/emlib/inc/em_pdm.h
PDM_IntGetEnabled#
uint32_t PDM_IntGetEnabled (PDM_TypeDef * pdm)
Get enabled and pending PDM interrupt flags.
[in] | pdm | A pointer to the PDM peripheral register block. |
Useful for handling more interrupt sources in the same interrupt handler.
Note
Interrupt flags are not cleared by the use of this function.
Returns
Pending and enabled PDM interrupt sources Return value is the bitwise AND of
the enabled interrupt sources in PDM_IEN and
the pending interrupt flags PDM_IF
377
of file platform/emlib/inc/em_pdm.h
PDM_IntSet#
void PDM_IntSet (PDM_TypeDef * pdm, uint32_t flags)
Set one or more pending PDM interrupts.
[in] | pdm | A pointer to the PDM peripheral register block. |
[in] | flags | PDM interrupt sources to set to pending. Use one or more valid interrupt flags for the PDM module. The flags are PDM_IFS_DV, PDM_IFS_DVL, PDM_IFS_OF and PDM_IFS_UF. |
397
of file platform/emlib/inc/em_pdm.h
PDM_Rx#
uint32_t PDM_Rx (PDM_TypeDef * pdm)
Read one entry from the PDM FIFO.
[in] | pdm | A pointer to the PDM peripheral register block. |
Note
This function will wait until a sample is available in the FIFO. Depending on PDM configuration, a FIFO entry can consist of one or two samples.
Returns
The entry read from the FIFO.
421
of file platform/emlib/inc/em_pdm.h
PDM_Start#
void PDM_Start (PDM_TypeDef * pdm)
Start the PDM operation (start the PDM filter).
[in] | pdm | A pointer to the PDM peripheral register block. |
436
of file platform/emlib/inc/em_pdm.h
PDM_StatusGet#
uint32_t PDM_StatusGet (PDM_TypeDef * pdm)
Get the PDM STATUS register.
[in] | pdm | A pointer to the PDM peripheral register block. |
Returns
STATUS register value.
454
of file platform/emlib/inc/em_pdm.h
PDM_Stop#
void PDM_Stop (PDM_TypeDef * pdm)
Stop the PDM operation (stop the PDM filter).
[in] | pdm | A pointer to the PDM peripheral register block. |
466
of file platform/emlib/inc/em_pdm.h
Macro Definition Documentation#
PDM_INIT_DEFAULT#
#define PDM_INIT_DEFAULTValue:
Default configuration for PDM.
Stereo Ch0/1, 16bit samples, 44,100 Hz sampling rate, 32 times oversampling (requires 1,411,209 Hz PDM clock).
226
of file platform/emlib/inc/em_pdm.h