<?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>Sleep current is high after  using SAADC</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/75983/sleep-current-is-high-after-using-saadc</link><description>Hi, 
 There is a similar case: 
 High power consumption in sleep mode after using SAADC 
 But I am using the SAADC driver version 2.0 because the oversampling feature is only supported in new driver, low power mode is not supported. 
 My environments</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 15 Jun 2021 04:21:47 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/75983/sleep-current-is-high-after-using-saadc" /><item><title>RE: Sleep current is high after  using SAADC</title><link>https://devzone.nordicsemi.com/thread/315265?ContentTypeID=1</link><pubDate>Tue, 15 Jun 2021 04:21:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:54cfc7d4-07ee-45f0-b80d-de56309de31b</guid><dc:creator>leox</dc:creator><description>&lt;p&gt;Hi Roy,&lt;/p&gt;
&lt;p&gt;Please find the attached source code, tested with a nRF52840DK, &amp;nbsp;it works ok now with low power on multi&amp;nbsp; ADC channels.&lt;/p&gt;
&lt;p&gt;1: apply the errata 212 which helped. More details on this errata: &lt;a href="https://infocenter.nordicsemi.com/topic/errata_nRF52840_Rev2/ERR/nRF52840/Rev2/latest/anomaly_840_212.html"&gt;https://infocenter.nordicsemi.com/topic/errata_nRF52840_Rev2/ERR/nRF52840/Rev2/latest/anomaly_840_212.html&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;As the source code re-configure the ADC on each timeout. So it&amp;rsquo;s ok to apply this workaround.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;2: change this &amp;nbsp;to 1 to use the workaround, 0: not to use.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #define ENABLE_ERRATA_212_WORKAROUND&amp;nbsp; 1&lt;/p&gt;
&lt;p&gt;3: Also noticed the second ADC output always 0, &amp;nbsp;now it&amp;rsquo;s ok with buffer index +1 instead &lt;strong&gt;+2&lt;/strong&gt; &amp;ldquo;NRF_LOG_INFO(&amp;quot;%d %d&amp;quot;, *(uint16_t *)p_event-&amp;gt;data.done.p_buffer, *(uint16_t *)(p_event-&amp;gt;data.done.p_buffer + &lt;strong&gt;1&lt;/strong&gt;));&amp;rdquo;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/5850.ble_5F00_app_5F00_saadc_5F00_sample.7z"&gt;devzone.nordicsemi.com/.../5850.ble_5F00_app_5F00_saadc_5F00_sample.7z&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sleep current is high after  using SAADC</title><link>https://devzone.nordicsemi.com/thread/315245?ContentTypeID=1</link><pubDate>Mon, 14 Jun 2021 21:25:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:90652abc-983d-4e0c-9899-a1ebe35858e8</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello Roy,&lt;br /&gt;&lt;br /&gt;Thank you for your patience, and&amp;nbsp;for testing this and getting back to me with your findings.&lt;br /&gt;I find this even more strange, and I will need to confer with our development and test teams, to see if they have any input.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I will let you know as soon as I have discussed this issue with them.&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: Sleep current is high after  using SAADC</title><link>https://devzone.nordicsemi.com/thread/314302?ContentTypeID=1</link><pubDate>Tue, 08 Jun 2021 23:21:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1f4eacb4-7441-4ca1-8633-a1de7503c568</guid><dc:creator>Roy Huang</dc:creator><description>&lt;p&gt;Hi Karl,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;For your suggestion:&lt;/p&gt;
&lt;p&gt;1. I tried inserting code &amp;quot;nrf_saadc_task_trigger(NRF_SAADC_TASK_STOP);&amp;quot; in SaadcHandler, but no difference.&lt;/p&gt;
&lt;p&gt;2. I tried to check the state bit in register HFCLKSTAT, but whatever sample one channel or two channels, this bit is always 1, so I guess I have no way to find out whether HFCLK is running when CPU is sleeping.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best Regards,&lt;/p&gt;
&lt;p&gt;Roy&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sleep current is high after  using SAADC</title><link>https://devzone.nordicsemi.com/thread/314199?ContentTypeID=1</link><pubDate>Tue, 08 Jun 2021 12:03:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a8f389c-2f64-4b0f-836a-5e30bade6ffb</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&lt;span&gt;Roy Huang,&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Thank you for your patience, and thank you for the very thorough description of your issue!&lt;br /&gt;&lt;br /&gt;This does indeed sound very strange, and I do not immediately see any flaws in your description or included code.&lt;br /&gt;I have discussed this with some colleagues, and it sounds similar to an issue we&amp;#39;ve heard of earlier, where the High Frequency CLK is never released and thus is left running. This corresponds well with the 600 µA increase in current you report.&lt;br /&gt;&lt;br /&gt;Could you try to call &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fps_nrf52840%2Fsaadc.html&amp;amp;anchor=register.TASKS_STOP"&gt;TASKS_STOP&lt;/a&gt;&amp;nbsp;at the end of your&amp;nbsp;NRFX_SAADC_EVT_DONE event handling?&lt;br /&gt;Alternatively, could you &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fps_nrf52840%2Fclock.html&amp;amp;anchor=register.HFCLKSTAT"&gt;check whether the status of the HFCLK is Running&lt;/a&gt; when the increase in current consumption is present?&lt;br /&gt;&lt;br /&gt;I will test your example here on my end shortly, to see if I can see the same behavior. If I am able to reproduce this I will open an internal ticket with our developers, so that they may examine this more closely.&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: Sleep current is high after  using SAADC</title><link>https://devzone.nordicsemi.com/thread/313531?ContentTypeID=1</link><pubDate>Fri, 04 Jun 2021 03:34:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cd04fe87-9630-4be5-9353-02fb43b4069e</guid><dc:creator>Roy Huang</dc:creator><description>&lt;p&gt;Here is my code to reproduce this issue and I changed it from ble_peripheral ble_app_blinky example in SDK 17.02&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define NUM_ADC_CHANNELS 1
// #define NUM_ADC_CHANNELS 2

