二进制码到gray码
gray[n-1]=bin[n-1];
gray=bin^bin[i+1];
gray码到二进制码
bin[n-1]=gray[n-1];
bin=gray^gray[i+1]^….^gray[n-1];
`define WIDTH 4
module test(gray, clk, reset);
input clk,reset;
output [`WIDTH-1:0] gray;
reg [`WIDTH-1:0] gnext,bnext,bin,gray;
reg [`WIDTH-1:0] i;
always@(posedge clk or negedge reset)
if(!reset) gray<=0;
else gray<=gnext;//gray码寄存器
always@(gray) begin
for(i=0;i<`WIDTH;i=i+1)
bin=^(gray>>i);//gray码到二进制码
bnext=bin+1;
gnext=(bnext>>1)^bnext;//二进制码到gray码
end
endmodule
文章评论(0条评论)
登录后参与讨论