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

Subversion Repositories waveform_gen

[/] [waveform_gen/] [trunk/] [vhdl/] [waveform_gen_bench.vhd] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sdoherty
----------------------------------------------------------------------
2
--                                                                  --
3
--  THIS VHDL SOURCE CODE IS PROVIDED UNDER THE GNU PUBLIC LICENSE  --
4
--                                                                  --
5
----------------------------------------------------------------------
6
--                                                                  --
7
--    Filename            : waveform_gen_bench.vhd                  --
8
--                                                                  --
9
--    Author              : Simon Doherty                           --
10
--                          Senior Design Consultant                --
11
--                          www.zipcores.com                        --
12
--                                                                  --
13 4 sdoherty
--    Date last modified  : 24.10.2008                              --
14 2 sdoherty
--                                                                  --
15
--    Description         : NCO / Periodic Waveform Generator TB    --
16
--                                                                  --
17
----------------------------------------------------------------------
18
 
19
 
20
use std.textio.all;
21
 
22
library ieee;
23
use ieee.std_logic_1164.all;
24
use ieee.std_logic_textio.all;
25
use ieee.std_logic_arith.all;
26
 
27
 
28
entity waveform_gen_bench is
29
begin
30
end waveform_gen_bench;
31
 
32
 
33
architecture behav of waveform_gen_bench is
34
 
35
 
36
component waveform_gen
37
 
38
port (
39
 
40
  -- system signals
41
  clk         : in  std_logic;
42
  reset       : in  std_logic;
43
 
44 4 sdoherty
  -- clock-enable
45
  en          : in  std_logic;
46
 
47 2 sdoherty
  -- NCO frequency control
48
  phase_inc   : in  std_logic_vector(31 downto 0);
49
 
50
  -- Output waveforms
51
  sin_out     : out std_logic_vector(11 downto 0);
52
  cos_out     : out std_logic_vector(11 downto 0);
53
  squ_out     : out std_logic_vector(11 downto 0);
54
  saw_out     : out std_logic_vector(11 downto 0) );
55
 
56
end component;
57
 
58
 
59
signal  clk        : std_logic := '0';
60
signal  reset      : std_logic := '0';
61
signal  capture    : std_logic := '0';
62 4 sdoherty
signal  en         : std_logic := '1';
63 2 sdoherty
 
64 4 sdoherty
signal  phase_inc  : std_logic_vector(31 downto 0) := (others => '0');
65 2 sdoherty
 
66
signal  sin_out    : std_logic_vector(11 downto 0);
67
signal  cos_out    : std_logic_vector(11 downto 0);
68
signal  squ_out    : std_logic_vector(11 downto 0);
69
signal  saw_out    : std_logic_vector(11 downto 0);
70
 
71
signal  sin_int    : integer;
72
signal  cos_int    : integer;
73
signal  squ_int    : integer;
74
signal  saw_int    : integer;
75
 
76
 
77
begin
78
 
79
 
80
-- Generate a 100MHz clk
81
clk <= not clk after 5 ns;
82
 
83
 
84
-- Set NCO frequency : Phase_inc = (Fout/Fclk)*2^32
85
phase_inc <= X"045a1cac"; -- 1.7MHz example frequency
86
 
87
 
88
-- Test bench control
89
test_bench_control: process
90
begin
91
    -- start of test
92
    wait for 1 us;
93
        wait until clk'event and clk = '1';
94
        -- bring out of reset
95
    reset <= '1';
96
 
97
    -- start output capture
98
    wait for 1 us;
99
        wait until clk'event and clk = '1';
100
    capture <= '1';
101 4 sdoherty
 
102 2 sdoherty
    -- run sim for a while
103
    wait for 100 us;
104
    wait until clk'event and clk = '1';
105
    assert false report "    SIMULATION FINISHED!" severity failure;
106
end process test_bench_control;
107
 
108
 
109
-- DUT
110
nco: waveform_gen
111
 
112
port map (
113
 
114
  -- system signals
115
  clk         => clk,
116
  reset       => reset,
117
 
118 4 sdoherty
  -- clock-enable
119
  en          => en,
120
 
121 2 sdoherty
  -- NCO frequency control
122
  phase_inc   => phase_inc,
123
 
124
  -- Output waveforms
125
  sin_out     => sin_out,
126
  cos_out     => cos_out,
127
  squ_out     => squ_out,
128
  saw_out     => saw_out );
129
 
130
 
131
-- Convert 12-bit outputs to integers
132
sin_int <= conv_integer(signed(sin_out));
133
cos_int <= conv_integer(signed(cos_out));
134
squ_int <= conv_integer(signed(squ_out));
135
saw_int <= conv_integer(signed(saw_out));
136
 
137
 
138
-- Capture output data
139
grab_data: process (clk)
140
 
141
  file     terminal   : text open write_mode is "waveform_out.txt";
142
  variable resoutline : line;
143
 
144
begin
145
 
146
  if clk'event and clk = '1' then
147
    if capture = '1' then
148
       write(resoutline, sin_int);
149
       write(resoutline, string'(" "));
150
       write(resoutline, cos_int);
151
       write(resoutline, string'(" "));
152
       write(resoutline, squ_int);
153
       write(resoutline, string'(" "));
154
       write(resoutline, saw_int);
155
       writeline(terminal, resoutline);
156
     end if;
157
   end if;
158
end process grab_data;
159
 
160
 
161
end behav;

powered by: WebSVN 2.1.0

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