数字IC笔试题|verilog实现CRC-8的串行计算

题目如下:在这里插入图片描述
verilog实现:

`timescale 1ns / 1ps
//
module crc(clk,rst_n,data,data_valid,crc_start,crc_out,crc_valid,crc_out_parallel);
input clk,rst_n;
input data;  //串行输入数据
input data_valid; //串行数据有效标识;
input crc_start;

output wire crc_out;
output reg [7:0] crc_out_parallel;
 
output reg crc_valid;

parameter idle = 3'b001;
parameter crc_cal = 3'b010;
parameter crc_output = 3'b100;
parameter polynomial = 8'b0000_0111;

reg [2:0] current_state,next_state;

always@(posedge clk or negedge rst_n)
begin 
if(rst_n==1'b0)
  
	  current_state<=idle;
else 
      current_state<=next_state;
end 

reg [5:0] cnt_in;
reg [2:0] cnt_out;
 
always@(*)
begin 
        case(current_state)
	        idle :    
			       if(crc_start==1'b1)
				        next_state = crc_cal;
				   else 
				        next_state = idle;
		    crc_cal:
			       if(cnt_in==6'd32)
				        next_state = crc_output;
				   else 
				        next_state = crc_cal;
			crc_out:
			       if(cnt_out==3'd7)
				        next_state = idle;
				   else 
				        next_state = crc_output;
		endcase
end 

always@(posedge clk or negedge rst_n)  //计数输入
begin 
if(rst_n==1'b0)
    cnt_in<=6'd0;
else if(current_state
  • 4
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值