<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Why Thingy52 PDM sample code skip buffer ?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/50777/why-thingy52-pdm-sample-code-skip-buffer</link><description>I am using thing SDK. And,following function is part of thingy SDK. Could someone can explain why the following function needs skip 31 times?</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 19 Aug 2019 11:46:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/50777/why-thingy52-pdm-sample-code-skip-buffer" /><item><title>RE: Why Thingy52 PDM sample code skip buffer ?</title><link>https://devzone.nordicsemi.com/thread/204736?ContentTypeID=1</link><pubDate>Mon, 19 Aug 2019 11:46:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9e879475-1077-4b48-b779-a760c6652309</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Louis&lt;/p&gt;
&lt;p&gt;No, the data from the microphone, and the data output by the PDM peripheral, is not the same.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The 1-bit PDM data is run through a low pass filter and decimated to provide the 16-bit PCM output.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For more information about this please refer to &lt;a href="https://en.wikipedia.org/wiki/Pulse-density_modulation"&gt;this&lt;/a&gt; and &lt;a href="https://en.wikipedia.org/wiki/Downsampling_(signal_processing)"&gt;this&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
[quote user="Louis Wnag"]drv_mic_data_handler()&amp;nbsp;function will send PCM data(I mean is data be Encode ?) via BLE&amp;nbsp; to cellphone?[/quote]
&lt;p&gt;Yes. The actual sending of PDM data over the Bluetooth link is handled by the ble_tss_mic_set(..) function, which is called from drv_mic_data_handler().&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why Thingy52 PDM sample code skip buffer ?</title><link>https://devzone.nordicsemi.com/thread/204263?ContentTypeID=1</link><pubDate>Thu, 15 Aug 2019 10:07:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:76e5ff2d-ebfd-4fd8-a60f-77dea9263061</guid><dc:creator>Louis Wnag</dc:creator><description>&lt;p&gt;Hi Overbekk&lt;/p&gt;
&lt;p&gt;Sorry I can not understand your mean totally.&lt;/p&gt;
&lt;p&gt;May I check with you agin that&amp;nbsp;&amp;nbsp;*p_buffer of drv_audio_pdm_event_handler() is raw data from digital microphone(PDM interface) ?&lt;/p&gt;
&lt;p&gt;If so the single(green line) of &amp;nbsp;occilloscope&amp;nbsp;must match with *p_buffer&amp;nbsp;. May I right ?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Another question:&lt;/p&gt;
&lt;p&gt;drv_mic_data_handler()&amp;nbsp;function will send PCM data(I mean is data be Encode ?) via BLE&amp;nbsp; to cellphone?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Louis&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why Thingy52 PDM sample code skip buffer ?</title><link>https://devzone.nordicsemi.com/thread/203968?ContentTypeID=1</link><pubDate>Wed, 14 Aug 2019 07:58:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02740082-8c2a-4976-89af-7a09ab59ac10</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Louis&lt;/p&gt;
&lt;p&gt;The input from the microphone is run through a decimation filter, to make what is essentially a high frequency 1-bit stream into 16-bit PCM samples.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For this reason the data you see reported from the PDM module&amp;nbsp; will not match the data you see on the bus.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;There is some more information on the decimation filter &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/pdm.html?cp=3_1_0_42_2#concept_tn3_xt2_yr"&gt;here&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why Thingy52 PDM sample code skip buffer ?</title><link>https://devzone.nordicsemi.com/thread/203768?ContentTypeID=1</link><pubDate>Tue, 13 Aug 2019 09:27:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f596a322-9e63-4734-bdeb-4b5af65367d4</guid><dc:creator>Louis Wnag</dc:creator><description>&lt;p&gt;Hi Overbekk&lt;/p&gt;
&lt;p&gt;The microphone I use is STmicro &lt;strong&gt;MP23DB01HP (L/R connected to GND as mono Left)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;GPIO-40 pull high for the trigger valid data (Once the m_skip_buffers counter reaches 0)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But the data received still cannot match the data shown in the scope.&lt;/p&gt;
&lt;p&gt;Is there anything miss?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static int buf_cnt = 0;
static void drv_audio_pdm_event_handler(uint32_t *p_buffer, uint16_t length)
{

    ASSERT(length == CONFIG_PDM_BUFFER_SIZE_SAMPLES);

    if (m_skip_buffers)
    {
        m_skip_buffers -= 1;
if(m_skip_buffers == 0){
printf(&amp;quot;PULL HIGH\r\n&amp;quot;);
nrf_gpio_pin_write(40,1);
}
    }
    else
    {
if(buf_cnt &amp;lt; 1){		
printf(&amp;quot;[%d] 0x%08x 0x%08x 0x%08x 0x%08x\r\n&amp;quot;, length, p_buffer[0] , p_buffer[1] , p_buffer[2], p_buffer[3]);		
}
        m_buffer_handler((int16_t *)p_buffer, length);//m_audio_buffer_handler(bufer,length)
buf_cnt++;
    }
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Consol message:&lt;/p&gt;
&lt;p&gt;PULL HIGH&lt;/p&gt;
&lt;p&gt;[256] 0x00d000cf 0x00cc00d0 0x00ce00d2 0x00c900cf&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/4760.scope_5F00_1.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why Thingy52 PDM sample code skip buffer ?</title><link>https://devzone.nordicsemi.com/thread/203722?ContentTypeID=1</link><pubDate>Tue, 13 Aug 2019 06:31:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6feefd53-8b9e-45e0-9fe0-e51cdde2a92f</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Louis&lt;/p&gt;
&lt;p&gt;The best of luck. Just let me know if you have more questions &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why Thingy52 PDM sample code skip buffer ?</title><link>https://devzone.nordicsemi.com/thread/203708?ContentTypeID=1</link><pubDate>Tue, 13 Aug 2019 02:12:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f1ecb687-233d-4e35-ade1-2d9a4b808fdc</guid><dc:creator>Louis Wnag</dc:creator><description>&lt;p&gt;Hi Overbekk&lt;/p&gt;
&lt;p&gt;Yes, thank you. You provide a good idea for me. I will try it.&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Louis&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why Thingy52 PDM sample code skip buffer ?</title><link>https://devzone.nordicsemi.com/thread/203619?ContentTypeID=1</link><pubDate>Mon, 12 Aug 2019 13:43:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eb6bf6d8-5aa9-4ca5-b7cb-29a9797f0c80</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I am a bit unsure what you are trying to do.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Do you want to trigger the scope once the first valid data is sent from the microphone?&lt;/p&gt;
&lt;p&gt;If so maybe you could set a GPIO in the&amp;nbsp;drv_audio_pdm_event_handler(..) function once the m_skip_buffers counter reaches 0, and use this signal to&amp;nbsp;trigger the oscilloscope?&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why Thingy52 PDM sample code skip buffer ?</title><link>https://devzone.nordicsemi.com/thread/203466?ContentTypeID=1</link><pubDate>Mon, 12 Aug 2019 06:15:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ea2f4b7-107a-4241-96ad-a0519a128a2e</guid><dc:creator>Louis Wnag</dc:creator><description>&lt;p&gt;Hi overbekk&lt;/p&gt;
&lt;p&gt;Thank&amp;#39;s for your response.&lt;/p&gt;
&lt;p&gt;I have another question. How to verify the data via the oscilloscope.&lt;/p&gt;
&lt;p&gt;I am going to&amp;nbsp;use following&amp;nbsp;C code to explain my question.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static int validdata = 0;
static void m_audio_buffer_handler(int16_t *p_buffer, uint16_t samples)
{
    uint32_t     err_code;
    pdm_buf_t  * p_pdm_buf = NULL;
    uint32_t     pdm_buf_addr;
	

int8_t *ptr = (int8_t *)p_buffer;
if(validdata &amp;lt; 1){
	NRF_LOG_INFO(&amp;quot;[%d] 0x%04x 0x%04x 0x%04x 0x%04x\r\n&amp;quot;, samples, *p_buffer , *(p_buffer+1) , *(p_buffer+2), *(p_buffer+3));
}
validdata++;

    for(uint32_t i = 0; i &amp;lt; PDM_BUF_NUM; i++)
    {
        if ( m_pdm_buf[i].free == true )
        {
            m_pdm_buf[i].free    = false;
            m_pdm_buf[i].samples = samples;
            for (uint32_t j = 0; j &amp;lt; samples; j++)
            {
                m_pdm_buf[i].buf[j] = p_buffer[j];
            }
            p_pdm_buf = &amp;amp;m_pdm_buf[i];
            pdm_buf_addr = (uint32_t)&amp;amp;m_pdm_buf[i];

            break;
        }
    }

    if (p_pdm_buf != NULL)
    {
        err_code = app_sched_event_put(&amp;amp;pdm_buf_addr, sizeof(pdm_buf_t *), m_audio_process);
        APP_ERROR_CHECK(err_code);
    }
    else
    {
        NRF_LOG_INFO(&amp;quot;m_audio_buffer_handler: BUFFER FULL!!\r\n&amp;quot;);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;drv_audio_pdm_event_handler() will skip invalid data then send valid data to m_audio_buffer_handler() to process.&lt;/p&gt;
&lt;p&gt;When I get CLK and DIN via an occilloscope&amp;#39;s trigger function&amp;nbsp;these&amp;nbsp;data are invalid at the beginning(microphone wake up).&amp;nbsp;Because occilloscope&amp;#39;s trigger function&amp;nbsp;can not get valid data so can not verify&amp;nbsp;thes data with print out information&amp;nbsp;.&lt;/p&gt;
&lt;p&gt;So,How to verify CLK and DIN via the oscilloscope ?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why Thingy52 PDM sample code skip buffer ?</title><link>https://devzone.nordicsemi.com/thread/203218?ContentTypeID=1</link><pubDate>Fri, 09 Aug 2019 07:42:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2aa563c-a174-4dfc-ba36-5d0411fc2533</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;The m_skip_buffers counter is controlled by the following define in drv_audio_config.h:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;// &amp;lt;o&amp;gt; PDM Microphone Transient State Length [ms] &amp;lt;1-1000&amp;gt;
// &amp;lt;i&amp;gt; Set the length of the PDM microphone transient state. In this state, the microphone produces invalid data after wakeup or after it is powered on.
#define CONFIG_PDM_TRANSIENT_STATE_LEN 500&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Apparently some of these PDM microphones need some time after startup before they produce valid data, so to avoid&amp;nbsp;unwanted clicks or noise when starting the&amp;nbsp;microphone it is necessary to&amp;nbsp;ignore the first 500ms of audio data produced.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>