VHDL Code For Digital Clock On FPGA
VHDL Code For Digital Clock On FPGA
VHDL Code For Digital Clock On FPGA
This project is the VHDL version code of the digital clock in Verilog I posted before
(link). The VHDL code for the digital clock is synthesizable.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_std.all;
use work.clock_div.all;
-- fpga4student.com FPGA projects, VHDL projects, Verilog projects
entity digital_clock is
port (
clk: in std_logic;
-- clock 50 MHz
rst_n: in std_logic;
-- Active low reset pulse, to set the time to the input hour and minute (as
-- defined by the H_in1, H_in0, M_in1, and M_in0 inputs) and the second to 00.
-- For normal operation, this input pin should be 1.
H_in1: in std_logic_vector(1 downto 0);
-- 2-bit input used to set the most significant hour digit of the clock
-- Valid values are 0 to 2.
H_in0: in std_logic_vector(3 downto 0);
-- 4-bit input used to set the least significant hour digit of the clock
-- Valid values are 0 to 9.
M_in1: in std_logic_vector(3 downto 0);
-- 4-bit input used to set the most significant minute digit of the clock
-- Valid values are 0 to 9.
M_in0: in std_logic_vector(3 downto 0);
-- 4-bit input used to set the least significant minute digit of the clock
-- Valid values are 0 to 9.
H_out1: out std_logic_vector(6 downto 0);
-- The most significant digit of the hour. Valid values are 0 to 2 ( Hexadecimal value on
7-segment LED)
H_out0: out std_logic_vector(6 downto 0);
-- The most significant digit of the hour. Valid values are 0 to 9 ( Hexadecimal value on
7-segment LED)
M_out1: out std_logic_vector(6 downto 0);
-- The most significant digit of the minute. Valid values are 0 to 9 ( Hexadecimal value
on 7-segment LED)
M_out0: out std_logic_vector(6 downto 0)
-- The most significant digit of the minute. Valid values are 0 to 9 ( Hexadecimal value
on 7-segment LED)
);
end digital_clock;
-- fpga4student.com FPGA projects, VHDL projects, Verilog projects
end Behavioral;
Testbench:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
-- fpga4student.com FPGA projects, VHDL projects, Verilog projects
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--USE ieee.numeric_std.ALL;
ENTITY tb_digital_clock IS
END tb_digital_clock;
--Inputs
signal clk : std_logic := '0';
signal rst_n : std_logic := '0';
signal H_in1 : std_logic_vector(1 downto 0) := (others => '0');
signal H_in0 : std_logic_vector(3 downto 0) := (others => '0');
signal M_in1 : std_logic_vector(3 downto 0) := (others => '0');
signal M_in0 : std_logic_vector(3 downto 0) := (others => '0');
--Outputs
signal H_out1 : std_logic_vector(6 downto 0);
signal H_out0 : std_logic_vector(6 downto 0);
signal M_out1 : std_logic_vector(6 downto 0);
signal M_out0 : std_logic_vector(6 downto 0);
BEGIN
-- fpga4student.com FPGA projects, VHDL projects, Verilog projects
-- Instantiate the Unit Under Test (UUT)
uut: digital_clock PORT MAP (
clk => clk,
rst_n => rst_n,
H_in1 => H_in1,
H_in0 => H_in0,
M_in1 => M_in1,
M_in0 => M_in0,
H_out1 => H_out1,
H_out0 => H_out0,
M_out1 => M_out1,
M_out0 => M_out0
);
-- Clock process definitions
clk_process :process
begin
clk <= '0';
wait for clk_period/2;
clk <= '1';
wait for clk_period/2;
end process;
END;
Simulation results:
Synthesis :