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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_ltc2355_2p.vhd] - Blame information for rev 213

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

Line No. Rev Author Line
1 194 jshamlet
-- Copyright (c)2013, 2020 Jeremy Seth Henry
2
-- All rights reserved.
3
--
4
-- Redistribution and use in source and binary forms, with or without
5
-- modification, are permitted provided that the following conditions are met:
6
--     * Redistributions of source code must retain the above copyright
7
--       notice, this list of conditions and the following disclaimer.
8
--     * Redistributions in binary form must reproduce the above copyright
9
--       notice, this list of conditions and the following disclaimer in the
10
--       documentation and/or other materials provided with the distribution,
11
--       where applicable (as part of a user interface, debugging port, etc.)
12
--
13
-- THIS SOFTWARE IS PROVIDED BY JEREMY SETH HENRY ``AS IS'' AND ANY
14
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
-- DISCLAIMED. IN NO EVENT SHALL JEREMY SETH HENRY BE LIABLE FOR ANY
17
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
--
24 191 jshamlet
-- VHDL units : ltc2355_2p
25
-- Description: Reads out a pair of LTC2355 14-bit ADCs which are wired with
26
--            :  common clock and CONVERT START inputs. Because they are
27
--            :  synchronized, this entity provides simultaneously updated
28
--            :  parallel data buses.
29
--
30
-- Notes      : Depends on the fact that the two LTC2355 converters are wired
31
--            :  with their SCLK and CONV lines tied together, and DATA1 and
32
--            :  DATA2 independently routed to separate I/O pins.
33
 
34
library ieee;
35
use ieee.std_logic_1164.all;
36
use ieee.std_logic_unsigned.all;
37
use ieee.std_logic_arith.all;
38
use ieee.std_logic_misc.all;
39
 
40
library work;
41
  use work.open8_pkg.all;
42
 
43
entity o8_ltc2355_2p is
44
generic(
45
  Address                    : ADDRESS_TYPE;
46
  Reset_Level                : std_logic;
47
  Sys_Freq                   : real
48
);
49
port(
50
  Clock                      : in  std_logic; -- 96MHz MAX for proper operation
51
  Reset                      : in  std_logic;
52
  uSec_Tick                  : in  std_logic;
53
  -- Client IF
54
  Bus_Address                : in  ADDRESS_TYPE;
55
  Wr_Enable                  : in  std_logic;
56
  Wr_Data                    : in  DATA_TYPE;
57
  Rd_Enable                  : in  std_logic;
58
  Rd_Data                    : out DATA_TYPE;
59
  Interrupt                  : out std_logic;
60
  -- ADC IF
61
  ADC_SCLK                   : out std_logic;
62
  ADC_CONV                   : out std_logic;
63
  ADC_DATA1                  : in  std_logic;
64
  ADC_DATA2                  : in  std_logic
65
);
66
end entity;
67
 
68
architecture behave of o8_ltc2355_2p is
69
 
70
  constant Divide_SCLK_by_2  : boolean := (Sys_Freq > 96000000.0);
71
 
72
  constant User_Addr         : std_logic_vector(15 downto 3) := Address(15 downto 3);
73
  alias  Comp_Addr           is Bus_Address(15 downto 3);
74
  alias  Reg_Sel             is Bus_Address(2 downto 0);
75
  signal Reg_Sel_q           : std_logic_vector(2 downto 0);
76
  signal Wr_Data_q           : DATA_TYPE;
77
  signal Addr_Match          : std_logic;
78
  signal Wr_En               : std_logic;
79
  signal Rd_En               : std_logic;
80
  signal User_In             : DATA_TYPE;
81
 
82
  signal User_Trig           : std_logic;
83
 
84
  signal Timer_Int           : DATA_TYPE;
85
  signal Timer_Cnt           : DATA_TYPE;
86
  signal Timer_Trig          : std_logic;
87
 
88
  type ADC_STATES is ( IDLE, START, CLK_HIGH, CLK_HIGH2, CLK_LOW, CLK_LOW2, UPDATE );
89
  signal ad_state            : ADC_STATES;
90
 
91
  signal rx_buffer1          : std_logic_vector(16 downto 0);
92
  signal rx_buffer2          : std_logic_vector(16 downto 0);
93
  signal bit_cntr            : std_logic_vector(4 downto 0);
94
  constant BIT_COUNT         : std_logic_vector(4 downto 0) :=
95
                                conv_std_logic_vector(16,5);
96
 
97
  signal ADC1_Data           : std_logic_vector(13 downto 0);
98
  signal ADC2_Data           : std_logic_vector(13 downto 0);
99
  signal ADC_Ready           : std_logic;
100
begin
101
 
102
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
103
 
104
  io_reg: process( Clock, Reset )
105
  begin
106
    if( Reset = Reset_Level )then
107
      Reg_Sel_q              <= (others => '0');
108
      Wr_Data_q              <= x"00";
109
      Wr_En                  <= '0';
110
      Rd_En                  <= '0';
111
      Rd_Data                <= OPEN8_NULLBUS;
112
      User_Trig              <= '0';
113
      Timer_Int              <= x"00";
114
    elsif( rising_edge( Clock ) )then
115
      Reg_Sel_q              <= Reg_Sel;
116
      Wr_Data_q              <= Wr_Data;
117
      Wr_En                  <= Wr_Enable and Addr_Match;
