shahulakthar
Member level 2
- Joined
- Oct 13, 2009
- Messages
- 45
- Helped
- 12
- Reputation
- 24
- Reaction score
- 10
- Trophy points
- 1,288
- Location
- Chennai, India
- Activity points
- 1,515
I need to count the external pulse coming on to FPGA.
Total time i take to count pulse is 5 sec.
internal clock is 50mhz.
external pulse duration is around 0.5 sec to 1.5 sec. so i am calculating number of pulses for 5 sec.
last 5sec pulses needs to be updated on 8 bit LED's.
not working as expected. output always shows "11110100" or "00000001"
Here is the VHDL code
Regards,
shahul
Total time i take to count pulse is 5 sec.
internal clock is 50mhz.
external pulse duration is around 0.5 sec to 1.5 sec. so i am calculating number of pulses for 5 sec.
last 5sec pulses needs to be updated on 8 bit LED's.
not working as expected. output always shows "11110100" or "00000001"
Here is the VHDL code
Code:
library IEEE;
use IEEE.std_logic_1164.ALL;
use IEEE.numeric_std.ALL;
entity fcnt is
port (
C : in std_logic;
S : in std_logic;
Q : out unsigned(7 downto 0));
end entity;
architecture RTL of fcnt is
constant MAX_CLK : integer := 250000000;
constant MAX_CNT : integer := 500;
signal count : unsigned(Q'range) := (others => '0');
signal toggle : std_logic := '0';
begin
clk_proc : process (C)
variable cnt_v : natural range 0 to MAX_CLK := 0;
begin
if rising_edge(C) then
if cnt_v = MAX_CLK then
Q <= count;
toggle <= not toggle;
cnt_v := 0;
else
cnt_v := cnt_v + 1;
end if;
end if;
end process;
cnt_proc : process (S, toggle)
variable cnt_v : natural range 0 to MAX_CNT := 0;
variable last_v : std_logic := '0';
begin
if toggle /= last_v then
last_v := toggle;
cnt_v := 0;
elsif rising_edge(S) then
if cnt_v < MAX_CNT then
cnt_v := cnt_v + 1;
end if;
count <= to_unsigned(cnt_v, count'length);
end if;
end process;
end RTL;
Regards,
shahul