{"id":152,"date":"2012-08-12T13:47:28","date_gmt":"2012-08-12T13:47:28","guid":{"rendered":"http:\/\/retroramblings.net\/?p=152"},"modified":"2012-08-12T13:47:28","modified_gmt":"2012-08-12T13:47:28","slug":"latching-power-circuit","status":"publish","type":"post","link":"http:\/\/retroramblings.net\/?p=152","title":{"rendered":"Latching power circuit"},"content":{"rendered":"<p>While the Altera DE1 board has been a great development platform for the MiniSOC project, I don&#8217;t want the project to live on that board forever.\u00a0 I&#8217;ve bought a relatively cheap Cyclone 3 board from EBay featuring an EP3C25 FPGA (this is the same FPGA as appears in the Turbo Chameleon 64), which has a shade under 25,000 logic elements to play with.\u00a0 (The board in question can be found here: <a href=\"http:\/\/www.ebay.co.uk\/itm\/Cyclone-III-FPGA-EP3C25-board-\/270910317225\">http:\/\/www.ebay.co.uk\/itm\/Cyclone-III-FPGA-EP3C25-board-\/270910317225<\/a>\u00a0 &#8211;\u00a0 that version has only a single 8-bit wide SDRAM chip, but when I contacted the sellers they were extremely helpful, and added a second chip for just $5 extra.)<\/p>\n<p>I have a rather nice small form factor case in which I&#8217;d like to install this project, but the case has a PC-style momentary push-button power switch, so I need some kind of latching power circuit.<\/p>\n<p>The requirements for the circuit are:<\/p>\n<ul>\n<li>Must draw only negligible power in the &#8220;off&#8221; state.<\/li>\n<li>Must latch reasonably quickly, and not turn off again until the button is released and pressed again.<\/li>\n<li>If FPGA signal pins are used, must not allow voltage to reach them in the &#8220;off&#8221; state.<\/li>\n<\/ul>\n<p>After studying a few similar circuits on the web, I decided to use a P-channel MOSFET and a BC547, with the base of the latter being driven by the FPGA.<\/p>\n<p>The schematic of my current circuit is as follows:<\/p>\n<p><a href=\"http:\/\/retroramblings.net\/wp-content\/uploads\/2012\/08\/PowerBoard1_3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-153\" title=\"PowerBoard1_3\" src=\"http:\/\/retroramblings.net\/wp-content\/uploads\/2012\/08\/PowerBoard1_3-1024x655.png\" alt=\"\" width=\"584\" height=\"373\" srcset=\"http:\/\/retroramblings.net\/wp-content\/uploads\/2012\/08\/PowerBoard1_3-1024x655.png 1024w, http:\/\/retroramblings.net\/wp-content\/uploads\/2012\/08\/PowerBoard1_3-300x192.png 300w, http:\/\/retroramblings.net\/wp-content\/uploads\/2012\/08\/PowerBoard1_3-468x300.png 468w, http:\/\/retroramblings.net\/wp-content\/uploads\/2012\/08\/PowerBoard1_3.png 1087w\" sizes=\"auto, (max-width: 584px) 100vw, 584px\" \/><\/a><\/p>\n<p>A few explanatory notes:<\/p>\n<ul>\n<li>PWR_BUTTON and PWR_HOLD are signal pins on the FPGA.\u00a0 The FPGA is powered from VOUT.<\/li>\n<li>S1 triggers the MOSFET and allows power to flow to VOUT<\/li>\n<li>The FPGA fires up, and as soon as it&#8217;s configured, sets PWR_HOLD to a high output, causing the BC547 to keep the MOSFET open.<\/li>\n<li>The FPGA sets PWR_BUTTON to an input with weak pullup, allowing it to detect a second press of the button.\u00a0 D1 prevents +5V reaching the non-5v-tolerant FPGA pin, and also prevents any voltage reaching that pin while the FPGA is off.\u00a0 R2 prevents the action of the BC547 interfering with the button press detection.<\/li>\n<li>R5 is a load resister that just drains away any stray charge that&#8217;s left when the circuit powers off.<\/li>\n<\/ul>\n<p>The button itself has to be debounced in the FPGA.\u00a0 The easiest way to do this is just to begin a delay any time the button line&#8217;s state changes, then sample it a second time when the delay&#8217;s elapsed, and compare.<\/p>\n<p>The VHDL looks like this:<\/p>\n<pre>signal debounce_counter : unsigned(11 downto 0) := X\"fff\"; \r\nsignal power_button_deb : std_logic; \r\nsignal power_button_deb1 : std_logic; \r\n...\r\n-- debounce the power switch \r\n\u00a0\u00a0 \u00a0process(clk) \r\n\u00a0\u00a0 \u00a0begin \r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if rising_edge(clk) then \r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if debounce_counter=X\"000\" then \r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if power_button_deb1='1' and power_button='1' then\u00a0\u00a0 \u00a0-- Is button stable? \r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0power_button_deb&lt;='1'; \r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0elsif power_button_deb1='0' and power_button='0' then \r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0power_button_deb&lt;='0'; \r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0else -- No? Start a delay... \r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0debounce_counter&lt;=X\"FFF\"; \r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0end if; \r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0power_button_deb1 &lt;= power_button; \r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0else \r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0debounce_counter&lt;=debounce_counter-1; \r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0end if; \r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0end if; \r\n\u00a0\u00a0 \u00a0end process;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>While the Altera DE1 board has been a great development platform for the MiniSOC project, I don&#8217;t want the project to live on that board forever.\u00a0 I&#8217;ve bought a relatively cheap Cyclone 3 board from EBay featuring an EP3C25 FPGA &hellip; <a href=\"http:\/\/retroramblings.net\/?p=152\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-152","post","type-post","status-publish","format-standard","hentry","category-fpga"],"_links":{"self":[{"href":"http:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/posts\/152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/retroramblings.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=152"}],"version-history":[{"count":6,"href":"http:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/posts\/152\/revisions"}],"predecessor-version":[{"id":159,"href":"http:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/posts\/152\/revisions\/159"}],"wp:attachment":[{"href":"http:\/\/retroramblings.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/retroramblings.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/retroramblings.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}