微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 微电子和IC设计 > IC后端设计交流 > 请大侠们看看我的程序错在哪里

请大侠们看看我的程序错在哪里

时间:10-02 整理:3721RD 点击:
这是个6位二进制转8位BCD码,5路输入输出,test是做测试用,检测到state==READ 时,状态不再变,并且不读数据。请各位指点一下,不胜感激~
//
//
modulebin2bcd (IN1,IN2,IN3,IN4,IN5,
clk,
showsign_in,
bitsign_in,
IN1bcd_out,IN2bcd_out,IN3bcd_out,IN4bcd_out,IN5bcd_out,
showsign_out,
bitsign_out,
test);

input[5:0]IN1,IN2,IN3,IN4,IN5;
inputclk;
input[4:0]showsign_in;
inputbitsign_in;
output[7:0]IN1bcd_out,IN2bcd_out,IN3bcd_out,IN4bcd_out,IN5bcd_out,test;
output[4:0]showsign_out;
outputbitsign_out;
reg[7:0]IN1bcd_out,IN2bcd_out,IN3bcd_out,IN4bcd_out,IN5bcd_out,IN1bcd,IN2bcd,IN3bcd,IN4bcd,IN5bcd;
reg[4:0]showsign_out,showsign_reg;
regbitsign_out,bitsign_reg;
reg[5:0]IN1reg,IN2reg,IN3reg,IN4reg,IN5reg;
reg[2:0]state;
reg[2:0]dex;
regcount;
reg[7:0]testreg;
parameterIDLE=3'b111;
parameterREAD=3'b101;
parameterYIWEI=3'b100;
parameterYUNSUAN=3'b110;
parameterJIEGUO=3'b000;
assign test=testreg;
always @(negedge clk) begin

case (state)

IDLE: begin state<=READ; dex<=3'b000; testreg<=8'b0000_0001; end

READ: begin

testreg<=8'b0000_0011;
IN1reg<=IN1;
IN2reg<=IN2;
IN3reg<=IN3;
IN4reg<=IN4;
IN5reg<=IN5;
dex<=3'b000;
IN1bcd<=7'h00;
IN2bcd<=7'h00;
IN3bcd<=7'h00;
IN4bcd<=7'h00;
IN5bcd<=7'h00;

showsign_reg<= showsign_in;
bitsign_reg<=bitsign_in;
state<=YIWEI;

end
YIWEI:begin testreg<={(|dex),7'b000_0111};
if(dex==3'd5) begin
IN1bcd<=(IN1bcd<< 1'b1) +IN1reg[5];
IN2bcd<=(IN2bcd<< 1'b1) +IN2reg[5];
IN3bcd<=(IN3bcd<< 1'b1) +IN3reg[5];
IN4bcd<=(IN4bcd<< 1'b1) +IN4reg[5];
IN5bcd<=(IN5bcd<< 1'b1) +IN5reg[5];
state<=JIEGUO;
end
else begin
dex<=dex + 1'b1;
IN1reg<=IN1reg << 1'b1;
IN2reg<=IN2reg << 1'b1;
IN3reg<=IN3reg<< 1'b1;
IN4reg<=IN4reg<< 1'b1;
IN5reg<=IN5reg<< 1'b1;
IN1bcd<=(IN1bcd<< 1'b1) +IN1reg[5];
IN2bcd<=(IN2bcd<< 1'b1) +IN2reg[5];
IN3bcd<=(IN3bcd<< 1'b1) +IN3reg[5];
IN4bcd<=(IN4bcd<< 1'b1) +IN4reg[5];
IN5bcd<=(IN5bcd<< 1'b1) +IN5reg[5];
state<=YUNSUAN;
count<=1'b0;
end
end
YUNSUAN:begintestreg<={(|dex),7'b000_1111};
if(count) begin
IN1bcd<=IN1bcd + ((IN1bcd[7:4]>4'b100)?8'b0011_0000:8'b0000_0000);
IN2bcd<=IN2bcd + ((IN2bcd[7:4]>4'b100)?8'b0011_0000:8'b0000_0000);
IN3bcd<=IN3bcd+ ((IN3bcd[7:4]>4'b100)?8'b0011_0000:8'b0000_0000);
IN4bcd<=IN4bcd+ ((IN4bcd[7:4]>4'b100)?8'b0011_0000:8'b0000_0000);
IN5bcd<=IN5bcd+ ((IN5bcd[7:4]>4'b100) ?8'b0011_0000:8'b0000_0000);
state<=YIWEI;
end
elsebegin
count<=1'b1;
IN1bcd<=IN1bcd + ((IN1bcd[3:0]>4'b100)?4'b0011:4'b0000);
IN2bcd<=IN2bcd + ((IN2bcd[3:0]>4'b100)?4'b0011:4'b0000);
IN3bcd<=IN3bcd+ ((IN3bcd[3:0]>4'b100)?4'b0011:4'b0000);
IN4bcd<=IN4bcd+ ((IN4bcd[3:0]>4'b100)?4'b0011:4'b0000);
IN5bcd<=IN5bcd+ ((IN5bcd[3:0]>4'b100) ?4'b0011:4'b0000);
end
end
JIEGUO:begin testreg<=8'b0001_1111;
IN1bcd_out<=IN1bcd;
IN2bcd_out<=IN2bcd;
IN3bcd_out<=IN3bcd;
IN4bcd_out<=IN4bcd;
IN5bcd_out<=IN5bcd;
showsign_out<=showsign_reg;
bitsign_out<=bitsign_reg;
dex<=3'b000;
state<=READ;
end
default: begin state<=IDLE; testreg<=8'b1111_1111; end
endcase



end
endmodule

太长了吧,看不下去!

已经找到毛病了,还是要谢谢大家

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top