PDM
概述
PDM 是对连续变化的模拟信号进行抽样、量化和编码产生的数字信号的信号调制方式。
PDM 通过合适的算法将典型的 24 比特的脉冲编码调制(Pulse Code Modulation,PCM)信号转换为 1 比特的音频信号,其为 1 位数字采样的高频数据流,脉冲的相对密度对应于模拟信号的幅度。原理图如下:
PDM SAMPLE 架构图
在 PDM 信号中,脉冲的相对密度对应于模拟信号的幅度。大量的 ‘1’ 对应于高(正)幅度值,而大量的 ‘0’ 对应于低(负)幅度值,交替的 ‘1’ 与 ‘0’ 对应于幅度值 ‘0’。
WQ7036 有 4 个 PDM Rx 模块和 1 个 PDM Tx 模块,支持最多 4 对(或 8 路)1 比特 PDM 格式数字信号输入和 1 对(或 2 路)1 比特 PDM 格式数字信号输出。每个 PDM 模块可以工作在不同时钟。
功能特性
PDM 模块特性如下:
支持双声道数据输入/输出,即上升沿(左声道),下降沿(右声道)。
支持 Tx/Rx 配置成 master 或者 slave。
master 模式下,输出时钟为 audio 工作时钟整数倍分频。
支持输入/输出数据时延配置(0~3 拍)。
支持 Tx/Rx 独立运行。
支持 4 MHz、3.2 MHz、2 MHz、1 MHz 等采样率(audio 工作时钟为 16 MHz)。
支持 3.84 MHz、3.072 MHz、1.92 MHz、1.56 MHz、0.96 MHz 等采样率(audio 工作时钟为 15.36 MHz)。
PDM RX 架构
PDM RX 的架构图如下图所示。
PDM RX 架构图
一个 PDM Rx 模块可以支持两路 PDM 数据传输和单路 PDM 数据传输:
两路数据传输时,在时钟上升沿和下降沿进行数据分离,得到两路独立的数字信号,再分别进行下采样和滤波处理,得到多比特高精度音频信号。
单路数据传输时,在任意时钟沿(上升沿或下降沿)提取数据,再分别进行下采样和滤波处理,得到多比特高精度音频信号。
WQ7036 最大支持 8 路 PDM MIC 数据输入。
PDM TX 架构
PDM TX 架构图如下图所示。
PDM TX 架构图
WQ7036 支持两路 PDM 数据输出。两路 PCM 数据经过上采样和滤波等处理之后,经过 PDM Tx 模块得到两路 1 比特数字信号,在时钟上升沿和下降沿合并两路 1 比特数字信号,并输出到芯片 GPIO 管脚。
API 介绍
This section introduces the PDM module's enum, structure, functions and how to use this driver.
-
struct wq_pdm_gpio_cfg
Public Members
-
WQ_GPIO_ID clk
The gpio id used by pdm clk
-
WQ_GPIO_ID sd
The gpio id used by pdm data
-
WQ_GPIO_ID clk
-
struct wq_pdm_cfg
Public Members
-
WQ_PDM_FREQ_SAMPLE pdm_bck
PDM sample rate
-
bool pdm_slave
Is PDM in slave mode? True indicates slave mode, false indicates master mode
-
uint8_t pdm_phase
Value range 0~3, phase control achieved by controlling the delay of data sampling
-
wq_pdm_gpio_cfg_t pdm_gpio_cfg
GPIO configuration used by PDM
-
WQ_PDM_FREQ_SAMPLE pdm_bck
-
struct wq_pdm_rx_chn_cfg
Public Members
-
wq_rx_dfe_config_t dfe_cfg
Rxdfe receives pdm rx data, which is the relevant configuration of Rxdfe
-
WQ_AUDIO_TIMER_ID timer_id
Audio timer iid used by PDM RX
-
wq_rx_dfe_config_t dfe_cfg
-
union wq_pdm_rx_en
-
struct wq_pdm_rx_analog_param
Public Members
-
wq_pdm_rx_en_t pdm_en
PDM_RX MODULE enable bitmap
-
wq_mic_adc_micbias_u micbias
Micbias configuration corresponding to PDM RX module
-
wq_mic_adc_micbias_voltage_u micbias_voltage
Micbias voltage configuration corresponding to PDM RX module
-
wq_pdm_rx_en_t pdm_en
Typedefs
-
typedef enum _WQ_PDM_PORT WQ_PDM_PORT
For specific definitions, please refer to the header file wq_audio_resource.h.
-
typedef enum _WQ_PDM_RX_CHANNEL WQ_PDM_RX_CHANNEL
For specific definitions, please refer to the header file wq_audio_resource.h.
-
typedef enum _WQ_PDM_FREQ_SAMPLE WQ_PDM_FREQ_SAMPLE
For specific definitions, please refer to the header file wq_audio_resource.h.
-
typedef enum _WQ_PDM_TX_CHANNEL WQ_PDM_TX_CHANNEL
For specific definitions, please refer to the header file wq_audio_resource.h.
-
typedef struct wq_pdm_gpio_cfg wq_pdm_gpio_cfg_t
For specific definitions, please refer to the header file wq_pdm.h.
-
typedef struct wq_pdm_cfg wq_pdm_cfg_t
For specific definitions, please refer to the header file wq_pdm.h.
-
typedef struct wq_pdm_rx_chn_cfg wq_pdm_rx_chn_cfg_t
For specific definitions, please refer to the header file wq_pdm.h.
-
typedef union wq_pdm_rx_en wq_pdm_rx_en_t
For specific definitions, please refer to the header file wq_pdm.h.
-
typedef struct wq_pdm_rx_analog_param wq_pdm_rx_analog_param_t
For specific definitions, please refer to the header file wq_pdm.h.
Functions
-
WQ_RET wq_pdm_rx_init(void)
This function is to initialize pdm rx.
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_pdm_rx_deinit(void)
This function is to deinitialize pdm rx.
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_pdm_tx_init(void)
This function is to initialize pdm tx.
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_pdm_tx_deinit(void)
This function is to deinitialize pdm tx.
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_rx_pdm_open(WQ_PDM_PORT port, WQ_PDM_RX_CHANNEL chn, const wq_pdm_cfg_t *pdm_cfg)
Open pdm rx and configure the hardware of pdm rx.
- 参数:
port -- pdm rx port
chn -- pdm rx channel
pdm_cfg -- the configuration of the selected pdm rx
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_rx_pdm_close(WQ_PDM_PORT port, WQ_PDM_RX_CHANNEL chn, const wq_pdm_gpio_cfg_t *pdm_gpio_cfg)
Close pdm rx and disable corresponding hardware.
- 参数:
port -- pdm rx port
chn -- pdm rx channel
pdm_gpio_cfg -- gpio configuration corresponding to pdm rx
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_rx_pdm_micbias_start(const wq_pdm_rx_analog_param_t *param)
Start pdm rx micbias.
- 参数:
param -- pdm mic and micbias parameter config
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_rx_pdm_micbias_stop(const wq_pdm_rx_analog_param_t *param)
Stop pdm rx micbias.
- 参数:
param -- pdm mic and micbias parameter config
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_rx_pdm_start(WQ_PDM_RX_CHANNEL chn, const wq_pdm_rx_chn_cfg_t *cfg)
Start pdm rx.
- 参数:
chn -- pdm rx channel
cfg -- pdm rx channels config
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_rx_pdm_stop(WQ_PDM_RX_CHANNEL chn)
Stop pdm rx.
- 参数:
chn -- pdm rx channel
- 返回:
WQ_RET_OK - success, other - failed
-
void wq_rx_pdm_data_start(WQ_PDM_RX_CHANNEL chn)
Trigger adc data for pdm rx.
- 参数:
chn -- pdm rx channel
-
WQ_RET wq_rx_pdm_gain_set(WQ_PDM_RX_CHANNEL chn, int16_t gain)
Set pdm rx gain, the gain pre step is 0.1875dB.
- 参数:
chn -- : pdm rx channel
gain -- target gain
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_rx_pdm_sample_rate_set(WQ_PDM_RX_CHANNEL chn, uint32_t out_fs, bool less_delay_mode_en)
Set pdm rx sample rate.
备注
Please call this interface after PDM open, and before RX-FIFO link. If set the sample rate after PDM started, some dirty data should be discarded, it is recommended to discard no less than 10 sample points.
- 参数:
chn -- pdm rx channel
out_fs -- Output sample rate
less_delay_mode_en -- Less delay mode enable
- 返回:
WQ_RET_OK - success, other - failed
-
uint32_t wq_rx_pdm_get_chn_clk(uint8_t chn)
Get the rx dfe clk corresponding to pdm.
- 参数:
chn -- is pdm rx channel
- 返回:
uint32_t return clk
-
WQ_RET wq_tx_pdm_open(const wq_tx_dfe_digtal_config_t *dfe_cfg, const wq_pdm_cfg_t *pdm_cfg)
This function is to open pdm tx and digital part of corresponding tx dfe. and does not work with output as spk.
- 参数:
dfe_cfg -- is txdfe configuration.
pdm_cfg -- is pdm tx configuration.
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_tx_pdm_close(WQ_PDM_TX_CHANNEL chn, const wq_pdm_gpio_cfg_t *pdm_gpio_cfg)
This function is to clsoe tx pdm and corresponding tx dfe.
- 参数:
chn -- is pdm tx channel
pdm_gpio_cfg -- is pdm gpio configuration.
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_tx_pdm_start(WQ_PDM_TX_CHANNEL chn)
This function is to start pdm tx and corresponding tx dfe.
- 参数:
chn -- is pdm tx channel
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_tx_pdm_stop(WQ_PDM_TX_CHANNEL chn)
This function is to stop pdm tx and corresponding tx dfe.
- 参数:
chn -- is pdm tx channel
- 返回:
WQ_RET_OK - success, other - failed