Advertisement
Guest User

Untitled

a guest
Mar 30th, 2023
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VeriLog 1.28 KB | Source Code | 0 0
  1. module cyclic_coder_systematic(
  2.     input logic clk,
  3.     input logic enable,
  4.     input logic in,
  5.     output logic out
  6. );
  7.  
  8.     logic [3:0] higher_lfsr;
  9.     logic [3:0] lower_lfsr;
  10.     logic [3:0] bit_counter = 4'b0000;
  11.    
  12.     wire higher_datapath = higher_lfsr[0];
  13.     wire lower_datapath = lower_lfsr[0];
  14.     wire feedback = (bit_counter > 11) ? higher_datapath : 0;
  15.    
  16.     always @(posedge clk)
  17.         if (enable)
  18.             bit_counter <= bit_counter + 1'h1;
  19.        
  20.    
  21.     always @(posedge clk) begin
  22.         if (enable) begin
  23.              higher_lfsr[3] <= in ^ feedback;
  24.              higher_lfsr[2] <= higher_lfsr[3] ^ feedback;
  25.              higher_lfsr[1] <= higher_lfsr[2];
  26.              higher_lfsr[0] <= higher_lfsr[1];
  27.              
  28.              lower_lfsr[3] <= in;
  29.              lower_lfsr[2] <= lower_lfsr[3];
  30.              lower_lfsr[1] <= lower_lfsr[2];
  31.              lower_lfsr[0] <= lower_lfsr[1];
  32.          end else begin
  33.             higher_lfsr <= 4'b0000;
  34.             lower_lfsr  <= 4'b0000;
  35.         end
  36.        
  37.         if (bit_counter == 4'h0) begin
  38.             higher_lfsr <= 4'b0000;
  39.             lower_lfsr <= 4'b0000;
  40.         end
  41.     end
  42.    
  43.     assign out = (bit_counter > 11) ? lower_datapath : higher_datapath;
  44.        
  45. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement