<?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>nrf52 adc spike problem</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/71214/nrf52-adc-spike-problem</link><description>Hi, 
 
 I&amp;#39;m using nrf52 with s132(v17.0.0). 
 When I connect nrf52 with my phone, there is error like this picture. 
 
 And, the code is 
 
 When the buffer is filled, then next buffer is filled by ADC value. 
 I guess the problem occurs at this time</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 08 Feb 2021 08:26:32 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/71214/nrf52-adc-spike-problem" /><item><title>RE: nrf52 adc spike problem</title><link>https://devzone.nordicsemi.com/thread/293250?ContentTypeID=1</link><pubDate>Mon, 08 Feb 2021 08:26:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03edf0a2-4ff8-4cba-aaa1-47f570eda25e</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote user="ENENER"]Thanks![/quote]
&lt;p&gt;No problem at all, I am happy to help!&lt;/p&gt;
[quote user="ENENER"]I think the reason is not nrf52 but application.[/quote]
&lt;p&gt;I too think this might be likely. I am glad to hear that you think you&amp;#39;ve found the source of the issue!&lt;br /&gt;&lt;br /&gt;Please do not hesitate to open a new ticket if you should encounter any issues or questions.&lt;br /&gt;&lt;br /&gt;Good luck with your development!&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52 adc spike problem</title><link>https://devzone.nordicsemi.com/thread/293187?ContentTypeID=1</link><pubDate>Sat, 06 Feb 2021 03:02:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0cc58545-1762-4091-be7f-405556112929</guid><dc:creator>ENENER</dc:creator><description>&lt;p&gt;Thank you&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I think the reason is not nrf52 but application.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52 adc spike problem</title><link>https://devzone.nordicsemi.com/thread/292720?ContentTypeID=1</link><pubDate>Wed, 03 Feb 2021 14:38:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:78c876d5-0dc2-4990-88dd-2b5bfae5b18e</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote user="ENENER"]&lt;p&gt;I applied sine graph.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In one buffer([0, ~ , 239]), there are linearity. And I can get sine graph so exactly.&lt;/p&gt;
&lt;p&gt;But when the buffer is changed, the problem occurs.&lt;/p&gt;
&lt;p&gt;There are no linearity.&lt;/p&gt;
&lt;p&gt;I guess the reason happens in changing buffer ( [0, ~ ,239] -&amp;gt; [0, ~ 239] ).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And I&amp;#39;m using PPI to use SAADC function.&lt;/p&gt;[/quote]
&lt;p&gt;Thank you for clarifying.&lt;br /&gt;&lt;br /&gt;Is the graph here from the values that the phone is receiving - i.e the phone is creating this graph to display the values it is getting, or is this a graph generated to illustrate the issue from the outputted SAADC values directly(no phone involved)? If there is a phone involved - could you tell me which BLE connection parameters are you using?&lt;br /&gt;How is this graph generated, and could you show me the raw output of the SAADC instead?&lt;br /&gt;I suppose the resolution of your graph is a little low, but it seems that the first value of the second buffer somehow is equal to the second last value of the first buffer.&lt;br /&gt;&lt;br /&gt;Since you are using double buffering the SAADC will immediately continue to sample into the next buffer once the first buffer is filled - so there will be no computational time necessary here before sampling resumes. This way, you will not miss a single sample.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52 adc spike problem</title><link>https://devzone.nordicsemi.com/thread/292640?ContentTypeID=1</link><pubDate>Wed, 03 Feb 2021 10:34:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3e1f777f-817a-4a54-b4ae-ef8bb4581494</guid><dc:creator>ENENER</dc:creator><description>&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;First of all, I attached screenshot picture which means Xaxis label(1st buffer, 2nd buffer).&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/1280x960/__key/communityserver-discussions-components-files/4/tempFileForShare_5F00_20210203_2D00_172953.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;I applied sine graph.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In one buffer([0, ~ , 239]), there are linearity. And I can get sine graph so exactly.&lt;/p&gt;
&lt;p&gt;But when the buffer is changed, the problem occurs.&lt;/p&gt;
&lt;p&gt;There are no linearity.&lt;/p&gt;
&lt;p&gt;I guess the reason happens in changing buffer ( [0, ~ ,239] -&amp;gt; [0, ~ 239] ).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And I&amp;#39;m using PPI to use SAADC function.&lt;/p&gt;
&lt;p&gt;I attached the code.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks&lt;pre class="ui-code" data-mode="text"&gt;void saadc_sampling_event_init(void)
{
    ret_code_t err_code;
    err_code = nrf_drv_ppi_init();
    APP_ERROR_CHECK(err_code);
    
    nrf_drv_timer_config_t timer_config = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_config.frequency = NRF_TIMER_FREQ_31250Hz;

    err_code = nrf_drv_timer_init(&amp;amp;m_timer, &amp;amp;timer_config, timer_handler);
    APP_ERROR_CHECK(err_code);

    /* setup m_timer for compare event */
    uint32_t ticks = nrf_drv_timer_us_to_ticks(&amp;amp;m_timer,SAADC_SAMPLE_RATE);
    nrf_drv_timer_extended_compare(&amp;amp;m_timer, NRF_TIMER_CC_CHANNEL0, ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, false);
    nrf_drv_timer_enable(&amp;amp;m_timer);

    uint32_t timer_compare_event_addr = nrf_drv_timer_compare_event_address_get(&amp;amp;m_timer, NRF_TIMER_CC_CHANNEL0);
    uint32_t saadc_sample_event_addr = nrf_drv_saadc_sample_task_get();

    /* setup ppi channel so that timer compare event is triggering sample task in SAADC */
    err_code = nrf_drv_ppi_channel_alloc(&amp;amp;m_ppi_channel);
    APP_ERROR_CHECK(err_code);
    
    err_code = nrf_drv_ppi_channel_assign(m_ppi_channel, timer_compare_event_addr, saadc_sample_event_addr);
    APP_ERROR_CHECK(err_code);
}


