Skip to content

Instantly share code, notes, and snippets.

@debugger22
Last active August 29, 2015 13:57
Show Gist options
  • Save debugger22/9531898 to your computer and use it in GitHub Desktop.
Save debugger22/9531898 to your computer and use it in GitHub Desktop.
N Bit Ripple Counter Example
from __future__ import print_function
from BinPy.tools import Clock
from BinPy.Sequential.counters import NBitRippleCounter
from BinPy.Gates import Connector
toggle = Connector(1)
# Initialize the clock with leading edge = 1 and frequency = 1000Hz
clock = Clock(init_state=1, frequency=1000)
clock.start() #Start the clock
clk_conn = clock.A #Clock.A provides the connector of the clock
enable = Connector(1)
# Initialize the counter
counter = NBitRippleCounter(4, clk_conn)
print ("INITIAL STATE")
print (counter.state())
print ("TRIGGERING THE COUNTER SEQUENTIALLY 2^4 + 1 times")
for i in range(1, 2 ** 4 + 1):
print (counter.state())
counter.trigger()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment