其他分享
首页 > 其他分享> > verilog简单奇校验

verilog简单奇校验

作者:互联网

  1. 介绍

·奇偶校验:根据被传输的一组二进制代码的数位中“1”的个数是奇数或偶数来进行校验。采用奇数的称为奇校验,反之,称为偶校验。采用何种校验是事先规定好的。通常专门设置一个奇偶校验位,用它使这组代码中“1”的个数为奇数或偶数。若用奇校验,则当接收端收到这组代码时,校验“1”的个数是否为奇数,从而确定传输代码的正确性。 粘贴的

  1. 例如
    发送端传输字节8’bx0111010;x是校验位,使用奇校验,因为字节中有效数据位中1的个数为4位,所以x位填1,是字节满足1的个数为奇数。
  2. 快速确定校验位
    缩位异或运算符^, bits = 7’b0111010; 因为 ^bits = 0; 所以 x = 1’b1; 此处若bits中有5个1,^bits1 = 1; 那么x=1’b0;上图对缩减解释的好,剪切自http://www.techbulo.com/2830.html
  3. 接收端奇校验
    对接收的字节进行缩减异或,若为1则正确,0位错误。
  4. verilog代码
//odd check
//result 1 is correct
module parity_check_top(
input	wire	[7:0]	bits,
output  wire    		odd_error
);
assign odd_error = ^bits;
endmodule



//add parity bit
module gen_odd_bit_for7(
input	wire	[6:0]	bits,
output	wire	[7:0]   parity
);
assign parity = (^bits == 1 ) ? {1'b0,bits}:{1'b1,bits};
endmodule

标签:parity,wire,奇数,odd,校验,verilog,简单,bits
来源: https://blog.csdn.net/weixin_36559534/article/details/110499251