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 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 danv
-------------------------------------------------------------------------------
2
--
3 3 danv
-- Copyright 2020
4 2 danv
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
5
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
6 3 danv
-- 
7
-- Licensed under the Apache License, Version 2.0 (the "License");
8
-- you may not use this file except in compliance with the License.
9
-- You may obtain a copy of the License at
10
-- 
11
--     http://www.apache.org/licenses/LICENSE-2.0
12
-- 
13
-- Unless required by applicable law or agreed to in writing, software
14
-- distributed under the License is distributed on an "AS IS" BASIS,
15
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
-- See the License for the specific language governing permissions and
17
-- limitations under the License.
18 2 danv
--
19
-------------------------------------------------------------------------------
20
 
21
LIBRARY IEEE, common_pkg_lib;
22
USE IEEE.std_logic_1164.ALL;
23
USE IEEE.numeric_std.ALL;
24
USE common_pkg_lib.common_pkg.ALL;
25
 
26
ENTITY tb_common_counter IS
27
END tb_common_counter;
28
 
29
ARCHITECTURE tb OF tb_common_counter IS
30
 
31
  CONSTANT clk_period   : TIME := 10 ns;
32
 
33
  CONSTANT c_cnt_init   : NATURAL := 3;
34
  CONSTANT c_cnt_w      : NATURAL := 5;
35
 
36
  SIGNAL rst      : STD_LOGIC;
37
  SIGNAL clk      : STD_LOGIC := '0';
38
 
39
  SIGNAL cnt_clr  : STD_LOGIC := '0';    -- synchronous cnt_clr is only interpreted when clken is active
40
  SIGNAL cnt_ld   : STD_LOGIC := '0';    -- cnt_ld loads the output count with the input load value, independent of cnt_en
41
  SIGNAL cnt_en   : STD_LOGIC := '1';
42
  SIGNAL load     : STD_LOGIC_VECTOR(c_cnt_w-1 DOWNTO 0) := TO_UVEC(c_cnt_init, c_cnt_w);
43
  SIGNAL count    : STD_LOGIC_VECTOR(c_cnt_w-1 DOWNTO 0);
44
  SIGNAL cnt_max  : STD_LOGIC_VECTOR(c_cnt_w-1 DOWNTO 0);
45
 
46
BEGIN
47
 
48
  clk <= NOT clk AFTER clk_period/2;
49
  rst <= '1', '0' AFTER clk_period*3;
50
 
51
  -- run 1 us
52
  p_in_stimuli : PROCESS
53
  BEGIN
54
    cnt_clr <= '0';
55
    cnt_ld  <= '0';
56
    cnt_en  <= '0';
57
    cnt_max <= (OTHERS => '0');
58
    WAIT UNTIL rst = '0';
59
    WAIT UNTIL rising_edge(clk);
60
 
61
    -- Start counting
62
    cnt_en  <= '1';
63
    FOR I IN 0 TO 9 LOOP
64
      WAIT UNTIL rising_edge(clk);
65
    END LOOP;
66
 
67
    -- Reload counter
68
    cnt_ld  <= '1';
69
    WAIT UNTIL rising_edge(clk);
70
    cnt_ld  <= '0';
71
    FOR I IN 0 TO 9 LOOP
72
      WAIT UNTIL rising_edge(clk);
73
    END LOOP;
74
 
75
    -- briefly stop counting
76
    cnt_en  <= '0';
77
    WAIT UNTIL rising_edge(clk);
78
    -- countine counting    
79
    cnt_en  <= '1';
80
    FOR I IN 0 TO 9 LOOP
81
      WAIT UNTIL rising_edge(clk);
82
    END LOOP;
83
 
84
    -- set the cnt_max
85
    cnt_max <= TO_UVEC(2**(c_cnt_w-1), c_cnt_w);
86
 
87
    WAIT;
88
  END PROCESS;
89
 
90
  -- device under test
91
  u_dut : ENTITY work.common_counter
92
  GENERIC MAP (
93
    g_init      => c_cnt_init,
94
    g_width     => c_cnt_w,
95
    g_step_size => 1
96
  )
97
  PORT MAP (
98
    rst     => rst,
99
    clk     => clk,
100
    cnt_clr => cnt_clr,
101
    cnt_ld  => cnt_ld,
102
    cnt_en  => cnt_en,
103
    cnt_max => cnt_max,
104
    load    => load,
105
    count   => count
106
  );
107
 
108
END tb;
109
 
110
 

powered by: WebSVN 2.1.0

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