• HDLbits: Lfsr5


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

    1. module top_module(
    2. input clk,
    3. input reset, // Active-high synchronous reset to 5'h1
    4. output [4:0] q
    5. );
    6. dff dff_1(clk, 0 ^ q[0],q[4]);
    7. dff dff_2(clk, q[4] ,q[3]);
    8. dff dff_3(clk, q[3] ^ q[0] ,q[2]);
    9. dff dff_4(clk, q[2] ,q[1]);
    10. dff dff_5(clk, q[1] ,q[0]);
    11. always@(posedge clk)
    12. if(reset)
    13. q <= 1;
    14. else
    15. q <= q;
    16. endmodule
    17. module dff(input clk, input d, output Q);
    18. always@(posedge clk)
    19. Q <= d;
    20. endmodule

    参考网友的写法:

    1. module top_module(
    2. input clk,
    3. input reset, // Active-high synchronous reset to 5'h1
    4. output [4:0] q
    5. );
    6. always@(posedge clk)
    7. if(reset)
    8. q <= 5'h1;
    9. else
    10. q <= {0 ^ q[0],q[4],q[3]^q[0],q[2],q[1]};
    11. 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]};

    1. module top_module(
    2. input clk,
    3. input reset,
    4. output reg [4:0] q);
    5. reg [4:0] q_next; // q_next is not a register
    6. // Convenience: Create a combinational block of logic that computes
    7. // what the next value should be. For shorter code, I first shift
    8. // all of the values and then override the two bit positions that have taps.
    9. // A logic synthesizer creates a circuit that behaves as if the code were
    10. // executed sequentially, so later assignments override earlier ones.
    11. // Combinational always block: Use blocking assignments.
    12. always @(*) begin
    13. q_next = q[4:1]; // Shift all the bits. This is incorrect for q_next[4] and q_next[2]
    14. q_next[4] = q[0]; // Give q_next[4] and q_next[2] their correct assignments
    15. q_next[2] = q[3] ^ q[0];
    16. end
    17. // This is just a set of DFFs. I chose to compute the connections between the
    18. // DFFs above in its own combinational always block, but you can combine them if you wish.
    19. // You'll get the same circuit either way.
    20. // Edge-triggered always block: Use non-blocking assignments.
    21. always @(posedge clk) begin
    22. if (reset)
    23. q <= 5'h1;
    24. else
    25. q <= q_next;
    26. end
    27. endmodule

  • 相关阅读:
    基于STM32设计的便携式温度自动记录仪
    Day29_8 Java学习之MySQL数据库
    垃圾回收 -标记清除算法
    台湾大学神经网络架构设计
    基于协同过滤算法的电影推荐系统
    x86-Hardware-Compatibility-Assessment-and-Porting-Guide
    redis 哨兵集群搭建
    GPT-4科研实践:数据可视化、统计分析、编程、机器学习数据挖掘、数据预处理、代码优化、科研方法论
    Anaconda的升级、配置及使用
    【VS编译报错:错误 1 error MSB6006: “cmd.exe”已退出,代码为 1。】
  • 原文地址:https://blog.csdn.net/weixin_41004238/article/details/133696729