How to Synthesize While Loop in Verilog?

前端 未结 3 830
南旧
南旧 2021-01-29 16:24

I have tried to design a Booth multiplier and it runs well in all compilers including:

Modelsim,Verilogger Extreame,Aldec Active Hdl & Xilinx\'s Isim......<

相关标签:
3条回答
  • 2021-01-29 16:56

    This is poorly written code.You have written it like a computer program. Verilog is a Hardware Description Language - not a programming language. In your case, synthesizer is trying to replicate logic inside the while loop in the case statement.

    • Design the hardware on a piece of paper before translating it to HDL
    • Identify the combinational and sequential logic in the design before coding.
    • Think what logic will synthesizer use to realize the logic you have written.
    0 讨论(0)
  • Here are some tips:

    • Remove the latches:
      • c[5:1] is a latch because it is not initialized in the if(a==5'b10000) branch.
      • d is not defined in if(a==5'b10000) and could be a potential latch depending on the synthesizer optimization capabilities.
      • e is not defined in if(b==5'b10000) and could be a potential latch like d.
      • At the beginning of the always block, make sure all the combination logic have initial values.
    • Try to avoid using disable for code to be synthesized. Use if-else statements instead.
      • Note: This is a guideline not a rule.
    • There is lot of redundant and poorly organized code:
      • All branches with in the case statement are the same. Should be cleaned up in consolidated.
      • There is code inside the while loop that is better suited outside the loop (e.g. the if(count*==3'b101) block)
    • If the while loop is having problems, try a for loop.
    0 讨论(0)
  • 2021-01-29 17:00

    While loops tend to imply something dynamic, like checking a condition. This is not a good use of verilog intended for synthesis. For loops which can be statically unrolled are more commonly used to shorten the written code.

    If you need some thing more dynamic a dedicated state machine should be written.

    To answer some of the questions raised in the comments:

    Combinatorial logic uses assign or is contained in always @* this is continuously evaluated and all runs in parallel think AND, OR, NOR gates.

    Sequential logic will be contained in an always @( posedge clk ) this is executed on every positive edge of the clock. The registers or memory elements used inside of this typically represent Flip-Flops.

    0 讨论(0)
提交回复
热议问题