差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录 前一修订版
实验2-2_4位比较器 [2017/03/02 11:04]
zhijun
实验2-2_4位比较器 [2017/03/02 16:38]
zhijun
行 29: 行 29:
 Verilog for循环语句的一般形式为 Verilog for循环语句的一般形式为
 // //
-{{ ::​foryunju.png?​600 |}}+{{ ::​foryunju.png?​200 |}}
 // //
  ​初始分配为循环变量设置初始值。当条件为真时,执行表达式,然后由语句描述的for循环实体执行。之后,增量更新,再执行一次表达式。for循环的实体一直循环执行,直到条件表达式的值为假。如果for循环的实体部分包含多条语句,那么应该放在begin和end之间。  ​初始分配为循环变量设置初始值。当条件为真时,执行表达式,然后由语句描述的for循环实体执行。之后,增量更新,再执行一次表达式。for循环的实体一直循环执行,直到条件表达式的值为假。如果for循环的实体部分包含多条语句,那么应该放在begin和end之间。
行 36: 行 36:
 ===== 4.Verilog HDL建模描述 ===== ===== 4.Verilog HDL建模描述 =====
  
-==== 程序清单gates.v ====+==== 程序清单comp4.v ====
  
 <code verilog> <code verilog>
行 42: 行 42:
 // >>>>>>>>>>>>>>>>>>>>>>>>>​ COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<<​ // >>>>>>>>>>>>>>>>>>>>>>>>>​ COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<<​
 // -------------------------------------------------------------------- // --------------------------------------------------------------------
-// File name    : gates.v +// File name    : comp4.v 
-// Module name  : gates+// Module name  : comp4
 // Author ​      : Step // Author ​      : Step
-// Description ​ : Logic gates+// Description ​ : comp4
 // Web          : www.stepfpga.com // Web          : www.stepfpga.com
 //  // 
行 54: 行 54:
 // V1.0     ​|2015/​11/​11 ​  ​|Initial ver // V1.0     ​|2015/​11/​11 ​  ​|Initial ver
 // -------------------------------------------------------------------- // --------------------------------------------------------------------
-  module ​gates +  module ​comp4 
-  +
-      //INPUT +    //INPUT 
-      ​a ​          , +    ​x ​          , 
-      ​b ​          , +    ​y ​          , 
-      //OUTPUT + 
-      ​led         +    ​//OUTPUT 
-      empty +    ​gt_led ​     , 
-  ); +    ​eq_led ​     
-      //​******************* +    lt_led ​     , 
-      //DEFINE INPUT +    ​empty 
-      //​******************* +); 
-      input   a,b    ​+ 
 +    ​//​******************* 
 +    //DEFINE INPUT 
 +    //​******************* 
 + 
 +input  ​[3:​0] ​       x              //4 bit input x (switch) 
 +    input  [3:0]        y           ; ​   //4 bit input y (button)
     ​     ​
-      //​******************* 
-      //DEFINE OUTPUT 
-      //​******************* 
-      output ​ [7:0]   ​empty;​ 
-      output ​ [5:0]   led; 
     ​     ​
-      wire    [5:0]   z; 
     ​     ​
-      ​//Combinational logic style +    ​//******************* 
-      ​assign ​ z[5]=a&​b; ​              //AND    +    //DEFINE OUTPUT 
-      ​assign ​ z[4]=~(a&​b); ​           ​//NAND +    //******************* 
-      ​assign ​ z[3]=a|b              ​//OR +    ​output ​             gt_led ​     ; ​   //x is bigger than y 
-      ​assign ​ z[2]=~(a|b)           //NOR +    ​output ​             eq_led ​     ; ​   //x is equal to y 
-      ​assign ​ z[1]=a^b              ​//XOR +    ​output ​             lt_led ​     ; ​   //x is smaller than y 
-      ​assign ​ z[0]=a~^b             //​XNOR+    ​output ​             empty       ;
     ​     ​
