2008-11-22 22:40:25 +01:00
|
|
|
from myhdl import *
|
|
|
|
|
|
|
|
from bin2gray2 import bin2gray
|
|
|
|
from inc import Inc
|
|
|
|
|
|
|
|
def GrayInc(graycnt, enable, clock, reset, width):
|
|
|
|
|
2012-12-21 15:06:18 +01:00
|
|
|
bincnt = Signal(modbv(0)[width:])
|
2008-11-22 22:40:25 +01:00
|
|
|
|
2012-12-21 15:06:18 +01:00
|
|
|
inc_1 = Inc(bincnt, enable, clock, reset)
|
2008-11-22 22:40:25 +01:00
|
|
|
bin2gray_1 = bin2gray(B=bincnt, G=graycnt, width=width)
|
|
|
|
|
|
|
|
return inc_1, bin2gray_1
|
|
|
|
|
|
|
|
|
|
|
|
def GrayIncReg(graycnt, enable, clock, reset, width):
|
|
|
|
|
2012-12-21 15:06:18 +01:00
|
|
|
graycnt_comb = Signal(modbv(0)[width:])
|
2008-11-22 22:40:25 +01:00
|
|
|
|
|
|
|
gray_inc_1 = GrayInc(graycnt_comb, enable, clock, reset, width)
|
|
|
|
|
|
|
|
@always(clock.posedge)
|
|
|
|
def reg_1():
|
|
|
|
graycnt.next = graycnt_comb
|
|
|
|
|
|
|
|
return gray_inc_1, reg_1
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
width = 8
|
2012-12-21 15:06:18 +01:00
|
|
|
graycnt = Signal(modbv(0)[width:])
|
|
|
|
enable = Signal(bool())
|
|
|
|
clock = Signal(bool())
|
2012-12-21 14:36:07 +01:00
|
|
|
reset = ResetSignal(0, active=0, async=True)
|
|
|
|
|
2008-11-22 22:40:25 +01:00
|
|
|
toVerilog(GrayIncReg, graycnt, enable, clock, reset, width)
|
|
|
|
toVHDL(GrayIncReg, graycnt, enable, clock, reset, width)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|