专栏中心

EEPW首页 > 专栏 > 编了个计数器程序与TESTBENCH

编了个计数器程序与TESTBENCH

发布人:zhchxgh 时间:2009-07-15 来源:工程师 发布文章
编了个计数器程序与TESTBENCH

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity counters is
    port(
        reset : in std_logic;
        cs : in std_logic;
        clk : in std_logic;
        q  : out std_logic_vector(11 downto 0)
        );
end counters;

architecture bev of counters is
    signal one,ten,hun : std_logic_vector(3 downto 0);
    
begin
    a: process(clk, reset, cs)
    begin
        if(reset = '1')then
            one<="0000";
        elsif cs = '1' then
            if clk'event and clk = '1' then
                if(one="1001")then
                    one<="0000";
                else 
                    one<=one+1;
                end if;
            end if;
        end if;
    end process;
    
    b: process(clk, reset, cs, one)
    begin
        if(reset = '1')then
            ten<="0000";
        elsif cs = '1' then
            if clk'event and clk = '1' then
                if(ten="1001" and one="1001")then
                    ten<="0000";
                elsif(one="1001")then
                    ten<=ten+1;
                end if;
            end if;
        end if;
    end process;
    
    c: process(clk, reset, cs, one, ten)
    begin
        if(reset = '1')then
            hun<="0000";
        elsif cs = '1' then
            if clk'event and clk = '1' then
                if(hun="1001" and ten="1001" and one="1001")then
                    hun<="0000";
                elsif(ten="1001" and one="1001")then
                    hun<=hun+1;
                end if;
            end if;
        end if;
    end process ;
    q<=hun&ten&one;
end bev;




--********************************************************************
--* This automatically generated Test Bench template has been created*
--* By ACTIVE-HDL    <TBgen v1.11>. Copyright (C) ALDEC Inc.         *
--*                                                                  *
--* This file was generated on:                      10:56, 01-12-18 *
--* Tested entity name:                                     counters *
--* File name contains tested entity:         $DSN\src\counter10.vhd *
--********************************************************************

library ieee;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_1164.all;

    -- Add your library and packages declaration here ...

entity counters_tb is
end counters_tb;

architecture TB_ARCHITECTURE of counters_tb is
    -- Component declaration of the tested unit
    component counters
    port(
        reset : in std_logic;
        cs : in std_logic;
        clk : in std_logic;
        q : out std_logic_vector(11 downto 0) );
end component;

    -- Stimulus signals - signals mapped to the input and inout ports of tested entity
    signal reset : std_logic;
    signal cs : std_logic;
    signal clk : std_logic;
    -- Observed signals - signals mapped to the output ports of tested entity
    signal q : std_logic_vector(11 downto 0);

    -- Add your code here ...
    constant clk_cycle : time := 10 ns;
begin

    -- Unit Under Test port map
    UUT : counters
        port map
            (reset => reset,
            cs => cs,
            clk => clk,
            q => q );

    -- Add your stimulus here ...
    rstp : process
    begin
        reset <= '1';
        wait for 10 ns;
        reset <= '0';
        cs <= '1';
        wait;
    end process;
    
    clkp : process
    begin
        clk <= '1';
        wait for clk_cycle;
        clk <= '0';
        wait for clk_cycle;
    end process;
    
end TB_ARCHITECTURE;

configuration TESTBENCH_FOR_counters of counters_tb is
    for TB_ARCHITECTURE
        for UUT : counters
            use entity work.counters(bev);
        end for;
    end for;
end TESTBENCH_FOR_counters;

专栏文章内容及配图由作者撰写发布,仅供工程师学习之用,如有侵权或者其他违规问题,请联系本站处理。 联系我们

关键词:

相关推荐

台积电等外资项目将助力美国FDI回升

EDA/PCB 2025-06-26

关于可穿戴机器人的一个令人惊讶的事实

机器人 2025-06-26

Qorvo推出全新紧凑型解决方案QPQ3550和QPA9862,以优化射频尺寸与散热性能简化5G基础设施部署

视频教程:WindowsCE.NET USB驱动开发基础(Level 300)

MIT利用生成式AI进行机器人设计

EasyARM1138嵌入式专题讲座

视频 2010-02-05

《嵌入式系统设计》21-Linux嵌入式系统设计(Linux驱动设计到)及MP3播放器设计(开发工具选择)

视频 2010-02-02

TSMC的全球扩张战略:增长推动因素还是利润风险?

EDA/PCB 2025-06-26

《嵌入式系统设计》23-MP3播放器设计(Uboot上增加新设备Ramdisk到结束)及网络存储设计(开始到结束)及一部分补充说明

视频 2010-02-02

研博XPE系统 1.1

物理AI在机器人领域的兴起

机器人 2025-06-26

用于高侧或低侧测量的1%电流感应放大器 IC

《嵌入式系统设计》22-MP3播放器设计(设计方法到块设备读取)

视频 2010-02-02

视频教程:使用Embeded Visual C++开发通讯终端及应用实例代码分析(Level 200)

英伟达和富士康正在商讨在休斯顿部署人形机器人,预计明年开始生产

数字信号处理教程

内存现货价格更新:DDR4 模块价格超过 DDR5;关税担忧可能引发恐慌性购买

了解GaN驱动的AI和机器人创新

《嵌入式系统设计》20-Linux嵌入式系统设计(Linux启动过程第一步到DeBug符号裁减)

视频 2010-02-02
更多 培训课堂
更多 焦点
更多 视频

技术专区