<?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>Measuring the battery voltage with nRF52832</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/14486/measuring-the-battery-voltage-with-nrf52832</link><description>Hi! 
 To measure the voltage level of a coin cell CR2450 can be done in different ways.
You can use the comparator, the low power comparator or the ADC.
I wonder which one is the most adequate to use and affects least the current consumption?
The</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 01 Sep 2022 12:41:19 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/14486/measuring-the-battery-voltage-with-nrf52832" /><item><title>RE: Measuring the battery voltage with nRF52832</title><link>https://devzone.nordicsemi.com/thread/384341?ContentTypeID=1</link><pubDate>Thu, 01 Sep 2022 12:41:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:14a6b815-cc29-47f8-beda-1a31f6a3ec80</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;With the nRF Connect SDK you can refer to the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.0.2/nrf/applications/nrf_desktop/doc/battery_meas.html"&gt;Battery measurement module&lt;/a&gt;&amp;nbsp;in nRF Desktop.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Measuring the battery voltage with nRF52832</title><link>https://devzone.nordicsemi.com/thread/384164?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2022 13:43:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9eae070f-3a0c-494f-8506-d085ba033212</guid><dc:creator>MDF</dc:creator><description>&lt;p&gt;Hi there&lt;/p&gt;
&lt;p&gt;I&amp;#39;m still wondering why there is no sample code from Nordic for measuring the battery voltage - BLE means low energy, it should be most common to have such a feature in the samples....&lt;/p&gt;
&lt;p&gt;Anyway, I need the battery level for a 52832 application and - thanks to you guys - I was able to use this code.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m using NCS 1.9.1 and like to notice that some things are different:&lt;/p&gt;
&lt;p&gt;- make sure you&amp;#39;ll #include &amp;quot;hal/nrf_saadc.h&amp;quot;&lt;br /&gt;- nrf_saadc_channel_config_t has not longer &amp;quot;pin_p&amp;quot; or &amp;quot;pin_n&amp;quot; members&lt;br /&gt;- all calls to nrf_saadc.... routines need an additional NRF_SAADC_Type* argument, I simply used NRF_SAADC&lt;br /&gt;- I was so far not able to validate whether ADC12_COUNTS_PER_VOLT = 4551 is correct in my case&lt;/p&gt;
&lt;p&gt;hope this might help others...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Measuring the battery voltage with nRF52832</title><link>https://devzone.nordicsemi.com/thread/193241?ContentTypeID=1</link><pubDate>Mon, 17 Jun 2019 15:44:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:15215421-a95b-46b1-8c4c-7a4eedf5ca4e</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Yes, if you mean can you copy it - feel free. If the battery voltage read fails note it returns the value 9999 as a warning/error - easily spotted in a log.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Measuring the battery voltage with nRF52832</title><link>https://devzone.nordicsemi.com/thread/193058?ContentTypeID=1</link><pubDate>Mon, 17 Jun 2019 06:15:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8b2a8d55-514d-433f-82b8-25480a371f7b</guid><dc:creator>gain</dc:creator><description>&lt;p&gt;HI,&lt;/p&gt;
&lt;p&gt;Is this code reusable ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Measuring the battery voltage with nRF52832</title><link>https://devzone.nordicsemi.com/thread/129422?ContentTypeID=1</link><pubDate>Mon, 23 Apr 2018 22:35:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2e4c0f86-e7f6-4262-a41f-3284732764c8</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Try this; I wrote it for polled mode for occasional low-power monitoring of CR2032 coin cells with no external components; that assumes of course no regulator or LDO or series schottky diode between coin cell and nRF52832:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Input range of internal Vdd measurement = (0.6 V)/(1/6) = 3.6 V
// 3.0 volts -&amp;gt; 14486 ADC counts with 14-bit sampling: 4828.8 counts per volt
#define ADC12_COUNTS_PER_VOLT 4551

/**
 * @brief Function for 14-bit adc init in polled mode
 */
void Adc12bitPolledInitialise(void)
{
    uint32_t timeout = 10;
    nrf_saadc_channel_config_t myConfig =
    {
        .resistor_p = NRF_SAADC_RESISTOR_DISABLED,
        .resistor_n = NRF_SAADC_RESISTOR_DISABLED,
        .gain       = NRF_SAADC_GAIN1_6,
        .reference  = NRF_SAADC_REFERENCE_INTERNAL,
        .acq_time   = NRF_SAADC_ACQTIME_40US,
        .mode       = NRF_SAADC_MODE_SINGLE_ENDED,
        .burst      = NRF_SAADC_BURST_ENABLED,
        .pin_p      = NRF_SAADC_INPUT_VDD,
        .pin_n      = NRF_SAADC_INPUT_DISABLED
    };

    nrf_saadc_resolution_set((nrf_saadc_resolution_t) 3);   // 3 is 14-bit
    nrf_saadc_oversample_set((nrf_saadc_oversample_t) 2);   // 2 is 4x, about 150uSecs total
    nrf_saadc_int_disable(NRF_SAADC_INT_ALL);
    nrf_saadc_event_clear(NRF_SAADC_EVENT_END);
    nrf_saadc_event_clear(NRF_SAADC_EVENT_STARTED);
    nrf_saadc_enable();

    NRF_SAADC-&amp;gt;CH[1].CONFIG =
              ((myConfig.resistor_p &amp;lt;&amp;lt; SAADC_CH_CONFIG_RESP_Pos)   &amp;amp; SAADC_CH_CONFIG_RESP_Msk)
            | ((myConfig.resistor_n &amp;lt;&amp;lt; SAADC_CH_CONFIG_RESN_Pos)   &amp;amp; SAADC_CH_CONFIG_RESN_Msk)
            | ((myConfig.gain       &amp;lt;&amp;lt; SAADC_CH_CONFIG_GAIN_Pos)   &amp;amp; SAADC_CH_CONFIG_GAIN_Msk)
            | ((myConfig.reference  &amp;lt;&amp;lt; SAADC_CH_CONFIG_REFSEL_Pos) &amp;amp; SAADC_CH_CONFIG_REFSEL_Msk)
            | ((myConfig.acq_time   &amp;lt;&amp;lt; SAADC_CH_CONFIG_TACQ_Pos)   &amp;amp; SAADC_CH_CONFIG_TACQ_Msk)
            | ((myConfig.mode       &amp;lt;&amp;lt; SAADC_CH_CONFIG_MODE_Pos)   &amp;amp; SAADC_CH_CONFIG_MODE_Msk)
            | ((myConfig.burst      &amp;lt;&amp;lt; SAADC_CH_CONFIG_BURST_Pos)  &amp;amp; SAADC_CH_CONFIG_BURST_Msk);

    NRF_SAADC-&amp;gt;CH[1].PSELN = myConfig.pin_n;
    NRF_SAADC-&amp;gt;CH[1].PSELP = myConfig.pin_p;
}

/**
 * @brief Function for 14-bit adc battery voltage by direct blocking reading
 */
uint16_t GetBatteryVoltage1(void)
{
    uint16_t result = 9999;         // Some recognisable dummy value
    uint32_t timeout = 10000;       // Trial and error
    volatile int16_t buffer[8];
    // Enable command
    nrf_saadc_enable();
    NRF_SAADC-&amp;gt;RESULT.PTR = (uint32_t)buffer;
    NRF_SAADC-&amp;gt;RESULT.MAXCNT = 1;
    nrf_saadc_event_clear(NRF_SAADC_EVENT_END);
    nrf_saadc_task_trigger(NRF_SAADC_TASK_START);
    nrf_saadc_task_trigger(NRF_SAADC_TASK_SAMPLE);

    while (0 == nrf_saadc_event_check(NRF_SAADC_EVENT_END) &amp;amp;&amp;amp; timeout &amp;gt; 0)
    {
        timeout--;
    }
    nrf_saadc_task_trigger(NRF_SAADC_TASK_STOP);
    nrf_saadc_event_clear(NRF_SAADC_EVENT_STARTED);
    nrf_saadc_event_clear(NRF_SAADC_EVENT_END);
    // Disable command to reduce power consumption
    nrf_saadc_disable();
    if (timeout != 0)
    {
        result = ((buffer[0] * 1000L)+(ADC12_COUNTS_PER_VOLT/2)) / ADC12_COUNTS_PER_VOLT;
    }
    return result;
}

&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Measuring the battery voltage with nRF52832</title><link>https://devzone.nordicsemi.com/thread/129407?ContentTypeID=1</link><pubDate>Mon, 23 Apr 2018 16:23:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:12239a7d-1f1a-4e25-818b-982f834d1678</guid><dc:creator>Renato Silva</dc:creator><description>&lt;p&gt;I am trying to resolve the same problem. Anyone can to resolved this question?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div id="selenium-highlight"&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Measuring the battery voltage with nRF52832</title><link>https://devzone.nordicsemi.com/thread/55307?ContentTypeID=1</link><pubDate>Sat, 19 Aug 2017 20:15:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c7ddc011-a504-4bd3-8ba9-eb0c724f6b07</guid><dc:creator>Krishna</dc:creator><description>&lt;p&gt;Hi Stefan,
I didn&amp;#39;t understood the configuration to read battery voltage .Also the links you given in explanation are blank.
How can i measure the battery voltage using your example?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Measuring the battery voltage with nRF52832</title><link>https://devzone.nordicsemi.com/thread/55308?ContentTypeID=1</link><pubDate>Wed, 17 May 2017 08:33:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d463447a-3b72-416d-b17e-ba65f3e3b024</guid><dc:creator>Bimal</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Found Intresting,
Still i have one quick query,
What are the setting available in Resistor ladder?
As we will require to do so. we are measuring 3V(CR2032) battery with ADC internal ref=0.6V.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Measuring the battery voltage with nRF52832</title><link>https://devzone.nordicsemi.com/thread/55306?ContentTypeID=1</link><pubDate>Fri, 17 Jun 2016 10:13:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ea9434ac-ac9f-47e7-af82-f03945e0f87c</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Hi Nixon&lt;/p&gt;
&lt;p&gt;All options can be low current, also the SAADC when used for battery measuring. I suspect the LPCOMP/COMP and Power Failure warnings generate more of low battery warning events, while the SAADC provides actual battery monitoring. If you use the SAADC to sample once a second or less, I suspect it will add less than 1uA to the current consumption. This is not given though, you have to set the SAADC up correctly in order to achieve low current. The default saadc example in the nRF5 SDK 11.0.0 conumes around 2mA. I attach a low power SAADC example for you to explore, which uses RTC to trigger sampling. I have tested it with &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52/dita/nrf52/compatibility_matrix/ic_rev_sdk_sd_comp_matrix.html?cp=2_1_2"&gt;SDK 11.0.0 and nRF52832 revision 1&lt;/a&gt;. The SAADC is only enabled before sampling and disabled when sampling completes to avoid high current consumption of the EasyDMA.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/saadc_5F00_low_5F00_power_5F00_with_5F00_rtc.zip"&gt;saadc_low_power_with_rtc.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This example is sampling on an intput pin. To sample the battery voltage which the nRF52832 IC is powered with, configure the SAADC channel you use to be &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.0/saadc.html?cp=2_2_0_35_10_7#register.CH-0.CONFIG"&gt;single ended&lt;/a&gt;, the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.0/saadc.html?cp=2_2_0_35_10_5#register.CH-0.PSELP"&gt;input on PSELP as VDD&lt;/a&gt; and &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.0/saadc.html?cp=2_2_0_35_10_7#register.CH-0.CONFIG"&gt;gain as 1/6&lt;/a&gt;, which will measure the battery voltage directly and give the SAADC range from 0V to 3.6V.&lt;/p&gt;
&lt;p&gt;Let me know if my message is unclear or if there are any questions&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>