当前位置: 首页 > news >正文

HDLbits: Lfsr5

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

module top_module(input clk,input reset,    // Active-high synchronous reset to 5'h1output [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;elseq <= q;
endmodulemodule dff(input clk, input d, output Q);always@(posedge clk)Q <= d;
endmodule

参考网友的写法:

module top_module(input clk,input reset,    // Active-high synchronous reset to 5'h1output [4:0] q
); always@(posedge clk)if(reset)q <= 5'h1;elseq <= {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]};

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 @(*) beginq_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 assignmentsq_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) beginif (reset)q <= 5'h1;elseq <= q_next;endendmodule

http://www.lryc.cn/news/188440.html

相关文章:

  • Visual Studio 错误CS0006:未能找到元数据文件踩坑记录
  • tcpdump(三)命令行参数讲解(二)
  • 面试算法25:链表中的数字相加
  • APP如何设计应用的屏幕截图以提高下载量
  • qt 关于自定义控件,然后其他页面提升后背景样式表不生效问题
  • 对比纯软开与嵌入式硬件开发谁更好呢?
  • 软考 系统架构设计师系列知识点之软件质量属性(5)
  • 修改ubuntu服务器fs文件最大打开数
  • linux下Qt的pro文件
  • git常用命令和开发常用场景
  • 02 认识Verilog HDL
  • 解决VUE安装依赖时报错:npm ERR! code ERESOLVE
  • 软件公司的项目管理软件选择指南
  • 2、服务器安装docker
  • UDP报文结构
  • (高阶) Redis 7 第21讲 IO多路复用模型 完结篇
  • 2023年入职/转行网络安全,该如何规划?
  • 解密RabbitMQ:你所不知道的端口及其重要性
  • Docker 环境搭建 (centeros)
  • 服务器编程基本框架
  • Leetcode——数组的遍历系列练习
  • 免费的ChatGPT与StableDiffusion AI绘画 二合一 附在线地址
  • vivado FFT IP仿真(3)FFT IP选项说明
  • 正点原子嵌入式linux驱动开发——Busybox根文件系统构建
  • React闭包
  • 【VS Code】推荐一套我非常喜欢的主题和字体样式
  • 【SQL】MySQL中的约束
  • css div左右布局
  • 06_Node.js服务器开发
  • git中添加不上传的文件夹或文件的名字