BinPy.tools package

Submodules

BinPy.tools.clock module

class BinPy.tools.clock.Clock(init_state=1, frequency=None, time_period=None, name=None)[source]

Bases: threading.Thread

This class uses threading technique to create a clock with a certain time period. This is how you can create a clock with this class:

>>> myClock = Clock(0,time_period=2,name="My First Clock")
>>> myClock.start()     #Do not call run method
>>> myClock.getState()
0
Note: Once you are done with the clock, use myClock.kill() to kill the clock.
Running too many clocks will unnecessarily overload the CPU.

Following are the parameters of the class

param frequency:
 It will decide time interval of the clock, use SI unit i.e. Hertz
param time_period:
 It will also decide time interval of the clock, use SI unit i.e. second
param init_state:
 It is the initial state of the clock(1 by default)
param name:It is the name of the clock.(optional)

If time_period and frequency both have been provided, then time_period will override frequency If nothing is provided, then it will set time_period = 1s by default

Methods : start(), getState(), setState(value), getName(), getTimePeriod(), kill()

getName()[source]

Returns the name of the clock

getState()[source]

Returns the current state of the clock

getTimePeriod()[source]

Returns the time period of the clock

kill()[source]

Kills the clock(Thread)

run()[source]
setState(value)[source]

Resets the state of the clock to the passed value

BinPy.tools.digital module

class BinPy.tools.digital.DigitDisplay(name=None)[source]

This class emulates a 7 segmented display(Common Cathode)

Parameters:
name: A name given to an object(Optional)
Methods:
evaluate() getName()
How to use:
>>> myDisplay = DigitDisplay("Display1")
>>> print myDisplay.evaluate([1,1,1,1,1,1,1])
8
Note:
You can either pass complete list of 10 pins [pin1, pin2, pin3, pin4, pin5, pin6, pin7, pin8, pin9, pin10] in standard order or you can directly pass the list of values corresponding to a, b, c, d, e, f and g in lexicographical order.

http://tronixstuff.files.wordpress.com/2010/05/7segpinout.jpg

evaluate(pin_conf)[source]

This method evaluates the values passed according to the display and returns an integer varying from 0 to 9

BinPy.tools.ground module

class BinPy.tools.ground.Ground[source]

Models a Ground from which various connectors can tap by connecting to it. taps: The list of all connectors connected to this ground. connect(): Takes in one or more connectors as input and connects them to the ground. disconnect(): Takes in one or more connectors as input and disconnects them from the ground.

connect(*connectors)[source]

Takes in one or more connectors as an input and taps to the ground.

disconnect(*connectors)[source]

Takes in one or more connectors as an input and disconnects them from the ground. A floating connector has a value of None. A message is printed if a specified connector is not already tapping from this ground.

BinPy.tools.multivibrator module

class BinPy.tools.multivibrator.Multivibrator(init_state=1, mode=1, frequency=None, time_period=None, on_time=None, off_time=None)[source]

Bases: threading.Thread

This class uses threading technique to create a multivibrator with a certain time period. USAGE:

>>> m1 = Multivibrator()
>>> m1.start()     # Start this thread
>>> m1.trigger()   # or m1()
>>> m1.getState()  # or m1.A.state
0
>>> m1.setMode(2)
>>> m1.trigger()
>>> m1.getstate()
>>> conn = Connector()
>>> m1.setOutput(conn) # To set the output to connector conn
>>> conn()             # Retrieves the current state
Note: Once you are done with the multivibrator, use m1.kill() to kill the Multivibrators.
>>> m1.kill()

Following are the parameters of the class

frequency: It will decide time interval of the Multivibrator, use SI unit i.e. Hertz time_period: It will also decide time interval of the Multivibrator, use SI unit i.e. second

If time_period and frequency both have been provided, then time_period will override frequency If nothing is provided, then it will set time_period = 1s by default

init_state: It is the initial state of the multivibrator(1 by default)

mode: It is the mode of operation.
1 –> Monostable 2 –> Astable 3 –> Bistable

Methods : trigger(),setMode(), getState(), setState(value), getTimePeriod(), kill(), stop(), setOutput()

getState()[source]

Returns the current state

getTimePeriod()[source]

Returns the time period of the clock

kill()[source]

Kills the Thread

run()[source]
setMode(mode)[source]

Sets the mode of the Multivibrator

setOutput(conn)[source]
setState(value)[source]

Resets the state of the clock to the passed value

stop()[source]
trigger()

BinPy.tools.oscilloscope module

class BinPy.tools.oscilloscope.Oscilloscope(*inputs)[source]

Bases: threading.Thread

Oscilloscope is helpful in visualizing simulations.

USAGE: # A clock of 1 hertz frequency clock = Clock(1, 1) clock.start() clk_conn = clock.A

bc = BinaryCounter() os1 = Oscilloscope( (bc.out[1],’lsb’) , (bc.out[0],’msb’)) os1.start() #Triggering the counter: for i in range(5):

b.trigger() print (b.state())

os1.stop() os1.display()

clear(keepInputs=False)[source]
clearLA()[source]
disconnect(conn)[source]

Disconnects conn from the inputDict

display()[source]
hold()[source]
kill()[source]
run()[source]
sampler(trigPoint)[source]
setColour(foreground=1, background=7)[source]

Acceptable values are: 1 –> RED 2 –> GREEN 4 –> BLUE 7 –> WHITE

To RESET call without parameters.

Please note that serColor is not supported by all operating systems. This will run without problems on most Linux systems.

setScale(scale=0.05)[source]

This decides the time per unit xWidth. To avoid waveform distortion, follow NYQUIST sampling theorem. That is if the least time period of the waveform is T; Set the scale to be greater than T/2 [ preferably T/5 - To avoid edge sampling effects ]

There is a lower bound on the scale value [ use trial and error to identify this for your particular PC ] This limitation is set by the processing time taken to set a plot etc.

setWidth(w=150)[source]

Set the maximum width of the oscilloscope. This is dependent on your current monitor configuration.

unhold()[source]
updateInputs(*inputs)[source]

Set inputs using a list of tuples.

For example: osc1.setInputs((conn1,”label”) , (conn2,”label”) ... )

BinPy.tools.powersource module

class BinPy.tools.powersource.PowerSource[source]

Models a Power Source from which various connectors can tap by connecting to it.

taps: The list of all connectors connected to this power source.

connect(): Takes in one or more connectors as input and connects them to the power source.

disconnect(): Takes in one or more connectors as input and disconnects them from the power source.

connect(*connectors)[source]

Takes in one or more connectors as an input and taps to the power source.

disconnect(*connectors)[source]

Takes in one or more connectors as an input and disconnects them from the power source. A floating connector has a value of None. A message is printed if a specified connector is not already tapping from this source.

Module contents