前文参考我的上一篇博客,本来在上面修改的最后不能发表,所以在这里补了最后一步极性转换,原理前文已经介绍通信原理---FPGA---HDB3码编码_基于fpga的hdb3编码-CSDN博客
always @ ( posedge clk or negedge rst_n )
begin
if( !rst_n ) begin
flag <= 0;
codeout <= 2'bxx;
end
else begin
if( codein_b == 2'b01 || codein_b == 2'b10 ) begin //输入1或B
if( flag == 0 ) begin
codeout <= 2'b01; //+1
flag <= 1; //极性更改
end
else begin
codeout <= 2'b10; //-1
flag <= 0; //极性更改
end
end
else if( codein_b == 2'b11 ) begin //输入V
if( flag == 0 ) //
codeout <= 2'b10; //输出-1
else
codeout <= 2'b01; //+1
end
else begin
codeout <= codein_b;
end
end
end