Author Topic: How to add in Verilog? Quartus, EPM7064STC44 etc.  (Read 499 times)

0 Members and 1 Guest are viewing this topic.

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
How to add in Verilog? Quartus, EPM7064STC44 etc.
« on: March 27, 2023, 08:25:59 pm »
So following on from my other thread I am essentially going to try to target a EPM7064STC44 and develop in Verilog using Quartus II 13.x...

All is going well for my first design... so moving to my second...

I have 2 values (both 8-bit unsigned) that I have to add together and then add 1... I need to produce the output.

Now simplistically...

adj_value = value1+value2+1

This works but produces some interesting output...

Info (278001): Inferred 1 megafunctions from design logic
Info (278002): Inferred adder/subtractor megafunction ("lpm_add_sub") from the following logic: "Add0"
Info (12130): Elaborated megafunction instantiation "lpm_add_sub:Add0"

OK... well if it wants to I suppose it can...

but this one is a bit more worrying...

Warning (10230): Verilog HDL assignment warning at Thing.sv(25): truncated value with size 32 to match size of target (8)

I have...

reg [7:0] adjusted_value;

always @(posedge s1_i) begin
   adjusted_value = value1+value2+1;
end

So really I just want an 8 bit full adder (where I can use the lowest carry to incorporate my +1)

These warnings made me wonder...  Should I be using something that is more knowledgeable about the underlying device?  Can I force the arithmetic to 8bit?  Should I bite the bullet and use a megafunction (and lock myself into the IP) or is there some more portable middle-ground?

Apologies for the newbie question!

 

Offline AK6DN

  • Regular Contributor
  • *
  • Posts: 55
  • Country: us
Re: How to add in Verilog? Quartus, EPM7064STC44 etc.
« Reply #1 on: March 27, 2023, 08:40:32 pm »
The warning is referring to the unsized constant "+1" you are using, it will be inferred as 32b by default.
So you are adding two 8b values and a 32b value and storing an 8b result. Thus the (innocuous, usually) warning.
If you want change the "+1" to be a sized value, like "+8'd1" to make it an 8b decimal 1.
Or just ignore the warning.
 
The following users thanked this post: NivagSwerdna

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: How to add in Verilog? Quartus, EPM7064STC44 etc.
« Reply #2 on: March 27, 2023, 09:02:33 pm »
That fixed it!  Thanks!

PS
I could probably squeeze an extra LUT by going proprietary but I have spare.  Much nicer to be more portable.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf