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 287

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 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 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
-- Revision History
38
-- Author          Date     Change
39
------------------ -------- ---------------------------------------------------
40
-- Seth Henry      04/16/20 Revision block added
41 191 jshamlet
 
42
library ieee;
43
use ieee.std_logic_1164.all;
44
use ieee.std_logic_unsigned.all;
45
use ieee.std_logic_arith.all;
46
use ieee.std_logic_misc.all;
47
 
48
library work;
49
  use work.open8_pkg.all;
50
 
51
entity o8_ltc2355_2p is
52
generic(
53 224 jshamlet
  Clock_Frequency            : real;
54
  Address                    : ADDRESS_TYPE
55 191 jshamlet
);
56
port(
57 223 jshamlet
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
58 191 jshamlet
  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 224 jshamlet
  alias Clock                is Open8_Bus.Clock;
71
  alias Reset                is Open8_Bus.Reset;
72
  alias uSec_Tick            is Open8_Bus.uSec_Tick;
73 191 jshamlet
 
74 224 jshamlet
  constant Divide_SCLK_by_2  : boolean := (Clock_Frequency > 96000000.0);
75
 
76 191 jshamlet
  constant User_Addr         : std_logic_vector(15 downto 3) := Address(15 downto 3);
77 223 jshamlet
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 3);
78 244 jshamlet
  signal Addr_Match          : std_logic;
79
  alias  Reg_Sel_d           is Open8_Bus.Address(2 downto 0);
80 191 jshamlet
  signal Reg_Sel_q           : std_logic_vector(2 downto 0);
81 244 jshamlet
  signal Wr_En_d             : std_logic := '0';
82
  signal Wr_En_q             : std_logic := '0';
83
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
84
  signal Wr_Data_q           : DATA_TYPE := x"00";
85
  signal Rd_En_d             : std_logic := '0';
86
  signal Rd_En_q             : std_logic := '0';
87 191 jshamlet
 
88
  signal User_Trig           : std_logic;
89
 
90
  signal Timer_Int           : DATA_TYPE;
91
  signal Timer_Cnt           : DATA_TYPE;
92
  signal Timer_Trig          : std_logic;
93
 
94
  type ADC_STATES is ( IDLE, START, CLK_HIGH, CLK_HIGH2, CLK_LOW, CLK_LOW2, UPDATE );
95
  signal ad_state            : ADC_STATES;
96
 
97
  signal rx_buffer1          : std_logic_vector(16 downto 0);
98
  signal rx_buffer2          : std_logic_vector(16 downto 0);
99
  signal bit_cntr            : std_logic_vector(4 downto 0);
100
  constant BIT_COUNT         : std_logic_vector(4 downto 0) :=
101
                                conv_std_logic_vector(16,5);
102
 
103
  signal ADC1_Data           : std_logic_vector(13 downto 0);
104
  signal ADC2_Data           : std_logic_vector(13 downto 0);
105
  signal ADC_Ready           : std_logic;
106
begin
107
 
108
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
109 258 jshamlet
  Wr_En_d                    <= Addr_Match and Open8_Bus.Wr_En;
110 244 jshamlet
  Rd_En_d                    <= Addr_Match and Open8_Bus.Rd_En;
111 191 jshamlet
 
112
  io_reg: process( Clock, Reset )
113
  begin
114
    if( Reset = Reset_Level )then
115 244 jshamlet
      Reg_Sel_q              <= "000";
116
      Wr_En_q                <= '0';
117 191 jshamlet
      Wr_Data_q              <= x"00";
118 244 jshamlet
      Rd_En_q                <= '0';
119 191 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
120 244 jshamlet
 
121 191 jshamlet
      User_Trig              <= '0';
122
      Timer_Int              <= x"00";
123
    elsif( rising_edge( Clock ) )then
124 244 jshamlet
      Reg_Sel_q              <= Reg_Sel_d;
125
 
126
      Wr_En_q                <= Wr_En_d;
127
      Wr_Data_q              <= Wr_Data_d;
128
 
129 191 jshamlet
      User_Trig              <= '0';
130 244 jshamlet
      if( Wr_En_q = '1' )then
131 191 jshamlet
        if( Reg_Sel_q = "110" )then
132
          Timer_Int          <= Wr_Data_q;
133
        end if;
134
        if( Reg_Sel_q = "111" )then
135
          User_Trig          <= '1';
136
        end if;
137
      end if;
138
 
139 244 jshamlet
      Rd_En_q                <= Rd_En_d;
140 191 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
141 244 jshamlet
      if( Rd_En_q = '1' )then
142 191 jshamlet
        case( Reg_Sel_q )is
143
          -- Channel 1, Full resolution, lower byte
144
          when "000" =>
