<?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>I used two channel saadc, but not all the time the same channel adc value has same index.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/76716/i-used-two-channel-saadc-but-not-all-the-time-the-same-channel-adc-value-has-same-index</link><description>I used 2 channel saadc, channel 1 and channel 3. 
 Maybe in the first few minutes, it&amp;#39;s done ok, 
 p_event-&amp;gt;data.done.p_buffer[0] is belong channel1 adc value 
 p_event-&amp;gt;data.done.p_buffer[1] is belong channel3 adc value 
 
 but, it will run error, 
</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 25 Jun 2021 08:19:36 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/76716/i-used-two-channel-saadc-but-not-all-the-time-the-same-channel-adc-value-has-same-index" /><item><title>RE: I used two channel saadc, but not all the time the same channel adc value has same index.</title><link>https://devzone.nordicsemi.com/thread/317151?ContentTypeID=1</link><pubDate>Fri, 25 Jun 2021 08:19:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bba9bfc3-1886-4b11-8b4c-e9b5ec15e60b</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user="suhaihui"]I have solved this issue.[/quote]
&lt;p&gt;Great, I am happy to hear that the issue is resolved!&lt;br /&gt;Did you pinpoint exactly what the issue was here? I see that you have changed your new buffers to be setup in the timeout handler instead of the callback function, is that it?&lt;br /&gt;&lt;br /&gt;I highly recommend that you trigger the SAADC sampling by connecting your TIMER CC event to the SAADC&amp;#39;s TASKS_SAMPLE task through PPI, like shown in the SAADC example.&lt;br /&gt;By triggering it through PPI the CPU does not have to be involved in triggering every sample, which is especially nice if you have a high-priority process running in parallel (like the SoftDevice).&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: I used two channel saadc, but not all the time the same channel adc value has same index.</title><link>https://devzone.nordicsemi.com/thread/317129?ContentTypeID=1</link><pubDate>Fri, 25 Jun 2021 07:37:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ad939a33-108b-4109-8883-4ec25902ad30</guid><dc:creator>suhaihui</dc:creator><description>&lt;p&gt;Hi, i just do adc calibration once.&lt;/p&gt;
&lt;p&gt;I have solved this issue.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;define SAMPLE_CHANNEL_CNT                                           2
#define SAMPLE_CNT      			                                1

#define ADC_TASK_TIMER                                  APP_TIMER_TICKS(5)
APP_TIMER_DEF(m_adc_task_timer_id);             

/*&amp;lt;adc sample value buffer*/
static nrf_saadc_value_t       m_buffer[SAMPLE_CHANNEL_CNT];

static void adc_timeout_handler(void* p_context);
static void saadc_callback(nrf_drv_saadc_evt_t const * p_event);
static uint16_t mean_value_calc(int16_t* data_buffer, uint8_t size);

void saadc_module_init(void)
{
    ret_code_t err_code;
    
    nrfx_saadc_config_t saadc_config = NRF_DRV_SAADC_DEFAULT_CONFIG;
    saadc_config.resolution = NRF_SAADC_RESOLUTION_14BIT;
    saadc_config.interrupt_priority = 1;        
    saadc_config.low_power_mode = false;
    
    err_code = nrf_drv_saadc_init(&amp;amp;saadc_config, saadc_callback);
    APP_ERROR_CHECK(err_code);
    
    // do a calibrate
    while (nrf_drv_saadc_calibrate_offset() != NRFX_SUCCESS)
        nrf_delay_ms(10);
    while (nrf_drv_saadc_is_busy())
        nrf_delay_ms(10);
    
    pressure_adc_init();
    battery_saadc_init();
    
    err_code = app_timer_create(&amp;amp;m_adc_task_timer_id, APP_TIMER_MODE_REPEATED, adc_timeout_handler);
    APP_ERROR_CHECK(err_code);  
}

void saadc_module_start(void)
{
    ret_code_t err_code;
    
    err_code = app_timer_start(m_adc_task_timer_id, ADC_TASK_TIMER, NULL);
    APP_ERROR_CHECK(err_code);    
}

static void adc_timeout_handler(void* p_context)
{
    ret_code_t err_code;
    
    if(!nrf_drv_saadc_is_busy())
    {
        err_code = nrf_drv_saadc_buffer_convert(&amp;amp;m_buffer[0], 1);
        APP_ERROR_CHECK(err_code);  
        err_code = nrf_drv_saadc_buffer_convert(&amp;amp;m_buffer[1], 1);
        APP_ERROR_CHECK(err_code);  
        
        APP_ERROR_CHECK(nrf_drv_saadc_sample());
    }
}


/**@brief adc module call back
 *
 * @param[in]   p_event   adc module event
 *
 */
static void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
    uint32_t                    err_code;
    
    if (p_event-&amp;gt;type == NRF_DRV_SAADC_EVT_DONE)
    {
//        err_code = nrf_drv_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer, SAMPLE_CHANNEL_CNT);
//        APP_ERROR_CHECK(err_code);
        
        pressure_adc_update(m_buffer[0]);
        battery_saadc_update(m_buffer[1]);
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I used two channel saadc, but not all the time the same channel adc value has same index.</title><link>https://devzone.nordicsemi.com/thread/316983?ContentTypeID=1</link><pubDate>Thu, 24 Jun 2021 12:26:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0076e770-a851-41d4-9463-ec33589d259d</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;br /&gt;&lt;br /&gt;How often are you doing offset calibration? This might be caused by &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Ferrata_nRF52840_Rev2%2FERR%2FnRF52840%2FRev2%2Flatest%2Fanomaly_840_237.html&amp;amp;cp=4_0_1_0_1_44"&gt;the Errata 237&lt;/a&gt;&amp;nbsp;which can cause an unexpected sample to be written to the RAM. This will shift your buffer, leading to behavior as you describe. Please make sure to have the workaround implemented and try this again, and tell me if this resolves your issue.&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>