{"id":5276,"date":"2017-03-07T15:18:51","date_gmt":"2017-03-07T07:18:51","guid":{"rendered":"http:\/\/www.rocketscream.com\/blog\/?post_type=portfolio&#038;p=5276"},"modified":"2017-03-09T17:30:43","modified_gmt":"2017-03-09T09:30:43","slug":"using-rtc-in-low-power-mode-on-mini-ultra-pro","status":"publish","type":"portfolio","link":"https:\/\/www.rocketscream.com\/blog\/docs-item\/using-rtc-in-low-power-mode-on-mini-ultra-pro\/","title":{"rendered":"Using RTC in Low Power Mode on Mini Ultra Pro"},"content":{"rendered":"<div  class='tabcontainer av-av_tab_container-cdfb33d025ccce82e3bec7780d128c1e sidebar_tab sidebar_tab_left  avia-builder-el-0  avia-builder-el-no-sibling  border_tabs'>\n<section class='av_tab_section av_tab_section av-av_tab-21127c225c921997827e1c80d5a962e2'  itemscope=\"itemscope\" itemtype=\"https:\/\/schema.org\/CreativeWork\" ><div id='tab-id-1-tab' class='tab active_tab' role='tab' aria-selected=\"true\" tabindex=\"0\" data-fake-id='#tab-id-1' aria-controls='tab-id-1-content'  itemprop=\"headline\" ><span class='tab_icon avia-iconfont avia-font-entypo-fontello' data-av_icon='\ue8a5' data-av_iconfont='entypo-fontello' ><\/span>Overview<\/div><div id='tab-id-1-content' class='tab_content active_tab_content' role='tabpanel' aria-labelledby='tab-id-1-tab' aria-hidden=\"false\"><div class='tab_inner_content invers-color'  itemprop=\"text\" ><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4410\" src=\"http:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/02\/MiniUltraProLithiumPolymer.jpg\" alt=\"\" width=\"600\" height=\"600\" srcset=\"https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/02\/MiniUltraProLithiumPolymer.jpg 600w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/02\/MiniUltraProLithiumPolymer-100x100.jpg 100w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/02\/MiniUltraProLithiumPolymer-80x80.jpg 80w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/02\/MiniUltraProLithiumPolymer-300x300.jpg 300w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/02\/MiniUltraProLithiumPolymer-36x36.jpg 36w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/02\/MiniUltraProLithiumPolymer-180x180.jpg 180w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>One of the most powerful feature of RTC is the ability to run in the lowest power mode possible on the ATSAMD21G18A-AU microcontroller. This allow the Mini Ultra Pro board to reside in ultra low power mode (<strong>21 \u00b5A or less<\/strong> of current only!) majority of the time and wake up upon alarm triggered by the RTC to perform scheduled tasks (sensor reading, data logging, radio communication, driving an actuator, etc).<\/p>\n<\/div><\/div><\/section>\n<section class='av_tab_section av_tab_section av-av_tab-59ac4863dec235d4c0eaf43fa0a230a1'  itemscope=\"itemscope\" itemtype=\"https:\/\/schema.org\/CreativeWork\" ><div id='tab-id-2-tab' class='tab' role='tab' aria-selected=\"false\" tabindex=\"0\" data-fake-id='#tab-id-2' aria-controls='tab-id-2-content'  itemprop=\"headline\" ><span class='tab_icon avia-iconfont avia-font-entypo-fontello' data-av_icon='\ue8a9' data-av_iconfont='entypo-fontello' ><\/span>Putting everything to sleep<\/div><div id='tab-id-2-content' class='tab_content' role='tabpanel' aria-labelledby='tab-id-2-tab' aria-hidden=\"true\"><div class='tab_inner_content invers-color'  itemprop=\"text\" ><p>Putting the Mini Ultra Pro into sleep mode (known as standby mode on the ATSAMD21 microcontroller series) will essentially stopping the main clock from running (which is also used to derived other clocks to drive peripherals).\u00a0The important aspect of putting the Mini Ultra Pro\u00a0into low power mode (a.k.a. sleep) is more than putting the microcontroller into standby mode. Identifying circuit components that could be driving excessive amount of current even when not in use is one of the crucial point to achieve the 21 \u03bcA or less of sleep current.<\/p>\n<p>The following are the list of components on the Mini Ultra Pro that we need to take care of in order to achieve the low power current consumption in\u00a0\u03bcA range.<\/p>\n<ol>\n<li>Radio module &#8211; either RFM95W or RFM69HCW:\n<ul>\n<li>Both radio module can be put into sleep mode and only draws 0.1 \u03bcA of current<\/li>\n<\/ul>\n<\/li>\n<li>Serial flash &#8211;\u00a0S25FL116K0XMFI041 16 Mbit (2 MByte):\n<ul>\n<li>The serial flash can be put into sleep mode and only draws 2 \u03bcA of current<\/li>\n<\/ul>\n<\/li>\n<li>USB core of ATSAMD21G18A:\n<ul>\n<li>USB bus must be in idle mode and in suspend condition in order to achieve low current mode<\/li>\n<\/ul>\n<\/li>\n<li>Pins not in use on the Mini Ultra Pro:\n<ul>\n<li>Pins that are not connected to any circuitry should be put into a defined state and not left floating<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>In this example, the RTC is configured to run in the background and an alarm is setup to wake up the microcontroller every 1 minute. Of course, this wake up interval can be configured as required by the application. The LED connected to pin D13 is toggle to indicate the sleep and wake up event. A Li-Ion\/Pol 3.7 V is used to power the setup.<\/p>\n<div id='avia-messagebox-' class='avia_message_box av_notification av-av_notification-774f0a4f170dc8724e42d8e0fffc6c2f avia-color-red avia-size-large avia-icon_select-yes avia-border-  avia-builder-el-1  avia-builder-el-no-sibling ' ><span class='avia_message_box_title' >Important<\/span><div class=\"avia_message_box_content\"><span class='avia_message_box_icon avia-iconfont avia-font-entypo-fontello' data-av_icon='\ue83e' data-av_iconfont='entypo-fontello' ><\/span><p>Take note that a 15 s delay in the beginning of the example is defined to provide ample amount of time for user to upload code before the USB device module detaches itself from the host. Once the Mini Ultra Pro board goes into low power mode, the PC will not be able to detect the USB serial port of the board unless the reset tact switch is press.<\/p>\n<\/div><\/div>\n<p>The measured current during sleep mode using the example code will result in\u00a021 \u03bcA of sleep current. The bulk of the 21 \u03bcA is\u00a0contributed by the on-board battery power management IC (BQ24074) but it is crucial to have a proper Li-Ion\/Pol battery power management like the BQ24074 is avoid shorter lifespan of the battery due to unnecessary charge and discharge cycle.<\/p>\n<pre>\/*******************************************************************************\r\n Mini Ultra Pro Sleep RTC Alarm\r\n Version: 0.10\r\n Date: 20-02-2017\r\n Company: Rocket Scream Electronics\r\n Author: Lim Phang Moh\r\n Website: www.rocketscream.com\r\n\r\n An example code demonstrating the ultra low sleep current capability of the \r\n Mini Ultra Pro while running the on-chip built-in RTC. Example puts the Mini\r\n Ultra Pro into standby mode (sleep) while RTC is allowed to run in the \r\n background. Alarm is set to wake the processor on the 15 s of a minute.\r\n This results in sleep period of 1 minute. The LED on pin 13 is set to toggle\r\n on every alarm match state. In sleep state with the built-in LED turn off, \r\n current measured is approximately 21.0 uA.\r\n\r\n Requirement:\r\n 1. Mini Ultra Pro board powered by a single cell Li-Ion\/Pol 3.7V battery.\r\n\r\n Important Note:\r\n 1. Upon using the SerialFlash.sleep() function, the only function that the \r\n serial flash chip response to is SerialFlash.wakeup(). \r\n\r\n Revision Description\r\n ======== ===========\r\n 0.10 Initial public release.\r\n*******************************************************************************\/\r\n\r\n#include &lt;SerialFlash.h&gt;\r\n#include &lt;RTCZero.h&gt;\r\n#include &lt;SPI.h&gt;\r\n#include &lt;RH_RF95.h&gt;\r\n\/\/#include &lt;RH_RF69.h&gt;\r\n\r\n\/\/ ***** CONSTANTS *****\r\nconst int radioDio0 = 2;\r\nconst int flashChipSelect = 4;\r\nconst int radioChipSelect = 5;\r\n\r\n\/\/ Choose correct on-board radio\r\nRH_RF95 radio(radioChipSelect, radioDio0);\r\n\/\/RH_RF69 radio(radioChipSelect, radioDio0);\r\nRTCZero rtc;\r\n\r\n\/* Change these values to set the current initial time *\/\r\nconst uint8_t seconds = 0;\r\nconst uint8_t minutes = 00;\r\nconst uint8_t hours = 10;\r\n\r\n\/* Change these values to set the current initial date *\/\r\nconst uint8_t day = 20;\r\nconst uint8_t month = 2;\r\nconst uint8_t year = 17;\r\n\r\n\/\/ ***** VARIABLES *****\r\nunsigned char pinNumber;\r\n\r\nvoid setup()\r\n{\r\n \/\/ Switch unused pins as input and enabled built-in pullup \r\n for (pinNumber = 0; pinNumber &lt; 23; pinNumber++)\r\n {\r\n pinMode(pinNumber, INPUT_PULLUP);\r\n }\r\n\r\n for (pinNumber = 32; pinNumber &lt; 42; pinNumber++)\r\n {\r\n pinMode(pinNumber, INPUT_PULLUP);\r\n }\r\n\r\n pinMode(25, INPUT_PULLUP);\r\n pinMode(26, INPUT_PULLUP);\r\n\r\n if (!radio.init()){}\r\n radio.sleep();\r\n \r\n SerialFlash.begin(flashChipSelect);\r\n SerialFlash.sleep();\r\n\r\n pinMode(LED_BUILTIN, OUTPUT);\r\n \r\n digitalWrite(LED_BUILTIN, HIGH);\r\n\r\n \/\/ ***** IMPORTANT DELAY FOR CODE UPLOAD BEFORE USB PORT DETACH DURING SLEEP *****\r\n delay(15000);\r\n\r\n \/\/***** UNCOMMENT FOR MINI ULTRA PRO VERSION 0V30 &amp; ABOVE IF PINS ARE CONNECTED TO RADIO ****\r\n \/*pinMode(6, INPUT);\r\n pinMode(7, INPUT);\r\n digitalWrite(3, HIGH);\r\n pinMode(3, OUTPUT);\r\n digitalWrite(3, HIGH);*\/\r\n \/\/*****\r\n\r\n \/\/ RTC initialization\r\n rtc.begin();\r\n rtc.setTime(hours, minutes, seconds);\r\n rtc.setDate(day, month, year);\r\n\r\n \/\/ RTC alarm setting on every 15 s resulting in 1 minute sleep period\r\n rtc.setAlarmSeconds(15);\r\n rtc.enableAlarm(rtc.MATCH_SS);\r\n rtc.attachInterrupt(alarmMatch);\r\n \r\n digitalWrite(LED_BUILTIN, LOW);\r\n USBDevice.detach();\r\n rtc.standbyMode();\r\n}\r\n\r\nvoid loop()\r\n{\r\n \/\/ Initialize USB and attach to host (not required if not in use)\r\n USBDevice.init();\r\n USBDevice.attach();\r\n \r\n digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));\r\n\r\n \/\/ Detach USB from host (not required if not in use)\r\n USBDevice.detach();\r\n \r\n \/\/ Sleep until next alarm match\r\n rtc.standbyMode();\r\n}\r\n\r\nvoid alarmMatch()\r\n{\r\n\r\n}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-5599\" src=\"http:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2017\/03\/MiniUltraProRTCAlarmSleepCurrentMeasurement.jpg\" alt=\"\" width=\"600\" height=\"600\" srcset=\"https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2017\/03\/MiniUltraProRTCAlarmSleepCurrentMeasurement.jpg 600w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2017\/03\/MiniUltraProRTCAlarmSleepCurrentMeasurement-100x100.jpg 100w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2017\/03\/MiniUltraProRTCAlarmSleepCurrentMeasurement-80x80.jpg 80w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2017\/03\/MiniUltraProRTCAlarmSleepCurrentMeasurement-300x300.jpg 300w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2017\/03\/MiniUltraProRTCAlarmSleepCurrentMeasurement-36x36.jpg 36w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2017\/03\/MiniUltraProRTCAlarmSleepCurrentMeasurement-180x180.jpg 180w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<\/div><\/div><\/section>\n<\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":5599,"comment_status":"open","ping_status":"closed","template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"tags":[],"portfolio_entries":[183,155],"class_list":["post-5276","portfolio","type-portfolio","status-publish","has-post-thumbnail","hentry","portfolio_entries-mini-ultra-pro","portfolio_entries-products"],"_links":{"self":[{"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/portfolio\/5276","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/portfolio"}],"about":[{"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/types\/portfolio"}],"author":[{"embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/comments?post=5276"}],"version-history":[{"count":1,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/portfolio\/5276\/revisions"}],"predecessor-version":[{"id":6114,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/portfolio\/5276\/revisions\/6114"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/media\/5599"}],"wp:attachment":[{"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/media?parent=5276"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/tags?post=5276"},{"taxonomy":"portfolio_entries","embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/portfolio_entries?post=5276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}