aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/gna/bug18361/cnt.vhdl
blob: 4f3b434a7baf3471a39094ff7c52a89e015bef3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity CNT_V is
Generic(clk_divisor: natural);
Port(clk      : in std_logic;
    reset     : in std_logic;
    q_o       : out std_logic);
end CNT_V;

architecture behv of CNT_V is
    --components
    --constants
    --signals
    signal q:     std_logic;
begin
    q_o <= q;
    count: process(clk, reset) is
        --variable
        variable idx: natural range 0 to clk_divisor-1;
        begin
            if reset = '1' then 
                idx:= 0;
                q <= '0';
            elsif rising_edge(clk) then
                if idx = clk_divisor - 1 then
                    q <= '1';
                    idx := 0;
                else
                    q <= '0';
                    idx := idx + 1;
                end if;
            end if;
        end process;
end behv;

-- Testbench:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity cnt_v_tb is
end cnt_v_tb;

architecture TB of cnt_v_tb is

component CNT_V is
Generic(clk_divisor: natural);
Port(clk      : in std_logic;
    reset     : in std_logic;
    q_o       : out std_logic);
end component;

--components
--constants
--signals
signal clk      : std_logic;
signal reset     : std_logic;
signal q_o       : std_logic;

begin

    DUV: cnt_v    
    --generic map(clk_divisor => 10) -- here ist the error 
    port map( clk, reset, q_o);

--stimuli here
--Stimuli for Signal "clk" 40 mhz
process
    begin
        clk <= '1';
        wait for 12.5 ns;
        clk <= '0';
        wait for 12.5 ns;
end process;

process
    begin
    --initialisation
    reset <= '1';
    wait for 20 ns;
    --stimuli
    reset <= '0';
    wait for 22 ns;
    -- do some stuff
    wait;
end process;
end TB;