1
0
mirror of https://github.com/myhdl/myhdl.git synced 2025-01-24 21:52:56 +08:00
2006-03-08 16:03:09 +00:00

58 lines
1.6 KiB
Python

from myhdl import *
def TimeCount(tens, ones, tenths, startstop, reset, clock):
""" 3 digit time counter in seconds and tenths of a second.
tens: most significant digit of the seconds
ones: least significant digit of the seconds
tenths: tenths of a second
startstop: input that starts or stops the counter on posedge
reset: reset input
clock: 10kHz clock input
"""
@instance
def logic():
seen = False
counting = False
while True:
yield clock.posedge, reset.posedge
if reset:
tens.next = 0
ones.next = 0
tenths.next = 0
seen = False
counting = False
else:
if startstop and not seen:
seen = True
counting = not counting
elif not startstop:
seen = False
if counting:
if tenths == 9:
tenths.next = 0
if ones == 9:
ones.next = 0
if tens == 5:
tens.next = 0
else:
tens.next = tens + 1
else:
ones.next = ones + 1
else:
tenths.next = tenths + 1
return logic