Getting initialized value in the waveform - vhdl

Below is the testbench
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity prime_tb is
end prime_tb;
architecture Behavioral of prime_tb is
COMPONENT prime_tb
PORT(
clk : in std_logic;
reset : in std_logic;
seq_in : in std_logic_vector(15 downto 0);
seq_out : out std_logic
);
END COMPONENT;
signal reset : std_logic := '0';
signal clk : std_logic := '0';
signal seq_in : std_logic_vector(15 downto 0);
signal seq_out : std_logic;
constant clk_period : time := 10 ns;
begin
uut: prime_tb PORT MAP (
clk => clk,
reset => reset,
seq_in => seq_in,
seq_out => seq_out
);
clk_process :process
begin
clk <= '0';
wait for clk_period/2;
clk <= '1';
wait for clk_period/2;
end process;
stim_proc: process
begin
seq_in <= "0000000011111111";
wait for clk_period;
seq_in <= "0000000000001111";
wait for clk_period;
wait;
end process;
end Behavioral;
I am new to VHDL and I am writing a function that takes a 16-bit input binary value and determining if it is a prime number. The output is '0' or '1'('1' for true and '0' for false). But when I run the simulation, the waveform I got has uninitialized values. It appears that both of my seq_in and seq_out are uninitialized. See link below.
Error:
Can someone help me to fix it?

You have a typo in your UUT instantiation. You didn't mean this:
COMPONENT prime_tb
PORT(
clk : in std_logic;
reset : in std_logic;
seq_in : in std_logic_vector(15 downto 0);
seq_out : out std_logic
);
END COMPONENT;
and this:
uut: prime_tb PORT MAP (
clk => clk,
reset => reset,
seq_in => seq_in,
seq_out => seq_out
);
You meant this:
COMPONENT prime
PORT(
clk : in std_logic;
reset : in std_logic;
seq_in : in std_logic_vector(15 downto 0);
seq_out : out std_logic
);
END COMPONENT;
and this:
uut: prime PORT MAP (
clk => clk,
reset => reset,
seq_in => seq_in,
seq_out => seq_out
);
BTW: you're not driving the reset input to your UUT.

Related

Sequential element is unused and will be removed from module in vivado

I got the warning "[Synth 8-6014] Unused sequential element MVM_RST_reg was removed. "
I am a little bit confused, because the signal is connected and used
The definition:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use IEEE.math_real.all;
use work.parameters.all;
entity MVM is
port (
EN: IN std_logic;
DIN: IN signed(DATA_WIDTH_IN-1 downto 0);
WEIGHT: IN signed(DATA_WIDTH_IN -1 downto 0);
CLK: IN std_logic;
RST: IN std_logic;
MVM_RESULT: OUT signed(DATA_WIDTH_IN-1 downto 0):= (OTHERS => '0')
);
end entity MVM;
architecture base of MVM is
begin
process(CLK)
variable acc_value : signed(DATA_WIDTH_IN-1 downto 0):= (OTHERS => '0');
begin
IF rising_edge(CLK) then
IF RST='1' THEN
acc_value := (OTHERS => '0'); -- reset accumulated value to 0
ELSIF EN='1' THEN
acc_value := resize((acc_value + WEIGHT* DIN), DATA_WIDTH_IN);
MVM_RESULT <= acc_value;
END IF;
END IF;
END process;
end base;
My component
component MVM is
port (
EN: in std_logic;
DIN: IN signed(DATA_WIDTH_IN-1 downto 0);
WEIGHT: IN signed(DATA_WIDTH_IN-1 downto 0);
CLK: IN std_logic;
RST: IN std_logic;
MVM_RESULT: OUT signed(DATA_WIDTH_IN-1 downto 0)
);
The signal
signal MVM_RST: std_logic;
My instantiation
MVM_UNITS: MVM
port MAP(
EN => MVM_En,
DIN => DIN_Array(i) ,
Weight => WEIGHT_Array(i),
CLK => CLK,
RST => MVM_RST,
MVM_RESULT => MVM_RESULT_ARRAY(i)
);
the usage of the Reset
state_machine: process(Clk) is
begin
if rising_edge(Clk) then
IF RST='1' then
MVM_RST <= '1';
Else
MVM_RST <= '0';
In detail the warning is reffering to the line RST=> MVM_RST of the instantiation
MVM_RST_reg is removed, because you reset acc_value instead of MVM_RESULT. acc_value is a variable and not a signal. This means, you will only get flipflops for acc_value, if there is a situation were you read acc_value before you assign a value to it. If RST=1, then you assign a value to acc_value but you do not read its value. So no flipflop is needed. If RST=0 and EN=1, then you first assign a value and then read it. So again, no flipflop is needed. As there is no flipflop for acc_value build in, you cannot reset any flipflops by MVM_RST. So the MVM_RST_reg is removed.

