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 249

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 244 jshamlet
  Rd_En_d                    <= Addr_Match and Open8_Bus.Rd_En;
110 191 jshamlet
 
111
  io_reg: process( Clock, Reset )
112
  begin
113
    if( Reset = Reset_Level )then
114 244 jshamlet
      Reg_Sel_q              <= "000";
115
      Wr_En_q                <= '0';
116 191 jshamlet
      Wr_Data_q              <= x"00";
117 244 jshamlet
      Rd_En_q                <= '0';
118 191 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
119 244 jshamlet
 
120 191 jshamlet
      User_Trig              <= '0';
121
      Timer_Int              <= x"00";
122
    elsif( rising_edge( Clock ) )then
123 244 jshamlet
      Reg_Sel_q              <= Reg_Sel_d;
124
 
125
      Wr_En_q                <= Wr_En_d;
126
      Wr_Data_q              <= Wr_Data_d;
127
 
128 191 jshamlet
      User_Trig              <= '0';
129 244 jshamlet
      if( Wr_En_q = '1' )then
130 191 jshamlet
        if( Reg_Sel_q = "110" )then
131
          Timer_Int          <= Wr_Data_q;
132
        end if;
133
        if( Reg_Sel_q = "111" )then
134
          User_Trig          <= '1';
135
        end if;
136
      end if;
137
 
138 244 jshamlet
      Rd_En_q                <= Rd_En_d;
139 191 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
140 244 jshamlet
      if( Rd_En_q = '1' )then
141 191 jshamlet
        case( Reg_Sel_q )is
142
          -- Channel 1, Full resolution, lower byte
143
          when "000" =>
144
            Rd_Data          <= ADC1_Data(7 downto 0);
145
          -- Channel 1, Full resolution, upper byte
146
          when "001" =>
147
            Rd_Data          <= "00" & ADC1_Data(13 downto 8);
148
          -- Channel 2, Full resolution, lower byte
149
          when "010" =>
150
            Rd_Data          <= ADC2_Data(7 downto 0);
151
          -- Channel 2, Full resolution, upper byte
152
          when "011" =>
153
            Rd_Data          <= "00" & ADC2_Data(13 downto 8);
154
          -- Channel 1, 8-bit resolution
155
          when "100" =>
156
            Rd_Data          <= ADC1_Data(13 downto 6);
157
          -- Channel 2, 8-bit resolution
158
          when "101" =>
159
            Rd_Data          <= ADC2_Data(13 downto 6);
160
          -- Self-update rate
161
          when "110" =>
162
            Rd_Data          <= Timer_Int;
163
          -- Interface status
164
          when "111" =>
165
            Rd_Data(7)       <= ADC_Ready;
166
          when others =>
167
            null;
168
        end case;
169
      end if;
170
    end if;
171
  end process;
172
 
173
  Interval_proc: process( Clock, Reset )
174
  begin
175
    if( Reset = Reset_Level )then
176
      Timer_Cnt              <= x"00";
177
      Timer_Trig             <= '0';
178
    elsif( rising_edge(Clock) )then
179
      Timer_Trig             <= '0';
180
      Timer_Cnt              <= Timer_Cnt - uSec_Tick;
181
      if( or_reduce(Timer_Cnt) = '0' )then
182
        Timer_Cnt            <= Timer_Int;
183
        Timer_Trig           <= or_reduce(Timer_Int); -- Only issue output on Int > 0
184
      end if;
185
    end if;
186
  end process;
187
 
188
  ADC_IO_FSM: process( Clock, Reset )
189
  begin
190
    if( Reset = Reset_Level )then
191
      ad_state               <= IDLE;
192
      ADC_Ready              <= '0';
193
 
194
      rx_buffer1             <= (others => '0');
195
      rx_buffer2             <= (others => '0');
196
 
197
      bit_cntr               <= (others => '0');
198
 
199
      ADC1_Data              <= (others => '0');
200
      ADC2_Data              <= (others => '0');
201
 
202
      ADC_SCLK               <= '1';
203
      ADC_CONV               <= '0';
204
 
205
      Interrupt              <= '0';
206
    elsif( rising_edge(Clock) )then
207
      ADC_Ready              <= '0';
208
      ADC_SCLK               <= '1';
209
      ADC_CONV               <= '0';
210
 
211
      Interrupt              <= '0';
212
 
213
      case( ad_state )is
214
        when IDLE =>
215
          ADC_Ready          <= '1';
216
          if( (User_Trig or Timer_Trig) = '1' )then
217
            ad_state         <= START;
218
          end if;
219
 
220
        when START =>
221
          ADC_SCLK           <= '0';
222
          ADC_CONV           <= '1';
223
          bit_cntr           <= BIT_COUNT;
224
          ad_state           <= CLK_HIGH;
225
 
226
        when CLK_HIGH =>
227
          ad_state           <= CLK_LOW;
228
          if( Divide_SCLK_by_2 )then
229
            ad_state         <= CLK_HIGH2;
230
          end if;
231
 
232
        when CLK_HIGH2 =>
233
          ad_state           <= CLK_LOW;
234
 
235
        when CLK_LOW =>
236
          ADC_SCLK           <= '0';
237
          rx_buffer1(conv_integer(bit_cntr)) <= ADC_DATA1;
238
          rx_buffer2(conv_integer(bit_cntr)) <= ADC_DATA2;
239
          bit_cntr           <= bit_cntr - 1;
240
          ad_state           <= CLK_HIGH;
241
          if( bit_cntr = 0 )then
242
            ad_state         <= UPDATE;
243
          elsif( Divide_SCLK_by_2 )then
244
            ad_state         <= CLK_LOW2;
245
          end if;
246
 
247
        when CLK_LOW2 =>
248
          ADC_SCLK           <= '0';
249
          ad_state           <= CLK_HIGH;
250
 
251
        when UPDATE =>
252
          ADC_SCLK           <= '0';
253
          ad_state           <= IDLE;
254
          ADC1_Data          <= rx_buffer1(14 downto 1);
255
          ADC2_Data          <= rx_buffer2(14 downto 1);
256
          Interrupt          <= '1';
257
 
258
        when others =>
259
          null;
260
      end case;
261
 
262
    end if;
263
  end process;
264
 
265
end architecture;

powered by: WebSVN 2.1.0

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