-      assign ​ led=~z; ​            //led is low active+    ​//******************** 
 +    //OUTPUT ATTRIBUTE 
 +    //​******************** 
 +    //REGS 
 +    reg                 ​gt_led ​     ;     
 +    reg                 ​eq_led ​     ; 
 +    reg                 ​lt_led ​     ;
     ​     ​
-      assign  ​empty=8'​b1111_1111; //led's defualt mode is lighted ​+    //WIRE 
 +    wire    [10:​0] ​     ​empty       ​; 
 + 
 +    ​//********************* 
 +    //INNER SIGNAL DECLARATION 
 +    //​********************* 
 +    //REGS 
 +    reg   ​[4:​0] ​        ​G ​ =0   ; ​    
 +    reg   ​[4:​0] ​        ​L ​ =0   ; ​    
 +    reg   ​[4:​1] ​        ​E ​      ; ​   ​
     ​     ​
-  endmodule ​+    //WIRES 
 +integer ​            ​i ​      ;
  
-</code> ​  +     
 +    //​********************* 
 +    //MAIN CORE 
 +    //​********************* 
 +     
 +    always @ (*) 
 +    begin 
 +        for(i=0;i<4;i=i+1) 
 +        comp1(x[i],​y[i],​G[i],​L[i],​G[i+1],​L[i+1],​E[i+1]);​ 
 +        gt_led=~G[4]; ​              //the led's default mode is lighted  
 +        eq_led=~E[4]; ​              //the led's default mode is lighted 
 +        lt_led=~L[4]; ​              //the led's default mode is lighted 
 +    end  
 +     
 +     
 +    task comp1( 
 +                input       ​x ​      , 
 +                input       ​y ​      , 
 +                input       ​Gin ​    , 
 +                input       ​Lin ​    , 
 +                output ​     Gout    , 
 +                output ​     Lout    , 
 +                output ​     Eout 
 +                ); 
 +    begin  
 +        Gout=x&​~y|x&​Gin|~y&​Gin;​ 
 +        Eout=~x&​~y&​~Gin&​~Lin|x&​y&​~Gin&​~Lin;​ 
 +        Lout=~x&​y|~x&​Lin|y&​Lin;​ 
 +    end 
 +    endtask 
 +     
 + ​assign ​ empty=11'​b111_1111_1111; ​   ​
  
-==== 仿真程序清单gates_tb.v ==== +endmodule ​ 
- +
- +
-<code verilog>​ +
-//​******************************************************** +
-// +
-//   ​Copyright(c)2016,​ STEP FPGA  +
-//   All rights reserved +
-// +
-//   File name       : ​  ​gates_tb.v +
-//   ​Module name     : ​  ​gates_tb +
- +
-//   ​Author ​         :   ​STEP +
-//   ​Email ​          : ​  ​info@stepfpga.com +
-//   ​Data ​           :   ​2016/​08/​19 +
- +
-//   ​Version ​        : ​  ​V1.0 +
-//   ​Description ​    : ​  ​testbench module +
-// +
-//   ​Modification history +
-//   ​---------------------------------------------------------------------------- +
-// Version ​      ​Data(2016/​08/​19) ​  ​V1.0 +
-// Description ​   +
-// +
-//​******************************************************** +
-// +
-// +
-//​******************* +
-//DEFINE MODULE PORT +
-//​******************* +
-`timescale 1ns/100ps +
-module gates_tb; +
- +
-reg a,b; +
-wire [5:0] led; +
-initial  +
- begin  +
- a=0; +
- b=0; +
- #50; +
- a=0; +
- b=1; +
- #50; +
- a=1; +
- b=0; +
- #50; +
- a=1; +
- b=1; +
- #50;  +
- end +
-gates gates_tb_uut( +
- .a (a),​ +
- .b (b),​ +
- .led (led),​ +
- .empty () +
- ); +
-endmodule+
  
 </​code> ​   </​code> ​  
- 
-