Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to make 4 bits adder to output 5 bits ?

Status
Not open for further replies.

gunnerunbeaten

Member level 2
Member level 2
Joined
Nov 15, 2010
Messages
42
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,551
when i write code below :
Code:
library IEEE;
use IEEE.std_logic_textio.all;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
.....
signal stage1 : unsigned (63 downto 0);
signal stage2 : unsigned (39 downto 0);
...
[COLOR="#FF0000"]stage2(4 downto 0) <= stage1(7 downto 4) + stage1(3 downto 0) ;[/COLOR]

after synthesis , there is error : " Target slice is 5 elements ; value is 4 elements ". Then i change inputs to 5 elements, but the timing is increase.
in verilog 4 bits + 4 bits => 5 bits is OK, how to do that in VHDL?
 

You can try this:
stage2(4 downto 0) <= ('0' & stage1(7 downto 4)) + ('0' & stage1(3 downto 0));
 

Use "resize" on one of the operands, to make it the same size as the result:

stage2(4 downto 0) <= resize(stage1(7 downto 4), 5) + stage1(3 downto 0);
 
You can try this:
stage2(4 downto 0) <= ('0' & stage1(7 downto 4)) + ('0' & stage1(3 downto 0));

This is fine for the OP's unsigned example, but std_match's example will work for signed and unsigned types.
 
Use "resize" on one of the operands, to make it the same size as the result:

stage2(4 downto 0) <= resize(stage1(7 downto 4), 5) + stage1(3 downto 0);

how about : 1 bit + 1 bit => 2 bits. when synthesis , i see error when " 1 bit + 1 bit " ????

- - - Updated - - -

This is fine for the OP's unsigned example, but std_match's example will work for signed and unsigned types.

how about : 1 bit + 1 bit => 2 bits. when synthesis , i see error when " 1 bit + 1 bit " ????
 

how about : 1 bit + 1 bit => 2 bits. when synthesis , i see error when " 1 bit + 1 bit " ????
No problem, if you use vectors of length 1, like "stage1(4 downto 4)".
It doesn't work for single bits, like "stage1(4)".
 
No problem, if you use vectors of length 1, like "stage1(4 downto 4)".
It doesn't work for single bits, like "stage1(4)".
in verilog , this code :
Code:
stage1[3:0] <= stage0[7] + stage0[6] + stage0[5] + stage0[4] + stage0[3] + stage0[2] + stage0[1] + stage0[0] ;

have no problem when synthesis, but when running in FPGA , the result is fail.
so I change this to VHDL :
Code:
stage1(3 downto 0) <=     stage0(7) +   stage0(6) +   stage0(5)  ;

the synthesis is error : "found '0' definitions of operator "+", cannot determine exact overloaded matching definition for "+""

your mean i have to do that ???
Code:
stage1(3 downto 0) <=     resize (stage0(7 downto 7),4) +   resize (stage0(6 downto 6),4) +   resize (stage0(5 downto 5),4)
 

Yes. Remember VHDL has a strong typing system.

So
signal a : unsigned(7 downto 0);

a is an array of std_logic

a(4) is a std_logic type. It is not an array. There are no arithmetic functions for std_logic type.
a(4 downto 4) is an unsigned type of length 1. hence you can do arithmatic on it.
 
Yes. Remember VHDL has a strong typing system.

So
signal a : unsigned(7 downto 0);

a is an array of std_logic

a(4) is a std_logic type. It is not an array. There are no arithmetic functions for std_logic type.
a(4 downto 4) is an unsigned type of length 1. hence you can do arithmatic on it.

Thank you so much !
 

It is enough to use "resize" on one of the operands:

stage1(3 downto 0) <= resize(stage0(7 downto 7), 4) + stage0(6 downto 6) + stage0(5 downto 5);
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top