1.原理图
实现代码如下:
module gray_counter(clk, gray, inr, reset_n)
parameter SIZE = 4;
input clk, inr, reset_n;
output [SIZE-1] gray;
reg [SIZE-1] gray_temp, gray, bin_temp, bin;
integer i;
always @ (gray or inr)
begin: gray_bin_gray
for (i = 0; i < SIZE; i = i + 1)
bin[i] = ^(gray >> i);//==格雷码到二进制的转换==
bin_temp = bin + inr;//==计数==
gray_temp = (bin_temp >> 1) ^ bin_temp;//==二进制到格雷码的转换
end
endmodule
再寄存起来;