Accumulator Design - vhdl

Thank you, everyone, here I have modified the post. I have written a simple code VHDL for trap filter by using different components for each task. The below is sample code where different components are used and all the other components are working perfectly except accumulator component(acc1), the out signal remains zero. In the acc1 one component I am trying to to make two accumulators where the first acc1 (output of the first accumulator) is the input for the acc2. As the other components are working so here I only showed the port mapping of acc1 component in the code along the test bench.
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use IEEE.std_logic_unsigned.all;
use ieee.fixed_pkg.all;
ENTITY TRAPFILTER IS
GENERIC (
K : integer :=80;
L : integer :=200
--M : signed(9 downto 0) := to_signed(5)
);
PORT
(
CLK : IN STD_LOGIC;
RST : IN STD_LOGIC;
DATAIN : IN STD_LOGIC_VECTOR(13 DOWNTO 0);
DATAOUT : OUT STD_LOGIC_VECTOR(24 DOWNTO 0);
DATAOUT1 : OUT STD_LOGIC_VECTOR(25 DOWNTO 0); ---
READY : OUT STD_LOGIC;
Soutout : out std_logic_vector(23 downto 0);
Koutout : out std_logic_vector(13 downto 0);
Loutout : out std_logic_vector(13 downto 0)
);
END ENTITY TRAPFILTER;
ARCHITECTURE RTL OF TRAPFILTER IS
constant M : sfixed(1 downto -2) := to_sfixed(0.01,1,-2);
type Sdelay_reg is array(0 to 2) OF signed(21 downto 0);
signal S_reg : Sdelay_reg :=(others=>(others=>'0'));
-------------------------------------------------------------
signal y_reg0 : signed (27 downto 0) :=(others=>'0');
signal y_reg1 : signed (31 downto 0) :=(others=>'0');
-----------------------------------------------------------
signal in_reg : signed(13 downto 0) :=(others=>'0');
signal out_reg : signed(DATAOUT'length-1 downto 0) :=
(others=>'0');
-- ----------------------------------------------------------
signal fs : std_logic :='0';
--------------------kdelay component----------------------------------
component kdelay is
GENERIC (
K : integer :=80;
L : integer :=200
);
port
(
clk : in std_logic ;
rst : in std_logic;
din : in STD_LOGIC_VECTOR (13 downto 0);
kout : OUT STD_LOGIC_VECTOR (13 downto 0)
);
end component;
signal kout : std_logic_vector (13 downto 0) :=(others=>
'0');
--------------------Ldelay component----------------------
------------
component Ldelay is
GENERIC (
K : integer :=80;
L : integer :=200
);
port
(
clk : in std_logic ;
rst : in std_logic;
din : in STD_LOGIC_VECTOR (13 downto
0);
Lout : OUT STD_LOGIC_VECTOR (13 downto
0)
);
end component;
signal Lout : std_logic_vector (13 downto 0) :=
(others=>'0');
---------------------------------------------------
component sub_mult is
port(
clk : in std_logic ;
rst : in std_logic;
din : in STD_LOGIC_VECTOR (13 downto
0);
Sout : out STD_LOGIC_VECTOR (23
downto 0)
);
end component;
signal Sout : std_logic_vector (23
downto 0) :=(others=>'0');
-------------------------------------------
component accum1 is
port(
clk : in std_logic ;
rst : in std_logic;
din : in
STD_LOGIC_VECTOR (23 downto 0);
Acout : out
STD_LOGIC_VECTOR (24 downto 0);
Acout1 : out
STD_LOGIC_VECTOR (25 downto 0)
);
end component;
signal acc_out1 : std_logic_vector (24 downto 0) :=(others=>'0');
signal acc_out2 : std_logic_vector (25 downto 0) :=(others=>'0');
----------------------------------------------------------------
BEGIN
Koutout <= Kout;
Loutout <= Lout;
Soutout <= Sout;
in_reg <= signed (DATAIN);
DATAOUT <= acc_out1;--std_logic_vector(out_reg);
DATAOUT1 <= acc_out2;
utacc1:component accum1
port map(
clk => clk,
rst => rst,--: in std_logic;
din => Sout, --: OUT STD_LOGIC_VECTOR
(13 downto 0);
Acout => acc_out1, -- : out STD_LOGIC_VECTOR (24 downto 0)
Acout1 => acc_out2
);
END RTL;
------------------------Accum1 component----------------------------------
library IEEEieee;`
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use IEEE.std_logic_unsigned.all;
use ieee.fixed_pkg.all;
entity accum1 is port(
clk : in std_logic ;
rst : in std_logic;
din : in STD_LOGIC_VECTOR (23 downto 0);
Acout : out STD_LOGIC_VECTOR (24 downto 0);
Acout1 : out STD_LOGIC_VECTOR (25 downto 0)
);
end entity;
architecture rtl of accum1 is
signal dout : signed(24 downto 0) :=(others=>'0');
signal datain : signed(23 downto 0) :=(others=>'0');
signal dout2 : signed(25 downto 0) :=(others=>'0');
begin
datain <= signed(din);
process(clk,rst,datain)
variable cm : signed(24 downto 0);
begin
if(rst='1' ) then
dout <= (others=>'0');
dout2 <= (others=>'0');
cm := (others=>'0');
elsif(rising_edge(clk) and clk'event) then
cm := datain + cm;
dout <= cm ;
dout2 <= dout2 + cm ;
end if;
end process;
Acout <= std_logic_vector(dout);
Acout1 <= std_logic_vector(dout2) ;
end rtl;
------------------------test bench only trapfilter comppnent portmapping
uttrap5:component TRAPFILTER
PORT MAP
(
CLK => TestClk, -- : IN STD_LOGIC;
RST => i_rstb, -- : IN STD_LOGIC;
DATAIN => odata, --odata, -- : IN STD_LOGIC_VECTOR(13 DOWNTO 0);
DATAOUT => trap_out, --: OUT STD_LOGIC_VECTOR(13 DOWNTO 0); ---
DATAOUT1 => trap_out1,
READY => trap_ready, --: OUT STD_LOGIC
Koutout => Koutout, --out std_logic_vector(23 downto 0);
Loutout => loutout, --: out std_logic_vector(13 downto 0);
Soutout => Soutout
);
enter image description here

Several issues in your code
You don't need datain in your sensitivity list.
When using rising_edge, you don't need event
The variable cm will not keep their value when re-enter the process. Use signal instead or just use value of dout.
I am really understand what is your dout2 logic?

Related

vhdl:warning: universal integer bound must be numeric literal or attribute

why does the following code generate the error message "vhdl:warning: universal integer bound must be numeric literal or attribute" on the line: " type mem_type is array ((2**ADDR_WIDTH)-1 downto) of std_logic_vector (DATA_WIDTH-1 downto 0);" and how do I fix it?
library ieee;
use ieee.std_logic_1164.all;
use IEEE.numeric_std.all;
entity bus_fifo_mem is
generic(
ADDR_WIDTH : integer := 32;
DATA_WIDTH : integer := 32;
ENABLE_BYPASS : integer := 1
);
port(
clk : in std_logic;
raddr : in std_logic_vector(ADDR_WIDTH-1 downto 0);
re : in std_logic;
waddr : in std_logic_vector(ADDR_WIDTH-1 downto 0);
we : in std_logic;
din : in std_logic_vector(DATA_WIDTH-1 downto 0);
dout : out std_logic_vector(DATA_WIDTH-1 downto 0)
);
end entity;
architecture rtl of bus_fifo_mem is
signal rdata : std_logic_vector(DATA_WIDTH-1 downto 0);
signal din_r : std_logic_vector(DATA_WIDTH-1 downto 0);
signal bypass : std_logic;
-- VERILOG
--reg [DATA_WIDTH-1:0] mem[(1<<ADDR_WIDTH)-1:0];
type mem_type is array ((2**ADDR_WIDTH)-1 downto 0)
of std_logic_vector (DATA_WIDTH-1 downto 0);
signal mem : mem_type := (others => (others => '0'));
begin
process(clk)
begin
if (clk = '1' and clk'event) then
if (we = '1') then
mem(to_integer(unsigned(waddr))) <= din;
end if;
if (re = '1') then
rdata <= mem(to_integer(unsigned(raddr)));
end if;
end if;
end process;
end architecture;
Use this:
type mem_type is array (integer'(2) ** ADDR_WIDTH - 1 downto 0)
of std_logic_vector(DATA_WIDTH-1 downto 0);
Instead of this:
type mem_type is array ((2**ADDR_WIDTH)-1 downto 0)
of std_logic_vector (DATA_WIDTH-1 downto 0);
Complete working example:
library ieee;
use ieee.std_logic_1164.all;
use IEEE.numeric_std.all;
entity bus_fifo_mem is
generic(
ADDR_WIDTH : integer := 32;
DATA_WIDTH : integer := 32;
ENABLE_BYPASS : integer := 1
);
port(
clk : in std_logic;
raddr : in std_logic_vector(ADDR_WIDTH-1 downto 0);
re : in std_logic;
waddr : in std_logic_vector(ADDR_WIDTH-1 downto 0);
we : in std_logic;
din : in std_logic_vector(DATA_WIDTH-1 downto 0);
dout : out std_logic_vector(DATA_WIDTH-1 downto 0)
);
end entity;
architecture rtl of bus_fifo_mem is
signal rdata : std_logic_vector(DATA_WIDTH-1 downto 0);
signal din_r : std_logic_vector(DATA_WIDTH-1 downto 0);
signal bypass : std_logic;
-- VERILOG
--reg [DATA_WIDTH-1:0] mem[(1<<ADDR_WIDTH)-1:0];
type mem_type is array (integer'(2) ** ADDR_WIDTH - 1 downto 0)
of std_logic_vector(DATA_WIDTH-1 downto 0);
signal mem : mem_type := (others => (others => '0'));
begin
process(clk)
begin
if (clk = '1' and clk'event) then
if (we = '1') then
mem(to_integer(unsigned(waddr))) <= din;
end if;
if (re = '1') then
rdata <= mem(to_integer(unsigned(raddr)));
end if;
end if;
end process;
end architecture;

How to initialize a VHDL std_logic_vector to "0001"

i want to initialize my vectors from "0001" instead of "0000" default cause i'm doing an "automatic" 4 Bit multiplier and (x * 0) isn't useful, so
I want to skip the "0000" value.
Here is my Entity:
ENTITY multiplier IS
PORT (
clk, rst : IN std_logic;
q, r : INOUT std_logic_vector (3 DOWNTO 0) := "0001"; -- this not work
f : OUT std_logic_vector(7 DOWNTO 0)
);
END multiplier;
Use intermediate signals
library ieee;
use ieee.std_logic_1164.all;
entity multiplier IS
port (
clk : in std_logic;
rst : in std_logic;
q : out std_logic_vector(3 downto 0);
r : out std_logic_vector(3 downto 0);
f : out std_logic_vector(7 downto 0)
);
end entity;
architecture rtl of multiplier is
use ieee.numeric_std.all;
signal q_temp: unsigned(3 downto 0) := "0001"; -- or signed
signal r_temp: unsigned(3 downto 0) := "0001"; -- or signed
begin
[...your code...]
q <= std_logic_vector(q_temp);
r <= std_logic_vector(r_temp);
end architecture;

VHDL writing warning

1.8-bit multiplier
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity M8 is
Port ( M1 : in STD_LOGIC_vector(7 downto 0);
M2 : in STD_LOGIC_vector(7 downto 0);
Mout : out STD_LOGIC_vector(15 downto 0)
);
end M8;
architecture Behavioral of M8 is
begin
process(M1,M2)
variable A1: std_logic_vector(17 downto 0);
begin
A1(17 downto 0) := "0000000000" & M1(7 downto 0);
for N in 1 to 9 loop
if A1(0)='1' then
A1(17 downto 9) := A1(17 downto 9) + '0'+ M2(7 downto 0);
end if;
A1(17 downto 0) := '0' & A1(17 downto 1);
end loop;
Mout<= A1(15 downto 0);
end process;
end Behavioral;
2.32-bit multiplier
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity M32 is
Port ( M1 : in STD_LOGIC_vector(31 downto 0);
M2 : in STD_LOGIC_vector(31 downto 0);
Mout : out STD_LOGIC_vector(63 downto 0)
);
end M32;
architecture Behavioral of M32 is
begin
process(M1,M2)
variable A1: std_logic_vector(65 downto 0);
begin
A1(65 downto 0) := "0000000000000000000000000000000000" & M1(31 downto 0);
for N in 1 to 33 loop
if A1(0)='1' then
A1(65 downto 33) := A1(65 downto 33) + '0'+ M2(31 downto 0);
end if;
A1(65 downto 0) := '0' & A1(65 downto 1);
end loop;
Mout<= A1(63 downto 0);
end process;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity MM32All is
port( MMM1: in std_logic_vector(31 downto 0);
MMM2: in std_logic_vector(31 downto 0);
MMMout: out std_logic_vector(63 downto 0)
);
end MM32All;
architecture Behavioral of MM32All is
component M32 port(MM1 : in std_logic_vector(31 downto 0);
MM2 : in std_logic_vector(7 downto 0);
MMout:out std_logic_vector(39 downto 0)
);
end component;
signal MMb: std_logic_vector(31 downto 0);
signal MMa: std_logic_vector(31 downto 0);
signal MMo1: std_logic_vector(39 downto 0);
signal MMo2: std_logic_vector(39 downto 0);
signal MMo3: std_logic_vector(39 downto 0);
signal MMo4: std_logic_vector(39 downto 0);
signal MMout1: std_logic_vector(63 downto 0);
begin
Ma4: M32 port map (MM1=> MMb, MM2=> MMa(31 downto 24), MMout=> MMo4);
Ma3: M32 port map (MM1=> MMb, MM2=> MMa(23 downto 16), MMout=> MMo3);
Ma2: M32 port map (MM1=> MMb, MM2=> MMa(15 downto 8) , MMout=> MMo2);
Ma1: M32 port map (MM1=> MMb, MM2=> MMa(7 downto 0 ) , MMout=> MMo1);
MMout1 <= ("000000000000000000000000" & MMo1) + ("0000000000000000" & MMo2 & "00000000")
+ ("00000000" & MMo3 & "0000000000000000" ) + ( MMo4 & "000000000000000000000000" );
MMb <= MMM1;
MMa <= MMM2;
MMMout <= MMout1;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity M32 is
port(MM1 : in std_logic_vector(31 downto 0);
MM2 : in std_logic_vector(7 downto 0);
MMout:out std_logic_vector(39 downto 0)
);
end M32;
architecture Behavioral of M32 is
component M8 Port ( M1 : in STD_LOGIC_vector(7 downto 0);
M2 : in STD_LOGIC_vector(7 downto 0);
Mout : out STD_LOGIC_vector(15 downto 0)
);
end component;
component M8b Port ( M1 : in STD_LOGIC_vector(7 downto 0);
M2 : in STD_LOGIC_vector(7 downto 0);
Mout : out STD_LOGIC_vector(15 downto 0)
);
end component;
component M8c Port ( M1 : in STD_LOGIC_vector(7 downto 0);
M2 : in STD_LOGIC_vector(7 downto 0);
Mout : out STD_LOGIC_vector(15 downto 0)
);
end component;
component M8d Port ( M1 : in STD_LOGIC_vector(7 downto 0);
M2 : in STD_LOGIC_vector(7 downto 0);
Mout : out STD_LOGIC_vector(15 downto 0)
);
end component;
signal internalMM1: std_logic_vector(31 downto 0);
signal internalMM2: std_logic_vector(7 downto 0);
signal internalMMout: std_logic_vector(39 downto 0);
signal M8dout:std_logic_vector(15 downto 0);
signal M8cout:std_logic_vector(15 downto 0);
signal M8bout:std_logic_vector(15 downto 0);
signal M8out:std_logic_vector(15 downto 0);
begin
--addres: for N in 0 to 3 generate
FulMd32: M8d port map( M1=> internalMM1(31 downto 24), M2=> internalMM2, Mout=> M8dout);
FulMb32: M8b port map( M1=> internalMM1(23 downto 16), M2=> internalMM2, Mout=> M8cout);
FulMc32: M8c port map( M1=> internalMM1(15 downto 8), M2=> internalMM2, Mout=> M8bout);
FulM32: M8 port map( M1=> internalMM1(7 downto 0), M2=> internalMM2, Mout=> M8out);
internalMMout<=("000000000000000000000000" & M8out)
+ ("0000000000000000" & M8bout & "00000000") + ("00000000" & M8cout & "0000000000000000")
+ (M8dout & "000000000000000000000000");
internalMM1 <= MM1;
internalMM2 <= MM2;
MMout <= internalMMout;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity ALU is
port( A :in std_logic_vector(31 downto 0);
B :in std_logic_vector(31 downto 0);
SS:in std_logic_vector(2 downto 0);
C :out std_logic_vector(63 downto 0);
D :out std_logic_vector(31 downto 0);
La,Sm,Eq: out std_logic);
end ALU;
architecture Behavioral of ALU is
Component M32 is port (M1 : in STD_LOGIC_vector(31 downto 0);
M2 : in STD_LOGIC_vector(31 downto 0);
Mout : out STD_LOGIC_vector(63 downto 0));
end component;
Component SUB32 is port(A : in STD_LOGIC_vector(31 downto 0);
B : in STD_LOGIC_vector(31 downto 0);
OFL:out std_logic;
S : out STD_LOGIC_vector(31 downto 0));
end component;
Component adder32 is Port(A : in STD_LOGIC_vector(31 downto 0);
B : in STD_LOGIC_vector(31 downto 0);
Cin : in STD_LOGIC;
Cout : out STD_LOGIC;
S : out STD_LOGIC_vector(31 downto 0));
end component;
signal aM1,aM2,bM1,bM2,cM1,cM2,cMout,bMout : STD_LOGIC_vector(31 downto 0);
signal aMout: STD_LOGIC_vector(63 downto 0);
signal Overflow: std_logic;
begin
A1: M32 port map( M1=> aM1, M2=>aM2, Mout=>aMout);
A2: SUB32 port map(A=> bM1, B=> bM2, S=>bMout, OFL=>Overflow);
A3: adder32 port map(A=> cM1, B=> cM2, Cout=>open,S=>cMout,Cin=>'0');
process(SS,A,B,Overflow,aMout,bMout,CMout)
begin
Case SS is
When "000"=> aM1<=A;
aM2<=B;
C<=aMout;
When "001" => if Overflow='1' then
bM1<=A;
bM2<=B;
D<=bMout;
else
D<="00000000000000000000000000000000";
end if;
when "010" => cM1<=A;
cM2<=B;
D<= cMout;
when "011" => if (A > B) then
La<='1';
Sm<='0';
Eq<='0';
else if (A<B) then
La<='0';
Sm<='1';
Eq<='0';
else
La<='0';
Sm<='0';
Eq<='1';
end if;
end if;
when "100" =>
D <= (A and B);
when "101" =>
D <= (A or B);
when "110" =>
D <= (A xor B);
When others=> C<="ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ";
D<="ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ";
end case;
end process;
end Behavioral;
32-bit ALU
Based on the Device utilization summary, two designs of multiplier have very similar area utilization. 32-bit multiplier by 8-bit multiplier use about 5% more logic unit than single 32-bit multiplier. The number of used route thru used for 32-bit multiplier by 8-bit multiplier is 238% of single 32-bit multiplier. Even use different design, their performance are the same.
You have very obscure way of doing multiplier as scary_jeff indicates. Most likely the synthesis tool gets confused about that.
Instead of
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
Please have
use ieee.numeric_std.all;
and instead of
std_logic_vector(n-1 downto 0)
use
signed(n-1 downto 0);
Then you can just multiply with *.
Off topic, but instead of
D<="00000000000000000000000000000000";
you can use
D <= (others => '0');

vhd xlinix something is wrong same values it must be with muxes

I have a problem with my program in xilinx vhd.
I have to create a processor that supports the classic instructions of MIPS32
add, sub, and, or, lw, sw, sine and cosine. Sine and Cosine will take as argument a number and will return the cos or sin of the angle in ΙΕΕΕ-754 Single precision and Integer from 0 – 1000.
I have an excel file which produce a hex output(for the commands of Mips32) that i use in one components(in InstructionRom)
The input numbers that I want to add or sub or and ..etc..I write them in HEX in the component DataRam.
The problem is with the top component in ReadData1 and ReadData2 I got the same values.
Below I have 2 screenshots and how the top entity is connected with other components.
Other components are working.
Can anyone take a look please?
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity myTOP is
Port ( clk : in STD_LOGIC;
reset : in STD_LOGIC;
instruction : out STD_LOGIC_VECTOR (31 downto 0);
regA : out STD_LOGIC_VECTOR (31 downto 0);
regB : out STD_LOGIC_VECTOR (31 downto 0);
ALUout : out STD_LOGIC_VECTOR (31 downto 0);
writeReg : out STD_LOGIC_VECTOR (4 downto 0);
Opcode : out STD_LOGIC_VECTOR (5 downto 0);
SinCos : out STD_LOGIC_VECTOR (31 downto 0);
DataOUT : out STD_LOGIC_VECTOR (31 downto 0);
ReadDATA1 : out STD_LOGIC_VECTOR (31 downto 0);
ReadDATA2 : out STD_LOGIC_VECTOR (31 downto 0);
WriteData : out STD_LOGIC_VECTOR (31 downto 0));
end myTOP;
architecture Behavioral of myTOP is
component InstructionsROM is
Port ( InstructionAddress : in STD_LOGIC_VECTOR (9 downto 0);
Instruction : out STD_LOGIC_VECTOR (31 downto 0));
end component;
component myPCRegister is
Port ( PC_INPUT : in STD_LOGIC_VECTOR (9 downto 0);
PC_OUTPUT : out STD_LOGIC_VECTOR (9 downto 0);
clk : in STD_LOGIC;
RESET : in STD_LOGIC);
end component;
component my_10bitAdder is
Port ( a : in STD_LOGIC_VECTOR (9 downto 0);
b : in STD_LOGIC;
cin : in STD_LOGIC;
cout : out STD_LOGIC;
z : out STD_LOGIC_VECTOR (9 downto 0));
end component;
component my_5bitMUX is
Port ( a : in STD_LOGIC_VECTOR (4 downto 0);
b : in STD_LOGIC_VECTOR (4 downto 0);
s : in STD_LOGIC;
z : out STD_LOGIC_VECTOR (4 downto 0));
end component;
component my32to9bit is
Port ( a : in STD_LOGIC_VECTOR (31 downto 0);
z : out STD_LOGIC_VECTOR (8 downto 0));
end component;
component my32BitRegistersFile is
Port ( ReadRegister1 : in STD_LOGIC_VECTOR (4 downto 0);
ReadRegister2 : in STD_LOGIC_VECTOR (4 downto 0);
WriteRegister : in STD_LOGIC_VECTOR (4 downto 0);
WriteData : in STD_LOGIC_VECTOR (31 downto 0);
ReadData1 : out STD_LOGIC_VECTOR (31 downto 0);
ReadData2 : out STD_LOGIC_VECTOR (31 downto 0);
ReadData3 : out STD_LOGIC_VECTOR (31 downto 0);
RegWrite : in STD_LOGIC;
clk : in STD_LOGIC;
Reset : in STD_LOGIC);
end component;
component myControlUnit is
Port ( A : in STD_LOGIC_VECTOR (5 downto 0);
RegDst : out STD_LOGIC;
ALUSrc : out STD_LOGIC;
MemtoReg : out STD_LOGIC;
RegWrite : out STD_LOGIC;
MemRead : out STD_LOGIC;
MemWrite : out STD_LOGIC;
ALUop1 : out STD_LOGIC;
SinCos : out STD_LOGIC;
FI : out STD_LOGIC);
end component;
component my16to32bit is
Port ( a : in STD_LOGIC_VECTOR (31 downto 0);
z : out STD_LOGIC_VECTOR (31 downto 0));
end component;
component myALUControl is
Port ( a : in STD_LOGIC_VECTOR (2 downto 0);
s : in STD_LOGIC;
op1 : out STD_LOGIC;
op2 : out STD_LOGIC;
bin : out STD_LOGIC);
end component;
component myALU_32bit is
Port ( a : in STD_LOGIC_VECTOR (31 downto 0);
b : in STD_LOGIC_VECTOR (31 downto 0);
bin : in STD_LOGIC;
cin : in STD_LOGIC;
op1 : in STD_LOGIC;
op2 : in STD_LOGIC;
cout : out STD_LOGIC;
z : out STD_LOGIC_VECTOR (31 downto 0));
end component;
component my_SinCos is
Port ( I1 : in STD_LOGIC_VECTOR (8 downto 0);
s : in STD_LOGIC_VECTOR (1 downto 0);
e : out STD_LOGIC;
O : out STD_LOGIC_VECTOR (31 downto 0));
end component;
component DataRAM is
Port ( DataAddress : in STD_LOGIC_VECTOR (9 downto 0);
clk : in STD_LOGIC;
readData : in STD_LOGIC;
writeData : in STD_LOGIC;
DataIn : in STD_LOGIC_VECTOR (31 downto 0);
DataOut : out STD_LOGIC_VECTOR (31 downto 0));
end component;
component my_32bitMUX is
Port ( a : in STD_LOGIC_VECTOR (31 downto 0);
b : in STD_LOGIC_VECTOR (31 downto 0);
s : in STD_LOGIC;
z : out STD_LOGIC_VECTOR (31 downto 0));
end component;
signal S2, S4, S5, S6, S7, S9 , S10 , S11, S12, S13, S14, S15, S16, S17 : STD_LOGIC_VECTOR(31 downto 0);
signal S0, S1:STD_LOGIC_VECTOR (9 downto 0);
signal S3:STD_LOGIC_VECTOR (4 downto 0);
signal S8:STD_LOGIC_VECTOR (8 downto 0);
signal SC:STD_LOGIC_VECTOR (8 downto 0);
signal SA :STD_LOGIC_VECTOR (2 downto 0);
signal S18:STD_LOGIC;
begin
U0: myPCRegister port map(PC_INPUT=>S1, PC_OUTPUT=>S0, clk=>clk, RESET=>reset);
U1: my_10bitAdder port map (a=>S0, b=>'1', cin=>'0', z=>S1);
U2: InstructionsROM port map(InstructionAddress=>S0 , Instruction=> S2 );
U3: my_5bitMUX port map( a=> S2(15 downto 11), b=>S2(20 downto 16), s=>SC(0), z=>S3);
U4: my32BitRegistersFile port map(ReadRegister1=>S2(25 downto 21), ReadRegister2=>S2(20 downto 16), WriteRegister=>S3, WriteData=>S17, ReadData1=>S5, ReadData2=>S6, RegWrite=>SC(3), clk=>clk, Reset=>reset );
U5: myControlUnit port map(A=>S2(31 downto 26),RegDst=>SC(0), ALUSrc=>SC(1), MemtoReg=>SC(2), RegWrite=>SC(3), MemRead=>SC(4), MemWrite=>SC(5), ALUop1=>SC(6), SinCos=>SC(7), FI=>SC(8));
U6: my16to32bit port map(a=>S2, z=>S4);
U7: myALUControl port map(a=>S2(2 downto 0), s=>SC(6),bin=>SA(0), op1=>SA(1), op2=>SA(2));
U8: my_32bitMUX port map(a=>S4, b=>S6, s=>SC(1), z=>S10);
U9: my_32bitMUX port map(a=>S11, b=>S5, s=>SC(8), z=>S9);
U10: myALU_32bit port map(a=>S9, b=>S10, cin=>'0', bin=>SA(0), op1=>SA(1), op2=>SA(2), z=>S12);
U11: my_32bitMUX port map(a=> S5, b=>S12, s=>SC(8), z=>S7);
U12: my32to9bit port map(a=>S7, z=>S8);
U13: my_SinCos port map(I1=>S8, s=>S2(31 downto 30), e=>S18, O=>S11);
U14: DataRAM port map(DataAddress=>S2(9 downto 0), clk=>clk, readData=>SC(4), writeData=>SC(5), DataIn=>S6, DataOut=>S14);
U15: my_32bitMUX port map(a=>S12, b=>S11, s=>SC(8), z=>S13);
U16: my_32bitMUX port map(a=>S14, b=>S12, s=>SC(2), z=>S15);
U17: my_32bitMUX port map(a=>S11, b=>S15, s=>SC(7), z=>S16);
U18: my_32bitMUX port map(a=>S11, b=>S16, s=>S18, z=>S17);
instruction<=S2;
regA<=S9;
regB<=S10;
ALUout<=S12;
writeReg<=S3;
Opcode<=S2(31 downto 26);
SinCos<= S11;
DataOUT<=S14;
WriteData<=S17;
ReadDATA1<= S5;
ReadDATA2 <=S6;
end Behavioral;
DATARAM
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity DataRAM is
Port ( DataAddress : in STD_LOGIC_VECTOR (9 downto 0);
clk : in STD_LOGIC;
readData : in STD_LOGIC;
writeData : in STD_LOGIC;
DataIn : in STD_LOGIC_VECTOR (31 downto 0);
DataOut : out STD_LOGIC_VECTOR (31 downto 0));
end DataRAM;
architecture Behavioral of DataRAM is
-- Define a new type with the name RAM_Array of 8 bits
type RAM_Array is array (0 to 1023)
of std_logic_vector(7 downto 0);
-- Set some initial values in RAM for Testing
signal RAMContent: RAM_Array := (
0 => X"0A", 1 => X"00", 2 => X"00", 3 => X"00",
4 => X"05", 5 => X"00", 6 => X"00", 7 => X"00",
8 => X"2C", 9 => X"01", 10 => X"00", 11 => X"00",
12 => X"00", 13 => X"00", 14 => X"00", 15 => X"00",
others => X"00");
begin
-- This process is called when we READ from RAM
p1: process (readData, DataAddress)
begin
if readData = '1' then
DataOut(7 downto 0) <= RAMContent(conv_integer(DataAddress));
DataOut(15 downto 8) <= RAMContent(conv_integer(DataAddress+1));
DataOut(23 downto 16) <= RAMContent(conv_integer(DataAddress+2));
DataOut(31 downto 24) <= RAMContent(conv_integer(DataAddress+3));
else
DataOut <= (DataOut'range => 'Z');
end if;
end process;
-- This process is called when we WRITE into RAM
p2: process (clk, writeData)
begin
if (clk'event and clk = '1') then
if writeData ='1' then
RAMContent(conv_integer(DataAddress)) <= DataIn(7 downto 0);
RAMContent(conv_integer(DataAddress+1)) <= DataIn(15 downto 8);
RAMContent(conv_integer(DataAddress+2)) <= DataIn(23 downto 16);
RAMContent(conv_integer(DataAddress+3)) <= DataIn(31 downto 24);
end if;
end if;
end process;
end Behavioral;
INSTRUCTION ROM
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity InstructionsROM is
Port ( InstructionAddress : in STD_LOGIC_VECTOR (9 downto 0);
Instruction : out STD_LOGIC_VECTOR (31 downto 0));
end InstructionsROM;
architecture Behavioral of InstructionsROM is
-- Define a new type with the name ROM_Array of 32 bits
type ROM_Array is array (0 to 1024)
of std_logic_vector(31 downto 0);
-- The data here should be replaced with the intructions in HEX
constant ROMContent: ROM_Array := (
X"8C000000",
X"8C810000",
X"00201822",
X"00201824",
X"00201825",
X"8D000000",
X"8D810000",
X"BC03000A",
X"FC03000A",
X"3C03000A",
X"7C03000A",
others => X"00000000");
begin
Instruction <= ROMContent(conv_integer(InstructionAddress));
end Behavioral;
DataRam and instructionrom were given to us ready ..we just change the values (it depends on what instruction we want to do)
Here are some serious problems with your code:
P1: process sensitivity list should include RAMContent
U1: cout is not connected
U4: readdata3 is not connected
U10: cout is not connected
U14: component my_32bitMUX_937286 is not declared. This gives a compilation error
The first four problems can cause problems without warnings from your simulator. The last is an error and would normally cause your simulator to throw and error and refuse to start the simulation.

error in a vhdl code

i am new to vhdl. i have a code with me as follows (the sub prog compiles very fine). i can't fix the following error
** Error: C:/Users/acer/Desktop/alu new/ALU_VHDL.vhd(110): Illegal sequential statement.
** Error: C:/Users/acer/Desktop/alu new/ALU_VHDL.vhd(115): Illegal sequential statement.
** Error: C:/Users/acer/Desktop/alu new/ALU_VHDL.vhd(120): Illegal sequential statement.
** Error: C:/Users/acer/Desktop/alu new/ALU_VHDL.vhd(128): Illegal sequential statement.
** Warning: [14] C:/Users/acer/Desktop/alu new/ALU_VHDL.vhd(128): (vcom-1272) Length of formal "Remainder" is 4; length of actual is 8.
** Error: C:/Users/acer/Desktop/alu new/ALU_VHDL.vhd(138): VHDL Compiler exiting
the line nos are bold ones in the code here.they are the portmap ones
Can anyone please help me out with this. it would be very kind of you.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity ALU_VHDL is
port
(
OperandA : in std_logic_vector(3 downto 0);
OperandB : in std_logic_vector(3 downto 0);
Operation: in std_logic_vector(2 downto 0);
Startt : in std_logic;
Ready : out std_logic;
Result_High : out std_logic_vector(3 downto 0);
Result_Low : out std_logic_vector(7 downto 0);
Errorsig : out std_logic;
Reset_n : in std_logic;
Clkk : in std_logic);
end entity ALU_VHDL;
architecture Behavioral of ALU_VHDL is
-- And gate
component AND_gate
port(
x,y : IN std_logic_vector(3 downto 0);
z : OUT std_logic_vector(3 downto 0));
end component;
-- OR Gate
component OR_gate
port(
x,y : IN std_logic_vector(3 downto 0);
z : OUT std_logic_vector(3 downto 0));
end component;
-- XOR gate
component XOR_gate
port(
x,y : IN std_logic_vector(3 downto 0);
z : OUT std_logic_vector(3 downto 0));
end component;
-- Adder
COMPONENT adder4
PORT
(
C : IN std_logic;
x,y : IN std_logic_vector(3 DOWNTO 0);
R : OUT std_logic_vector(3 DOWNTO 0);
C_out : OUT std_logic);
END COMPONENT;
-- Subtractor
COMPONENT Substractor4
PORT
(
br_in : IN std_logic;
x,y : IN std_logic_vector(3 DOWNTO 0);
R : OUT std_logic_vector(3 DOWNTO 0);
E : out std_logic);
END COMPONENT;
-- Multiplier
COMPONENT mult4by4
port(operA, operB: in std_logic_vector(3 downto 0);
sumOut: out std_logic_vector(7 downto 0));
END COMPONENT;
-- Division
COMPONENT Division
Port ( Dividend : in std_logic_vector(3 downto 0);
Divisor : in std_logic_vector(3 downto 0);
Start : in std_logic;
Clk : in std_logic;
Quotient : out std_logic_vector(3 downto 0);
Remainder : out std_logic_vector(3 downto 0);
Finish : out std_logic);
END COMPONENT;
begin
process(OperandA, OperandB, Startt, Operation) is
begin
case Operation is
when "000" =>
Result_High <= "XXXX";
when "001" =>
Result_High <= OperandA and OperandB;
when "010" =>
Result_High <= OperandA or OperandB;
when "011" =>
Result_High <= OperandA xor OperandB;
when "100" =>
-- Adder
**U05 : adder4 PORT MAP (C=>Startt,x=>OperandA,y=>OperandB,R=>Result_High,C_out=>Ready);**
when "101" =>
-- Substractor & Error signal
**U06 : Substractor4 PORT MAP (br_in=>Startt,x=>OperandA,y=>OperandB,R=>Result_High,E=>Errorsig);**
when "110" =>
-- multiplication
**U07 : mult4by4 PORT MAP (operA=>OperandA,operB=>OperandB,sumOut=>Result_Low);**
when "111" =>
-- Division
if (OperandB ="0000") then
Errorsig <= '1';
else
**U08 : Division PORT MAP (Dividend=>OperandA,Divisor=>OperandB,Start=>Startt,Clk=>Clkk,Quotient=>Result_High,Remainder=>Result_Low,Finish=>Ready);**
end if;
when others =>
Errorsig <= '1';
end case;
end process;
end architecture Behavioral;
You cannot instantiate entities within a process.
Move all entity instantiations out of the process (into the architecture body) and work from there.
If you want to in instantiate component depending on the value of 'Operation', like the zennehoy wrote, you should instantiate components out of the process and in this case statement only use signal connected to this components in instantiations and link it to port you want.
For the length issue change the "Remainder : out std_logic_vector(3 downto 0);"
to "Remainder : out std_logic_vector(7 downto 0);"

Resources