行为级描述
首先采用电路的行为级描述方式。
Verilog HDL设计代码为:
module counter5(clk, rst, cnt, co)
input clk
input rst
output co//输出为进位
reg co
output [2:0] cnt
reg[2:0] cnt
always@(posedge clk)
begin
if(rst)
begin
cnt <= 3'b000
co <= 1'b0
end
else if(cnt == 3'b100)
begin
cnt <= 3'b000
co <= 1'b1
end
else
begin
cnt <= cnt + 1'b1
co <= 1'b0
end
end
endmodule
登录后复制
ISE综合
RTL Schematic
展开后
Technology Schematic
状态机描述状态转移图
Verilog HDL代码
`timescale 1ns / 1ps
//
// Company:
// Engineer:
//
// Create Date:22:12:23 08/03/2018
// Design Name:
// Module Name:counter5
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//
module counter5(clk,rst, cnt, co)
input clk
input rst
output[2:0] cnt
output co
reg co
reg[2:0] pre_state, next_state
parameter s0 = 3'b000, s1 = 3'b001, s2 = 3'b010, s3 = 3'b011, s4 = 3'b100
always@(posedge clk or posedge rst)
begin
if(rst)
begin
pre_state <= s0
// co <= 1'b0
end
else
begin
pre_state <= next_state
end
end
always@(pre_state)
begin
case(pre_state)
s0:
begin
next_state = s1
co = 1'b0
end
s1:
begin
next_state = s2
co = 1'b0
end
s2:
begin
next_state = s3
co = 1'b0
end
s3:
begin
next_state = s4
co = 1'b0
end
s4:
begin
next_state = s0
co = 1'b1
end
default:
begin
next_state = s0
co = 1'b0
end
endcase
end
assign cnt = pre_state
endmodule
登录后复制
测试文件
`timescale 1ns/1ps
module counter5_tb
reg clk,rst
wire[2:0] cnt
wire co
always
begin
#10 clk = ~clk
end
initial
begin
clk = 1'b0
rst = 1'b1
#20 rst = 1'b0
end
counter5 u1(.clk(clk), .rst(rst), .cnt(cnt), .co(co))
endmodule
登录后复制
仿真波形
ISE综合
RTL Schematic
展开后
Technology Schematic
修正为同步复位
Verilog HDL语言描述
`timescale 1ns / 1ps
//
// Company:
// Engineer:
//
// Create Date:22:12:23 08/03/2018
// Design Name:
// Module Name:counter5
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//
module counter5(clk,rst, cnt, co)
input clk
input rst
output[2:0] cnt
output co
reg co
reg[2:0] pre_state, next_state
parameter s0 = 3'b000, s1 = 3'b001, s2 = 3'b010, s3 = 3'b011, s4 = 3'b100
always@(posedge clk )
begin
if(rst)
begin
pre_state <= s0
// co <= 1'b0
end
else
begin
pre_state <= next_state
end
end
always@(pre_state)
begin
case(pre_state)
s0:
begin
next_state = s1
co = 1'b0
end
s1:
begin
next_state = s2
co = 1'b0
end
s2:
begin
next_state = s3
co = 1'b0
end
s3:
begin
next_state = s4
co = 1'b0
end
s4:
begin
next_state = s0
co = 1'b1
end
default:
begin
next_state = s0
co = 1'b0
end
endcase
end
assign cnt = pre_state
endmodule
登录后复制
测试代码不变
省略
仿真波形图
ISE综合
RTL Schematic
Technology Schematic
注:用有限状态机这种描述方法中,出现了一系列的错误,这也是一个发现错误并解决的过程,解决问题的代价是很大的(时间的花费,心理的奔溃),但解决问题后的成就感是微妙的,问题见博文:Modelsim下进行功能仿真没问题,可是在ISE综合报错,如何解决?
结构性描述
其实还有一种描述方式,是结构性描述,但这种描述方式实在过于繁琐,例如本例如果采用结构性描述,就不得不画卡诺图,化简卡诺图,等等,真的很让人X疼,这不如让我用原理图来设计电路算了。
这里就不采用这种方式了,但这也不意味着结构性的描述方式一无是处,在有的场合还是需要的;
这三种描述方式有的时候可以混合使用,例如模60计数器的实现就可以采用模10计数器和模6计数器的级联来描述,见博客:
级联模60计数器(Verilog HDL语言描述)(仿真与综合)
这里的级联方式不就是一种结构性的描述吗?
而小的模块的描述则采用的是比价抽象的行为级描述方式。
简单的比较
从RTL Schematic中可以看出,行为级描述方式和有限状态机描述方式综合出来的电路还是有很大不同的:
行为级描述的RTL Schematic
或者选择soft(在综合时保持层次,在实现时有利用ISE软件自动进行优化),这样有利于你从模块中找到你想抓取的信号和信号名不被更改。2.在Constraints
的问题。其实ISE的工程设置有“keep_hierarchy”。在程序里面,也可以通过添加一些语句。如果是Verilog:
Place the Verilog constraint
immediately before the module or instantiation.
Specify the Verilog constraint asfollows:
(* KEEP = “{TRUE|FALSE |SOFT}” *)
假如我们要观察的一个信号cnt:reg[10:0]cnt,那么就按照
文档中的介绍,要保持此信号不被综合,则:(* KEEP =“TRUE” *)reg[10:0]cnt ,或者(*keep=“true” *)reg[10:0]cnt
这样就可以实现ChipScope的观察而不被优化掉了。类似的VHDL:
Declare the VHDL constraint asfollows:
attribute keep : string
根据个人经验。据个人经验,在Xilinx ISE下综合、布局布线时可以选择Design &Goals这个策略选择开始于综合阶段。ise综合之后根据个人经验手动更改布局布线。国际证券交易所(International Securities Exchange, Inc., ISE)于2000年5月成立,是美国期权市场第一家全电子化交易的期权交易所。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)