x^5 + x^4 + x^3 + 1.
The term x^5 is implied in the generic parameter since the length of the register is 5. Messages are shifted in and out most-significant-bit first (where the highest bit is the coefficient of the highest degree term in the polynomial.)
This code block has a mode with feedback enabled, and a shift-only mode for shifting out the result.
module lfsr(
input rst_n,
input clk,
input d,
input en,
input calc_shft_n,
output q
);
reg [4:0] shift;
parameter g = 5'b11001;
assign q = shift[4];
always @(posedge clk or negedge rst_n)
if (!rst_n)
shift <= 5'b00000;
else
if (en)
if (calc_shft_n) begin
shift[0] <= d ^ shift[4];
shift[1] <= shift[0] ^ (shift[4] & g[1]);
shift[2] <= shift[1] ^ (shift[4] & g[2]);
shift[3] <= shift[2] ^ (shift[4] & g[3]);
shift[4] <= shift[3] ^ (shift[4] & g[4]);
end
else begin
shift[0] <= d;
shift[1] <= shift[0];
shift[2] <= shift[1];
shift[3] <= shift[2];
shift[4] <= shift[3];
end
endmodule
No comments:
Post a Comment