People tend to frown on using data as a watch for various reasons.
Personally, if I wrote this, I would go with:
module edge_detect (
input A,
input B,
input clk,
output OUT
);
reg AA;
reg BB;
wire enA;
always @(posedge clk) begin
BB <= B;
end
assign enA = !BB && B;
always @(posedge clk)begin
if (enA) begin
AA <= A;
end
end
assign OUT = AA;
endmodule
+----+
A ----------------------------|D |----- OUT
+---+ | AA |
/--------------| | | |
| +----+ |AND|------|E |
B ----| |------o| | | |
| BB | +---+ | |
clk ----|> | clk ----|> |
+----+ +----+
The behavior is a little different though.
source
share