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

Subversion Repositories pid_controler

[/] [pid_controler/] [trunk/] [tb_pid_controller_0.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 aTomek1328
-------------------------------------------------------------------------------
2
-- Title      : Testbench for pid_controller
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : tb_pid_controller_0.vhd
6
-- Author     : Tomasz Turek  <tomasz.turek@gmail.com>
7
-- Company    : SzuWar ZOO
8
-- Created    : 16:43:29 21-07-2010
9
-- Last update: 20:54:54 04-10-2010
10
-- Platform   : Xilinx ISE 10.1.03
11
-- Standard   : VHDL'93/02
12
-------------------------------------------------------------------------------
13
-- Description: 
14
-------------------------------------------------------------------------------
15
-- Copyright (c) 2010 SzuWar ZOO
16
-------------------------------------------------------------------------------
17
-- Revisions  :
18
-- Date                  Version  Author  Description
19
-- 16:43:29 21-07-2010   1.0      aTomek  Created
20
-- 20:54:31 04-10-2010   1.1      aTomek  Created
21
-------------------------------------------------------------------------------
22
 
23
LIBRARY ieee;
24
USE ieee.std_logic_1164.ALL;
25
USE ieee.std_logic_unsigned.all;
26
USE ieee.numeric_std.ALL;
27
 
28
entity tb_pid_controller_0 is
29
 
30
end entity tb_pid_controller_0;
31
 
32
architecture testbench of tb_pid_controller_0 is
33
-------------------------------------------------------------------------------
34
-- components --
35
-------------------------------------------------------------------------------
36
   component pid_controller is
37
 
38
      generic
39
         (
40
               iDataWidith    : integer range 8 to 32 := 12;
41
               iKP            : integer range 0 to 7  := 2;  -- 0 - /2, 1 - /4, 2 - /8, 3 - /16, 4 - /32, 5 - /64, 6 - /128, 7 - /256
42
               iKI            : integer range 0 to 7  := 3;  -- 0 - /2, 1 - /4, 2 - /8, 3 - /16, 4 - /32, 5 - /64, 6 - /128, 7 - /256
43
               iKD            : integer range 0 to 7  := 4;  -- 0 - /2, 1 - /4, 2 - /8, 3 - /16, 4 - /32, 5 - /64, 6 - /128, 7 - /256
44
               iKM            : integer range 0 to 7  := 0;  -- 0 - /1, 1 - /2, 2 - /4, 3 - /8 , 4 - /16, 5 - /32, 6 - /64 , 7 - /128
45
               iDelayD        : integer range 1 to 16 := 1;
46
               iWork          : integer range 0 to 1  := 1   -- 0 - różnica sygnałów sterujących, 1 - błąd
47
               );
48
 
49
      port
50
         (
51
               CLK_I               : in  std_logic;
52
               RESET_I             : in  std_logic;
53
               ERROR_I             : in  std_logic_vector(iDataWidith - 1 downto 0);
54
               PATERN_I            : in  std_logic_vector(iDataWidith - 1 downto 0);
55
               PATERN_ESTIMATION_I : in  std_logic_vector(iDataWidith - 1 downto 0);
56
               CORRECT_O           : out std_logic_vector(iDataWidith - 1 downto 0)
57
               );
58
 
59
   end component pid_controller;
60
 
61
-------------------------------------------------------------------------------
62
-- constants --
63
-------------------------------------------------------------------------------
64
   constant TS : time := 5 ns;
65
   constant iDataWidith    : integer range 8 to 32 := 12;
66
   constant iKP            : integer range 0 to 7  := 2;  -- 0 - /2, 1 - /4, 2 - /8, 3 - /16, 4 - /32, 5 - /64, 6 - /128, 7 - /256
67
   constant iKI            : integer range 0 to 7  := 1;  -- 0 - /2, 1 - /4, 2 - /8, 3 - /16, 4 - /32, 5 - /64, 6 - /128, 7 - /256
68
   constant iKD            : integer range 0 to 7  := 1;  -- 0 - /2, 1 - /4, 2 - /8, 3 - /16, 4 - /32, 5 - /64, 6 - /128, 7 - /256
69
   constant iKM            : integer range 0 to 7  := 0;  -- 0 - /1, 1 - /2, 2 - /4, 3 - /8 , 4 - /16, 5 - /32, 6 - /64 , 7 - /128
70
   constant iDelayD        : integer range 1 to 16 := 16;
71
   constant iWork          : integer range 0 to 1  := 0;
72
 
73
-------------------------------------------------------------------------------
74
-- signals --
75
-------------------------------------------------------------------------------
76
   -- Inputs --
77
   signal CLK_I               : std_logic := '0';
78
   signal RESET_I             : std_logic := '0';
79
   signal ERROR_I             : std_logic_vector(iDataWidith - 1 downto 0) := x"00f";
80
   signal PATERN_I            : std_logic_vector(iDataWidith - 1 downto 0) := x"6ff";
81
   signal PATERN_ESTIMATION_I : std_logic_vector(iDataWidith - 1 downto 0) := x"007";
82
   -- Outputs --
83
   signal CORRECT_O           : std_logic_vector(iDataWidith - 1 downto 0);
84
    -- Others --
85
   signal v_count : std_logic_vector(15 downto 0) := x"0000";
86
 
87
begin  -- architecture testbench
88
 
89
   -- Unit Under Test --
90
   uut :
91
      pid_controler
92
 
93
         generic map
94
         (
95
               iDataWidith    => iDataWidith,
96
               iKP            => iKP,
97
               iKI            => iKI,
98
               iKD            => iKD,
99
               iKM            => iKM,
100
               iDelayD        => iDelayD,
101
               iWork          => iWork
102
               )
103
 
104
         port map
105
         (
106
               CLK_I               => CLK_I,
107
               RESET_I             => RESET_I,
108
               ERROR_I             => ERROR_I,
109
               PATERN_I            => PATERN_I,
110
               PATERN_ESTIMATION_I => PATERN_ESTIMATION_I,
111
               CORRECT_O           => CORRECT_O
112
               );
113
 
114
 
115
   -- stimulate proces --
116
   stim_proc: process
117
   begin
118
 
119
      for i in 0 to 1000000 loop
120
 
121
         CLK_I <= '0';
122
 
123
         wait for TS;
124
 
125
         CLK_I <= '1';
126
 
127
         wait for TS;
128
 
129
      end loop;  -- i
130
 
131
   end process;
132
 
133
   T0: process (CLK_I) is
134
   begin  -- process T0
135
 
136
      if rising_edge(CLK_I) then
137
 
138
         case v_count is
139
 
140
            when x"0010" =>
141
 
142
               v_count <= v_count + 1;
143
               RESET_I <= '1';
144
            when x"0020" =>
145
 
146
               v_count <= v_count + 1;
147
               RESET_I <= '0';
148
 
149
 
150
 
151
            when others =>
152
 
153
               PATERN_ESTIMATION_I <= PATERN_I - 336 + CORRECT_O;
154
               v_count <= v_count + 1;
155
 
156
         end case;
157
 
158
      end if;
159
 
160
   end process T0;
161
 
162
end architecture testbench;

powered by: WebSVN 2.1.0

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