FPGA部分语法
{ }变成了begin和and
<位宽><进制><数字>这种描述方式。
重点是位宽指的是二进制位宽,如果16进制一个数占4个位宽。
用“always”块
如:always@(posedge clk or posedge clr)是类似while语句的
使用ise14.7跑例子的坑
timescale
`timescale 10ns / 1ns
timescale 仿真时间单位 / 时间精度
注意:用于说明仿真时间单位和时间精度的数字只能是1、10、100,不能为其它的数字。而且,时间精度不能比时间单位还要大。最多两则一样大。
https://blog.csdn.net/zhenzhen90/article/details/8784099 有例子
形象理解:
timescale对相对时间的影响
如果设定`timescale 1ns/1ps,#100是相对时间,等价于#100ns,而#100.1111会被认为是#100.111ns,因为它的精度高于timescaled的时间精度,而被四舍五入。
https://www.cnblogs.com/hxxy/articles/3574141.html
前面的是单位时间 后面的是处理的时间精度
综合
行为仿真
分频器代码
–top.v–
`timescale 10ns / 1ns
module top(
input CLK,
input RST,
output reg[3:0] cnter); //端口声明
reg[26:0] buf_cnter;
always @ (posedge CLK or posedge RST)
begin
if (RST)
begin
buf_cnter <= 27'b0; //置位时赋初值
cnter <= 4'b0;
end
else
begin
if(buf_cnter == 27'd499) //设置分频系数
begin
buf_cnter <= 0; //分频计数器计数到最大后置位
if(cnter == 4'b1111) //判断4位计数器是否计数到最大值
cnter <= 4'b0; //置位
else
cnter <= cnter + 1'b1; // 4位计数器计数
end
else
buf_cnter <= buf_cnter + 1'b1; //分频器计数
end
end
endmodule
top描述了一个分频器,RST脉冲上升沿负责重置buf_cnter和 cnter。
CLK是时钟,只要上升沿就判断buf_cnter是否达到499,否则buf_cnter+1,(每500个时钟上升沿,做一次操作,分频器的核心)
到499后,判断cnter是否达到最大,最大就复位,否则就cnter+1。(计数器,没懂,是不是改成2进制更好一点)
test.v
`timescale 10ns / 1ns
module test;
// Inputs
reg CLK;
reg RST;
// Outputs
wire [3:0] cnter;
// Instantiate the Unit Under Test (UUT)
top uut (
.CLK(CLK),
.RST(RST),
.cnter(cnter)
);
initial begin
// Initialize Inputs
CLK = 0;
RST = 1;
// Wait 100 ns for global reset to finish
#800;
RST = 0;
// Add stimulus here
end
always begin
#100;CLK=~CLK;
end
endmodule
为测试模块
`timescale 10ns / 1ns两个文件应该保持一致。test负责生成clk 及部分初始化任务
输入法
不能用中文输入法 否则崩溃,问题待解决。