Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
21602 Discussions

Exponents in Verilog

Altera_Forum
Honored Contributor II
3,139 Views

Hi, I am pretty new to Verilog and Quartus II, and was hoping someone could help me out. 

 

My output is a 12-bit signed register. I get the value of this through an equation, and as part of that equation I have an exponential calculation, 2**B (where B is a register containing a value of 0-10). Doing this gives me an error "Warning (10230): Verilog HDL assignment warning at xxx.v(25): truncated value with size 32 to match size of target (12)", but the value of the calculation is correct. I think this is because it is treating the 2 as 32-bit integer, then when it truncates to 12 bits, it is just cutting off leading zeroes. So I tried changing it to something like 2'd2**B, but then the result of the calculation is wrong. Is there a way to do an exponent without getting an error? 

 

Thanks so much!
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
2,032 Views

We should be clear. You are not getting an error but a warning. The warning is simply telling you that the value (2**B) has a result that is larger than 12 bits.  

 

You can safely ignore the warning. 

or 

change it to this: 

 

{12'd2}**B; 

 

Jake
0 Kudos
Altera_Forum
Honored Contributor II
2,032 Views

Thank you very much for the help. Just so that I can learn something through this process, I would really appreciate it if you could tell me how the code is interpreted differently. How is {12'd2) different than 12'd2? Thanks.

0 Kudos
Reply