VHDL MUX Test Bench Issue - vhdl

I'm trying to learn VHDL through P. Ashenden's book: Designer's Guide to VHDL. Chapter one's exercise 10 asks you to write 2-to-1 (I'm assuming 1 bit wide) MUX in VHDL and simulate it. I apologize in advance for being a complete noob. This is my first VHDL code.
My MUX didn't produce any errors or warnings in synthesis. My test bench doesn't produce errors or warnings, either. However, the simulation comes up completely blank, except for the names of the signals.
I've tried looking at a multitude of other MUX examples online (as well as a bench test example from the book), all of which gave errors when I tried sythesizing them, so I wasn't confident enough to use them as guides and didn't get much out of them. I'm not sure what I'm doing wrong here. I'd include an image of the simulation, but I don't have enough rep points :(
Also, I realize that a good MUX should also have cases for when it receives no select input/high impedance values, ect.. In this case, I'm just trying to get the toy model working.
The MUX code is:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity MUXtop is
Port (a, b, sel: in bit;
z: out bit);
end MUXtop;
architecture behav of MUXtop is
begin
choose: process is
begin
if sel = '0' then
z <= b;
else
z <= a;
end if;
end process choose;
end architecture behav;
The test bench code is:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY MUXtest IS
END MUXtest;
ARCHITECTURE behavior OF MUXtest IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT MUXtop
PORT(
a : IN bit;
b : IN bit;
sel : IN bit;
z : OUT bit
);
END COMPONENT MUXtop;
--Inputs
signal a : bit := '0';
signal b : bit := '0';
signal sel : bit := '0';
--Outputs
signal z : bit;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: MUXtop PORT MAP (
a => a,
b => b,
sel => sel,
z => z
);
-- Stimulus process
stimulus: process
begin
wait for 10 ns;
a <= '1';
wait for 10 ns;
sel <= '1';
wait for 10 ns;
b <= '1';
wait;
end process stimulus;
END architecture behavior;

You don't need a use clause for package std_logic_1164 when using type bit (declared in package standard).
Your process statement choose in MUXtop has no sensitivity clause which cause the process to continually execute in simulation. (It won't do anything until you trip over a delta cycle iteration limit which might be set to infinity).
I added a sensitivity list, commented out the superfluous use clauses in the two design units and added some more stimulus steps as well as a final wait for 10 ns; to allow the last action to be seen in your testbench:
library IEEE;
-- use IEEE.STD_LOGIC_1164.ALL;
entity MUXtop is
Port (a, b, sel: in bit;
z: out bit);
end MUXtop;
architecture behav of MUXtop is
begin
choose: process (a, b, sel) -- is
begin
if sel = '0' then
z <= b;
else
z <= a;
end if;
end process choose;
end architecture behav;
LIBRARY ieee;
-- USE ieee.std_logic_1164.ALL;
ENTITY MUXtest IS
END MUXtest;
ARCHITECTURE behavior OF MUXtest IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT MUXtop
PORT(
a : IN bit;
b : IN bit;
sel : IN bit;
z : OUT bit
);
END COMPONENT MUXtop;
--Inputs
signal a : bit := '0';
signal b : bit := '0';
signal sel : bit := '0';
--Outputs
signal z : bit;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: MUXtop PORT MAP (
a => a,
b => b,
sel => sel,
z => z
);
-- Stimulus process
stimulus: process
begin
wait for 10 ns;
a <= '1';
wait for 10 ns;
sel <= '1';
wait for 10 ns;
sel <= '0'; -- added
wait for 10 ns; -- added
b <= '1';
wait for 10 ns; -- added
wait;
end process stimulus;
END architecture behavior;
And that gives:
(clickable)

Related

Entity has no architecture problem in Modelsim

I'm new to FPGA design using VHDL and I'm stucked in a problem of testbench simulation: each time I try to simulate my model (which testbench was given by the testbench writer) I get the following error that's driving me crazy:
Error: (vsim-3173) Entity >'C:/intelFPGA_lite/progetto_dsp/simulation/modelsim/rtl_work.progetto_dsp_top_vhd_t>st' has no architecture.
My model is a simple Phase Frequency Detector (PFD) and all I'd like is to simulate its behavior at different input signals.
Following I post my testbench code, the only thing that I changed from the auto-generated code is the addition of the A and B signals (which I made like clock signals with different frequency).
-- Generated on "05/02/2021 16:58:30"
-- Vhdl Test Bench template for design : progetto_dsp_top
--
-- Simulation tool : ModelSim-Altera (VHDL)
--
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY progetto_dsp_top_vhd_tst IS
END progetto_dsp_top_vhd_tst;
ARCHITECTURE progetto_dsp_top_arch OF progetto_dsp_top_vhd_tst IS
-- constants
constant period_A : time := 10 ps;
constant period_B : time := 20 ps;
-- signals
SIGNAL A : STD_LOGIC := '0';
SIGNAL B : STD_LOGIC := '0';
SIGNAL High : STD_LOGIC : '1';
SIGNAL QA : STD_LOGIC;
SIGNAL QB : STD_LOGIC;
COMPONENT progetto_dsp_top
PORT (
A : IN STD_LOGIC;
B : IN STD_LOGIC;
High : IN STD_LOGIC;
QA : OUT STD_LOGIC;
QB : OUT STD_LOGIC
);
END COMPONENT;
BEGIN
--signal A generation
process
begin
A <= '1';
wait for period_A/2;
A <= '0';
wait for period_A/2;
if end_sim_s = true then
wait; -- end of simulation
end if;
end process;
signal B generation
process
begin
B <= '1';
wait for period_B/2;
B <= '0';
wait for period_B/2;
if end_sim_s = true then
wait; -- end of simulation
end if;
end process;
i1 : progetto_dsp_top
PORT MAP (
-- list connections between master ports and signals
A => A,
B => B,
High => High,
QA => QA,
QB => QB
);
init : PROCESS
-- variable declarations
BEGIN
-- code that executes only once
WAIT;
END PROCESS init;
always : PROCESS
-- optional sensitivity list
-- ( )
-- variable declarations
BEGIN
-- code executes for every event on sensitivity list
WAIT;
END PROCESS always;
END progetto_dsp_top_arch;

My VHDL code compile but the RTL Simulation doesn't run

I am somewhat new to VHDL and am trying to create a simple code for a Flip Flop D. My code compiles correctly, however when I run my Testbench tb_FlipFlopD in ModelSim Altera, the program opens but there's no wave, and I don't have the option to add it either.
The bug is problaby in my Testbench.
My Top-level identity code FlipFlopD:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity FlipFlopD is
port( clock: in std_logic;
D: in std_logic;
Q: out std_logic
);
end FlipFlopD;
architecture RTL of FlipFlopD is
begin
Q <= D when clock = '1' and clock'event;
end RTL;
My Testbench tb_FlipFlopD:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity tb_FlipFlopD is
end tb_FlipFlopD;
architecture teste of tb_FlipFlopD is
component FlipFlopD is
port (
clock : in std_logic;
D : in std_logic;
Q : out std_logic
);
end component;
signal I: std_logic;
signal O: std_logic;
signal C: std_logic := '0';
constant clk_period : time := 1 ns;
begin
instancia_FlipFlopD: FlipFlopD port map( D => I, Q => O, clock => C);
I <= '0', '1' after 1 ns, '1' after 2 ns, '0' after 3 ns, '1' after 4 ns;
clk_process : process
begin
C <= '0';
wait for clk_period/2;
C <= '1';
wait for clk_period/2;
end process;
end teste;
Your problem is that you simulation runs, but never stops; it just keeps on running forever.
Any VHDL (or Verilog) simulation will keep running if there is still stuff to do. This process:
clk_process : process
begin
C <= '0';
wait for clk_period/2;
C <= '1';
wait for clk_period/2;
end process;
generates an event (a change) on the the signal C every clk_period/2. Forever. To cure this, you need to put something in to stop this, eg:
clk_process : process
begin
while not STOP loop
C <= '0';
wait for clk_period/2;
C <= '1';
wait for clk_period/2;
end loop;
wait;
end process;
The wait; at the end of the process, waits forever. Signal STOP is a boolean:
signal STOP : boolean := false;
Then you need something like this to drive signal STOP:
STOP <= false, true after 10 ns;

VHDL Warning: (vcom-1263) Configuration specification "all : bcd" applies to no component instantiation statements

I have been stuck with this problem for a while. I would be really grateful if someone is able help. Have gone through most of the code repeatedly without any solution. There are sets of codes in use; this bcd counter is used further in the rest of my project. I have added the necessary codes below:
BCD counter for 1 digit:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.NUMERIC_STD.ALL;
USE WORK.mypackage_p.ALL;
ENTITY bcd_e IS
PORT(
res_i, clk_i, enable_i, counter_res_i : IN STD_LOGIC;
bcd_o : OUT STD_LOGIC_VECTOR(bcd_width_c-1 DOWNTO 0);
carry_o : OUT STD_LOGIC
);
END bcd_e;
ARCHITECTURE bcd_a OF bcd_e IS
SIGNAL count_s : INTEGER RANGE bcd_cnt_c DOWNTO 0;
BEGIN
PROCESS(res_i, clk_i)
BEGIN
IF (res_i = '1') THEN
count_s <= 0;
ELSIF (clk_i = '1' AND clk_i'EVENT) THEN
IF (enable_i = '1') THEN
IF(count_s >= bcd_cnt_c) THEN
count_s <= 0;
ELSE
count_s <= count_s + 1;
END IF;
END IF;
IF (counter_res_i = '1') THEN
count_s <= 0;
END IF;
END IF;
END PROCESS;
bcd_o <= STD_LOGIC_VECTOR(to_unsigned(count_s, bcd_width_c));
carry_o <= '1' WHEN (count_s = bcd_cnt_c) ELSE '0';
END bcd_a;
8 digit BCD using the above bcd counter to create 8 digits
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.NUMERIC_STD.ALL;
USE WORK.mypackage_p.ALL;
ENTITY bcd_8counter_e IS
PORT(
res_i, clk_i, enable_i, counter_res_i : IN STD_LOGIC;
bcd_array_o : OUT bcd_array_t
);
END bcd_8counter_e;
ARCHITECTURE bcd_8counter_a OF bcd_8counter_e IS
COMPONENT bcd
PORT(
res_i, clk_i, enable_i, counter_res_i : IN STD_LOGIC;
bcd_o : OUT STD_LOGIC_VECTOR(bcd_width_c-1 DOWNTO 0);
carry_o : OUT STD_LOGIC
);
END COMPONENT;
SIGNAL bcd_array_s : bcd_array_t;
SIGNAL enable_s : STD_LOGIC_VECTOR(no_of_digits_c-1 DOWNTO 0);
SIGNAL carry_s : STD_LOGIC_VECTOR(no_of_digits_c-1 DOWNTO 0);
FOR ALL : bcd USE ENTITY WORK.bcd_e (bcd_a);
BEGIN
carry_s(0) <= enable_i;
gen_carry : FOR i IN 1 TO (no_of_digits_c-1) GENERATE
carry_s(i) <= carry_s((i-1)) AND enable_s((i-1));
END GENERATE gen_carry;
gen_bcd : FOR i IN 0 TO (no_of_digits_c-1) GENERATE
digitx : bcd PORT MAP(res_i, clk_i, carry_s(i), counter_res_i, bcd_array_s(i), enable_s(i));
END GENERATE gen_bcd;
bcd_array_o <= bcd_array_s
END bcd_8counter_a;
My package file for the constants:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.NUMERIC_STD.ALL;
PACKAGE mypackage_p IS
CONSTANT freq_20k_c : INTEGER := 2500;
CONSTANT bcd_cnt_c : INTEGER := 9;
CONSTANT bcd_width_c : INTEGER := 4;
CONSTANT no_of_digits_c : INTEGER := 8;
TYPE bcd_array_t IS ARRAY(7 DOWNTO 0) OF STD_LOGIC_VECTOR(3 DOWNTO 0);
END PACKAGE;
I keep getting the following warning:
Warning: /home/stud/mr-131416/Desktop/VHDL_Project_Latest/src/bcd_counter8_a.vhd(15): (vcom-1263) Configuration specification "all : bcd" applies to no component instantiation statements.
The code does not pass test/simulation of a test-bench because of this warning. Help would be really appreciated.
It's a matter of scope. A component configuration configures a component instantiation. The generate statement produces a block statement (or nested block statements when a port map is supplied).
A block statement (for an internal or external block) use a block configuration which is only found in a configuration declaration.
Binding indications are not hierarchical, without the ability to reach down into a block to specify a component instantiation you can either use a configuration declaration or move the configuration specification:
-- for all : bcd use entity work.bcd_e (bcd_a);
begin
carry_s(0) <= enable_i;
gen_carry :
for i in 1 to (no_of_digits_c-1) generate
carry_s(i) <= carry_s((i-1)) and enable_s((i-1));
end generate gen_carry;
gen_bcd :
for i in 0 to (no_of_digits_c-1) generate
for all: bcd use entity work.bcd_e (bcd_a);
begin
digitx : bcd port map (res_i, clk_i, carry_s(i),
counter_res_i, bcd_array_s(i), enable_s(i));
end generate gen_bcd;
bcd_array_o <= bcd_array_s; -- CHANGED WAS MISSING SEMICOLON
end bcd_8counter_a;
Note the missing semicolon on the assignment statement for bcd_array_o has been added.
With these changes your design analyzes and elaborates without warnings.
You could note not all synthesis tools support configuration declarations while most support configuration specifications.
See IEEE Std 1076-2008 7.3 Configuration specification, 3.4 Configuration declarations, 3.4.2 Block configurations
The failure to simulate or synthesize would be because the distx component instantiations are unbound because there isn't a bcd entity found in the working directory.
Writing a simple testbench that does not invoke the synchronous reset, uses a clock with a 10 ns period and runs for 10 ms:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.mypackage_p.all;
entity tb is
end entity;
architecture foo of tb is
signal reset: std_logic; -- '1' for RESET
signal clk: std_logic := '0';
signal en: std_logic; -- '1' for ENABLE
signal syn_reset: std_logic; -- '1' for SYNCHRONOUS RESET
signal bcd_array: bcd_array_t;
begin
DUT:
entity work.bcd_8counter_e
port map (
res_i => reset,
clk_i => clk,
enable_i => en,
counter_res_i => syn_reset,
bcd_array_o => bcd_array
);
CLOCK:
process
begin
wait for 5 ns;
clk <= not clk;
if now > 10 ms then
wait;
end if;
end process;
STIMULI:
process
begin
wait for 10 ns;
reset <= '0';
en <= '0';
syn_reset <= '0';
wait for 10 ns;
reset <= '1';
wait for 20 ns;
reset <= '0';
wait for 20 ns;
en <= '1';
wait;
end process;
end architecture;
Shows that the counter depends on enable and shows that the first 6 digits work:

Why my VHDL code for generating a VGA signal doesn't work

I have been going crazy trying to make it work but nothing been on this for the past 6 hours and still didn't solve it :/
so this the top module
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 Test is
Port ( CLKI : in STD_LOGIC;
HSO : out STD_LOGIC;
VSO : out STD_LOGIC;
RO,GO,BO : out STD_LOGIC);
end Test;
architecture Behavioral of Test is
component CLK_25Mhz_Divider
Port ( CLK : in STD_LOGIC;
CLK_OUT : out STD_LOGIC);
end component;
component VGA_Sync
Port ( CLK : in STD_LOGIC;
HS : out STD_LOGIC;
VS : out STD_LOGIC;
R,G,B : out STD_LOGIC);
end component;
signal CLKBE: STD_LOGIC;
begin
CLK_Divider_1: CLK_25Mhz_Divider port map ( CLK => CLKI,
CLK_OUT => CLKBE);
VGA_S1: VGA_Sync port map ( CLK => CLKBE,
HS => HSO,
VS => VSO,
R => RO,
G => GO,
B => BO );
end Behavioral;
the clock divider
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 CLK_25MHz_Divider is
Port ( CLK : in STD_LOGIC;
CLK_OUT : out STD_LOGIC);
end CLK_25MHz_Divider;
architecture Behavioral of CLK_25MHz_Divider is
BEGIN
PROCESS(CLK)
VARIABLE COUNT : INTEGER:=0;
VARIABLE TEMP : STD_LOGIC:='0';
BEGIN
IF RISING_EDGE(CLK)THEN
COUNT:=COUNT+1;
IF COUNT=2 THEN
TEMP:=NOT TEMP;
COUNT:=0;
END IF;
END IF;
CLK_OUT<=TEMP;
END PROCESS;
end Behavioral;
The VGA signal generation module
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 VGA_Sync is
Port ( CLK : in STD_LOGIC;
HS : out STD_LOGIC;
VS : out STD_LOGIC;
R,G,B : out STD_LOGIC);
end VGA_Sync;
architecture Behavioral of VGA_Sync is
begin
process(CLK)
Variable countH : Integer := 0;
Variable countV : Integer := 0;
begin
if (CLK'EVENT and CLK = '1') then
if countH < 800 then
countH := countH + 1;
else
countH := 0;
if countV < 500 then
countV := countV + 1;
else
countV := 0;
end if;
end if;
if countH >= 16 and countH < 112 then
HS <= '0';
else
HS <= '1';
end if;
if countV >= 10 and countV < 12 then
VS <= '0';
else
VS <= '1';
end if;
if (countH < 160) or (countV < 45) then
R <= '0';
G <= '0';
B <= '0';
else
R <= '1';
G <= '0';
B <= '1';
end if;
end if;
end process;
end Behavioral;
so tell me your thoughts on what is wrong with the code
Because you haven't actually describe the problem and because I had a testbench for a 25 MHz clocked vga generator that only required changing the type for r, g and b, I ran you sync_vga against the testbench:
library ieee;
use ieee.std_logic_1164.all;
entity vga_sync_tb is
end entity;
architecture foo of vga_sync_tb is
signal clk: std_logic := '0';
signal hs: std_logic;
signal vs: std_logic;
signal r,g,b: std_logic;
begin
DUT:
entity work.vga_sync
port map (
clk => clk,
hs => hs,
vs => vs,
r => r,
g => g,
b => b
);
CLOCK:
process
begin
wait for 20 ns; -- clock period 25 MHz = 40 ns;
clk <= not clk;
if now > 20 ms then -- one frame time plus a bit
wait;
end if;
end process;
end architecture;
It gave a vertical sync rate around 60 Hz:
Zooming in and measuring between two HS edges shows a horizontal rate of around 31.17 KHz.
You have horizontal and vertical blanking intervals and your R, G, and B does what your code says.
That sort of leaves the clock divider or something platform related.
Because a testbench for the clock is simple:
library ieee;
use ieee.std_logic_1164.all;
entity clock_tb is
end entity;
architecture foo of clock_tb is
signal clk: std_logic := '0';
signal clk25: std_logic;
begin
DUT:
entity work.clk_25mhz_divider
port map (
clk => clk,
clk_out => clk25
);
CLOCK:
process
begin
wait for 10 ns; -- half the period of 50 MHz
clk <= not clk;
if now > 130 ns then
wait;
end if;
end process;
end architecture;
It demonstrates Martin Zabel's answer:
That your divide by two actually divides by four. giving a period of 80 ns (12.5 MHz).
This demonstrates the usefulness of simulation and in simulation it can also be helpful to use signals instead of variables which have no history. Variables don't have a projected output waveform and he simulator has to attach extra code to display them in a waveform.
The simulation performance increase using variables instead of signals is traded for the ability to display them and there is no interesting distinction in synthesis.
From comments below question:
at that resolution i should use 25Mhz so i using the onboard clock
that's 50 Mhz and dividing it using the Clock divider module. –
Mostafa
Your clock divider divides the input frequency by 4 instead of 2. You toggle TEMP every two cycles of CLK which is CLKI of the top module. So a full cycle of CLK_OUT takes 4 cycles of the input clock.
To divide by two, you must toggle TEMP every clock cycle of the input clock:
architecture Behavioral of CLK_25MHz_Divider is
BEGIN
PROCESS(CLK)
VARIABLE TEMP : STD_LOGIC:='0';
BEGIN
IF RISING_EDGE(CLK)THEN
TEMP:=NOT TEMP;
END IF;
CLK_OUT<=TEMP;
END PROCESS;
end Behavioral;
Starting with TEMP = '0', it toggles to '1' at the first rising edge of CLK. At the second rising edge, TEMP toggles to '0', and at the third rising edge back to '1'. The duration between the first and third rising-edge of the 50 MHz input clock is 40 ns, which makes a frequency of 25 MHz for the output clock.

VHDL simulation won't run

I have just picked up The Designer's Guide to VHDL and I am working through the exercises in the first chapter. I ran into an issue with my 2 bit multiplexer that I don't understand.
The code for my multiplexer:
library ieee;
use ieee.std_logic_1164.all;
entity multi2 is
port
(
a,b : in bit;
sel : in boolean;
z : out bit
);
end multi2;
architecture behave of multi2 is
begin
storage : process is
variable stored_d0 : bit;
begin
wait for 1 ns;
if sel then
z <= a;
else
z <= b;
end if;
end process storage;
end architecture behave;
I can't figure out why I need the "wait for 1 ns;" line. If I move it to below the "end if" line the simulation won't work and I won't get my .vcd output from GHDL. Without the wait line, or it being in the wrong spot gives me an error in my vcd file about beginning and end time being the same.
Do I need wait statements in my process in order to work?
My test bench code is below:
library ieee;
use ieee.std_logic_1164.all;
entity multi2_tb is
end multi2_tb;
architecture test of multi2_tb is
component multi2
port
(
a,b : in bit;
sel : in boolean;
z : out bit
);
end component;
signal a,b : bit;
signal sel : boolean;
signal z : bit;
begin
multiplexer2: multi2 port map (a => a, b => b, sel => sel, z => z);
process begin
a <= '0';
b <= '1';
sel <= false;
wait for 3 ns;
a <= '0';
b <= '1';
sel <= true;
wait for 3 ns;
a <= '0';
b <= '1';
sel <= false;
wait for 3 ns;
assert false report "Reached end of test";
wait;
end process;
end test;

Resources