coded_data:附加上5位CRC校验码的17位CRC码,在生成模块被发送,在接收模块被接收;
4.1.1 编码模块设计与仿真
根据前面的论述,用VHDL代码实现逐位运算的程序如下: process(clk)
variable crcvar : std_logic_vector(5 downto 0);
begin
if(clk'event and clk = '1')then
if(st='0'and load='1')then
dtemp<=data; sdatam<=data; cnt<=(others=>'0'); send<='0'; st<='1';
elsif(st='1' and cnt<7)then
cnt<=cnt+1;
if(dtemp(11)='1')then
crcvar:=dtemp(11 downto 6)xor multi_coef;
dtemp<=crcvar(4 downto 0)& dtemp(5 downto 0) & '0';
else dtemp<=dtemp(10 downto 0) & '0'; end if;
elsif(st='1' and cnt=7)then
coded_data<=sdatam & dtemp(11 downto 7); send<='1';cnt<=cnt+1;
elsif(st='1' and cnt=8)then
send<='0'; st<='0';
end if;
end if;
end process; end hev;
22
四川理工学院本科生毕业(论文)设计
图4-2 CRC生成模块
仿真波形:添加激励信号clk时钟信号周期为10ns,数据装载load为1,输入数据data:110011010101,激励信号添加完成按照软件设计进行仿真输出数据为11001101010101000,同时按照理论公式进行计算验证结果相同,CRC编码模块功能正常。
11107642x?x?x?x?x?x?1 110011010101多项式表示为:
542x?x?x?1 110101多项式表示为:
x6?x3?1x5?x4?x2?1x11?x10?x7?x6?x4?x2?1x11?x10?x8?x6x8?x7?x4?x2?1x8?x7?x5?x3x5?x4?x3?x2?1x5?x4?x2?1x310010011101011100110101011101011100101101011111011101010010003
多项式x五位二进制表示01000
- 23 -
编码后的CRC编码:11001101010101000用信息多项式表示为
x16?x15?x12?x11?x9?x7?x5?x3
图4-3 CRC生成模块仿真
4.1.2 解码模块设计与仿真
根据前面的论述,程序校验采用CRC码中包含的数据信息位与生成多项式相除,将得到的结果与CRC码中的校验位作比较,如果相等则判为数据传输无误,反之判为数据传输错误,用VHDL代码实现运算的程序如下:
process(clk,reception)
variable rcrcvar : std_logic_vector(5 downto 0); begin
if(clk'event and clk = '1')then
if(rt='0'and reception='1')then
rdtemp<=coded_data(16 DOWNTO 5);rdatacrc<=coded_data; rcnt<=(others=>'0'); error1<='0';rt<='1';
elsif(rt='1'and rcnt<7)then
datafini<='0';rcnt<=rcnt+1;
rcrcvar:=rdtemp(11 downto 6)xor multi_coef; if(rdtemp(11)='1')then
rdtemp<=rcrcvar(4 downto 0)& rdtemp(5 downto 0)& '0';
24
四川理工学院本科生毕业(论文)设计
else rdtemp<=rdtemp(10 downto 0) & '0';
end if;
elsif(rt='1' and rcnt=7)then datafini<='1';
decode_data<=rdatacrc(16 downto 5); rt<='0';
if(rdatacrc(4 downto 0) /=rdtemp(11 downto 7)) then
error1<='1';
end if; end if;
end if;
end process; end hev; 解码功能模块
图4-4 CRC解码模块
仿真波形:添加激励信号clk时钟信号周期为10ns,数据装载reception为1,输入数据coded_data: 11001101010101000,激励信号添加完成,按照软件设计进行仿真输出数据decode_data为110011010101,将解码器模块仿真数据与编码器仿真数据做对比,可以看出编码模块的输出数据coded_data输入解码模块后解码出的数据与编码器的输入数据相同,可以证明解码器模块功能能够准确实现。
x11?x10?x7?x6?x4?x3?x2?1
- 25 -
x6?x3?1x5?x4?x2?1x11?x10?x7?x6?x4?x3?x2?1x11?x10?x8?x6x8?x7?x4?x2?1x8?x7?x5?x3x5?x4?x2?1x5?x4?x2?101001001110101110011011101110101110011110101110101110101000000
图4-5 CRC解码仿真
4.1.3 循环冗余码编码模块与解码模块联合运行
模块联合连接示意图:
26