Component declaration error in VHDL - vhdl

I'm trying to declare and use a componenet in a VHDL file, but Quartus II is giving me the following errors:
Error (10482): VHDL error at operacao_mod_datapath.vhd(85): object "i_LD" is used but not declared
Error (10482): VHDL error at operacao_mod_datapath.vhd(86): object "i_IN" is used but not declared
Error (10482): VHDL error at operacao_mod_datapath.vhd(87): object "o_DOUT" is used but not declared
Error (10558): VHDL error at operacao_mod_datapath.vhd(87): cannot associate formal port "o_DOUT" of mode "out" with an expression
The VHDL file of reg_in is correct, and i always declare components like that and Quartus never gives me this error. what is happening?
Below is the code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
USE ieee.numeric_std.ALL;
entity operacao_mod_datapath is
port (
i_RESET : IN STD_LOGIC; -- Sinal para resetar a maquina de estados do contador
i_CLOCK : IN STD_ULOGIC; -- Clock
i_LOAD_K : IN STD_LOGIC; -- Sinal para carregar K
i_LOAD_A : IN STD_LOGIC;
i_LOAD_B : IN STD_LOGIC;
i_LOAD_S : IN STD_LOGIC;
i_LOAD_CLEAR : IN STD_LOGIC; -- Sinal para limpar K
i_A : IN UNSIGNED (7 downto 0); -- Entrada A
i_B : IN UNSIGNED (7 downto 0); -- Entrada B
o_OUTS : OUT INTEGER; -- Saida da operação aritmética
o_COMP : OUT STD_LOGIC -- Saída do comparador
);
end operacao_mod_datapath;
architecture arch_1 of operacao_mod_datapath is
component array_multiplier is
port (
i_MULTIPLICAND : in unsigned(7 downto 0); -- data input
i_MULTIPLIER : in integer; -- data input
o_DOUT : out std_logic_vector(15 downto 0)); -- data output
end component;
component k_reg is
port (
i_CLR : IN STD_LOGIC;
i_CLK : IN STD_ULOGIC;
i_DINL : IN STD_LOGIC ; -- Sinal de load para carregar K
i_DINK : IN INTEGER; -- Valor antigo de K
o_DOUTK : BUFFER INTEGER -- saída S da operação de mod
);
end component;
component comparator is
port (
i_DINS : IN INTEGER; -- Entrada S (saída S da alu_mod)
i_DINB : IN UNSIGNED (7 downto 0); -- Entrada B (entrada do usuário)
o_DOUT : OUT STD_LOGIC); -- Saída para informar o resultado da comparação
end component;
component reg_in is
port (
i_LD : IN STD_LOGIC;
i_IN : IN UNSIGNED (7 downto 0);
o_DOUT : OUT UNSIGNED (7 downto 0)
);
end component;
component alu_mod is
port (
i_LD : IN STD_LOGIC; -- sinal de load
i_DINA : IN UNSIGNED (7 downto 0); -- Entrada A
i_DINM : IN STD_LOGIC_VECTOR(15 downto 0); -- entrada do multiplicador
o_DOUTS : OUT INTEGER -- saída S da operação de mod
);
end component;
SIGNAL w_OUT0 : UNSIGNED (7 downto 0);
SIGNAL w_OUT1 : UNSIGNED (7 downto 0);
SIGNAL w_OUT2 : INTEGER;
SIGNAL w_OUT3 : STD_LOGIC_VECTOR (15 downto 0);
SIGNAL w_OUT4 : INTEGER;
SIGNAL w_OUT5 : STD_LOGIC;
begin
u_0: reg_in port map (
i_LD <= i_LOAD_A,
i_IN <= i_A,
o_DOUT <= w_OUT0
);
u_1: reg_in port map (
i_LD <= i_LOAD_B,
i_IN <= i_B,
o_DOUT <= w_OUT1
);
u_2: array_multiplier port map (
i_MULTIPLICAND => w_OUT2,
i_MULTIPLIER => w_OUT1,
o_DOUT => w_OUT3
);
u_3: k_reg port map (
i_CLR => i_RESET,
i_CLK => i_CLOCK,
i_DINL => i_LOAD_K,
i_DINK => w_OUT2,
o_DOUTK => w_OUT2
);
u_4: alu_mod port map (
i_LD => i_LOAD_S,
i_DINA => w_OUT0,
i_DINM => w_OUT3,
o_DOUTS => w_OUT4
);
u_5: comparator port map (
i_DINS => w_OUT4,
i_DINB => w_OUT1,
o_DOUT => w_OUT5
);
o_OUTS <= w_OUT4,
o_COMP <= w_OUT5;
end arch_1;

After looking the code again I found the error:
u_0: reg_in port map (
i_LD <= i_LOAD_A,
i_IN <= i_A,
o_DOUT <= w_OUT0
);
u_1: reg_in port map (
i_LD <= i_LOAD_B,
i_IN <= i_B,
o_DOUT <= w_OUT1
)
The correct is:
u_0: reg_in port map (
i_LD => i_LOAD_A,
i_IN => i_A,
o_DOUT => w_OUT0
);
u_1: reg_in port map (
i_LD => i_LOAD_B,
i_IN => i_B,
o_DOUT => w_OUT1
);

You don't only need to declare the components, but you need to port map them as well. Port mapping is when you decide to route the signals between the various modules that are there in the code. One module's output can be routed as an input to another module and this is what port mapping is and what the tool means by "using".

Related

How to fix the VHDL error "type of identifier xxx does not agree with its usage as xxx type"?

I'm new to VHDL. My code now looks like this:
...
entity g14_lpm is
port ( i_clk : in std_logic;
i_rstb : in std_logic;
i_x : in std_logic_vector(31 downto 0);
i_y : in std_logic_vector(31 downto 0);
o_xx, o_yy : out std_logic_vector(64 downto 0)
);
end g14_lpm;
architecture arc of g14_lpm is
signal r_x : signed(31 downto 0);
signal r_y : signed(31 downto 0);
signal xx : signed(63 downto 0);
signal yy : signed(63 downto 0);
signal xy : signed(53 downto 0);
component LPM_MULT
...
port ( DATAA : in std_logic_vector(LPM_WIDTHA-1 downto 0);
DATAB : in std_logic_vector(LPM_WIDTHB-1 downto 0);
ACLR : in std_logic := '0';
CLOCK : in std_logic := '0';
CLKEN : in std_logic := '1';
RESULT : out std_logic_vector(LPM_WIDTHP-1 downto 0));
end component;
begin
------------------------COMPONENT INSTANTIATION---------------------------------
mult1 : LPM_MULT generic map (
LPM_WIDTHA => 32,
LPM_WIDTHB => 32,
LPM_WIDTHP => 64,
LPM_REPRESENTATION => "SIGNED",
LPM_PIPELINE => 4
)
--ERROR IS HERE↓
port map ( DATAA => i_x, DATAB => i_x, CLOCK => i_clk, RESULT => xx );
--ERROR IS HERE↑
...
p_mult : process (i_clk, i_rstb)
begin
...
elsif (rising_edge(i_clk)) then
r_x <= signed(i_x);
r_y <= signed(i_y);
o_xx <= std_logic_vector ('0' & xx - yy);
o_yy <= std_logic_vector (r_X*r_y & '0');
end if;
end process p_mult;
end arc;
And I am getting two errors at line 49, which is highlighted, saying type of identifier "xx" does not agree with its usage "std_logic_vector" type and cannot associate formal port "RESULT" of mode "out" with an expression.
I'm not sure what to change for this part, a significant portion of the code is provided in the manual.
How do I fix this?
Either use a helper signal
signal result : std_logic_vector(63 downto 0);
port map (
DATAA => i_x,
DATAB => i_x,
CLOCK => i_clk,
RESULT => result
);
xx <= signed(result);
or maybe they can be cast directly - never tried to be honest - like
port map (
DATAA => i_x,
DATAB => i_x,
CLOCK => i_clk,
signed(RESULT) => xx
);
as mentioned here

How to instantiate multiple components with variable size ports in vhdl?

