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

Subversion Repositories manchesterwireless

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

Go to most recent revision | 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
--  Future revisions tracked in Subversion at OpenCores.org
22
--  under the manchesterwireless project
23
-----------------------------------------------------------------------------
24
 
25
library ieee;
26
use ieee.std_logic_1164.all;
27
use ieee.std_logic_arith.all;
28
use work.globals.all;
29
 
30
--------------------------------------------------------------------------------
31
 
32
entity singleDouble is
33
  port (
34
    clk_i   :  in  std_logic;
35
    ce_i    :  in  std_logic;
36
    rst_i   :  in  std_logic;
37
    data_i  :  in  std_logic;
38
    q_o     :  out std_logic_vector(3 downto 0);
39
    ready_o :  out std_logic
40
  );
41
end;
42
 
43
--------------------------------------------------------------------------------
44
--------------------------------------------------------------------------------
45
 
46
architecture behavioral of singleDouble is
47
 
48
  signal single_one:      std_logic;
49
  signal double_one:      std_logic;
50
  signal single_zero:     std_logic;
51
  signal double_zero:     std_logic;
52
  signal count_ones    : integer range 0 to INTERVAL_MAX_DOUBLE;
53
  signal count_zeros   : integer range 0 to INTERVAL_MAX_DOUBLE;
54
 
55
  signal data_i_d  :         std_logic;
56
  signal data_i_d2 :         std_logic;
57
 
58
  signal    ct_state, nxt_state  : bit_vector(2 downto 0);
59
  signal    ce_i_RT, data_i_RT, data_i_FT : std_logic;
60
  signal    ce_i_d, ce_i_d2               : std_logic;
61
  signal    count_zeros_en, count_ones_en : std_logic;
62
  constant  IDLE: bit_vector(2 downto 0) := "001";
63
  constant  CNT0: bit_vector(2 downto 0) := "010";
64
  constant  CNT1: bit_vector(2 downto 0) := "100";
65
 
66
  begin
67
    process (clk_i,rst_i)
68
    begin
69
      if (rst_i = '1') then
70
        ce_i_d  <= '0';
71
        ce_i_d2 <= '0';
72
      elsif (clk_i'event and clk_i = '1') then
73
        ce_i_d    <= ce_i;
74
        ce_i_d2  <= ce_i_d;
75
      end if;
76
    end process;
77
    ce_i_RT   <= ce_i_d and (not(ce_i_d2));  --CE rising edge
78
 
79
    process (clk_i,rst_i)
80
    begin
81
      if (rst_i = '1') then
82
        data_i_d  <= '0';
83
        data_i_d2 <= '0';
84
      elsif (clk_i'event and clk_i = '1') then
85
        data_i_d  <= data_i;
86
        data_i_d2  <= data_i_d;
87
      end if;
88
    end process;
89
    data_i_RT   <= data_i_d and (not(data_i_d2));  --Data rising edge
90
    data_i_FT   <= (not data_i_d) and data_i_d2;  --Data falling edge
91
 
92
    ready_o     <= ((data_i_RT or data_i_FT) and ce_i) or ce_i_RT;
93
 
94
    process (clk_i,rst_i)  --State register
95
    begin
96
      if (rst_i = '1') then
97
        ct_state <= IDLE;
98
      elsif (clk_i'event and clk_i = '1') then
99
        ct_state <= nxt_state;
100
      end if;
101
    end process;
102
 
103
    process (ct_state,ce_i_RT,data_i,ce_i,data_i_FT,data_i_RT)  --Next State logic
104
    begin
105
      case ct_state is
106
          when IDLE   =>
107
            if ((ce_i_RT = '1') and (data_i = '0'))then
108
              nxt_State <= CNT0;
109
            elsif ((ce_i_RT = '1') and (data_i = '1')) then
110
              nxt_state <= CNT1;
111
            else
112
              nxt_state <= IDLE;
113
            end if;
114
 
115
          when CNT0   =>
116
            if (ce_i = '0') then
117
              nxt_state <= IDLE;
118
            elsif (data_i_RT = '1') then
119
              nxt_state <= CNT1;
120
            else
121
              nxt_state <= CNT0;
122
            end if;
123
 
124
          when CNT1   =>
125
            if (ce_i = '0') then
126
              nxt_state <= IDLE;
127
            elsif (data_i_FT = '1') then
128
              nxt_state <= CNT0;
129
            else
130
              nxt_state <= CNT1;
131
            end if;
132
 
133
          when others   =>
134
            nxt_state <=  IDLE;
135
      end case;
136
    end process;
137
 
138
    process (ct_state)  --State output logic
139
    begin
140
      case ct_state is
141
        when IDLE   =>
142
          count_ones_en    <= '0';
143
          count_zeros_en   <= '0';
144
 
145
        when CNT0   =>
146
          count_ones_en    <= '0';
147
          count_zeros_en   <= '1';
148
 
149
        when CNT1   =>
150
          count_ones_en    <= '1';
151
          count_zeros_en   <= '0';
152
        when others    => null;
153
    end case;
154
  end process;
155
 
156
  process (clk_i,rst_i)  --counters
157
  begin
158
    if (rst_i = '1') then
159
      count_ones    <=  0;
160
      count_zeros   <=  0;
161
    elsif (clk_i'event and clk_i = '1') then
162
      if (count_zeros_en = '1') then
163
        count_zeros   <= count_zeros + 1;
164
        count_ones    <= 0;
165
      elsif (count_ones_en = '1') then
166
        count_ones   <= count_ones + 1;
167
        count_zeros    <= 0;
168
      end if;
169
    end if;
170
  end process;
171
 
172
  process(count_ones)
173
  begin
174
    if (count_ones >= INTERVAL_MIN_DOUBLE) and (count_ones <= INTERVAL_MAX_DOUBLE) then
175
      double_one <= '1';
176
    else
177
      double_one <= '0';
178
    end if;
179
    if (count_ones >= INTERVAL_MIN_SINGLE) and (count_ones <= INTERVAL_MAX_SINGLE) then
180
      single_one <= '1';
181
    else
182
      single_one <= '0';
183
    end if;
184
  end process;
185
 
186
  process(count_zeros)
187
  begin
188
    if (count_zeros >= INTERVAL_MIN_DOUBLE) and (count_zeros <= INTERVAL_MAX_DOUBLE) then
189
      double_zero <= '1';
190
    else
191
      double_zero <= '0';
192
    end if;
193
    if (count_zeros >= INTERVAL_MIN_SINGLE) and (count_zeros <= INTERVAL_MAX_SINGLE) then
194
      single_zero <= '1';
195
    else
196
      single_zero <= '0';
197
    end if;
198
  end process;
199
 
200
  process (rst_i,data_i_RT,data_i_FT)
201
  begin
202
    if (rst_i = '1') then
203
      q_o   <= "0000";
204
    else
205
      q_o   <= double_zero & single_zero & double_one & single_one;
206
    end if;
207
  end process;
208
end;

powered by: WebSVN 2.1.0

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