PSoC 6 Peripheral Driver Library
PDM_PCM (PDM-PCM Converter)

General Description

The pulse-density modulation to pulse-code modulation (PDM-PCM) driver provides an API to manage PDM-PCM conversion.

A PDM-PCM converter is used to convert 1-bit digital audio streaming data to PCM data.

The functions and other declarations used in this driver are in cy_pdm_pcm.h. You can include cy_pdl.h to get access to all functions and declarations in the PDL.


Pulse-density modulation, or PDM, represents an analog signal with a binary signal. In a PDM signal, specific amplitude values are not encoded into codewords of pulses of different weight as they would be in pulse-code modulation (PCM); rather, the relative density of the pulses corresponds to the analog signal's amplitude. The output of a 1-bit DAC is the same as the PDM encoding of the signal.

Pulse-code modulation (PCM) is the method used to digitally represent sampled analog signals. It is the standard form of digital audio in computers, compact discs, digital telephony, and other digital audio applications. In a PCM stream, the amplitude of the analog signal is sampled regularly at uniform intervals, and each sample is quantized to the nearest value within a range of digital steps.

Configuration Considerations

To set up a PDM-PCM, provide the configuration parameters in the cy_stc_pdm_pcm_config_t structure.

For example, set dataStreamingEnable to true, configure rxFifoTriggerLevel, dmaTriggerEnable (depending on whether DMA is going to be used), provide clock settings (clkDiv, mclkDiv and ckoDiv), set sincDecRate to the appropriate decimation rate, wordLen, and wordBitExtension. No other parameters are necessary for this example.

To initialize the PDM-PCM block, call the Cy_PDM_PCM_Init function, providing the filled cy_stc_pdm_pcm_config_t structure.

If you use a DMA, the DMA channel should be previously configured. PDM-PCM interrupts (if applicable) can be enabled by calling Cy_PDM_PCM_SetInterruptMask.

For example, if the trigger interrupt is used during operation, the ISR should call the Cy_PDM_PCM_ReadFifo as many times as required for your FIFO payload. Then call Cy_PDM_PCM_ClearInterrupt with appropriate parameters.

If a DMA is used and the DMA channel is properly configured, no CPU activity (or application code) is needed for PDM-PCM operation.

More Information

See: the PDM-PCM chapter of the device technical reference manual (TRM); the PDM_PCM_PDL Component datasheet; CE219431 - PSOC 6 MCU PDM-TO-PCM EXAMPLE.

MISRA-C Compliance

The PDM-PCM driver has the following specific deviations:

MISRA Rule Rule Class (Required/Advisory) Rule Description Description of Deviation(s)
10.3 R A composite expression of the "essentially unsigned" type is cast to a different type category. The value got from the bitfield physically can't exceed the enumeration that describes this bitfield. So the code is safe by design.
11.4 A A cast should not be performed between a pointer to the object type and a different pointer to the object type. The function Cy_PDM_PCM_DeepSleepCallback is a callback of cy_en_syspm_status_t type. The cast operation safety in this function becomes the user responsibility because the pointer is initialized when a callback is registered in SysPm driver.


VersionChangesReason for Change
2.20.2 Minor documentation updates. Documentation enhancement.
2.20.1 Snippet updated. Old snippet outdated.
2.20 Flattened the organization of the driver source code into the single source directory and the single include directory. Driver library directory-structure simplification.
Added register access layer. Use register access macros instead of direct register access using dereferenced pointers. Makes register access device-independent, so that the PDL does not need to be recompiled for each supported part number.
2.10 The gain values in range +4.5...+10.5dB (5 items) of /ref cy_en_pdm_pcm_gain_t are corrected. Added Low Power Callback section. Incorrect setting of gain values in limited range. Documentation update and clarification.

Enumeration types for gain and soft mute cycles are added.
Function parameter checks are added.
The next functions are removed:

  • Cy_PDM_PCM_EnterLowPowerCallback
  • Cy_PDM_PCM_ExitLowPowerCallback
  • Cy_PDM_PCM_EnableDataStream
  • Cy_PDM_PCM_DisableDataStream
  • Cy_PDM_PCM_SetFifoLevel
  • Cy_PDM_PCM_GetFifoLevel
  • Cy_PDM_PCM_EnableDmaRequest
  • Cy_PDM_PCM_DisableDmaRequest

The next functions behaviour are modified:

  • Cy_PDM_PCM_Enable
  • Cy_PDM_PCM_Disable
  • Cy_PDM_PCM_SetInterruptMask
  • Cy_PDM_PCM_GetInterruptMask
  • Cy_PDM_PCM_GetInterruptStatusMasked
  • Cy_PDM_PCM_GetInterruptStatus
  • Cy_PDM_PCM_ClearInterrupt
  • Cy_PDM_PCM_SetInterrupt

The Cy_PDM_PCM_GetFifoNumWords function is renamed to Cy_PDM_PCM_GetNumInFifo.
The Cy_PDM_PCM_GetCurrentState function is added.

Improvements based on usability feedbacks.
API is reworked for consistency within the PDL.
1.0 Initial version

API Reference

 Data Structures
 Enumerated Types