仿真的激励信号错在哪里呀? 谢谢
时间:10-02
整理:3721RD
点击:
一个点灯程序的部分代码:
assign sw = {sw0,sw1,sw2,sw3};
assign {led0,led1,led2,led3,led4,led5,led6,led7} = led;
always @ ( posedge clk or negedge rst)
begin
if(!rst)
led<='b0;
else
case ( sw )
4'b1110: led <= 8'b0000_0001;
4'b1101: led <= 8'b0000_0010;
4'b1011: led <= 8'b0000_0100;
4'b0111: led <= 8'b0000_1000;
4'b1100: led <=8'b0001_0000;
烧到板子里时,按下sw0 ,板子上的LED5灯是亮的, 即led4=1 ,
4'b1001: led <= 8'b0010_0000;
4'b0011: led <= 8'b0100_0000;
4'b0110: led <= 8'b1000_0000;
default: led <= 8'b0000_0000;
但是,仿真时,就出了问题,仿真是对激励如下:
initial begin
//Initialize Inputs
clk= 0;
rst= 0;
sw0= 0;
sw1= 0;
sw2= 0;
sw3= 0;
//Wait 100 ns for global reset to finish
#100;
//Add stimulus here
clk=1;
rst=1;
//#100;
sw0=0;sw1=0;sw2=1;sw3=1;
此处符合:4'b1100: led <= 8'b0001_0000;
#100clk=0;rst=0;
End
但是,isim里的波形对不上如下图
Led4,的值应该是 1 才对呀,,,是什么问题呢?
谢谢
assign sw = {sw0,sw1,sw2,sw3};
assign {led0,led1,led2,led3,led4,led5,led6,led7} = led;
always @ ( posedge clk or negedge rst)
begin
if(!rst)
led<='b0;
else
case ( sw )
4'b1110: led <= 8'b0000_0001;
4'b1101: led <= 8'b0000_0010;
4'b1011: led <= 8'b0000_0100;
4'b0111: led <= 8'b0000_1000;
4'b1100: led <=8'b0001_0000;
烧到板子里时,按下sw0 ,板子上的LED5灯是亮的, 即led4=1 ,
4'b1001: led <= 8'b0010_0000;
4'b0011: led <= 8'b0100_0000;
4'b0110: led <= 8'b1000_0000;
default: led <= 8'b0000_0000;
但是,仿真时,就出了问题,仿真是对激励如下:
initial begin
//Initialize Inputs
clk= 0;
rst= 0;
sw0= 0;
sw1= 0;
sw2= 0;
sw3= 0;
//Wait 100 ns for global reset to finish
#100;
//Add stimulus here
clk=1;
rst=1;
//#100;
sw0=0;sw1=0;sw2=1;sw3=1;
此处符合:4'b1100: led <= 8'b0001_0000;
#100clk=0;rst=0;
End
但是,isim里的波形对不上如下图
Led4,的值应该是 1 才对呀,,,是什么问题呢?
谢谢
这不是四位的0011么?怎么会是1100?
应该是这一条吧4'b0011: led <= 8'b0100_0000;
时钟不对,时钟clk上升沿时,对应的sw0= 0;sw1= 0;sw2= 0; sw3= 0;
你的仿真程序中没有时钟信号,现在的程序相当于是clk赋值两次,但没有真正时钟产生。
仿真语句中时钟要使用always #10 clk=~clk; 表示每10个时间单位clk翻转一次。