Py4Hw User Guide> 2.2 Logical and Relational Operations¶

Next: 2.3 Bit Manipulation¶

py4hw supports the classic bitwise relational operations that you would expect to have in any programming language: ==, !=, >, <, ...

In [1]:
import py4hw
import matplotlib.pyplot as plt
import wavedrom as wd
In [2]:
hw = py4hw.HWSystem()
a = py4hw.Wire(hw, 'a', 8)
b = py4hw.Wire(hw, 'b', 8)

gt = py4hw.Wire(hw, 'gt')
eq = py4hw.Wire(hw, 'eq')
lt = py4hw.Wire(hw, 'lt')

py4hw.Sequence(hw, 'a', [1, 2, 3, 4, 6, 7, 8, 9], a)
py4hw.Sequence(hw, 'b', [1, 4, 8], b)

py4hw.Comparator(hw, 'cmp',  a, b, gt, eq, lt)

wvf = py4hw.Waveform(hw, 'wvf', [a, b, gt, eq, lt])

hw.getSimulator().clk(20)

wd.render(str(wvf.get_wavedrom(shortNames=True)))
Out[2]:
wvf0123456789101112131415161718192021clka01234678912346789123b01481481481481481481gteqlt

We also support comparators with constants

In [3]:
hw = py4hw.HWSystem()
a = py4hw.Wire(hw, 'a', 8)
is5 = py4hw.Wire(hw, 'is5')


py4hw.Sequence(hw, 'a', [1, 2, 3, 4, 5, 6, 7, 8, 9], a)


py4hw.EqualConstant(hw, 'is5', a, 5, is5)

wvf = py4hw.Waveform(hw, 'wvf', [a, is5])

hw.getSimulator().clk(20)

wd.render(str(wvf.get_wavedrom(shortNames=True)))
Out[3]:
wvf0123456789101112131415161718192021clka01234567891234567891is5

Summary¶

  • There are comparators
  • There are constant comparators
In [ ]: