Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Generic Gray Code Counter

Status
Not open for further replies.
aslijia said:
Added after 3 minutes:

omara007 said:
I don't want to have the glitches resulted from the binary counting

if you use combination logic, you must have glitches, even the simplest combination circuit with only 2 ANDs, by some inputs.


Counters are not COMBINATIONAL circuits
 

I whipped up this synchronous Gray counter without using any intermediate counter or tedious 'case' statement. The 'bin' value is combinatorial. The number of bits is easily adjusted.
Code:
module top (clk, gray);
  parameter             bits = 8;
  input                 clk;
  reg        [bits-1:0] bin = 0;
  output reg [bits-1:0] gray = 0;

  integer i;
  always @ (gray)
    for (i = 0; i < bits; i = i + 1)
      bin[i] <= ^(gray >> i);

  always @ (posedge clk)
    gray <= ((bin + 1'd1) >> 1) ^ (bin + 1'd1);  // to count down, change both + to -
endmodule
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top