VHDL incrementer "add one" - vhdl

I do not how to write the truth table of this question so I can not do this question, can anyone help me understand what this question let us do? Thank you very much.
An incrementer is a combinational circuit that adds ONE to an input unsigned integer (X). The output unsigned integer (Y) has the same number of bits as the input. There is no output carry, an input string of all ‘1’s increments to all ‘0’s.
a) Write the Full-Adder Equations with inputs A0 , B0 and C0 . (aka Cin)
b) substitute with A0 = X0 , B0 = ‘0’ and C0 = ‘1 and then simplify.
c) Write the Full-Adder Equations with inputs Ai , Bi and Ci.
d) substitute with Ai = Xi , and Bi = ‘0’ and then simplify.
e) Consider a 6-bit Ripple-Adder that has A = X, B = 0 and Cin = ‘1’. Clearly this would be an incrementer. Draw a Structural Diagram of a 6-bit incrementer using the simplified circuits that you have derived in (b) and (d). (Label all instances and signals.)
VHDL can be used to model the time delay of individual gates. Please refer to your lecture notes for the BNF syntax of signal assignment. The delay format is used by simulators but is ignored by synthesizers. Use the following statements to code 2-input gates and inverters.
Code 2-input AND gates using statements with 4 ns delays,Y <= A and B after 4 ns;
Code 2-input XOR gates using the statements with 4 ns delays,Y <= A xor B after 4 ns;
Code inverters using the statements with 1 ns delays,Y <= not A after 1 ns;
Make a new directory called PLA03 and then start a new ModelSim project called PLA03.Always put Entity/Architectures in their own source files and use the Entity name as the filename.
f) Write an Entity/Architecture for your simplified circuit in (b). Name the Entity IncStage0
g) Write an Entity/Architecture for your simplified circuit in (d). Name the Entity IncStageI
h) Write an Entity named Inc6 and a Structural Architecture for your 6-bit Incrementer in (e). Remember to declare the inputs and outputs as unsigned.
library ieee;
use ieee.std_logic_1164.all;
Use ieee.numeric_std.all;
Entity IncStage0 is
port(
X:in unsigned;
S: out unsigned;
Cout: out unsigned);
End Entity IncStage0;
Architecture behaviour of IncStage0 is
Begin
S <= not X after 4 ns;
Cout <= X;
End Architecture behaviour;
library ieee;
use ieee.std_logic_1164.all;
Use ieee.numeric_std.all;
Entity IncStageI is
port(
X:in unsigned;
Cin: in unsigned;
S: out unsigned;
Cout:out unsigned);
End Entity IncStageI;
Architecture stageI of IncStageI is
Begin
S <= X xor Cin after 4 ns;
Cout <= X and Cin after 4 ns;
End Architecture stageI;
library ieee;
use ieee.std_logic_1164.all;
Use ieee.numeric_std.all;
Entity Inc6 is
port(
X:in unsigned (5 downto 0);
Y:out unsigned (5 downto 0));
End Entity Inc6;
Architecture behaviour of Inc6 is
signal C:unsigned (5 downto 0);
Component IncStage0
port(
X:in unsigned;
S: out unsigned;
Cout: out unsigned);
End Component ;
Component IncStageI
port(
X:in unsigned;
Cin: in unsigned;
S: out unsigned;
Cout:out unsigned);
End Component;
Begin
I0: IncStage0
port map(X=>X, S=>Y, Cout=>C);
I1: IncStageI
port map(X=>X, S=>Y, Cout=>C,Cin=>C);
I2: IncStageI
port map(X=>X, S=>Y, Cout=>C,Cin=>C);
I3: IncStageI
port map(X=>X, S=>Y, Cout=>C,Cin=>C);
I4: IncStageI
port map(X=>X, S=>Y, Cout=>C,Cin=>C);
I5: IncStageI
port map(X=>X, S=>Y, Cout=>C,Cin=>C);
End Architecture behaviour;
Library ieee;
Use ieee.std_logic_1164.all;
Use ieee.numeric_std.all;
Entity TBInc6 is
End Entity TBInc6;
Architecture rtl of TBInc6 is
signal tbX,tbY: unsigned(5 downto 0);
Begin
DUT: Entity work.Inc6 port map(X => tbX, Y => tbY);
Main: Process
Begin
for i in 0 to 63 loop
tbX <= to_unsigned(i,6);
wait for 30 ns;
end loop;
Wait;
End Process Main;
End Architecture rtl;

After fixing the delay in incStage0 for the NOT (should be 1 ns, not 4 ns),and changing the unconstrained subtype indications for type unsigned to type std_logic (incStage0, incStageI and their component declarations), as well as restoring the indexes for I0 through I5 you removed in your questions 5th edit and then you get:
Which looks correct compared to your instructor's supplied waveform.
Note it's hard to hit a moving target, every time you change your question the answer changes. A good indication you should be asking separate questions.
You could modify inc6 to declare signal C as:
architecture behaviour of Inc6 is
signal C:unsigned (4 downto 0);
component IncStage0
port(
X:in std_logic;
S: out std_logic;
Cout: out std_logic);
end component ;
And change the I5 instantiation:
I5: IncStageI
port map(X=>X(5), S=>Y(5), Cout=> open, Cin=>C(4));
Because you're using name association in the interface list you could simply:
I5: IncStageI
port map(X=>X(5), S=>Y(5),Cin=>C(4));
leave off mention of the carry out.
addendum
Is that means I should change every type unsigned to std_logic or
std_logic_vector?But if I try to change everything to std_logic, it
says no feasible entries for to_unsigned which is in part h code, how
to fix that?
No. unsigned is an array type. From package numeric_std (-2008):
type UNRESOLVED_UNSIGNED is array (NATURAL range <>) of STD_ULOGIC;
subtype UNSIGNED is (resolved) UNRESOLVED_UNSIGNED;
-1987, -1993, -2002:
type UNSIGNED is array (NATURAL range <>) of STD_LOGIC;
While in package std_logic_1164 (-2008):
subtype STD_LOGIC is resolved STD_ULOGIC;
-1987, -1993, -2002:
SUBTYPE std_logic IS resolved std_ulogic;
In all revisions of the VHDL standard the base type of std_logic is std_ulogic, which is also the base type of the element type of the array type unsigned.
This means you can connect elements of an unsigned (representing bits) to std_logic signals, including ports. The element base type of both is std_ulogic which is a multi value representation of a bit providing both weak and strong logic level forcing and meta values representing the value of a bit:
TYPE std_ulogic IS ( 'U', -- Uninitialized
'X', -- Forcing Unknown
'0', -- Forcing 0
'1', -- Forcing 1
'Z', -- High Impedance
'W', -- Weak Unknown
'L', -- Weak 0
'H', -- Weak 1
'-' -- Don't care
);
(Also see IEEE Std 1076-2008, 16.8.2.2 The STD_LOGIC_1164 values - "The logical values '1', 'H', '0', and 'L' of type STD_ULOGIC are interpreted as representing one of two logic levels, where each logic level represents one of two distinct voltage ranges in the circuit to be synthesized.", the one of two logical values, a bit).
As you have undoubtedly discovered you can't connect an array type to a scalar type. incStage0 (I0) and inStageI (I1, I2, I3, I4 and I5) represent bits:
h) Write an Entity named Inc6 and a Structural Architecture for your 6-bit Incrementer in (e). Remember to declare the inputs and outputs as unsigned.
In the code snippets showing the use of an open for an actual on I5 the declaration for C is shown as unsigned and I5 is shown using indexed names (elements on an array object). In addition to declaring the bit slice elements of inc6 as std_logic:
entity IncStage0 is
port(
X:in std_logic;
S: out std_logic;
Cout: out std_logic);
Entity IncStageI is
port(
X:in std_logic;
Cin: in std_logic;
S: out std_logic;
Cout:out std_logic);
component IncStage0
port(
X:in std_logic;
S: out std_logic;
Cout: out std_logic);
end component ;
component IncStageI
port(
X:in std_logic;
Cin: in std_logic;
S: out std_logic;
Cout:out std_logic);
end component;
You want unsigned array values in inc6:
entity Inc6 is
port(
X:in unsigned (5 downto 0);
Y:out unsigned (5 downto 0));
architecture behaviour of Inc6 is
signal C: unsigned (4 downto 0);
And indexed array elements as actuals connected to scalar formals:
begin
I0: IncStage0
port map(X=>X(0), S=>Y(0), Cout=>C(0));
I1: IncStageI
port map(X=>X(1), S=>Y(1), Cout=>C(1),Cin=>C(0));
I2: IncStageI
port map(X=>X(2), S=>Y(2), Cout=>C(2),Cin=>C(1));
I3: IncStageI
port map(X=>X(3), S=>Y(3), Cout=>C(3),Cin=>C(2));
I4: IncStageI
port map(X=>X(4), S=>Y(4), Cout=>C(4),Cin=>C(3));
I5: IncStageI
port map(X=>X(5), S=>Y(5), Cout=> open,Cin=>C(4));
And this leaves TBinc6 as you originally displayed it using unsigned and to_unsigned without error.
And don't forget to change the time specification for delay in incStage0:
architecture behaviour of IncStage0 is
begin
S <= not X after 1 ns;
After which you can generate a wave form that shows identically to the exercise handout.
You've had more that 99 percent of the answer before running into the difference between array type and scalar types and their values. The circumlocution giving you snippets allows students taking the course to claim their work is their own. Learning and understanding, instead of simply copying.

