Sunday, June 19, 2011

Write a verilog code for 4 bit binary UP counter


module fourbit_upcount(Reset, Clock, E, Q);
  input Reset, Clock, E;
  output [3:0] Q;
  reg [3:0] Q;
  always @ (posedge Clock)
    if (!Reset)
      Q <= 0;
    else if (E)
      Q <= Q+1;
     
endmodule

1 comment:

  1. // 18-07-2014
    // 4bit binary up counter using behavioural modeling;


    module binary_counter (q,clk,rst,en);
    //output declaration
    output reg [3:0] q;
    //input declaration
    input clk; //clock
    input rst; // reset (active low)
    input en; // enable pin (active high)
    //body of code
    initial q <= 0;
    always @ (posedge clk, negedge rst, negedge en)
    if ((!rst) && en)
    q <= q+1;
    else
    q <= 0;
    endmodule

    ReplyDelete