Using PDM for 2 Microphones in Stereo Mode

Hello, I'm trying to use two microphones in stereo mode of PDM (nrf52832, SDK17). Unfortunately, I have a major problem with my Right microphone. It seems that "nrfx_pdm_buffer_set" just put the Left one in the buffer.

This is my initialization for PDM in main function:

int main(void) {
    .
    .
    ...
    nrfx_pdm_config_t pdm_config = NRFX_PDM_DEFAULT_CONFIG(PDM_CLK_PIN, PDM_DATA_PIN);
    pdm_config.mode = PDM_MODE_OPERATION_Stereo;
    pdm_config.gain_l = PDM_GAIN;
    pdm_config.gain_r = PDM_GAIN;
    pdm_config.clock_freq = PDM_PDMCLKCTRL_FREQ_1000K; // 15625 Samples per Second
    pdm_config.edge = PDM_MODE_EDGE_LeftFalling;
    pdm_config.interrupt_priority = APP_IRQ_PRIORITY_HIGH;
    err_code = nrfx_pdm_init(&pdm_config, pdm_event_handler);
    APP_ERROR_CHECK(err_code);
    .
    .
    .
}

This is "pdm_event_handler" function and "pdm_buffer" array:

int16_t pdm_buffer[PDM_BUFFER_SIZE_SAMPLES];

static void pdm_event_handler(nrfx_pdm_evt_t const *const p_evt) {
    if (p_evt->buffer_requested) {
	    nrfx_pdm_buffer_set(pdm_buffer, PDM_BUFFER_SIZE_SAMPLES);
    } 
    if (p_evt->buffer_released) {
    	do_something(pdm_buffer);
    }
}

I tried many methods, including:

1. Make the type of "pdm_buffer" array uint32_t instead of int16_t.

2. Make "pdm_buffer" array 2 dimensional (int16_t pdm_buffer[2][PDM_BUFFER_SIZE_SAMPLES]).

3. Double the "PDM_BUFFER_SIZE_SAMPLES" constant in the buffer set ("nrfx_pdm_buffer_set(pdm_buffer, 2 * PDM_BUFFER_SIZE_SAMPLES)").

But non of them work.

Parents Reply
  • I am not sure what I am looking at, or what it is supposed to look like.

    You have set "pdm_config.edge = PDM_MODE_EDGE_LeftFalling;" So that means that the data we see here (all the changes) are from the left channel, since they are directly after the clock is falling from high to low. No change on low to high, do you agree?

    And the microphone behaves like this both if you connect LR to GND or VDD? It always changes on HiToLo?

    BR,

    Edvin

Children
  • I do not agree. As I can see PDM_DATA has both 0 and 1 in falling and rising of PDM_CLOCK. There must be a problem with my code or SDK as I mentioned before.

    I don't understand what you are seeking for when you say: "And the microphone behaves like this both if you connect LR to GND or VDD? It always changes on HiToLo?"

    I used 2 microphones on my own-designed PCB and I want to use them in stereo mode. My code doesn't detect anything from the right microphone (all data is captured from left one). Please take a look at my code or the problem may happened due to a problem in nrfx driver.

  • Perhaps I misunderstand something, or don't know how PDM is supposed to work, but all of the changes on the data line are changing directly after the clock goes high to low:

    Doesn't that suggest that it is only sending data on the falling clock?

    BR,
    Edvin

Related