CSC270 GYRSequencer.py
--D. Thiebaut 10:48, 2 March 2012 (EST)
This program shows how programming can be used to check if the equations found for a sequencer actually make the system work as advertised.
See this page for additional examples of how to create logic operators in python.
Python V2.X
# GYRSequencer.py # D. Thiebaut # A very quick and dirty way to check a sequencer... # This sequencer activates a G, Y, and R light system # s.t. G is on for 2 cycles, followed by Y for 1 cycle # followed by R for 1 cycle. Then the whole cycle repeats Q1 = 0 Q2 = 0 def NOT( a ): return 1 - a 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... D1 = Q1 ^ Q2 # xor D2 = NOT( Q2 ) G = Q1 Y = NOT ( Q1 | Q2 ) R = NOT ( G | Y ) # show the stable circuit signals print "Q1Q2 = %d %d | GYR = %d %d %d" % ( Q1, Q2, G, Y, R ) # wait for the next clock tick (the user presses Enter) raw_input( "> " ) # as soon as the clock has ticked, D1 and D2 get latched in the flipflops # and Q1 and Q2 reflect the values captured. Q1 = D1 Q2 = D2
Python V3.X
# GYRSequencer.py # D. Thiebaut # A very quick and dirty way to check a sequencer... # This sequencer activates a G, Y, and R light system # s.t. G is on for 2 cycles, followed by Y for 1 cycle # followed by R for 1 cycle. Then the whole cycle repeats Q1 = 0 Q2 = 0 def NOT( a ): return 1 - a 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... D1 = Q1 ^ Q2 # xor D2 = NOT( Q2 ) G = Q1 Y = NOT ( Q1 | Q2 ) R = NOT ( G | Y ) # show the stable circuit signals print( "Q1Q2 = %d %d | GYR = %d %d %d" % ( Q1, Q2, G, Y, 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. Q1 = D1 Q2 = D2