modelsim里
仿真出现的问题,网上的也看了一些,不太懂,找不到解决方法呀,求大神帮一下忙
uart的tx模块:
module data_tx(clk_bps,reset,tx_en,data_from_fifo,flag_tx,data_to_rs232);
input clk_bps,reset,tx_en;//tx_en±íʾ·¢ËÍʹÄÜÐźţ¬1±íʾÓÐЧ
input [7:0]data_from_fifo;
output reg flag_tx;//·¢ËͱêÖ¾£¬1±íʾ·¢ËÍÍê³É
output wire data_to_rs232;//´®ÐÐÊý¾ÝÊä³ö
reg data_tx;
reg busy_tx;//1±íʾ·¢ËÍ״̬棬0±íʾ¿ÕÏÐ
reg [7:0]data_tx_reg;
reg [3:0]cnt_tx;
reg n_state;
reg c_state;
always@(posedge clk_bps or negedge reset)
begin
if(!reset)
cnt_tx<=4'd0;
else if(cnt_tx==4'd10)
cnt_tx<=4'd0;
else
cnt_tx<=cnt_tx+1'b1;
end
parameter idle=1;
parameter tx_state=2;
parameter tx_done=3;
assign data_to_rs232=data_tx;
always@(posedge clk_bps or negedge reset)
begin
if(!reset)
c_state<=idle;
else
c_state<=n_state;
end
always@(posedge clk_bps or negedge reset)
begin
if(!reset)
begin
cnt_tx<=4'd0;
busy_tx<=1'b0;
flag_tx<=1'b0;
end
else
case(c_state)
idle:
begin
cnt_tx<=4'd0;
busy_tx<=1'b0;
flag_tx<=1'b0;
data_tx<=1'b1;
end
tx_state:
begin
case(cnt_tx)
0:
begin
cnt_tx<=cnt_tx+1'b1;
busy_tx<=1'b1;
flag_tx<=1'b0;
data_tx<=1'b0;
end
1:
begin
cnt_tx<=cnt_tx+1'b1;
busy_tx<=1'b1;
flag_tx<=1'b0;
data_tx<=data_from_fifo[0];
end
2:
begin
cnt_tx<=cnt_tx+1'b1;
busy_tx<=1'b1;
flag_tx<=1'b0;
data_tx<=data_from_fifo[1];
end
3:
begin
cnt_tx<=cnt_tx+1'b1;
busy_tx<=1'b1;
flag_tx<=1'b0;
data_tx<=data_from_fifo[2];
end
4:
begin
cnt_tx<=cnt_tx+1'b1;
busy_tx<=1'b1;
flag_tx<=1'b0;
data_tx<=data_from_fifo[3];
end
5:
begin
cnt_tx<=cnt_tx+1'b1;
busy_tx<=1'b1;
flag_tx<=1'b0;
data_tx<=data_from_fifo[4];
end
6:
begin
cnt_tx<=cnt_tx+1'b1;
busy_tx<=1'b1;
flag_tx<=1'b0;
data_tx<=data_from_fifo[5];
end
7:
begin
cnt_tx<=cnt_tx+1'b1;
busy_tx<=1'b1;
flag_tx<=1'b0;
data_tx<=data_from_fifo[6];
end
8:
begin
cnt_tx<=cnt_tx+1'b1;
busy_tx<=1'b1;
flag_tx<=1'b0;
data_tx<=data_from_fifo[7];
end
9:
begin
cnt_tx<=4'd0;
busy_tx<=1'b1;
flag_tx<=1'b0;
data_tx<=1'b1;
end
default:
begin
cnt_tx<=4'd0;
busy_tx<=1'b1;
flag_tx<=1'b0;
data_tx<=1'b1;
end
endcase
end
tx_done:
begin
cnt_tx<=4'd0;
busy_tx<=1'b1;
flag_tx<=1'b1;
data_tx<=1'b1;
end
default:
begin
cnt_tx<=4'd0;
busy_tx<=1'b0;
flag_tx<=1'b0;
data_tx<=1'b1;
end
endcase
end
always@(c_state)
begin
case(c_state)
idle:
begin
if(!busy_tx&tx_en)//·¢ËÍʹÄÜÓÐЧ²¢ÇÒ·¢ËͲ»Ã¦
c_state<=tx_state;
else
c_state<=idle;
end
tx_state:
begin
if(cnt_tx==4'd9)
c_state<=tx_done;
else
c_state<=tx_state;
end
tx_done:
begin
c_state<=idle;
end
default:c_state<=idle;
endcase
end
endmodule
........................................................................................................................................................
tx模块的测试模块:
`
timescale 10ps/1ps
module data_tx_tb();
reg clk_bps,reset,tx_en;
reg [7:0]data_from_fifo;
wire flag_tx,data_to_rs232;
data_tx tx_tb(.clk_bps(clk_bps),.reset(reset),.tx_en(tx_en),.data_from_fifo(data_from_fifo),
.flag_tx(flag_tx),.data_to_rs232(data_to_rs232));
always
begin
#1 clk_bps<=~clk_bps;
end
initial
begin
clk_bps<=1'b0;
reset<=1'b0;
tx_en<=1'b0;
data_from_fifo<=8'd0;
#10 data_from_fifo<=8'd1;
#2 reset<=1'b1;
#10 tx_en<=1'b1;
#10 data_from_fifo<=8'd2;
#50 data_from_fifo<=8'd3;
#50 data_from_fifo<=8'd4;
#50 data_from_fifo<=8'd5;
#50 data_from_fifo<=8'd6;
#50 data_from_fifo<=8'd7;
#50 data_from_fifo<=8'd8;
#50 data_from_fifo<=8'd9;
#50 data_from_fifo<=8'd10;
#50 data_from_fifo<=8'd11;
#50 data_from_fifo<=8'd12;
#50 data_from_fifo<=8'd13;
#50 data_from_fifo<=8'd14;
#50 data_from_fifo<=8'd15;
#50 data_from_fifo<=8'd16;
#10tx_en<=1'b0;
#20 data_from_fifo<=8'd1;
end
endmodule
一周热门 更多>