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

Subversion Repositories manchesterwireless

[/] [manchesterwireless/] [branches/] [singledouble/] [simTest.vhd] - Blame information for rev 15

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 kingmu
library ieee;
2
use ieee.std_logic_1164.all;
3
 
4
use work.globals.all;
5
 
6
entity testSim is
7
end testSim;
8
 
9
architecture Behavioral of testSim is
10
 
11 12 kingmu
  component manchesterWireless
12 2 kingmu
  port (
13
    clk_i             : in  std_logic;
14
    rst_i             : in  std_logic;
15
    data_i            : in  std_logic;
16
    q_o               : out std_logic_vector(WORD_LENGTH-1 downto 0);
17
    ready_o           : out std_logic;
18
    recieved_debug    : out std_logic_vector(3 downto 0);
19
    waitforstart_rdy  : out std_logic
20
  );
21
  end component;
22
 
23
  signal decode_output : std_logic_vector(WORD_LENGTH-1 downto 0);
24 12 kingmu
  -- up/down and left/right buffers
25
  signal parity_o_buff, parity_o_reg : std_logic;
26 2 kingmu
  signal button_o_buff, button_o_reg : std_logic_vector(1 downto 0);
27 12 kingmu
  signal ud_buff1, ud_buff2, lr_buff1, lr_buff2 : std_logic_vector(6 downto 0);
28 2 kingmu
  signal ud_buff1_reg, ud_buff2_reg, lr_buff1_reg, lr_buff2_reg : std_logic_vector(6 downto 0);
29
  signal char_select : integer range 0 to 3;
30 12 kingmu
  signal reset_manchester, soft_reset, ready_o_buff : std_logic;
31
 
32
 
33 2 kingmu
  signal clk_i             : std_logic;
34
  signal rst_i             : std_logic := '1';
35
  signal data_i            : std_logic;
36
  signal ready_o           : std_logic;
37
  signal character_o       : std_logic_vector(0 to 7);
38
  signal anode_ctrl        : std_logic_vector(3 downto 0);
39
  signal button_o          : std_logic_vector(1 downto 0);
40
  signal parity_o          : std_logic;
41
  signal recieved_debug    : std_logic_vector(3 downto 0);
42 12 kingmu
  signal waitforstart_rdy  : std_logic;
43
 
44 2 kingmu
  signal coded_rdy: std_logic;
45
  signal coded : std_logic_vector(WORD_LENGTH-1 downto 0);
46
  constant half_period : time := 10 ns;
47
  constant period : time := 2*half_period;
48
  constant mid_single : time := (INTERVAL_MIN_SINGLE+INTERVAL_MAX_SINGLE)/2*period;
49 12 kingmu
  constant WORD : std_logic_vector(28 downto 0) := "01100101100101010101010101010";
50 2 kingmu
 
51
begin
52
  character_o(7) <= '1'; -- turn off decimal point
53
 
54
  reset_manchester <=  rst_i or soft_reset;
55
  ready_o <= ready_o_buff;
56
 
57 12 kingmu
  inst_manchesterWireless: manchesterWireless
58 2 kingmu
  port map(
59
    clk_i   => clk_i,
60
    rst_i   => reset_manchester,
61
    data_i  => data_i,
62
    q_o     => decode_output,
63
    ready_o => ready_o_buff,
64
    recieved_debug => recieved_debug,
65
    waitforstart_rdy => waitforstart_rdy
66
  );
67
 
68
  -- the transmitter is sending the following UP/DOWN (4 bits)
69
  -- then left/right (3 bits), and finally the parity (1 bit)
70
  -- each command was ror onto the transmitter -- one at a time.
71
  -- the decoder was written to assume that all the data was in 
72
  -- being shifted to the transmitter from the right
73
  -- thus, while we are transmitting:
74
  -- initialize|up/down|left/right|buttons|parity|stop
75
  -- the decoder will return results to us as
76
  -- parity|buttons|left/right|up/down
77
  -- bits 9|  8-7  |   6-4    |  3-0
78
 
79
  -- decode up/down first digit (ones place)
80
  with decode_output(3 downto 0) select
81
     ud_buff1  <= "0000001" when x"D",  -- off
82
                   "1001111" when x"F",  -- 1
83
                   "0010010" when x"7",  -- 2
84
                   "0000110" when x"5",  -- 3
85
                   "1001100" when x"1",  -- 4
86
                   "0100100" when x"3",  -- 5
87
                   "0100000" when x"2",  -- 6
88
                   "0001111" when x"6",  -- 7
89
                   "0000000" when x"e",  -- 8
90
                   "0000100" when x"c",  -- 9