118
      User_Trig              <= '0';
119
      if( Wr_En = '1' )then
120
        if( Reg_Sel_q = "110" )then
121
          Timer_Int          <= Wr_Data_q;
122
        end if;
123
        if( Reg_Sel_q = "111" )then
124
          User_Trig          <= '1';
125
        end if;
126
      end if;
127
 
128
      Rd_En                  <= Rd_Enable and Addr_Match;
129
      Rd_Data                <= OPEN8_NULLBUS;
130
 
131
      if( Rd_En = '1' )then
132
        case( Reg_Sel_q )is
133
          -- Channel 1, Full resolution, lower byte
134
          when "000" =>
135
            Rd_Data          <= ADC1_Data(7 downto 0);
136
          -- Channel 1, Full resolution, upper byte
137
          when "001" =>
138
            Rd_Data          <= "00" & ADC1_Data(13 downto 8);
139
          -- Channel 2, Full resolution, lower byte
140
          when "010" =>
141
            Rd_Data          <= ADC2_Data(7 downto 0);
142
          -- Channel 2, Full resolution, upper byte
143
          when "011" =>
144
            Rd_Data          <= "00" & ADC2_Data(13 downto 8);
145
          -- Channel 1, 8-bit resolution
146
          when "100" =>
147
            Rd_Data          <= ADC1_Data(13 downto 6);
148
          -- Channel 2, 8-bit resolution
149
          when "101" =>
150
            Rd_Data          <= ADC2_Data(13 downto 6);
151
          -- Self-update rate
152
          when "110" =>
153
            Rd_Data          <= Timer_Int;
154
          -- Interface status
155
          when "111" =>
156
            Rd_Data(7)       <= ADC_Ready;
157
          when others =>
158
            null;
159
        end case;
160
      end if;
161
    end if;
162
  end process;
163
 
164
  Interval_proc: process( Clock, Reset )
165
  begin
166
    if( Reset = Reset_Level )then
167
      Timer_Cnt              <= x"00";
168
      Timer_Trig             <= '0';
169
    elsif( rising_edge(Clock) )then
170
      Timer_Trig             <= '0';
171
      Timer_Cnt              <= Timer_Cnt - uSec_Tick;
172
      if( or_reduce(Timer_Cnt) = '0' )then
173
        Timer_Cnt            <= Timer_Int;
174
        Timer_Trig           <= or_reduce(Timer_Int); -- Only issue output on Int > 0
175
      end if;
176
    end if;
177
  end process;
178
 
179
  ADC_IO_FSM: process( Clock, Reset )
180
  begin
181
    if( Reset = Reset_Level )then
182
      ad_state               <= IDLE;
183
      ADC_Ready              <= '0';
184
 
185
      rx_buffer1             <= (others => '0');
186
      rx_buffer2             <= (others => '0');
187
 
188
      bit_cntr               <= (others => '0');
189
 
190
      ADC1_Data              <= (others => '0');
191
      ADC2_Data              <= (others => '0');
192
 
193
      ADC_SCLK               <= '1';
194
      ADC_CONV               <= '0';
195
 
196
      Interrupt              <= '0';
197
    elsif( rising_edge(Clock) )then
198
      ADC_Ready              <= '0';
199
      ADC_SCLK               <= '1';
200
      ADC_CONV               <= '0';
201
 
202
      Interrupt              <= '0';
203
 
204
      case( ad_state )is
205
        when IDLE =>
206
          ADC_Ready          <= '1';
207
          if( (User_Trig or Timer_Trig) = '1' )then
208
            ad_state         <= START;
209
          end if;
210
 
211
        when START =>
212
          ADC_SCLK           <= '0';
213
          ADC_CONV           <= '1';
214
          bit_cntr           <= BIT_COUNT;
215
          ad_state           <= CLK_HIGH;
216
 
217
        when CLK_HIGH =>
218
          ad_state           <= CLK_LOW;
219
          if( Divide_SCLK_by_2 )then
220
            ad_state         <= CLK_HIGH2;
221
          end if;
222
 
223
        when CLK_HIGH2 =>
224
          ad_state           <= CLK_LOW;
225
 
226
        when CLK_LOW =>
227
          ADC_SCLK           <= '0';
228
          rx_buffer1(conv_integer(bit_cntr)) <= ADC_DATA1;
229
          rx_buffer2(conv_integer(bit_cntr)) <= ADC_DATA2;
230
          bit_cntr           <= bit_cntr - 1;
231
          ad_state           <= CLK_HIGH;
232
          if( bit_cntr = 0 )then
233
            ad_state         <= UPDATE;
234
          elsif( Divide_SCLK_by_2 )then
235
            ad_state         <= CLK_LOW2;
236
          end if;
237
 
238
        when CLK_LOW2 =>
239
          ADC_SCLK           <= '0';
240
          ad_state           <= CLK_HIGH;
241
 
242
        when UPDATE =>
243
          ADC_SCLK           <= '0';
244
          ad_state           <= IDLE;
245
          ADC1_Data          <= rx_buffer1(14 downto 1);
246
          ADC2_Data          <= rx_buffer2(14 downto 1);
247
          Interrupt          <= '1';
248
 
249
        when others =>
250
          null;
251
      end case;
252
 
253
    end if;
254
  end process;
255
 
256
end architecture;

powered by: WebSVN 2.1.0

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