Home

Saturday, August 31, 2013

Experiment V (Electronics Laboratory)

-------------------------------------- Clock_Divider --------------------------------

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;

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

entity clk_divider is
    Port ( clk_in : in  STD_LOGIC;
           reset : in  STD_LOGIC;
           clk_out : out  STD_LOGIC);
end clk_divider;

architecture Behavioral of clk_divider is

signal temporal: STD_LOGIC;
signal counter : integer range 0 to 12499999:= 0;

begin
frequency_divider: process (reset, clk_in) begin
if (reset = '1') then
temporal <= '0';
counter <= 0;
elsif rising_edge(clk_in) then
if (reset ='0') then 
if (counter = 12499999) then
temporal <= NOT(temporal);
counter <= 0;
else
counter <= counter + 1; 
end if;
end if;
end if;
end process;

clk_out <= temporal;

end Behavioral;

-------------------------------------- Counter 10 ------------------------------

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 using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity count10 is
    Port ( clk : in  STD_LOGIC;
           counter_out : out  STD_LOGIC_VECTOR (3 downto 0));
end count10;
architecture Behavioral of count10 is
signal c : std_logic_vector(3 downto 0);
begin
process(clk)
begin
if(clk'EVENT and clk = '1')then
if(c <= 8)then
c <= c +1 ;

else
c <= "0000";
end if ;
end if;
end process;
counter_out <= c;
end Behavioral;

---------------------------------- BCD 7segment ------------------------------

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;

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

entity BCD_7segment is
    Port ( S : in  STD_LOGIC_VECTOR(3 Downto 0);
           Segs : out  STD_LOGIC_VECTOR(7 DOWNTO 1);
 dg : out std_logic);
end BCD_7segment;

architecture Behavioral of BCD_7segment is

begin
process (S)
begin
case S is
WHEN "0000" =>segs<="1111110";
WHEN "0001" =>segs<="0110000";
WHEN "0010" =>segs<="1101101";
WHEN "0011" =>segs<="1111001";
WHEN "0100" =>segs<="0110011";
WHEN "0101" =>segs<="1011011";
WHEN "0110" =>segs<="1011111";
WHEN "0111" =>segs<="1110000";
WHEN "1000" =>segs<="1111111";
WHEN "1001" =>segs<="1110011";
WHEN OTHERS =>segs<="0000000";

end case;
end process;

dg <= '0';
end Behavioral;


-------------------------------------- TOP Module -------------------------------

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;

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

entity Exper_5 is
    Port ( clk_system : in  STD_LOGIC;
           reset : in  STD_LOGIC;
           z : out  STD_LOGIC_VECTOR (6 downto 0);
 dg : out std_logic);
end Exper_5;

architecture Behavioral of Exper_5 is

signal int1 : std_logic;
signal int2 : std_logic_vector (3 downto 0);
 

component clk_divider
    Port ( clk_in : in  STD_LOGIC;
           reset : in  STD_LOGIC;
           clk_out : out  STD_LOGIC);
end component;

component count10
    Port ( clk : in  STD_LOGIC;
           counter_out : out  STD_LOGIC_VECTOR (3 downto 0));
end component;

component BCD_7segment
    Port ( S : in  STD_LOGIC_VECTOR(3 Downto 0);
           Segs : out  STD_LOGIC_VECTOR(7 DOWNTO 1);
 dg : out std_logic);
end component;

begin

U1: clk_divider port map (clk_system,reset,int1);
U2: count10 port map (int1,int2);
U3: BCD_7segment port map (int2,z,dg);

end Behavioral;


 -------------------------- UCF ----------------------------------------

NET "clk_system" LOC = P127;
NET "reset" LOC = P44;

NET "z[6]" LOC = P40; #a
NET "z[5]" LOC = P35; #b
NET "z[4]" LOC = P32; #c
NET "z[3]" LOC = P30; #d
NET "z[2]" LOC = P27; #e
NET "z[1]" LOC = P25; #f
NET "z[0]" LOC = P23; #g
NET "dg" LOC = P70;

No comments:

Post a Comment