hdl

What is the difference between == and === in Verilog?

帅比萌擦擦* 提交于 2019-11-29 01:43:11
问题 What is the difference between: if (dataoutput[7:0] == 8'bx) begin and if (dataoutput[7:0] === 8'bx) begin After executing dataoutput = 52'bx , the second gives 1, but the first gives 0. Why? (0 or 1 is the comparison result.) 回答1: Some data types in Verilog, such as reg , are 4-state. This means that each bit can be one of 4 values: 0,1,x,z. With the "case equality" operator, === , x's are compared, and the result is 1. With == , the result of the comparison is not 0, as you stated; rather,

How to implement a (pseudo) hardware random number generator

淺唱寂寞╮ 提交于 2019-11-27 20:19:19
How do you implement a hardware random number generator in an HDL (verilog)? What options need to be considered? This question is following the self-answer format. Addition answers and updates are encouraged. As noted in Morgan's answer this will only produce a single random bit. The number of bits in the LFSR only set how many values you get before the sequence repeats. If you want an N bit random number you have to run the LFSR for N cycles. However, if you want a new number every clock cycle the other option is to unroll the loop and predict what the number will be in N cycles. Repeating

Incrementing Multiple Genvars in Verilog Generate Statement

徘徊边缘 提交于 2019-11-27 18:03:54
问题 I'm trying to create a multi-stage comparator in verilog and I can't figure out how to increment multiple genvars in a single generate loop. I'm trying the following: genvar i,j; //Level 1 generate j=0; for (i=0;i<128;i=i+1) begin: level1Comp assign ci1[i] = minw(tc[j],tc[j+1]); j = j+2; end endgenerate And getting the following error: Error-[SE] Syntax error Following verilog source has syntax error : "encoder.v", 322: token is '=' j=0; Anyone know how to increment multiple genvars in the

Parameter array in Verilog

旧城冷巷雨未停 提交于 2019-11-26 23:27:12
问题 Is it possible to create parameter array in verilog? For example, anything like the following: parameter[TOTAL-1 : 0] PARAM_ARRAY = {1, 0, 0, 2} If it is not possible, what could be the alternative solution? Thanks in advance 回答1: The given example is assigning unpacked values to packed parameter array. This in not allowed with Verilog. Verilog only support simple vector based parameters. It does not support unpacked arrays. SystemVerilog, which superseded Verilog, does support parameter