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 236

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

powered by: WebSVN 2.1.0

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