Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] beginner in vhdl::code for frequency counter

Status
Not open for further replies.

devika v kurup

Newbie level 6
Joined
May 23, 2011
Messages
11
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,303
Location
India/Kerala
Activity points
1,383
Hai,
I'm a beginner in VHDL coding and trying to write a code for frequency counter consisting of a clock divider ,count gate (AND gate), counter. I need a 1second clock as the output of clock divider. ise simulator is not responding while i create a 1second test bench. Could you help me to code the blocks?
THANK YOU.
 

Here is my code.


Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
 
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
 
entity clk_div is
    Port ( clk1 : in  STD_LOGIC;
           rst1 : in  STD_LOGIC;
           q1 : out  STD_LOGIC);
end clk_div;
 
architecture Behavioral of clk_div is
signal count:integer:=1;
begin
process(rst1,clk1)
begin
if(rst1='0')then
count<=0;
elsif(clk1'event and clk1='1')then
count<=count+1;
if(count>1000)then
count<=0;
elsif(count<=500)then
q1<='0';
elsif(count<=1000)then
q1<='1';
end if;
end if;
end process;
end Behavioral;



But i cant select second (s) for initial test bench lenght.
thanks for your valuable time.
 
Last edited by a moderator:

If you are using normal clock frequencies it will take a very long time to simulate one second.
Use a shorter time for simulation and debugging.
When you have it working you can build it for 1 second and test it in a real FPGA.
 
I made a test bench of 1000ns instead 1s. Now it is working and counts all the events in the unknown input. But i want the frequncy of unknown input. Clock frequncy=50MHz,ie 20ns, clk divider output frequency=1MHz ie, 1000ns. Can you verify and correct my code?
Code:
CLOCK DIVIDER
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity clk_div is
    Port ( clk1 : in  STD_LOGIC;
           rst1 : in  STD_LOGIC;
           q1 : out  STD_LOGIC);
end clk_div;

architecture Behavioral of clk_div is

begin
process(rst1,clk1)


variable count:natural:=1;
begin

if rst1='0' then
count:=0;
q1<='0';
elsif clk1'event and clk1='1' then
count:=count+1;
if count<250 then
q1<= '0';
elsif count<500 then 
q1<='1';
else 
q1<='0';
end if;
end if;
end process;

end Behavioral;


GATE

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity gate is
    Port ( q1 : in  STD_LOGIC;
           unk1 : in  STD_LOGIC;
           q2 : out  STD_LOGIC);
end gate;

architecture Behavioral of gate is

begin
process(q1,unk1)
begin

if(q1='1')then

q2<=q1 and unk1;
end if;

end process;
end Behavioral;




COUNTER

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity ctr is
    Port ( q2 : in  STD_LOGIC;
           rst1 : in  STD_LOGIC;
           q1 : in  STD_LOGIC;
             q3 : out  STD_LOGIC_vector(7 downto 0));
end ctr;

architecture Behavioral of ctr is

signal temp:std_logic_vector(7 downto 0):="00000000";
begin
process(q2,rst1)
begin
if(rst1='0' or q1='0')then
temp<="00000000";
elsif(q2'event and q2='1')then
if(q1='1')then
temp<=temp+1;
end if;

end process;
q3<=temp;
end Behavioral;
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top