<?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>Simultaneous implementation of AD conversion</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/98781/simultaneous-implementation-of-ad-conversion</link><description>Thank you for your assistance. We are currently using the nrf52840 board to implement the LED connection monitoring function and battery voltage monitoring function at the same time. We have previously implemented the battery voltage monitoring function</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 19 Apr 2023 08:53:03 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/98781/simultaneous-implementation-of-ad-conversion" /><item><title>RE: Simultaneous implementation of AD conversion</title><link>https://devzone.nordicsemi.com/thread/421193?ContentTypeID=1</link><pubDate>Wed, 19 Apr 2023 08:53:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ff523b4e-3fba-45c1-b6cc-de3b5f9c1265</guid><dc:creator>LemonCake</dc:creator><description>&lt;p&gt;Thank you for your assistance.&lt;br /&gt;Thank you very much for taking the time for me.&lt;br /&gt;I proceeded with the coding based on the advice you gave me, and was able to successfully complete the simultaneous implementation.&lt;br /&gt;Thank you very much.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Simultaneous implementation of AD conversion</title><link>https://devzone.nordicsemi.com/thread/421095?ContentTypeID=1</link><pubDate>Tue, 18 Apr 2023 15:48:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e31f093-e51c-4df7-a549-d39a2c5da2a3</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You should not call&amp;nbsp;nrf_drv_saadc_init() twice, with different event handlers. The driver only needs to be initialized once, unless you uninitialized the driver to stop using it at some point. Both channels will be sampled and accessible in the buffer pointed at in the common event handler, through&amp;nbsp;p_evt-&amp;gt;data.done.p_buffer[0] and&amp;nbsp;p_evt-&amp;gt;data.done.p_buffer[1].&lt;/p&gt;
&lt;p&gt;In the code you posted, both channels are set to&amp;nbsp;NRF_SAADC_INPUT_AIN5. Also make sure that&amp;nbsp;adc_buf is declared with space for two SAADC samples.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Simultaneous implementation of AD conversion</title><link>https://devzone.nordicsemi.com/thread/420893?ContentTypeID=1</link><pubDate>Tue, 18 Apr 2023 04:54:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ed8bfa79-cf6d-4cd3-9244-915ef6957775</guid><dc:creator>LemonCake</dc:creator><description>&lt;p&gt;Thank you very much for your reply.&lt;br /&gt;Regarding the content of the error, if you set two programs of the same type in es_battery_voltage_saadc.c as shown below and execute them in main (), both the battery voltage and the LED connection voltage will be output as 0. increase.&lt;br /&gt;Thank you very much.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void saadc_event_handler(nrf_drv_saadc_evt_t const * p_evt)
{
    if (p_evt-&amp;gt;type == NRF_DRV_SAADC_EVT_DONE)
    {
        nrf_saadc_value_t adc_result;

        adc_result = p_evt-&amp;gt;data.done.p_buffer[0];

        m_batt_lvl_in_milli_volts =
            ADC_RESULT_IN_MILLI_VOLTS(adc_result) + DIODE_FWD_VOLT_DROP_MILLIVOLTS;
    }
}

static void saadc_event_handler2(nrf_drv_saadc_evt_t const * p_evt)
{
    if (p_evt-&amp;gt;type == NRF_DRV_SAADC_EVT_DONE)
    {
        nrf_saadc_value_t adc_result;

        adc_result = p_evt-&amp;gt;data.done.p_buffer[0];

        m_batt_lvl_in_milli_volts2 =
            ADC_RESULT_IN_MILLI_VOLTS(adc_result) + DIODE_FWD_VOLT_DROP_MILLIVOLTS;
    }
}


void es_battery_voltage_init(void)
{
    ret_code_t err_code = nrf_drv_saadc_init(NULL, saadc_event_handler);

    APP_ERROR_CHECK(err_code);

    nrf_saadc_channel_config_t config =
        NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN5);
    err_code = nrf_drv_saadc_channel_init(0, &amp;amp;config);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_saadc_buffer_convert(&amp;amp;adc_buf, 2);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_saadc_sample();
    APP_ERROR_CHECK(err_code);
}


void es_battery_voltage_get(uint16_t * p_vbatt)
{
    VERIFY_PARAM_NOT_NULL_VOID(p_vbatt);

    *p_vbatt = m_batt_lvl_in_milli_volts;
    if (!nrf_drv_saadc_is_busy())
    {
        ret_code_t err_code = nrf_drv_saadc_buffer_convert(&amp;amp;adc_buf, 2);
        APP_ERROR_CHECK(err_code);

        err_code = nrf_drv_saadc_sample();
        APP_ERROR_CHECK(err_code);
    }
}

void led_monitor_init(void)
{
    ret_code_t err_code = nrf_drv_saadc_init(NULL, saadc_event_handler2);

    APP_ERROR_CHECK(err_code);

    nrf_saadc_channel_config_t config =
        NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN5);
    err_code = nrf_drv_saadc_channel_init(1, &amp;amp;config);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_saadc_buffer_convert(&amp;amp;adc_buf, 2);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_saadc_sample();
    APP_ERROR_CHECK(err_code);
}

void led_monitor_get(uint16_t * p_vbatt)
{
    VERIFY_PARAM_NOT_NULL_VOID(p_vbatt);

    *p_vbatt = m_batt_lvl_in_milli_volts2;
    if (!nrf_drv_saadc_is_busy())
    {
        ret_code_t err_code = nrf_drv_saadc_buffer_convert(&amp;amp;adc_buf, 2);
        APP_ERROR_CHECK(err_code);

        err_code = nrf_drv_saadc_sample();
        APP_ERROR_CHECK(err_code);
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Simultaneous implementation of AD conversion</title><link>https://devzone.nordicsemi.com/thread/420799?ContentTypeID=1</link><pubDate>Mon, 17 Apr 2023 13:43:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cfe42b1b-9e9b-4d60-b7fb-fb729b77b611</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Can you elaborate on what is not working with the code you tested?&lt;/p&gt;
&lt;p&gt;Once you have two channels enabled at the same time, the SAADC peripheral will enter scan mode, where each enabled channel is sampled consecutively each time you trigger the sample task. The samples will be &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/saadc.html#saadc_easydma"&gt;stored in the buffer&lt;/a&gt; as shown in the peripheral documentation. You need to increase the buffer size passed to&amp;nbsp;nrf_drv_saadc_buffer_convert() if you want to have two channels enabled at the same time.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>