{"id":25,"date":"2011-12-14T00:26:56","date_gmt":"2011-12-14T05:26:56","guid":{"rendered":"http:\/\/sunapi386.ca\/wordpress\/?p=25"},"modified":"2012-03-29T22:24:22","modified_gmt":"2012-03-30T03:24:22","slug":"reducing-equations","status":"publish","type":"post","link":"https:\/\/sunapi386.ca\/wordpress\/reducing-equations\/","title":{"rendered":"Circuit board that displays the digits of e"},"content":{"rendered":"<h1>Circuit board display first 16 digits of e<\/h1>\n<p>This is the final project for our CP 120 Digital Electronics lab. We are to build a circuit board display first 16 digits of e. It\u00a0takes in a number (the n<em>th<\/em>\u00a0digit)\u00a0and output that digit of <em>e.<\/em><\/p>\n<p>In general, we create the logic equation, reduce it with Karnaugh map, program it with a complex programmable logic device (CPLD), and wire it all up to light up a 7-segment\u00a0display.<\/p>\n<p>Let&#8217;s start:<\/p>\n<p>How does one simplify the work of creating outputs to a 7-segment display?<br \/>\nTraditionally, you&#8217;d have to use k-maps, and repeat the process for each lighting diode. This means a lot of errors could result.<\/p>\n<p>So how does one automate the process of creating equations?<\/p>\n<p>Let&#8217;s start of by defining:<\/p>\n<ol>\n<li>Inputs<\/li>\n<li>Outputs<\/li>\n<\/ol>\n<p><!--more--><br \/>\nLet&#8217;s assume you want to display the first 16 digits of pi &#8211; basically one would specify which place you digit you want to call.<br \/>\nExample, the 0th digit would be 3, 1st would be 1, 2nd would be 4, etc.<\/p>\n<p>Assuming one uses a binary digit representation of those numbers, 0 -&gt; 0000, 1 -&gt; 0001, 2-&gt; 0010, etc.<br \/>\nYou would map when each diode turns on\/off according to the inputs, let&#8217;s call them Q3, Q2, Q1, Q0.<\/p>\n<p><a href=\"http:\/\/en.wikipedia.org\/wiki\/Seven-segment_display\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"7-segment display\" src=\"http:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/0\/02\/7_segment_display_labeled.svg\/300px-7_segment_display_labeled.svg.png\" alt=\"\" width=\"300\" height=\"300\" \/><\/a><\/p>\n<p>Since the diode has a, b, c, d, e, f, g as outputs, you&#8217;d figure out the equation for each of these.<br \/>\nYou can do so with karnaugh maps, but this is a tedious task.<\/p>\n<p>Basically, here is the program that will automate the generation of the equations.<\/p>\n<p><code><br \/>\n# Python 3.1<\/code><\/p>\n<p># Let&#8217;s define our output, the first 16 digit of pi<br \/>\nPI = [ 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3 ]<\/p>\n<p># Then we need to create a dictionary, of what each number maps to define the inputs one would get for a 7-segment display.<br \/>\ndef segment_7d_dictionary():<br \/>\ndi = {}<\/p>\n<p># We define the nth digit&#8217;s relation to the outputs of a to g.<br \/>\n# So digit 0 would have all the diodes on except for diode g<br \/>\n# di[n] = [a, b, c, d, e, f, g]<\/p>\n<p>di[0] = [1, 1, 1, 1, 1, 1, 0]<br \/>\ndi[1] = [0, 1, 1, 0, 0, 0, 0]<br \/>\ndi[2] = [1, 1, 0, 1, 1, 0, 1]<br \/>\ndi[3] = [1, 1, 1, 1, 0, 0, 1]<br \/>\ndi[4] = [0, 1, 1, 0, 0, 1, 1]<br \/>\ndi[5] = [1, 0, 1, 1, 0, 1, 1]<br \/>\ndi[6] = [1, 0, 1, 1, 1, 1, 1]<br \/>\ndi[7] = [1, 1, 1, 0, 0, 0, 0]<br \/>\ndi[8] = [1, 1, 1, 1, 1, 1, 1]<br \/>\ndi[9] = [1, 1, 1, 1, 0, 1, 1]<\/p>\n<p>return di<\/p>\n<p>def cr_7d_display_eqn ( dictionary, constant, node ):<br \/>\nsegmenent_representation = []<br \/>\nfor digit in constant:<br \/>\nsegmenent_representation.append( dictionary[digit][node] )<\/p>\n<p>print( segmenent_representation )<br \/>\nm_lines = []<br \/>\nfor i in range( 0, len( segmenent_representation ) ):<br \/>\nif segmenent_representation[i] == 1:<br \/>\nm_lines.append( i )<\/p>\n<p>equation = qm.qm( ones = m_lines )<br \/>\nreturn equation<\/p>\n<p>Now that we have our functions defined and out of the way, here is the main program:<\/p>\n<p><code><br \/>\nimport qm<br \/>\n# To reduce equations http:\/\/robertdick.org\/python\/qm.html<\/code><\/p>\n<p>for node in range ( 0, 7 ):<br \/>\ncr_7d_display_eqn ( segment_7d_dictionary(), E, node )<\/p>\n<p>&nbsp;<\/p>\n<p>So there we have it.<br \/>\nIf you run this, you get:<\/p>\n<p><code><br \/>\n[1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1]<br \/>\n['XX0X', 'XXX1']<br \/>\n[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0]<br \/>\n['XX0X', '0XXX', 'XXX0']<br \/>\n[0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1]<br \/>\n['XXX1', '11XX', 'XX1X']<br \/>\n[1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1]<br \/>\n['XX00', 'XX11', 'X10X', '1X0X']<br \/>\n[1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0]<br \/>\n['0X00', '0X11', '100X', 'X101']<br \/>\n[0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1]<br \/>\n['X1X1', '1X1X', '1XX1', '11XX', 'XX11']<br \/>\n[1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1]<br \/>\n['010X', 'XX11', 'XX00', '10XX', '1XX0']<\/code><\/p>\n<p>&nbsp;<\/p>\n<p>This returns what place of digit it turns on (1), and the corresponding equation.<br \/>\nX = don&#8217;t care<br \/>\n0 = negated (let&#8217;s define NQ0 as negation of Q0, etc.)<br \/>\n1 = itself<br \/>\nFor the last one<br \/>\n([&#8216;010X&#8217;, &#8216;XX11&#8217;, &#8216;XX00&#8242;, &#8217;10XX&#8217;, &#8216;1XX0&#8217;])<br \/>\nthe sum of product equation would be:<br \/>\ng = NQ3 BQ2 NQ1 + Q1 Q0 + NQ1 NQ0 + Q3 NQ2 + Q3 NQ0<br \/>\nNow we have simplified the equation with the k-map program, we have to wire it up.<\/p>\n<p>After hooking everything up, it looks something like this (note, the PLD is not present):<br \/>\n<a href=\"https:\/\/sunapi386.ca\/wordpress\/wp-content\/uploads\/2011\/12\/IMG_0330.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-26\" title=\"IMG_0330\" src=\"https:\/\/sunapi386.ca\/wordpress\/wp-content\/uploads\/2011\/12\/IMG_0330-1024x768.jpg\" alt=\"RC\" width=\"640\" height=\"480\" srcset=\"https:\/\/sunapi386.ca\/wordpress\/wp-content\/uploads\/2011\/12\/IMG_0330-1024x768.jpg 1024w, https:\/\/sunapi386.ca\/wordpress\/wp-content\/uploads\/2011\/12\/IMG_0330-300x225.jpg 300w, https:\/\/sunapi386.ca\/wordpress\/wp-content\/uploads\/2011\/12\/IMG_0330.jpg 2048w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Circuit board display first 16 digits of e This is the final project for our CP 120 Digital Electronics lab. We are to build a circuit board display first 16 digits of e. It\u00a0takes in a number (the nth\u00a0digit)\u00a0and output that digit of e. In general, we create the logic equation, reduce it with Karnaugh &hellip; <a href=\"https:\/\/sunapi386.ca\/wordpress\/reducing-equations\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Circuit board that displays the digits of e<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[10,9,8],"class_list":["post-25","post","type-post","status-publish","format-standard","hentry","category-hack2600","tag-circuits","tag-k-maps","tag-project"],"_links":{"self":[{"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/posts\/25","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/comments?post=25"}],"version-history":[{"count":14,"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/posts\/25\/revisions"}],"predecessor-version":[{"id":171,"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/posts\/25\/revisions\/171"}],"wp:attachment":[{"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/media?parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/categories?post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/tags?post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}