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

Subversion Repositories manchesterwireless

[/] [manchesterwireless/] [branches/] [singledouble/] [singleDouble/] [singleDouble.vhd] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 kingmu
-----------------------------------------------------------------------------
2
--      Copyright (C) 2009 José Rodríguez-Navarro
3
--
4
-- This code is free software; you can redistribute it and/or
5
-- modify it under the terms of the GNU Lesser General Public
6
-- License as published by the Free Software Foundation; either
7
-- version 2.1 of the License, or (at your option) any later version.
8
--
9
-- This code is distributed in the hope that it will be useful,
10
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
11
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
-- Lesser General Public License for more details.
13
--
14
--  Identify single/double ones/zeros based on length 
15
--  of time data_i is high/low
16
--
17
--  Revision  Date        Author                Comment
18
--  --------  ----------  --------------------  ----------------
19
--  1.0       20/02/09    J. Rodriguez-Navarro  Initial revision
20
--  1.1       21/06/09    M. Thiagarajan        Modified with FSM
21 9 thiagu_com
--  1.2       25/06/09    M. Thiagarajan        Modified Nxt State Logic
22
--                                              to avoid inferring latch
23 7 kingmu
--  Future revisions tracked in Subversion at OpenCores.org
24
--  under the manchesterwireless project
25
-----------------------------------------------------------------------------
26
 
27
library ieee;
28
use ieee.std_logic_1164.all;
29
use ieee.std_logic_arith.all;
30
use work.globals.all;
31
 
32
--------------------------------------------------------------------------------
33
 
34
entity singleDouble is
35
  port (
36
    clk_i   :  in  std_logic;
37
    ce_i    :  in  std_logic;
38
    rst_i   :  in  std_logic;
39
    data_i  :  in  std_logic;
40
    q_o     :  out std_logic_vector(3 downto 0);
41
    ready_o :  out std_logic
42
  );
43
end;
44
 
45
--------------------------------------------------------------------------------
46
--------------------------------------------------------------------------------
47
 
48
architecture behavioral of singleDouble is
49
 
50
  signal single_one:      std_logic;
51
  signal double_one:      std_logic;
52
  signal single_zero:     std_logic;
53
  signal double_zero:     std_logic;
54
  signal count_ones    : integer range 0 to INTERVAL_MAX_DOUBLE;
55
  signal count_zeros   : integer range 0 to INTERVAL_MAX_DOUBLE;
56
 
57
  signal data_i_d  :         std_logic;
58
  signal data_i_d2 :         std_logic;
59
 
60
  signal    ct_state, nxt_state  : bit_vector(2 downto 0);
61
  signal    ce_i_RT, data_i_RT, data_i_FT : std_logic;
62
  signal    ce_i_d, ce_i_d2               : std_logic;
63
  signal    count_zeros_en, count_ones_en : std_logic;
64
  constant  IDLE: bit_vector(2 downto 0) := "001";
65
  constant  CNT0: bit_vector(2 downto 0) := "010";
66
  constant  CNT1: bit_vector(2 downto 0) := "100";
67
 
68
  begin
69
    process (clk_i,rst_i)
70
    begin
71
      if (rst_i = '1') then
72
        ce_i_d  <= '0';
73
        ce_i_d2 <= '0';
