Verilog LFSR(2)

#学习记录#

数字设计-LFSR (1)-CSDN博客

1  Fibonacci LFSR

Fibonacci LFSR的反馈多项式为:x^3+x^2+1,电路图如下图1所示,schematic如图2所示。输出序列为111-110-100-001-010-101-011。

图1  斐波那契LFSR电路图

图2  斐波那契LFSR schematic

1.1  Verilog描述Fibonacci LFSR

1.1.1  代码

`timescale 1ns / 1ps
//
// Company: 
// Engineer: Mr-pn-junction
// 
// Create Date: 2023/11/01 08:00:45
// Design Name: 
// Module Name: LFSR_fibonacci
// Project Name: 
// Target Devices: 
// Tool Versions: 
// Description: 
// 
// Dependencies: 
// 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// 
//


module LFSR_fibonacci(
    input clk,
    input rst_n,
    output reg [2:0] q
    );
always @(posedge clk or negedge  rst_n) begin
    if(!rst_n) 
        q<=3'b111;
    else
    q<={q[1],q[0],q[2]^q[1]};
end           
endmodule

1.1.2  testbench

`timescale 1ns / 1ps
//
// Company: 
// Engineer: Mr-pn-junction
// 
// Create Date: 2023/11/01 08:15:30
// Design Name: 
// Module Name: LFSR_fibonaccitb
// Project Name: 
// Target Devices: 
// Tool Versions: 
// Description: 
// 
// Dependencies: 
// 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// 
//


module LFSR_fibonaccitb(  );
    reg clk;
    reg rst_n;
    wire [2:0] q;
LFSR_fibonacci tb(
    .clk(clk),
    .rst_n(rst_n),
    .q(q)
);
initial begin
    rst_n=0;clk=0;
    #5
    rst_n=1;
    #1000
    $stop;
end
always #5 clk=~clk;
endmodule

1.2  仿真波形

图3  斐波那契LFSR仿真波形

2  Galois LFSR

Galois LFSR的反馈多项式为x^3+x^2+1,电路如图4所示,schematic如图5所示。输出序列为111-101-100-010-001-110-011。

图4  伽罗瓦LFSR电路图

图5  伽罗瓦LFSR schematic

2.1  Verolog描述Galois LFSR

2.1.1  代码

`timescale 1ns / 1ps
//
// Company: 
// Engineer: Mr-pn-junction
// 
// Create Date: 2023/11/01 08:47:10
// Design Name: 
// Module Name: LFSR_galois
// Project Name: 
// Target Devices: 
// Tool Versions: 
// Description: 
// 
// Dependencies: 
// 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// 
//


module LFSR_galois(
    input clk,
    input rst_n,
    output reg [2:0] q
 );
always @(posedge clk or negedge rst_n) begin
    if(!rst_n)
        q<=3'b111;
    else
        q<={q[0],q[2]^q[0],q[1]};
end
endmodule

2.1.2  testbench

`timescale 1ns / 1ps
//
// Company: 
// Engineer: Mr-pn-junction
// 
// Create Date: 2023/11/01 09:03:07
// Design Name: 
// Module Name: LFSR_galoistb
// Project Name: 
// Target Devices: 
// Tool Versions: 
// Description: 
// 
// Dependencies: 
// 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// 
//


module LFSR_galoistb(  );
    reg    clk;
    reg  rst_n;
    wire [2:0] q;
LFSR_galois tb(
    .clk(clk),
    .rst_n(rst_n),
    .q(q)
);

initial begin
    clk=0; rst_n=0;
    #5
    rst_n=1;
    #1000
    $stop;
end
always #5 clk=~clk;
endmodule

2.2  仿真波形

图6  伽罗瓦LFSR仿真波形

参考文献

[1] Verilog高级数字系统设计技术与实例分析. Kishore Mishra. 电子工业出版社.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值