The second process increment the seconds,minutes and hours etc when the conditions are met.For example at every clock cycle we increment 'seconds'.Whenever seconds reaches the value '60' we increment 'minutes' by 1.Similarly whenever minutes reach '60' we increment 'hours' by 1.Once hours reaches the value '23' we reset the digital clock.The VHDL code for digital clock is given below:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity digi_clk is
port (clk1 : in std_logic;
seconds : out std_logic_vector(5 downto 0);
minutes : out std_logic_vector(5 downto 0);
hours : out std_logic_vector(4 downto 0)
);
end digi_clk;
architecture Behavioral of digi_clk is
signal sec,min,hour : integer range 0 to 60 :=0;
signal count : integer :=1;
signal clk : std_logic :='0';
begin
seconds <= conv_std_logic_vector(sec,6);
minutes <= conv_std_logic_vector(min,6);
hours <= conv_std_logic_vector(hour,5);
--clk generation.For 100 MHz clock this generates 1 Hz clock.
process(clk1)
begin
if(clk1'event and clk1='1') then
count <=count+1;
if(count = 50000000) then
clk <= not clk;
count <=1;
end if;
end if;
end process;
process(clk) --period of clk is 1 second.
begin
if(clk'event and clk='1') then
sec <= sec+ 1;
if(sec = 59) then
sec<=0;
min <= min + 1;
if(min = 59) then
hour <= hour + 1;
min <= 0;
if(hour = 23) then
hour <= 0;
end if;
end if;
end if;
end if;
end process;
end Behavioral;
This digital clock can be used as a component in your main program.If you want to display the time in LCD panel or use a speaker to tell the time then you need to write the appropriate VHDL code for interfacing with such components in your FPGA board.Such programs may vary depending upon the board and FPGA chip you are using.use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity digi_clk is
port (clk1 : in std_logic;
seconds : out std_logic_vector(5 downto 0);
minutes : out std_logic_vector(5 downto 0);
hours : out std_logic_vector(4 downto 0)
);
end digi_clk;
architecture Behavioral of digi_clk is
signal sec,min,hour : integer range 0 to 60 :=0;
signal count : integer :=1;
signal clk : std_logic :='0';
begin
seconds <= conv_std_logic_vector(sec,6);
minutes <= conv_std_logic_vector(min,6);
hours <= conv_std_logic_vector(hour,5);
--clk generation.For 100 MHz clock this generates 1 Hz clock.
process(clk1)
begin
if(clk1'event and clk1='1') then
count <=count+1;
if(count = 50000000) then
clk <= not clk;
count <=1;
end if;
end if;
end process;
process(clk) --period of clk is 1 second.
begin
if(clk'event and clk='1') then
sec <= sec+ 1;
if(sec = 59) then
sec<=0;
min <= min + 1;
if(min = 59) then
hour <= hour + 1;
min <= 0;
if(hour = 23) then
hour <= 0;
end if;
end if;
end if;
end if;
end process;
end Behavioral;
Nice code... But I only want to ask one ques, say i have to set clock manually. How will that can be done..
ReplyDeleteawsome! but how will it look like if i want the results to be displayed on the LCD
ReplyDeletei still don't understand how to generate the necessary clock frequency. For 100 MHz clock, why you wait for 'count' till 50000000 instead of 100000000?
ReplyDelete@timmy : look at the code snippet carefully.What we are doing here is that a signal 'clk' is toggled whenever the count reaches 50m(50 million). This means that
ReplyDeleteclk='1' for 50m clock cycles of clk1.
then clk='1' for 50m clock cycles of clk1.and this toggling goes on.
In effect, one clock cycle of clk = 100m clock cycles of clk1.
I hope now you understand.
can u postt the testbench for it?
ReplyDeletehey....how can we adjust the time of this clock?? i mean if we press the BTN1 it should increment or decrement the minutes.....do you have a sample code for this..??
ReplyDeleteHey...do you ppl have a code which can adjust the time of the clock using its different buttons or switches??i mean if switch/button is pressed it increment or decrements the time??kindly help out
ReplyDelete@Uzar : This is the basic code for the clock. I dont have the code for the time setting part.
ReplyDeletehi i wnt vhdl code for interfacing gsm and gpsm modem to fpga
ReplyDeletecan u send me another code for digital clock
ReplyDeletehi can u send me another code for digital clock
ReplyDeletehow to set mode pin in clock using vhdl code?
ReplyDeletecan anyone help to write a vhdl program for analog to digital converter
ReplyDeleteHi. Sorry for this newbie question. Why do you use integer type for sec,min,hour and then convert to std_logic_vector? Why aren´t sec,min,hour declared as std_logic_vector in the beginning?
ReplyDeleteRegards,
Maia
what value i am supposed to give as/ for "clk1"...?? i mean what is input here precisely if i want to see simulation wave-forms for tis program?? ...reply ASAP....im in so hurry....plz....
ReplyDeletehey what as an input i am supposed to put here in "clk1"???...reply ASAP....i want to see simulation waveforms in xilinx and model sim also...plz reply ASAP........
ReplyDeleteplease post code for a Stop Watch, which displays the time in three decimal digits, and counts from 00.0 to 99.9 seconds and wraps around. It contains a synchronous clear signal, clr, which
ReplyDeletereturns the count to 00.0, and an enable signal, go, which enables and suspends the
counting. This design is basically a BCD (binary-coded decimal) counter, which counts
in BCD format. Our Broad has a 100-MHz clock;