74
      elsif (clk_i'event and clk_i = '1') then
75
        ce_i_d    <= ce_i;
76
        ce_i_d2  <= ce_i_d;
77
      end if;
78
    end process;
79
    ce_i_RT   <= ce_i_d and (not(ce_i_d2));  --CE rising edge
80
 
81
    process (clk_i,rst_i)
82
    begin
83
      if (rst_i = '1') then
84
        data_i_d  <= '0';
85
        data_i_d2 <= '0';
86
      elsif (clk_i'event and clk_i = '1') then
87
        data_i_d  <= data_i;
88
        data_i_d2  <= data_i_d;
89
      end if;
90
    end process;
91
    data_i_RT   <= data_i_d and (not(data_i_d2));  --Data rising edge
92
    data_i_FT   <= (not data_i_d) and data_i_d2;  --Data falling edge
93
 
94
    ready_o     <= ((data_i_RT or data_i_FT) and ce_i) or ce_i_RT;
95
 
96
    process (clk_i,rst_i)  --State register
97
    begin
98
      if (rst_i = '1') then
99
        ct_state <= IDLE;
100
      elsif (clk_i'event and clk_i = '1') then
101
        ct_state <= nxt_state;
102
      end if;
103
    end process;
104
 
105
    process (ct_state,ce_i_RT,data_i,ce_i,data_i_FT,data_i_RT)  --Next State logic
106
    begin
107
      case ct_state is
108
          when IDLE   =>
109
            if ((ce_i_RT = '1') and (data_i = '0'))then
110
              nxt_State <= CNT0;
111
            elsif ((ce_i_RT = '1') and (data_i = '1')) then
112
              nxt_state <= CNT1;
113
            else
114
              nxt_state <= IDLE;
115
            end if;
116
 
117
          when CNT0   =>
118
            if (ce_i = '0') then
119
              nxt_state <= IDLE;
120
            elsif (data_i_RT = '1') then
121
              nxt_state <= CNT1;
122
            else
123
              nxt_state <= CNT0;
124
            end if;
125
 
126
          when CNT1   =>
127
            if (ce_i = '0') then
128
              nxt_state <= IDLE;
129
            elsif (data_i_FT = '1') then
130
              nxt_state <= CNT0;
131
            else
132
              nxt_state <= CNT1;
133
            end if;
134
 
135
          when others   =>
136
            nxt_state <=  IDLE;
137
      end case;
138
    end process;
139
 
140
    process (ct_state)  --State output logic
141
    begin
142
      case ct_state is
143
        when IDLE   =>
144
          count_ones_en    <= '0';
145
          count_zeros_en   <= '0';
146
 
147
        when CNT0   =>
148
          count_ones_en    <= '0';
149
          count_zeros_en   <= '1';
150
 
151
        when CNT1   =>
152
          count_ones_en    <= '1';
153
          count_zeros_en   <= '0';
154 9 thiagu_com
        --when others    => null;
155
        when others    =>
156
          count_ones_en    <= '0';
157
          count_zeros_en   <= '0';
158 7 kingmu
    end case;
159
  end process;
160
 
161
  process (clk_i,rst_i)  --counters
162
  begin
163
    if (rst_i = '1') then
164
      count_ones    <=  0;
165
      count_zeros   <=  0;
166
    elsif (clk_i'event and clk_i = '1') then
167
      if (count_zeros_en = '1') then
168
        count_zeros   <= count_zeros + 1;
169
        count_ones    <= 0;
170
      elsif (count_ones_en = '1') then
171
        count_ones   <= count_ones + 1;
172
        count_zeros    <= 0;
173
      end if;
174
    end if;
175
  end process;
176
 
177
  process(count_ones)
178
  begin
179
    if (count_ones >= INTERVAL_MIN_DOUBLE) and (count_ones <= INTERVAL_MAX_DOUBLE) then
180
      double_one <= '1';
181
    else
182
      double_one <= '0';
183
    end if;
184
    if (count_ones >= INTERVAL_MIN_SINGLE) and (count_ones <= INTERVAL_MAX_SINGLE) then
185
      single_one <= '1';
186
    else
187
      single_one <= '0';
188
    end if;
189
  end process;
190
 
191
  process(count_zeros)
192
  begin
193
    if (count_zeros >= INTERVAL_MIN_DOUBLE) and (count_zeros <= INTERVAL_MAX_DOUBLE) then
194
      double_zero <= '1';
195
    else
196
      double_zero <= '0';
197
    end if;
198
    if (count_zeros >= INTERVAL_MIN_SINGLE) and (count_zeros <= INTERVAL_MAX_SINGLE) then
199
      single_zero <= '1';
200
    else
201
      single_zero <= '0';
202
    end if;
203
  end process;
204
 
205
  process (rst_i,data_i_RT,data_i_FT)
206
  begin
207
    if (rst_i = '1') then
208
      q_o   <= "0000";
209
    else
210
      q_o   <= double_zero & single_zero & double_one & single_one;
211
    end if;
212
  end process;
213
end;

powered by: WebSVN 2.1.0

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