The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Apr 27th, 2024, 7:05pm
Pages: 1
Send Topic Print
Verilog counter (newbie) (Read 1710 times)
athlon
New Member
*
Offline

Newbie- but trying
to learn!

Posts: 1
NY
Verilog counter (newbie)
Dec 20th, 2005, 9:07pm
 
Hi,

This is my first post, so I hope it's not a bad question or anything.

I'm trying to learn Verilog, and I wanted to ask if the following 2 are identical in making a 4 bit counter.

Thank you!
Jason


*********** #1 ***********

module counter(clk, rst, ld, q3, q2, q1, q0);
   input clk;
   input rst;
   input ld;
   output q3;
   output q2;
   output q1;
   output q0;

always @ (posedge clk)
begin
     if (rst == 1'b1)
           [q3,q2,q1,q0] = 4'd0;
     else if (ld == 1'b1)
           [q3,q2,q1,q0] = 4'b1;
     else
           [q3,q2,q1,q0] = ([q3,q2,q1,q0] + 1) % 16;
end
endmodule

*********** #2 ***********

module counter(clk, rst, ld, q3, q2, q1, q0);
   input clk;
   input rst;
   input ld;
   output q3;
   output q2;
   output q1;
   output q0;
   wire [3:0] Q;
   reg [3:0] C;

   assign Q = {q3,q2,q1,q0};

   always@(posedge clk or posedge rst)  // reset
   begin
    if(rst) C <= {4'b0000};
     else
      C <= Q + 1;
     end

      assign q3 = C[3:3];
      assign q2 = C[2:2];
      assign q1 = C[1:1];
      assign q0 = C[0:0];
endmodule Undecided
Back to top
 
 
View Profile   IP Logged
Pages: 1
Send Topic Print
Copyright 2002-2024 Designer’s Guide Consulting, Inc. Designer’s Guide® is a registered trademark of Designer’s Guide Consulting, Inc. All rights reserved. Send comments or questions to editor@designers-guide.org. Consider submitting a paper or model.