Question

Design in VHDL a 4-bit up-down counter as presented below:

XЗ Q3 X3X2X1X0 Parallel Load X2 S1SO Function Select Input Q2 RST-Asynchronous Reset Input X1 CLK- Clock Input Q1 хо Q3Q2Q1Q0

The operation of the up-down counter is described by the following truth table:

S1 S0

Action

0 0

Hold

0 1

Count up

1 0

Count down

1 1

Parallel Load

Provide VHDL code and testbench

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

--VHDL Code

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity up_down_counter is
   port (   X3, X2, X1, X0   : in std_logic;
       CLK       : in std_logic;
       S1, S0       : in std_logic;
       RST       : in std_logic;
       Q3, Q2, Q1, Q0   : out std_logic
   );
end up_down_counter;

architecture arch of up_down_counter is

signal reg :std_logic_vector(3 downto 0):= "0000";

signal sel :std_logic_vector(1 downto 0);

begin

sel <= (S1 & S0);

process (CLK, RST)

begin

   if (RST = '1') then --Asynchronous reset
       reg <= "0000";
   else

       if rising_edge (CLK) then
       case (sel) is
           when "00"=> reg <= reg;
           when "01"=> reg <= reg + 1;
           when "10"=> reg <= reg - 1;
           when "11"=> reg <= (X3 & X2 & X1 & X0);
           when others => null;
       end case;
       end if;
   end if;

end process;

Q3 <= reg(3);
Q2 <= reg(2);
Q1 <= reg(1);
Q0 <= reg(0);

end arch;

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

--VHDL TESTBENCH

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

entity up_down_counter_tb is
end;

architecture bench of up_down_counter_tb is

component up_down_counter
   port (   X3, X2, X1, X0   : in std_logic;
       CLK       : in std_logic;
       S1, S0       : in std_logic;
       RST       : in std_logic;
       Q3, Q2, Q1, Q0   : out std_logic
   );
end component;

signal X3, X2, X1, X0: std_logic;
signal CLK: std_logic;
signal S1, S0: std_logic;
signal RST: std_logic;
signal Q3, Q2, Q1, Q0: std_logic ;

begin

uut: up_down_counter port map ( X3 => X3,
X2 => X2,
X1 => X1,
X0 => X0,
CLK => CLK,
S1 => S1,
S0 => S0,
RST => RST,
Q3 => Q3,
Q2 => Q2,
Q1 => Q1,
Q0 => Q0 );

CLOCK: process
begin
  
   CLK <= '0';
   wait for 10 ns;
   CLK <= '1';
   wait for 10 ns;
end process;

STIMULUS: process
begin
  
   X3 <= '1';
   X2 <= '0';
   X1 <= '0';
   X0 <= '0';
   RST <= '0';
   S1 <= '0';
   S0 <= '0';

   wait for 100 ns;

   S1 <= '0';
   S0 <= '1';

   wait for 100 ns;

   RST <= '1';

   wait for 100 ns;

   RST <= '0';
   S1 <= '1';
   S0 <= '0';

   wait for 100 ns;

   S1 <= '1';
   S0 <= '1';


wait;
end process;


end;

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

--Simulation on ModelSim

M Model5im- INTEL FPGA STARTER EDITION 10.5b File Edit View Compile Simulate Add Wave Tools Layout Bookmarks Window Help E- SM Model5im- INTEL FPGA STARTER EDITION 10.5b File Edit View Compile Simulate Add Wave Tools Layout Bookmarks Window Help E- S

