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 2

Go to most recent revision | 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
--    Date last modified  : 23.10.2008                              --
14
--                                                                  --
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
  -- NCO frequency control
45
  phase_inc   : in  std_logic_vector(31 downto 0);
46
 
47
  -- Output waveforms
48
  sin_out     : out std_logic_vector(11 downto 0);
49
  cos_out     : out std_logic_vector(11 downto 0);
50
  squ_out     : out std_logic_vector(11 downto 0);
51
  saw_out     : out std_logic_vector(11 downto 0) );
52
 
53
end component;
54
 
55
 
56
signal  clk        : std_logic := '0';
57
signal  reset      : std_logic := '0';
58
signal  capture    : std_logic := '0';
59
 
60
signal  phase_inc  : std_logic_vector(31 downto 0);
61
 
62
signal  sin_out    : std_logic_vector(11 downto 0);
63
signal  cos_out    : std_logic_vector(11 downto 0);
64
signal  squ_out    : std_logic_vector(11 downto 0);
65
signal  saw_out    : std_logic_vector(11 downto 0);
66
 
67
signal  sin_int    : integer;
68
signal  cos_int    : integer;
69
signal  squ_int    : integer;
70
signal  saw_int    : integer;
71
 
72
 
73
begin
74
 
75
 
76
-- Generate a 100MHz clk
77
clk <= not clk after 5 ns;
78
 
79
 
80
-- Set NCO frequency : Phase_inc = (Fout/Fclk)*2^32
81
phase_inc <= X"045a1cac"; -- 1.7MHz example frequency
82
 
83
 
84
-- Test bench control
85
test_bench_control: process
86
begin
87
    -- start of test
88
    wait for 1 us;
89
        wait until clk'event and clk = '1';
90
        -- bring out of reset
91
    reset <= '1';
92
 
93
    -- start output capture
94
    wait for 1 us;
95
        wait until clk'event and clk = '1';
96
    capture <= '1';
97
 
98
    -- run sim for a while
99
    wait for 100 us;
100
    wait until clk'event and clk = '1';
101
    assert false report "    SIMULATION FINISHED!" severity failure;
102
end process test_bench_control;
103
 
104
 
105
-- DUT
106
nco: waveform_gen
107
 
108
port map (
109
 
110
  -- system signals
111
  clk         => clk,
112
  reset       => reset,
113
 
114
  -- NCO frequency control
115
  phase_inc   => phase_inc,
116
 
117
  -- Output waveforms
118
  sin_out     => sin_out,
119
  cos_out     => cos_out,
120
  squ_out     => squ_out,
121
  saw_out     => saw_out );
122
 
123
 
124
-- Convert 12-bit outputs to integers
125
sin_int <= conv_integer(signed(sin_out));
126
cos_int <= conv_integer(signed(cos_out));
127
squ_int <= conv_integer(signed(squ_out));
128
saw_int <= conv_integer(signed(saw_out));
129
 
130
 
131
-- Capture output data
132
grab_data: process (clk)
133
 
134
  file     terminal   : text open write_mode is "waveform_out.txt";
135
  variable resoutline : line;
136
 
137
begin
138
 
139
  if clk'event and clk = '1' then
140
    if capture = '1' then
141
       write(resoutline, sin_int);
142
       write(resoutline, string'(" "));
143
       write(resoutline, cos_int);
144
       write(resoutline, string'(" "));
145
       write(resoutline, squ_int);
146
       write(resoutline, string'(" "));
147
       write(resoutline, saw_int);
148
       writeline(terminal, resoutline);
149
     end if;
150
   end if;
151
end process grab_data;
152
 
153
 
154
end behav;

powered by: WebSVN 2.1.0

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