(Verilog)有关如何使用LSFR使LED随机闪烁的建议

时间:2018-12-09 18:18:19

标签: verilog fpga quartus

我目前正在研究开发“记忆游戏”的项目。目前,我有4个使用LSFR的随机LED闪烁。我的问题是我需要使LED一次闪烁1,但不确定如何执行此操作。

如果有人可以提供建议,我将非常感谢!

    module Memory_Game
 #(parameter BITS = 5)
(clk, rst_n, out); 
input clk;
input rst_n;
output reg [3:0] out;
reg [3:0] out_next;
integer count=0;
reg clk_1hz;
reg [3:0] I; //user input is stored here
reg [3:0] R;

initial begin
        R <= 4'b0101;
        I <= 4'b0000;
        out_next <= 4'b0001;
 end

always @ (posedge clk) begin // slows our clock from 50mhz to 1hz 
if (count<25000000)
    count = count +1; 
    else begin 
    clk_1hz = ~clk_1hz;
    count = 0;
    end 
end 


always @* begin // responsible for determing the blinking of the leds
   out_next = out;
      repeat(BITS) begin
        R <= {R[2:0], R[3] ^ R[0]}; 
      out_next = {out_next[2:0],(out_next[3]^out_next[0])};
end
end


   always @(posedge clk_1hz or negedge rst_n) begin
      if(!rst_n)
         out <= 4'h1f;
      else
         out <= out_next;
        end

endmodule

0 个答案:

没有答案