def convert(hdl, width=8):

    B = Signal(intbv(0)[width:])
    G = Signal(intbv(0)[width:])

    inst = bin2gray(B, G)
    inst.convert(hdl=hdl)
예제 #2
0
def convert(hdl, width=8):

    B = Signal(intbv(0)[width:])
    G = Signal(intbv(0)[width:])

    inst = bin2gray(B, G)
    inst.convert(hdl=hdl)
예제 #3
0
def gray_inc(graycnt, enable, clock, reset, width):
    
    bincnt = Signal(modbv(0)[width:])
    
    inc_0 = inc(bincnt, enable, clock, reset)
    bin2gray_0 = bin2gray(B=bincnt, G=graycnt)
    
    return inc_0, bin2gray_0
예제 #4
0
 def runTests(self, test):
     """Helper method to run the actual tests."""
     for w in range(1, MAX_WIDTH):
         B = Signal(intbv(0)[w:])
         G = Signal(intbv(0)[w:])
         dut = bin2gray(B, G)
         check = test(B, G)
         sim = Simulation(dut, check)
         sim.run(quiet=1)
예제 #5
0
 def runTests(self, test):
     """Helper method to run the actual tests."""
     for w in range(1, MAX_WIDTH):
         B = Signal(intbv(0)[w:])
         G = Signal(intbv(0)[w:])
         dut = bin2gray(B, G)
         check = test(B, G)
         sim = Simulation(dut, check)
         sim.run(quiet=1)
예제 #6
0
def testbench(width):

    B = Signal(intbv(0)[width:])
    G = Signal(intbv(0)[width:])

    dut = bin2gray(B, G)
    dut.config_sim(trace=True)

    @instance
    def stimulus():
        for i in range(2**width):
            B.next = intbv(i)
            yield delay(10)
            print("B: " + bin(B, width) + "| G: " + bin(G, width))

    return dut, stimulus
def testbench(width):

    B = Signal(intbv(0)[width:])
    G = Signal(intbv(0)[width:])

    dut = bin2gray(B, G)
    dut.config_sim(trace=True)

    @instance
    def stimulus():
        for i in range(2**width):
            B.next = intbv(i)
            yield delay(10)
            print("B: " + bin(B, width) + "| G: " + bin(G, width))

    return dut, stimulus
예제 #8
0
    def testUniqueCodeWords(self):
        """ Check that all codewords occur exactly once """
        def test(B, G, width):
            actual = []
            for i in range(2**width):
                B.next = intbv(i)
                yield delay(10)
                actual.append(int(G))
            actual.sort()
            expected = list(range(2**width))
            self.assertEqual(actual, expected)

        for width in range(1, MAX_WIDTH):
            B = Signal(intbv(1))
            G = Signal(intbv(0))
            dut = bin2gray(B, G, width)
            check = test(B, G, width)
            sim = Simulation(dut, check)
            sim.run(quiet=1)
예제 #9
0
    def testSingleBitChange(self):
        """ Check that only one bit changes in successive codewords """
        def test(B, G, G_Z, width):
            B.next = intbv(0)
            yield delay(10)
            for i in range(1, 2**width):
                G_Z.next = G
                B.next = intbv(i)
                yield delay(10)
                diffcode = bin(G ^ G_Z)
                self.assertEqual(diffcode.count('1'), 1)

        for width in range(2, MAX_WIDTH):
            B = Signal(intbv(1))
            G = Signal(intbv(0))
            G_Z = Signal(intbv(0))
            dut = bin2gray(B, G, width)
            check = test(B, G, G_Z, width)
            sim = Simulation(dut, check)
            sim.run(quiet=1)
예제 #10
0
    def testUniqueCodeWords(self):
        
        """ Check that all codewords occur exactly once """

        def test(B, G, width):
            actual = []
            for i in range(2**width):
                B.next = intbv(i)
                yield delay(10)
                actual.append(int(G))
            actual.sort()
            expected = range(2**width)
            self.assertEqual(actual, expected)
       
        for width in range(1, MAX_WIDTH):
            B = Signal(intbv(-1))
            G = Signal(intbv(0))
            dut = bin2gray(B, G, width)
            check = test(B, G, width)
            sim = Simulation(dut, check)
            sim.run(quiet=1)
예제 #11
0
    def testOriginalGrayCode(self):
        """Check that the code is an original Gray code."""

        Rn = []

        def stimulus(B, G, n):
            for i in range(2**n):
                B.next = intbv(i)
                yield delay(10)
                Rn.append(bin(G, width=n))

        Ln = ['0', '1'] # n == 1
        for w in range(2, MAX_WIDTH):
            Ln = nextLn(Ln)
            del Rn[:]
            B = Signal(intbv(0)[w:])
            G = Signal(intbv(0)[w:])
            dut = bin2gray(B, G)
            stim = stimulus(B, G, w)
            sim = Simulation(dut, stim)
            sim.run(quiet=1)
            self.assertEqual(Ln, Rn)
예제 #12
0
 def testSingleBitChange(self):
     
     """ Check that only one bit changes in successive codewords """
     
     def test(B, G, width):
         B.next = intbv(0)
         yield delay(10)
         for i in range(1, 2**width):
             G_Z.next = G
             B.next = intbv(i)
             yield delay(10)
             diffcode = bin(G ^ G_Z)
             self.assertEqual(diffcode.count('1'), 1)
     
     for width in range(1, MAX_WIDTH):
         B = Signal(intbv(-1))
         G = Signal(intbv(0))
         G_Z = Signal(intbv(0))
         dut = bin2gray(B, G, width)
         check = test(B, G, width)
         sim = Simulation(dut, check)
         sim.run(quiet=1)