I want to retiteratively elaborate a couple of components using for generate statements, these components have variable size ports and I don't have an idea of how assign these variable size ports to signals.
I'm using a package with this declaration:
library ieee;
use ieee.std_logic_1164.all;
PACKAGE Arrays_package IS
type Generic_ARRAY_type is array (integer range <>) of std_logic_vector;
END Arrays_package;
The components are Pre_pre_buffer_conv and Pre_buffer_conv in the code below.
How I can to declare the signal xdataout_preprebuffer?
library ieee;
use ieee.std_logic_1164.all;
use work.Arrays_package.all;
entity Naive_RNC_problem is
generic(
no_col_imag : integer := 28;
no_bits : integer := 9;
no_bits_fraction : natural := 8;
no_col_filt : integer := 3
);
port
(
CLOCK_50 : in std_logic;
KEY : in std_logic_vector(3 downto 0);
SW : in std_logic_vector(17 downto 0);
xdataout_pre_buffer_conv : out Generic_ARRAY_type(no_col_filt*no_col_filt-1 downto 0)((no_bits-1) downto 0)
);
end entity;
architecture rtl of Naive_RNC_problem is
component Image_ROM IS
PORT
(
address : IN STD_LOGIC_VECTOR (9 DOWNTO 0);
clock : IN STD_LOGIC := '1';
q : OUT STD_LOGIC_VECTOR (8 DOWNTO 0)
);
END component;
component generic_mask_nxn_v2 is
generic(
no_col_imag : integer := 28;
no_col_filt : integer := 3;
stride : integer := 1;
no_bits : integer := 10
);
Port (
-- ENTRADAS ------------------------
iclk, irst : in std_logic;
ien : in std_logic;
idatain : in std_logic_vector (no_bits-1 downto 0);
index : in integer;
iindex_ctrl : in std_logic_vector(7 downto 0);
-- SALIDAS -------------------------
odataout : out Generic_ARRAY_type(no_col_filt-1 downto 0)((no_col_filt*no_bits-1) downto 0) ;
omasken : out std_logic
);
end component;
component Pre_pre_buffer_conv is
generic
(
no_col_filt : integer := 3;
no_bits : integer := 10
);
port
(
-- ENTRADAS ------------------------
iclk, irst : in std_logic;
ien : in std_logic;
index : in integer;
iindex_ctrl : in std_logic_vector(7 downto 0);
idatain : in Generic_ARRAY_type(no_col_filt-1 downto 0)(no_col_filt*no_bits-1 downto 0);
-- SALIDAS -------------------------
odataout : out Generic_ARRAY_type(no_col_filt-1 downto 0)(no_col_filt*no_bits-1 downto 0)
);
end component;
component Pre_buffer_conv is
generic
(
no_col_filt : integer := 3;
no_bits : integer := 9
);
port
(
-- ENTRADAS ------------------------
iclk, irst : in std_logic;
ien : in std_logic;
idatain : in Generic_ARRAY_type(no_col_filt-1 downto 0)(no_col_filt*no_bits-1 downto 0);
isel_row : in std_logic_vector(3 downto 0);
isel_col : in std_logic_vector(3 downto 0);
-- SALIDAS -------------------------
odataout : out std_logic_vector (no_bits-1 downto 0)
);
end component;
component Top_Control_prepre_buffer is
port (-- ENTRADAS -----------
iclk, ireset : in std_logic;
iStart : in std_logic;
imasken_conv : in std_logic;
ifin_convolvers : in std_logic;
ifin_interfaz_Conv_pool : in std_logic;
-- SALIDAS -----------------------
oidle : out std_logic;
orst : out std_logic;
oen_line_buffer_conv : out std_logic;
odir_imagen : out std_logic_Vector(15 downto 0);
ocarga_prepre_buffer : out std_logic;
ocarga_pre_buffer_conv : out std_logic;
oind_pre_buffers_conv : out std_logic_Vector(15 downto 0);
oStart_convolver : out std_logic;
oinicia_interfaz_Conv_pool : out std_logic
);
end component;
--=======================================================
-- Signal declarations
--=======================================================
signal xRST : std_logic;
signal xrst_ctrl : std_logic;
signal xStart : std_logic;
signal xclk_50 : std_logic;
signal xaddress_memoria_MNIST_ROM, xaddress_MNIST_PORTA: STD_LOGIC_VECTOR (9 DOWNTO 0);
signal xdataout_MNIST_ROM : STD_LOGIC_VECTOR (8 DOWNTO 0);
signal xaddress_memoria_MNIST_ctrl : STD_LOGIC_VECTOR (15 DOWNTO 0);
signal xrst_buffer_conv : std_logic;
signal xdatain_buffer : std_logic_vector (no_bits-1 downto 0);
signal xdataout_buffer : Generic_ARRAY_type(no_col_filt-1 downto 0)((no_col_filt*no_bits-1) downto 0) ;
signal xmasken_buffer : std_logic;
signal xen_line_buffer_conv : std_logic;
signal xcarga_prepre_buffer : std_logic;
signal xsel_row_pre_buffer : std_logic_vector(3 downto 0);
signal xsel_col_pre_buffer : std_logic_vector(3 downto 0);
signal xstart_fill_buffers_conv : std_logic;
signal xcarga_pre_buffer_conv : std_logic;
signal xind_pre_buffers_conv_ctrl : std_logic_vector(15 downto 0);
signal xind_pre_buffers_conv : std_logic_vector(7 downto 0);
signal xrst_contol_prepre_buffer : std_logic;
signal xfin_convolver, xfin_Interfaz_conv_pool : std_logic;
-- how to declare this signal? ---------------------------
type my_type1 is array (no_col_filt-1 downto 0) of std_logic_vector((no_col_filt*no_bits-1) downto 0);
type my_type2 is array(no_col_filt*no_col_filt-1 downto 0) of my_type1;
signal xdataout_preprebuffer : my_type2;
----
--=======================================================
-- Structural coding
--=======================================================
begin
xRST <= not KEY(0);
xStart <= not KEY(1);
-- RELOJES ===============================================
xclk_50 <= CLOCK_50;
-- MEMORIA IMAGEN MNIST ===============================================
MemoriaROM_MNIST : Image_ROM port map (xaddress_memoria_MNIST_ROM, xclk_50, xdataout_MNIST_ROM);
xaddress_memoria_MNIST_ROM <= xaddress_memoria_MNIST_Ctrl(9 downto 0);
-- Line Buffer convolucion ==============================================
Buffer_mask : generic_mask_nxn_v2 generic map ( no_col_imag => no_col_imag,
no_col_filt => no_col_filt,
stride => 1,
no_bits => no_bits
)
port map (-- ENTRADAS ------------------------
xclk_50, xrst_buffer_conv,
xen_line_buffer_conv, xdatain_buffer,
0,
(others => '0'),
-- SALIDAS -------------------------
xdataout_buffer, -- this is a variable size port (no problem here)
xmasken_buffer
);
xrst_buffer_conv <= xRST or xrst_ctrl ;--(not xRST) or
xdatain_buffer <= xdataout_MNIST_ROM;
-- Control Prepre Buffer convolucion ==============================================
Prepre_buffer_ctrl : Top_Control_prepre_buffer port map (-- ENTRADAS -----------------------
xclk_50, xrst_contol_prepre_buffer,
xStart,
xmasken_buffer,
xfin_convolver,
xfin_Interfaz_conv_pool,
-- SALIDAS -----------------------
open, xrst_ctrl,
xen_line_buffer_conv,
xaddress_memoria_MNIST_ctrl,
xcarga_prepre_buffer, xcarga_pre_buffer_conv, xind_pre_buffers_conv_ctrl,
open,
open
);
xrst_contol_prepre_buffer <= xRST;
xfin_convolver <= '1';
xfin_Interfaz_conv_pool <= '1';
-- Pre pre Buffer convolucion ===========================================
pre_pre_buffers_conV : for i in 0 to (no_col_filt*no_col_filt-1) generate
pre_pre_buffer_conV_cmp : Pre_pre_buffer_conv generic map (no_col_filt => no_col_filt,
no_bits => no_bits
)
port map (-- ENTRADAS -----------------------
xclk_50, xrst_buffer_conv,
xcarga_prepre_buffer,
i,
xind_pre_buffers_conv,
xdataout_buffer, -- this is a variable size port (no problem here)
-- SALIDAS -----------------------
xdataout_preprebuffer(i) -- this is a variable size port (ERROR HERE)
);
end generate;
-- Pre Buffer convolucion ==============================================
pre_buffers_conV : for i in 0 to (no_col_filt*no_col_filt-1) generate
pre_buffer_conV_cmp : Pre_buffer_conv generic map (no_col_filt => no_col_filt,
no_bits => no_bits
)
port map (-- ENTRADAS -----------------------
xclk_50, xrst_buffer_conv,
xcarga_pre_buffer_conv,
xdataout_preprebuffer(i), -- this is a variable size port (ERROR HERE)
xsel_row_pre_buffer,
xsel_col_pre_buffer,
-- SALIDAS -----------------------
xdataout_pre_buffer_conv(i)
);
end generate;
xind_pre_buffers_conv <= xind_pre_buffers_conv_ctrl(7 downto 0);
xsel_row_pre_buffer <= (others => '0');
xsel_col_pre_buffer <= (others => '0');
end rtl;
The errors thrown by analysis & elaboration stage were:
Error (10381): VHDL Type Mismatch error at Naive_RNC_problem.vhd(228):
indexed name returns a value whose type does not match
"Generic_ARRAY_type", the type of the target expression
Error: Quartus Prime Analysis & Elaboration was unsuccessful. 1 error,
0 warnings
I believe that the signal xdataout_preprebuffer has to be declared as 2d array signal, but I don't know how to accomplish that.
Two changes.
An added type in the package:
library ieee;
use ieee.std_logic_1164.all;
package arrays_package is
type generic_array_type is array (integer range <>) of std_logic_vector;
type generic_array_of_generic_type is -- ADDED type
array (integer range <>) of generic_array_type;
end package arrays_package;
and the signal declaration:
signal xdataout_preprebuffer: generic_array_of_generic_type -- type mark
-- index subtype:
(no_col_filt * no_bits - 1 downto 0)
-- element constraint (generic_array_type):
-- index subtype:
(no_col_filt - 1 downto 0)
-- element index constraint (std_logic_vector):
(no_col_filt * no_bits - 1 downto 0);
After which your code will analyze (elaboration and simulation requires the entities to which all those components are bound during elaboration. With entity declarations and dummy architecture bodies for your components your code elaborates and simulates (showing associations and assignments don't have bounds errors).
The added type uses the -2008 unbounded array definition as does the original (See IEEE Std 1076-2008 5.3.2 Array types, 5.3.2.1 General,
5.3.2.2 Index constraints and discrete ranges, 6.3 Subtype declarations).
What we have is an unbound one-dimensional array type (generic_array_of_generic_type) whose element type (unbounded one-dimensional type generic_array_type) has it's own element unbounded one-dimensional array type (std_logic_vector). The index constraints for the unbounded array types are provided during object declaration.

Two outputs values in a mod operation using vhdl

I am trying to do a circuit that get the MOD of two numbers, my problem is in the output of that circuit, the output shows 0 and then the correct value of MOD, i have to integrate this circuito to another circuit to do a circuito that shows if a number is prime or not. When i integrate the MOD circuit to the PRIME number circuit, the output of the PRIME circuit goes always wrong because the situation above, the output of the MOD circuit shows always two values. The output form below:
In this image the circuit get always 0 and 3 because my state machine stays in loop, this is not the problem, the problem is: i need that output stay always with the value of the MOD and no zeros. In this example should stay always 3.
My control code.
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
USE IEEE.std_logic_unsigned.ALL;
use IEEE.std_logic_arith.ALL;
ENTITY operacao_modulo_control IS
PORT (
i_CLK : IN STD_ULOGIC;
i_RST : IN STD_LOGIC;
i_S : IN INTEGER;
i_COMP : IN STD_LOGIC;
o_LD_CLR : OUT STD_LOGIC;
o_LD_K : OUT STD_LOGIC;
o_DOUT : OUT INTEGER
);
END operacao_modulo_control;
ARCHITECTURE arch_1 OF operacao_modulo_control IS
TYPE state_type IS (s0, s1, s2,s3);
SIGNAL stateT : state_type;
BEGIN
PROCESS(i_CLK)
BEGIN
IF rising_edge(i_CLK) THEN
IF (i_RST = '1') THEN
stateT <= s0;
ELSE
CASE stateT IS
when s0 => stateT <= s1;
when s1 => if (i_COMP = '1') then
stateT <= s2;
else
stateT <= s3;
end if;
when s2 => stateT <= s1;
when s3 => stateT <= s0;
END CASE;
END IF;
END IF;
END PROCESS;
o_LD_CLR <= '1' WHEN (stateT = s0) ELSE '0';
o_LD_K <= '1' WHEN (stateT = s2) ELSE '0';
o_DOUT <= i_S WHEN (stateT = s3) ELSE 0;
END arch_1;
How can i change this to make the output shows only the correct value of the MOD and no zeros?
If the other codes is necessary, they are below:
Datapath:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
USE ieee.numeric_std.ALL;
entity operacao_modulo_datapath is
port (
i_RESET : IN STD_LOGIC; -- Sinal para resetar a maquina de estados do contador
i_CLOCK : IN STD_ULOGIC; -- Clock
i_LOAD_K : IN STD_LOGIC; -- Sinal para carregar K
i_LOAD_CLEAR : IN STD_LOGIC; -- Sinal para limpar K
i_A : IN UNSIGNED (7 downto 0); -- Entrada A
i_B : IN UNSIGNED (7 downto 0); -- Entrada B
o_OUTS : OUT INTEGER; -- Saida da operação aritmética
o_COMP : OUT STD_LOGIC -- Saída do comparador
);
end operacao_modulo_datapath;
architecture arch_1 of operacao_modulo_datapath is
component tot is
port (
i_RST : IN STD_LOGIC;
i_CLR : IN STD_LOGIC; -- Sinal vindo do controle para limpar o valor de K
i_CLK : IN STD_ULOGIC; -- Sinal de clock para sincronizar com o controle
i_DINL : IN STD_LOGIC ; -- Sinal de load para carregar K
i_DINK : IN INTEGER; -- Valor antigo de K
o_DOUTK : OUT INTEGER
); -- data output
end component;
component array_multiplier is
port (
i_MULTIPLICAND : in unsigned(7 downto 0); -- data input
i_MULTIPLIER : in integer; -- data input
o_DOUT : out std_logic_vector(15 downto 0)); -- data output
end component;
component alu_mod is
port (
i_DINA : IN UNSIGNED (7 downto 0); -- Entrada A
i_DINM : IN STD_LOGIC_VECTOR(15 downto 0); -- entrada do multiplicador
o_DOUTS : OUT INTEGER -- saída S da operação de mod
);
end component;
component comparator is
port (
i_DINS : IN INTEGER; -- Entrada S (saída S da alu_mod)
i_DINB : IN UNSIGNED (7 downto 0); -- Entrada B (entrada do usuário)
o_DOUT : OUT STD_LOGIC); -- Saída para informar o resultado da comparação
end component;
signal w_OUT : STD_LOGIC;
signal w_Ko : INTEGER;
signal w_Ki : INTEGER;
signal w_OUT0 : INTEGER;
signal w_OUT1 : std_logic_vector(15 downto 0);
begin
u_0: tot port map (
i_RST => i_RESET,
i_CLR => i_LOAD_CLEAR,
i_CLK => i_CLOCK,
i_DINL => i_LOAD_K,
i_DINK => w_Ko,
o_DOUTK => w_Ko
);
u_1: array_multiplier port map (
i_MULTIPLICAND => i_B,
i_MULTIPLIER => w_Ko,
o_DOUT => w_OUT1
);
u_2: alu_mod port map (
i_DINA => i_A,
i_DINM => w_OUT1,
o_DOUTS => w_OUT0
);
u_3: comparator port map (
i_DINS => w_OUT0,
i_DINB => i_B,
o_DOUT => w_OUT
);
o_OUTS <= w_OUT0;
o_COMP <= w_OUT;
end arch_1;
Top level entity:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
USE ieee.numeric_std.ALL;
entity operacao_modulo_top is
port (
i_RESETAR : IN STD_LOGIC; -- Sinal para resetar a maquina de estados do contador
i_CLCK : IN STD_ULOGIC; -- Clock
i_INA : IN UNSIGNED (7 downto 0); -- Entrada A
i_INB : IN UNSIGNED (7 downto 0); -- Entrada B
o_SOMA : OUT INTEGER -- Saida da operação aritmética
);
end operacao_modulo_top;
architecture arch_1 of operacao_modulo_top is
component operacao_modulo_datapath is
port(
i_RESET : IN STD_LOGIC; -- Sinal para resetar a maquina de estados do contador
i_CLOCK : IN STD_ULOGIC; -- Clock
i_LOAD_K : IN STD_LOGIC; -- Sinal para carregar K
i_LOAD_CLEAR : IN STD_LOGIC; -- Sinal para limpar K
i_A : IN UNSIGNED (7 downto 0); -- Entrada A
i_B : IN UNSIGNED (7 downto 0); -- Entrada B
o_OUTS : OUT INTEGER; -- Saida da operação aritmética
o_COMP : OUT STD_LOGIC -- Saída do comparador
);
end component;
component operacao_modulo_control is
port (
i_CLK : IN STD_ULOGIC;
i_RST : IN STD_LOGIC;
i_S : IN INTEGER;
i_COMP : IN STD_LOGIC;
o_LD_CLR : OUT STD_LOGIC;
o_LD_K : OUT STD_LOGIC;
o_DOUT : OUT INTEGER
);
end component;
signal w_OUT0 : INTEGER;
signal w_OUT3 : INTEGER;
signal w_OUT1 : STD_LOGIC;
signal w_OUT2 : STD_LOGIC;
signal w_OUT : STD_LOGIC;
begin
u_0: operacao_modulo_datapath port map (
i_RESET => i_RESETAR,
i_CLOCK => i_CLCK,
i_LOAD_K => w_OUT2,
i_LOAD_CLEAR => w_OUT1,
i_A => i_INA,
i_B => i_INB,
o_OUTS => w_OUT0,
o_COMP => w_OUT
);
u_1: operacao_modulo_control port map (
i_CLK => i_CLCK,
i_RST => i_RESETAR,
i_S => w_OUT0,
i_COMP => w_OUT,
o_LD_CLR => w_OUT1,
o_LD_K => w_OUT2,
o_DOUT => w_OUT3
);
o_SOMA <= w_OUT3;
end arch_1;
Your problem is this line:
o_DOUT <= i_S WHEN (stateT = s3) ELSE 0;
stateT only equals s3 one clock in three, hence you output. If you don't want the zeros, you need to store the value of i_S in some flip-flops, which are updated when stateT = s3:
PROCESS(i_CLK)
BEGIN
IF rising_edge(i_CLK) THEN
IF i_RST = '1' THEN
o_DOUT <= 0;
ELSIF stateT = s3 THEN
o_DOUT <= i_S;
END IF;
END IF;
END PROCESS;
http://www.edaplayground.com/x/25QN

Blind/ground unused testbench ports

I got top module including sub-modules instantiated in testbench file. The sub-modules are pretty free on their own, therefore when I am testing the top module, I need to introduce only few signals and track few outputs, but the top module has many other ports.
May I provide some "default"/"undefined" signal (and sink) to those pins (not regarding their size, type)?
There are 2 ways I solve that right now, either take out the sub-module to test it (well, but I want to test it within top module) or write appropriate "zero" inputs for inputs and introduce signals for outputs (lot of work as well).
using VHDL with Vivado 2015
alright, so this is the testbench
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;
entity tb_FIR_v0_3 is
end tb_FIR_v0_3;
architecture Behavioral of tb_FIR_v0_3 is
shared variable C_S00_AXI_DATA_WIDTH : integer := 32;
shared variable C_S00_AXI_ADDR_WIDTH : integer := 7;
component FIR_v0_3 is
generic (
C_S00_AXI_DATA_WIDTH : integer := 32;
C_S00_AXI_ADDR_WIDTH : integer := 7
);
port (
fir_clk : in std_logic;
fir_x_in : in std_logic_vector(C_S00_AXI_DATA_WIDTH-1 downto 0);
fir_y_out : out std_logic_vector(C_S00_AXI_DATA_WIDTH-1 downto 0);
fir_d_out : out std_logic_vector(C_S00_AXI_DATA_WIDTH-1 downto 0);
-- User ports ends
s00_axi_aclk : in std_logic;
s00_axi_aresetn : in std_logic;
s00_axi_awaddr : in std_logic_vector(C_S00_AXI_ADDR_WIDTH-1 downto 0);
s00_axi_awprot : in std_logic_vector(2 downto 0);
s00_axi_awvalid : in std_logic;
s00_axi_awready : out std_logic;
s00_axi_wdata : in std_logic_vector(C_S00_AXI_DATA_WIDTH-1 downto 0);
s00_axi_wstrb : in std_logic_vector((C_S00_AXI_DATA_WIDTH/8)-1 downto 0);
s00_axi_wvalid : in std_logic;
s00_axi_wready : out std_logic;
s00_axi_bresp : out std_logic_vector(1 downto 0);
s00_axi_bvalid : out std_logic;
s00_axi_bready : in std_logic;
s00_axi_araddr : in std_logic_vector(C_S00_AXI_ADDR_WIDTH-1 downto 0);
s00_axi_arprot : in std_logic_vector(2 downto 0);
s00_axi_arvalid : in std_logic;
s00_axi_arready : out std_logic;
s00_axi_rdata : out std_logic_vector(C_S00_AXI_DATA_WIDTH-1 downto 0);
s00_axi_rresp : out std_logic_vector(1 downto 0);
s00_axi_rvalid : out std_logic;
s00_axi_rready : in std_logic
);
end component FIR_v0_3;
signal e_clk : std_logic := '1' ;
signal e_reset : std_logic := '1' ;
signal e_x_in : std_logic_vector (31 downto 0);
signal e_y_out : std_logic_vector (31 downto 0);
signal e_d_out : std_logic_vector (31 downto 0);
signal s00_axi_awready : std_logic;
signal s00_axi_wready : std_logic;
signal s00_axi_bresp : std_logic_vector(1 downto 0);
signal s00_axi_bvalid : std_logic;
signal s00_axi_arready : std_logic;
signal s00_axi_rdata : std_logic_vector(32-1 downto 0);
signal s00_axi_rresp : std_logic_vector(1 downto 0);
signal s00_axi_rvalid : std_logic;
signal s00_axi_aclk : std_logic := '0';
signal s00_axi_aresetn : std_logic;
signal s00_axi_awaddr : std_logic_vector(C_S00_AXI_ADDR_WIDTH-1 downto 0);
signal s00_axi_awprot : std_logic_vector(2 downto 0);
signal s00_axi_awvalid : std_logic := '0';
signal s00_axi_wdata : std_logic_vector(C_S00_AXI_DATA_WIDTH-1 downto 0);
signal s00_axi_wstrb : std_logic_vector((C_S00_AXI_DATA_WIDTH/8)-1 downto 0);
signal s00_axi_wvalid : std_logic := '0';
signal s00_axi_bready : std_logic := '0';
signal s00_axi_araddr : std_logic_vector(C_S00_AXI_ADDR_WIDTH-1 downto 0);
signal s00_axi_arprot : std_logic_vector(2 downto 0);
signal s00_axi_arvalid : std_logic := '0';
signal s00_axi_rready : std_logic := '0';
begin
inst_FIR_v0_3 : FIR_v0_3
generic map (
C_S00_AXI_DATA_WIDTH => 32,
C_S00_AXI_ADDR_WIDTH => 7
)
port map (
-- Users to add ports here
fir_clk => e_clk,
fir_x_in => e_x_in,
fir_y_out => e_y_out,
fir_d_out => e_d_out,
-- Ports of Axi Slave Bus Interface S00_AXI
s00_axi_aclk => s00_axi_aclk,
s00_axi_aresetn => e_reset,
s00_axi_awaddr => ( others => '0' ),
s00_axi_awprot => ( others => '0' ),
s00_axi_awvalid => s00_axi_awvalid,
s00_axi_awready => s00_axi_awready,
s00_axi_wdata => ( others => '0' ),
s00_axi_wstrb => ( others => '0' ),
s00_axi_wvalid => s00_axi_wvalid,
s00_axi_wready => s00_axi_wready,
s00_axi_bresp => s00_axi_bresp,
s00_axi_bvalid => s00_axi_bvalid,
s00_axi_bready => s00_axi_bready,
s00_axi_araddr => ( others => '0' ),
s00_axi_arprot => ( others => '0' ),
s00_axi_arvalid => s00_axi_arvalid,
s00_axi_arready => s00_axi_arready,
s00_axi_rdata => s00_axi_rdata,
s00_axi_rresp => s00_axi_rresp,
s00_axi_rvalid => s00_axi_rvalid,
s00_axi_rready => s00_axi_rready
);
process
variable count : integer := 0;
begin
if ( count = 0 ) then
-- e_reset <= '0'; -- VALUES NOT INITIATED PROPERLY, FUCKER ? ... With the non-stop, pop pop and stainless steel (DMX)
e_x_in <= x"00000000";
end if;
if ( count = 3 ) then
-- e_reset <= '1';
end if;
if ( count = 3 ) then
e_x_in <= x"00000001";
end if;
if ( count = 5 ) then
e_x_in <= x"00000000";
end if;
if ( count = 8 ) then
e_x_in <= x"00000000";
end if;
e_clk <= not(e_clk);
wait for 0.5 ns;
count := count + 1;
if( (count = 60) ) then
count := 0;
end if;
end process;
end Behavioral;
I am too lazy to create signal for every AXI input/output ports and then connect them one by one. May I avoid somehow creating those 21 signals ...
signal s00_axi_awready : std_logic;
signal s00_axi_wready : std_logic;
signal s00_axi_bresp : std_logic_vector(1 downto 0);
signal s00_axi_bvalid : std_logic;
signal s00_axi_arready : std_logic;
....
...
and then connecting them ? Like this ...
s00_axi_wvalid => s00_axi_wvalid,
s00_axi_wready => s00_axi_wready,
s00_axi_bresp => s00_axi_bresp,
s00_axi_bvalid => s00_axi_bvalid,
s00_axi_bready => s00_axi_bready,
Is there any "universal" in/out signal that I would tie to pins that are not important, because I cant leave the ports of an instance unconnected (as far as I know and tried).
If I understand the question correctly, inputs in your port definition can have default values, and outputs can be left unconnected in an instantiation. For example:
entity ShiftRegister is
Generic (
WIDTH : integer
);
Port (
clk : in STD_LOGIC;
enable : in STD_LOGIC := '1';
serial_in : in STD_LOGIC := '0';
parallel_out : out STD_LOGIC_VECTOR (WIDTH-1 downto 0);
);
end ShiftRegister;
...
SR : entity work.ShiftRegister
Generic map (
WIDTH : integer => 8
)
Port map(
clk => serial_clk,
serial_in => serial_data_in
);
In this example, the register will always be enabled, and the entity does not output anything. Not a very useful instantiation in this case, but I think this answers your question!

VHDL Factorial calculator

I am attempting to create a 16-bit factorial calculator for an unsigned binary number. In doing so I have created a data path and a state machine that
a.) outputs a final value of 1 if the value input is 0
b.) displays and overflow flag if the input is over 8!
c.) Calculates the value for the factorial if the value input is less then 8 and not zero.
The system seems to fall apart if the value I input is anything over 3 yet still not an overflow. I think the issue is somewhere in Test3, Update 1, update 2 in my state machine. Could anyone help explain what is going wrong?
State Machine:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity fact_16_ctrlv2 is
port(
go : in STD_LOGIC;
clk : in STD_LOGIC;
clr : in STD_LOGIC;
overflow : in STD_LOGIC;
numeqcnt : in STD_LOGIC;
factzero : in STD_LOGIC;
flag: out STD_logic;
xload : out STD_LOGIC;
cntmux : out STD_LOGIC;
cntload : out STD_LOGIC;
factload : out STD_LOGIC;
factmux : out STD_LOGIC;
finalload : out STD_LOGIC;
finalmuxselect: out STD_logic;
decimalpoint: out std_logic
);
end fact_16_ctrlv2;
--}} End of automatically maintained section
architecture fact_16_ctrlv2 of fact_16_ctrlv2 is
type state_type is (start, input, test1, test2, test3, update1, update2, update3, done);
signal present_state, next_state: state_type;
begin
sreg: process(clk, clr)
begin
if clr='1' then
present_state <= start;
elsif clk'event and clk='1' then
present_state <= next_state;
end if;
end process;
c1: process(present_state, go, overflow, factzero, numeqcnt)
begin
case present_state is
when start =>
if go = '1' then
next_state <= input;
else
next_state <= start;
end if;
when input =>
next_state <= test1;
when test1 =>
if factzero= '1' then
next_state <= done;
else
next_state <= test2;
end if;
when test2 =>
if overflow = '1' then
next_state <= done;
else
next_state <= update3;
end if;
when update3 =>
next_state <= test3;
when test3 =>
if numeqcnt = '1' then
next_state <= done;
else
next_state <= update1;
end if;
when update1 =>
next_state <= update2;
when update2 =>
next_state <= test3;
when done =>
next_state <= done;
when others =>
null;
end case;
end process;
C2: process(present_state, overflow, numeqcnt, factzero)
begin
xload<= '0';
flag <= '0';
cntmux <= '0';
cntload<= '0';
factload<='0';
factmux<='0';
finalload <='0';
finalmuxselect<='0';
decimalpoint<='0';
case present_state is
when input =>
xload<='1';
--cntmux<='1';
--cntload<='1';
when test2 =>
if overflow ='1' then
flag <= '1';
finalmuxselect<='0';
finalload<='1';
factload <='1';
decimalpoint <='1';
end if;
when test1 =>
if factzero ='1' then
flag <= '1';
finalmuxselect <='1';
finalload <='1';
end if;
when update3 =>
cntmux<='1';
cntload<='1';
factmux<= '1';
factload<= '1';
when test3 =>
if numeqcnt ='1' then
finalmuxselect<='0';
--finalload<='1';
factload <='1';
cntload<='1';
factmux<='0';
else
end if;
when update1 =>
factmux<='0';
factload<='1';
when update2 =>
cntmux<='0';
cntload<='1';
--factload<='1';
when done =>
finalload<='1';
when others =>
null;
end case;
end process;
end fact_16_ctrlv2;
Data Path
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity fact_16_dp is
port(
clr : in STD_LOGIC;
clk : in STD_LOGIC;
X : in STD_LOGIC_VECTOR(3 downto 0);
overflow : out STD_LOGIC;
finalfact : out STD_LOGIC_VECTOR(15 downto 0);
cntload, cntmult, factload, factmult, xload, finalload :in Std_logic;
equalone, numcnt : out Std_logic;
finalmuxselect, flagin: in STD_logic
);
end fact_16_dp;
--}} End of automatically maintained section
architecture fact_16_dp of fact_16_dp is
-- Component declaration of the "mult16b(mult16b)" unit defined in
-- file: "./../src/multiplier.vhd"
component mult16b
port(
a : in STD_LOGIC_VECTOR(15 downto 0);
b : in STD_LOGIC_VECTOR(15 downto 0);
p : out STD_LOGIC_VECTOR(15 downto 0));
end component;
for all: mult16b use entity work.mult16b(mult16b);
-- Component declaration of the "comp(comp)" unit defined in
-- file: "./../src/comparitor.vhd"
component comp
generic(
N : INTEGER := 8);
port(
x : in STD_LOGIC_VECTOR(N-1 downto 0);
y : in STD_LOGIC_VECTOR(N-1 downto 0);
gt : out STD_LOGIC;
eq : out STD_LOGIC;
lt : out STD_LOGIC);
end component;
for all: comp use entity work.comp(comp);
-- Component declaration of the "adder(adder)" unit defined in
-- file: "./../src/adder.vhd"
component adder
generic(
N : INTEGER := 8);
port(
a : in STD_LOGIC_VECTOR(N-1 downto 0);
b : in STD_LOGIC_VECTOR(N-1 downto 0);
y : out STD_LOGIC_VECTOR(N-1 downto 0));
end component;
for all: adder use entity work.adder(adder);
-- Component declaration of the "reg(reg)" unit defined in
-- file: "./../src/reg.vhd"
component reg
generic(
N : INTEGER := 8);
port(
load : in STD_LOGIC;
clk : in STD_LOGIC;
clr : in STD_LOGIC;
d : in STD_LOGIC_VECTOR(N-1 downto 0);
q : out STD_LOGIC_VECTOR(N-1 downto 0));
end component;
for all: reg use entity work.reg(reg);
-- Component declaration of the "mux2g(mux2g)" unit defined in
-- file: "./../src/mux21.vhd"
component mux2g
generic(
N : INTEGER);
port(
a : in STD_LOGIC_VECTOR(N-1 downto 0);
b : in STD_LOGIC_VECTOR(N-1 downto 0);
s : in STD_LOGIC;
y : out STD_LOGIC_VECTOR(N-1 downto 0));
end component;
for all: mux2g use entity work.mux2g(mux2g);
-- Component declaration of the "mux4g(mux4g)" unit defined in
-- file: "./../src/mux4to1.vhd"
component mux4g
generic(
N : INTEGER);
port(
a : in STD_LOGIC_VECTOR(N-1 downto 0);
b : in STD_LOGIC_VECTOR(N-1 downto 0);
c : in STD_LOGIC_VECTOR(N-1 downto 0);
s : in STD_LOGIC_VECTOR(1 downto 0);
y : out STD_LOGIC_VECTOR(N-1 downto 0));
end component;
for all: mux4g use entity work.mux4g(mux4g);
--signal cntload, cntmult, numcnt, factload, factmult, xload, numload, equalone, finalload :Std_logic;
signal adderout, cntregout, cntregin, x2 :Std_logic_vector(3 downto 0);
signal xin, factregin, factregout, overin, factmout, checkzero, numregout, flag, finalmuxout, cntregoutb :Std_logic_vector(15 downto 0);
begin
x2 <= x;
xin <= "000000000000" & x2; --Change 4 bit number input into a 16 bit number
cntregoutb <= "000000000000" & cntregout; --change count from 4 bit value to a 16 bit value
flag <= "000000000000000" & flagin;
cntreg : reg --4-bit counter register
generic map(
N => 4
)
port map(
load => cntload,
clk => clk,
clr => clr,
d => cntregin, --not in drawing
q => cntregout
);
factreg : reg --16-bit fact register
generic map(
N => 16
)
port map(
load => factload,
clk => clk,
clr => clr,
d => factregin,
q => factregout
);
--numreg : reg --16-bit num register
--generic map(
--N => 16
--)
--port map(
--load => numload,
--clk => clk,
--clr => clr,
--d => xin,
--q => numregout
--);
xreg : reg --4-bit initial x vlaue register
generic map(
N => 4
)
port map(
load => xload,
clk => clk,
clr => clr,
d => x, --x(3:0)
q => x2
);
finalreg : reg --16-bit final fact register
generic map(
N => 16
)
port map(
load => finalload,
clk => clk,
clr => clr,
d => finalmuxout,
q => finalfact
);
cntmux : mux2g --4-bit cnt mux
generic map(
N => 4
)
port map(
b => "0001", --initial value set
a => adderout, --value after initial run through
s => cntmult,
y => cntregin --cntregin not in drawing
);
factmux : mux2g --16-bit fact mux
generic map(
N => 16
)
port map(
b => "0000000000000001", --initial value set
a => factmout, --value after initial run through
s => factmult,
y => factregin
);
add1 : adder --Increment counter 4-bit
generic map(
N => 4
)
port map(
a => cntregout, --add 1
b => "0001", --1
y => adderout --out of the adder
);
multiplier : mult16b --multiply cnt and fact 16-bit
port map(
a => factregout,
b => cntregoutb, --cnt plus 12 zeros to 16-bit
p => factmout --Multiplier out
);
greater8 : comp --16-bit check x overflow if greater then 8
generic map(
N => 16
)
port map(
x => xin, --check value to 8
y => "0000000000001000",
gt => overflow --send overflow flag
--eq => eq,
--lt => lt
);
check0 : comp --16-bit check x not equal to zero
generic map(
N => 16
)
port map(
x => xin,
y => "0000000000000000",
--gt => gt,
eq => equalone
--lt => lt
);
numeqcnt : comp --16-bit check if num equals cnt
generic map(
N => 16
)
port map(
x => xin,
y => cntregoutb, --need 16 bit
--gt => gt,
eq => numcnt --not in drawing
--lt => lt
);
finalmux: mux2g
generic map(
N => 16
)
port map(
a => factregout,
b => flag,
s => finalmuxselect,
y => finalmuxout
);
end fact_16_dp;
Connected together
-------------------------------------------------------------------------------
--
-- Title : fact_16
-- Design : lab4
-- Author :
-- Company :
--
-------------------------------------------------------------------------------
--
-- File : c:\My_Designs\lab4\lab4\src\fact_16.vhd
-- Generated : Tue Oct 14 16:40:38 2014
-- From : interface description file
-- By : Itf2Vhdl ver. 1.22
--
-------------------------------------------------------------------------------
--
-- Description :
--
-------------------------------------------------------------------------------
--{{ Section below this comment is automatically maintained
-- and may be overwritten
--{entity {fact_16} architecture {fact_16}}
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity fact_16 is
port(
go : in STD_LOGIC;
clk : in STD_LOGIC;
clr : in STD_LOGIC;
x : in STD_LOGIC_VECTOR(3 downto 0);
overflowB : out STD_LOGIC;
factout : out STD_LOGIC_VECTOR(15 downto 0)
);
end fact_16;
architecture fact_16 of fact_16 is
-- Component declaration of the "fact_16_dp(fact_16_dp)" unit defined in
-- file: "./../src/fact_16_dp.vhd"
component fact_16_dp
port(
clr : in STD_LOGIC;
clk : in STD_LOGIC;
X : in STD_LOGIC_VECTOR(3 downto 0);
overflow : out STD_LOGIC;
finalfact : out STD_LOGIC_VECTOR(15 downto 0);
cntload : in STD_LOGIC;
cntmult : in STD_LOGIC;
factload : in STD_LOGIC;
factmult : in STD_LOGIC;
xload : in STD_LOGIC;
finalload : in STD_LOGIC;
equalone : out STD_LOGIC;
numcnt : out STD_LOGIC;
finalmuxselect : in STD_LOGIC;
flagin : in STD_LOGIC);
end component;
for all: fact_16_dp use entity work.fact_16_dp(fact_16_dp);
-- Component declaration of the "fact_16_ctrlv2(fact_16_ctrlv2)" unit defined in
-- file: "./../src/fact_16_ctrlv2.vhd"
component fact_16_ctrlv2
port(
go : in STD_LOGIC;
clk : in STD_LOGIC;
clr : in STD_LOGIC;
overflow : in STD_LOGIC;
numeqcnt : in STD_LOGIC;
factzero : in STD_LOGIC;
flag : out STD_LOGIC;
xload : out STD_LOGIC;
cntmux : out STD_LOGIC;
cntload : out STD_LOGIC;
factload : out STD_LOGIC;
factmux : out STD_LOGIC;
finalload : out STD_LOGIC;
finalmuxselect : out STD_LOGIC;
decimalpoint : out STD_LOGIC);
end component;
for all: fact_16_ctrlv2 use entity work.fact_16_ctrlv2(fact_16_ctrlv2);
signal overflow, numeqcnt, factzero, xload, cntmux, cntload, factload, flag, factmux, numload, finalload: STD_logic;
signal finalmuxselect: std_logic;
begin
Dpath : fact_16_dp
port map(
clr => clr,
clk => clk,
X => X,
overflow => overflow,
finalfact => factout,
cntload => cntload,
cntmult => cntmux,
factload => factload,
factmult => factmux,
xload => xload,
finalload => finalload,
equalone => factzero,
numcnt => numeqcnt,
finalmuxselect => finalmuxselect,
flagin => flag
);
Cunit : fact_16_ctrlv2
port map(
go => go,
clk => clk,
clr => clr,
overflow => overflow,
numeqcnt => numeqcnt,
factzero => factzero,
flag => flag,
xload => xload,
cntmux => cntmux,
cntload => cntload,
factload => factload,
factmux => factmux,
finalload => finalload,
finalmuxselect => finalmuxselect,
decimalpoint => overflowB
);
end fact_16;

Resources