What the question seems to be getting at, is that while you can use a general purpose adder (A + B + carry) to perform an increment, there are certain simplifications if you only need (A + 1) or (A + carry).
It appears to assume you have already been taught basic digital logic, gates, half adders and full adders. If not, this information is easily found.
So start by drawing out the "Full Adder" circuit for each bit. In Step (e), show what the simplifications are (at the gate level) when you simplify a 6 bit adder from (A + B + carry) to (A + carry).
The remaining steps will let you see if the simplified circuit is actually any faster. Looks like a good exercise in using the tools to do something really basic.

Related

Synthesizing full adder with ISE

I wrote a simple full adder which uses 2 half adders and an OR gate. The VHDL code is pretty simple
library ieee;
use ieee.std_logic_1164.all;
entity ha is
port( x: in std_logic;
y: in std_logic;
s: out std_logic;
c: out std_logic);
end;
architecture x of ha is
begin
s <= x xor y;
c <= x and y;
end;
and
library ieee;
use ieee.std_logic_1164.all;
entity fa is
port( a: in std_logic; b: in std_logic; cin: in std_logic;
sum: out std_logic; cout: out std_logic);
end;
architecture y of fa is
component ha port( x: in std_logic; y: in std_logic;
s: out std_logic; c: out std_logic);
end component;
signal im1, im2, im3: std_logic;
begin
ha1: ha port map( x=>a, y=>b, s=>im1, c=>im2 );
ha2: ha port map( x=>im1, y=>cin, s=>sum, c=>im3 );
cout <= im3 or im2;
end;
The output of the synthesizer however shows there are two XOR gates. Where are the OR gate and others for half adder?
=========================================================================
* Advanced HDL Synthesis *
=========================================================================
Advanced HDL Synthesis Report
Macro Statistics
# Xors : 2
1-bit xor2 : 2
=========================================================================
Also, the RTL schematic of the FA is correct, however, the RTL schematic of the half adder is weird! The y port is not present and there is data[1:0]. What does that mean?
FA:
HA:
I've seen the Vivado synthesizer leave stuff off of the macro statistics regularly. Macro reports aren't really meaningful for an FPGA design because all your logic is really going to be mapped into LUTs. In this case it looks like your basic and/or gates aren't considered to be macros, but an XOR is (as indicated by it being a box in the schematic instead of a logic symbol).
As far as your half adder schematic, the tools have combined your two single bit input ports into a two bit bus. The triangles before the and gate are taps on that bus to pull one of the two bits out. It's just another way to represent the same thing.

