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

Subversion Repositories sigma_delta_dac_dual_loop

[/] [sigma_delta_dac_dual_loop/] [trunk/] [dsm3/] [dac_tb.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 wzab
-------------------------------------------------------------------------------
2
-- Title      : Testbench for design "dac_dsm2"
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : dac_dsm2_tb.vhd
6
-- Author     : Wojciech M. Zabolotny ( wzab[at]ise.pw.edu.pl )
7
-- Company    : 
8
-- Created    : 2009-04-28
9
-- Last update: 2012-10-16
10
-- Platform   : 
11
-- Standard   : VHDL'93c
12
-------------------------------------------------------------------------------
13
-- Description: Testbench for S-D DAC converters
14
-------------------------------------------------------------------------------
15
-- Copyright (c) 2009  - THIS IS PUBLIC DOMAIN CODE!!!
16
-------------------------------------------------------------------------------
17
-- Revisions  :
18
-- Date        Version  Author  Description
19
-- 2009-04-28  1.0      wzab    Created
20
-------------------------------------------------------------------------------
21
 
22
library ieee;
23
use ieee.std_logic_1164.all;
24
use ieee.numeric_std.all;
25
use ieee.math_real.all;
26
use std.textio.all;
27
 
28
-------------------------------------------------------------------------------
29
 
30
entity dac_tb is
31
 
32
end dac_tb;
33
 
34
-------------------------------------------------------------------------------
35
 
36
architecture beh1 of dac_tb is
37
 
38
  -- Configuration of the testbench
39
  -- Clock period [ns]
40
  constant TCLK : time := 10 ns;
41
  constant OSR  : real := 256.0;        -- Oversampling ratio:
42
 
43
  constant FREQ1  : real := 0.35;  -- Frequency of the first sinusoid (relative to the sampling frequency)
44
  constant AMP1   : real := 0.2;        -- Amplitude of the first sinusoid
45
  constant PHASE1 : real := 0.35;       -- Phase of the first sinusoid
46
  constant FREQ2  : real := 0.3;  -- Frequency of the second sinusoid (relative to the sampling frequency)
47
  constant AMP2   : real := 0.4;        -- Amplitude of the second sinusoid
48
  constant PHASE2 : real := 0.35;       -- Phase of the second sinusoid
49
  constant FREQ3  : real := 0.25;  -- Frequency of the third sinusoid (relative to the sampling frequency)
50
  constant AMP3   : real := 0.3;        -- Amplitude of the third sinusoid
51
  constant PHASE3 : real := 0.35;       -- Phase of the third sinusoid
52
  constant TSTEP  : real := 3.1415926 / OSR;  -- Phase/time step of the sinusoid generation (considering the OSR)
53
 
54
  file OUTFILE : text is out "dac_tb.dat";
55
 
56
  component dac_dsm3_top
57
    generic (
58
      nbits : integer);
59
    port (
60
      din   : in  signed((nbits-1) downto 0);
61
      dout  : out std_logic;
62
      clk   : in  std_logic;
63
      n_rst : in  std_logic);
64
  end component;
65
 
66
  -- component generics
67
  constant nbits : integer := 16;
68
 
69
  -- component ports
70
  signal din    : signed((nbits-1) downto 0) := (others => '0');
71
  signal dout   : std_logic                  := '0';
72
  signal n_rst  : std_logic                  := '0';
73
 
74
  -- input signal
75
  signal s_inp  : real      := 0.0;
76
  signal s_time : real      := 0.0;
77
  -- clock
78
  signal Clk    : std_logic := '1';
79
 
80
begin  -- beh1
81
 
82
  -- component instantiation
83
  DUT1 : dac_dsm3_top
84
    generic map (
85
      nbits => nbits)
86
    port map (
87
      din   => din,
88
      dout  => dout,
89
      clk   => clk,
90
      n_rst => n_rst);
91
 
92
  -- clock generation
93
  Clk <= not Clk after TCLK/2.0;
94
 
95
  -- Generation of input signal and simulation of DACs
96
  din <= to_signed(integer(s_inp), nbits);
97
  process (clk, n_rst)
98
    variable s  : line;
99
    variable c  : character := ' ';
100
    variable c1 : character := '1';
101
    variable c0 : character := '0';
102
  begin  -- process
103
    if n_rst = '0' then                 -- asynchronous reset (active low)
104
      s_time <= 0.0;
105
    elsif clk'event and clk = '1' then  -- rising clock edge
106
      s_time <= s_time+TSTEP;
107
      s_inp <= (2.0**(nbits-1))*(
108
        AMP1 * sin(s_time*FREQ1+PHASE1) +
109
        AMP2 * sin(s_time*FREQ2+PHASE2) +
110
        AMP3 * sin(s_time*FREQ3+PHASE3)
111
        );
112
      -- Write results to file
113
      write(s, s_inp);
114
      write(s, c);
115
 
116
      if dout = '1' then
117
        write(s, c1);
118
      else
119
        write(s, c0);
120
      end if;
121
      writeline(OUTFILE, s);
122
    end if;
123
  end process;
124
 
125
  -- waveform generation
126
  WaveGen_Proc : process
127
  begin
128
    -- insert signal assignments here  
129
    wait until Clk = '1';
130
    wait for 25 ns;
131
    n_rst <= '1';
132
  end process WaveGen_Proc;
133
 
134
end beh1;
135
 
136
 

powered by: WebSVN 2.1.0

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