VerilogCPU/edge_detector.sv

19 lines
457 B
Systemverilog
Raw Permalink Normal View History

2018-06-05 23:42:20 -07:00
/**
* Simple edge detector circuit. Takes in a clock and a signal,
* and produces an output of 1 when the signal changes from 0 to 1.
* Otherwise, the output is 0.
*/
2018-06-07 21:26:46 -07:00
momodule edge_detector(input logic in, clk, reset,
output logic pos_edge, neg_edge);
2018-06-05 22:57:01 -07:00
logic old_in;
2018-06-05 23:42:20 -07:00
2018-06-05 22:57:01 -07:00
always_ff@(posedge clk)
2018-06-07 21:26:46 -07:00
if(reset)
old_in <= 0;
else
old_in <= in;
2018-06-05 23:42:20 -07:00
2018-06-07 21:26:46 -07:00
assign pos_edge = in & ~old_in;
assign neg_edge = ~in & old_in;
endmodulemodule