Edge Detector
Let's start with the most fundamental design that is widely used in logic design - the edge detector. The edge detector generates a synchronous one clock cycle pulse upon a change in level (transition) of a signal from high->low or low->high. Edge detectors are used to detect the initial condition and to trigger other logic dependent on this signal - an example would be an active low interrupt where the transition from high to low indicates an interrupt has been asserted.
The edge detect circuit and waves are depicted in the thumbnail below - this detects both rising and falling transitions of the signal.
Edge Detector Circuit
We will now look at the verilog code to implement this logic :
-
always @(posedge CLK or negedge RST_L) begin
-
if (~RST_L) begin
-
IN_D1 <= 1'b0;
-
IN_D2 <= 1'b0;
-
end
-
else begin
-
IN_D1 <= IN;
-
IN_D2 <= IN_D1;
-
end
-
end
-
-
wire OUT = IN_D1 ^ IN_D2; // detects both rising edge and falling edge transitions
-
wire OUT_posedge = IN_D1 & ~IN_D2; // detects rising edge
-
wire OUT_negedge = ~IN_D1 & IN_D2; // detects falling edge
Sphere: Related Content