using sin and cos through the lookup table in VHDL

i'm using the sin/cos lookup table in VHDL known as sincos_lut.vhd and i'm getting an error when used with my code. I'm implementing my datapath and i need to perform sin and cos on an integer value. I do not know where my problem is but here is the code and error:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_ARITH.all;
use IEEE.STD_LOGIC_UNSIGNED.all;
use IEEE.MATH_REAL.all;
entity DFT is
port(
clk_en, clk, reset, Clock: std_logic;
t_sel,K_sel,sr_sel,si_sel,ld_t,ld_K,ld_sumreal,ld_sumimag,ld_angle: in std_logic;
N: in integer;
e: in std_logic_vector(3 downto 0);
outreal, outimag: out integer;
sig1, sig2: out std_logic
);
end DFT;
architecture str of DFT is
component Adder
Port( a, b: in integer;
f: out integer
);
end component;
component Reg
Port(
Clk: in std_logic;
ld: in std_logic;
a: in integer;
f: out integer
);
end component;
component Mul
Port(
a, b: in integer;
f: out integer
);
end component;
component LT
Port(
a, b: in integer;
sig: out std_logic
);
end component;
component Div
Port(
a, b: in integer;
f: out integer
);
end component;
component Mux
Port(
sel: in std_logic;
a, b: in integer;
f: out integer
);
end component;
component Mem
port( Clock: in std_logic;
Read: in std_logic;
Write: in std_logic;
Address: in integer;
Data_in: in integer;
Data_out: out integer
);
end component;
component sincos_lut Port
(
reset : in std_logic;
clk : in std_logic;
clk_en : in std_logic;
theta : in integer;
sin_data : out signed(integer);
cos_data : out signed(integer)
);
end component;
signal s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16,s17,s18,s19,s20,s21,s22,s23,s24,s25,s26,s30,s31,s32,s33 : integer;
constant MATH_PI : real := 3.14159_26535_89793_23846;
begin
G1: Mux port map(K_sel,0,s1,s2);
G2: Mux port map(t_sel,0,s3,s4);
G3: Reg port map(Clk,ld_K,s2,s5);
G4: Reg port map(Clk,ld_t,s4,s6);
G5: LT port map(s5,N,sig1);
G6: LT port map(s6,N,sig2);
G7: Adder port map(s5,1,s1);
G8: Adder port map(s6,1,s3);
G9: Div port map(s5,N,s7);
G10: Mul port map(s7,s6,s8);
G11: Mul port map(s8,integer(MATH_PI),s9);
G12: Mul port map(s9,2,s10);
G13: Reg port map(Clk, ld_angle,s10,s11);
G14: Mem port map(Clock,'1','0',s6,0,s12);
G15: Mem port map(Clock,'1','0',s6,0,s13);
G16: Mul port map(s12,s33,s14);
G17: Mul port map(s13,s30,s15);
G18: Adder port map(s14,s15,s16);
G19: Mux port map(sr_sel,0,s17,s18);
G20: Reg port map(Clk, ld_sumreal,s18,s19);
G21: Adder port map(s16,s19,s17);
G22: Mul port map(s12, -1,s20);
G31: sincos_lut port map(reset, clk, clk_en, s11, s30, s31);
G32: sincos_lut port map(reset, clk, clk_en, s11, s32, s33);
G23: Mul port map(s20, s30, s21);
G24: Mul port map(s13, s33, s22);
G25: Adder port map(s21, s22,s23);
G26: Mux port map(si_sel,0,s24,s25);
G27: Reg port map(Clk, ld_sumimag,s25,s26);
G28: Adder port map(s23,s26,s24);
G29: Mem port map(Clock, '0','1',s5,outimag);
G30: Mem port map(Clk, '0','1',s5,outreal);
sincos_lut
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity sincos_lut is
port
(
reset : in std_logic;
clk : in std_logic;
clk_en : in std_logic;
theta : in integer;
sin_data : out signed(integer);
cos_data : out signed(integer)
);
end sincos_lut;
architecture rtl of sincos_lut is
signal theta_int : integer range 0 to 4095 := 0;
signal sin_data_int : signed(integer);
signal cos_data_int : signed(integer);
begin
theta_int <= theta;
process(reset,clk)
begin
if(reset = '1')then
sin_data_int <= to_signed(0,12);
cos_data_int <= to_signed(0,12);
elsif(rising_edge(clk)) then
if clk_en = '1' then
sin_data <= sin_data_int;
cos_data <= cos_data_int;
case theta_int is
end str;
Errors:
Error (10476): VHDL error at DFT.vhd(119): type of identifier "s30" does not agree with its usage as "SIGNED" type
Error (10558): VHDL error at DFT.vhd(119): cannot associate formal port "sin_data" of mode "out" with an expression
Error (10476): VHDL error at DFT.vhd(119): type of identifier "s31" does not agree with its usage as "SIGNED" type
Error (10558): VHDL error at DFT.vhd(119): cannot associate formal port "cos_data" of mode "out" with an expression
Line 119 is:
G31: sincos_lut port map(reset, clk, clk_en, s11, s30, s31);
Your errors are because s30 and s31 are integers and you are connecting them to a signed ports.
Kevin.
type of identifier "s30" does not agree with its usage as "SIGNED" type
This error is caused by mixing different types. The type of s30 is integer, but you are trying to map it to a port of type signed.
cannot associate formal port "sin_data" of mode "out" with an expression
This error is normally caused by "reading" an output port in your logic, but I don't see a clear reason for this error. Possibly this is related to your ports of type : signed(integer). Signed() is used for type conversion.
Your code isn't a Minimal, Complete, and Verifiable example. Note your sincos_lut doesn't analyze either.
signal s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16,s17,s18,s19,s20,s21,s22,s23,s24,s25,s26,s30,s31,s32,s33 : integer;
constant MATH_PI : real := 3.14159_26535_89793_23846;
signal signed_s30: signed (11 downto 0);
signal signed_s31: signed (11 downto 0);
signal signed_s32: signed (11 downto 0);
signal signed_s33: signed (11 downto 0);
begin
s30 <= to_integer(signed_s30);
s31 <= to_integer(signed_s31);
s32 <= to_integer(signed_s32);
s33 <= to_integer(signed_s33);
You can create signed versions of s30, s31, s32 and s33 and convert
and assign them to s30, s31, s32, s33.
Also note there were associated errors in the sincos_lut, both in port declarations and signal declarations. A type name doesn't represent a range constraint. These have been fixed by:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity sincos_lut is
port
(
reset : in std_logic;
clk : in std_logic;
clk_en : in std_logic;
theta : in integer;
sin_data : out signed(11 downto 0); -- integer);
cos_data : out signed(11 downto 0) -- integer)
);
end sincos_lut;
architecture rtl of sincos_lut is
signal theta_int : integer range 0 to 4095 := 0;
signal sin_data_int : signed(11 downto 0); -- integer);
signal cos_data_int : signed(11 downto 0); -- integer);
The range of the signed values (actually the length) is determined by the to_signed function calls in the process.
Note use package numeric_std function to_integer, and in dft:
library ieee;
use ieee.std_logic_1164.all;
-- use ieee.std_logic_arith.all;
-- use ieee.std_logic_unsigned.all;
-- use ieee.math_real.all;
use ieee.numeric_std.all; -- never, never mix std_logic_arith/numeric_std
-- (see sincos_lut)
Type declarations in two different packages are unique regardless of whether they have the same name and base type or not. They are not compatible. If your tool let's you it is not compliant to the VHDL standard.
G31: sincos_lut port map(reset, clk, clk_en, s11, signed_s30, signed_s31);
G32: sincos_lut port map(reset, clk, clk_en, s11, signed_s32, signed_s33);
That lops of those errors, but reveals two more:
G29: Mem port map(Clock, '0','1',s5,outimag);
G30: Mem port map(Clk, '0','1',s5,outreal);
If you look at your mem component and the positional association list in the instance port maps you'll find you're missing an integer argument for both of these representing Address.
I don't think you've revealed enough of your 'precious' IP from someone to tell what should be connected here. It's part of the price in seeking help, showing what you got. When someone tells you it isn't a minimum example, in this case it would be throwing out component instantiations and signals not connected to the actual error reports.
Also note the promiscuous use of unconstrained integers which can end up implying 32 bit values in synthesis. You should be careful and constrain everything you can.
For instance defining the range constraint for the integer address going to the Mem component defines how big the memory is.
Dummy-ing up a signal Address, an integer and inserting it in the component allows dft to finish analyzing:
G29: Mem port map(Clock, '0','1',Address,s5,outimag);
G30: Mem port map(Clk, '0','1',Address,s5,outreal);
It's not possible to elaborate your design without dummy-ing up entity and architecture pairs for all your instantiated components or eliminating them (which would lead you to a second question later).
(And you could have produced integers from the sincos_lut entity/architecture pair, but without a range constraint that would have likely been a 32 bit value).

