Arithmetic operator (Sub/Add/+1/-1) N bits Cascaded

Guest #6038419
Rate this post
useful
not useful
Hello i've got a matter with my simulation, the result of the sub 
operation is not the result expected.

My code :

I) The dataflow code to describe cell.
1
 
2
library ieee;
3
use ieee.std_logic_1164.all;
4
use ieee.std_logic_unsigned.all;
5
use ieee.numeric_std.all;
6

7
entity cell is 
8
port(Ai,Bi,Ci : in std_logic;
9
     S : in std_logic_vector (1 downto 0);
10
     Co,Go : out std_logic);
11
end cell;
12

13
architecture dflow of cell is
14
signal oper : std_logic_vector(1 downto 0);
15
signal tabc : std_logic_vector(2 downto 0);
16
begin
17
with tabc select oper <=
18
                          '0' & Ai + Bi  when "001",
19
                          '0' & Ai + Bi when "010" ,
20
                          '0' & Ai - '1' when "011" ,
21
                    '0' & Ai + '1' when "100" ,
22
                          '0' & Ai - Bi when "101" ,
23
                          '0' & Ai + Bi + '1' when "110",
24
                          '0' & Ai when others;
25

26
Co <= oper(1);
27
Go <= oper(0);
28
tabc <= Ci&S;
29
end architecture;

II) The structural code to link 4 cells to implement the arithmetic 
operator
1
 
2
library ieee;
3
use ieee.std_logic_1164.all,ieee.std_logic_unsigned.all;
4

5

6
entity operator is
7
port(A,B : in std_logic_vector(3 downto 0);
8
     S : in std_logic_vector(1 downto 0);
9
     cin : in std_logic;
10
     G : out std_logic_vector(3 downto 0);
11
     cout : out std_logic);
12
end entity;
13

14
architecture rtl of operator is
15
component cell is 
16
port(Ai,Bi,Ci : in std_logic;
17
     S : in std_logic_vector (1 downto 0);
18
     Co,Go : out std_logic);
19
end component;
20
signal C : std_logic_vector(3 downto 1);
21
begin
22
cell0 : cell port map(Ai=>A(0),Bi=>B(0),Ci=>cin,S=>S,Co =>C(1),Go => G(0));
23
cell1 : cell port map(Ai=>A(1),Bi=>B(1),Ci=>C(1),S=>S,Co=>C(2),Go => G(1));
24
cell2 : cell port map(Ai=>A(2),Bi=>B(2),Ci=>C(2),S=>S,Co=>C(3),Go => G(2));
25
cell3 : cell port map(Ai=>A(3),Bi=>B(3),Ci=>C(3),S=>S,Co =>cout,Go =>G(3));
26
end architecture;
Attached files:
Moderator (Company: Titel) #6038481
Rate this post
useful
not useful
YouseKalack wrote:
> the result of the sub operation is not the result expected.
What do you expect and wht do you get instead?

> My code
Pls use the [vhdl] tags further on to wrap your code!
See the "Formatting options" above each edit box...

> use ieee.std_logic_unsigned.all;
> use ieee.numeric_std.all;
Never ever both together!
Otherwise you will encounter strange problems due to multiple type 
definitions.
Guest #6038527
Rate this post
useful
not useful
My code :

I) The dataflow code to describe cell.
1
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.std_logic_unsigned.all;
4
use ieee.numeric_std.all;
5

6
entity cell is 
7
port(Ai,Bi,Ci : in std_logic;
8
     S : in std_logic_vector (1 downto 0);
9
     Co,Go : out std_logic);
10
end cell;
11

12
architecture dflow of cell is
13
signal oper : std_logic_vector(1 downto 0);
14
signal tabc : std_logic_vector(2 downto 0);
15
begin
16
with tabc select oper <=
17
                          '0' & Ai + Bi  when "001",
18
                          '0' & Ai + Bi when "010" ,
19
                          '0' & Ai - '1' when "011" ,
20
                    '0' & Ai + '1' when "100" ,
21
                          '0' & Ai - Bi when "101" ,
22
                          '0' & Ai + Bi + '1' when "110",
23
                          '0' & Ai when others;
24

25
Co <= oper(1);
26
Go <= oper(0);
27
tabc <= Ci&S;
28
end architecture;
II) The structural code to link 4 cells to implement the arithmetic
operator
1
library ieee;
2
use ieee.std_logic_1164.all,ieee.std_logic_unsigned.all;
3

4

5
entity operator is
6
port(A,B : in std_logic_vector(3 downto 0);
7
     S : in std_logic_vector(1 downto 0);
8
     cin : in std_logic;
9
     G : out std_logic_vector(3 downto 0);
10
     cout : out std_logic);
11
end entity;
12

13
architecture rtl of operator is
14
component cell is 
15
port(Ai,Bi,Ci : in std_logic;
16
     S : in std_logic_vector (1 downto 0);
17
     Co,Go : out std_logic);
18
end component;
19
signal C : std_logic_vector(3 downto 1);
20
begin
21
cell0 : cell port map(Ai=>A(0),Bi=>B(0),Ci=>cin,S=>S,Co =>C(1),Go => G(0));
22
cell1 : cell port map(Ai=>A(1),Bi=>B(1),Ci=>C(1),S=>S,Co=>C(2),Go => G(1));
23
cell2 : cell port map(Ai=>A(2),Bi=>B(2),Ci=>C(2),S=>S,Co=>C(3),Go => G(2));
24
cell3 : cell port map(Ai=>A(3),Bi=>B(3),Ci=>C(3),S=>S,Co =>cout,Go =>G(3));
25
end architecture;
Moderator (Company: Titel) #6038534
Rate this post
useful
not useful
YouseKalack wrote:
> as you can see in the simulation ....
So setup a second test bench for your "cell" and have a look wether its 
working as desired.

> I) The dataflow code to describe cell.
By looking at the picture bottom left corner a thought pops up in my 
mind: shouldn't that "cell" also be described as a logic/structural 
expression instead as a functional data flow description? And shouldn't 
the CI be used for any operation in the "cell"?

To clear the view: the top left hand table is not related to the "cell" 
driectly. That table shows the expected behaviour of the top level 
module "operator".
Guest #6038572
Rate this post
useful
not useful
Yousekalack wrote:
> Yes the test work for one cell but only sub is not working good.. i
> think the problem is when A = '0' and A - 1 = ???

No, for a single cell your code is also not working correctly.

Perform a simulation for a single cell. What are the correct outputs for 
A=0, Cin=0 and opeartion A-1? What does your simulation show instead?
Guest #6038753
Rate this post
useful
not useful
Huynh J. wrote:
> Oper(1) is the carry out from all operations, i put'0' & but the '0'
> will be replace if there is a carry

ok you're right, my mistake. "&" and "-" have identical priority and are 
evaluted from left to right. So

   '0' & Ai - '1'

turns into

  ('0' & Ai) - '1'

and then  the higer bit (i.e. the carry) can indeed be set after the 
operation

Reply

Please log in before posting.

or

Log in with Google account

Registration is free and takes only a minute.

Register now