I want to detect a rising edge of a signal from a flip-flop AA
to BB
+----+
A ----------------| |----- OUT
+----+ | BB |
B ----| |------|> |
| AA | +----+
clk ----|> |
+----+
Verilog code:
module edge_detect (
input A,
input B,
input clk,
output OUT
);
reg AA;
reg BB;
always @(posedge clk) begin
AA <= B;
end
always @(posedge AA)begin
BB <= A;
end
assign OUT = BB;
endmodule
The output of AA
is used as a clock to BB
saying that AA
has done its job and then BB
can now continue its operation.
I rarely see this code. Is this a good practice?
If not, are there any other proper way to detect an edge of a signal?
enA = not BB && B;
is equivalent toenA = !BB && B;
andif (enA) { ... }
is equivalent toif (enA) begin ... end
in verilog. Anyway, can you state its advantage? Thank you for the quick answer. =) – Macaluso