mirror of
https://github.com/myhdl/myhdl.git
synced 2025-01-24 21:52:56 +08:00
43 lines
943 B
Python
43 lines
943 B
Python
from __future__ import absolute_import
|
|
from myhdl import *
|
|
|
|
def timer_sig(flag, clock, reset, MAXVAL):
|
|
|
|
count = Signal(intbv(0, min=0, max=MAXVAL+1))
|
|
|
|
@always (clock.posedge, reset.posedge)
|
|
def logic():
|
|
if reset == 1:
|
|
count.next = 0
|
|
else:
|
|
flag.next = 0
|
|
if count == MAXVAL:
|
|
flag.next = 1
|
|
count.next = 0
|
|
else:
|
|
count.next = count + 1
|
|
|
|
return logic
|
|
|
|
|
|
def timer_var(flag, clock, reset, MAXVAL):
|
|
|
|
@instance
|
|
def logic():
|
|
count = intbv(0, min=0, max=MAXVAL+1)
|
|
while True:
|
|
yield clock.posedge, reset.posedge
|
|
if reset == 1:
|
|
count[:] = 0
|
|
else:
|
|
flag.next = 0
|
|
if count == MAXVAL:
|
|
flag.next = 1
|
|
count[:] = 0
|
|
else:
|
|
count += 1
|
|
|
|
return logic
|
|
|
|
|