From 64b8a07b2c72e5fb870bafe9ef00f926d1bd0faf Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sun, 9 Aug 2020 19:44:09 +0100 Subject: [PATCH] add rising edge function for generating pulse --- src/nmutil/util.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/nmutil/util.py b/src/nmutil/util.py index 3aae6ef..5e8660b 100644 --- a/src/nmutil/util.py +++ b/src/nmutil/util.py @@ -1,5 +1,5 @@ from collections.abc import Iterable -from nmigen import Mux +from nmigen import Mux, Signal # XXX this already exists in nmigen._utils # see https://bugs.libre-soc.org/show_bug.cgi?id=297 @@ -46,3 +46,15 @@ def wrap(process): yield from process return wrapper + +# a "rising edge" generator. can take signals of greater than width 1 + +def rising_edge(m, sig): + delay = Signal.like(sig) + rising = Signal.like(sig) + delay.name = "%s_dly" % sig.name + rising.name = "%s_rise" % sig.name + m.d.sync += delay.eq(sig) # 1 clock delay + m.d.comb += rising.eq(sig & ~delay) # sig is hi but delay-sig is lo + return rising + -- 2.30.2