mirror of
https://github.com/myhdl/myhdl.git
synced 2024-12-14 07:44:38 +08:00
23 lines
562 B
Python
23 lines
562 B
Python
|
from __future__ import generators
|
||
|
from myhdl import Signal, intbv, posedge, negedge
|
||
|
|
||
|
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
|
||
|
"""
|
||
|
while 1:
|
||
|
yield posedge(clock), negedge(reset)
|
||
|
if reset == ACTIVE_LOW:
|
||
|
count.next = 0
|
||
|
else:
|
||
|
if enable:
|
||
|
count.next = (count + 1) % n
|
||
|
|