Question

In: Electrical Engineering

Using Behavorial VHDL, design a 4-bit up/down counter.

Using Behavorial VHDL, design a 4-bit up/down counter.

Solutions

Expert Solution

Vhdl code:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity UPDOWN_COUNTER is
    Port ( clk: in std_logic; -- clock input
           reset: in std_logic; -- reset input 
     up_down: in std_logic; -- up or down
           counter: out std_logic_vector(3 downto 0) -- output 4-bit counter
     );
end UPDOWN_COUNTER;

architecture Behavioral of UPDOWN_COUNTER is
signal counter_updown: std_logic_vector(3 downto 0);
begin
-- down counter
process(clk,reset)
begin
if(rising_edge(clk)) then
    if(reset='1') then
         counter_updown <= x"0";
    elsif(up_down='1') then
         counter_updown <= counter_updown - x"1"; -- count down
  else 
   counter_updown <= counter_updown + x"1"; -- count up
    end if;
 end if;
end process;
 counter <= counter_updown;

end Behavioral;

Testbench:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity tb_counters is
end tb_counters;

architecture Behavioral of tb_counters is

component UPDOWN_COUNTER 
    Port ( clk: in std_logic; -- clock input
           reset: in std_logic; -- reset input 
     up_down: in std_logic; 
           counter: out std_logic_vector(3 downto 0) -- output 4-bit counter
     );
end component;
signal reset,clk,up_down: std_logic;
signal counter:std_logic_vector(3 downto 0);

begin
dut: UPDOWN_COUNTER port map (clk => clk, reset=>reset, up_down => up_down, counter => counter);
   -- Clock process definitions
clock_process :process
begin
     clk <= '0';
     wait for 10 ns;
     clk <= '1';
     wait for 10 ns;
end process;


-- Stimulus process
stim_proc: process
begin        
   -- hold reset state for 100 ns.
     reset <= '1';
   up_down <= '0';
    wait for 20 ns;    
    reset <= '0';
  wait for 300 ns;    
  up_down <= '1';
   wait;
end process;
end Behavioral;


Related Solutions

Using behavioral VHDL, 32-bit up counter with enable.
Using behavioral VHDL, 32-bit up counter with enable.
Design a 4-bit up/down counter which displays its output on the the 7-led segment using the...
Design a 4-bit up/down counter which displays its output on the the 7-led segment using the decoder used in Lab 2. In this lab, you will design a 4-bit up/down counter which displays its output on the 7-segment LED using the decoder that you designed in Lab 2. The 4-bit up/down counter module has 4 inputs, Clk_1Hz, Reset, Pause, and Up; and a 4-bit output Count. If Reset is 1, the counter should reset its count value to zero (0000)....
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
Objective: Design, construct, and test a three-bit counter that counts up or down. An enable input...
Objective: Design, construct, and test a three-bit counter that counts up or down. An enable input E determines whether the counter is on or off.  If E=0, the counter is disabled and remains at its present count even though clock pulses are applied to the flip-flops.  If E=1, the counter is enabled and a second input, x, determines the direction of the count.  If x=1, the circuit counts upward with the sequence 000, 001, 010, 011, 100,...
Verilog counter problem: Using the attached 4-bit up-counter module and testbench as a template, write a...
Verilog counter problem: Using the attached 4-bit up-counter module and testbench as a template, write a Verilog module that implements a certain 4-bit counter. The module should include two more input variables: “updown” and “count2”. If “updown” is 1, the circuit should count up (by 1s); if it is 0 it should count down (by 1s). If “count2” has a value of 1, the circuit should instead count up by 2s; otherwise it will have no effect (the circuit counts...
Verilog counter problem: Using the attached 4-bit up-counter module and testbench as a template, write a...
Verilog counter problem: Using the attached 4-bit up-counter module and testbench as a template, write a Verilog module that implements a certain 4-bit counter. The module should include two more input variables: “updown” and “count2”. If “updown” is 1, the circuit should count up (by 1s); if it is 0 it should count down (by 1s). If “count2” has a value of 1, the circuit should instead count up by 2s; otherwise it will have no effect (the circuit counts...
SOLVE FOLLOWING a.   Desgin and VERILOG code of a 3 bit up down counter USING T...
SOLVE FOLLOWING a.   Desgin and VERILOG code of a 3 bit up down counter USING T FLIP FLOP..... b. using behavioural module.Write a verilog discription of an N-BIT up down binary counter. Record the simulation output waveform in observation.....
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.
3-(7494) Design and implementation of 4 bit shift register using VHDL Behavioral style of modeling
3-(7494) Design and implementation of 4 bit shift register using VHDL Behavioral style of modeling
You are to design an 4 bit counter that takes as input a clock and a...
You are to design an 4 bit counter that takes as input a clock and a reset signal and outputs a 4-bit count When the clock is asserted and the reset is high, the clock increments. When it increments at 1111,it resets to 0000 Create a schematic diagram of your design using either Xilinx ISE or a drawing tool of your choice or a neatly hand-drawn diagram Create a Verilog module within Xilinx. Verify your design is syntactically correct. Create...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT