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

Subversion Repositories manchesteruart

[/] [manchesteruart/] [trunk/] [bench/] [vhdl/] [manchester_tb.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 skeptonomi
--*************************************************************************
2
--*                                                                       *
3
--* Copyright (C) 2014 William B Hunter - LGPL                            *
4
--*                                                                       *
5
--* This source file may be used and distributed without                  *
6
--* restriction provided that this copyright statement is not             *
7
--* removed from the file and that any derivative work contains           *
8
--* the original copyright notice and the associated disclaimer.          *
9
--*                                                                       *
10
--* This source file is free software; you can redistribute it            *
11
--* and/or modify it under the terms of the GNU Lesser General            *
12
--* Public License as published by the Free Software Foundation;          *
13
--* either version 2.1 of the License, or (at your option) any            *
14
--* later version.                                                        *
15
--*                                                                       *
16
--* This source is distributed in the hope that it will be                *
17
--* useful, but WITHout ANY WARRANTY; without even the implied            *
18
--* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR               *
19
--* PURPOSE.  See the GNU Lesser General Public License for more          *
20
--* details.                                                              *
21
--*                                                                       *
22
--* You should have received a copy of the GNU Lesser General             *
23
--* Public License along with this source; if not, download it            *
24
--* from http://www.opencores.org/lgpl.shtml                              *
25
--*                                                                       *
26
--*************************************************************************
27
--
28
-- Engineer: William B Hunter
29
-- Create Date: 08/08/2014
30
-- Project: Manchester Uart
31
-- File: Manchester_tb.vhd
32
-- Description: This is a testbench for the Manchester UART. It consists of two instances of
33
--   the UART, both run on independant clocks. The clocks start off at the same frequency (
34
--    16x 9600 baud), and one is slowly decreaased to check the robustness of the uart to
35
--    differences in clock frequencies. Currently it fails when the clocks are about 18% different.
36
--  The test bench consists of the two UARTs, each has a feeder process and a capture process.
37
--     The feeder sends data to the transmitters, and the capture process is simply to make viewing
38
--     the output more convenient. 
39
 
40
----------------------------------------------------------------------------------
41
 
42
 
43
entity manchester_tb is
44
 
45
end manchester_tb;
46
 
47
 
48
library IEEE;
49
use IEEE.STD_LOGIC_1164.ALL;
50
use IEEE.NUMERIC_STD.ALL;
51
 
52
architecture Behavioral of manchester_tb is
53
  signal sdat_1to2 : std_logic := '1';
54
  signal sdat_2to1 : std_logic := '1';
55
  signal clk1 : std_logic := '1';
56
  signal clk2 : std_logic := '1';
57
  signal xrst : std_logic := '1';
58
  signal txerr1 : std_logic := '0';
59
  signal txidle1 : std_logic := '0';
60
  signal rxerr1 : std_logic := '0';
61
  signal rxidle1 : std_logic := '0';
62
  signal txdata1 : std_logic_vector(15 downto 0) := x"0000";
63
  signal txstb1 : std_logic := '0';
64
  signal rxdata1 : std_logic_vector(15 downto 0) := x"0000";
65
  signal rxstb1 : std_logic := '0';
66
  signal txerr2 : std_logic := '0';
67
  signal txidle2 : std_logic := '0';
68
  signal rxerr2 : std_logic := '0';
69
  signal rxidle2 : std_logic := '0';
70
  signal txdata2 : std_logic_vector(15 downto 0) := x"0000";
71
  signal txstb2 : std_logic := '0';
72
  signal rxdata2 : std_logic_vector(15 downto 0) := x"0000";
73
  signal rxstb2 : std_logic := '0';
74
  signal clk2_time : time := 3.255 ns;
75
  signal cap1 : std_logic_vector(15 downto 0) := x"0000";
76
  signal cap2 : std_logic_vector(15 downto 0) := x"0000";
77
 
78
begin
79
 
80
  xrst <= '1', '0' after 1000 ns;
81
 
82
  --clk1 is a fixed 16x 9600 clock
83
  p_clk1 :process
84
  begin
85
    clk1 <= '0';
86
    wait for 3.255 us;
87
    clk1 <= '1';
88
    wait for 3.255 us;
89
  end process;
90
 
91
  --this process slowly decreases the clk2 by 100 ns every 10 ms
92
  p_clkmod :process
93
  begin
94
    clk2_time <= 3.255 us;
95
    while true loop
96
      wait for 10 ms;
97
      clk2_time <= clk2_time - 100 ns;
98
    end loop;
99
  end process;
100
 
101
  --this is the slowly decreasing clock 2
102
  p_clk2 :process
103
  begin
104
    clk2 <= '0';
105
    wait for clk2_time;
106
    clk2 <= '1';
107
    wait for clk2_time;
108
  end process;
109
 
110
 
111
  --first UART
112
  u_manch1 : entity work.Manchester(rtl)
113
  port map(
114
    clk16x => clk1,
115
    srst => xrst,
116
    rxd => sdat_2to1,
117
    rx_data => rxdata1,
118
    rx_stb => rxstb1,
119
    rx_idle => rxidle1,
120
    fm_err => rxerr1,
121
    txd => sdat_1to2,
122
    tx_data => txdata1,
123
    tx_stb => txstb1,
124
    tx_idle => txidle1,
125
    or_err => txerr1
126
  );
127
 
128
 
129
  --second UART
130
  u_manch2 : entity work.Manchester(rtl)
131
  port map(
132
    clk16x => clk2,
133
    srst => xrst,
134
    rxd => sdat_1to2,
135
    rx_data => rxdata2,
136
    rx_stb => rxstb2,
137
    rx_idle => rxidle2,
138
    fm_err => rxerr2,
139
    txd => sdat_2to1,
140
    tx_data => txdata2,
141
    tx_stb => txstb2,
142
    tx_idle => txidle2,
143
    or_err => txerr2
144
  );
145
 
146
  --feeder 1 - feeds data into UART1's transmitter
147
  p_feeder1 : process
148
  begin
149
    txdata1 <= x"aaaa";
150
    txstb1 <= '0';
151
    wait until xrst = '0';
152
    for i in 1 to 100 loop
153
      wait until clk1 = '1';
154
    end loop;
155
    while unsigned(txdata1) < x"abaa" loop
156
      wait until clk1 = '1';
157
      if txidle1 = '1' then
158
        wait for 400 us;
159
        wait until clk1 = '0';
160
        txdata1 <= std_logic_vector(unsigned(txdata1) + x"0001");
161
        txstb1 <= '1';
162
        wait until clk1 = '0';
163
        txstb1 <= '0';
164
        wait until clk1 = '0';
165
      end if;
166
    end loop;
167
  end process;
168
 
169
 
170
  --feeder 2 - feeds data into UART2's tranmitter
171
  p_feeder2 : process
172
  begin
173
    txdata2 <= x"5555";
174
    txstb2 <= '0';
175
    wait until xrst = '0';
176
    for i in 1 to 100 loop
177
      wait until clk2 = '1';
178
    end loop;
179
    while unsigned(txdata2) > x"5455" loop
180
      wait until clk2 = '1';
181
      if txidle2 = '1' then
182
        wait for 400 us;
183
        wait until clk2 = '0';
184
        txdata2 <= std_logic_vector(unsigned(txdata2) - x"0001");
185
        txstb2 <= '1';
186
        wait until clk2 = '0';
187
        txstb2 <= '0';
188
        wait until clk2 = '0';
189
      end if;
190
    end loop;
191
  end process;
192
 
193
  --cap1 - captures rx data from UART1's reciever for easy viewing
194
  p_cap1 : process
195
  begin
196
      wait until rxstb1 = '1';
197
      wait until clk1 = '0';
198
      cap1 <= rxdata1;
199
  end process;
200
 
201
  --cap2 - captures rx data from UART2's reciver for easy viewing
202
  p_cap2 : process
203
  begin
204
      wait until rxstb2 = '1';
205
      wait until clk2 = '0';
206
      cap2 <= rxdata2;
207
  end process;
208
 
209
end Behavioral;

powered by: WebSVN 2.1.0

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