I keep getting an error that says:
line 25: type error near num_values ; current type unsigned; expected
type unsigned.
It is already the type that is supposed to be, and I think it is same in bit length and declared alright, what am I doing wrong here?
The code is about implementation of fifo queue structure.
<Queue.vhd>
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity Queue is
port (
-- clock
clk: in std_logic;
-- input
push: in std_logic;
push_data: in std_logic_vector(31 downto 0);
pop: in std_logic;
-- output
pop_data: out std_logic_vector(31 downto 0);
num_values: out unsigned(31 downto 0)
);
end entity;
architecture Behavioral of Queue is
type items is array(0 to 31) of std_logic_vector(31 downto 0);
signal manager : items := (others => (others => '0'));
signal push_idx, pop_idx : integer := 0;
begin
process(clk) is
variable howmany : integer := 0;
begin
if rising_edge(clk) then
if (push = '1') then
manager(push_idx) <= push_data;
push_idx <= push_idx + 1;
howmany := howmany + 1;
end if;
if (pop = '1') then
if (howmany /= 0) then
pop_data <= manager(pop_idx);
pop_idx <= pop_idx + 1;
howmany := howmany - 1;
end if;
else
pop_data <= std_logic_vector(to_unsigned(0,pop_data'length));
end if;
if (push_idx = 31) then
push_idx <= 0;
end if;
if (pop_idx = 31) then
pop_idx <= 0;
end if;
num_values <= to_unsigned(howmany,32);
end if;
end process;
end architecture;
<QueueTb.vhd>
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity QueueTb is
end entity;
architecture sim of QueueTb is
constant ClockFrequency : integer := 100e6;
constant ClockPeriod : time := 1000ms / ClockFrequency;
signal clk : std_logic := '0';
signal push, pop : std_logic := '0';
signal num_values : unsigned(31 downto 0);
signal push_data, pop_data : std_logic_vector(31 downto 0) := (others =>'0');
begin
UUT : entity work.Queue(Behavioral)
port map(
clk => clk,
push => push,
pop => pop,
num_values => num_values, <=== this is where error occurs!
push_data => push_data,
pop_data => pop_data);
clk <= not clk after ClockPeriod / 2;
process is
begin
wait for 10 ns;
push <= '1';
push_data <= conv_std_logic_vector(123,32);
wait for 10 ns;
push_data <= conv_std_logic_vector(456,32);
wait for 10 ns;
push <= '0';
push_data <= conv_std_logic_vector(0,32);
pop <= '1';
wait for 10 ns;
pop <= '0';
push <= '1';
push_data <= conv_std_logic_vector(789,32);
wait for 10 ns;
push <= '0';
pop <= '1';
wait for 80 ns;
end process;
end architecture;
What am I doing wrong here??
In the Queue entity you are using ieee.numeric_std and in the QueueTB you are using ieee.std_logic_arith . Both define different unsigned types.
Delete std_logic_arith from the testbench as it is not a standard VHDL library and use numeric_std instead.
I have the follwing existing FPGA code
fpga_avr32_data : INOUT STD_LOGIC_VECTOR(15 DOWNTO 0);
SIGNAL read_sensor : INTEGER;
TYPE meas_type IS ARRAY (7 DOWNTO 0) OF STD_LOGIC_VECTOR(11 DOWNTO 0);
TYPE meas_reg_type IS ARRAY (NATURAL RANGE <>) OF meas_type;
fpga_avr32_data <= "0000" & meas_reg(read_sensor)(read_channel)
--
I want to replace "0000" with the lowest 4 "bits" of read_sensor, something like this
fpga_avr32_data <= read_sensor(3 DOWNTO 0) & meas_reg(read_sensor)(read_channel)
Is this possible ?
Regards
Yes, it is possible. But not the way you do it. read_sensor is an integer while fpga_avr32_data is a STD_LOGIC_VECTOR, so you must first convert the integer into a vector:
library ieee;
use ieee.numeric_std.all;
...
signal rsv: std_logic_vector(31 downto 0);
...
rsv <= std_logic_vector(to_signed(read_sensor, 32));
And then extract the 4 LSBs:
fpga_avr32_data <= rsv(3 DOWNTO 0) & meas_reg(read_sensor)(read_channel);
I'm trying to implement a circuit for a digital signature (RSA) on a FPGA Digilent Basys.
I ended to write down all the components and the top level entity. The Control Unit is formed by a Finit State Machine that controls the whole circuit.
But when I load it on my Basys, it seems to freeze in the State "V_wait_sign".
I can say that because how you can see in the FSM, in the state "V_wait_sign" I puts Leds out to "00100", so just the Led2 is On.
Below the code of the Top Level Entity and the FSM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity FirmaDigitale is
Port ( Clock : in STD_LOGIC;
Buttons : in STD_LOGIC_VECTOR (3 downto 0);
Switches : in STD_LOGIC_VECTOR (7 downto 0);
Leds : out STD_LOGIC_VECTOR (7 downto 0);
Cathodes : out STD_LOGIC_VECTOR (7 downto 0);
Anodes : out STD_LOGIC_VECTOR (3 downto 0));
end FirmaDigitale;
architecture Structural of FirmaDigitale is
component Comparator32
Generic(width : Positive := 32);
Port ( a : in STD_LOGIC_VECTOR (width-1 downto 0);
b : in STD_LOGIC_VECTOR (width-1 downto 0);
Clock : in STD_LOGIC;
Comp_en : in STD_LOGIC; -- 1 attivo
equal : out STD_LOGIC;
Notequal : out STD_LOGIC);
end component;
component Decoder_2_4
Port ( i : in STD_LOGIC_VECTOR (1 downto 0);
o : out STD_LOGIC_VECTOR (3 downto 0));
end component;
component Decoder_Seven_segm
Port ( Ing : in STD_LOGIC_VECTOR (3 downto 0);
Cathodes : out STD_LOGIC_VECTOR (6 downto 0));
end component;
component FSM_RSA
Port (
Clock : in STD_LOGIC; -- Clock
--in
Start_sign : in STD_LOGIC; --start sign
Load : in STD_LOGIC; --load 8 bits
Verify : in STD_LOGIC; --start verify signature
Done : in STD_LOGIC; --end message
Exp_Done : in STD_LOGIC; --end exp operation
Count_hit :in STD_LOGIC; --signature load
Count_eq :in STD_LOGIC; --
Count_neq :in STD_LOGIC; --
--control
Enable_Hash : out STD_LOGIC; -- Enable hash '0' attivo (2colpi)
Enable_Exp : out STD_LOGIC; -- Enable exp '1' attivo
Enable_RegExp : out STD_LOGIC; -- Enable RegExp '0' attivo
Enable_sign_reg : out STD_LOGIC; -- Enable sign_reg '0' attivo
Enable_comp : out STD_LOGIC; -- Enable Comparator '1' attivo
Enable_Disp : out STD_LOGIC_VECTOR(3 downto 0); -- Enable 7segm '0' attivo
Leds_step : out STD_LOGIC_VECTOR(4 downto 0);
Mux_sel : out STD_LOGIC; -- 1 per verifica, 0 per firma
Mux_disp : out STD_LOGIC; -- 1 MSB, 0 LSB
Reset_State : out STD_LOGIC -- Reset '0' attivo
);
end component;
component HashFunction
Generic( width : integer := 32; width_reg : integer := 8);
Port ( CharacterByte : in STD_LOGIC_VECTOR(width_reg-1 downto 0);
Clock : in STD_LOGIC;
Reset : in STD_LOGIC; --0 attivo
Reg_en : in STD_LOGIC; --0 attivo
Digest : out STD_LOGIC_VECTOR(width-1 downto 0)
);
end component;
component Mux_2n_1n
Generic(width : integer := 8);
Port ( a : in STD_LOGIC_VECTOR(width-1 downto 0);
b : in STD_LOGIC_VECTOR(width-1 downto 0);
s : in STD_LOGIC;
o : out STD_LOGIC_VECTOR(width-1 downto 0));
end component;
component RAsync_2UpNCount_UpCounter
Generic (width : integer := 2);
Port ( clock : in STD_LOGIC; -- Clock
reset : in STD_LOGIC; -- Segnale di reset 0 attivo
en : in STD_LOGIC; -- Segnale di enable 1 attivo
count : out STD_LOGIC_VECTOR (width-1 downto 0) := (others => '0')); -- conteggio attuale
end component;
component SignReg
Generic( width : integer := 32; width_reg : integer := 8 );
Port ( SignatureByte : in STD_LOGIC_VECTOR (width_reg-1 downto 0);
Reset : in STD_LOGIC;
Count_En : in STD_LOGIC;
Clock : in STD_LOGIC;
hit : out STD_LOGIC;
Signature : out STD_LOGIC_VECTOR (width-1 downto 0));
end component;
component exponentiator
Generic (n : integer := 32);
Port (
x, y, m: in std_logic_vector(n-1 downto 0);
z: inout std_logic_vector(n-1 downto 0);
clk, reset, start: in std_logic;
done: out std_logic
);
end component;
component display_7_segments
Generic(
clock_frequency_in : integer := 50000000;
clock_frequency_out : integer := 50000000
);
Port ( clock : in STD_LOGIC;
reset_n : in STD_LOGIC;
digits : in STD_LOGIC_VECTOR (15 downto 0);
enable : in STD_LOGIC_VECTOR (3 downto 0);
dots : in STD_LOGIC_VECTOR (3 downto 0);
anodes : out STD_LOGIC_VECTOR (3 downto 0);
cathodes : out STD_LOGIC_VECTOR (7 downto 0));
end component;
component Debouncer_xilinx is
Port ( CLK : in STD_LOGIC;
Sig : in STD_LOGIC;
Deb_Sig : out STD_LOGIC);
end component;
signal temp_exp_done, temp_enable_exp, sel_muxTo_display, temp_count_hit, temp_sel_EncDec, temp_comp_en, temp_eq, temp_not_eq, temp_en_RegExp : STD_LOGIC := '0';
signal temp_reset_state, temp_enable_hash, temp_en_SignReg : STD_LOGIC := '1';
signal temp_digest, temp_exp_out, temp_key, temp_sign, Exp_mux_out, RegExp_out : STD_LOGIC_VECTOR(31 downto 0) := (others => '0');
signal temp_enable_disp : STD_LOGIC_VECTOR(3 downto 0) := (others => '0');
signal temp_digits, temp_digits_to_display, temp_fin_digits : STD_LOGIC_VECTOR(15 downto 0);
signal Start_temp, Load_temp, Verify_temp, Done_temp : STD_LOGIC;
begin
deb_0: Debouncer_xilinx
port map(
CLK => Clock,
Sig => Buttons(0),
Deb_Sig => Start_temp
);
deb_1: Debouncer_xilinx
port map(
CLK => Clock,
Sig => Buttons(1),
Deb_Sig => Load_temp
);
deb_2: Debouncer_xilinx
port map(
CLK => Clock,
Sig => Buttons(2),
Deb_Sig => Verify_temp
);
deb_3: Debouncer_xilinx
port map(
CLK => Clock,
Sig => Buttons(3),
Deb_Sig => Done_temp
);
FSM: FSM_RSA
Port map (
Clock => Clock,
Start_sign => Start_temp,
Load => Load_temp, --load 8 bits
Verify => Verify_temp,
Done => Done_temp,
Exp_Done => temp_exp_done,
Count_hit => temp_count_hit,
Count_eq => temp_eq,
Count_neq => temp_not_eq,
--control
Enable_Hash => temp_enable_hash,
Enable_Exp => temp_enable_exp,
Enable_RegExp => temp_en_RegExp,
Enable_sign_reg => temp_en_SignReg,
Enable_comp => temp_comp_en,
Enable_Disp => temp_enable_disp,
Leds_step => Leds(4 downto 0),
Mux_sel => temp_sel_EncDec,
Mux_disp => sel_muxTo_display,
Reset_State => temp_reset_state
);
RegExp : entity work.Generic_RAsync_Register
generic map (width => 32)
port map (
D=> temp_exp_out,
clock => Clock,
reset => temp_reset_state,
en => temp_en_RegExp,
Q => RegExp_out
);
EncriptDecript: exponentiator
Generic map(n => 32)
Port map( x => temp_key,
y => Exp_mux_out,
m => x"0000008F", --143, p=11, q=13; pq=143
z => temp_exp_out,
clk => Clock,
reset => not temp_reset_state,
start => temp_enable_exp,
done => temp_exp_done
);
Leds(7) <= temp_exp_done;
Mux_Enc_Dec: Mux_2n_1n
Generic map(width => 32)
Port map( a => x"00000071", --113, Chiave Privata
b => x"00000011", --17, Chiave Pubblica
s => temp_sel_EncDec,
o => temp_key
);
RegistroFirma: SignReg
Generic map( width => 32, width_reg => 8 )
Port map( SignatureByte => Switches,
Reset => temp_reset_state,
Count_En => temp_en_SignReg,
Clock => Clock,
hit => temp_count_hit,
Signature => temp_sign
);
Exp_mux : Mux_2n_1n generic map (width => 32)
port map(
a => temp_digest,
b => temp_sign,
s => temp_sel_EncDec,
o => Exp_mux_out
);
HASH: HashFunction
Generic map( width => 32, width_reg => 8)
Port map( CharacterByte => Switches,
Clock => Clock,
Reset => temp_reset_state,
Reg_en => temp_enable_hash,
Digest => temp_digest
);
Display: display_7_segments
Generic map( clock_frequency_in => 50000000, clock_frequency_out => 1000 )
Port map( clock => Clock,
reset_n => temp_reset_state,
digits => temp_digits,
enable => temp_enable_disp,
dots => "0000",
anodes => Anodes,
cathodes => Cathodes
);
Mux_MSB_LSB: Mux_2n_1n
Generic map(width => 16)
Port map( a => RegExp_out(15 downto 0),
b => RegExp_out(31 downto 16),
s => sel_muxTo_display,
o => temp_digits
);
Compare: Comparator32
Generic map( width => 32 )
Port map( a => RegExp_out,
b => temp_sign,
Clock => Clock,
Comp_en => temp_comp_en,
equal => temp_eq,
Notequal => temp_not_eq
);
Leds(6) <= temp_eq;
Leds(5) <= temp_not_eq;
end Structural;
this is the FSM instead:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity FSM_RSA is
Port (
Clock : in STD_LOGIC; -- Clock
--in
Start_sign : in STD_LOGIC; --start sign
Load : in STD_LOGIC; --load 8 bits
Verify : in STD_LOGIC; --start verify signature
Done : in STD_LOGIC; --end message
Exp_Done : in STD_LOGIC; --end exp operation
Count_hit :in STD_LOGIC; --signature load
Count_eq :in STD_LOGIC; --
Count_neq :in STD_LOGIC; --
--control
Enable_Hash : out STD_LOGIC; -- Enable hash '0' attivo (2colpi)
Enable_Exp : out STD_LOGIC; -- Enable exp '1' attivo
Enable_RegExp : out STD_LOGIC; -- Enable RegExp '0' attivo
Enable_sign_reg : out STD_LOGIC; -- Enable sign_reg '0' attivo
Enable_comp : out STD_LOGIC; -- Enable Comparator '1' attivo
Enable_Disp : out STD_LOGIC_VECTOR(3 downto 0); -- Enable 7segm '0' attivo
Leds_step : out STD_LOGIC_VECTOR(4 downto 0);
Mux_sel : out STD_LOGIC; -- 1 per verifica, 0 per firma
Mux_disp : out STD_LOGIC; -- 1 MSB, 0 LSB
Reset_State : out STD_LOGIC -- Reset '0' attivo
);
end FSM_RSA;
architecture Behavioral of FSM_RSA is
-- Definizione dell'insieme degli stati
type State is (Idle, V_wait8, S_wait8, V_Hash,V_waitReg, V_waitH, S_waitH, S_Hash, V_wait_sign, V_decrypt, V_comp, V_reg, S_encrypt, S_dispMSB, S_dispLSB);
-- Definizione dei segnali di "stato" e inizializzazione allo stato iniziale idle
signal Current_State, Next_State : State := Idle;
begin
-- Process per la gestione dell'evoluzione dello stato
state_management : process(Clock)
begin
if falling_edge(Clock) then
Current_State <= Next_State;
else
Current_State <= Current_State;
end if;
end process;
-- Process per la gestione della FSM
FSM : process(Current_State, Start_sign, Load, Verify, Done, Exp_Done, Count_eq, Count_neq, Count_hit)
begin
case Current_State is
--macchina in attesa di comandi. Tutti i registri disabilitati
when Idle =>
Enable_Hash <= '1';
Enable_Exp <= '0';
Enable_RegExp <= '1';
Enable_sign_reg <= '1';
Enable_comp <= '0';
Enable_Disp <= "0000";
Reset_State <= '0';
Mux_sel <= '0';
Mux_disp <= '0';
Leds_step <= "00000";
if (Verify = '1') then
Next_State <= V_wait8;
else
if ( Start_sign ='1') then
Next_state <= S_wait8;
else
Next_state <= Idle;
end if;
end if;
when S_encrypt =>
Enable_Hash <= '1';
Enable_Exp <= '1'; -- abilito
Enable_RegExp <= '0'; -- abilito
Enable_sign_reg <= '1';
Enable_comp <= '0';
Enable_Disp <= "0000";
Reset_State <= '1';
Mux_sel <= '0'; --decript M_h**d modn
Mux_disp <= '0';
Leds_step <= "00010";
if (Exp_Done = '1') then
Next_State <= S_dispMSB;
else
Next_state <= S_encrypt;
end if;
when S_dispLSB =>
Enable_Hash <= '1';
Enable_Exp <= '0';
Enable_RegExp <= '1';
Enable_sign_reg <= '1';
Enable_comp <= '0';
Enable_Disp <= "1111"; -- abilito
Reset_State <= '1';
Mux_sel <= '0';
Mux_disp <= '0'; --LSB
if (Done = '1') then
Next_State <= Idle;
else
Next_state <=S_dispLSB;
end if;
when S_dispMSB =>
Enable_Hash <= '1';
Enable_Exp <= '0';
Enable_RegExp <= '1';
Enable_sign_reg <= '1';
Enable_comp <= '0';
Enable_Disp <= "1111"; -- abilito
Reset_State <= '1';
Mux_sel <= '0';
Mux_disp <= '1'; --MSB
if (Load = '1') then
Next_State <= S_dispLSB;
else
Next_state <=S_dispMSB;
end if;
when S_waitH =>
Enable_Hash <= '1'; --disabilito tutto
Enable_Exp <= '0';
Enable_RegExp <= '1';
Enable_sign_reg <= '1';
Enable_comp <= '0';
Enable_Disp <= "0000";
Reset_State <= '1';
Mux_sel <= '0';
if( Load = '0') then
Next_State <= S_wait8;
else
Next_State <= S_waitH;
end if;
when S_Hash =>
Enable_Hash <= '0'; -- abilito
Enable_Exp <= '0';
Enable_RegExp <= '1';
Enable_sign_reg <= '1';
Enable_comp <= '0';
Enable_Disp <= "0000";
Reset_State <= '1';
Mux_sel <= '0';
Mux_disp <= '0';
Next_State <= S_waitH;
when S_wait8 =>
Enable_Hash <= '1'; --disabilito tutto
Enable_Exp <= '0';
Enable_RegExp <= '1';
Enable_sign_reg <= '1';
Enable_comp <= '0';
Enable_Disp <= "0000";
Reset_State <= '1';
Mux_sel <= '0';
Mux_disp <= '0';
Leds_step <= "00001";
if (Done = '1') then
Next_State <= S_encrypt;
else
if ( Load = '1') then
Next_state <= S_Hash;
else
Next_state <= S_wait8;
end if;
end if;
when V_comp =>
Enable_Hash <= '1';
Enable_Exp <= '0';
Enable_RegExp <= '0';
Enable_sign_reg <= '1';
Enable_comp <= '1'; -- abilito
Enable_Disp <= "0000";
Reset_State <= '1';
Mux_sel <= '1'; --decript M_h**e modn
Mux_disp <= '0';
Leds_step <= "10000";
if (Count_eq = '1' OR Count_neq ='1') then
if (Done = '1') then
Next_State <= Idle;
end if;
end if;
when V_decrypt =>
Enable_Hash <= '1';
Enable_Exp <= '1'; -- abilito
Enable_RegExp <= '0'; -- abilito
Enable_sign_reg <= '1';
Enable_comp <= '0';
Enable_Disp <= "0000";
Reset_State <= '1';
Mux_sel <= '1'; --decript M_h**e modn
Mux_disp <= '0';
Leds_step <= "01000";
if (Exp_Done = '1') then
Next_State <= V_comp;
else
Next_state <= V_decrypt;
end if;
when V_Reg =>
Enable_Hash <= '1';
Enable_Exp <= '0';
Enable_RegExp <= '1';
Enable_sign_reg <= '0'; -- abilito
Enable_comp <= '0';
Enable_Disp <= "1111";
Reset_State <= '1';
Mux_sel <= '0';
Mux_disp <= '0';
if( Count_hit = '1') then
Next_State <= V_decrypt;
else
Next_State <= V_waitReg;
end if;
when V_waitReg =>
Enable_Hash <= '1'; --disabilito tutto
Enable_Exp <= '0';
Enable_RegExp <= '1';
Enable_sign_reg <= '1';
Enable_comp <= '0';
Enable_Disp <= "0000";
Reset_State <= '1';
Mux_sel <= '0';
Mux_disp <= '0';
if( Load = '0') then
Next_State <= V_wait_sign;
else
Next_State <= V_waitReg;
end if;
when V_wait8 =>
Enable_Hash <= '1'; --disabilito tutto
Enable_Exp <= '0';
Enable_RegExp <= '1';
Enable_sign_reg <= '1';
Enable_comp <= '0';
Enable_Disp <= "0000";
Reset_State <= '1';
Mux_sel <= '0';
Mux_disp <= '0';
if (Done = '1') then
Next_State <= V_wait_sign;
else
if ( Load = '1') then
Next_state <= V_Hash;
else
Next_state <= V_wait8;
end if;
end if;
when V_Hash =>
Enable_Hash <= '0'; -- abilito
Enable_Exp <= '0';
Enable_RegExp <= '1';
Enable_sign_reg <= '1';
Enable_comp <= '0';
Enable_Disp <= "0000";
Reset_State <= '1';
Mux_sel <= '0';
Mux_disp <= '0';
Next_State <= V_waitH;
when V_waitH =>
Enable_Hash <= '1'; --disabilito tutto
Enable_Exp <= '0';
Enable_RegExp <= '1';
Enable_sign_reg <= '1';
Enable_comp <= '0';
Enable_Disp <= "0000";
Reset_State <= '1';
Mux_sel <= '0';
if( Load = '0') then
Next_State <= V_wait8;
else
Next_State <= V_waitH;
end if;
when V_wait_sign =>
Enable_Hash <= '1'; --disabilito tutto
Enable_Exp <= '0';
Enable_RegExp <= '1';
Enable_sign_reg <= '1';
Enable_comp <= '0';
Enable_Disp <= "0000";
Reset_State <= '1';
Mux_sel <= '0';
Leds_step <= "00100";
if (Load = '1') then -- AND Count_hit = '0') then
Next_State <= V_reg;
-- else
-- if (Count_hit = '1') then
-- Next_state <= V_decrypt;
else
Next_state <= V_wait_sign;
--end if;
end if;
end case;
end process;
end Behavioral;
I can't understand what could be wrong. When I try the testbench, it seems to work.
But tjan on the FPGA it freezes on that state. It is as if he did not receive the signal "Count Hit" from the "SignReg". But I'm not sure about that
I tried to implement an adder which is way faster then the average RCA. Therefore I used the XILINX library and found one easy adder called adsu8. I want to embed it into my recent VHDL code. but therefore I have to stick to the data type BIT and BIT_VECTOR. Now every time I synthesise there pops out a bunch of warnings like this:
:Xst:2036 - Inserting OBUF on port > driven by black box . Possible simulation mismatch.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- entity of module
entity rca_8bit is
Port ( OP_A : in BIT_VECTOR (7 downto 0);
OP_B : in BIT_VECTOR (7 downto 0);
ADDSUB : in BIT;
SUM : out BIT_VECTOR (7 downto 0);
FLAGS : out BIT_VECTOR (4 downto 0));
end rca_8bit;
-- architecture describes behavior of module
architecture behavioral of rca_8bit is
-- sub-module is declared
component adsu8
port ( A : in STD_LOGIC_VECTOR (7 downto 0);
B : in STD_LOGIC_VECTOR (7 downto 0);
CI : in BIT;
S : out STD_LOGIC_VECTOR (7 downto 0);
CO : out BIT;
OFL : out BIT);
end component;
-- some code to avoid the blackbox warning message of
-- component adsu8 which is implemented from schematics
attribute box_type : string;
attribute box_type of adsu8 : component is "black_box";
-- additional wires std_logic
signal SIG_A,SIG_B,SIG_S : STD_LOGIC_VECTOR (7 downto 0);
-- additional wires bit
signal SIG_SUM : BIT_VECTOR (7 downto 0);
signal SIG_FLAGS : BIT_VECTOR (4 downto 0);
signal SIG_CO,SIG_OFL : BIT;
begin
-- instantiate and do port map
AS8 : adsu8 port map (SIG_A,SIG_B,ADDSUB,SIG_S,SIG_CO,SIG_OFL);
-- convert and forward std_logic to bit
SIG_A <= to_stdlogicvector(OP_A);
SIG_B <= to_stdlogicvector(OP_B);
SIG_SUM <= to_bitvector(SIG_S);
-- assign result
SUM <= SIG_SUM;
-- generate flags
SIG_FLAGS(0) <= SIG_SUM(7) xor SIG_FLAGS(1); -- S (N xor V)
SIG_FLAGS(1) <= SIG_OFL; -- V
SIG_FLAGS(2) <= SIG_SUM(7); -- N (MSB = 0)
SIG_FLAGS(3) <= '1' when SIG_SUM = "00000000" else '0'; -- Z
SIG_FLAGS(4) <= SIG_CO; -- C
-- assign flags
FLAGS <= SIG_FLAGS;
end behavioral;
I am not this experienced in VHDL but also not that less. But this problem confuses me and causes headache. I am grateful for any solution or information in the right direction.
Thanks in advance and best regards
Tobi
I want to use four push buttons as inputs and three seven-segment LED displays as outputs. Two push buttons should step up and down through the sixteen RAM locations; the other two should increment and decrement the contents of the currently-displayed memory location. I am now trying to simulate my design using ModelSim test benches, with button presses. Here is what I believe to be the relevant portions of my code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity DE2_TOP is
port (
KEY : in std_logic_vector(3 downto 0); -- Push button
);
end DE2_TOP;
architecture datapath of DE2_TOP is
begin
U1: entity work.lab1 port map (
key => key,
);
end datapath;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity raminfr is -STANDARD RAM INFERENCE
port (
clk : in std_logic;
we : in std_logic;
a : in unsigned(3 downto 0);
di : in unsigned(7 downto 0);
do : out unsigned(7 downto 0)
);
end raminfr;
architecture rtl of raminfr is
type ram_type is array (0 to 15) of unsigned(7 downto 0);
signal RAM : ram_type;
signal read_a : unsigned(3 downto 0);
begin
process (clk)
begin
if rising_edge(clk) then
if we = '1' then
RAM(to_integer(a)) <= di;
end if;
read_a <= a;
end if;
end process;
do <= RAM(to_integer(read_a));
end rtl;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity lab1 is
port(
clock : in std_logic;
key : in std_logic_vector(3 downto 0);
);
end lab1;
architecture up_and_down of lab1 is
signal value_in_ram : unsigned(7 downto 0);
signal clk : std_logic;
signal we : std_logic;
signal value_counter : unsigned(7 downto 0) ;
signal register_counter : unsigned(3 downto 0);
begin
U1: entity work.raminfr port map (
a => register_counter,
di => value_counter,
do => value_in_ram,
clk => clk,
we => we
);
process(clock)
begin
if rising_edge(clock) then
if (key(3)='0' and key(2)='0' and key(1)='1' and key(0)='0') then
value_counter <= value_counter + "1";
elsif (key(3)='0' and key(2)='0' and key(1)='0' and key(0)='1') then
value_counter <= value_counter - "1";
elsif (key(3)='1' and key(2)='0' and key(1)='0' and key(0)='0') then
register_counter<= register_counter + "1";
value_counter <= value_in_ram;
elsif (key(3)='0' and key(2)='1' and key(1)='0' and key(0)='0') then
register_counter<= register_counter - "1";
value_counter <= value_in_ram;
end if;
end if;
end process;
end architecture up_and_down;
The problem is that despite initializing "key" (the buttons) in my test bench, ModelSim still lists the object as "UUUU". Here is the code for my test bench, which is located in a separate file:
library ieee;
use ieee.std_logic_1164.all;
entity DE2_TOP_TEST is
end;
architecture BENCH of DE2_TOP_TEST is
signal KEY : std_logic_vector(3 downto 0);
begin
KEY<="0010";
U1: entity work.DE2_TOP port map (
key=>key,
);
end BENCH;
Anyone know what's wrong?
You use registers in your design. So you need to add a signal to your clock input:
constant tb_clk_period : time := (1 sec) / 10_000_000; -- 10 MHz
signal tb_clk : std_ulogic := '0';
...
-- clock generator
tb_clk <= not tb_clk after tb_clk_period / 2;