<?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>nRF51: IoT-SDK and current consumption / sleep modes</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/17654/nrf51-iot-sdk-and-current-consumption-sleep-modes</link><description>Hello again, 
 fortunately I made some progress using the IoT-SDK v0.8.0 on nRF51. I extended the MQTT-example to my needs, but there are still some questions.
The final device is battery-powered and should transmit some sensor values periodically,</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 06 Jan 2017 10:35:44 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/17654/nrf51-iot-sdk-and-current-consumption-sleep-modes" /><item><title>RE: nRF51: IoT-SDK and current consumption / sleep modes</title><link>https://devzone.nordicsemi.com/thread/67892?ContentTypeID=1</link><pubDate>Fri, 06 Jan 2017 10:35:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1486665f-6002-4cc5-b93a-d54f3f19210d</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;app_timer is using RTC1, and the softdevice is using RTC0. The softdevice uses TIMER only for radio activity, and turns this on only during the BLE event.&lt;/p&gt;
&lt;p&gt;TIMER =&amp;gt; HF clock =&amp;gt; high current consumption&lt;/p&gt;
&lt;p&gt;RTC =&amp;gt; LF clock =&amp;gt; low current consumption&lt;/p&gt;
&lt;p&gt;So, you don&amp;#39;t want the TIMER to be running all the time because it uses a lot of current, that&amp;#39;s why both the softdevice and app_timer uses the RTC peripherals. TIMER is only active when you need a very high accuracy (like the radio link).&lt;/p&gt;
&lt;p&gt;When you call ble_stack_init() you set which source you want for the RTC0. In the code you pasted above you tell the SD that your LF clock source is an external crystal with a minimum accuracy of 20ppm.&lt;/p&gt;
&lt;p&gt;nrf_drv_timer is the driver for the TIMER peripheral and has nothing to do with app_timer.&lt;/p&gt;
&lt;p&gt;Creating an app timer is pretty simple. It is documented &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v12.2.0/lib_timer.html?cp=4_0_1_3_33"&gt;here&lt;/a&gt;. You can do something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#define APP_TIMER_OP_QUEUE_SIZE 3                                  // Increase this by one
#define MYTIMER_INTERVAL APP_TIMER_TICKS(100, APP_TIMER_PRESCALER) // Set the interval of your timer
static app_timer_id_t m_mytimer_id;                                // Your timer id

//Create a timeout handler:
static void mytimer_timeout_handler(void * p_context){
    NRF_POWER-&amp;gt;SYSTEMOFF = 1;
}

// Register your timer in the main() function:
app_timer_create(&amp;amp;m_mytimer_id, APP_TIMER_MODE_REPEATED, mytimer_timeout_handler);
app_timer_start(m_mytimer_id, MYTIMER_INTERVAL, NULL);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The transmission power of the radio is set using this SD call: &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v3.0.0/group___b_l_e___g_a_p___f_u_n_c_t_i_o_n_s.html?#ga0f1931af876bef39520c58de5ac060ca"&gt;sd_ble_gap_tx_power_set()&lt;/a&gt;. Call this after ble_stack_init()&lt;/p&gt;
&lt;p&gt;&lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v0.9.0/group___n_r_f___s_o_c___f_u_n_c_t_i_o_n_s.html?#ga11d88d38ac99fb72cde74c9385d36433"&gt;sd_app_evt_wait()&lt;/a&gt; should be called in the main loop to ensure that the chip is in the lowest possible power consumption state. This is the System ON IDLE state which means that the CPU is sleeping, but other peripherals like the RTC is running so that it can wake up the CPU on f.ex. an app_timer event.&lt;/p&gt;
&lt;p&gt;The only mode that uses less power than System ON IDLE is &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/power.html?#unique_863354678"&gt;System OFF mode&lt;/a&gt;. But then no RTCs are running, which means that the only way to wake up the chip is through an external event on a GPIO pin, LPCOMP, NFC or a reset. On other words, the chip cannot wake up itself from SysOFF.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>