#学习记录#
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. 电子工业出版社.