Created
March 8, 2023 13:34
-
-
Save DanielChuDC/70ca348ebb78f5bd7fe5e37f5430d84b to your computer and use it in GitHub Desktop.
LSFR Verilog Implementation example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module lfsr( | |
input clk, | |
input rst, | |
output reg [3:0] rand_out, | |
output reg [3:0] LED | |
); | |
reg [3:0] lfsr_reg; | |
always @(posedge clk or posedge rst) begin | |
if (rst) begin | |
lfsr_reg <= 4'b0001; // set initial value of LFSR | |
end else begin | |
lfsr_reg <= {lfsr_reg[2:0], lfsr_reg[3] ^ lfsr_reg[2]}; | |
// feedback taps at bits 3 and 2, shift left | |
end | |
end | |
assign rand_out = lfsr_reg; | |
assign LED = lfsr_reg; | |
endmodule |
Author
DanielChuDC
commented
Mar 8, 2023
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment