用CPLD做编码器的解码,用的是状态机写的485通讯,遇到一个很奇怪的问题,写的状态机如下:
case(state)
Idle:
begin
over <= 1'b0;
txd <= 1'b1;
if(start_fg == 1'b1)
begin
state <= Request;
E_c <= 1'b1;
start_fg1 <= 1'b1;
end
end
Request:
begin
if(i == 8'd10)
begin
state <= Wait;
start_fg1 <= 1'b0;
E_c <= 1'b0;
CF_r <= 10'd0;
txd <= 1'b1;
i <= 6'd0;
end
else
begin
txd <= CF[6'd9-i];
i <= i+1'b1;
end
end
Wait:
begin
txd <= 1'b1;
E_b <= 1'b1;
if(CF_r[3:0] == 4'b0010)
begin
state <= Receive;
i <= 6'd0;
CF_r <= (CF_r << 1)|re;
i <= 6'd4;
end
else
begin
CF_r <= (CF_r << 1)|re;
if(i == 4'd14)
begin
state <= Idle;
erro <= 2'd3;
end
else
begin
i <= i+1'b1;
end
end
end
Receive:
begin
if(i < 6'd9)
begin
CF_r <= (CF_r << 1)|re;
i <= i+1'b1;
end
else if(i == 6'd9)
begin
if(CF_r == CF)
begin
CRC_buf <= CRC_buf|{CF_r[8:1],40'd0};
CF_r <= (CF_r << 1)|re;
i <= i+1'b1;
end
else
begin
state <= Idle;
i <= 0;
erro <= 2'd0;
end
end
else if(i < 6'd19)
begin
CF_r <= (CF_r << 1)|re;
i <= i+1'b1;
end
else if(i == 6'd19)
begin
if(CF_r[4] | CF_r[3])
begin
erro <= 2'd2;
i <= i+1'b1;
end
else
begin
CRC_buf <= CRC_buf|{CF_r[8:1],32'd0};
DATA_TEMP <= (DATA_TEMP >> 1)|{re, 29'd0};
i <= i+1'b1;
end
end
else if(i < 6'd49)
begin
DATA_TEMP <= (DATA_TEMP >> 1)|{re, 29'd0};
i <= i+1'b1;
end
else if(i < 6'd59)
begin
CF_r <= (CF_r << 1)|re;
i <= i+1'b1;
end
else
begin
DATA_TEMP[23:0] = {DATA_TEMP[28:21],DATA_TEMP[18:11],DATA_TEMP[8:1]};
for(i = 6'd0; i < 24; i = i+1'd1)
begin
CRC_buf[31-i] = DATA_TEMP;
end
CRC_buf = CRC_buf|CF_r[8:1];
for(i = 6'd47; i > 6'd7; i = i-1'b1)
begin
CRC_buf[47:40] = {CRC_buf[46:40],(CRC_buf[47]^CRC_buf[39])};
CRC_buf[39:0] = CRC_buf[38:0]<<1; //shift
end
if (!CRC_buf[47:40])
begin
DATA_LAST =DATA; //24'd3;//
DATA =DATA_TEMP[23:0]; //24'h01fffd; //
end
else
begin
CRC_buf[47:40]=8'd0;
DATA=24'hffffff;
end
state <= Idle;
E_b <= 1'd0;
i <= 6'd0;
over <= 1'd1;
end
end
endcase
加了一句如下划线的语句后,状态机不跳了,txd没有输出,看RTL Viewer太复杂了查不过来,有没有哪位有经验的前辈能够指点一下这会是什么原因呢?DATA跟状态机完全没有关系呢。。
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
与电子爱好者谈读图四被打赏50分 | |
与电子爱好者谈读图二被打赏50分 | |
【FRDM-MCXN947评测】Core1适配运行FreeRtos被打赏50分 | |
【FRDM-MCXN947评测】双核调试被打赏50分 | |
【CPKCORRA8D1B评测】---移植CoreMark被打赏50分 | |
【CPKCORRA8D1B评测】---打开硬件定时器被打赏50分 | |
【FRDM-MCXA156评测】4、CAN loopback模式测试被打赏50分 | |
【CPKcorRA8D1评测】--搭建初始环境被打赏50分 | |
【FRDM-MCXA156评测】3、使用FlexIO模拟UART被打赏50分 | |
【FRDM-MCXA156评测】2、rt-thread MCXA156 BSP制作被打赏50分 |