Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LTC2496.h
Go to the documentation of this file.
1 /*!
2 LTC2496: 16-Bit 8-/16-Channel Delta Sigma ADC with Easy Drive Input Current Cancellation
3 
4 @verbatim
5 
6 The LTC2496 is a 16-channel (8-differential) 16-bit No Latency ΔΣ ADC with Easy
7 Drive technology. The patented sampling scheme eliminates dynamic input current
8 errors and the shortcomings of on-chip buffering through automatic cancellation
9 of differential input current. This allows large external source impedances,
10 and rail-to-rail input signals to be directly digitized while maintaining
11 exceptional DC accuracy.
12 
13 The LTC2496 includes an integrated oscillator. This device can be configured to
14 measure an external signal (from combinations of 16 analog input channels
15 operating in single ended or differential modes). It automatically rejects
16 line frequencies of 50Hz and 60Hz, simultaneously.
17 
18 SPI DATA FORMAT (MSB First):
19 
20  Byte #1 Byte #2 Byte #3
21 
22 Data Out : !EOC DMY SIG MSB D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 - - - -
23 Data In : 1 0 EN SGL OS S2 S1 S0 X X X X X X X X X X X X X X X X
24 
25 !EOC : End of Conversion Bit (Active Low)
26 DMY : Dummy Bit (Always 0)
27 SIG : Sign Bit (1-data positive, 0-data negative)
28 MSB : Most Significant Bit (Provides under range and over range indication)
29 Dx : Data Bits
30 EN : Enable Bit (0-keep previous mode, 1-change mode)
31 SGL : Enable Single-Ended Bit (0-differential, 1-single-ended)
32 OS : ODD/Sign Bit
33 Sx : Address Select Bit
34 
35 Command Byte
36 1 0 EN SGL OS S2 S1 S0 Comments
37 1 0 0 X X X X X Keep Previous Mode
38 1 0 1 0 X X X X Differential Mode
39 1 0 1 1 X X X X Single-Ended Mode
40 
41 
42 Example Code:
43 
44 Read Channel 0 in Single-Ended mode
45 
46  uint16_t miso_timeout = 1000;
47  adc_command = LTC2496_CH0; // Build ADC command for channel 0
48 
49  if(LTC2496_EOC_timeout(LTC2496_CS, miso_timeout)) // Check for EOC
50  return(1);
51  LTC2496_read(LTC2496_CS, adc_command, &adc_code); // Throws out last reading
52 
53  if(LTC2496_EOC_timeout(LTC2496_CS, miso_timeout)) // Check for EOC
54  return(1);
55  LTC2496_read(LTC2496_CS, adc_command, &adc_code); // Obtains the current reading and stores to adc_code variable
56 
57  // Convert adc_code to voltage
58  adc_voltage = LTC2496_code_to_voltage(adc_code, LTC2496_lsb , LTC2496_offset_code);
59 
60 @endverbatim
61 
62 http://www.linear.com/product/LTC2496
63 
64 http://www.linear.com/product/LTC2496#demoboards
65 
66 
67 
68 Copyright 2018(c) Analog Devices, Inc.
69 
70 All rights reserved.
71 
72 Redistribution and use in source and binary forms, with or without
73 modification, are permitted provided that the following conditions are met:
74  - Redistributions of source code must retain the above copyright
75  notice, this list of conditions and the following disclaimer.
76  - Redistributions in binary form must reproduce the above copyright
77  notice, this list of conditions and the following disclaimer in
78  the documentation and/or other materials provided with the
79  distribution.
80  - Neither the name of Analog Devices, Inc. nor the names of its
81  contributors may be used to endorse or promote products derived
82  from this software without specific prior written permission.
83  - The use of this software may or may not infringe the patent rights
84  of one or more patent holders. This license does not release you
85  from the requirement that you obtain separate licenses from these
86  patent holders to use this software.
87  - Use of the software either in source or binary form, must be run
88  on or directly connected to an Analog Devices Inc. component.
89 
90 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
91 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
92 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
93 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
94 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
95 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
96 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
97 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
98 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
99 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
100 */
101 
102 /*! @file
103  @ingroup LTC2496
104  Header for LTC2496 LTC2496: 16-Bit 8-/16-Channel Delta Sigma ADC with Easy Drive Input Current Cancellation
105 */
106 
107 #ifndef LTC2496_H
108 #define LTC2496_H
109 
110 //! define the SPI CS pin
111 #ifndef LTC2496_CS
112 #define LTC2496_CS QUIKEVAL_CS
113 #endif
114 
115 //! @name LTC2496 Command Constraints
116 //!@{
117 //! Command Constants.
118 #define LTC2496_DISABLE 0x80
119 #define LTC2496_ENABLE 0xA0
120 
121 
122 //!Channel Selection OR with ENABLE or select DISABLE to use previous selection
123 /*!
124 //!Use table to select address
125 /*!
126 |LTC2496 Channel Selection | Value |
127 | :--------------------------: | :------: |
128 | LTC2496_P0_N1 | 0x00 |
129 | LTC2496_P1_N0 | 0x08 |
130 | | |
131 | LTC2496_P2_N3 | 0x01 |
132 | LTC2496_P3_N2 | 0x09 |
133 | | |
134 | LTC2496_P4_N5 | 0x02 |
135 | LTC2496_P5_N4 | 0x0A |
136 | | |
137 | LTC2496_P6_N7 | 0x03 |
138 | LTC2496_P7_N6 | 0x0B |
139 | | |
140 | LTC2496_P8_N9 | 0x04 |
141 | LTC2496_P9_N8 | 0x0C |
142 | | |
143 | LTC2496_P10_N11 | 0x05 |
144 | LTC2496_P11_N10 | 0x0D |
145 | | |
146 | LTC2496_P12_N13 | 0x06 |
147 | LTC2496_P13_N12 | 0x0E |
148 | | |
149 | LTC2496_P14_N15 | 0x07 |
150 | LTC2496_P15_N14 | 0x0F |
151 */
152 /*! @name LTC2496 Differential Channel Selection
153 @{*/
154 
155 #define LTC2496_P0_N1 0x00
156 #define LTC2496_P1_N0 0x08
157 
158 #define LTC2496_P2_N3 0x01
159 #define LTC2496_P3_N2 0x09
160 
161 #define LTC2496_P4_N5 0x02
162 #define LTC2496_P5_N4 0x0A
163 
164 #define LTC2496_P6_N7 0x03
165 #define LTC2496_P7_N6 0x0B
166 
167 #define LTC2496_P8_N9 0x04
168 #define LTC2496_P9_N8 0x0C
169 
170 #define LTC2496_P10_N11 0x05
171 #define LTC2496_P11_N10 0x0D
172 
173 #define LTC2496_P12_N13 0x06
174 #define LTC2496_P13_N12 0x0E
175 
176 #define LTC2496_P14_N15 0x07
177 #define LTC2496_P15_N14 0x0F
178 
179 /*!
180 |LTC2496 Channel Selection | Value |
181 | :--------------------------: | :------: |
182 | LTC2496_CH0 | 0x10 |
183 | LTC2496_CH1 | 0x18 |
184 | LTC2496_CH2 | 0x11 |
185 | LTC2496_CH3 | 0x19 |
186 | LTC2496_CH4 | 0x12 |
187 | LTC2496_CH5 | 0x1A |
188 | LTC2496_CH6 | 0x13 |
189 | LTC2496_CH7 | 0x1B |
190 | LTC2496_CH8 | 0x14 |
191 | LTC2496_CH9 | 0x1C |
192 | LTC2496_CH10 | 0x15 |
193 | LTC2496_CH11 | 0x1D |
194 | LTC2496_CH12 | 0x16 |
195 | LTC2496_CH13 | 0x1E |
196 | LTC2496_CH14 | 0x17 |
197 | LTC2496_CH15 | 0x1F |
198 */
199 /*! @name LTC2496 Single-Ended Channel Selection
200 @{ */
201 
202 #define LTC2496_CH0 0x10
203 #define LTC2496_CH1 0x18
204 #define LTC2496_CH2 0x11
205 #define LTC2496_CH3 0x19
206 #define LTC2496_CH4 0x12
207 #define LTC2496_CH5 0x1A
208 #define LTC2496_CH6 0x13
209 #define LTC2496_CH7 0x1B
210 #define LTC2496_CH8 0x14
211 #define LTC2496_CH9 0x1C
212 #define LTC2496_CH10 0x15
213 #define LTC2496_CH11 0x1D
214 #define LTC2496_CH12 0x16
215 #define LTC2496_CH13 0x1E
216 #define LTC2496_CH14 0x17
217 #define LTC2496_CH15 0x1F
218 
219 
220 //! Checks for EOC with a specified timeout
221 //! @return Returns 0=successful, 1=unsuccessful (exceeded timeout)
222 int8_t LTC2496_EOC_timeout(uint8_t cs, //!< Chip Select pin
223  uint16_t miso_timeout //!< Timeout (in millisends)
224  );
225 
226 //! Read LTC2496 result, program configuration for next conversion
227 // Example - read channel external input with 60Hz rejection and 2X enabled.
228 // adc_command = LTC2496_ENABLE|LTC2496_P0_N1;
229 //! @return void
230 void LTC2496_read(uint8_t cs, //!< Chip Select pin
231  uint8_t adc_command, //!< Command byte
232  int32_t *adc_code //!< Returns raw 32-bit code read from ADC
233  );
234 
235 
236 //! Calculates the LTC2496 input voltage
237 //! @return Calculated voltage
238 float LTC2496_code_to_voltage(int32_t adc_code, //!< Raw ADC code
239  float vref //!< the reference voltage to the ADC
240  );
241 #endif