koolslash
Junior Member level 3
#if debug
kindly debug the following code if u can:
its about a counter which counts feed_in pulses for 1sec. the clock used as a reference is 50MHz.
kindly debug the following code if u can:
its about a counter which counts feed_in pulses for 1sec. the clock used as a reference is 50MHz.
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
USE IEEE.numeric_std.ALL;
USE ieee.std_logic_unsigned.all;
ENTITY feedback IS
PORT( clk : IN std_logic;
reset : IN std_logic;
enb : IN std_logic;
feed_in : IN std_logic;
feed_out : OUT std_logic_vector(7 DOWNTO 0)
);
END feedback;
ARCHITECTURE rtl OF feedback IS
-- Signals
SIGNAL tcount : std_logic_vector(7 DOWNTO 0);
SIGNAL pcount : std_logic_vector(7 DOWNTO 0);
SIGNAL feed_count : std_logic_vector(7 DOWNTO 0);
SIGNAL Count_out : std_logic_vector(7 DOWNTO 0);
SIGNAL Counter_out1 : std_logic_vector(25 DOWNTO 0);
SIGNAL Count_total : std_logic_vector(7 DOWNTO 0);
BEGIN
--Counter for 1sec time
Counter_process : PROCESS (clk, reset)
BEGIN
IF reset = '1' THEN
Counter_out1 <= (others=> '0');
elsIF clk'event AND clk = '1' THEN
IF Counter_out1 = "10111110101111000010000000" THEN --50M cycles/sec => 50MHz clock
Counter_out1 <= (others=> '0');
ELSE
Counter_out1 <= Counter_out1 + 1;
END IF;
END IF;
END PROCESS Counter_process;
--counter for number of pulses in 1sec
Counter_pulse : PROCESS (feed_in, reset)
BEGIN
IF reset = '1'THEN
pcount <= (others=> '0');
IF Counter_out1 = "10111110101111000010000000" THEN
Count_total <= pcount;
pcount <= (others=> '0');
ELSIF feed_in'event AND feed_in = '1' THEN
pcount <= pcount + 1;
END IF;
END IF;
END PROCESS Counter_pulse;
--incomplete task:scalling the output count with x6.to make: 40 to 240
Count_out <= Count_total;
--final output
feed_out <= Count_out(7 DOWNTO 0);
END rtl;