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

Subversion Repositories t48

[/] [t48/] [tags/] [rel_1_4/] [rtl/] [vhdl/] [adc.vhd] - Blame information for rev 344

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 333 arniml
-------------------------------------------------------------------------------
2
--
3
-- The T48 SAR ADC.
4
--
5
-- Copyright (c) 2023, Arnim Laeuger (arniml@opencores.org)
6
--
7
-- All rights reserved
8
--
9
-- Redistribution and use in source and synthezised forms, with or without
10
-- modification, are permitted provided that the following conditions are met:
11
--
12
-- Redistributions of source code must retain the above copyright notice,
13
-- this list of conditions and the following disclaimer.
14
--
15
-- Redistributions in synthesized form must reproduce the above copyright
16
-- notice, this list of conditions and the following disclaimer in the
17
-- documentation and/or other materials provided with the distribution.
18
--
19
-- Neither the name of the author nor the names of other contributors may
20
-- be used to endorse or promote products derived from this software without
21
-- specific prior written permission.
22
--
23
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
27
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
-- POSSIBILITY OF SUCH DAMAGE.
34
--
35
-- Please report bugs to the author, but before you do so, please
36
-- make sure that this is not a derivative work and that
37
-- you have the latest version of this file.
38
--
39
-- The latest version of this file can be found at:
40
--      http://www.opencores.org/cvsweb.shtml/t48/
41
--
42
-------------------------------------------------------------------------------
43
 
44
library ieee;
45
use ieee.std_logic_1164.all;
46
 
47
use work.t48_pack.word_t;
48
use work.t48_pack.mstate_t;
49
 
50
entity t48_adc is
51
 
52
  port (
53
    clk_i      : in  std_logic;
54
    res_i      : in  std_logic;
55
    en_clk_i   : in  boolean;
56
    ale_i      : in  boolean;
57
    mstate_i   : in  mstate_t;
58
    sel_an0_i  : in  boolean;
59
    sel_an1_i  : in  boolean;
60
    read_adc_i : in  boolean;
61
    data_o     : out word_t;
62
    sel_an_o   : out std_logic;
63
    sh_o       : out std_logic;
64
    sar_o      : out std_logic_vector(7 downto 0);
65
    comp_i     : in  std_logic
66
  );
67
 
68
end t48_adc;
69
 
70
 
71
use work.t48_pack.all;
72
 
73
architecture rtl of t48_adc is
74
 
75
  type adc_state_t is (ADC_SH,
76
                       ADC_B7, ADC_B6, ADC_B5, ADC_B4,
77
                       ADC_B3, ADC_B2, ADC_B1, ADC_B0);
78
  signal adc_state_q : adc_state_t;
79
 
80
  signal ale_q : boolean;
81
 
82
  signal sar_q, crr_q : word_t;
83
 
84
  signal start_conv_s : boolean;
85
 
86
begin
87
 
88
  start_conv_s <= sel_an0_i or sel_an1_i;
89
 
90
  process (res_i, clk_i)
91
  begin
92
    if res_i = res_active_c then
93
      ale_q       <= false;
94
      sar_q       <= (others => '0');
95
      crr_q       <= (others => '0');
96
      sel_an_o    <= '0';
97
      adc_state_q <= ADC_SH;
98
 
99
    elsif clk_i'event and clk_i = clk_active_c then
100
      if ale_i then
101
        ale_q <= true;
102
      elsif en_clk_i then
103
        ale_q <= ale_i;
104
      end if;
105
 
106
      if en_clk_i then
107
        if sel_an0_i then
108
          sel_an_o <= '0';
109
        elsif sel_an1_i then
110
          sel_an_o <= '1';
111
        end if;
112
 
113
        case adc_state_q is
114
          when ADC_SH =>
115
            if ale_q then
116
              adc_state_q <= ADC_B7;
117
              sar_q       <= "10000000";
118
            end if;
119
 
120
          when ADC_B7 =>
121
            if mstate_i = MSTATE1 then
122
              sar_q(7)    <= comp_i;
123
              sar_q(6)    <= '1';
124
              adc_state_q <= ADC_B6;
125
            end if;
126
 
127
          when ADC_B6 =>
128
            if mstate_i = MSTATE3 then
129
              sar_q(6)    <= comp_i;
130
              sar_q(5)    <= '1';
131
              adc_state_q <= ADC_B5;
132
            end if;
133
 
134
          when ADC_B5 =>
135
            if mstate_i = MSTATE1 then
136
              sar_q(5)    <= comp_i;
137
              sar_q(4)    <= '1';
138
              adc_state_q <= ADC_B4;
139
            end if;
140
 
141
          when ADC_B4 =>
142
            if mstate_i = MSTATE3 then
143
              sar_q(4)    <= comp_i;
144
              sar_q(3)    <= '1';
145
              adc_state_q <= ADC_B3;
146
            end if;
147
 
148
          when ADC_B3 =>
149
            if mstate_i = MSTATE1 then
150
              sar_q(3)    <= comp_i;
151
              sar_q(2)    <= '1';
152
              adc_state_q <= ADC_B2;
153
            end if;
154
 
155
          when ADC_B2 =>
156
            if mstate_i = MSTATE3 then
157
              sar_q(2)    <= comp_i;
158
              sar_q(1)    <= '1';
159
              adc_state_q <= ADC_B1;
160
            end if;
161
 
162
          when ADC_B1 =>
163
            if mstate_i = MSTATE1 then
164
              sar_q(1)    <= comp_i;
165
              sar_q(0)    <= '1';
166
              adc_state_q <= ADC_B0;
167
            end if;
168
 
169
          when ADC_B0 =>
170
            if mstate_i = MSTATE3 then
171
              sar_q(0)    <= comp_i;
172
              crr_q       <= sar_q(7 downto 1) & comp_i;
173
              adc_state_q <= ADC_SH;
174
            end if;
175
 
176
          when others =>
177
            adc_state_q <= ADC_SH;
178
 
179
        end case;
180
        --
181
        if start_conv_s then
182
          adc_state_q <= ADC_SH;
183
        end if;
184
 
185
      end if;
186
    end if;
187
  end process;
188
 
189
 
190
  -----------------------------------------------------------------------------
191
  -- Outpu mapping
192
  -----------------------------------------------------------------------------
193
  sh_o   <= '1' when adc_state_q = ADC_SH and ale_q and en_clk_i else '0';
194
  sar_o  <= sar_q;
195
  data_o <=   crr_q
196
            when read_adc_i else
197
              (others => bus_idle_level_c);
198
 
199
end rtl;

powered by: WebSVN 2.1.0

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