91
                   "0000001" when x"a",  -- 10
92
                   "1001111" when x"b",  -- 11
93
                   "0010010" when x"9",  -- 12
94
                   "0000110" when x"8",  -- 13
95
                   "1111111" when others; -- 'E'rror
96
 
97
  -- decode up/down second digit (tens place)                 
98
  with decode_output(3 downto 0) select
99
     ud_buff2  <=  "1001111" when x"a",  -- 10
100
                   "1001111" when x"b",  -- 11
101
                   "1001111" when x"9",  -- 12
102
                   "1001111" when x"8",  -- 13
103
                   "1111111" when others;
104
 
105
  -- decode left/right first digit
106
  with decode_output(6 downto 4) select
107
     lr_buff1  <=  "1001111" when "010",  -- -1
108
                   "0010010" when "011",  -- -2
109
                   "0000110" when "001",  -- -3
110
                   "0000001" when "110",  -- 0
111
                   "1001111" when "100",  -- 1
112
                   "0010010" when "101",  -- 2
113
                   "0000110" when "111",  -- 3
114
                   "1111111" when others;
115
 
116
  -- decode left/right sign digit
117
  with decode_output(6 downto 4) select
118
     lr_buff2  <=  "1111110" when "010",  -- -1
119
                   "1111110" when "011",  -- -2
120
                   "1111110" when "001",  -- -3
121
                   "1111111" when others;
122
 
123
  -- decode buttons                    
124
  with decode_output(8 downto 7) select
125
     button_o_buff  <=  "11" when "10",  -- 00
126
                        "01" when "11",  -- 10
127
                        "10" when "01",  -- 01
128
                        "00" when "00",  -- 11
129
                        "11" when others;
130
 
131 12 kingmu
  parity_o_buff <= decode_output(9);
132 2 kingmu
  parity_o <= parity_o_reg;
133
 
134
  process (clk_i,rst_i)
135
    variable counter : integer range 0 to 1023;
136
  begin
137
     if rst_i = '1' then
138
       char_select <= 0;
139
       counter := 0;
140 12 kingmu
       div_clk := '0';
141 2 kingmu
       soft_reset <= '0';
142 12 kingmu
     elsif (clk_i'event and clk_i = '1') then
143
       -- register the output
144
       if (ready_o_buff = '1') then
145
        ud_buff1_reg <= ud_buff1;
146
        ud_buff2_reg <= ud_buff2;
147
        lr_buff1_reg <= lr_buff1;
148
        lr_buff2_reg <= lr_buff2;
149
        button_o_reg <= button_o_buff;
150
        parity_o_reg <= parity_o_buff;
151
        soft_reset <= '1';
152
       else
153
        soft_reset <= '0';
154
       end if;
155 2 kingmu
 
156
       counter := counter + 1;
157
       if (counter = 1023) then
158
 
159 12 kingmu
         -- this is for simulation
160
         -- ModelSim does not want to roll over
161
         if char_select < 3 then
162
          char_select <= char_select + 1;
163
         else
164
          char_select <= 0;
165
         end if;
166
 
167 2 kingmu
         counter := 0;
168
       end if;
169
 
170
     end if;
171
  end process;
172
 
173
  -- set output
174
  with char_select select
175
    character_o(0 to 6) <= ud_buff2_reg when 0,
176
                           ud_buff1_reg when 1,
177
                           lr_buff2_reg when 2,
178
                           lr_buff1_reg when 3;
179
 
180
  with char_select select
181
    anode_ctrl <= "0111" when 0,
182
                  "1011" when 1,
183
                  "1101" when 2,
184
                  "1110" when 3;
185
 
186
  process
187
  begin
188
    wait for 5*period;
189
    rst_i <= '0';
190
 
191
    -- begin transmission header 
192
    data_i <= '1';
193
    wait for 5*MID_SINGLE;
194
 
195
    data_i <= '0';
196
    wait for MID_SINGLE;
197
    -- end transmission header
198
 
199
    for i in WORD'left downto 0 loop
200
      data_i <= WORD(i);
201
      wait for MID_SINGLE;
202
    end loop;
203
 
204
    data_i <= '1';
205
    wait for MID_SINGLE;
206
 
207
    rst_i <= '1';
208
    wait for 5*period;
209
 
210
  end process;
211
 
212
  clock : process
213
  begin
214
    clk_i <= '1';
215
    loop
216
      wait for half_period;
217
      clk_i <= not clk_i;
218
    end loop;
219 12 kingmu
  end process;
220 2 kingmu
 
221
end Behavioral;
222
 
223
 
224
 

powered by: WebSVN 2.1.0

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