
Make exceptions only where you can't handle it other way, and think carefully before each such decision. In other words - just one signal is assigned over in always block. As a guideline, I suggest you will define a separate always block for each signal. You may also want to read this paper in order to get a deeper understanding of Verilog simulators behavior.Įxcept for that, your coding style is very bug-prone. In this case either think of other algorithmic implementation, or spread the calculation on several clock cycles. Once again: if synthesis tool warns you about comb loops you mustn't use this design. Where calcNewHashValue is the function encapsulating the for loop from your code. HashValue <= calcNewHashValue(hashValue, poly, data_in)
#Crc32 verilog code
Therefore you might use the second approach, in which case the code will look like this (not tested): always clk)
#Crc32 verilog software
However, this approach may be tricky, since many algorithms are written in software forms. The first approach is the correct one - Verilog is not a programming language, and the statements you are using to describe logic must be maximally similar to the inferred logic. Find an equivalent form which does not use circular reference.However, by inspection of your code, it seems that circular reference here is just for convenience - maybe it will not synthesize into comb loop. You want to avoid using any synthesizable comb loop. Even if they are intended - this is very bad practice.

There correct way to handle this is to define a clock signal and use a sequential always clk) construct.įurthermore, it seems that you have at least two combinatorial loops in your code. Was a Google Mapmaker Advocate and speaker on several international Google. Specializes in interconnecting computers, robots and humans. Used machine learning before it had a name. He is developing embedded systems since the eighties. About the Author: Lammert Bies is a dad, husband and polyglot. Once again - synthesis tool will produce the correct logic for this code, therefore these kind of bugs are very dangerous. On-line CRC calculation and free library.
#Crc32 verilog simulator

In your code these signals are: data_in, poly and hashValue. always construct means "evaluate the following block of code any time any of the signals used on the right hand side of the assignment change".

However, in simulation it behaves differently: If you will synthesize this code and run a test on FPGA - it will work (at least you'll not see constant hash value). This is a good example of mismatch in results between simulation and synthesis.
