Gray counter verilog

Guest #6386832
Rate this post
• ▲ useful
▼ not useful
Hi guys!
I want to write the verilog code for a 8-bit gray counter. I added in 
attach the code and the testbech. For some reason I cannot understand, I 
cannot see as outputs the counting, I have only "z" value as output. 
Please could you help me? Thank you very much!
Attached files:
Guest #6393206
Rate this post
• ▲ useful
▼ not useful
Thank you! I solved the problem. I want that the counter stops when it 
reaches the maximum value until I give a new clear signal. Hence, I 
added an "if" but it doesn't work because the counter keeps counting and 
then stops when it reaches "10000000". Could you help me?
The code is presented here

1
 module gray_counter (clk, clear, count, out);
2

3
input clk, clear, count; 
4
output wire [7:0] out;
5

6
wire clk;
7
wire clear;
8
wire count;
9
reg [7:0] temp_out;
10

11
always @ (posedge clk)
12
begin
13
  if(clear) 
14
    temp_out <= 8'b00000000;  
15
  else if(count && temp_out != 8'b11111111) 
16
    temp_out <= temp_out + 1'b1;
17
end
18

19
assign out = {temp_out[7], (temp_out[7]^temp_out[6]), (temp_out[6]^temp_out[5]), (temp_out[5]^temp_out[4]), (temp_out[4]^temp_out[3]), (temp_out[3]^temp_out[2]), (temp_out[2]^temp_out[1]), (temp_out[1]^temp_out[0])};
20

21
endmodule //end module gray_counter
Guest #6393242
Rate this post
• ▲ useful
▼ not useful
I tried to write
1
  else if(count && out != 8'b11111111)
2
    temp_out <= temp_out + 1'b1;
instead of
1
  else if(count && temp_out != 8'b11111111)
2
    temp_out <= temp_out + 1'b1;
and now it seems working but I cannot understand why.

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.