본문 바로가기

Verilog/HDLbits

[HDLBits] Lfsr5

1. 문제 및 설명

  • 선형 피드백 시프트 레지스터(LSFR)를 설계하시오.
    • 아래 도식은 비트 위치 5와 3에 탭이 있는 5비트 최대 길이 LSFR이다.(탭 위치는 일반적으로 1부터 번호를 매긴다.)

2. 모듈 정의

module top_module(
    input clk,
    input reset,    // Active-high synchronous reset to 5'h1
    output [4:0] q
);

 

 

3. 답

module top_module(
    input clk,
    input reset,    // Active-high synchronous reset to 5'h1
    output [4:0] q
); 
    wire input_5, input_3;
    
    //assign input_5 = q[0];
    //assign input_3 = q[3]^q[0];

    DFF_a i4 (clk, reset, q[0], q[4]);
    DFF_a i3 (clk, reset, q[4], q[3]);
    DFF_a i2 (clk, reset, q[3]^q[0], q[2]);
    DFF_a i1 (clk, reset, q[2], q[1]);
    DFF_b i0 (clk, reset, q[1], q[0]);
    

            

endmodule

module DFF_a(
    input clk,
    input reset,
    input D,
    output Q);
    
    always@(posedge clk)
        begin
            if(reset)
                Q <= 1'b0;
            else
                begin
                    Q <= D;
                end
        end
endmodule

module DFF_b(
    input clk,
    input reset,
    input D,
    output Q);
    
    always@(posedge clk)
        begin
            if(reset)
                Q <= 1'b1;
            else
                begin
                    Q <= D;
                end
        end
endmodule

'Verilog > HDLbits' 카테고리의 다른 글

[HDLBits] Shift18  (0) 2026.01.22
[HDLBits] Mt2015 lfsr  (0) 2026.01.22
[HDLBits] Shift18  (0) 2026.01.19
[HDLBits] Rotate100  (0) 2026.01.19
[HDLBits] Shift4  (0) 2026.01.14