2016-03-10 20:27:07 +01:00
|
|
|
import myhdl
|
2005-12-14 14:41:53 +00:00
|
|
|
from myhdl import *
|
2003-04-24 19:24:37 +00:00
|
|
|
|
|
|
|
ACTIVE_LOW, INACTIVE_HIGH = 0, 1
|
|
|
|
|
|
|
|
def inc(count, enable, clock, reset, n):
|
|
|
|
""" Incrementer with enable.
|
|
|
|
|
|
|
|
count -- output
|
|
|
|
enable -- control input, increment when 1
|
|
|
|
clock -- clock input
|
|
|
|
reset -- asynchronous reset input
|
|
|
|
n -- counter max value
|
|
|
|
"""
|
2005-12-14 14:41:53 +00:00
|
|
|
|
|
|
|
@always(clock.posedge, reset.negedge)
|
|
|
|
def logic():
|
2003-04-24 19:24:37 +00:00
|
|
|
if reset == ACTIVE_LOW:
|
|
|
|
count.next = 0
|
|
|
|
else:
|
|
|
|
if enable:
|
|
|
|
count.next = (count + 1) % n
|
|
|
|
|
2005-12-14 14:41:53 +00:00
|
|
|
return logic
|