您的位置:首页 > 其它

并行流水灯设计方法

2015-04-15 17:48 183 查看
这种设计方法与前面一篇一样仍是并行建模,建立Flash_module和Run_module两个模型,这两个模型在顶层模块中并行执行。

1、流水灯模块(相当于一个计数器:001>010->100->000->001)

(1)、建模:

module Run_module(clock,reset,Led_out);

input clock,reset;

output [2:0]Led_out;

reg [2:0]Led_out;

reg [2:0]count1;

reg [1:0]count2;

always @(posedge clock,negedge reset)

if(!reset)

count1<=3'd0;

else if(count1==3'd7)

count1<=3'd0;

else

count1<=count1+3'd1;

always @(posedge clock,negedge reset)

if(!reset)

count2<=2'd0;

else if(count2==2'd2)

count2<=2'd0;

else if(count1==3'd7)

count2<=count2+2'd1;

always @(posedge clock,negedge reset)

if(!reset)

Led_out=3'b001;

else if(count2==2'd2)

case(Led_out)

3'b000 : Led_out<=3'b001;

3'b001 : Led_out<=3'b010;

3'b010 : Led_out<=3'b100;

3'b100 : Led_out<=3'b000;

endcase

endmodule

(2)、仿真:

`include "Run_module.v"

module run_stimulus;

reg clk;

reg reset;

//wire [7:0]count;

wire [2:0]LED_out;

//Run_module led(clock,reset,Led_out)

Run_module led(clk,reset,LED_out);

initial

begin

clk=1;

forever #5 clk=~clk;

end

initial

begin

reset=0;

#10 reset=1;

#800 reset=0;

end

endmodule

(3)出错点:

在建模的端口声明中,声明Led_out时,直接写成 reg Led_out;没有指明Led_out的位数,导致出现如下错误(端口不匹配)


仿真的波形如下(除了最低位,其他位都显示高阻值z):


3、顶层模块:

(1)、建模:

`include "Run_module.v"

`include "Flash_module.v"

module Top_module(CLK,RST,Flash_Out,Run_Out);

input CLK,RST;

output Flash_Out;

output [2:0]Run_Out;

reg Flash_Out;

reg [2:0]Run_Out;

Flash_module fo(CLK,RST,Flash_Out);

Run_module ro(CLK,RST,Run_Out);

endmodule

(2)、仿真:

`include "Top_module.v"

module top_module_stimulus;

reg clk;

reg reset;

wire Flash_Out;

wire [2:0]Run_Out;

Top_module led(clk,reset,Flash_Out,Run_Out);

initial

begin

clk=0;

forever #5 clk=~clk;

end

initial

begin

reset=0;

#5 reset=1;

#1000 reset=0;

end

endmodule

(3)、仿真波形:



(4)所犯错误:



这是因为,我在编写top_module模块时,做了如下定义:

reg Flash_Out;

reg [2:0]Run_Out;

但在top_module_stimulus仿真模块中,Flash_Out和 [2:0]Run_Out都是wire类型的,端口不匹配!!!

总结:

查了一个下午的错,终于找到了源头,好吧,我发现了新错误!!!编码时要小心啊!编写多个模块时,出现错误,还是给每个模块分别写testbench,看哪个模块仿真错误吧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: