Question

In: Electrical Engineering

Create a VHDL code of a 4 bit Counter using D flip flop and a Frequency...

Create a VHDL code of a 4 bit Counter using D flip flop and a Frequency Divider that provides the clock signal input for counter

Solutions

Expert Solution

Truth Table of 4-bit UP Counter

PRESENT STATE

NEXT STATE

Q3

Q2

Q1

Q0

Q3+

Q2+

Q1+

Q0+

0

0

0

0

0

0

0

1

0

0

0

1

0

0

1

0

0

0

1

0

0

0

1

1

0

0

1

1

0

1

0

0

0

1

0

0

0

1

0

1

0

1

0

1

0

1

1

0

0

1

1

0

0

1

1

1

0

1

1

1

1

0

0

0

1

0

0

0

1

0

0

1

1

0

0

1

1

0

1

0

1

0

1

0

1

0

1

1

1

0

1

1

1

1

0

0

1

1

0

0

1

1

0

1

1

1

0

1

1

1

1

0

1

1

1

0

1

1

1

1

1

1

1

1

0

0

0

0

D Flip Flop input expression using Karnaugh Mapping:

We use structural design approach. Separate modules for clock divider, d flip flop and top modules is shown below.

--Clock divider

library ieee;
use ieee.std_logic_1164.all;

entity clk_divider is
   port (   clock   : in std_logic;
       d_clock   : out std_logic
   );
end clk_divider;

architecture arch of clk_divider is

signal reg : integer := 0;

signal clkout : std_logic := '0';

begin

process (clock)
begin

   if rising_edge (clock) then
       if (reg = 16) then
           reg    <= 0;
           clkout    <= not clkout;
       else
           reg <= reg + 1;
       end if;
   end if;

end process;

d_clock <= clkout;

end arch;

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

--D Flip Flop

library ieee;
use ieee.std_logic_1164.all;

entity dff is
   port (   clock   : in std_logic;  
       d   : in std_logic;
       clr   : in std_logic;
       Q   : out std_logic
   );
end dff;

architecture arch of dff is

signal reg : std_logic := '0';

begin

process (clock, clr)

begin
   if (clr = '0') then

       reg <= '0';

   else

       if rising_edge(clock) then

           reg <= d;  
      
       end if;

   end if;  
  
end process;

Q <= reg;

end arch;

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

--Top Design

library ieee;
use ieee.std_logic_1164.all;

entity counter is
   port (   clock   : in std_logic;
       clear   : in std_logic;
       Q   : out std_logic_vector(3 downto 0)
   );
end counter;

architecture structural of counter is

component clk_divider is
   port (   clock   : in std_logic;
       d_clock   : out std_logic
   );
end component;

component dff is
   port (   clock   : in std_logic;  
       d   : in std_logic;
       clr   : in std_logic;
       Q   : out std_logic
   );
end component;

signal d : std_logic_vector(3 downto 0);

signal din : std_logic_vector(3 downto 0);

signal dclk: std_logic;

begin

   din(0) <= not d(0);
   din(1) <= d(1) xor d(0);
   din(2) <= (not d(2) and d(1) and d(0)) or (d(2) and not d(0)) or (d(2) and not d(1));
   din(3) <= (d(3) and not d(2)) or (d(3) and not d(1)) or (d(3) and not d(0)) or (not d(3) and d(2) and d(1) and d(0));

   uut : clk_divider port map (clock, dclk);

   uut0 : dff port map (dclk, din(0), clear, d(0));
   uut1 : dff port map (dclk, din(1), clear, d(1));
   uut2 : dff port map (dclk, din(2), clear, d(2));
   uut3 : dff port map (dclk, din(3), clear, d(3));

   Q <= d;

end structural;

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

--Simulated on ModelSim


Related Solutions

You are to implement the following in VHDL: D flip-flop D flip-flop       with enable and reset J-K...
You are to implement the following in VHDL: D flip-flop D flip-flop       with enable and reset J-K flip flop with asynchronous set T Flip flop with asynchronous clear
A T flip-flop is a 1-bit synchronous storage component alternative to the D flip-flop, with a...
A T flip-flop is a 1-bit synchronous storage component alternative to the D flip-flop, with a slightly different interface. The T flip-flop has one input t to synchronously control the state of the flip-flop, as follows: When t is 0, the flip-flop does not change its state value. When t is 1, the flip-flop inverts its current state value (0 becomes 1, and 1 becomes 0). Write a Verilog module for the T flip-flop using a behavioral model. The flip-flop...
Design a 5-bit binary counter using JK flip flops. Draw the flip-flop circuit diagram, the state...
Design a 5-bit binary counter using JK flip flops. Draw the flip-flop circuit diagram, the state graph, the timing diagram, the truth table (with clk pulse) and the state table (with present and next states).
Write VHDL code (behavior model) to implement a 4-bit modulo-9 counter and simulate your VHDL code...
Write VHDL code (behavior model) to implement a 4-bit modulo-9 counter and simulate your VHDL code of 4-bit modulo-9 counter in ModelSim, and capture the screenshot of your simulated waveform. Assume clock period Tclk=100ns, initially, the counter is reset to Q3Q2Q1Q0=0000 you need to simulate a complete counting cycle plus one more additional clock period after it is reset to “0000” state.
Using Behavorial VHDL, design a 4-bit up/down counter.
Using Behavorial VHDL, design a 4-bit up/down counter.
Design a synchronously settable flip-flop using a regular D flip-flop and additional gates.
Design a synchronously settable flip-flop using a regular D flip-flop and additional gates.
Using behavioral VHDL, 32-bit up counter with enable.
Using behavioral VHDL, 32-bit up counter with enable.
Create a state meachine that encrypts an incoming digital bitstream using a D-flip-flop and a Mealy...
Create a state meachine that encrypts an incoming digital bitstream using a D-flip-flop and a Mealy Meachine. The device have to meet these requirments: A. The output of the encryption device matches the input bitstream until a certain set of bits is detected (such as 110). After this detection, the output is the complemented version of the input. B. When a second bitstream 010 is detected, the output reverts to simply matching the input stream again. Please make both bitstreams...
Create a 4-bit Register This is very similar to your flip-flop design from lab task 1....
Create a 4-bit Register This is very similar to your flip-flop design from lab task 1. Ensure that your 4-bit register has inputs “D” (dat, “CLK” (the clock), and “RST” (an asynchronous reset), and an output “Q”. [3 pts] Create a test bench and ensure that your 4-bit register operates correctly (test your reset signal and ensure that you can store a couple different values in the register). If your output behavior is correct, then copy your VHDL design code...
9. Why is the D flip flop the more common flip flop? 10. What is the...
9. Why is the D flip flop the more common flip flop? 10. What is the purpose of a clock in a digital system?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT