设为首页收藏本站淘宝杂货铺

从F到0 - From F to 0

 找回密码
 注册已关闭
搜索
查看: 360|回复: 0
收起左侧

Quartus Verilog HDL/FPGA 实现硬件CRC32算法模块板的功能测试验证程序 (带LED指示灯)

[复制链接]
发表于 2023-1-25 20:53:41 | 显示全部楼层 |阅读模式
本帖最后由 HDL 于 2023-1-25 20:53 编辑

main.png
  1. module crc32_table(                        //CRC32查表模块
  2.         input [7:0] in,                        //8位宽地址
  3.         output [31:0] out                        //32位宽值
  4. );
  5.                 reg [31:0] crc;
  6.                 always @(*) begin
  7.                 crc = {24'd0,in};
  8.                         repeat(8) begin
  9.                         crc = (crc >> 1) ^ (crc & 1 ? 32'hEDB88320 : 0);
  10.                         end
  11.                 end
  12. assign out = crc;
  13. endmodule

  14. module crc32_byte(                                        //CRC32 字节计算模块
  15.         input [31:0] in_crc32,                        //输入CRC32
  16.         input [7:0] dat,                                        //字节值
  17.         output [31:0] out_crc32                        //输出CRC32
  18. );
  19.         wire [31:0] out;
  20.                 crc32_table crc32_table(
  21.                         .in(in_crc32[7:0] ^ dat),
  22.                         .out(out)
  23.                 );
  24.         assign out_crc32 = out ^ (in_crc32 >> 8);
  25. endmodule

  26. /*
  27.         CRC32算法板:由18个74HC86(71个异或门)组成(组合逻辑) 或另一颗FPGA/CPLD芯片
  28.         如果全部计算正确,则在LED闪烁 2^40/12500000=87960.930222 秒后转为常亮
  29. */

  30. module main(
  31.         input [31:0] out_crc32,                //接CRC32算法板输出 32个Pin
  32.         output [31:0] in_crc32,                //接CRC32算法板输入 32个Pin
  33.         output [7:0] dat,                                //接CRC32算法板字节输入 B0~B7 8个Pin
  34.         input clk,                                                //50Mhz有源晶振时钟 Pin17
  35.         input rst,                                                //复位按钮 (低电平按下) Pin144
  36.         output reg led                                        //LED Pin3 计算中:闪烁 错误:熄灭 正确:常亮 (低电平点亮)
  37. );

  38. wire [31:0] out_crc32B;
  39. reg [31:0] in_crc32B;
  40. reg [7:0] datB;
  41. assign in_crc32 = in_crc32B;
  42. assign dat = datB;

  43. crc32_byte crc32_byte(                //模块实例化
  44.         .in_crc32(in_crc32),
  45.         .dat(dat),
  46.         .out_crc32(out_crc32B)
  47. );

  48. //时钟分频
  49. reg [1:0] i;
  50. always @(posedge clk) begin
  51.         i <= i + 2'd1;
  52. end

  53. reg err;
  54. reg ok;
  55. reg [22:0] j;
  56. initial err = 1'd0;
  57. initial ok = 1'd0;
  58. always @(posedge i[1]) begin                //12.5Mhz
  59.         if(!rst) begin
  60.         led <= 1'd1;
  61.         err = 1'd0;
  62.         ok = 1'd0;
  63.         {in_crc32B,datB} = 40'd0;
  64.         j = 23'd0;
  65.         end else begin
  66.                 if(err) begin
  67.                         led <= 1'd1;
  68.                 end else begin
  69.                         if(ok) begin
  70.                                 led <= 1'd0;
  71.                         end else begin
  72.                                 {datB,in_crc32B} = {datB,in_crc32B} + 40'd1;
  73.                                 j = j + 23'd1;
  74.                                 if(j >= 23'd1562500) begin
  75.                                         j = 23'd0;
  76.                                         led <= !led;
  77.                                 end
  78.                                 if(out_crc32 != out_crc32B) begin
  79.                                         err <= 1'd1;
  80.                                 end else if(!{datB,in_crc32B}) begin
  81.                                         ok <= 1'd1;
  82.                                 end
  83.                         end
  84.                 end
  85.         end
  86. end
  87. endmodule
复制代码

相关帖子

您需要登录后才可以回帖 登录 | 注册已关闭

本版积分规则

QQ|手机版|Archiver|从F到0 ( 蒙ICP备17002595号-1 )
蒙公网安备15010402000325号

腾讯云安全认证

GMT+8, 2024-4-26 17:08 , Processed in 1.395080 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表