Quartus Prime Lite Failed to find INSTANCE

I've tryed to run a simulation with ModelSim on Quartus Prime Lite but I've got this error messages:
Error (suppressible): (vsim-SDF-3250) Counter_6_1200mv_85c_vhd_slow.sdo(0): Failed to find INSTANCE '/i1'.
Error (suppressible): (vsim-SDF-3894) : Errors occured in reading and resolving instances from compiled SDF file(s).
Error (suppressible): (vsim-SDF-3250) Counter_6_1200mv_85c_vhd_slow.sdo(0): Failed to find INSTANCE '/i1'
It doesn't matter which code I'm running. The compilation was succesfull and the simulation path is right.
-- The code.
-- ADC reader: reads data from ADXL345
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity g_reader is port (
clk_50: in std_logic; -- 50 MHz clock
reset_n : in std_logic; -- reset signal (active low)
-- SPI interface
CS_N : out std_logic; -- connected to chip select of g sensor
SCLK : out std_logic; -- spi clock
SDIO : inout std_logic; -- spi data (bidirectional)
-- data output
dataX : out std_logic_vector(12 downto 0);
dataY : out std_logic_vector(12 downto 0);
dataZ : out std_logic_vector(12 downto 0)
);
end g_reader;
architecture behavior of g_reader is
signal SCLK_counter : integer := 0; -- starts clock
signal SCLK_1 : std_logic; -- 1 MHz clock
constant half_period : time := 10 ns;
begin
-- SCLK
process(clk_50)
begin
if (falling_edge(clk_50)) then
if (SCLK_counter <= 24) then
SCLK_1 <= '0';
else
SCLK_1 <= '1';
end if;
if (SCLK_counter >= 49) then
SCLK_counter <= 0;
else
SCLK_counter <= SCLK_counter + 1;
end if;
end if;
end process;
CS_N <= '0';
SCLK <= '0';
dataX <= "0000000000000";
dataY <= "0000000000000";
dataZ <= "0000000000000";
end behavior;
The testbench:
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY g_reader_vhd_tst IS
END g_reader_vhd_tst;
ARCHITECTURE g_reader_arch OF g_reader_vhd_tst IS
-- constants
constant half_period : time := 10 ns;
-- signals
signal clk : std_logic := '0';
SIGNAL clk_50 : STD_LOGIC;
SIGNAL CS_N : STD_LOGIC;
SIGNAL dataX : STD_LOGIC_VECTOR(12 DOWNTO 0);
SIGNAL dataY : STD_LOGIC_VECTOR(12 DOWNTO 0);
SIGNAL dataZ : STD_LOGIC_VECTOR(12 DOWNTO 0);
SIGNAL reset_n : STD_LOGIC;
SIGNAL SCLK : STD_LOGIC;
SIGNAL SDIO : STD_LOGIC;
COMPONENT g_reader
PORT (
clk_50 : IN STD_LOGIC;
CS_N : OUT STD_LOGIC;
dataX : OUT STD_LOGIC_VECTOR(12 DOWNTO 0);
dataY : OUT STD_LOGIC_VECTOR(12 DOWNTO 0);
dataZ : OUT STD_LOGIC_VECTOR(12 DOWNTO 0);
reset_n : IN STD_LOGIC;
SCLK : OUT STD_LOGIC;
SDIO : INOUT STD_LOGIC
);
END COMPONENT;
BEGIN
i1 : g_reader
PORT MAP (
-- list connections between master ports and signals
clk_50 => clk_50,
CS_N => CS_N,
dataX => dataX,
dataY => dataY,
dataZ => dataZ,
reset_n => reset_n,
SCLK => SCLK,
SDIO => SDIO
);
init : PROCESS
-- variable declarations
BEGIN
-- code that executes only once
WAIT;
END PROCESS init;
clk_proc : process
begin
clk <= not clk after half_period;
end process clk_proc;
end g_reader_arch;

