HDLbits: Lfsr5

我的错误写法,半成品,完全错误:

cs 复制代码
module top_module(
    input clk,
    input reset,    // Active-high synchronous reset to 5'h1
    output [4:0] q
); 
    
    dff dff_1(clk, 0 ^ q[0],q[4]);
    dff dff_2(clk, q[4] ,q[3]);
    dff dff_3(clk, q[3] ^ q[0] ,q[2]);
    dff dff_4(clk, q[2] ,q[1]);
    dff dff_5(clk, q[1] ,q[0]);
    
    always@(posedge clk)
        if(reset)
            q <= 1;
   		else
            q <= q;
endmodule

module dff(input clk, input d, output Q);
    always@(posedge clk)
        Q <= d;
endmodule

参考网友的写法:

cpp 复制代码
module top_module(
    input clk,
    input reset,    // Active-high synchronous reset to 5'h1
    output [4:0] q
); 
    always@(posedge clk)
        if(reset)
            q <= 5'h1;
    	else
            q <= {0 ^ q[0],q[4],q[3]^q[0],q[2],q[1]};   
endmodule

官方的写法:感觉像第一个always是一个组合逻辑块(阻塞赋值,执行有先后顺序),第二个always是时序逻辑块。

其中,q_next[4] = q[0];应该是q_next[4] = q[0] ^ 0; 因为值不变省略了。

另外q_next = q[4:1]; 应该是q_next ={q[0],q[4:1]};

cs 复制代码
module top_module(
	input clk,
	input reset,
	output reg [4:0] q);
	
	reg [4:0] q_next;		// q_next is not a register

	// Convenience: Create a combinational block of logic that computes
	// what the next value should be. For shorter code, I first shift
	// all of the values and then override the two bit positions that have taps.
	// A logic synthesizer creates a circuit that behaves as if the code were
	// executed sequentially, so later assignments override earlier ones.
	// Combinational always block: Use blocking assignments.
	always @(*) begin
		q_next = q[4:1];	// Shift all the bits. This is incorrect for q_next[4] and q_next[2]
		q_next[4] = q[0];	// Give q_next[4] and q_next[2] their correct assignments
		q_next[2] = q[3] ^ q[0];
	end
	
	
	// This is just a set of DFFs. I chose to compute the connections between the
	// DFFs above in its own combinational always block, but you can combine them if you wish.
	// You'll get the same circuit either way.
	// Edge-triggered always block: Use non-blocking assignments.
	always @(posedge clk) begin
		if (reset)
			q <= 5'h1;
		else
			q <= q_next;
	end
	
endmodule
相关推荐
最遥远的瞬间4 小时前
四、Xilinux在线调试方法和XADC的使用
fpga开发
tobias.b11 小时前
408真题解析-2010-12-计组-程序执行时间
单片机·嵌入式硬件·fpga开发·计算机考研·408真题解析
洋洋Young18 小时前
【Xilinx FPGA】7 Series 收发器架构与时钟设计
fpga开发·xilinx
unicrom_深圳市由你创科技19 小时前
XDMA 技术及在 Windows 平台的应用实践
fpga开发
s09071361 天前
【Agent】Claude code辅助verilog编程
fpga开发
3有青年1 天前
altera fpga agilex 5 连接到HVIO BANK上的参考时钟,是否可以作为HSIO BANK内部IOPLL的输入时钟
fpga开发
FPGA_ADDA2 天前
基于ZU47DR 的高性能射频卡
fpga开发
ooo-p2 天前
FPGA学习篇——Verilog学习之“流水灯”
学习·fpga开发
FPGA小c鸡2 天前
【FPGA视频处理】帧缓冲设计完全指南:从单缓冲到三缓冲的深度解析与实战应用
fpga开发·音视频
hexiaoyan8272 天前
【无标题】高速信号处理设计原理图:413-基于双XCVU9P+C6678的100G光纤加速卡
fpga开发·高速信号处理·光纤加速·xcvu9p芯片·硬件加速卡