您当前的位置:五五电子网电子知识电子学习基础知识电脑-单片机-自动控制使用SignalTap II观察reg与wire值 正文
使用SignalTap II观察reg与wire值

使用SignalTap II观察reg与wire值

点击数:7970 次   录入时间:06-23 08:02:01   整理:http://www.55dianzi.com   电脑-单片机-自动控制

写Verilog时,虽然每个module都会先用ModelSim或QUARTus II自带的simulator仿真过,但真的将每个module合并时,一些不可预期的“run-time”问题可能才一一浮现,这时得靠SignalTap II来帮忙debug。


使用环境:Quartus II 8.0 + DE2-70 (Cyclone II EP2C70F896C6N)

实际使用SignalTap II时,会发现有些reg与wire可以观察,有些又无法观察,本文整理出完整的reg与wire观察方法。

观察reg

SSignalTapII_register_not_preserve.v / Verilog

 

  1. module SignalTapII_register_not_preserve (  
  2.   input ICLK,  
  3.   input iRST_N  
  4. );  
  5.  
  6. reg [3:0] cnt;  
  7.  
  8. always@(posedge iCLK, negedge iRST_N) begin  
  9.   if (!iRST_N)  
  10.     cnt <= 4'h0;  
  11.   else 
  12.     cnt <= cnt + 4'h1;  
  13. end  
  14.  
  15. endmodule  


 

这是个很简单的计数器,我故意让cnt不做output,而想用SignalTap II去观察cnt这个reg的值。

signaltap2_reg0 

cnt都是0,显然不合理,表示SignalTap II无法capture cnt这个reg的值。为什么会这样呢?

若我们将SignalTap II拿掉,重新用Quartus II编译,观察其compilation report,显示register为0。

signaltap2_reg1

观察RTL Viewer的合成结果,真的没有register!!

signaltap2_reg2

这证明了一件事情,Quartus II在合成时,发现cnt并没有需要output,而自动最佳化不合成cnt,导致SignalTap II无法观察reg,不过有时为了debug方便,我们就是想观察这种reg,有办法让Quartus II暂时不要启动最佳化吗?

使用Synthesis Attribute避免最佳化

SignalTapII_register_preserve.v / Verilog

  1. module SignalTapII_register_preserve (  
  2.   input iCLK,  
  3.   input iRST_N  
  4. )  
  5.  
  6. reg [3:0] cnt /*synthesis noprune*/;  
  7.  
  8. always@(posedge iCLK, negedge iRST_N) begin  
  9.   if (!iRST_N)  
  10.     cnt <= 4'h0;  
  11.   else 
  12.     cnt <= cnt + 4'h1;  
  13. end  
  14.  
  15. endmodule 


6行
reg [3:0] cnt /*synthesis noprune*/;

多了/*synthesis noprune*/这个synthesis attribute,指示Quartus II不要对cnt做最佳化,保留此register以供SignalTap II观察,注意必须写在分号前面,不能如下写在分号后面。

reg [3:0] cnt;/*synthesis noprune*/ //错!! 

编译后,SignalTap II就能顺利的观察到cnt的值!!重点是不需改top module的interface,只需对想观察的reg加上synthesis attribute即可。

signaltap2_reg3

Quartus II也支援Verilog 2001的語法

  1. module SignalTapII_register_preserve (  
  2.   input iCLK,  
  3.   input iRST_N  
  4. );  
  5.  
  6. // Verilog 2001  
  7. //(*noprune*) reg [3:0] cnt;  
  8.  
  9. always@(posedge iCLK, negedge iRST_N) begin  
  10.   if (!iRST_N)  
  11.     cnt <= 4'h0;  
  12.   else 
  13.     cnt <= cnt + 4'h1;  
  14. end  
  15.  
  16. endmodule  


7行
(*noprune*) reg [3:0] cnt;

这是Verilog 2001的语法,Quartus II 8.0也能看得懂。

若希望整个module的reg都不被最佳化,可将synthesis attribute放在module。

  1. module SignalTapII_register_preserve (  
  2.   input iCLK,  
  3.   input iRST_N  
  4. ) /*synthesis noprune*/;  
  5.  
  6. reg [3:0] cnt;  
  7.  
  8. always@(posedge iCLK, negedge iRST_N) begin  
  9.   if (!iRST_N)  
  10.     cnt <= 4'h0;  
  11.   else 
  12.     cnt <= cnt + 4'h1;  
  13. end  
  14.  
  15. endmodule  


1行
module SignalTapII_register_preserve (
  input iCLK,
  input iRST_N
//);
) /*synthesis noprune*/;

将/*synthesis noprune*/放在module,这样整个module的reg将不被最佳化,不用再一一指定。 

另外一个与reg相关的Synthesis Attribute:/*synthesis preserve*/
跟reg相关的attribute,除了/*synthesis noprune*/可用,还有一个/*synthesis preserve*/可用,两者的差异在于:

/*synthesis noprune*/避免Quartus II优化掉没output的reg。

/*synthesis preserve*/避免Quartus II将reg优化为常数,或者合并重复的reg。

也可以使用Verilog 2001的写法

//(*preserve*) reg [3:0] cnt; 


或者整个module的写法

module SignalTapII_register_preserve (
  input iCLK,
  input iRST_N
) /*synthesis preserve*/;

[1] [2] [3]  下一页


本文关键字:暂无联系方式电脑-单片机-自动控制电子学习 - 基础知识 - 电脑-单片机-自动控制

《使用SignalTap II观察reg与wire值》相关文章>>>