static nrf_saadc_value_t samples[NUM_ADC_CHANNELS];
APP_TIMER_DEF(m_sample_timer);

static uint8_t m_event_type;

static void UninitAdc(void * event_data, uint16_t event_size)
{

    ASSERT(*(uint8_t*)event_data == 0x1);
    NRF_LOG_DEBUG(&amp;quot;Uninit ADC&amp;quot;);

    nrfx_saadc_uninit();
    NRF_SAADC-&amp;gt;INTENCLR = (SAADC_INTENCLR_END_Clear &amp;lt;&amp;lt; SAADC_INTENCLR_END_Pos);
    NVIC_ClearPendingIRQ(SAADC_IRQn);
}


static void SaadcHandler(nrfx_saadc_evt_t const * p_event)
{
    if (p_event-&amp;gt;type == NRFX_SAADC_EVT_DONE)
    {
        ASSERT(p_event-&amp;gt;data.done.size == NUM_ADC_CHANNELS);

        NRF_LOG_INFO(&amp;quot;%d %d&amp;quot;, *(uint16_t *)p_event-&amp;gt;data.done.p_buffer, *(uint16_t *)(p_event-&amp;gt;data.done.p_buffer + 2));

        m_event_type = 0x1;
        ret_code_t err_code = app_sched_event_put(&amp;amp;m_event_type, sizeof(m_event_type), UninitAdc);
        APP_ERROR_CHECK(err_code);
    }
}

static void SampleHandler(void * p_context)
{
    uint8_t adc_channel_mask;
    ret_code_t err_code;

#if (NUM_ADC_CHANNELS == 1)
    nrfx_saadc_channel_t channels[NUM_ADC_CHANNELS] = {NRFX_SAADC_DEFAULT_CHANNEL_SE(NRF_SAADC_INPUT_AIN3, 0)};
#else
    nrfx_saadc_channel_t channels[NUM_ADC_CHANNELS] = {NRFX_SAADC_DEFAULT_CHANNEL_SE(NRF_SAADC_INPUT_AIN3, 0),
                                                       NRFX_SAADC_DEFAULT_CHANNEL_SE(NRF_SAADC_INPUT_AIN2, 1)};
#endif

    /* Use gain 1/4 for all conversions */
    for (uint8_t i = 0; i &amp;lt; NUM_ADC_CHANNELS; ++i)
    {
        channels[i].channel_config.gain = NRF_SAADC_GAIN1_4;
    }

    err_code = nrfx_saadc_init(NRFX_SAADC_CONFIG_IRQ_PRIORITY);
    APP_ERROR_CHECK(err_code);

    err_code = nrfx_saadc_channels_config(channels, NUM_ADC_CHANNELS);
    APP_ERROR_CHECK(err_code);

    for (uint8_t i = 0; i &amp;lt; NUM_ADC_CHANNELS; ++i)
    {
        adc_channel_mask |= 1 &amp;lt;&amp;lt; i;
    }

    err_code = nrfx_saadc_simple_mode_set(adc_channel_mask,
                                          NRF_SAADC_RESOLUTION_12BIT,
                                          NRF_SAADC_OVERSAMPLE_16X,
                                          SaadcHandler);
    APP_ERROR_CHECK(err_code);

    err_code = nrfx_saadc_buffer_set(samples, NUM_ADC_CHANNELS);
    APP_ERROR_CHECK(err_code);

    err_code = nrfx_saadc_mode_trigger();
    APP_ERROR_CHECK(err_code);
    
    NRF_LOG_INFO(&amp;quot;Sample started&amp;quot;);
}

void SampleInit(void)
{
    ret_code_t err_code;

    app_timer_create(&amp;amp;m_sample_timer,
                        APP_TIMER_MODE_REPEATED,
                        SampleHandler);

    err_code = app_timer_start(
        m_sample_timer,
        APP_TIMER_TICKS(2000), NULL);
}

/**@brief Function for application main entry.
 */
int main(void)
{
    // Initialize.
    log_init();
    // leds_init();
    timers_init();
    // buttons_init();
    power_management_init();
    APP_SCHED_INIT(1, 10);
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();

    // Start execution.
    NRF_LOG_INFO(&amp;quot;Blinky example started.&amp;quot;);
    advertising_start();

    SampleInit();

    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
        app_sched_execute();
    }
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Below is the current curve from PPK2 when only one channel is sampled, advertising interval is about 800ms. Every 2 seconds, SAADC is enabled, after sampling, SAADC is disabled. It works fine.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/800x240/__key/communityserver-discussions-components-files/4/current1.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Current curve from PPK2 when two channels are sampled.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/600x155/__key/communityserver-discussions-components-files/4/current2.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I attached the code which is modified from the ble_app_blinky example and can reproduce this phenomenon.&lt;/p&gt;
&lt;p&gt;Unzip it to directory examples\ble_peripheral.&lt;/p&gt;
&lt;p&gt;There is an macro NUM_ADC_CHANNELS at line 564 in file main.c. When it is defined as 1, only one channel is sampled; when defined as 2, two channel are sampled.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/ble_5F00_app_5F00_saadc_5F00_sample.7z"&gt;devzone.nordicsemi.com/.../ble_5F00_app_5F00_saadc_5F00_sample.7z&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>