Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Register.sv 2.3 KiB

il y a 3 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. `timescale 1ns / 1ps
  2. //////////////////////////////////////////////////////////////////////////////////
  3. // Company: BITSILICA PRIVATE LIMITED
  4. //
  5. // Design Name: Register
  6. // Module Name: register
  7. // Project Name: POLAR ENCODER-DECODER
  8. // Tool Versions: VIVADO 2020.1
  9. //////////////////////////////////////////////////////////////////////////////////
  10. // register is written to synchronize a combiational logic w.r.t clock and reset signals
  11. module register #(
  12. parameter int WIDTH = 1, // width of the input and output of the register
  13. parameter logic [1:0] SR = 2'b00, // SET and RESET inputs of the register
  14. parameter logic [WIDTH-1:0] RST_VAL = {WIDTH{1'b0}} // reset value to be provided at the output when reset signal is active
  15. ) (
  16. input logic clk, // clock signal for register
  17. input logic rstb, // active low, synchronous reset
  18. input logic [WIDTH-1:0] din, // input to be registered
  19. output logic [WIDTH-1:0] dout // registered outputs
  20. );
  21. generate
  22. if(SR==2'b00) begin : NON_RESET_FLOP // if SR==00, irrespective of other signals the input needs to be registered
  23. always_ff @ (posedge clk) begin
  24. dout <= din; // registering input w.r.t posedge of clock signal
  25. end
  26. end : NON_RESET_FLOP
  27. else begin: RESET_FLOP // if SR!==00, input needs to be registered according to other signals w.r.t posedge of clock signal
  28. always_ff @ (posedge clk ) begin
  29. if (~rstb) // if reset is active
  30. if (SR == 2'b01)
  31. dout <= {WIDTH{1'b0}}; // if SR==01, reset the output
  32. else if (SR == 2'b10)
  33. dout <= {WIDTH{1'b1}}; // if SR==10, set the output
  34. else
  35. dout <= RST_VAL; // if SR==11, reset the output according the reset value provided
  36. else
  37. dout <= din; // if reset is inactive, register the input
  38. end
  39. end: RESET_FLOP
  40. endgenerate
  41. endmodule