ahmed saeed
Newbie level 3
- Joined
- May 13, 2012
- Messages
- 3
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,318
Hi,
I'm trying to write a VHDL code for frequency counter count 2 seconds ,I using Altera board DE2 frequency 27 MHz. I need a 2second count as the output of clock divider.
I write the code but I'm not sure if is right or mot so please Can you verify and correct my code?
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity two_sec_cnt is
Port (
clk : in std_logic;
enl : in std_logic;
second : out std_logic
);
end two_sec_cnt;
architecture Timer of two_sec_cnt is
constant max_count : natural := 54000000;
-- I used 27MHz clock
begin
process (clk, enl)
variable count : natural range 0 to max_count;
begin
if (enl = '0') then
count := 0;
second <= '1';
elsif rising_edge(clk) then
if count < (max_count/2)-1 then
second <='1';
count := count + 1;
elsif count < max_count-1 then
second <='0';
count := count + 1;
else
count := 0;
second <='1';
end if;
end if;
end process;
end Timer;
I'm trying to write a VHDL code for frequency counter count 2 seconds ,I using Altera board DE2 frequency 27 MHz. I need a 2second count as the output of clock divider.
I write the code but I'm not sure if is right or mot so please Can you verify and correct my code?
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity two_sec_cnt is
Port (
clk : in std_logic;
enl : in std_logic;
second : out std_logic
);
end two_sec_cnt;
architecture Timer of two_sec_cnt is
constant max_count : natural := 54000000;
-- I used 27MHz clock
begin
process (clk, enl)
variable count : natural range 0 to max_count;
begin
if (enl = '0') then
count := 0;
second <= '1';
elsif rising_edge(clk) then
if count < (max_count/2)-1 then
second <='1';
count := count + 1;
elsif count < max_count-1 then
second <='0';
count := count + 1;
else
count := 0;
second <='1';
end if;
end if;
end process;
end Timer;