Question

In: Electrical Engineering

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 normally up or down by 1s).

(Hint: use “if” and “else if” statements. After checking the “Resetn” value, check the value of “count2”).

Simulate the module in EDA Playground. In the testbench, use the following input signals:

    Clock = 0;                       // initial value

    updown = 1;                  // initially count up

    count2 = 0;                    // count-by-2 disabled

    Resetn = 0;                    // reset active

    En = 1;                                           // enable active

    #10

    Resetn = 1;                    // reset disabled

    #40

    updown = 0;                  // count down

    #80

    count2 = 1;                    // count-up-by-2 enabled

    #40

Submit a printout your module (do not have to show the testbench) as well as a screenshot of the simulation results (waveforms

Solutions

Expert Solution

module counter_updown (
  input Clock, Resetn, En,
  input updown, count2,
  output reg [3:0] count
);

always @ (posedge Clock)
  begin
   if (!Resetn) // Asynchronous active high reset
   count <= 4'b0;
   else if (En)
   begin
   if (updown) // Count up
   count <= count + count2 + 1'b1;
   else // Count down
   count <= count - count2 - 1'b1;
   end
  end

endmodule

////////////////////////// TESTBENCH FILE ////////////////////////
module counter_updown_tb;
reg Clock, Resetn, En;
reg updown, count2;
wire [3:0] count;

counter_updown m1 (.Clock(Clock), .Resetn(Resetn), .En(En), .updown(updown), .count2(count2), .count(count));

always
  #5 Clock = !Clock;

initial
  begin
   $recordfile("file1.trn");
   $recordvars();
  end

initial
  begin
   Clock = 1'b0;
   Resetn = 1'b0;
   updown = 1'b1;
   count2 = 1'b0;
   En = 1'b1;

   #10;
   Resetn = 1'b1;
   #40;
   updown = 1'b0;
   #80;
   count2 = 1'b1;
   #40;
   $finish;
  end
endmodule


Related Solutions

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...
Create a testbench in Verilog for the following module (logic). Verify the testbench works in your...
Create a testbench in Verilog for the following module (logic). Verify the testbench works in your answer. I'll upvote correct answers. This module does the following. The algorithm takes an input between 0 and 255 (in unsigned binary and counts the number of ones in each number (ex. 01010101 has 4 ones). Then the output would be 00000100 (4 in binary because there are 4 ones. The test bench would need to verify the inputs and outputs of each number....
Create a testbench in Verilog for the following module (logic). Verify the testbench works in your...
Create a testbench in Verilog for the following module (logic). Verify the testbench works in your answer. I'll upvote correct answers. This module does the following. The algorithm takes an input between 0 and 255 (in unsigned binary and counts the number of ones in each number (ex. 01010101 has 4 ones). Then the output would be 00000100 (4 in binary because there are 4 ones. The test bench would need to verify the inputs and outputs of each number....
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.....
Design a 4-bit multiplier by using 4 bit full adder and write a verilog code.
Design a 4-bit multiplier by using 4 bit full adder and write a verilog code.
Design and write a verilog code and testbench for a 16-bit RISC MIPS Processor on vivado...
Design and write a verilog code and testbench for a 16-bit RISC MIPS Processor on vivado and show waveform.
Write the Verilog Code for the module to multiply two 7-bit numbers using the array multiplie
Write the Verilog Code for the module to multiply two 7-bit numbers using the array multiplie
Design an 8-bit adder. Show Verilog code and testbench.
Design an 8-bit adder. Show Verilog code and testbench.
Using Behavorial VHDL, design a 4-bit up/down counter.
Using Behavorial VHDL, design a 4-bit up/down counter.
Question B Write an 8 bit adder module in System Verilog by appropriately connecting two 4...
Question B Write an 8 bit adder module in System Verilog by appropriately connecting two 4 bit adders (the System Verilog code of a 4 bit adder is available in the lecture notes). Instantiate your 8 bit adder module on DE2 board. Design a test circuit on DE2 board that allows us to test the 8 bit adder using the switches and the seven segment displays on DE2 board. The test circuit will need the module you designed for Part...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT