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

Subversion Repositories pwm_with_dithering

[/] [pwm_with_dithering/] [trunk/] [testbench/] [test_top.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 TeroS
--------------------------------------------------------------------------------
2
-- Company:             Aboa Space Research Oy (ASRO)
3
-- Engineer:            Tero Säntti
4
--
5
-- Create Date:   14:58:12 01/27/2021
6
-- Design Name:   PWM test top
7
-- Project Name:  PWM
8
-- Target Device: None / Simulation ONLY
9
-- Tool versions: None / non-specific
10
-- Description:   Very generic testbench for pwm
11
-- 
12
-- Revision:
13
-- Revision 0.01 - File Created
14
-- Additional Comments:
15
--
16
--------------------------------------------------------------------------------
17
LIBRARY ieee;
18
USE ieee.std_logic_1164.ALL;
19
 
20
ENTITY test_top IS
21
        generic(
22
                bits            :integer:=16;
23
                vdd             :real:=3.3;
24
                dithering:integer:=5
25
        );
26
END test_top;
27
 
28
ARCHITECTURE behavior OF test_top IS
29
 
30
 
31
COMPONENT pwm
32
    Generic (
33
                                bits: integer:=16;
34
                                dithering:integer:=5
35
                                );
36
    PORT(
37
         clk : IN  std_logic;
38
         set : IN  std_logic_vector(bits-1 downto 0);
39
         o : OUT  std_logic
40
        );
41
END COMPONENT;
42
 
43
COMPONENT pwm_pipelined
44
    Generic (
45
                                bits: integer:=16;
46
                                dithering:integer:=5
47
                                );
48
    PORT(
49
         clk : IN  std_logic;
50
         set : IN  std_logic_vector(bits-1 downto 0);
51
         o : OUT  std_logic
52
        );
53
END COMPONENT;
54
 
55
COMPONENT pwm_pipelined_small
56
    Generic (
57
                                bits: integer:=16;
58
                                dithering:integer:=5
59
                                );
60
    PORT(
61
         clk : IN  std_logic;
62
         set : IN  std_logic_vector(bits-1 downto 0);
63
         o : OUT  std_logic
64
        );
65
END COMPONENT;
66
 
67
COMPONENT pwm_ineq
68
    Generic (
69
                                bits: integer:=16;
70
                                dithering:integer:=5
71
                                );
72
    PORT(
73
         clk : IN  std_logic;
74
         set : IN  std_logic_vector(bits-1 downto 0);
75
         o : OUT  std_logic
76
        );
77
END COMPONENT;
78
 
79
COMPONENT pwm_reg
80
    Generic (
81
                                bits: integer:=16;
82
                                dithering:integer:=5
83
                                );
84
    PORT(
85
         clk : IN  std_logic;
86
         set : IN  std_logic_vector(bits-1 downto 0);
87
         o : OUT  std_logic
88
        );
89
END COMPONENT;
90
 
91
component pwm_to_voltage is
92
    Generic (
93
                                autorefresh_interval : time;
94
                                autorefresh_enabled : boolean;
95
                                supply_voltage : real:=3.3;
96
                                R : real:=100.0;
97
                                C : real:=0.0001
98
                                );
99
    Port ( pwm : in  STD_LOGIC;
100
           voltage : out real;
101
                          frequency : out real
102
                          );
103
end component;
104
 
105
 
106
component rc_filter is
107
    Generic (
108
                                autorefresh_interval : time;
109
                                autorefresh_enabled : boolean;
110
                                supply_voltage : real:=3.3;
111
                                R : real:=100.0;
112
                                C : real:=0.0001
113
                                );
114
    Port ( v_in : in  real;
115
           v_out : out real
116
                          );
117
end component;
118
 
119
component pseudo_ADC is
120
    Generic (
121
                                bits : integer :=bits;
122
                                supply_voltage : real:=3.3
123
                                );
124
    Port ( v_in : in  real;
125
                          digital_out : out std_logic_vector(bits-1 downto 0)
126
                          );
127
end component;
128
 
129
component analyzer is
130
    Generic (
131
                                supply_voltage : real:=3.3;
132
                                filter_strength: real:=0.99
133
                                );
134
    Port ( enable : in std_logic;
135
                          v_in : in  real;
136
           v_out : buffer real;
137
                          v_max : buffer real;
138
                          v_min : buffer real;
139
                          v_p2p : out real
140
                          );
141
end component;
142
 
143
   --Inputs
144
   signal clk : std_logic := '0';
145
   signal set : std_logic_vector(bits-1 downto 0) := (others => '0');
146
 
147
        --Outputs
148
   signal o : std_logic;
149
 
150
        signal volts:real;
151
        signal frequency:real;
152
        signal filtered_volts:real;
153
   signal read_back : std_logic_vector(bits-1 downto 0);
154
        signal analyzed_volts: real;
155
        signal analyzed_min: real;
156
        signal analyzed_max: real;
157
        signal analyzed_p2p: real;
158
        signal analyzer_enable: std_logic;
159
 
160
   -- Clock period definitions
161
   constant clk_period : time := 8.3333333 ns; -- AKA 120MHz
162
 
163
BEGIN
164
 
165
        -- Instantiate the Unit Under Test (UUT)
166
   uut: pwm_pipelined_small
167
    Generic map(
168
                                bits             => bits,
169
                                dithering => dithering
170
                                )
171
         PORT MAP (
172
          clk => clk,
173
          set => set,
174
          o => o
175
        );
176
 
177
   -- Clock process definitions
178
   clk_process :process
179
   begin
180
                clk <= '0';
181
                wait for clk_period/2;
182
                clk <= '1';
183
                wait for clk_period/2;
184
   end process;
185
 
186
   -- Stimulus process (Set your test patterns here, or make a more automated test structure as needed)
187
        -- This is set for running 100ms.
188
   stim_proc: process
189
   begin
190
                analyzer_enable <= '0';
191
      set <= "1000000000010000";
192
                wait for 30 ms;
193
                analyzer_enable <= '1';
194
                wait for 20 ms;
195
                analyzer_enable <= '0';
196
      set <= "0010111001000101";
197
                wait for 30 ms;
198
                analyzer_enable <= '1';
199
      wait;
200
   end process;
201
 
202
voltage_generator: pwm_to_voltage
203
    Generic map(
204
                                autorefresh_interval => 0.1 us,--: time;
205
                                autorefresh_enabled  => true,--: boolean;
206
                                supply_voltage          => vdd,--: real:=3.3;
207
                                R                                                       => 100000.0,-- 100k
208
                                C                                                       => 0.000000018 -- 18n 
209
                                )
210
    Port map(
211
                                pwm              => o,--: in  STD_LOGIC;
212
                                voltage          => volts,--: out real;
213
                           frequency => frequency--: out real
214
                                );
215
 
216
Secondary_RC_filter: rc_filter
217
    Generic map(
218
                                autorefresh_interval => 1 us,--: time;
219
                                autorefresh_enabled  => false,--: boolean; -- IF previous stages are set to update often, then this can be false
220
                                supply_voltage          => vdd,--: real:=3.3;
221
                                R                                                       => 100.0,--: real:=100.0; 0.1k
222
                                C                                                       => 0.000000200 -- 200n
223
                                )
224
    Port map(
225
                                v_in                    => volts,--: in  real;
226
            v_out                       => filtered_volts--: out real;
227
                           );
228
 
229
Output_analyzer: analyzer
230
    Generic map(
231
                                supply_voltage  => vdd,--: real:=3.3;
232
                                filter_strength => 0.999--: real:=0.99
233
                                )
234
    Port map(
235
                                enable => analyzer_enable,--: in std_logic;
236
                           v_in          => filtered_volts,--: in  real;
237
            v_out  => analyzed_volts,--: buffer real;
238
                           v_max  => analyzed_max,--: buffer real;
239
                           v_min  => analyzed_min,--: buffer real;
240
                           v_p2p  => analyzed_p2p--: out real
241
                          );
242
 
243
read_back_ADC:pseudo_ADC
244
    Generic map(
245
                                bits                            => bits,--: integer :=16;
246
                                supply_voltage => vdd--: real:=3.3
247
                                )
248
    Port map(
249
                                v_in => analyzed_volts,--: in  real;
250
                           digital_out => read_back--: out std_logic_vector(bits-1 downto 0)
251
                          );
252
 
253
 
254
END;

powered by: WebSVN 2.1.0

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