void saadc_sampling_event_enable(void)
{
    ret_code_t err_code = nrf_drv_ppi_channel_enable(m_ppi_channel);
    APP_ERROR_CHECK(err_code);
}


void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
    if (p_event-&amp;gt;type == NRF_DRV_SAADC_EVT_DONE)
    {
        ret_code_t err_code;
        uint16_t bytes_to_send = (uint16_t) SAADC_SAMPLES_IN_BUFFER;
        uint8_t DATA[SAADC_SAMPLES_IN_BUFFER];
        // set buffers
        err_code = nrf_drv_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer, SAADC_SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);

        // print samples on hardware UART and parse data for BLE transmission

        for (int i = 0; i &amp;lt; SAADC_SAMPLES_IN_BUFFER; i++)
        {
          DATA[i] = p_event-&amp;gt;data.done.p_buffer[i];
          printf(&amp;quot;%d\r\n&amp;quot;, DATA[i]);
        }
       err_code = ble_nus_data_send(&amp;amp;m_nus, DATA, &amp;amp;bytes_to_send, m_conn_handle);
         
        if ((err_code != NRF_ERROR_INVALID_STATE) 
        &amp;amp;&amp;amp; (err_code != NRF_ERROR_NOT_FOUND)
        &amp;amp;&amp;amp; (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING))
        {
            APP_ERROR_CHECK(err_code);
        }
        
    }
}


void saadc_init(void)
{
    ret_code_t err_code;
	
    nrf_drv_saadc_config_t saadc_config = NRF_DRV_SAADC_DEFAULT_CONFIG;
    saadc_config.resolution = NRF_SAADC_RESOLUTION_8BIT;
	
    nrf_saadc_channel_config_t channel_0_config =
    NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0);

    channel_0_config.gain = NRF_SAADC_GAIN1_6;
    channel_0_config.reference = SAADC_CH_CONFIG_REFSEL_Internal;
    channel_0_config.acq_time = NRF_SAADC_ACQTIME_40US;
    
    err_code = nrf_drv_saadc_init(&amp;amp;saadc_config, saadc_callback);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_saadc_channel_init(0, &amp;amp;channel_0_config);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0],SAADC_SAMPLES_IN_BUFFER);
    APP_ERROR_CHECK(err_code);   
    err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1],SAADC_SAMPLES_IN_BUFFER);
    APP_ERROR_CHECK(err_code);
}

/**@brief Application main function.
 */
int main(void)
{
    bool erase_bonds;

    // Initialize.
      uart_init();
    log_init();
    timers_init();
    buttons_leds_init(&amp;amp;erase_bonds);
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();
    
    saadc_sampling_event_init();
    saadc_init();
    saadc_sampling_event_enable();

    // Start execution.
    printf(&amp;quot;\r\nUART started.\r\n&amp;quot;);
    NRF_LOG_INFO(&amp;quot;Debug logging for UART over RTT started.&amp;quot;);
    advertising_start();

    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
    }
}   &lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52 adc spike problem</title><link>https://devzone.nordicsemi.com/thread/292494?ContentTypeID=1</link><pubDate>Tue, 02 Feb 2021 13:37:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:51a8f8eb-8218-4376-83f4-bf1d47270551</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user=""]I&amp;#39;m using nrf52 with s132(v17.0.0).[/quote]
&lt;p&gt;Thank you for clarifying. I recommend that you upgrade to SDK v17.0.2 as it is API compatible and contains some bugfixes - all you need to do is download the v.17.0.2 SDK and move your project over to it instead.&lt;/p&gt;
[quote user=""]When I connect nrf52 with my phone, there is error like this picture.[/quote]
&lt;p&gt;What is the axis labels here? Please include more of the image. Without the axis&amp;#39; labels and magnitudes it is very hard to say anything about what this is depicting.&lt;/p&gt;
[quote user=""]And, the code is[/quote]
&lt;p&gt;Could you possibly share your entire main.c file, or at least all the SAADC related code from your application?&lt;br /&gt;For example, how are you triggering sampling - are doing periodic sampling through PPI ( like in the SAADC example ), or are you calling the samples manually?&lt;/p&gt;
[quote user=""]I guess the problem occurs at this time.[/quote][quote user=""]Also, when I use printf function to see value in PC, same problem occurs.[/quote]
&lt;p&gt;I assume these values are a list of returned SAADC samples? If so, what were you sampling, and what were you expecting?&lt;br /&gt;It seems you have a 10x value halfway through this list. Is this expected?&lt;br /&gt;Since I know nothing about what you are sampling, I also do not know if this 10 x spike is as expected. If it is, I have no idea what you would like me to read from this list - please elaborate.&amp;nbsp;&lt;/p&gt;
[quote user=""]How can I solve this?[/quote]
&lt;p&gt;I do not yet know enough about the issue to help you resolve it, but I look forward to resolving this issue together!&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>