sync.v 379 B

1234567891011121314151617181920212223
  1. module sync #(parameter WIDTH = 4)
  2. (
  3. input reset_n,
  4. input clk,
  5. input [WIDTH - 1 : 0] in,
  6. output [WIDTH - 1 : 0] out
  7. );
  8. reg [WIDTH - 1 : 0] data_gray [1 : 0];
  9. assign out = data_gray[1];
  10. always @(posedge clk) begin
  11. if (reset_n == 1'b0) begin
  12. data_gray[0] <= 0;
  13. data_gray[1] <= 0;
  14. end else begin
  15. data_gray[1] <= data_gray[0];
  16. data_gray[0] <= in;
  17. end
  18. end
  19. endmodule