why does my VHDL testbench give me 'U' for outputs? using 4x1MUX and Dflipflop

I am trying to write code for a device that can shift right, shift left, circle right and circle left. as you can see in this picture.
The Device
so the i wrote code for the 4x1 MUX and DFlipFlop Modules and used them in my main module with port map. and so when i make a testbench, my Outputs are 'U'.
you can see my code down below:
4x1 Multiplexer:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity MUX4x1 is
Port ( in1 : in std_logic; -- mux input1
in2 : in std_logic; -- mux input2
in3 : in std_logic; -- mux input3
in4 : in std_logic; -- mux input4
sel : in std_logic_vector(1 downto 0); -- selection line
dataout : out std_logic); -- output data
end MUX4x1;
architecture Behavioral of MUX4x1 is
begin
-- This process for mux logic
process (sel, in1, in2, in3, in4)
begin
case SEL is
when "00" => dataout <= in1;
when "01" => dataout <= in2;
when "10" => dataout <= in3;
when "11" => dataout <= in4;
when others => dataout <= '0';
end case;
end process;
end Behavioral;
D FlipFlop:
entity Dflipflop is
port
(
clk : in std_logic;
rst : in std_logic;
pre : in std_logic;
ce : in std_logic;
d : in std_logic;
q : out std_logic
);
end Dflipflop;
architecture Behavioral of Dflipflop is
begin
process (clk) is
begin
if rising_edge(clk) then
if (rst='1') then
q <= '0';
elsif (pre='1') then
q <= '1';
elsif (ce='1') then
if (d ='1') then
q <= '1';
elsif (d ='0') then
q<= '0';
end if;
end if;
end if;
end process;
end Behavioral;
Main Module
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Main is
port(
--input: in std_logic_vector(3 downto 0);
s: in std_logic_vector(1 downto 0);
clk: in std_logic;
output0: out std_logic;
output1: out std_logic;
output2: out std_logic;
output3: out std_logic
);
end Main;
architecture Behavioral of Main is
component MUX4x1 is
Port (
in1 : in std_logic; -- mux input1
in2 : in std_logic; -- mux input2
in3 : in std_logic; -- mux input3
in4 : in std_logic; -- mux input4
sel : in std_logic_vector(1 downto 0); -- selection line
dataout : out std_logic); -- output data
end component;
component Dflipflop is
port
(
clk : in std_logic;
rst : in std_logic;
pre : in std_logic;
ce : in std_logic;
d : in std_logic;
q : out std_logic
);
end component;
signal temp: std_logic_vector(3 downto 0);
signal A:std_logic_vector(3 downto 0) := "0010";
begin
MUX1: MUX4x1 port map (A(1),'0',A(1),A(3),s,temp(0));
MUX2: MUX4x1 port map (A(2),A(0),A(3),A(1),s,temp(1));
MUX3: MUX4x1 port map (A(3),A(1),A(3),A(1),s,temp(2));
MUX4: MUX4x1 port map (A(0),A(2),A(0),A(2),s,temp(3));
FF1: Dflipflop port map(clk,'0','0','1',temp(0),A(0));
FF2: Dflipflop port map(clk,'0','0','1',temp(1),A(1));
FF3: Dflipflop port map(clk,'0','0','1',temp(2),A(2));
FF4: Dflipflop port map(clk,'0','0','1',temp(3),A(3));
output0<=A(0);
output1<=A(1);
output2<=A(2);
output3<=A(3);
end Behavioral;
and using this testbench i'm getting 'U's for my outputs:
ENTITY TestBench IS
END TestBench;
ARCHITECTURE behavior OF TestBench IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT Main
PORT(
s : IN std_logic_vector(1 downto 0);
clk : IN std_logic;
output0 : OUT std_logic;
output1 : OUT std_logic;
output2 : OUT std_logic;
output3 : OUT std_logic
);
END COMPONENT;
--Inputs
signal s : std_logic_vector(1 downto 0) := (others => '0');
signal clk : std_logic := '0';
--Outputs
signal output0 : std_logic;
signal output1 : std_logic;
signal output2 : std_logic;
signal output3 : std_logic;
-- Clock period definitions
constant clk_period : time := 10 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: Main PORT MAP (
s => s,
clk => clk,
output0 => output0,
output1 => output1,
output2 => output2,
output3 => output3
);
-- Clock process definitions
clk_process :process
begin
clk <= '0';
wait for clk_period/2;
clk <= '1';
wait for clk_period/2;
end process;
-- Stimulus process
stim_proc: process
begin
-- hold reset state for 100 ns.
wait for 100 ns;
wait for clk_period*10;
-- insert stimulus here
wait;
end process;
END;

