Question

VERILOG CODE Design a new Verilog module to define a 4-bit counter algorithmically using behavioral modeling....

VERILOG CODE

Design a new Verilog module to define a 4-bit counter algorithmically using behavioral modeling. This time we no longer need T FlipFlop submodule. The 4-bit counter can be directly implemented using a 4-bit register variable and adding 1 to its value as follows:

input Clock, Clear, Enable;

output reg [3:0] Q;

always @ (posedge Clock or negedge Clear)

if (~Clear) Q <= 0;

else if (Enable)

Q <= Q + 1'b1;

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

the verilog module:

module counter(out_count,clk,reset);
input clk,reset;
output reg [3:0] out_count=0;
always@(posedge clk)
begin
if(!reset)
begin
out_count<=0;
end
else
begin
out_count<=out_count+1;
end
end
endmodule

testbench:

module test();
reg clk,reset;
wire [3:0] out_count;
counter c1(out_count,clk,reset);
initial
begin
clk=0;reset=0;
#2 reset=0;
#4 reset=1;
#40
#4 reset=0;
#4 reset=1;
$finish;
end
initial
forever
#2 clk=~clk;
initial
$monitor("out_count=%b",out_count);
endmodule

waveform:

Add a comment
Know the answer?
Add Answer to:
VERILOG CODE Design a new Verilog module to define a 4-bit counter algorithmically using behavioral modeling....
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
  • Consider the circuit in Figure 1. It is a 4-bit (QQ2Q3) synchronous counter which uses four T-typ...

    Consider the circuit in Figure 1. It is a 4-bit (QQ2Q3) synchronous counter which uses four T-type flip-flops. The counter increases its value on each positive edge of the clock if the Enable signal is asserted. The counter is reset to 0 by setting the Clear signal low. You are to implement an 8-bit counter of this type Enable T Q Clock Clear Figure 1. 4-bit synchronous counter (but you need to implement 8-bit counter in this lab) Specific notes:...

  • Write a behavioral Verilog module for a 4-bit Johnson counter that has 8 states. The counter load...

    Write a behavioral Verilog module for a 4-bit Johnson counter that has 8 states. The counter loads the "0000" state if reset is low. The counter should start and end with this state. Write a testbench to verify the correctness of the 4-bit Johnson counter. The testbenclh should have a clock with a period of 20ns and a reset signal. The testbench should store the 4-bit binary outputs of the counter in a file, which will be used to provide...

  • Write a test bench to thoroughly test the Verilog module dff_fe_asyn_h. below is the module ddff_fe_asyn_h.code...

    Write a test bench to thoroughly test the Verilog module dff_fe_asyn_h. below is the module ddff_fe_asyn_h.code Simulate the circuit using ISim and analyze the resulting waveform. Take full screenshots of all Verilog source codes and the resulting simulation waveform to be included in the lab report. Include explanation of the waveform and how you can conclude that the D flip flop implemented in step 9 is correct in the lab report. Verilog Code for dff_fe_asyn_h is mentioned below:- //DFF module...

  • Please explain what he verilog code does: module lab7_2_3( input clk, input Enable, input Clear, input...

    Please explain what he verilog code does: module lab7_2_3( input clk, input Enable, input Clear, input Load, output [3:0] Q, reg [3:0] count,      wire cnt_done );             assign cnt_done = ~| count;     assign Q = count;     always @(posedge clk)          if (Clear)              count <= 0;          else if (Enable)          if (Load | cnt_done)          count <= 4'b1010; // decimal 10          else          count <= count - 1; Endmodule

  • 5.28 The Verilog code in Figure P5.9 represents a 3-bit linear-feedback shift register (LFSR) This type...

    5.28 The Verilog code in Figure P5.9 represents a 3-bit linear-feedback shift register (LFSR) This type of circuit generates a counting sequence of pseudo-random numbers that repeats after 2" - 1 clock cycles, where n is the number of flip-flops in the LFSR. Synthesize a circuit to implement the LFSR in a chip. Draw a diagram of the circuit. Simulate the circuit's behavior by loading the pattern 001 into the LFSR and then enabling the register to count. What is...

  • please give the verilog code and explain in the form of comments. Part I Consider the...

    please give the verilog code and explain in the form of comments. Part I Consider the circuit in Figure 1. It is a 4-bit synchronous counter (text Section 5.9.2) that uses four T-type flip- flops (text Section 5.5). The counter increments its value on each positive edge of the clock if the Enable signal is asserted. The counter is reset to 0 by setting the Clear b signal low - it is an active-low asynchronous clear. You are to implement...

  • 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...

  • a Read the following codes in Verilog and the corresponding testbench file. Describe what the codes...

    a Read the following codes in Verilog and the corresponding testbench file. Describe what the codes are doing by adding comments in the code. Then write down the simulation results of res1, res2, res3, and res4, respectively. Source code module vector_defn (num1, res1, res2, res3, res4); input [7:0] num1; output res1; output [3:0] res2; output [0:7] res3; output [15:0] res4; assign res1=num1[2]; assign res2=num1[7:4]; assign res3=num1; assign res4={2{num1}}; endmodule testbench: `timescale 1ns / 1ps module vector_defn_tb; reg [7:0] in1; wire...

  • help me to finish the verilog code and test bench Part 2: Sequence Counter Design the...

    help me to finish the verilog code and test bench Part 2: Sequence Counter Design the sequence counter using Xilinx Vivado. Consider the required number of D flip-flops(4). A sample VERILOG source file is as shown: module Seq_COUNT(     ??? clock,     ??? wire [?:?] D,     ??? ??? [?:?] out     );     always @ (??? ???)     ???         // 3 bit Sequence Given is 0 2 4 6 1 3 5 7         out[N-1] <= some expression;...

  • 1) Using Verilog behavioral modeling, describe an n-bit circuit that has four n-bit unsigned inpu...

    1) Using Verilog behavioral modeling, describe an n-bit circuit that has four n-bit unsigned inputs A B, C, and D, and two control inputs C1, and CO. The circuit produces an n+1-bit output Y according to the following table: (No delavs) 120 marks CI CO Function 1 Y MAX (A,B,C,D) , i.e. Y equals the maximum of the four inputs 0 | Y 〈 MIN (A,B,C,D), i.e. Y, equals the minimum of the four inputs 1 YAVERAGE (A,B.C,D), i.e. Y...

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