<?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>Need help with battery example</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/93510/need-help-with-battery-example</link><description>OK, this will no doubt be an easy one. I&amp;#39;m playing around with the zephyr/samples/boards/nrf/battery example, as I have a need for something similar in my own application. My environment is: 
 
 Visual Studio Code with nRF Connect extension 
 nRF Connect</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 07 Feb 2023 13:50:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/93510/need-help-with-battery-example" /><item><title>RE: Need help with battery example</title><link>https://devzone.nordicsemi.com/thread/408579?ContentTypeID=1</link><pubDate>Tue, 07 Feb 2023 13:50:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6efce783-169a-4ca3-a3ad-a85347c89d36</guid><dc:creator>BehicMV</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;If you done it, can you help&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/96407/cant-build-zephyr-battery-example"&gt;this ticket&lt;/a&gt;&amp;nbsp;?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Need help with battery example</title><link>https://devzone.nordicsemi.com/thread/394285?ContentTypeID=1</link><pubDate>Sun, 06 Nov 2022 23:14:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5b8d8efb-d7c9-43d3-8f58-58ece043d752</guid><dc:creator>Mike Austin (LPI)</dc:creator><description>&lt;p&gt;Thanks Jared.&amp;nbsp; Think the penny dropped for me about the same time you sent that explanation through.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve actually got a similar circuit set up on my custom board, except I&amp;#39;m using P0.30 as my BAT_MON_EN signal, and at the moment I have two 150K resistors as my resistor divider network.&lt;/p&gt;
&lt;p&gt;So, I modified my overlay file to this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/ {
    vbatt {
       compatible = &amp;quot;voltage-divider&amp;quot;;
       io-channels = &amp;lt;&amp;amp;adc 0&amp;gt;;
       output-ohms = &amp;lt;150000&amp;gt;;
       full-ohms = &amp;lt;(150000 + 150000)&amp;gt;;
       power-gpios = &amp;lt;&amp;amp;gpio0 30 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)&amp;gt;;
    };
 };&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And everything works as expected&lt;/p&gt;
&lt;p&gt;Thanks again&lt;/p&gt;
&lt;p&gt;Mike&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Need help with battery example</title><link>https://devzone.nordicsemi.com/thread/394111?ContentTypeID=1</link><pubDate>Fri, 04 Nov 2022 10:10:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ca2616ca-7a0f-4370-9f89-1650a480ade1</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi Mike,&lt;/p&gt;
&lt;p&gt;Great, that you found the solution!&lt;/p&gt;
[quote user="Mike Austin (LPI)"]One other question - the power-gpios is an optional parameter in the vbatt node.&amp;nbsp; What actually is that for?&amp;nbsp; I&amp;#39;ve just commented it out in my application, but I&amp;#39;d like to understand what it does[/quote]
&lt;p&gt;From &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.1.99-ncs1/dts/bindings/adc/voltage-divider.yaml#L33-L40"&gt;here&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;power-gpios:&lt;br /&gt; type: phandle-array&lt;br /&gt; required: false&lt;br /&gt; description: |&lt;br /&gt; Control power to the voltage divider inputs.&lt;br /&gt; If present the corresponding GPIO must be set to an active level&lt;br /&gt; to enable the divider input.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;To be honest, I haven&amp;#39;t really used this child node before so not entirely sure how it&amp;#39;s used.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;EDIT: Actually, I found a use case where this child node would have been used. For example on our Thingy:52 we have a signal called BAT_MON_EN that &amp;quot;turns off&amp;quot; the voltage divider when it&amp;#39;s not in use:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1667557348070v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Need help with battery example</title><link>https://devzone.nordicsemi.com/thread/394024?ContentTypeID=1</link><pubDate>Thu, 03 Nov 2022 22:09:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ca26ba80-fa82-49cb-80af-be54686e83b7</guid><dc:creator>Mike Austin (LPI)</dc:creator><description>&lt;p&gt;Hi Jared,&lt;/p&gt;
&lt;p&gt;That was actually my objective - to use AIN0.&amp;nbsp; I didn&amp;#39;t realise that I also have to specify a channel though.&amp;nbsp; I probably need to understand a bit more about the SAADC function and how channels work - can you point me to some documentation that explains this part of it?&lt;/p&gt;
&lt;p&gt;Looking at the battery.c code, I was able to see what the issue is.&amp;nbsp; In this snippet:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;if (cfg-&amp;gt;output_ohm != 0) {
		accp-&amp;gt;input_positive = SAADC_CH_PSELP_PSELP_AnalogInput0
			+ iocp-&amp;gt;channel;
	} else {
		accp-&amp;gt;input_positive = SAADC_CH_PSELP_PSELP_VDD;
	}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;its basically setting the analog positive input channel to equal VDD if I haven&amp;#39;t added the vbatt definition to my overlay file.&amp;nbsp; Which explains why the output of the example code was sitting unchanged at ~ 3V even though I was varying the analog signal at P0.02.&lt;/p&gt;
&lt;p&gt;I added the following to my overlay file:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt; / {
    vbatt {
       compatible = &amp;quot;voltage-divider&amp;quot;;
       io-channels = &amp;lt;&amp;amp;adc 0&amp;gt;;
       output-ohms = &amp;lt;150000&amp;gt;;
       full-ohms = &amp;lt;(1500000 + 150000)&amp;gt;;
       //power-gpios = &amp;lt;&amp;amp;sx1509b 4 0&amp;gt;;
    };
 };&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And changed this section of battery.c:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;f (cfg-&amp;gt;output_ohm != 0) {
		accp-&amp;gt;input_positive = SAADC_CH_PSELP_PSELP_AnalogInput0;
			//+ iocp-&amp;gt;channel;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And now its working as I would expect.&lt;/p&gt;
&lt;p&gt;One other question - the power-gpios is an optional parameter in the vbatt node.&amp;nbsp; What actually is that for?&amp;nbsp; I&amp;#39;ve just commented it out in my application, but I&amp;#39;d like to understand what it does&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Mike&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Need help with battery example</title><link>https://devzone.nordicsemi.com/thread/393882?ContentTypeID=1</link><pubDate>Thu, 03 Nov 2022 13:05:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:25ccb794-58ef-4c02-96ef-192e43e32f6e</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi there MIke,&lt;/p&gt;
&lt;p&gt;I think that would setup the DK to use AIN0 and channel 0.&lt;/p&gt;
&lt;p&gt;The ADC examples sets the device to use the same pin number as the channel &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/78a9e8effce0366562b9bb1f4e08096fa4cb13b9/samples/boards/nrf/battery/src/battery.c#L126"&gt;here&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you want to use AIN2 and channel 0 then you have to set &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/78a9e8effce0366562b9bb1f4e08096fa4cb13b9/samples/boards/nrf/battery/src/battery.c#L126"&gt;this&lt;/a&gt;&amp;nbsp;line in the example to&amp;nbsp;&lt;span&gt;SAADC_CH_PSELP_PSELP_AnalogInput2 and omit &amp;quot;+ iocp-&amp;gt;&lt;span&gt;channel&amp;quot;.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;regards&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Jared&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>