Question

Write a VHDL code to implement the circuit function described below. 6. The circuit is to display the last four digits of you

0 0
Add a comment Improve this question Transcribed image text
Answer #1

--VHDL Code

--We will design a Moore State Machine, with four states
--Each state will output one digit on seven segment display
--last four digit is 3416
--seven segment display shown is of common anode type

library ieee;
use ieee.std_logic_1164.all;

entity circuit_function is

   port (   DIR   : in std_logic;
       CLK   : in std_logic;
       RST   : in std_logic;
       A, B, C, D, E, F, G : out std_logic
   );
end circuit_function;

architecture arch of circuit_function is

type state is (S0, S1, S2, S3);
signal present_state, next_state : state;

signal seg : std_logic_vector(6 downto 0); --represents gfedcba segments

begin

process (CLK)
begin

   if (RST = '1') then
       present_state <= S0;

   elsif falling_edge (CLK) then
       present_state <= next_state;
   end if;

end process;

process (present_state)
begin
   case (present_state) is
       when S0 =>    seg <= "0110000";    --digit 3
               if (DIR = '1') then
                   next_state <= S1;
               else
                   next_state <= S3;
               end if;
      
       when S1 =>    seg <= "0011001";   --digit 4
               if (DIR = '1') then
                   next_state <= S2;
               else
                   next_state <= S0;
               end if;

       when S2 =>    seg <= "1111001";   --digit 1
               if (DIR = '1') then
                   next_state <= S3;
               else
                   next_state <= S1;
               end if;

       when S3 =>    seg <= "0000010";   --digit 6
               if (DIR = '1') then
                   next_state <= S0;
               else
                   next_state <= S2;
               end if;

       when others =>    next_state <= S0;

   end case;

end process;

A <= seg(0);
B <= seg(1);
C <= seg(2);
D <= seg(3);
E <= seg(4);
F <= seg(5);
G <= seg(6);

end arch;

---------------------------------------------------------------------------------------------------------------------------------------

--Testbench

library IEEE;
use IEEE.Std_logic_1164.all;
use IEEE.Numeric_Std.all;

entity circuit_function_tb is
end;

architecture bench of circuit_function_tb is

component circuit_function
   port (   DIR   : in std_logic;
       CLK   : in std_logic;
       RST   : in std_logic;
       A, B, C, D, E, F, G : out std_logic
   );
end component;

signal DIR: std_logic;
signal CLK: std_logic;
signal RST: std_logic;
signal A, B, C, D, E, F, G: std_logic ;

constant clock_period: time := 10 ns;
  
begin

uut: circuit_function port map ( DIR => DIR,
CLK => CLK,
RST => RST,
A => A,
B => B,
C => C,
D => D,
E => E,
F => F,
G => G );

stimulus: process
begin
  
   RST <= '1';
   DIR <= '1';

   wait for 20 ns;
  
   RST <= '0';

   wait for 60 ns;

   DIR <= '0';
  
wait;
end process;

clocking: process
begin

CLK <= '0';
wait for clock_period / 2;
CLK <= '1';
wait for clock_period / 2;
end process;

end;

-----------------------------------------------------------------------------------------------------------------------------------------

Wave File Edit View Add Format Tools Bookmarks Window Help Wave -Default Msgs arcuit functon b/CLK orcuit_function_b/RST arcu

Add a comment
Know the answer?
Add Answer to:
Write a VHDL code to implement the circuit function described below. 6. The circuit is to display the last four digits...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT