{"id":1536,"date":"2015-06-06T21:56:10","date_gmt":"2015-06-06T19:56:10","guid":{"rendered":"http:\/\/www.sciencetronics.com\/greenphotons\/?p=1536"},"modified":"2025-06-16T18:38:06","modified_gmt":"2025-06-16T16:38:06","slug":"atmega328p-measuring-its-own-supply-voltage-iii","status":"publish","type":"post","link":"https:\/\/www.sciencetronics.com\/greenphotons\/?p=1536","title":{"rendered":"ATmega328P &#8211; measuring its own supply voltage III"},"content":{"rendered":"<p>After the first two parts of this series<\/p>\n<ul>\n<li><a href=\"http:\/\/www.sciencetronics.com\/greenphotons\/?p=1521\" title=\"ATmega328P \u2013 measuring its own supply voltage\">ATmega328P \u2013 measuring its own supply voltage<\/a><\/li>\n<li><a href=\"http:\/\/www.sciencetronics.com\/greenphotons\/?p=1532\" title=\"ATmega328P \u2013 measuring its own supply voltage II\">ATmega328P \u2013 measuring its own supply voltage II<\/a><\/li>\n<\/ul>\n<p>where I investigated the possibility of the Atmel ATmega series microcontrollers to select the internal bandgap voltage VBG as input for the  analog-to-digital converter. Using the analog supply voltage AVcc as reference for the conversion this allows you to measure the chip&#8217;s supply voltage without using any pin or any external devices.<\/p>\n<p>However, when implementing this feature into a project prototype I observed a strange behavior. The datasheet and the big internet were not very helpful in this respect, recommending among other things to discard the first conversion result, but this did not result in concise results either. <\/p>\n<p>It became obvious that the reason for this behavior was a highly resistive connection between the VBG source and the sample-and-hold capacitor. I went over to a new breadboard and set up a versatile test circuit:<br \/>\n<figure id=\"attachment_1540\" aria-describedby=\"caption-attachment-1540\" style=\"width: 191px\" class=\"wp-caption alignleft\"><a href=\"http:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150606_mega328_adctest.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150606_mega328_adctest-191x300.png\" alt=\"A simple yet versatile testcircuit for the analod-to-digital converter.\" width=\"191\" height=\"300\" class=\"size-medium wp-image-1540\" srcset=\"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150606_mega328_adctest-191x300.png 191w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150606_mega328_adctest-653x1024.png 653w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150606_mega328_adctest-95x150.png 95w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150606_mega328_adctest-400x626.png 400w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150606_mega328_adctest.png 883w\" sizes=\"auto, (max-width: 191px) 100vw, 191px\" \/><\/a><figcaption id=\"caption-attachment-1540\" class=\"wp-caption-text\">A simple yet versatile testcircuit for the analod-to-digital converter.<\/figcaption><\/figure><figure id=\"attachment_1539\" aria-describedby=\"caption-attachment-1539\" style=\"width: 259px\" class=\"wp-caption alignright\"><a href=\"http:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150606_connect_mega328_adc_700.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150606_connect_mega328_adc_700-259x300.png\" alt=\"A sketch of the test circuit on a breadboard.\" width=\"259\" height=\"300\" class=\"size-medium wp-image-1539\" srcset=\"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150606_connect_mega328_adc_700-259x300.png 259w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150606_connect_mega328_adc_700-129x150.png 129w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150606_connect_mega328_adc_700.png 733w\" sizes=\"auto, (max-width: 259px) 100vw, 259px\" \/><\/a><figcaption id=\"caption-attachment-1539\" class=\"wp-caption-text\">A sketch of the test circuit on a breadboard.<\/figcaption><\/figure><br \/>\n<br clear=\"all\"\/><br \/>\nIn this test circuit I connected the ADCx inputs of the ATmega328P to the supply rails through differently sized resistors:<\/p>\n<ul>\n<li>ADC0 directly connected to AVcc<\/li>\n<li>ADC1 <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/ql-cache\/quicklatex.com-f1023576b0dd11842ac64a0b9d36aa60_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#73;&#123;&#49;&#125;&#123;&#107;&#105;&#108;&#111;&#111;&#104;&#109;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"11\" width=\"77\" style=\"vertical-align: 0px;\"\/> to AVcc<\/li>\n<li>ADC2 <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/ql-cache\/quicklatex.com-43bf378e00ea33cafb779d8912de675a_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#73;&#123;&#49;&#48;&#125;&#123;&#107;&#105;&#108;&#111;&#111;&#104;&#109;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"11\" width=\"85\" style=\"vertical-align: 0px;\"\/> to AVcc<\/li>\n<li>ADC3 <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/ql-cache\/quicklatex.com-7dfd9fda1fcfce1f16b0faf33d78be30_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#73;&#123;&#49;&#48;&#48;&#125;&#123;&#107;&#105;&#108;&#111;&#111;&#104;&#109;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"11\" width=\"92\" style=\"vertical-align: 0px;\"\/> to AVcc<\/li>\n<li>ADC4 <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/ql-cache\/quicklatex.com-7784f33cb53fe6fb3a8697576d049928_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#73;&#123;&#49;&#125;&#123;&#109;&#101;&#103;&#97;&#111;&#104;&#109;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"88\" style=\"vertical-align: -3px;\"\/> to AVcc<\/li>\n<li>ADC5 <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/ql-cache\/quicklatex.com-7784f33cb53fe6fb3a8697576d049928_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#73;&#123;&#49;&#125;&#123;&#109;&#101;&#103;&#97;&#111;&#104;&#109;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"88\" style=\"vertical-align: -3px;\"\/> to GND<\/li>\n<\/ul>\n<p>By charging the sample-and-hold capacitor from one channel of the input multiplexer and then switching to another channel it is possible to extract the dynamic properties of the analog-to-digital converter section inside the ATmega.<\/p>\n<p>As can be seen from the graphs below, the sample-and-hold capacitor inside the ATmega328P appears to be about <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/ql-cache\/quicklatex.com-6adbd449205a1b1471d632119ae14199_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#73;&#123;&#50;&#53;&#125;&#123;&#112;&#105;&#99;&#111;&#102;&#97;&#114;&#97;&#100;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"14\" width=\"97\" style=\"vertical-align: -3px;\"\/> and thus larger than the value of <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/ql-cache\/quicklatex.com-89f973bebb0bd9ad7b4896705c2788d6_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#73;&#123;&#49;&#52;&#125;&#123;&#112;&#105;&#99;&#111;&#102;&#97;&#114;&#97;&#100;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"14\" width=\"97\" style=\"vertical-align: -3px;\"\/> from the datasheet. The datasheet recommends a source impedance of <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/ql-cache\/quicklatex.com-43bf378e00ea33cafb779d8912de675a_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#73;&#123;&#49;&#48;&#125;&#123;&#107;&#105;&#108;&#111;&#111;&#104;&#109;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"11\" width=\"85\" style=\"vertical-align: 0px;\"\/> or below &#8211; interestingly, the designers at Atmel themselves did not follow this recommendation when they designed the connection of the VBG source to the input multiplexer. The impedance for this connection appears to be in the order of <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/ql-cache\/quicklatex.com-7784f33cb53fe6fb3a8697576d049928_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#73;&#123;&#49;&#125;&#123;&#109;&#101;&#103;&#97;&#111;&#104;&#109;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"88\" style=\"vertical-align: -3px;\"\/> but apart from this the connection is asymmetric with a source which can rather source than sink a current.<\/p>\n<p><figure id=\"attachment_1544\" aria-describedby=\"caption-attachment-1544\" style=\"width: 156px\" class=\"wp-caption alignleft\"><a href=\"http:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150605_mega328_adcspeed_3v3_800.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150605_mega328_adcspeed_3v3_800-156x300.png\" alt=\"Timing of the internal analog-to-digital converter of an ATmega328P with a 3.3 V supply voltage.\" width=\"156\" height=\"300\" class=\"size-medium wp-image-1544\" srcset=\"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150605_mega328_adcspeed_3v3_800-156x300.png 156w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150605_mega328_adcspeed_3v3_800-533x1024.png 533w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150605_mega328_adcspeed_3v3_800-78x150.png 78w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150605_mega328_adcspeed_3v3_800-400x767.png 400w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150605_mega328_adcspeed_3v3_800.png 834w\" sizes=\"auto, (max-width: 156px) 100vw, 156px\" \/><\/a><figcaption id=\"caption-attachment-1544\" class=\"wp-caption-text\">Timing of the internal analog-to-digital converter of an ATmega328P with a 3.3 V supply voltage.<\/figcaption><\/figure><figure id=\"attachment_1545\" aria-describedby=\"caption-attachment-1545\" style=\"width: 156px\" class=\"wp-caption alignright\"><a href=\"http:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150605_mega328_adcspeed_5v_800.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150605_mega328_adcspeed_5v_800-156x300.png\" alt=\"Timing of the internal analog-to-digital converter of an ATmega328P with a 5 V supply voltage.\" width=\"156\" height=\"300\" class=\"size-medium wp-image-1545\" srcset=\"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150605_mega328_adcspeed_5v_800-156x300.png 156w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150605_mega328_adcspeed_5v_800-533x1024.png 533w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150605_mega328_adcspeed_5v_800-78x150.png 78w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150605_mega328_adcspeed_5v_800-400x767.png 400w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150605_mega328_adcspeed_5v_800.png 834w\" sizes=\"auto, (max-width: 156px) 100vw, 156px\" \/><\/a><figcaption id=\"caption-attachment-1545\" class=\"wp-caption-text\">Timing of the internal analog-to-digital converter of an ATmega328P with a 5 V supply voltage.<\/figcaption><\/figure><br \/>\n<br clear=\"all\"\/><br \/>\nThe above data was collected using a <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/ql-cache\/quicklatex.com-c564ddd5f5f05a69542a281727733b00_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#73;&#123;&#49;&#50;&#125;&#123;&#109;&#101;&#103;&#97;&#104;&#101;&#114;&#116;&#122;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"101\" style=\"vertical-align: -3px;\"\/> quartz crystal and an assembler loop for the timing delay in steps of <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/ql-cache\/quicklatex.com-7fede84c62ed62934ba13f09bc278a4a_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#73;&#123;&#49;&#125;&#123;&#109;&#105;&#99;&#114;&#111;&#115;&#101;&#99;&#111;&#110;&#100;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"11\" width=\"107\" style=\"vertical-align: 0px;\"\/>. The charging of the sample-and-hold capacitor before switching channels was done for <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/ql-cache\/quicklatex.com-8081d8271e7542e61ef23ad88334b332_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#73;&#123;&#49;&#48;&#125;&#123;&#109;&#105;&#108;&#108;&#105;&#115;&#101;&#99;&#111;&#110;&#100;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"11\" width=\"108\" style=\"vertical-align: 0px;\"\/> from a low-resistance conenction to either AVcc (external, ADC0) or GND (internal). The ATmega328P has a datecode of &#8220;1312&#8221;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After the first two parts of this series ATmega328P \u2013 measuring its own supply voltage ATmega328P \u2013 measuring its own supply voltage II where I investigated the possibility of the Atmel ATmega series microcontrollers to select the internal bandgap voltage VBG as input for the analog-to-digital converter. Using the analog supply voltage AVcc as reference [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1544,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[46,22,11,27],"tags":[],"class_list":["post-1536","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-avr","category-computers_en","category-electronics_en","category-science_en","entry","has-media"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2015\/06\/20150605_mega328_adcspeed_3v3_800.png","jetpack_shortlink":"https:\/\/wp.me\/p48grL-oM","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=\/wp\/v2\/posts\/1536","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1536"}],"version-history":[{"count":9,"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=\/wp\/v2\/posts\/1536\/revisions"}],"predecessor-version":[{"id":2413,"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=\/wp\/v2\/posts\/1536\/revisions\/2413"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=\/wp\/v2\/media\/1544"}],"wp:attachment":[{"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1536"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1536"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1536"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}