This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

PDM code implementation and testing

I have to connect a MIC  working on PDM to nrf52 DK Board.For that, I have written the above code.  But when I am testing I am not able to get the clock pulses at the defined pin. Also do not know at which Freq it is working?

And when I read the pdm documentation it says I need to change the PSEL.CLK register value? Then how should I do it and with what value? same for PSEL.DIN register. I am confused a lot. Please suggest me the solution to all my doubts.I have checked the clk pin on Oscilloscope, the clock is not being generated.In order to generate clk at pin number 22 of nrf52 DK board should I define pin clk  as #define CONFIG_IO_PDM_CLK 0x22 or 0x16 (hex value of 22 )instead o rtf 0x22?

Parents
  • The PDM driver will call nrf_pdm_psel_connect who'll set the PSEL.CLK and PSEL.DIN. I suggest you read the implementation of nrfx_pdm_init and see how the driver and HAL configures the PDM registers. This will give you valuable insight into how our drivers and HALs work in relation to the peripherals HW documentation.

    "should I define pin clk  as #define CONFIG_IO_PDM_CLK 0x22 or 0x16 (hex value of 22 )instead o rtf 0x22?"
    pin numbers are decimal, so either 22 or 0x16. 

  • Ok. But even though I am doing #define PDM_CONFIG_CLOCK_FREQ 134217728 which is 1MHz, Iam not getting the clock signal at pin 22. For this what should I do?

  • Hi Sara

    I don't think the UART driver is very happy if you try to access the driver from a high priority interrupt. 

    Could you try to reduce the interrupt priority of the PDM interrupt handler and see if it works better?

    A higher IRQ priority number corresponds to lower interrupt priority, with 7 being the lowest and 0 the highest. 

    Best regards
    Torbjørn

  • Hi, i had made the interrupt priorities changes as below , but still my device resets and goes into Fatal error.

    #ifndef NRFX_UART_DEFAULT_CONFIG_IRQ_PRIORITY
    #define NRFX_UART_DEFAULT_CONFIG_IRQ_PRIORITY 5
    #endif

    #ifndef PDM_CONFIG_IRQ_PRIORITY
    #define PDM_CONFIG_IRQ_PRIORITY 7
    #endif

  • Hi Sara

    Any particular reason you are not using the PDM driver provided with the SDK?

    I tried to add the PDM driver to the ble_app_uart example, and was able to get it running very quickly. I can print out parts of the PDM data without any issues (I didn't try to print out all the data, as this might be too much for the UART to handle). 

    You can download my project here if you want to have a look:
    ble_app_uart_pdmtest.zip

    Best regards
    Torbjørn

  • Hi,

     Thank  you, initially I had tried with the SDK PDM but in that I was not able to get the clock so I switched with this code. And now out due to weekend so will try out your code on Monday. And if I want all the data then what should I do?? And wich MIC have you interfaced with the nrf52? I have to use the INvensense MIC ICS -41352

  • Thank you soo much Ovrebekk, the code which you gave is working for me now. But now just working on data as I need all the data and printing all the data does not work. So if you have any alternative for it do help.

Reply
  • Thank you soo much Ovrebekk, the code which you gave is working for me now. But now just working on data as I need all the data and printing all the data does not work. So if you have any alternative for it do help.

Children
  • hello, Ovrebekk.

    I need data because I want to validate the MIC data. Is there any other way to validate PDM MIC data?

  • Hi 

    The problem of printing the data live is that we are talking about a raw data stream of 256kbps. 

    This is technically possible to output on the UART if you use a high baudrate (460800 or more is probably needed), but you will have to display the data as raw data, not as hex. Some terminal programs might be able to show you the data in decimal or hex form, but not all will do this. 

    Have you considered storing a burst of data in a buffer that you can analyze afterwards?

    Either you can use the debugger to inspect the data in the buffer, or you can output the buffer to UART once you have filled it up (then you don't have to worry about how much time it takes to empty the buffer, since you are not writing to the UART live). 

    Best regards
    Torbjørn

  • Hello,

    Now able to get data by storing a burst of data in a buffer.

    Thank you so much for your support Overbekk.

  • That's great news, the best of luck with your project Slight smile

  • Thanks a lot, Overbekk and Haakonsh for your support!