mirror of
https://github.com/myhdl/myhdl.git
synced 2025-01-24 21:52:56 +08:00
partial
This commit is contained in:
parent
eee364fd65
commit
42f26ccded
@ -1,13 +1,10 @@
|
|||||||
from __future__ import generators
|
|
||||||
|
|
||||||
from random import randrange
|
from random import randrange
|
||||||
|
from myhdl import *
|
||||||
from myhdl import Signal, Simulation, StopSimulation
|
|
||||||
from myhdl import intbv, delay, posedge, negedge, now, always, instance
|
|
||||||
|
|
||||||
ACTIVE_LOW, INACTIVE_HIGH = 0, 1
|
ACTIVE_LOW, INACTIVE_HIGH = 0, 1
|
||||||
|
|
||||||
def Inc(count, enable, clock, reset, n):
|
def Inc(count, enable, clock, reset, n):
|
||||||
|
|
||||||
""" Incrementer with enable.
|
""" Incrementer with enable.
|
||||||
|
|
||||||
count -- output
|
count -- output
|
||||||
@ -15,20 +12,24 @@ def Inc(count, enable, clock, reset, n):
|
|||||||
clock -- clock input
|
clock -- clock input
|
||||||
reset -- asynchronous reset input
|
reset -- asynchronous reset input
|
||||||
n -- counter max value
|
n -- counter max value
|
||||||
|
|
||||||
"""
|
"""
|
||||||
while 1:
|
|
||||||
yield clock.posedge, reset.negedge
|
@always(clock.posedge, reset.negedge)
|
||||||
|
def incLogic():
|
||||||
if reset == ACTIVE_LOW:
|
if reset == ACTIVE_LOW:
|
||||||
count.next = 0
|
count.next = 0
|
||||||
else:
|
else:
|
||||||
if enable:
|
if enable:
|
||||||
count.next = (count + 1) % n
|
count.next = (count + 1) % n
|
||||||
|
|
||||||
|
return incLogic
|
||||||
|
|
||||||
|
|
||||||
def testbench():
|
def testbench():
|
||||||
count, enable, clock, reset = [Signal(intbv(0)) for i in range(4)]
|
count, enable, clock, reset = [Signal(intbv(0)) for i in range(4)]
|
||||||
|
|
||||||
INC_1 = Inc(count, enable, clock, reset, n=4)
|
inc_1 = Inc(count, enable, clock, reset, n=4)
|
||||||
|
|
||||||
HALF_PERIOD = delay(10)
|
HALF_PERIOD = delay(10)
|
||||||
|
|
||||||
@ -55,7 +56,7 @@ def testbench():
|
|||||||
yield delay(1)
|
yield delay(1)
|
||||||
print " %s %s" % (enable, count)
|
print " %s %s" % (enable, count)
|
||||||
|
|
||||||
return clockGen, stimulus, INC_1, monitor
|
return clockGen, stimulus, inc_1, monitor
|
||||||
|
|
||||||
tb = testbench()
|
tb = testbench()
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from myhdl import Signal, Simulation, delay, always_comb
|
from myhdl import Signal, Simulation, delay, always_comb
|
||||||
|
|
||||||
def Mux(z, a, b, sel):
|
def Mux(z, a, b, sel):
|
||||||
|
|
||||||
""" Multiplexer.
|
""" Multiplexer.
|
||||||
|
|
||||||
z -- mux output
|
z -- mux output
|
||||||
@ -8,14 +9,15 @@ def Mux(z, a, b, sel):
|
|||||||
sel -- control input: select a if asserted, otherwise b
|
sel -- control input: select a if asserted, otherwise b
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@always_comb
|
@always_comb
|
||||||
def muxlogic():
|
def muxLogic():
|
||||||
if sel == 1:
|
if sel == 1:
|
||||||
z.next = a
|
z.next = a
|
||||||
else:
|
else:
|
||||||
z.next = b
|
z.next = b
|
||||||
|
|
||||||
return muxlogic
|
return muxLogic
|
||||||
|
|
||||||
from random import randrange
|
from random import randrange
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user