Add a comment
Know the answer?
Add Answer to:
Design in VHDL a 4-bit up-down counter as presented below: The operation of the up-down counter...
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
  • Design C-1 (modulo-10 up-counter): Using the behavioral VHDL coding, create an up-counter to count upward. The...

    Design C-1 (modulo-10 up-counter): Using the behavioral VHDL coding, create an up-counter to count upward. The up counter has the following control inputs En.reset, CLK. The counting outputs are Q0, O1, Q2. and O3 reset clears the outputs of the counter to 0. En enables the counting when En-1. When En-0, the counter stops. The counter sequentially counts all the possible numbers and loops again, from 0 to 9, back to 0 and 9, etc Design C-2: Ten-second Counter with...

  • Q3. Synchronous Counter Figure 8.3(a) shows a modulo-8 synchronous up-counter (Modulo-8 because this counter can count...

    Q3. Synchronous Counter Figure 8.3(a) shows a modulo-8 synchronous up-counter (Modulo-8 because this counter can count only from 0 to 7 with its 3 bits qo, q1 and 92.). Treat each gray cell in the figure as a component and write generic VHDL codes to create a modulo-2N counter, where N is the number of flip-flops required. Use nominal mapping for this problem while instantiating components. When the asynchronous reset signal rst is high, the counter is set to 0...

  • Use a behavioral Verilog model to design a 3-bit fault tolerant up-down counter. For each flip-fl...

    Use a behavioral Verilog model to design a 3-bit fault tolerant up-down counter. For each flip-flop (FF) include asynchronous reset and preset signals. Refer to Example 4.3 on page 160 for an example of a single FF with both reset and preset signals as well as with an enable signal. For this project, you don't need to use FFs with enables. You don't also need not-q (nq) in this assignment. Use active-high signals for reset and present signals. The example...

  • Problem 7. Consider the 74x194 4-bit bidirectional universal shift register shown below Determine the operation of...

    Problem 7. Consider the 74x194 4-bit bidirectional universal shift register shown below Determine the operation of this circuit by filling out the table. Assume that the register is cleared initially as indicated by the first row in the table, and then connected to +5V (before time t), as shown in schematic. Also assume that t 'is that time at which a positive edge occurs in the input signal 'clock'. Si and S0 inputs (given) are used to switch between modes...

  • Design a 3- bit Multipurpose Register. The register utilizes 3 "D" type flip flops with outputs...

    Design a 3- bit Multipurpose Register. The register utilizes 3 "D" type flip flops with outputs Q0, Q1, Q2. The Registers has a synchronous clock input(CLK) that clocks all 3 flip flops on its positive edge The Registers has an asynchronous clear input(CLR' ) that sets all flip flops to "0" when active low. The Register has 2 select inputs, S0 and S1 that selects the functions as folows: S1 = 0, 0, 1, 1 and S0 = 0,1,0,1 and...

  • 5. (7 points) Shown in the following block diagram is a 4-bit up-counter with parallel load, clk ...

    5. (7 points) Shown in the following block diagram is a 4-bit up-counter with parallel load, clk Dc BA load clr where clr and load are asynchronous inputsi.e., one of the following operations will be performed “simultaneously" (independently of the clock) when the inputs change values: clr load operations 1 X clear 0 0parallel load 1 up-counting 0 the above block diagram and any logic gates you want to build an offset down-counter to count from QpQcQBQA 0111 0110010 ....

  • in VHDL Show synthesizable VHDL code for a register unit that performs operations shown below. The unit has a 3-bit mod...

    in VHDL Show synthesizable VHDL code for a register unit that performs operations shown below. The unit has a 3-bit mode (md) input, an asynchronous reset (rs) input, a 1-bit output control (oc) input, and an 8-bit bi-directional io bus. The internal register drives the io bus when oc is ‘I, and md is not “11 1". Use std-logic. md-000: does nothing md-001: right shift the register md-010: left shift the register md 011: up count, binary md-100: down count,...

  • Using VHDL language, design, simulate and implement a “2-Digit up/down BCD seconds counter with reset button”circuit....

    Using VHDL language, design, simulate and implement a “2-Digit up/down BCD seconds counter with reset button”circuit. The counter value must be automatically incremented/decremented twice every second (slow down the clock to 2 Hz). The up counting or down counting is determined by the status of a toggle switch on DE10-Lite board. If the toggle switch is set to logic 0 , the counter should count down and vice versa. In the up counting mode, if the counter reaches “59”, the...

  • Lab 7: Design a 4 bit register in VHDL. The register file has a synchronous load...

    Lab 7: Design a 4 bit register in VHDL. The register file has a synchronous load signal and an asynchronous reset. When the reset signal is high the register file should be cleared. The input is stored only when the load and clock signal is high. 

  • a) (5 marks) Explain the difference between a latch, a gated latch and a flip flop....

    a) (5 marks) Explain the difference between a latch, a gated latch and a flip flop. b) (5 marks) A gated SR latch has the following schematic diagram CLK a) Draw a timing diagram showing the Q and Q outputs for the following sequence of inputs: CLK R Assume that the initial state of the outputs is Q 0 and Q 1 c) (5 marks) Draw a schematic diagram for a rising edge-triggered master-slave D flip- flop built using two...

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