{"id":349,"date":"2011-04-26T01:27:26","date_gmt":"2011-04-25T17:27:26","guid":{"rendered":"http:\/\/www.rocketscream.com\/blog\/?p=349"},"modified":"2013-07-06T12:52:05","modified_gmt":"2013-07-06T04:52:05","slug":"mini-ultra-8-mhz-current-consumption-part-2","status":"publish","type":"post","link":"https:\/\/www.rocketscream.com\/blog\/2011\/04\/26\/mini-ultra-8-mhz-current-consumption-part-2\/","title":{"rendered":"Mini Ultra 8 MHz &#8211; Current Consumption (Part 2)"},"content":{"rendered":"<p>This is the second part of current consumption measurement of Mini Ultra 8 MHz. We&#8217;ll show some important steps to put the board into very low power state. The result is well beyond our expectation and we are pretty excited as this marks the completion of one of the main objective of the design.<!--more--><\/p>\n<p>It has been a pretty hectic but a fruitful weekend. Over the weekend, works on the PID control of the reflow oven controller has progressed extremely well (<a href=\"http:\/\/brettbeauregard.com\/blog\/2011\/04\/improving-the-beginners-pid-introduction\/\">thank you Brett for helping out<\/a>) and now we get to complete the testing on Mini Ultra 8 MHz.<\/p>\n<p>Back to where we left in the first part of the current consumption measurement, we soldered the remaining components onto the board. We are using a new revision of the board (yes, it went through 3 cycles already!) which has a ceramic resonator with built-in capacitor which saves board space with a reasonable 0.5% accuracy. Here&#8217;s a snapshot of the fully assembled board. At the moment of writing this, the board went for the 4th and final revision. \ud83d\ude42<br \/>\n<a href=\"http:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2011\/04\/miniUltra.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-361\" title=\"Mini Ultra 8 MHz\" alt=\"\" src=\"http:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2011\/04\/miniUltra.jpg\" width=\"600\" height=\"500\" srcset=\"https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2011\/04\/miniUltra.jpg 600w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2011\/04\/miniUltra-300x250.jpg 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><br \/>\nThe board is preloaded with Arduino Pro Mini 8 MHz bootloader with modified extended fuses. The only differences is the Brown Out Detect (BOD) fuse which we disabled completely for this purpose of testing. This is done easily by changing line 11 (snapshot below) in the hardware\/arduino\/boards.txt file from 0x05 to 0x07. The BOD settings explanation can be found on page 298 of the <a href=\"http:\/\/www.atmel.com\/dyn\/resources\/prod_documents\/doc8271.pdf\">ATmega328P datasheet<\/a> and you can use a very handy<a href=\"http:\/\/www.engbedded.com\/fusecalc\/\">AVR fuse calculator here<\/a>. Keep in mind that with the BOD feature enabled, there will an extra of 20 \u00b5A current consumed during power down mode. The BOD can also be changed on the fly through software control but it will require strict timing which we will cover in another post. For this testing purpose, we&#8217;ll use the fuse setting to disable the BOD.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n##############################################################\r\n\r\npro328.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w\/ ATmega328\r\n\r\npro328.upload.protocol=stk500\r\npro328.upload.maximum_size=30720\r\npro328.upload.speed=57600\r\n\r\npro328.bootloader.low_fuses=0xFF\r\npro328.bootloader.high_fuses=0xDA\r\npro328.bootloader.extended_fuses=0x05\r\npro328.bootloader.path=atmega\r\npro328.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex\r\npro328.bootloader.unlock_bits=0x3F\r\npro328.bootloader.lock_bits=0x0F\r\n\r\npro328.build.mcu=atmega328p\r\npro328.build.f_cpu=8000000L\r\npro328.build.core=arduino\r\n\r\n##############################################################\r\n<\/pre>\n<p>Once the bootloader is loaded, it&#8217;s time to write some code to enable the board to go into power down mode. The ATmega328P can be put into 6 different type of sleep modes. Each sleep mode has different power consumption, active clocks, and wake up sources. We&#8217;ll be putting the microcontroller into power down mode in this case. The microcontroller can be waken up through external interrupt, TWI address match, and watchdog timer (we&#8217;ll do a series of tutorials and examples on how to use them pretty soon) in this mode. Here&#8217;s the code used to put the Mini Ultra 8 MHz into power down mode.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\/\/ **** INCLUDES *****\r\n#include &lt;avr\/sleep.h&gt;\r\n#include &lt;avr\/power.h&gt;\r\n\/\/ ***** CONSTANT *****\r\n#define MAX_PIN_COUNT 22    \/\/ Digital IO 0-13, Analog A0-A7\r\n\r\nvoid setup()\r\n{\r\n    uint8_t pin;\r\n\r\n    \/\/ Put all pins into output mode and low state\r\n    for (pin = 0; pin &lt; MAX_PIN_COUNT; pin++)\r\n    {\r\n        pinMode(pin,OUTPUT);\r\n        digitalWrite(pin,LOW);\r\n    }\r\n\r\n    \/\/ Set sleep mode\r\n    set_sleep_mode(SLEEP_MODE_PWR_DOWN);\r\n    \/\/ Enable sleep mode\r\n    sleep_enable();\r\n    \/\/ Disable ADC, must be done before calling\r\n    \/\/ power_all_disable() as to disable ADC,\r\n    \/\/ clock is required\r\n    \/\/ Refer to datasheet page 45\r\n    ADCSRA &amp;= ~(1 &lt;&lt; ADEN);\r\n    \/\/ Disable all peripheral power\r\n    power_all_disable();\r\n    \/\/ Enter sleep mode\r\n    sleep_mode();\r\n}\r\n\r\nvoid loop()\r\n{\r\n    \/\/ Zzz...\r\n}\r\n<\/pre>\n<p>The above code basically puts the microcontroller into power down mode and shutting down all peripherals. Special treatment is required for the ADC module as it must be disabled before shutting it down. Once the code is loaded onto the board we perform the current measurement using the setup below. We managed to get the current consumption of the board down to 2.1 \u00b5A. At the beginning of the design, we have set a target of 5 \u00b5A, but the end result is pretty amazing. The ATmega328P is basically consuming only 0.5 \u00b5A (2.1 &#8211; 1.6 \u00b5A) as the on board regulator consumes the remaining about 1.6 \u00b5A (<a href=\"http:\/\/www.rocketscream.com\/blog\/2011\/04\/06\/mini-ultra-8-mhz-current-consumption-part-1\/\">refer to our previous post<\/a>). We&#8217;ll be giving some examples soon on waking up the board to perform certain task (sensor reading, data transmission, data logging) before going into power down mode again. Plans for a small power management library (sort of wrapper functions with wake up source selection and power down duration) is in the pipeline and we hope can finish that while the boards go for first batch of production.<\/p>\n<p><a href=\"http:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2011\/04\/measurementSetup.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-370\" title=\"Measurement Setup\" alt=\"\" src=\"http:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2011\/04\/measurementSetup.jpg\" width=\"600\" height=\"464\" srcset=\"https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2011\/04\/measurementSetup.jpg 600w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2011\/04\/measurementSetup-300x232.jpg 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>Take care and happy tinkering.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the second part of current consumption measurement of Mini Ultra 8 MHz. We&#8217;ll show some important steps to put the board into very low power state. The result is well beyond our expectation and we are pretty excited as this marks the completion of one of the main objective of the design.<\/p>\n","protected":false},"author":1,"featured_media":363,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","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":""},"categories":[18,14],"tags":[151,7,19],"class_list":["post-349","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mini-ultra-8-mhz","category-projects","tag-arduino","tag-low-power","tag-mini-ultra"],"_links":{"self":[{"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/posts\/349","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"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=349"}],"version-history":[{"count":27,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/posts\/349\/revisions"}],"predecessor-version":[{"id":1449,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/posts\/349\/revisions\/1449"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/media\/363"}],"wp:attachment":[{"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/media?parent=349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/categories?post=349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/tags?post=349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}