145
            Rd_Data          <= ADC1_Data(7 downto 0);
146
          -- Channel 1, Full resolution, upper byte
147
          when "001" =>
148
            Rd_Data          <= "00" & ADC1_Data(13 downto 8);
149
          -- Channel 2, Full resolution, lower byte
150
          when "010" =>
151
            Rd_Data          <= ADC2_Data(7 downto 0);
152
          -- Channel 2, Full resolution, upper byte
153
          when "011" =>
154
            Rd_Data          <= "00" & ADC2_Data(13 downto 8);
155
          -- Channel 1, 8-bit resolution
156
          when "100" =>
157
            Rd_Data          <= ADC1_Data(13 downto 6);
158
          -- Channel 2, 8-bit resolution
159
          when "101" =>
160
            Rd_Data          <= ADC2_Data(13 downto 6);
161
          -- Self-update rate
162
          when "110" =>
163
            Rd_Data          <= Timer_Int;
164
          -- Interface status
165
          when "111" =>
166
            Rd_Data(7)       <= ADC_Ready;
167
          when others =>
168
            null;
169
        end case;
170
      end if;
171
    end if;
172
  end process;
173
 
174
  Interval_proc: process( Clock, Reset )
175
  begin
176
    if( Reset = Reset_Level )then
177
      Timer_Cnt              <= x"00";
178
      Timer_Trig             <= '0';
179
    elsif( rising_edge(Clock) )then
180
      Timer_Trig             <= '0';
181
      Timer_Cnt              <= Timer_Cnt - uSec_Tick;
182
      if( or_reduce(Timer_Cnt) = '0' )then
183
        Timer_Cnt            <= Timer_Int;
184
        Timer_Trig           <= or_reduce(Timer_Int); -- Only issue output on Int > 0
185
      end if;
186
    end if;
187
  end process;
188
 
189
  ADC_IO_FSM: process( Clock, Reset )
190
  begin
191
    if( Reset = Reset_Level )then
192
      ad_state               <= IDLE;
193
      ADC_Ready              <= '0';
194
 
195
      rx_buffer1             <= (others => '0');
196
      rx_buffer2             <= (others => '0');
197
 
198
      bit_cntr               <= (others => '0');
199
 
200
      ADC1_Data              <= (others => '0');
201
      ADC2_Data              <= (others => '0');
202
 
203
      ADC_SCLK               <= '1';
204
      ADC_CONV               <= '0';
205
 
206
      Interrupt              <= '0';
207
    elsif( rising_edge(Clock) )then
208
      ADC_Ready              <= '0';
209
      ADC_SCLK               <= '1';
210
      ADC_CONV               <= '0';
211
 
212
      Interrupt              <= '0';
213
 
214
      case( ad_state )is
215
        when IDLE =>
216
          ADC_Ready          <= '1';
217
          if( (User_Trig or Timer_Trig) = '1' )then
218
            ad_state         <= START;
219
          end if;
220
 
221
        when START =>
222
          ADC_SCLK           <= '0';
223
          ADC_CONV           <= '1';
224
          bit_cntr           <= BIT_COUNT;
225
          ad_state           <= CLK_HIGH;
226
 
227
        when CLK_HIGH =>
228
          ad_state           <= CLK_LOW;
229
          if( Divide_SCLK_by_2 )then
230
            ad_state         <= CLK_HIGH2;
231
          end if;
232
 
233
        when CLK_HIGH2 =>
234
          ad_state           <= CLK_LOW;
235
 
236
        when CLK_LOW =>
237
          ADC_SCLK           <= '0';
238
          rx_buffer1(conv_integer(bit_cntr)) <= ADC_DATA1;
239
          rx_buffer2(conv_integer(bit_cntr)) <= ADC_DATA2;
240
          bit_cntr           <= bit_cntr - 1;
241
          ad_state           <= CLK_HIGH;
242
          if( bit_cntr = 0 )then
243
            ad_state         <= UPDATE;
244
          elsif( Divide_SCLK_by_2 )then
245
            ad_state         <= CLK_LOW2;
246
          end if;
247
 
248
        when CLK_LOW2 =>
249
          ADC_SCLK           <= '0';
250
          ad_state           <= CLK_HIGH;
251
 
252
        when UPDATE =>
253
          ADC_SCLK           <= '0';
254
          ad_state           <= IDLE;
255
          ADC1_Data          <= rx_buffer1(14 downto 1);
256
          ADC2_Data          <= rx_buffer2(14 downto 1);
257
          Interrupt          <= '1';
258
 
259
        when others =>
260
          null;
261
      end case;
262
 
263
    end if;
264
  end process;
265
 
266
end architecture;

powered by: WebSVN 2.1.0

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