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
相关推荐
hazy1k3 小时前
51单片机基础-IO扩展(并转串 74HC165)
stm32·单片机·嵌入式硬件·fpga开发·51单片机·1024程序员节
9527华安4 小时前
全国产化方案实现NVMe over 100G RDMA,解决智算超算中“存算”不匹配问题
fpga开发·nvme·rdma
碎碎思4 小时前
FPGA新闻速览-从漏洞到突破:FPGA技术在安全、架构与量子领域
安全·fpga开发
FPGA_ADDA4 小时前
100%全国产化4路125M FMC子卡
fpga开发·fmc子卡·全国产·4路ad采集·国产ad9653
国科安芯8 小时前
抗辐照MCU芯片在激光雷达领域的适配性分析
网络·人工智能·单片机·嵌入式硬件·fpga开发
数字IC吗喽10 小时前
三、ILA逻辑分析仪抓取及查看波形
fpga开发
bnsarocket12 小时前
Verilog和FPGA的自学笔记8——按键消抖与模块化设计
笔记·fpga开发·verilog·自学·硬件编程
奋斗的牛马15 小时前
FPGA—ZYNQ学习GPIO-EMIO,MIO,AXIGPIO(五)
单片机·嵌入式硬件·学习·fpga开发·信息与通信
FPGA_ADDA18 小时前
基于VU13P的6U VPX 载板
fpga开发·信号处理·xcvu13p
KOAN凯擎小妹1 天前
晶振信号质量:上升下降时间与占空比
单片机·嵌入式硬件·fpga开发·信息与通信