Question

In: Electrical Engineering

The goal in this experiment is to implement a 0-12 counter with a test bench that...

The goal in this experiment is to implement a 0-12 counter with a test bench that displays the output of each of the flip-flops in the counter. A behavioral code should be written for this experiment.

Set the time format to 1 nanosecond with a precision of 100 picosecond.

Solutions

Expert Solution

VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity UP_COUNTER is
Port ( clk: in std_logic; -- clock input
reset: in std_logic; -- reset input
counter: out std_logic_vector(3 downto 0) -- output 4-bit counter
);
end UP_COUNTER;
architecture Behavioral of UP_COUNTER is
signal counter_up: std_logic_vector(3 downto 0);
begin
-- up counter
process(clk,reset)
begin
if(rising_edge(clk)) then
if(reset='1' or counter_up="1100") then
counter_up <= x"0";
else
counter_up <= counter_up + x"1";
end if;
end if;
end process;
counter <= counter_up;
end Behavioral;
TEST BENCH FOR VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- FPGA projects using Verilog code VHDL code
-- fpga4student.com: FPGA projects, Verilog projects, VHDL projects
-- VHDL project: VHDL code for counters with testbench  
-- VHDL project: Testbench VHDL code for up counter
entity tb_counters is
end tb_counters;
architecture Behavioral of tb_counters is
component UP_COUNTER
Port ( clk: in std_logic; -- clock input
reset: in std_logic; -- reset input
counter: out std_logic_vector(3 downto 0) -- output 4-bit counter
);
end component;
signal reset,clk: std_logic;
signal counter:std_logic_vector(3 downto 0);
begin
dut: UP_COUNTER port map (clk => clk, reset=>reset, 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';
wait for 20 ns;   
reset <= '0';
wait;
end process;
end Behavioral;
The screen shot of the testbench simulation is given below:

Verilog code:

module mod13_vlog(
out , // Output of the counter
clk , // clock input
reset // reset input
);
//----------Output Ports--------------
output [3:0] out;
//------------Input Ports--------------
input clk, reset;
//------------Internal Variables--------
reg [3:0] out;
//-------------Code Starts Here-------
always @(posedge clk)
if (reset)
begin // active high reset
out <= 3'b0 ;
end
else if (out<12)
begin
out <= out + 1;
end
else
begin
out <= 3'b0 ;
end
endmodule
Verilog Test bench:
`timescale 1ns/100ps
module tb_mod13_vlog;
// Inputs
reg clk;
reg reset;
// Outputs
wire [3:0] out;
// Instantiate the Unit Under Test (UUT)
mod13_vlog uut (
.out(out),
.clk(clk),
.reset(reset)
);
initial begin
clk=1'b1;
forever #5 clk=~clk;
end

initial begin
$monitor($time," out=%h q[0]=%b q[1]=%b q[2]=%b q[3]=%b ",out,out[0],out[1],out[2],out[3]);
reset = 1;#10;
reset = 0;#30;
  
end

endmodule
The screen shot of the testbench results is given below:


Related Solutions

Implement a 4x4 multiplier using gate level (verilog code and test bench)
Implement a 4x4 multiplier using gate level (verilog code and test bench)
IV. TESTING EXPERIMENT: YOUNG’S DOUBLE SLIT EXPERIMENT The goal of this experiment is to test the...
IV. TESTING EXPERIMENT: YOUNG’S DOUBLE SLIT EXPERIMENT The goal of this experiment is to test the relationships we just developed about the positions of the bright spots of an interference pattern. Available equipment: Laser pointer, plate with two closely-positioned narrow slits, whiteboard or white screen, meter stick, protractor. f) Design an experiment to test the relationship we just developed. Sketch the experimental set-up. g) Use the hypothesis to predict the outcome of the experiment. Show your work on your whiteboard....
Implement a JK Flip flop using behavioral modeling in verilog, also write its test bench code.
Implement a JK Flip flop using behavioral modeling in verilog, also write its test bench code.
Implement 1x4 de-multiplexer using data flow modeling in verilog, also write its test bench.
Implement 1x4 de-multiplexer using data flow modeling in verilog, also write its test bench.
a) Implement a decade counter using FF JK-MS. b) Implement a counter dividing by 6 using...
a) Implement a decade counter using FF JK-MS. b) Implement a counter dividing by 6 using FF JK-MS. c) Repeat the previous exercises using FF Type-D.
create a test bench for the following code: module signed_mult (out, clk, a, b); output [15:0]...
create a test bench for the following code: module signed_mult (out, clk, a, b); output [15:0] out; input clk; input signed [7:0] a; input signed [7:0] b; reg signed [7:0] a_reg; reg signed [7:0] b_reg; reg signed [15:0] out; wire signed [15:0] mult_out; assign mult_out = a_reg * b_reg; always@(posedge clk) begin a_reg <= a; b_reg <= b; out <=mult_out; end endmodule
In an experiment to test the effectiveness of a new sleeping aid, a sample of 12...
In an experiment to test the effectiveness of a new sleeping aid, a sample of 12 patients took the new drug, and a sample of 15 patients took a commonly used drug. Of the patients taking the new drug, the average time to fall asleep was 28.6 minutes with a sample standard deviation of 5.2 minutes, and for the patients taking the commonly used drug the average time was 30.7 minutes with a sample standard deviation of 4.1 minutes. Can...
Tim ran an experiment to test optimum power and time settings for microwave popcorn. His goal...
Tim ran an experiment to test optimum power and time settings for microwave popcorn. His goal was to deliver popcorn with fewer than 10% of the kernels left unpopped, on average. To be sure that the method was successful, he popped 8 more bags of popcorn (selected at random). All were of high quality, with the percentages of unpopped kernels shown: 5.5, 2.4, 7.2, 7.4, 5.1, 10.8, 2.4, 9.2 The appropriate null and alternative hypotheses are: H0:μ=10Ha:μ<10 (a) Calculate the...
What was the goal of the 1960s counter-culture movement and did they achieve their dream?
What was the goal of the 1960s counter-culture movement and did they achieve their dream?
Write the VERILOG code for an arithmetic/logic unit (ALU) with a test bench that does the...
Write the VERILOG code for an arithmetic/logic unit (ALU) with a test bench that does the following with 4 bit inputs , and can be tested in on nexys 4 board This is to be implement on : ISE Design Suite - Xilinx /* ALU Arithmetic and Logic Operations ---------------------------------------------------------------------- |ALU_Sel| ALU Operation ---------------------------------------------------------------------- | 0000 | ALU_Out = A + B; ---------------------------------------------------------------------- | 0001 | ALU_Out = A - B; ---------------------------------------------------------------------- | 0010 | ALU_Out = A * B;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT