1
0
mirror of https://github.com/myhdl/myhdl.git synced 2025-01-24 21:52:56 +08:00
This commit is contained in:
jand 2005-12-16 22:23:45 +00:00
parent a2f7106f14
commit 24c5c1251f
2 changed files with 10 additions and 3 deletions

View File

@ -7,7 +7,7 @@ from myhdl import *
from util import setupCosimulation
def bin2gray(B, G, width):
def bin2gray2(B, G, width):
""" Gray encoder.
B -- input intbv signal, binary encoded
@ -21,21 +21,24 @@ def bin2gray(B, G, width):
for i in range(width):
G.next[i] = Bext[i+1] ^ Bext[i]
def bin2gray2(B, G, width):
def bin2gray(B, G, width):
""" Gray encoder.
B -- input intbv signal, binary encoded
G -- output intbv signal, gray encoded
width -- bit width
"""
@always_comb
def logic():
Bext = intbv(0)[width+1:]
Bext[:] = B
for i in range(width):
G.next[i] = Bext[i+1] ^ Bext[i]
return always_comb(logic)
return logic
objfile = "bin2gray.o"

View File

@ -30,6 +30,7 @@ def incRef(count, enable, clock, reset, n):
count.next = (count + 1) % n
def inc(count, enable, clock, reset, n):
""" Incrementer with enable.
count -- output
@ -37,7 +38,9 @@ def inc(count, enable, clock, reset, n):
clock -- clock input
reset -- asynchronous reset input
n -- counter max value
"""
@always(clock.posedge, reset.negedge)
def incProcess():
if reset == ACTIVE_LOW:
@ -45,6 +48,7 @@ def inc(count, enable, clock, reset, n):
else:
if enable:
count.next = (count + 1) % n
return incProcess
def inc2(count, enable, clock, reset, n):