image.png

    1. `timescale 1ns/1ns
    2. module edge_detect(
    3. input clk,
    4. input rst_n,
    5. input a,
    6. output reg rise,
    7. output reg down
    8. );
    9. reg a_r1;
    10. always @(posedge clk or negedge rst_n) begin
    11. if(!rst_n) begin
    12. rise <= 1'b0;
    13. down <= 1'b0;
    14. end
    15. else begin
    16. a_r1 <= a;
    17. if(!a_r1 & a) begin
    18. rise <= 1'b1;
    19. end
    20. else if(a_r1 & !a) begin
    21. down <= 1'b1;
    22. end
    23. else begin
    24. rise <= 1'b0;
    25. down <= 1'b0;
    26. end
    27. end
    28. end
    29. endmodule