m序列的verilog实现
module mxulie( clk, rst, ena, m_out, load ); input clk; input rst; input ena; output reg m_out; output reg load;
reg [11:0] shift;
always @(posedge clk) begin if(!rst) begin m_out <= 1'b0; load <= 1'b0; shift <= 12'b1111_1111_1111; end else begin if(ena) begin //shift[0] <= ( shift[0]^shift[3]^shift[5]^shift[11] ); shift <= { shift[10:0],shift[0] }; shift[0] <= ( shift[0]^shift[3]^shift[5]^shift[11] ); load <= 1'b1; end else begin load <= 1'b0; end //end m_out <= shift[11]; end end
endmodule
测试模块:
`timescale 1 ns/100 ps module m_test;
reg clk; reg rst; reg ena; wire load; wire m_out;
initial begin clk = 1'b0; rst = 1'b0; ena = 1'b0; #40 rst = 1'b1; #50 ena = 1'b1; end
always #10 clk = ~clk;
mxulie m1( .clk(clk), .rst(rst), .ena(ena), .load(load), .m_out(m_out) ); endmodule
程序中的m序列生成多项式为f(x)=x^12+x^6+x^4+x+1;
rst:复位信号,低电平有效
clk:时钟信号
ena:控制信号,高电平时序列发生器开始工作
m_out:数据信号,输出m伪随机序列
load:控制信号,为高电平时表示伪随机序列开始
posted on 2012-04-01 13:24 chenfengfei 阅读(2868) 评论(0) 收藏 举报