Wednesday, January 13, 2010

ASIC Logic Interview Questions Part #4

1) Design a Gray counter to count 6.

   The reflected binary code, also known as Gray code after Frank Gray, is a binary numeral system where two successive values differ in only one bit.

Dec Gray Binary
0 000 000
1 001 001
2 011 010
3 010 011
4 110 100
5 111 101
6 101 110
7 100 111


module gray_counter (
out , // counter out
enable , // enable for counter
clk , // clock
rst // active hight reset
);

//------------Input Ports--------------
input clk, rst, enable;
//----------Output Ports----------------
output [ 2:0] out;
//------------Internal Variables--------
wire [2:0] out;
reg [2:0] count;
//-------------Code Starts Here---------
always @ (posedge clk)
if (rst)
count <= 0;
else if (enable)
  begin

  if(count < 3'b101)
 count <= count + 1;
else

count <= 0;

end
assign out = { count[2], (count[2] ^
count[1]),(count[1] ^ count[0]) };

endmodule






1 comment:

  1. Shouldn't the else part of the code be count <= count rather than count <= 0 ??

    ReplyDelete

Search This Blog