generic adder "inference architecture": simulation error

So, I have to create a generic N-bit adder with carry in and carry out.
I have made two fully working architectures so far, one using the generate function and one using the rtl description as follows:
entity:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity adder_n is
generic (N: integer:=8);
port (
a,b: in std_logic_vector(0 to N-1);
cin: in std_logic;
s: out std_logic_vector(0 to N-1);
cout: out std_logic);
end adder_n;
architectures 1 and 2:
--STRUCT
architecture struct of adder_n is
component f_adder
port (
a,b,cin: in std_logic;
s,cout: out std_logic);
end component;
signal c: std_logic_vector(0 to N);
begin
c(0)<=cin;
cout<=c(N);
adders: for k in 0 to N-1 generate
A1: f_adder port map(a(k),b(k),c(k),s(k),c(k+1));
end generate adders;
end struct;
--END STRUCT
architecture rtl of adder_n is
signal c: std_logic_vector(1 to N);
begin
s<=(a xor b) xor (cin&c(1 to N-1));
c<=((a or b) and (cin&c(1 to N-1))) or (a and b);
cout<=c(N);
end rtl;
Now, my problem is in the third architecture where I'm trying to infer the adder. Even though the following architecture I created compiles just fine, when I try to simulate it, I get a simulation error (on Modelsim), which I have attached at the end of this post.
I'm guessing there's something wrong with the numeric_std definitions. I am trying to avoid the arith library and I'm still trying to get used to the IEEE standard.
Any ideas are welcomed!! Thank you!
Inference arch:
--INFERENCE
architecture inference of adder_n is
signal tmp: std_logic_vector(0 to N);
signal atmp, btmp, ctmp, add_all : integer :=0;
signal cin_usgn: std_logic_vector(0 downto 0);
signal U: unsigned(0 to N);
begin
atmp <= to_integer(unsigned(a));
btmp <= to_integer(unsigned(b));
cin_usgn(0) <= cin;
ctmp <= to_integer(unsigned(cin_usgn));
add_all <= (atmp + btmp + ctmp);
U <= to_unsigned(add_all,N);
tmp <= std_logic_vector(U);
s <= tmp(0 to N-1);
cout <= tmp(N);
end inference;
-- END
Simulation error:
# Cannot continue because of fatal error.
# HDL call sequence:
# Stopped at C:/altera/14.1/modelsim_ase/test1_simon/adder_inference.vhd 58 Architecture inference
The length of U is N+1 (0 to N)
Changing
U <= to_unsigned(add_all,N);
To
U <= to_unsigned(add_all,N+1);
Will prevent a length mismatch between the left hand side and right hand side of the signal assignment in architecture inference of adder_n.
The passed parameter to to_unsigned specifies the length.

2's compliment input and using vhdl library for signed input

My input data is 2's compliment and I designed the input is signed number and the all of operation is used signed number,the library i used ieee.numeric_std.all, but when i do ‘+’ an error occurred "found '0' definitions of operator "+", cannot determine exact overloaded matching definition for "+"". So I changed another to another library ieee.std_logic_arith.all ans make the add operation as a component, it works.
when i simulate my code by using testbench, error occurred: Entity port xin does not match with type signed of component port.
I think this error is about my library.
can anyone help me ?
new
i do not use adder as a component and the below code works
adder: process(clk)
begin
if (clk'event and clk = '1')then
if enable1='1' then
add1 <= (x0(7)&x0) + (x15(8)&x15);
add2 <= (x1(7)&x1) + (x14(8)&x14);
add3 <= (x2(7)&x2) + (x13(8)&x13);
add4 <= (x3(7)&x3) + (x12(8)&x12);
add5 <= (x4(7)&x4) + (x11(8)&x11);
add6 <= (x5(7)&x5) + (x10(8)&x10);
add7 <= (x6(7)&x6) + (x9(8)&x9);
add8 <= (x7(7)&x7) + (x8(8)&x8);
end if;
end if;
end process adder;
and the library of my testbench use use ieee.numeric_std.all;
USE ieee.std_logic_1164.ALL;
use ieee.numeric_std.all;
use ieee.std_logic_textio.all;
use std.textio.all;
ENTITY tb_signedinput IS
END tb_signedinput;
ARCHITECTURE behavior OF tb_signedinput IS
-- Component Declaration
COMPONENT signedinput is
port( Clk : in std_logic;
reset : in std_logic;
enable1 : in std_logic;
Xin : in signed(7 downto 0);
Yout : out signed(19 downto 0)
);
END COMPONENT;
--Inputs
signal Clk : std_logic := '0';
signal reset : std_logic := '0';
signal Xin : signed(7 downto 0) := (others => '0');
signal enable1 : std_logic := '0';
--Outputs
signal Yout : signed(19 downto 0);
-- Array
constant MEMSIZE: integer :=99;
type testarray is array (MEMSIZE downto 0) of signed(7 DOWNTO 0);
signal testvectors: testarray;
shared variable vectornum,outnum: integer;
-- Clock period definitions
constant Clk_period : time := 10 ns;
BEGIN
-- Component Instantiation
uut: signedinput PORT MAP( Clk => Clk,
reset => reset,
Xin => Xin,
enable1 =>enable1,
Yout => Yout );
the error still occur:
Entity port xin does not match with type std_logic_vector of component port
Entity port yout does not match with type std_logic_vector of component port
therefore, I changed my adder again to
add1 <= resize(x0,9) + x15;
syntax good but same error in testbench..
Is error about my ISE type or library type?
Thank you!
Your addition expression in adder1 is invalid because you're trying to index element "8" when the range of a1 and a2 is 7 downto 0.
Assuming thet you're trying to sign extend it would look something more like this:
q <=(a1(7)&a1 + a2(7)&a2);
The "+" operator has higher precedence than "&" so you are trying to add a1 + a2(7) which is signed + std_logic. This doesn't have an overload defined in numeric_std in addition to being logically wrong.
This works:
q <=(a1(7)&a1) + (a2(7)&a2);
But it isn't the canonical way to implement sign extension when using numeric_std. You only need the left side term to have the same size as q. The signed "+" operator will take care of sign extending its right hand side automatically.
q <= resize(a1, q'length) + a2; -- Sign extend a1 and add
This gives cleaner code that says what it's doing without relying on the non-standard std_logic_arith.
The actual error about the type mismatch on xin isn't apparent from your code. It is possible that you have an older version of signedinput compiled with a different type on its port and haven't updated the library.
Kevin made it look tough, so I figured I'd show something that makes for a good explanation:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity adder1 is
port (
a1: in signed (7 downto 0);
a2: in signed (7 downto 0);
clk: in std_logic;
enable1: in std_logic;
q: out signed (8 downto 0)
);
end entity;
architecture behavioral of adder1 is
begin
UNLABELLED:
process(clk)
begin
if clk'event and clk ='1' then
if enable1 = '1' then
q <= a1(7) & a1 + a2 ;
end if;
end if;
end process;
end architecture;
The assignment to q looks naked so it's worth explaining.
The "+" in numeric_std for signed will sign extend the shorter operand to match the length of the longer operand.
The rest is priority magic.
"+" and "&" are the same priority, which means they're evaluated in left to right textual order, meaning the sign extension with the concatenation operator is performed first (see IEEE Std 1076-2008, 9.2 Operators).
The "+" operator sees the left operand as longer and matches the right operand to it's length, (see package numeric_std "+" for L,R: signed). It does this by using signed RESIZE on both operands after finding the MAX of the length of both, along with converting metavalues to 'X's.
It works if the right operand is longer too:
q <= a1 + (a2(7) & a2) ;
And here we need parentheses to associate the result of the concatenation operator as the right operand of the adding operator, because the two operators are the same priority and would otherwise be encountered in textual order.
There's no reason to call resize yet again, it's only a one bit sign extension by concatenation, based on knowing the sign is embodied in the left hand element (bit) of a two's compliment number.
The term canonical is not found in the VHDL standard.
As far as Xin, I'd agree with Kevin, something likely needs to be reanalyzed so that both references to signed are found in the same package.
Each declaration used in a design is unique. If say the actual in the port map depends on the type signed declaration in package std_logic_arith and the formal were to depend on the declaration of signed in package numeric_std they would be of different types.

4 Bit Adder using port maps

So I am trying to do a 4 bit adder and have ran into an error I can't seem to figure out.
Error (10430): VHDL Primary Unit Declaration error at adder1.vhd(3): primary unit "Adder1Vhd" already exists in library "work"
I have a project called 4 bit adder and inside that project folder is the .vhd file for Adder1.vhd. Here is the codes I have, if somebody could help me figure this out it would be greatly appreciated.
Adder4.vhd:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY Adder4 IS
GENERIC(CONSTANT N: INTEGER := 4);
PORT(
a, b: IN STD_LOGIC_VECTOR(N-1 DOWNTO 0); -- Input SW[7..4]: a[3..0] inputs,
-- SW[3..0]: b[3..0]
cIn: in std_logic;
sum: OUT STD_LOGIC_VECTOR(N-1 DOWNTO 0); -- Output LEDR[3..0]
cOut: OUT STD_LOGIC -- Output LEDR[4]
);
END Adder4;
ARCHITECTURE imp OF Adder4 IS
COMPONENT Adder1
PORT(
a, b, cIn : in STD_LOGIC;
sum, cOut : out STD_LOGIC);
END COMPONENT;
SIGNAL carry_sig: std_logic_vector(N-1 DOWNTO 0);
BEGIN
A1: Adder1 port map (a(0), b(0), cIn, sum(0), carry_sig(0));
A2: Adder1 port map (a(1), b(1), carry_sig(0), sum(1), carry_sig(1));
A3: Adder1 port map (a(2), b(2), carry_sig(1), sum(2), carry_sig(2));
A4: Adder1 port map (a(3), b(3), carry_sig(2), sum(3), cOut);
END imp;
Adder1.vhd(the file inside the Adder4 project folder):
library ieee;
use ieee.std_logic_1164.all;
entity Adder1Vhd is
port(
a, b, cIn : in std_logic;
sum, cOut : out std_logic);
end Adder1Vhd;
architecture imp of Adder1Vhd is
begin
-- Add two lines (one for sum and the other for cOut) of VHDL code here
sum <= (a xor b) xor cIn;
cOut <= (a and b) or (cIn and (a xor b));
end imp;
There is another file that has an entity named Adder1Vhd in the library work (current work library). You can either delete the file on disk or just remove it from the library work in the file navigator of Quartus II.
By the way, it's a good convention to save a VHDL files using the same name as the entity.
And the name of a component must be the name of it's entity, not the filename. So,
COMPONENT Adder1 -- here 'Adder1' should be 'Adder1Vhd'
PORT(
a, b, cIn : in STD_LOGIC;
sum, cOut : out STD_LOGIC);
END COMPONENT;
Component instantiation statements are the same.

Resources