这是一篇我的心得,写verilog的心得,啊,对于
学习
verilog
设计
FPGA的同学一定会有帮助的啊!
本人就例子来教大家怎样提取关键路径:
先解释一下什么叫关键路径
所谓关键路径就是,在电路中频繁调用,而且延迟过长,
或者产生意外的几率比较大的线路。
1:组合电路中的关键路径提取:
q=a&b&c|d&e&b;
这个很简单了,估计大家都会的,因为b的传输要两级,
可以简单的提取b作为一级的:
q=(a&c|d&e)&b
2: always——block中的关键路径提取:
always中关键路径的提取一般用分步法提取,请看下面一个
always——block,
always@(in)
begin
if(!a)
if(c&&(!b&&e))
out=out1;
else out=out2;
else if(b&&e) out =out1;
end
这里面e是关键路径,我们可以分两个步骤提取关键路径
(1) 当e=1的时候有:
if(!a)
if(c&&(!b))
out=out1;
else out=out2;
(2)当e=0的时候有:
if(!a) out=out2;
因此这个always可以写成这个样子:
always@(in)
begin
if(e)
if(!a)
if(c&&(!b))
out=out1;
else out=out2;
else if(!a) out=out2;
end
这是中间形式,还要写成最终形式:
定义两个临时变量,为了在综合时候,被 综合掉,要定义他们
为输出端口(output)——切记!!!
output out_temp1,out_temp2;
out_temp1=a?out
c&&(!b))?out1
ut2;
out_temp2=a?out
ut2;
assign out=e?out_temp1
ut_temp2;
好了,这个已经提取成功!~
再来看第三个例子,在应用中经常用到的啊
3。FSM中的关键路径的提取:关于状态机,这是FPGA设计必备的基础,编码方式有很多中比如:one——hot,or one--cool
还有就是组合电路和 时序 电路的写法,这里主要讲关键路径的提取至于状态机的写法,还是查阅一下 资料啊!
FSM中关键路径的提取方法一般是先将要提取的关键路径去掉
然后将原来FSM中的next-state用另外一个符号代替,作为次FSM 的输入,即有主从两个FSM。
来看一下这个简单的状态机啊:
pa rameter s0=0;
parameter s1=1;
parameter s2=2;
parameter s3=3;
input in1,in2,in3,set;
reg[1:0] nextstate,currentstate;
always@(in1 or in2 or in3 or currentstate)
begin
nextstate=s0;// start state
case(currentstate)
s0: if(in1&&!set)
nextstate=s1;
else if(set) nextstate=s2;
s1:if(in2&&set)
nextstate=s3;
else if(!set) nextstate=s2;
s2:if(set) nexstate=s3;
s3:if(in3) nextstate=s0;
default:nextstate=s0;
endcase
end
好,现在来看第一步,将状态机中的关键路径去掉,这里的关键路径为set,试想如果状态从s0一路到s3,都是set在起作用,如果有一个不小心的毛刺产生,就会执行错误的行为,所以这里的set为关键路径。
提取后的状态机如下:
reg[1:0]temp;
always@(in1 or in2 or in3 or currentstate)
begin
nextstate=s0;// start state
temp=s0;
case(currentstate)
s0: if(in1)
temp=s1;
s1:if(in2)
temp=s3;
s2: temp=temp;
s3:if(in3) temp=s0;
default:temp=s0;
endcase
end
第二步:
always2(temp or currentstate or set)
begin
case(currentstate)
s0:if(!set)
nextstate=temp
else nextstate=s2;
s1: if(set)
nextstate=temp;
else nextstate=s2;
s2:if(set) nextstate=s3;
else nextstate=temp;
s3: nextstate=temp;
default:nextstate=temp;
endcase
end
本人就例子来教大家怎样提取关键路径:
先解释一下什么叫关键路径
所谓关键路径就是,在电路中频繁调用,而且延迟过长,
或者产生意外的几率比较大的线路。
1:组合电路中的关键路径提取:
q=a&b&c|d&e&b;
这个很简单了,估计大家都会的,因为b的传输要两级,
可以简单的提取b作为一级的:
q=(a&c|d&e)&b
2: always——block中的关键路径提取:
always中关键路径的提取一般用分步法提取,请看下面一个
always——block,
always@(in)
begin
if(!a)
if(c&&(!b&&e))
out=out1;
else out=out2;
else if(b&&e) out =out1;
end
这里面e是关键路径,我们可以分两个步骤提取关键路径
(1) 当e=1的时候有:
if(!a)
if(c&&(!b))
out=out1;
else out=out2;
(2)当e=0的时候有:
if(!a) out=out2;
因此这个always可以写成这个样子:
always@(in)
begin
if(e)
if(!a)
if(c&&(!b))
out=out1;
else out=out2;
else if(!a) out=out2;
end
这是中间形式,还要写成最终形式:
定义两个临时变量,为了在综合时候,被 综合掉,要定义他们
为输出端口(output)——切记!!!
output out_temp1,out_temp2;
out_temp1=a?out
![](https://i-blog.csdnimg.cn/blog_migrate/2807fd639b99fdd24c3437426d9a55f8.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a7af074e79f1d349bab44938bce2b269.png)
out_temp2=a?out
![](https://i-blog.csdnimg.cn/blog_migrate/a7af074e79f1d349bab44938bce2b269.png)
assign out=e?out_temp1
![](https://i-blog.csdnimg.cn/blog_migrate/a7af074e79f1d349bab44938bce2b269.png)
好了,这个已经提取成功!~
再来看第三个例子,在应用中经常用到的啊
3。FSM中的关键路径的提取:关于状态机,这是FPGA设计必备的基础,编码方式有很多中比如:one——hot,or one--cool
还有就是组合电路和 时序 电路的写法,这里主要讲关键路径的提取至于状态机的写法,还是查阅一下 资料啊!
FSM中关键路径的提取方法一般是先将要提取的关键路径去掉
然后将原来FSM中的next-state用另外一个符号代替,作为次FSM 的输入,即有主从两个FSM。
来看一下这个简单的状态机啊:
pa rameter s0=0;
parameter s1=1;
parameter s2=2;
parameter s3=3;
input in1,in2,in3,set;
reg[1:0] nextstate,currentstate;
always@(in1 or in2 or in3 or currentstate)
begin
nextstate=s0;// start state
case(currentstate)
s0: if(in1&&!set)
nextstate=s1;
else if(set) nextstate=s2;
s1:if(in2&&set)
nextstate=s3;
else if(!set) nextstate=s2;
s2:if(set) nexstate=s3;
s3:if(in3) nextstate=s0;
default:nextstate=s0;
endcase
end
好,现在来看第一步,将状态机中的关键路径去掉,这里的关键路径为set,试想如果状态从s0一路到s3,都是set在起作用,如果有一个不小心的毛刺产生,就会执行错误的行为,所以这里的set为关键路径。
提取后的状态机如下:
reg[1:0]temp;
always@(in1 or in2 or in3 or currentstate)
begin
nextstate=s0;// start state
temp=s0;
case(currentstate)
s0: if(in1)
temp=s1;
s1:if(in2)
temp=s3;
s2: temp=temp;
s3:if(in3) temp=s0;
default:temp=s0;
endcase
end
第二步:
always2(temp or currentstate or set)
begin
case(currentstate)
s0:if(!set)
nextstate=temp
else nextstate=s2;
s1: if(set)
nextstate=temp;
else nextstate=s2;
s2:if(set) nextstate=s3;
else nextstate=temp;
s3: nextstate=temp;
default:nextstate=temp;
endcase
end