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 326

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 220 jshamlet
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 194 jshamlet
--
24 322 jshamlet
-- VHDL units : o8_ltc2355_2p
25 191 jshamlet
-- 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 224 jshamlet
--
34
--            : Works best when the clock frequency is 96MHz or lower. Module
35
--            :  will divide the clock by 2 if it is greater than this.
36
--
37 322 jshamlet
-- Register Map:
38
-- Offset  Bitfield Description                        Read/Write
39
--   0x0   AAAAAAAA ADC Channel 1 Data(7:0)              (RO)
40
--   0x1   --AAAAAA ADC Channel 1 Data(13:8)             (RO)
41
--   0x2   AAAAAAAA ADC Channel 2 Data(7:0)              (RO)
42
--   0x3   --AAAAAA ADC Channel 2 Data(13:8) (reduced)   (RO)
43
--   0x4   AAAAAAAA ADC Channel 1 Data(13:6) (reduced)   (RO)
44
--   0x5   AAAAAAAA ADC Channel 2 Data(13:6)             (RO)
45
--   0x6   AAAAAAAA Update / Sample Rate (in uS)         (RW)
46
--   0x7   A------- Force Trigger / Status               (RW)
47
--
48 224 jshamlet
-- Revision History
49
-- Author          Date     Change
50
------------------ -------- ---------------------------------------------------
51 322 jshamlet
-- Seth Henry      12/14/20 Forked
52 191 jshamlet
 
53
library ieee;
54
use ieee.std_logic_1164.all;
55
use ieee.std_logic_unsigned.all;
56
use ieee.std_logic_arith.all;
57
use ieee.std_logic_misc.all;
58
 
59
library work;
60
  use work.open8_pkg.all;
61
 
62
entity o8_ltc2355_2p is
63
generic(
64 224 jshamlet
  Clock_Frequency            : real;
65
  Address                    : ADDRESS_TYPE
66 191 jshamlet
);
67
port(
68 223 jshamlet
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
69 191 jshamlet
  Rd_Data                    : out DATA_TYPE;
70
  Interrupt                  : out std_logic;
71
  -- ADC IF
72
  ADC_SCLK                   : out std_logic;
73
  ADC_CONV                   : out std_logic;
74
  ADC_DATA1                  : in  std_logic;
75
  ADC_DATA2                  : in  std_logic
76
);
77
end entity;
78
 
79
architecture behave of o8_ltc2355_2p is
80
 
81 224 jshamlet
  alias Clock                is Open8_Bus.Clock;
82
  alias Reset                is Open8_Bus.Reset;
83
  alias uSec_Tick            is Open8_Bus.uSec_Tick;
84 191 jshamlet
 
85 224 jshamlet
  constant Divide_SCLK_by_2  : boolean := (Clock_Frequency > 96000000.0);
86
 
87 191 jshamlet
  constant User_Addr         : std_logic_vector(15 downto 3) := Address(15 downto 3);
88 223 jshamlet
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 3);
89 322 jshamlet
  signal Addr_Match          : std_logic := '0';
90 244 jshamlet
  alias  Reg_Sel_d           is Open8_Bus.Address(2 downto 0);
91 322 jshamlet
  signal Reg_Sel_q           : std_logic_vector(2 downto 0) := (others => '0');
92 244 jshamlet
  signal Wr_En_d             : std_logic := '0';
93
  signal Wr_En_q             : std_logic := '0';
94
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
95
  signal Wr_Data_q           : DATA_TYPE := x"00";
96
  signal Rd_En_d             : std_logic := '0';
97
  signal Rd_En_q             : std_logic := '0';
98 191 jshamlet
 
99 322 jshamlet
  signal User_Trig           : std_logic := '0';
100 191 jshamlet
 
101 322 jshamlet
  signal Timer_Int           : DATA_TYPE := (others => '0');
102
  signal Timer_Cnt           : DATA_TYPE := (others => '0');
103
  signal Timer_Trig          : std_logic := '0';
104 191 jshamlet
 
105
  type ADC_STATES is ( IDLE, START, CLK_HIGH, CLK_HIGH2, CLK_LOW, CLK_LOW2, UPDATE );
106
  signal ad_state            : ADC_STATES;
107
 
108 322 jshamlet
  signal rx_buffer1          : std_logic_vector(16 downto 0) := (others => '0');
109
  signal rx_buffer2          : std_logic_vector(16 downto 0) := (others => '0');
110
  signal bit_cntr            : std_logic_vector(4 downto 0) := (others => '0');
111 191 jshamlet
  constant BIT_COUNT         : std_logic_vector(4 downto 0) :=
112
                                conv_std_logic_vector(16,5);
113
 
114 322 jshamlet
  signal ADC1_Data           : std_logic_vector(13 downto 0) := (others => '0');
115
  signal ADC2_Data           : std_logic_vector(13 downto 0) := (others => '0');
116
  signal ADC_Ready           : std_logic := '0';
117
 
118 191 jshamlet
begin
119
 
120
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
121 258 jshamlet
  Wr_En_d                    <= Addr_Match and Open8_Bus.Wr_En;
122 244 jshamlet
  Rd_En_d                    <= Addr_Match and Open8_Bus.Rd_En;
123 191 jshamlet
 
124
  io_reg: process( Clock, Reset )
125
  begin
126
    if( Reset = Reset_Level )then
127 244 jshamlet
      Reg_Sel_q              <= "000";
128
      Wr_En_q                <= '0';
129 191 jshamlet
      Wr_Data_q              <= x"00";
130 244 jshamlet
      Rd_En_q                <= '0';
131 191 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
132 244 jshamlet
 
133 191 jshamlet
      User_Trig              <= '0';
134
      Timer_Int              <= x"00";
135
    elsif( rising_edge( Clock ) )then
136 244 jshamlet
      Reg_Sel_q              <= Reg_Sel_d;
137
 
138
      Wr_En_q                <= Wr_En_d;
139
      Wr_Data_q              <= Wr_Data_d;
140
 
141 191 jshamlet
      User_Trig              <= '0';
142 244 jshamlet
      if( Wr_En_q = '1' )then
143 191 jshamlet
        if( Reg_Sel_q = "110" )then
144
          Timer_Int          <= Wr_Data_q;
145
        end if;
146
        if( Reg_Sel_q = "111" )then
147
          User_Trig          <= '1';
148
        end if;
149
      end if;
150
 
151 244 jshamlet
      Rd_En_q                <= Rd_En_d;
152 191 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
153 244 jshamlet
      if( Rd_En_q = '1' )then
154 191 jshamlet
        case( Reg_Sel_q )is
155
          -- Channel 1, Full resolution, lower byte
156
          when "000" =>
157
            Rd_Data          <= ADC1_Data(7 downto 0);
158
          -- Channel 1, Full resolution, upper byte
159
          when "001" =>
160
            Rd_Data          <= "00" & ADC1_Data(13 downto 8);
161
          -- Channel 2, Full resolution, lower byte
162
          when "010" =>
163
            Rd_Data          <= ADC2_Data(7 downto 0);
164
          -- Channel 2, Full resolution, upper byte
165
          when "011" =>
166
            Rd_Data          <= "00" & ADC2_Data(13 downto 8);
167
          -- Channel 1, 8-bit resolution
168
          when "100" =>
169
            Rd_Data          <= ADC1_Data(13 downto 6);
170
          -- Channel 2, 8-bit resolution
171
          when "101" =>
172
            Rd_Data          <= ADC2_Data(13 downto 6);
173
          -- Self-update rate
174
          when "110" =>
175
            Rd_Data          <= Timer_Int;
176
          -- Interface status
177
          when "111" =>
178
            Rd_Data(7)       <= ADC_Ready;
179
          when others =>
180
            null;
181
        end case;
182
      end if;
183
    end if;
184
  end process;
185
 
186
  Interval_proc: process( Clock, Reset )
187
  begin
188
    if( Reset = Reset_Level )then
189
      Timer_Cnt              <= x"00";
190
      Timer_Trig             <= '0';
191
    elsif( rising_edge(Clock) )then
192
      Timer_Trig             <= '0';
193
      Timer_Cnt              <= Timer_Cnt - uSec_Tick;
194
      if( or_reduce(Timer_Cnt) = '0' )then
195
        Timer_Cnt            <= Timer_Int;
196
        Timer_Trig           <= or_reduce(Timer_Int); -- Only issue output on Int > 0
197
      end if;
198
    end if;
199
  end process;
200
 
201
  ADC_IO_FSM: process( Clock, Reset )
202
  begin
203
    if( Reset = Reset_Level )then
204
      ad_state               <= IDLE;
205
      ADC_Ready              <= '0';
206
 
207
      rx_buffer1             <= (others => '0');
208
      rx_buffer2             <= (others => '0');
209
 
210
      bit_cntr               <= (others => '0');
211
 
212
      ADC1_Data              <= (others => '0');
213
      ADC2_Data              <= (others => '0');
214
 
215
      ADC_SCLK               <= '1';
216
      ADC_CONV               <= '0';
217
 
218
      Interrupt              <= '0';
219
    elsif( rising_edge(Clock) )then
220
      ADC_Ready              <= '0';
221
      ADC_SCLK               <= '1';
222
      ADC_CONV               <= '0';
223
 
224
      Interrupt              <= '0';
225
 
226
      case( ad_state )is
227
        when IDLE =>
228
          ADC_Ready          <= '1';
229
          if( (User_Trig or Timer_Trig) = '1' )then
230
            ad_state         <= START;
231
          end if;
232
 
233
        when START =>
234
          ADC_SCLK           <= '0';
235
          ADC_CONV           <= '1';
236
          bit_cntr           <= BIT_COUNT;
237
          ad_state           <= CLK_HIGH;
238
 
239
        when CLK_HIGH =>
240
          ad_state           <= CLK_LOW;
241
          if( Divide_SCLK_by_2 )then
242
            ad_state         <= CLK_HIGH2;
243
          end if;
244
 
245
        when CLK_HIGH2 =>
246
          ad_state           <= CLK_LOW;
247
 
248
        when CLK_LOW =>
249
          ADC_SCLK           <= '0';
250
          rx_buffer1(conv_integer(bit_cntr)) <= ADC_DATA1;
251
          rx_buffer2(conv_integer(bit_cntr)) <= ADC_DATA2;
252
          bit_cntr           <= bit_cntr - 1;
253
          ad_state           <= CLK_HIGH;
254
          if( bit_cntr = 0 )then
255
            ad_state         <= UPDATE;
256
          elsif( Divide_SCLK_by_2 )then
257
            ad_state         <= CLK_LOW2;
258
          end if;
259
 
260
        when CLK_LOW2 =>
261
          ADC_SCLK           <= '0';
262
          ad_state           <= CLK_HIGH;
263
 
264
        when UPDATE =>
265
          ADC_SCLK           <= '0';
266
          ad_state           <= IDLE;
267
          ADC1_Data          <= rx_buffer1(14 downto 1);
268
          ADC2_Data          <= rx_buffer2(14 downto 1);
269
          Interrupt          <= '1';
270
 
271
        when others =>
272
          null;
273
      end case;
274
 
275
    end if;
276
  end process;
277
 
278 322 jshamlet
end architecture;

powered by: WebSVN 2.1.0

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