网站公告列表

  没有公告

加入收藏
设为首页
联系站长
您现在的位置: 61EDA中国电子网 >> 技术文库 >> HDL语言 >> 正文
  测试向量(Test Bench)和波形发生器           ★★★ 【字体:
测试向量(Test Bench)和波形发生器
作者:Free    文章来源:本站原创    点击数:    更新时间:2008-2-4    

加法器源程序
module counter (count, clk, reset);

output [7:0] count;

input clk, reset;

reg [7:0] count;

parameter tpd_clk_to_count   =  1;

parameter tpd_reset_to_count =  1;


function [7:0] increment;

input [7:0] val;

reg [3:0] i;

reg carry;

  begin

    increment = val;

    carry = 1'b1;

    /*

     * Exit this loop when carry == zero, OR all bits processed

     */

    for (i = 4'b0; ((carry == 4'b1) || (i <= 7));  i = i+ 4'b1)

       begin

         increment[i] = val[i] ^ carry;

         carry = val[i] & carry;

       end

  end     

endfunction

always @ (posedge clk or posedge reset)

  if (reset)

     count = #tpd_reset_to_count 8'h00;

  else

     count <= #tpd_clk_to_count increment(count);

/*

 * To make module counter synthesizeable, use the following

 *  alternate form of the always block:

 */

/***********************************************

always @ (posedge clk or posedge reset)

  if (reset)

     count <= 8'h00;

  else

     count <= count + 8'h01;

***********************************************/

endmodule

测试向量(test bench)
module test_counter;

reg clk, rst;

wire [7:0] count;

counter #(5,10) dut (count,clk,rst);

initial // Clock generator

  begin

    clk = 0;

    #10 forever #10 clk = !clk;

  end

initial  // Test stimulus

  begin

    rst = 0;

    #5 rst = 1;

    #4 rst = 0;

    #50000 $stop;

  end

initial

    $monitor($stime,, rst,, clk,,, count);

endmodule  

文章录入:admin    责任编辑:admin 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
    基于SOPC的多功能车辆息线控…
    基于VHDL状态机设计的智能交…
    基于梯形图-VHDL的CPLD开发方…
    半整数分频的VHDL程序
    学写Testbench-结构篇
    TESTBENCH语法参考
    编写高效的测试设计(testben…
    Verilog 编码原则…
    一个简单的总线轮询仲裁器Ve…
    VHDL秒表计时器
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    湘ICP备08001332号 站长:61EDA