Simulation vhdl code in vivado - Uninitialized output

I'm writing TDC based on Vernier method in Vivado. My board is VC707 with virtex 7 core. After I finished writing my vhdl code i started simulation . Unfortunately I'm still learning fpga and vhdl so I stuck with one problem.
At first i wanted to check my my input circuit so i write a simple testbench to simulate. I generate short time interval to check this part of TDC. After i start simulation two of my outputs are uninicialized and other outputs have no sense ( should be high edge but simulation show zeros on the output).
On outputs should be rising edges. This circuit is intended to shape signals for my ring oscillators.
My vhdl desing:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Uklad_WE is
Port ( Start : in STD_LOGIC;
Stop : in STD_LOGIC;
Reset : in STD_LOGIC;
Pulse_st : out STD_LOGIC;
Pulse_sp : out STD_LOGIC;
Encnt_st : out STD_LOGIC;
Encnt_sp : out STD_LOGIC);
end Uklad_WE;
architecture Behavioral of Uklad_WE is
signal dst1_out : std_logic;
signal dst2_out : std_logic;
signal dsp1_out : std_logic;
signal dsp2_out : std_logic;
signal INV_chain_13_o : std_logic;
signal INV_chain_15_o : std_logic;
signal gate_cnt1_o : std_logic;
signal gate_cnt2_o : std_logic;
signal dcnt1_out : std_logic;
signal dcnt2_out : std_logic;
component ffd
port(
D,CLK,R : in STD_LOGIC;
Q: out STD_LOGIC
);
end component;
component ffd_set
port(
D,S,CLK : in STD_LOGIC;
Q : out STD_LOGIC
);
end component;
component INV_chain_15
port(
input : in STD_LOGIC;
output : out STD_LOGIC;
cnt_sig : inout std_logic
);
end component;
component INV_chain_13
port(
input : in STD_LOGIC;
output : out STD_LOGIC;
cnt_sig : inout std_logic
);
end component;
begin
DST1: ffd port map(
D => '1',
CLK => Start,
R => Reset,
Q => dst1_out);
DST2 : ffd_set port map(
D => '0',
CLK => dst1_out,
S => INV_chain_13_o,
Q => dst2_out);
DSP1 : ffd port map(
D => dst1_out,
CLK => Stop,
R => Reset,
Q => dsp1_out);
DSP2 : ffd_set port map(
D => '0',
CLK => dsp1_out,
S => INV_chain_15_o,
Q => dsp2_out);
DCNT1 : ffd port map(
D => '1',
CLK => gate_cnt1_o,
R => Reset,
Q => dcnt1_out);
DCNT2 : ffd port map(
D => '1',
CLK => gate_cnt2_o,
R => Reset,
Q => dcnt2_out);
INV_chain_st : INV_chain_13 port map(
input => dst2_out,
output => INV_chain_13_o,
cnt_sig => gate_cnt1_o);
INV_chain_sp : INV_chain_15 port map(
input => dsp2_out,
output => INV_chain_15_o,
cnt_sig => gate_cnt2_o);
Pulse_st <= dst2_out;
Pulse_sp <= dsp2_out;
Encnt_st <= dcnt1_out;
Encnt_sp <= dcnt2_out;
end Behavioral;
My testbench :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_unsigned.ALL;
entity symulacja_tdc_vo is
end symulacja_tdc_vo;
architecture Behavioral of symulacja_tdc_vo is
component Uklad_WE
Port(
Start : in STD_LOGIC;
Stop : in STD_LOGIC;
Reset : in STD_LOGIC;
Pulse_st : out STD_LOGIC;
Pulse_sp : out STD_LOGIC;
Encnt_st : out STD_LOGIC;
Encnt_sp : out STD_LOGIC);
end component;
--inputs
signal Start : STD_LOGIC := '0';
signal Stop : STD_LOGIC := '0';
signal Reset : STD_LOGIC := '0';
--outputs
signal Pulse_st : STD_LOGIC;
signal Pulse_sp : STD_LOGIC;
signal Encnt_st : STD_LOGIC;
signal Encnt_sp : STD_LOGIC;
begin
--uut
uut: Uklad_WE port map(
Start => Start,
Stop => Stop,
Reset => Reset,
Pulse_st => Pulse_st,
Pulse_sp => Pulse_sp,
Encnt_st => Encnt_st,
Encnt_sp => Encnt_sp);
-- stimuluis process
stim_proc1: process
begin
Start <= not Start after 5 ps;
wait for 500 ps;
end process;
stim_proc2: process
begin
Stop <= not Stop after 50 ps;
wait for 500 ps;
end process;
stim_proc3: process
begin
wait for 250 ps;
Reset <= not Reset;
wait for 500 ps;
end process;
end Behavioral;
Components code :
ffd - ffd with reset
library ieee;
use ieee.std_logic_1164.all;
entity ffd is
port (
D, CLK, R : in std_logic;
Q : out std_logic );
end ffd;
architecture Bech of ffd is
begin
process( CLK, R )
begin
if R = '0' then
Q <= '0';
elsif rising_edge(CLK) then
Q <= D;
end if;
end process;
end Bech;
ffd_set - ffd with set
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity ffd_set is
port (
D, CLK, S : in std_logic;
Q : out std_logic );
end ffd_set;
architecture Bech of ffd_set is
begin
process( CLK, S )
begin
if S = '0' then
Q <= '1';
elsif rising_edge(CLK) then
Q <= D;
end if;
end process;
end Bech;
INV_chain_13 - inverters chain
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity INV_chain_13 is
Port ( input : in STD_LOGIC;
output : out STD_LOGIC;
cnt_sig : inout STD_LOGIC);
end INV_chain_13;
architecture Behavioral of INV_chain_13 is
signal gate_o : std_logic_vector(12 downto 0);
begin
gate_o(0) <= input;
inv_g_chain : for i in 1 to gate_o'high generate
gate_o(i) <= not gate_o(i-1);
end generate;
gate_o(1) <= cnt_sig;
output <= gate_o(12);
end Behavioral;
INV_chain_15 - also inverters chain, only number of inv is diffrent
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity INV_chain_15 is
Port ( input : in STD_LOGIC;
output : out STD_LOGIC;
cnt_sig : inout STD_LOGIC);
end INV_chain_15;
architecture Behavioral of INV_chain_15 is
signal gate_o : std_logic_vector(14 downto 0);
begin
gate_o(0) <= input;
inv_g_chain : for i in 1 to gate_o'high generate
gate_o(i) <= not gate_o(i-1);
end generate;
gate_o(1) <= cnt_sig;
output <= gate_o(14);
end Behavioral;
RTL Analysis
This is schematic of my design
RTL form Vivado screenshot
Simulation
And major problem :
Simulation screenshot
Maybe it's vhdl code issue, I don't know every rule of vhdl programming yet, I hope someone with better experience can help me.
I think there is some problem with set and reset in ffd . I try many options but nothing helped.
First of all: you're learning VHDL, and you have a Virtex-7??? I'm programming VHDL for 15 years now, but often only work with spartans... Virtex is just too expensive. Restectp.
But anyhow
inv_g_chain : for i in 1 to gate_o'high generate
gate_o(i) <= not gate_o(i-1);
end generate;
What are you trying to do here? I expect you want to use inverters to get some delay? Only, in VHDL concurrent assignment is instantaneous, so it does not work. You should add the delay manually. E.g.:
gate_o(i) <= not gate_o(i-1) after 10 ns;
by the way, do you know that you could use generics, more links to have a variable inverter delay chain length? Then you could combine INV_chain_13 and INV_chain_15 into one entity.
Then you have multiple drivers for the same signal:
gate_o(1) <= not gate_o(0);
and
gate_o(1) <= cnt_sig;
Multiple drivers does not work properly. And what's up with cnt_sig being of the inout type? <= is not a bidirectional assignment. VHDL is not good at bidirectional assignments, so try a different approach.
You are trying to build an asynchronous system. It is possible, but quite difficult. Please consider making something synchronous first, to get some experience.... Now you're trying to do F1 at your first driving lesson.

