Difference between revisions of "CSC270 Homework 5 Solution 2012"
(Created page with "--~~~~ ---- <onlysmith> Pdf </onlysmith> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> Category:CSC270[[Category:...") |
|||
Line 2: | Line 2: | ||
---- | ---- | ||
<onlysmith> | <onlysmith> | ||
+ | =PDF= | ||
[[Media:CSC270Homework5Solutions2012.pdf|Pdf]] | [[Media:CSC270Homework5Solutions2012.pdf|Pdf]] | ||
+ | |||
+ | =Source= | ||
+ | |||
+ | <source lang="python"> | ||
+ | # Homework 5 | ||
+ | # Problems 1 and 2 | ||
+ | # CSC 270 | ||
+ | # 2012 | ||
+ | # D.T. | ||
+ | # for problem #2, since we associated Red ON with the state where | ||
+ | # Q0, Q1, and Q2 are 0, then all we need to do is clear D2, D1, and | ||
+ | # D0 when the command is 1. So we AND the functions of Problem 1 that | ||
+ | # generate D2, D1, and D0 with NOT( cmd ). No analysis necessary! | ||
+ | # | ||
+ | |||
+ | def NOT( a ): | ||
+ | return 1 - a | ||
+ | |||
+ | |||
+ | def Problem1(): | ||
+ | Q2 = 1 | ||
+ | Q1 = 0 | ||
+ | Q0 = 0 | ||
+ | |||
+ | |||
+ | for step in range( 20 ): | ||
+ | |||
+ | # the Q1 and Q2 outputs go through combinational logic to generate the new values | ||
+ | # of D1, D2, and the outputs G, Y, R... | ||
+ | D2 = NOT( Q2 ) & Q1 & NOT( Q0 ) | ||
+ | D1 = ( Q0 & Q1 ) | ( Q2 ^ Q1 ) ^ Q0 | ||
+ | D0 = NOT( Q2 ) & NOT( Q1 ) | ( Q2 & Q0 ) | ||
+ | R = NOT( Q1 ) & NOT( Q0 ) | ||
+ | G = NOT( R ) | ||
+ | |||
+ | # show the stable circuit signals | ||
+ | print( "Q2Q1Q0 = %d %d %d | GR = %d %d" % ( Q2, Q1, Q0, G, R ) ) | ||
+ | |||
+ | # wait for the next clock tick (the user presses Enter) | ||
+ | #input( "> " ) | ||
+ | |||
+ | # as soon as the clock has ticked, D1 and D2 get latched in the flipflops | ||
+ | # and Q1 and Q2 reflect the values captured. | ||
+ | Q0 = D0 | ||
+ | Q1 = D1 | ||
+ | Q2 = D2 | ||
+ | |||
+ | def Problem2(): | ||
+ | Q2 = 0 | ||
+ | Q1 = 0 | ||
+ | Q0 = 0 | ||
+ | |||
+ | |||
+ | for cmd in [0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,1,1,0]: | ||
+ | # the Q1 and Q2 outputs go through combinational logic to generate the new values | ||
+ | # of D1, D2, and the outputs G, Y, R... | ||
+ | D2 = NOT(cmd) & ( NOT( Q2 ) & Q1 & NOT( Q0 ) ) | ||
+ | D1 = NOT(cmd) & (( Q0 & Q1 ) | ( Q2 ^ Q1 ) ^ Q0 ) | ||
+ | D0 = NOT(cmd) & (NOT( Q2 ) & NOT( Q1 ) | ( Q2 & Q0 )) | ||
+ | R = NOT( Q1 ) & NOT( Q0 ) | ||
+ | G = NOT( R ) | ||
+ | |||
+ | # show the stable circuit signals | ||
+ | print( "cmd Q2Q1Q0 = %d %d %d %d | GR = %d %d" % ( cmd, Q2, Q1, Q0, G, R ) ) | ||
+ | |||
+ | # wait for the next clock tick (the user presses Enter) | ||
+ | #input( "> " ) | ||
+ | |||
+ | # as soon as the clock has ticked, D1 and D2 get latched in the flipflops | ||
+ | # and Q1 and Q2 reflect the values captured. | ||
+ | Q0 = D0 | ||
+ | Q1 = D1 | ||
+ | Q2 = D2 | ||
+ | |||
+ | def main(): | ||
+ | print( "Problem #1\n-------------" ) | ||
+ | Problem1() | ||
+ | print( "\n\nProblem #2\n-------------" ) | ||
+ | Problem2() | ||
+ | |||
+ | main() | ||
+ | |||
+ | """ | ||
+ | Copy of the output | ||
+ | Problem #1 | ||
+ | ------------- | ||
+ | Q2Q1Q0 = 1 0 0 | GR = 0 1 | ||
+ | Q2Q1Q0 = 0 1 0 | GR = 1 0 | ||
+ | Q2Q1Q0 = 1 1 0 | GR = 1 0 | ||
+ | Q2Q1Q0 = 0 0 0 | G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md Q2Q1Q0 = 1 0 0 0 | GR = 0 1 | ||
+ | cmd Q2Q1Q0 = 1 0 0 0 | GR = 0 1 | ||
+ | cmd Q2Q1Q0 = 1 0 0 0 | GR = 0 1 | ||
+ | cmd Q2Q1Q0 = 1 0 0 0 | GR = 0 1 | ||
+ | cmd Q2Q1Q0 = 1 0 0 0 | GR = 0 1 | ||
+ | cmd Q2Q1Q0 = 0 0 0 0 | GR = 0 1 | ||
+ | cmd Q2Q1Q0 = 0 0 0 1 | GR = 1 0 | ||
+ | cmd Q2Q1Q0 = 0 0 1 1 | GR = 1 0 | ||
+ | cmd Q2Q1Q0 = 1 0 1 0 | GR = 1 0 | ||
+ | cmd Q2Q1Q0 = 1 0 0 0 | GR = 0 1 | ||
+ | cmd Q2Q1Q0 = 0 0 0 0 | GR = 0 1 | ||
+ | """</sourcr> | ||
+ | |||
</onlysmith> | </onlysmith> | ||
Revision as of 07:29, 13 March 2012
--D. Thiebaut 18:24, 12 March 2012 (EDT)