1 / 18

行为建模

行为建模. 这里主要介绍过程赋值语句的特征,过程赋值语句主要用于行为建模。 一、过程结构 下面两中语句是一个设计的行为建模的主要机制。 initial 语句 always 语句. 1 、 initial 语句 initial 语句表示, initial 语句后面的一句语句只能被执行一次。语句在模拟开始值执行,即在 0 时刻开始执行。 格式: initial [timing_control] procedural_statement 2 、 always 语句 always 语句表示, always 语句后面的一句语句可以被重复执行。

eileen
Download Presentation

行为建模

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 行为建模 这里主要介绍过程赋值语句的特征,过程赋值语句主要用于行为建模。 一、过程结构 下面两中语句是一个设计的行为建模的主要机制。 initial语句 always语句

  2. 1、initial语句 initial语句表示,initial语句后面的一句语句只能被执行一次。语句在模拟开始值执行,即在0时刻开始执行。 格式: initial [timing_control] procedural_statement 2、always语句 always语句表示,always语句后面的一句语句可以被重复执行。 格式: always [timing_control] procedural_statement

  3. 二、块语句 块语句是提供将两条或两条以上的语句组合成语法结构上相当于一条语句的机制。在Verilog HDL中,有两类块语句。 1、顺序块语句(begin ……end) 块语句中的语句按给定次序依次执行。每条语句中的时延值与其前面的语句值性的模拟时间相关。一旦顺序执行完每条语句,紧跟顺序块语句的下一条语句将被继续执行,语句延时与上条语句相关。 语法结构: begin [:block_name] procedural_statements; end

  4. 例如: begin #2 stream=1; #5 stream=0; #3 stream=1; #4 stream=0; #2 stream=1; end 2、并行块语句(fork……join) 块语句中的语句同时并行执行。语句延时都与块语句开始执行时间相关。当并行块语句执行结束(不一定时最后一条语句),紧跟块语句的语句将被执行。

  5. 语法结构: fork [:block_name] procedural_statements; join 例如: fork #2 stream=1; #7 stream=0; #10 stream=1; #14 stream=0; #16 stream=1; join

  6. 三、时序控制 有两种时序控制形式。 1、时延控制: a、外部时延控制: #delay a=b; 先赋值,后时延。 b、内部时延控制: a= #delay b; 线延时,后赋值。 例如:数据交换 fork fork #10a=b; a=#10 b; #10b=a; b=#10 a; join join 可能存在竞争冒险

  7. 2、事件控制 在事件控制中,always的过程语句基于事件执行 @ (事件敏感) a、@(信号名)信号真值触发 b、@(posedge信号名)信号上升延触发 @(negedge信号名)信号下降延触发 c、@(敏感事件1 or敏感事件2 or…)多事件 真值触发 d、@(表达式)表达式真值触发 例:@ (clk) a=b; @ (posedge clk) a=b; @ (!reset) a=b;

  8. 四、过程赋值 过程赋值是在initial或always内进行赋值,它只能对寄存器数据类型的变量赋值。 1、语句延时 外部模式: <时序控制> <寄存器变量> = <表达式> 内部模式: <寄存器变量> = <时序控制> <表达式> 2、阻塞性过程赋值 赋值操作符为:“= ” 下条语句等待上条语句执行结束后,再执性。

  9. 例:initial begin a=#10 1; b=#5 0; c=#1 1; end 3、非阻塞性过程赋值 赋值操作符为:“<= ” 对目标赋值是非阻塞的,所有语句并行执行。

  10. 例:initial initial begin fork a<=#10 1; a=#10 1; b<=#5 0; b=#5 0; c<=#1 1; c=#1 1; end join 4、过程赋值与连续赋值的比较 (1)对象不同:过程赋值是寄存器类型变量;连续赋值是线网性变量。 (2)出现位置不同:过程赋值必须在always或initial语句中。 (3)语句结构不同:连续赋值语句的操作符为“=”;过程赋值语句为“=”或“<=”。 (4)赋值过程不同:连续赋值在右端操作数变化是执行;过程赋值由时序控制。

  11. 高级语言 一、if语句 1、if(条件表达式)块语句 2、if (条件表达式)块语句1 else 块语句2 3、if(条件表达式1) 块语句1 else if (条件表达式2) 块语句2 ………… else if (条件表达式n) 块语句n else 块语句n+1;

  12. 例:if (sum<60) begin Grade=C; Total_C=Total_C+1; end else if (sum<75) begin Grade=B; Total_B=Total_B+1; end else begin Grade=A; Total_A=Total_A+1; end

  13. 4、嵌套语句 if(条件表达式1) begin if(条件表达式2) 块语句1; else 块语句2; end else begin if(条件表达式3) 块语句3; else 块语句4; end

  14. 例:if (ctr1) begin if(~ctr2) MUX=4’d2; else MUX=4’d1; else begin if(~ctr2) MUX=4d’8; else MUX=4’d4; end

  15. 例:module count60 (qout,cout,data,load,cin,reset,clk); output[7:0] qout; output cout; input[7:0] data; input load,cin,clk,reset; reg[7:0] qout; always @(posedge clk) begin if (reset) qout=0; else if (load) qout=data; else if (cin)

  16. begin if (qout[3:0]==9) begin qout[3:0]=0; if (qout[7:4]==5) qout[7:4]=0; else qout[7:4]=qout[7:4]+1; end else qout[3:0]=qout[3:0]+1; end

  17. end assign cout=((qout==8'h59)&cin) ? 1:0; endmodule

More Related