并行流水灯设计方法
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,看哪个模块仿真错误吧。
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,看哪个模块仿真错误吧。
相关文章推荐
- 并行口设计花样流水灯实验
- 流水灯并行设计
- 用定时器来定时,分别使用中断和查询方法,设计流水灯
- C++多核高级编程 - 07 应用程序并行设计方法 (PADL 和 PBS)
- 并行口设计花样流水灯实验
- ASIC设计中一种通用型并行设计方法
- 数据库表结构设计方法及原则
- 简单干净的C#方法设计案例:SFCUI.AjaxLoadPage()之一
- 23种设计模式之模板方法模式
- java设计模式学习笔记之模块方法模式
- 软件设计和数据库设计方法
- main方法的详解、单例设计模式、Hadoop简介
- java设计模式----模板方法模式
- 测试用例设计白皮书--因果图方法
- FPGA基础设计(一):VGA显示方法(文字、图形、波形)的全方面解析
- 采用[ICONIX] 方法实践BLOG设计之七 [关键设计复核]
- 传统的概要设计 详细设计是不是面向过程或者是数据流的分析方法
- 2. JavaScript 设计模式(简单工厂,工厂方法,抽象工厂)
- java设计模式(行为型)之模板方法模式