Guest
I need to implement 2 counters that counts 1's and 0's of an incoming bit stream.
However I have a problem that not even the clock is generated on ModelSim and all the signals
are labeled as 'no data'. Is there a problem in my code or is it related to some configuration or settings?
This is my code;
--bit_counter.vhd
LIBRARY ieee;
-- STD_LOGIC and STD_LOGIC_VECTOR types, and relevant functions
use ieee.std_logic_1164.all;
-- SIGNED and UNSIGNED types, and relevant functions
use ieee.numeric_std.all;
entity bit_counter is
port(Start : in std_logic := '0' ; --was in
Reset : in std_logic := '1';
Clock : in std_logic := '0';
Bit_stream : in std_logic := '0';
Q_H, Q_L : out std_logic_vector (3 downto 0)
);
end entity bit_counter;
architecture RTL of bit_counter is
--type state_type is (IDLE, Bit_is_high, Bit_is_low);
--signal initBitH, initBitL, BitH, BitL : std_logic;
signal cnt_L, cnt_H : integer range 0 to 15;
begin
count: process(Start, Reset, Clock, Bit_stream, cnt_L, cnt_H)
begin
Q_H <= std_logic_vector(to_unsigned(Cnt_H, Q_H'length));
Q_L <= std_logic_vector(to_unsigned(Cnt_L, Q_L'length));
if(Reset = '0') then
cnt_H <= 0;
cnt_L <= 0;
elsif (Start = '1') then
if(rising_edge(Clock)) then
if (Bit_stream = '1') then
cnt_H <= cnt_H + 1;
cnt_L <= cnt_L;
elsif (Bit_stream = '0') then
Cnt_H <= Cnt_H;
Cnt_L <= Cnt_L + 1;
end if;
end if;
end if;
end process;
end architecture RTL;
--bit_counter_test.vhd
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_unsigned.all;
entity bit_counter_test is
end Entity bit_counter_test;
Architecture behavioral of bit_counter_test is
Signal Bit_stream, Clock : std_logic := '0';
Signal Reset_count, Start_count : std_logic := '1';
Signal Q_H, Q_L : std_logic_vector (3 downto 0) := (others => '0');
begin
UUT : entity work.bit_counter
port map (
Bit_stream => Bit_stream,
Start => Start_count,
Reset => Reset_count,
Clock => Clock);
CLK_process
rocess
begin
for C in 30 downto 0 loop
Clock <= NOT Clock after 5ns;
end loop;
end process;
Signals : process
Begin
for I in 30 downto 0 loop
wait for 10 ns;
Start_count <= '1';
Reset_count <= '1';
Bit_stream <= '0';
end loop ;
wait for 10 ns;
for J in 30 downto 0 loop
wait for 10 ns;
Start_count <= '1';
Reset_count <= '1';
Bit_stream <= '1';
end loop ;
wait;
end process;
end Architecture behavioral;
In the past I already managed to simulate combinational logic with model sim so clock wasn't involved. It seams that the problem is I am not using the clock correctly..
However I have a problem that not even the clock is generated on ModelSim and all the signals
are labeled as 'no data'. Is there a problem in my code or is it related to some configuration or settings?
This is my code;
--bit_counter.vhd
LIBRARY ieee;
-- STD_LOGIC and STD_LOGIC_VECTOR types, and relevant functions
use ieee.std_logic_1164.all;
-- SIGNED and UNSIGNED types, and relevant functions
use ieee.numeric_std.all;
entity bit_counter is
port(Start : in std_logic := '0' ; --was in
Reset : in std_logic := '1';
Clock : in std_logic := '0';
Bit_stream : in std_logic := '0';
Q_H, Q_L : out std_logic_vector (3 downto 0)
);
end entity bit_counter;
architecture RTL of bit_counter is
--type state_type is (IDLE, Bit_is_high, Bit_is_low);
--signal initBitH, initBitL, BitH, BitL : std_logic;
signal cnt_L, cnt_H : integer range 0 to 15;
begin
count: process(Start, Reset, Clock, Bit_stream, cnt_L, cnt_H)
begin
Q_H <= std_logic_vector(to_unsigned(Cnt_H, Q_H'length));
Q_L <= std_logic_vector(to_unsigned(Cnt_L, Q_L'length));
if(Reset = '0') then
cnt_H <= 0;
cnt_L <= 0;
elsif (Start = '1') then
if(rising_edge(Clock)) then
if (Bit_stream = '1') then
cnt_H <= cnt_H + 1;
cnt_L <= cnt_L;
elsif (Bit_stream = '0') then
Cnt_H <= Cnt_H;
Cnt_L <= Cnt_L + 1;
end if;
end if;
end if;
end process;
end architecture RTL;
--bit_counter_test.vhd
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_unsigned.all;
entity bit_counter_test is
end Entity bit_counter_test;
Architecture behavioral of bit_counter_test is
Signal Bit_stream, Clock : std_logic := '0';
Signal Reset_count, Start_count : std_logic := '1';
Signal Q_H, Q_L : std_logic_vector (3 downto 0) := (others => '0');
begin
UUT : entity work.bit_counter
port map (
Bit_stream => Bit_stream,
Start => Start_count,
Reset => Reset_count,
Clock => Clock);
CLK_process
begin
for C in 30 downto 0 loop
Clock <= NOT Clock after 5ns;
end loop;
end process;
Signals : process
Begin
for I in 30 downto 0 loop
wait for 10 ns;
Start_count <= '1';
Reset_count <= '1';
Bit_stream <= '0';
end loop ;
wait for 10 ns;
for J in 30 downto 0 loop
wait for 10 ns;
Start_count <= '1';
Reset_count <= '1';
Bit_stream <= '1';
end loop ;
wait;
end process;
end Architecture behavioral;
In the past I already managed to simulate combinational logic with model sim so clock wasn't involved. It seams that the problem is I am not using the clock correctly..