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
相关推荐
GateWorld2 小时前
深入浅出IIC协议 - 从总线原理到FPGA实战开发 -- 第一篇:I2C总线协议深度解剖
fpga开发·开源协议
爱学习的张哥4 小时前
UDP--DDR--SFP,FPGA实现之模块梳理及AXI读写DDR读写上板测试
单片机·fpga开发·udp·axi·ddr
白杨树田8 小时前
【EDA软件】【联合Modelsim仿真使用方法】
fpga开发
搬砖的小码农_Sky9 小时前
FPGA: XILINX Kintex 7系列器件的架构
fpga开发·架构·硬件架构
搬砖的小码农_Sky13 小时前
FPGA:如何提高RTL编码能力?
fpga开发·硬件架构
晶台光耦13 小时前
高速光耦在通信行业的应用(五) | 5Mbps通信光耦的特性
fpga开发
梓仁沐白19 小时前
Verilog HDL 语言整理
fpga开发
FPGA_ADDA1 天前
基于PXIE 总线架构的Kintex UltraScale 系列FPGA 高性能数据预处理板卡
fpga开发·pxie总线·ku060·ku115
搬砖的小码农_Sky1 天前
FPGA:Lattice的FPGA产品线以及器件选型建议
嵌入式硬件·fpga开发·硬件架构·硬件工程
超能力MAX1 天前
ZYNQ-AXI4 DDR读写测试
fpga开发