Shift Right Register-ParallelLoad

I have to create an n bit shift right register(used 4 bits here) with parallel load. For this purpose i used a Mux 2 in 1 and d flip flops. If load is '1' then the register is loaded with a value(DataIn), otherwise the register starts to shift.
The code for the Multiplexer is:
entity Mux2in1onebit is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Q : out STD_LOGIC;
sel : in STD_LOGIC);
end Mux2in1onebit;
architecture Behavioral of Mux2in1onebit is
begin
Q <= A when sel = '0' else
B;
end Behavioral
The code for the flip flop:
entity FlipFlop is
Port ( Din : in STD_LOGIC;
Q : out STD_LOGIC;
Enable : in STD_LOGIC;
Clk : in STD_LOGIC;
Reset : in STD_LOGIC);
end FlipFlop;
architecture Behavioral of FlipFlop is
signal Qtemp : std_logic;
begin
process(clk)
begin
if(rising_edge(clk)) then
if(reset = '1') then
Qtemp <= '0';
else
if (enable = '1') then
Qtemp <= Din;
else
Qtemp <= Qtemp;
end if;
end if;
end if;
end process ;
Q <= Qtemp;
end Behavioral;
Now in a top level module i have connected the muxs and the flip flops as following:
entity ShiftRegister is
Port ( DataIn : in STD_LOGIC_VECTOR (3 downto 0);
DataOut : out STD_LOGIC_VECTOR (3 downto 0);
Enable : in STD_LOGIC;
Load :in STD_LOGIC;
BitIn : in STD_LOGIC;
Bitout : out STD_LOGIC;
Reset : in STD_LOGIC;
Clk : in STD_LOGIC);
end ShiftRegister;
architecture Structural of ShiftRegister is
COMPONENT FlipFlop
PORT(
Din : IN std_logic;
Enable : IN std_logic;
Clk : IN std_logic;
Reset : IN std_logic;
Q : OUT std_logic
);
END COMPONENT;
COMPONENT Mux2in1onebit
PORT(
A : IN std_logic;
B : IN std_logic;
sel : IN std_logic;
Q : OUT std_logic
);
END COMPONENT;
signal sigdin, sigq : std_logic_vector(3 downto 0);
begin
MBIT3: Mux2in1onebit PORT MAP(
A => BitIn,
B => DataIn(3),
Q => sigdin(3),
sel => Load
);
BIT3: FlipFlop PORT MAP(
Din => sigdin(3),
Q => sigq(3),
Enable => Enable,
Clk => Clk,
Reset => Reset
);
MBIT2: Mux2in1onebit PORT MAP(
A => sigq(3),
B => DataIn(2),
Q => sigdin(2),
sel => Load
);
BIT2: FlipFlop PORT MAP(
Din => sigdin(2),
Q => sigq(2),
Enable => Enable,
Clk => Clk,
Reset => Reset
);
MBIT1: Mux2in1onebit PORT MAP(
A => sigq(2),
B => DataIn(1),
Q => sigdin(1),
sel => Load
);
BIT1: FlipFlop PORT MAP(
Din => sigdin(1),
Q => sigq(1),
Enable => Enable,
Clk => Clk,
Reset => Reset
);
MBIT0: Mux2in1onebit PORT MAP(
A => sigq(1),
B => DataIn(0),
Q => sigdin(0),
sel => Load
);
BIT0: FlipFlop PORT MAP(
Din => sigdin(0),
Q => sigq(0),
Enable => Enable,
Clk => Clk,
Reset => Reset
);
BitOut <= sigq(0);
DataOut <= sigdin;
end Structural;
Now when i simulate the above code, for reset = '1' the flip flops are set to 0 and when load = '1' then the DataIn is loaded, as expected. But when enable = '1' the register does not shift, but i get "0000" as a result. Thanks.
Your question isn't quite a Minimal, Complete, and Verifiable example, missing the stimuli and actual results.
All three entity and architecture pairs were missing context clauses (library ieee; use ieee.std_logic_1164.all;) and the architecture for Mux2in1onebit was missing a semicolon after end Behavioral.
After fixing those I wrote a simple testbench:
library ieee;
use ieee.std_logic_1164.all;
entity sr_tb is
end entity;
architecture fum of sr_tb is
signal datain: std_logic_vector (3 downto 0) := "1011"; -- load value
signal dataout: std_logic_vector (3 downto 0);
signal enable: std_logic := '0';
signal load: std_logic := '0';
signal bitin: std_logic;
signal bitout: std_logic;
signal reset: std_logic := '0';
signal clk: std_logic := '0';
begin
DUT:
entity work.shiftregister
port map (
datain => datain,
dataout => dataout,
enable => enable,
load => load,
bitin => bitin,
bitout => bitout,
reset => reset,
clk => clk
);
CLOCK:
process
begin
wait for 5 ns;
clk <= not clk;
if now > 160 ns then
wait;
end if;
end process;
STIMULI:
process
begin
wait for 6 ns;
reset <= '0';
wait for 10 ns;
reset <= '1';
wait for 10 ns;
reset <= '0';
wait for 10 ns;
load <= '1';
enable <= '1';
wait for 10 ns;
load <= '0';
enable <= '0';
wait for 10 ns;
bitin <= '0';
wait for 10 ns;
enable <= '1';
wait for 10 ns;
bitin <= '1';
wait for 10 ns;
bitin <= '0';
wait for 10 ns;
wait for 10 ns;
bitin <= '1';
wait for 10 ns;
wait;
end process;
end architecture;
And that produced:
Which shows sigq outputs of the four flip flops are correct and points out DataOut should be assigned from sigq instead of sigdin:
dataout <= sigdin; -- should be sigq
end architecture structural;
If you follow sigq(0) in the waveform you'll see it's values are consisted with the stimuli.
From your comment to your question you were also missing Enable being a '1' when loading.

Resources