Home /
Expert Answers /
Computer Science /
2-4-pts-modify-the-code-of-the-x-bit-counter-shown-in-code-example-5-to-accommodate-the-followin-pa366
(Solved): 2. [4 Pts] Modify the code of the x-bit counter shown in Code Example 5 to accommodate the followin ...
2. [4 Pts] Modify the code of the x-bit counter shown in Code Example 5 to accommodate the following characteristics: the counter should have 2 extra inputs: i. input UpDown → to count up (increment) or count down (decrement) (0: increment, 1 : decrement) ii. input [1:0] Step → to enable the counter to count (increment/decrement) with a step of 0,1,2, or 3 . 3. [4 Pts] Develop a testbench to test question 2 module above and simulate it. Choose appropriate test cases that fully test your design. Provide a table of the test cases with their expected outputs, and a screenshot of the module output waveform showing all of these test cases.
Code Example 5: x-bit mod-n binary counter: module counter_x_bit \# (parameter x=3,n=6 ) (input clk, reset, output [x-1:0] count); reg [x−1:0] count; always @ (posedge clk, posedge reset) begin if (reset ==1 ) count <= 0; // non-blocking assignment // initialize flip flop here else if (count ==n−1 ) count <= 0; // non-blocking assignment // reach count end and get back to zero else count <= count +1;// non-blocking assignment // normal operation end