OpenCores
URL https://opencores.org/ocsvn/astron_counter/astron_counter/trunk

Subversion Repositories astron_counter

[/] [astron_counter/] [trunk/] [tb_common_counter.vhd] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 danv
-------------------------------------------------------------------------------
2
--
3
-- Copyright (C) 2011
4
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
5
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
6
--
7
-- This program is free software: you can redistribute it and/or modify
8
-- it under the terms of the GNU General Public License as published by
9
-- the Free Software Foundation, either version 3 of the License, or
10
-- (at your option) any later version.
11
--
12
-- This program is distributed in the hope that it will be useful,
13
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
14
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
-- GNU General Public License for more details.
16
--
17
-- You should have received a copy of the GNU General Public License
18
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
--
20
-------------------------------------------------------------------------------
21
 
22
LIBRARY IEEE, common_pkg_lib;
23
USE IEEE.std_logic_1164.ALL;
24
USE IEEE.numeric_std.ALL;
25
USE common_pkg_lib.common_pkg.ALL;
26
 
27
ENTITY tb_common_counter IS
28
END tb_common_counter;
29
 
30
ARCHITECTURE tb OF tb_common_counter IS
31
 
32
  CONSTANT clk_period   : TIME := 10 ns;
33
 
34
  CONSTANT c_cnt_init   : NATURAL := 3;
35
  CONSTANT c_cnt_w      : NATURAL := 5;
36
 
37
  SIGNAL rst      : STD_LOGIC;
38
  SIGNAL clk      : STD_LOGIC := '0';
39
 
40
  SIGNAL cnt_clr  : STD_LOGIC := '0';    -- synchronous cnt_clr is only interpreted when clken is active
41
  SIGNAL cnt_ld   : STD_LOGIC := '0';    -- cnt_ld loads the output count with the input load value, independent of cnt_en
42
  SIGNAL cnt_en   : STD_LOGIC := '1';
43
  SIGNAL load     : STD_LOGIC_VECTOR(c_cnt_w-1 DOWNTO 0) := TO_UVEC(c_cnt_init, c_cnt_w);
44
  SIGNAL count    : STD_LOGIC_VECTOR(c_cnt_w-1 DOWNTO 0);
45
  SIGNAL cnt_max  : STD_LOGIC_VECTOR(c_cnt_w-1 DOWNTO 0);
46
 
47
BEGIN
48
 
49
  clk <= NOT clk AFTER clk_period/2;
50
  rst <= '1', '0' AFTER clk_period*3;
51
 
52
  -- run 1 us
53
  p_in_stimuli : PROCESS
54
  BEGIN
55
    cnt_clr <= '0';
56
    cnt_ld  <= '0';
57
    cnt_en  <= '0';
58
    cnt_max <= (OTHERS => '0');
59
    WAIT UNTIL rst = '0';
60
    WAIT UNTIL rising_edge(clk);
61
 
62
    -- Start counting
63
    cnt_en  <= '1';
64
    FOR I IN 0 TO 9 LOOP
65
      WAIT UNTIL rising_edge(clk);
66
    END LOOP;
67
 
68
    -- Reload counter
69
    cnt_ld  <= '1';
70
    WAIT UNTIL rising_edge(clk);
71
    cnt_ld  <= '0';
72
    FOR I IN 0 TO 9 LOOP
73
      WAIT UNTIL rising_edge(clk);
74
    END LOOP;
75
 
76
    -- briefly stop counting
77
    cnt_en  <= '0';
78
    WAIT UNTIL rising_edge(clk);
79
    -- countine counting    
80
    cnt_en  <= '1';
81
    FOR I IN 0 TO 9 LOOP
82
      WAIT UNTIL rising_edge(clk);
83
    END LOOP;
84
 
85
    -- set the cnt_max
86
    cnt_max <= TO_UVEC(2**(c_cnt_w-1), c_cnt_w);
87
 
88
    WAIT;
89
  END PROCESS;
90
 
91
  -- device under test
92
  u_dut : ENTITY work.common_counter
93
  GENERIC MAP (
94
    g_init      => c_cnt_init,
95
    g_width     => c_cnt_w,
96
    g_step_size => 1
97
  )
98
  PORT MAP (
99
    rst     => rst,
100
    clk     => clk,
101
    cnt_clr => cnt_clr,
102
    cnt_ld  => cnt_ld,
103
    cnt_en  => cnt_en,
104
    cnt_max => cnt_max,
105
    load    => load,
106
    count   => count
107
  );
108
 
109
END tb;
110
 
111
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.