![]() |
RA Flexible Software Package Documentation
Release v6.0.0
|
|
Functions | |
fsp_err_t | R_PDM_Open (pdm_ctrl_t *const p_ctrl, pdm_cfg_t const *const p_cfg) |
fsp_err_t | R_PDM_Start (pdm_ctrl_t *const p_ctrl, void *const p_buffer, size_t const buffer_size, uint32_t const number_of_data_to_callback) |
fsp_err_t | R_PDM_Stop (pdm_ctrl_t *const p_ctrl) |
fsp_err_t | R_PDM_SoundDetectionEnable (pdm_ctrl_t *const p_ctrl, pdm_sound_detection_setting_t sound_detection_setting) |
fsp_err_t | R_PDM_SoundDetectionDisable (pdm_ctrl_t *const p_ctrl) |
fsp_err_t | R_PDM_Read (pdm_ctrl_t *const p_ctrl, void *const p_dest, uint32_t const bytes) |
fsp_err_t | R_PDM_StatusGet (pdm_ctrl_t *const p_ctrl, pdm_status_t *const p_status) |
fsp_err_t | R_PDM_Close (pdm_ctrl_t *const p_ctrl) |
fsp_err_t | R_PDM_CallbackSet (pdm_ctrl_t *const p_ctrl, void(*p_callback)(pdm_callback_args_t *), void *const p_context, pdm_callback_args_t *const p_callback_memory) |
Driver for the PDM peripheral on RA MCUs. This module implements the PDM Interface.
The Pulse Density Modulation Interface (PDM-IF) has channels that are connectable with external microphone which outputs the pulse density modulated signal. PDM-IF can filter and convert 1-bit digital data streams that were pulse density modulated at a high sampling rate into 20-bit or 16-bit digital data at a lower sampling rate.
Configuration | Options | Default | Description |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
DMAC Support |
| Disabled | If enabled code for DMAC transfer support is included in the build. |
Configuration | Options | Default | Description |
---|---|---|---|
Input | |||
Edge |
| Rising | Select the edge of input audio data. |
PDM_CLK Frequency | Refer to the RA Configuration tool for available options. | module.driver.pdm.clock_div.clock_div_2 | Select PDM_CLK Frequency (Hz). |
Output | |||
Bit Format |
| module.driver.pdm.pcm_width.pcm_width_20bits_0_18 | Select the bit format of the PCM data stored into the data FIFO. |
Target Sampling Frequency (Hz) | Manual Entry | 32000 | Select Target sampling Frequency (Hz). |
Filter | |||
Filter > Low-pass Filter | |||
Low-pass Filter Input Shift |
| No shift | Select the low-pass (half-band decimation) filter input shift setting. |
LPF Coefficient h0(10) | Value must be an integer between 0x0000 and 0x1FFF | 0x0400 | Specify the Low-Pass Filter Coefficient h0(10) |
LPF Coefficient h1(0) | Value must be an integer between 0x0000 and 0x1FFF | 0x1FF8 | Specify the Low-Pass Filter Coefficient h1(0) |
LPF Coefficient h1(1) | Value must be an integer between 0x0000 and 0x1FFF | 0x000A | Specify the Low-Pass Filter Coefficient h1(1) |
LPF Coefficient h1(2) | Value must be an integer between 0x0000 and 0x1FFF | 0x1FF0 | Specify the Low-Pass Filter Coefficient h1(2) |
LPF Coefficient h1(3) | Value must be an integer between 0x0000 and 0x1FFF | 0x0018 | Specify the Low-Pass Filter Coefficient h1(3) |
LPF Coefficient h1(4) | Value must be an integer between 0x0000 and 0x1FFF | 0x1FDC | Specify the Low-Pass Filter Coefficient h1(4) |
LPF Coefficient h1(5) | Value must be an integer between 0x0000 and 0x1FFF | 0x0034 | Specify the Low-Pass Filter Coefficient h1(5) |
LPF Coefficient h1(6) | Value must be an integer between 0x0000 and 0x1FFF | 0x1FB3 | Specify the Low-Pass Filter Coefficient h1(6) |
LPF Coefficient h1(7) | Value must be an integer between 0x0000 and 0x1FFF | 0x0076 | Specify the Low-Pass Filter Coefficient h1(7) |
LPF Coefficient h1(8) | Value must be an integer between 0x0000 and 0x1FFF | 0x1F2E | Specify the Low-Pass Filter Coefficient h1(8) |
LPF Coefficient h1(9) | Value must be an integer between 0x0000 and 0x1FFF | 0x0289 | Specify the Low-Pass Filter Coefficient h1(9) |
LPF Coefficient h1(10) | Value must be an integer between 0x0000 and 0x1FFF | 0x0289 | Specify the Low-Pass Filter Coefficient h1(10) |
LPF Coefficient h1(11) | Value must be an integer between 0x0000 and 0x1FFF | 0x1F2E | Specify the Low-Pass Filter Coefficient h1(11) |
LPF Coefficient h1(12) | Value must be an integer between 0x0000 and 0x1FFF | 0x0076 | Specify the Low-Pass Filter Coefficient h1(12) |
LPF Coefficient h1(13) | Value must be an integer between 0x0000 and 0x1FFF | 0x1FB3 | Specify the Low-Pass Filter Coefficient h1(13) |
LPF Coefficient h1(14) | Value must be an integer between 0x0000 and 0x1FFF | 0x0034 | Specify the Low-Pass Filter Coefficient h1(14) |
LPF Coefficient h1(15) | Value must be an integer between 0x0000 and 0x1FFF | 0x1FDC | Specify the Low-Pass Filter Coefficient h1(15) |
LPF Coefficient h1(16) | Value must be an integer between 0x0000 and 0x1FFF | 0x0018 | Specify the Low-Pass Filter Coefficient h1(16) |
LPF Coefficient h1(17) | Value must be an integer between 0x0000 and 0x1FFF | 0x1FF0 | Specify the Low-Pass Filter Coefficient h1(17) |
LPF Coefficient h1(18) | Value must be an integer between 0x0000 and 0x1FFF | 0x000A | Specify the Low-Pass Filter Coefficient h1(18) |
LPF Coefficient h1(19) | Value must be an integer between 0x0000 and 0x1FFF | 0x1FF8 | Specify the Low-Pass Filter Coefficient h1(19) |
Filter > Compensation Filter | |||
Compensation Filter Input Shift |
| No shift | Select the compensation filter input shift setting. |
Compensation Filter Coefficient h(0) | Value must be an integer between 0x0000 and 0x1FFF | 0x1FE8 | Specify the Compensation Filter Coefficient h(0) |
Compensation Filter Coefficient h(1) | Value must be an integer between 0x0000 and 0x1FFF | 0x0039 | Specify the Compensation Filter Coefficient h(1) |
Compensation Filter Coefficient h(2) | Value must be an integer between 0x0000 and 0x1FFF | 0x003C | Specify the Compensation Filter Coefficient h(2) |
Compensation Filter Coefficient h(3) | Value must be an integer between 0x0000 and 0x1FFF | 0x1E56 | Specify the Compensation Filter Coefficient h(3) |
Compensation Filter Coefficient h(4) | Value must be an integer between 0x0000 and 0x1FFF | 0x01DC | Specify the Compensation Filter Coefficient h(4) |
Compensation Filter Coefficient h(5) | Value must be an integer between 0x0000 and 0x1FFF | 0x06E1 | Specify the Compensation Filter Coefficient h(5) |
Compensation Filter Coefficient h(6) | Value must be an integer between 0x0000 and 0x1FFF | 0x01DC | Specify the Compensation Filter Coefficient h(6) |
Compensation Filter Coefficient h(7) | Value must be an integer between 0x0000 and 0x1FFF | 0x1E56 | Specify the Compensation Filter Coefficient h(7) |
Compensation Filter Coefficient h(8) | Value must be an integer between 0x0000 and 0x1FFF | 0x003C | Specify the Compensation Filter Coefficient h(8) |
Compensation Filter Coefficient h(9) | Value must be an integer between 0x0000 and 0x1FFF | 0x0039 | Specify the Compensation Filter Coefficient h(9) |
Compensation Filter Coefficient h(10) | Value must be an integer between 0x0000 and 0x1FFF | 0x1FE8 | Specify the Compensation Filter Coefficient h(10) |
Filter > High-pass Filter | |||
High-pass Filter Input Shift |
| No shift | Select the high-pass filter input shift setting. |
HPF Coefficient s(0) | Value must be an integer between 0x0000 and 0xFFFF | 0x3F61 | Specify the High-Pass Filter Coefficient s(0) |
HPF Coefficient k(1) | Value must be an integer between 0x0000 and 0xFFFF | 0x3EC1 | Specify the High-Pass Filter Coefficient k(1) |
HPF Coefficient h(0) | Value must be an integer between 0x0000 and 0xFFFF | 0x4000 | Specify the High-Pass Filter Coefficient h(0) |
HPF Coefficient h(1) | Value must be an integer between 0x0000 and 0xFFFF | 0xC000 | Specify the High-Pass Filter Coefficient h(1) |
Moving Average Mode |
| 1-order (filter is skipped) | Select the moving average mode for sound detection data. |
Sinc Filter Mode |
| 4-order | Select the sinc filter mode setting. |
Data Reception | |||
Buffer Overwrite Detection Enable |
| Enabled | Select buffer overwrite detection. |
Data Reception Interrupt Threshold |
| 16 or more data | Select Data reception interrupt threshold. |
Short Circuit Detection | |||
Short Circuit Detection Enable |
| Disabled | Select short circuit detection. |
Short Circuit Detection High Continuous Detection Count | Value must be an integer between 0x0000 and 0x1FFF | 0x0 | Specify the Short circuit detection High Continuous detection count. |
Short Circuit Detection Low Continuous Detection Count | Value must be an integer between 0x0000 and 0x1FFF | 0x0 | Short circuit detection Low Continuous detection count. |
Overvoltage Detection | |||
Overvoltage Detection Lower Limit Enable |
| Disabled | Select overvoltage detection lower limit. |
Overvoltage Detection Lower Limit | Value must be an integer between 0x0000 and 0xFFFFF | 0x0 | Specify the Overvoltage detection lower limit |
Overvoltage Detection Upper Limit Enable |
| Disabled | Select overvoltage detection upper limit. |
Overvoltage Detection Upper Limit | Value must be an integer between 0x0000 and 0xFFFFF | 0x0 | Specify the Overvoltage detection upper limit |
Interrupt | |||
Callback | Name must be a valid C symbol | NULL | A user callback function can be provided. If this callback function is provided, it will be called from all three interrupt service routines (ISR). |
Sound Detection Interrupt Priority | MCU Specific Options | Select the sound detection interrupt priority. | |
Data Reception Interrupt Priority | MCU Specific Options | Select the data reception interrupt priority. | |
Error Detection Interrupt Priority | MCU Specific Options | Select the error detection interrupt priority. | |
Name | Name must be a valid C symbol | g_pdm0 | Module name. |
Channel | Value must be an non-negative integer | 0 | Specify the PDM channel. |
Upon calling R_PDM_Open the user must wait for the filters to settle and any connected microphones to startup, otherwise PDM data may not be correct upon calling R_PDM_Start.
A macro G_PDMn_FILTER_SETTLING_TIME_US
(where n is the channel number) is generated for the settling time. The user can use this macro to delay for the settling time via their preferred method of doing a delay.
In addition to the filter settling time any connected microphone startup time should be accounted for. This can be found in the connected microphone's datasheet.
PDM hardware converts PDM data to PCM data.
Data arrays have the following size, alignment, and length based on the "Bit Depth" setting:
Bit Depth | Array Data Type | Required Alignment |
---|---|---|
16 Bits | 32-bit integer, right justified | 4 byte alignment |
20 Bits | 32-bit integer, right justified | 4 byte alignment |
Bit | Description |
---|---|
31-20 | Fixed to 0 |
19-16 | Sign bits |
15-0 | Fixed-point data |
Bit | Description |
---|---|
31-20 | Fixed to 0 |
19-0 | Fixed-point data |
In addition to calling R_PDM_Open, other APIs need to be called to activate certain features of PDM. The following table lists what each API controls:
API | Features Enabled by API |
---|---|
R_PDM_Open | over/undervoltage detection, short circuit detection |
R_PDM_Start | data reception via interrupts or DMAC depending configuration, error interrupts |
R_PDM_SoundDetectionEnable | sound detection, sound detection thresholds, error interrupts |
Error interrupts are only enabled when data reception is enabled (R_PDM_Start has been called) OR sound detection is enabled (R_PDM_SoundDetectionEnable has been called).
R_PDM_StatusGet can be called to get error statuses if error interrupts are not enabled (e.g. if only R_PDM_Open has been called).
Some microphones support going into a low power mode by changing the PDM clock to a low frequency. In order to do this with r_pdm the module instance should be closed and reopened with a separate configuration that uses a lower PDM clock.
pcm_edge
configuration to get left/right stereo output from an appropriately configured PDM data stream, however, the data from these two instances will not be synchronized. Full synchronization of PDM channels requires using PDM mirror registers and starting data reading at the same time between channels. In the future a stereo-specific driver may be implemented using the r_pdm driver as a lower level driver to cover this use case.R_PDM_Start
any data in the FIFO before DATRE is enabled will be discarded.Data Structures | |
struct | pdm_instance_ctrl_t |
struct | pdm_extended_cfg_t |
Macros | |
#define | PDM_NUM_HPF_COEFFICIENT_H |
Number of high pass filter h coefficients. | |
#define | PDM_NUM_COMPENSATION_FILTER_COEFFICIENT_H |
Number of compensation filter h coefficients. | |
#define | PDM_NUM_LPF_FILTER_COEFFICIENT_H1 |
Number of low pass filter h1 coefficients. | |
Enumerations | |
enum | pdm_clk_div_t |
enum | pdm_moving_average_mode_t |
enum | pdm_low_pass_filter_shift_t |
enum | pdm_compensation_filter_shift_t |
enum | pdm_high_pass_filter_shift_t |
enum | pdm_sinc_filter_mode_t |
enum | pdm_interrupt_threshold_t |
enum | pdm_short_circuit_enable_t |
enum | pdm_overvoltage_lower_limit_enable_t |
enum | pdm_overvoltage_upper_limit_enable_t |
enum | pdm_buffer_overwrite_detection_enable_t |
struct pdm_instance_ctrl_t |
Channel instance control block. DO NOT INITIALIZE. Initialization occurs when pdm_api_t::open is called.
struct pdm_extended_cfg_t |
PDM configuration extension. This extension is optional.
Data Fields | ||
---|---|---|
pdm_clk_div_t | clock_div | PDM_CLKn's division ratio to core clock. |
pdm_short_circuit_enable_t | short_circuit_detection_enable |
Short circuit detection enable. Function Settings. |
pdm_overvoltage_lower_limit_enable_t | over_voltage_lower_limit_detection_enable | Overvoltage detection lower limit enable. |
pdm_overvoltage_upper_limit_enable_t | over_voltage_upper_limit_detection_enable | Overvoltage detection upper limit enable. |
pdm_buffer_overwrite_detection_enable_t | buffer_overwrite_detection_enable | Buffer overwrite detection enable. |
pdm_moving_average_mode_t | moving_average_mode |
Moving average mode f or sound detection data. Filter Settings. |
pdm_low_pass_filter_shift_t | low_pass_filter_shift | Low-pass (half -band decimation) filter input shift setting. |
pdm_compensation_filter_shift_t | compensation_filter_shift | Compensation filter input shift setting. |
pdm_high_pass_filter_shift_t | high_pass_filter_shift | High-pass filter input shift setting. |
pdm_sinc_filter_mode_t | sinc_filter_mode | Sinc filter mode setting. |
uint8_t | sincrng | Sinc filter output valid range. |
uint8_t | sincdec | Sinc filter decimation ratio. |
uint16_t | hpf_coefficient_s0 | High-pass filter coefficient s0 (16-bit signed fixed point data) |
uint16_t | hpf_coefficient_k1 | High-pass filter coefficient k1 (16-bit signed fixed point data) |
uint16_t | hpf_coefficient_h[PDM_NUM_HPF_COEFFICIENT_H] | High-pass filter coefficient h(p) (16-bit signed fixed point data) |
uint16_t | compensation_filter_coefficient_h[PDM_NUM_COMPENSATION_FILTER_COEFFICIENT_H] | High-pass filter coefficient h(p) (13-bit signed fixed point data) |
uint16_t | lpf_coefficient_h0 | Low-pass (half-band decimation) filter coefficient h0 (13-bit signed fixed point data) |
uint16_t | lpf_coefficient_h1[PDM_NUM_LPF_FILTER_COEFFICIENT_H1] | Low-pass (half-band decimation) filter coefficient h1 (13-bit signed fixed point data) |
pdm_interrupt_threshold_t | interrupt_threshold |
Data reception interrupt threshold. Data Reception. |
uint16_t | short_circuit_count_h |
Short circuit detection High Continuous detection count. Short-Circuit Detection. |
uint16_t | short_circuit_count_l | Continuous detection count. |
uint32_t | overvoltage_detection_lower_limit |
Overvoltage detection lower limit (20-bit signed fixed point data) Overvoltage Detection. |
uint32_t | overvoltage_detection_upper_limit | Overvoltage detection upper limit (20-bit signed fixed point data) |
enum pdm_clk_div_t |
PDM_CLKn's division ratio to core clock.
Data reception interrupt threshold.
fsp_err_t R_PDM_Open | ( | pdm_ctrl_t *const | p_ctrl, |
pdm_cfg_t const *const | p_cfg | ||
) |
Opens the PDM. Implements pdm_api_t::open.
This function sets this clock divisor and the configurations specified in pdm_cfg_t.
FSP_SUCCESS | Ready for PDM communication. |
FSP_ERR_ASSERTION | The pointer to p_ctrl or p_cfg is null. |
FSP_ERR_ALREADY_OPEN | The control block has already been opened. |
FSP_ERR_IP_CHANNEL_NOT_PRESENT | Channel number is not available on this device. |
fsp_err_t R_PDM_Start | ( | pdm_ctrl_t *const | p_ctrl, |
void *const | p_buffer, | ||
size_t const | buffer_size, | ||
uint32_t const | number_of_data_to_callback | ||
) |
Starts PDM. Implements pdm_api_t::start.
This function enables reception, and enables any transfer instances used.
The PDM will start on the next frame boundary.
FSP_SUCCESS | PDM communication stop request issued. |
FSP_ERR_ASSERTION | The pointer to p_ctrl was null. |
FSP_ERR_INVALID_SIZE | The size of buffer is not a multiple of pdm_interrupt_threshold_t. |
FSP_ERR_INVALID_ALIGNMENT | The alignment of argument buffer_size is not matched with hardware specification. |
FSP_ERR_NOT_OPEN | The channel is not opened. |
fsp_err_t R_PDM_Stop | ( | pdm_ctrl_t *const | p_ctrl | ) |
Stops PDM. Implements pdm_api_t::stop.
This function disables reception, and disables any transfer instances used.
The PDM will stop on the next frame boundary.
FSP_SUCCESS | PDM communication stop request issued. |
FSP_ERR_ASSERTION | The pointer to p_ctrl was null. |
FSP_ERR_NOT_OPEN | The channel is not opened. |
fsp_err_t R_PDM_SoundDetectionEnable | ( | pdm_ctrl_t *const | p_ctrl, |
pdm_sound_detection_setting_t | sound_detection_setting | ||
) |
Configures and enables sound detection. Implements pdm_api_t::soundDetectionEnable.
This function configures sound detection based on the passed in settings. It then enables sound detection.
FSP_SUCCESS | Sound detection configured and enabled. |
FSP_ERR_ASSERTION | The pointer to p_ctrl was null. |
FSP_ERR_NOT_OPEN | The channel is not opened. |
fsp_err_t R_PDM_SoundDetectionDisable | ( | pdm_ctrl_t *const | p_ctrl | ) |
Disables sound detection. Implements pdm_api_t::soundDetectionDisable.
This function disables sound detection.
FSP_SUCCESS | Sound detection disabled. |
FSP_ERR_ASSERTION | The pointer to p_ctrl was null. |
FSP_ERR_NOT_OPEN | The channel is not opened. |
fsp_err_t R_PDM_Read | ( | pdm_ctrl_t *const | p_ctrl, |
void *const | p_dest, | ||
uint32_t const | bytes | ||
) |
This function is not supported. Implements pdm_api_t::read.
FSP_ERR_UNSUPPORTED | This function is not supported. |
fsp_err_t R_PDM_StatusGet | ( | pdm_ctrl_t *const | p_ctrl, |
pdm_status_t *const | p_status | ||
) |
Gets PDM status and stores it in provided pointer p_status. Implements pdm_api_t::statusGet.
Calling this function will clear any set error flags in the hardware.
FSP_SUCCESS | Information stored successfully. |
FSP_ERR_ASSERTION | The p_ctrl or p_status parameter was null. |
FSP_ERR_NOT_OPEN | The channel is not opened. |
fsp_err_t R_PDM_Close | ( | pdm_ctrl_t *const | p_ctrl | ) |
Closes PDM. Implements pdm_api_t::close.
This function powers down the PDM and closes the lower level timer and transfer drivers if they are used.
FSP_SUCCESS | Device closed successfully. |
FSP_ERR_ASSERTION | The pointer to p_ctrl was null. |
FSP_ERR_NOT_OPEN | The channel is not opened. |
fsp_err_t R_PDM_CallbackSet | ( | pdm_ctrl_t *const | p_ctrl, |
void(*)(pdm_callback_args_t *) | p_callback, | ||
void *const | p_context, | ||
pdm_callback_args_t *const | p_callback_memory | ||
) |
Updates the user callback and has option of providing memory for callback structure. Implements pdm_api_t::callbackSet
FSP_SUCCESS | Callback updated successfully. |
FSP_ERR_ASSERTION | A required pointer is NULL. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
FSP_ERR_NO_CALLBACK_MEMORY | p_callback is non-secure and p_callback_memory is either secure or NULL. |