Question

In: Electrical Engineering

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

Solutions

Expert Solution


// PART A) 3 bit Counter UP DOWN using TFF
module tff (
  input clk, // Clock
  input rst, // Reset
  input T, // T input
  output Q // Output
);

reg temp;

always @ (posedge clk)
  begin
   if (rst) // synchronous and active high reset
   temp <= 1'b0;
   else
   begin
   if (T)
   temp <= ~temp; // toggle output
   else
   temp <= temp; // maintains previous state
   end
  end

assign Q = temp;

endmodule

module counter_top ( // UP DOWN counter using TFF
  input clk,
  input rst,
  input updown, // updown = 0 counter increments ; updown = 1 counter decrements
  output [2:0] count
);

wire temp2, temp1, temp0, Q2, Q1, Q0;

assign temp2 = (~Q1 & ~Q0 & updown) | (Q1 & Q0 & ~updown);
assign temp1 = (~Q0 & updown) | (Q0 & ~updown);
assign temp0 = 1'b1;

tff m2 (.clk(clk), .rst(rst), .T(temp2), .Q(Q2));
tff m1 (.clk(clk), .rst(rst), .T(temp1), .Q(Q1));
tff m0 (.clk(clk), .rst(rst), .T(temp0), .Q(Q0));

assign count = {Q2, Q1, Q0};

endmodule


module counter_tb;
reg clk , rst, updown;
wire [2:0] count;

counter_top COUNTER_TFF (.clk(clk), .rst(rst), .updown(updown), .count(count));

always
  #5 clk = ~clk;

initial
  begin
   clk = 1'b0;
   rst = 1'b1;
   repeat(2)
   @(negedge clk);
   rst = 1'b0;
   updown = 1'b0;
   repeat(10)
   @(negedge clk);
   updown = 1'b1;
   repeat(5)
   @(negedge clk);
   updown = 1'b0;
   repeat(4)
   @(negedge clk);
   $finish;
  end

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

endmodule




// PART B) N bit UP DOWN COUNTER verilog behavioral code

module counter_updown #(parameter WIDTH = 4) (
  input clk,
  input rst,
  input updown,
  output reg [WIDTH-1:0] count
);


always @ (posedge clk)
  begin
   if (rst) // Synchronous active high reset
   count <= {WIDTH{1'b0}};
   else
   begin
   if (!updown) // Count up
   count <= count + 1'b1;
   else // Count down
   count <= count - 1'b1;
   end
  end

endmodule

module counter_tb;
reg clk , rst, updown;
wire [2:0] count;

counter_updown #(.WIDTH(3)) COUNTER_BEHAVE (.clk(clk), .rst(rst), .updown(updown), .count(count));

always
  #5 clk = ~clk;

initial
  begin
   clk = 1'b0;
   rst = 1'b1;
   repeat(2)
   @(negedge clk);
   rst = 1'b0;
   updown = 1'b0;
   repeat(10)
   @(negedge clk);
   updown = 1'b1;
   repeat(5)
   @(negedge clk);
   updown = 1'b0;
   repeat(4)
   @(negedge clk);
   $finish;
  end

initial
  begin
   $recordfile("file1.trn");
   $recordvars();
  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...
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...
Using Behavorial VHDL, design a 4-bit up/down counter.
Using Behavorial VHDL, design a 4-bit up/down counter.
Design a 32 bit after using a single 4 bit using verilog code
Design a 32 bit after using a single 4 bit using verilog code
Design a 32 bit adder using a single 4 bit adder using verilog code
Design a 32 bit adder using a single 4 bit adder using verilog code
Create a 3-bit counter in verilog that cycles through this sequence, 6,2,4,5,0,7,3,1, with a synchronous rest...
Create a 3-bit counter in verilog that cycles through this sequence, 6,2,4,5,0,7,3,1, with a synchronous rest 4.
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.
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)....
verilog code to implement 32 bit Floating Point Adder in Verilog using IEEE 754 floating point...
verilog code to implement 32 bit Floating Point Adder in Verilog using IEEE 754 floating point representation.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT