Esempio n. 1
0
# Example for N Bit Binary Ripple Counter.

from __future__ import print_function
from BinPy.tools.digital import Clock
from BinPy.Sequential.counters import NBitRippleCounter
from BinPy.Gates import Connector
from BinPy.tools.oscilloscope import Oscilloscope

print("Initialize a toggle connectr for inpput in TFlipFlop")
print("toggle = Connector(1)")
toggle = Connector(1)

print("Initializing the Clock")
print("clock = Clock(1, 50)")
print("clock.start()")
clock = Clock(1, 50)
clock.start()
# A clock of 100 hertz frequency
print("clk_conn = clock.A")
clk_conn = clock.A
print("\n")

print("Initialize enable")
print("enable = Connector(1)")
enable = Connector(1)

print ("Setting No of Bits to 4")
print ("Clock frequency is 10 Hz")

# Initializing the counter
print("\n")
Esempio n. 2
0
# Example for JKFlipFlop

from __future__ import print_function
from BinPy.Sequential.sequential import JKFlipFlop
from BinPy.tools.digital import Clock
from BinPy.Gates import Connector

j = Connector(1)
k = Connector(0)

p = Connector(0)
q = Connector(1)

# Initialize the clock
clock = Clock(1, 1)
clock.start()
# A clock of 1 hertz frequency
clk_conn = clock.A

enable = Connector(1)

jkff = JKFlipFlop(j, k, enable, clk_conn, enable)

# To connect outputs use s.setOutputs(op1,op2)
jkff.setOutputs(A=p, B=q)

print("SET STATE - J = 1, K = 0")
# Set State
j.state = 1
k.state = 0
# The same thing can also be done by --> jkff.setInputs(j = 1, k = 0)
Esempio n. 3
0
# Example for N Bit Binary Ripple Counter.

from __future__ import print_function
from BinPy.tools.digital import Clock
from BinPy.Sequential.counters import NBitRippleCounter
from BinPy.Gates import Connector

toggle = Connector(1)

# Initialize the clock
clock = Clock(1, 100)
clock.start()
# A clock of 100 hertz frequency
clk_conn = clock.A

enable = Connector(1)

print("Setting No of Bits to 8")
print("Clock frequency is 100 Hz")

# Initializing the counter
b = NBitRippleCounter(8, clk_conn)

print("INITIAL STATE")
print(b.state())

print("TRIGGERING THE COUNTER SEQUENTIALLY 2^8 + 1 times")

for i in range(1, 2**8 + 1):
    b.trigger()
    print(b.state())
Esempio n. 4
0
# Example for DFlipFlop

from __future__ import print_function
from BinPy.Sequential.sequential import DFlipFlop
from BinPy.tools.digital import Clock
from BinPy.Gates import Connector

data = Connector(1)

p = Connector(0)
q = Connector(1)

# Initialize the clock
clock = Clock(1, 1)
clock.start()
# A clock of 1 hertz frequency
clk_conn = clock.A

enable = Connector(1)

# Initialize the D-FlipFlop
dff = DFlipFlop(data, enable, clk_conn, p, q)
# To connect different set of connectors use :
# dff.setInputs(conn1,enab,clk)
# To connect different outputs use s.setOutputs(op1,op2)
dff.setOutputs(A=p, B=q)

print ("Data is 1")
data.state = 1
while True:
    if clk_conn.state == 0:
Esempio n. 5
0
# Example for Binary Counter a n bit counter.

from __future__ import print_function
from BinPy.tools.digital import Clock
from BinPy.Sequential.counters import BinaryCounter
from BinPy.Gates import Connector
from BinPy.tools.oscilloscope import Oscilloscope
import time

print("Initializing the Clock")
print("clock = Clock(0, 1)")
print("clock.start()")
clock = Clock(0, 1)
clock.start()
# A clock of 1 hertz frequency
print("clk_conn = clock.A")
clk_conn = clock.A
print("\n")
print("Initializing Binary Counter with 2 bits and clock_conn")
print("b = BinaryCounter(2, clk_conn)")
b = BinaryCounter(2, clk_conn)

print("\n")
print("Initializing the Oscillioscope")
print(
    "o=Oscilloscope((clk_conn, 'CLK'), (b.out[0], 'MSB'), (b.out[1],'LSB')')")
print("o.start() # starting the oscillioscope")
print("o.setScale(0.05) # setting the scale")

o = Oscilloscope((clk_conn, 'CLK'), (b.out[0], 'MSB'), (b.out[1], 'LSB'))
o.start()
Esempio n. 6
0
# Example for TFlipFlop

from __future__ import print_function
from BinPy.Sequential.sequential import TFlipFlop
from BinPy.tools.digital import Clock
from BinPy.Gates import Connector
from BinPy.tools.oscilloscope import Oscilloscope

toggle = Connector(1)

p = Connector(0)
q = Connector(1)

# Initialize the clock
clock = Clock(1, 4)
clock.start()
# A clock of 4 hertz frequency
clk_conn = clock.A

enable = Connector(1)

# Initialize the T-FlipFlop
tff = TFlipFlop(toggle, enable, clk_conn, a=p, b=q)

# To connect different set of connectors use :
# tff.setInputs(conn1,enab,clk)
# To connect different outputs use:
tff.setOutputs(A=p, B=q)

o = Oscilloscope((clk_conn, 'CLK'), (toggle, 'TOGGLE'), (p, 'OUT'),
                 (q, 'OUT!'), (enable, 'ENABLE'))