Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LTC2756.h
Go to the documentation of this file.
1 /*!
2 LTC2756: Serial 18-Bit SoftSpan IOUT DAC
3 
4 @verbatim
5 
6 The LTC2756 is an 18-bit multiplying serial-input,
7 current-output digital-to-analog converter. LTC2756A
8 provides full 18-bit performance-INL and DNL of +/-1LSB
9 maximum-over temperature without any adjustments. 18-bit
10 monotonicity is guaranteed in all performance grades. This
11 SoftSpan(TM) DAC operates from a single 3V to 5V supply
12 and offers six output ranges (up to +/-10V) that can be
13 programmed through the 3-wire SPI serial interface or
14 pin-strapped for operation in a single range.
15 
16 SPI DATA FORMAT (MSB First):
17 
18 Transfer Sequence:
19  Byte #1 Byte #2
20 MOSI: C3 C2 C1 C0 0 0 0 0 D17 D16 D15 D14 D13 D12 D11 D10
21 MISO: 0 0 0 0 0 0 0 0 D17 D16 D15 D14 D13 D12 D11 D10
22 
23  Byte #3 Byte #4
24 MOSI: D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 X X X X X X
25 MISO: D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 0 0 0 0 0 0
26 
27 Write SPAN Sequence:
28  Byte #1 Byte #2
29 MOSI: C3 C2 C1 C0 0 0 0 0 X X X X X X X X
30 MISO: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
31 
32  Byte #3 Byte #4
33 MOSI: X X X X S3 S2 S1 S0 X X X X X X X X
34 MISO: 0 0 0 0 S3 S2 S1 S0 0 0 0 0 0 0 0 0
35 
36 
37 Cx : DAC Command bits
38 Sx : SPAN bits
39 Dx : DAC Data Bits
40 X : Don't care
41 
42 Example Code:
43 
44 Set DAC to -5v to +5v and set output to 2.5v
45 
46 uint8_t tx[4],rx[4];
47 
48 // Set DAC to -5v to +5v
49 tx[3] = LTC2756_WRITE_SPAN;
50 tx[2] = 0x00;
51 tx[1] = LTC2756_BIPOLAR_N5_P5;
52 tx[0] = 0x00;
53 
54 LTC2756_transfer_4bytes(LTC2756_CS, tx, rx);
55 
56 float voltage = 2.5;
57 float LTC2756_lsb = 3.8146972656e-5; // Typical lsb for -5V to +5v bipolar mode only
58 int32_t LTC2756_offset = 0x20000; // Typical offset for -5V to +5v bipolar mode only
59 
60 // Convert voltage to code
61 uint32_t code;
62 code = LTC2756_voltage_to_code(voltage, LTC2756_lsb, LTC2756_offset);
63 
64 uint8_t tx[4],rx[4];
65 union
66 {
67  uint8_t byte[4];
68  uint32_t code;
69 } data;
70 
71 // Load tx array with write command and code
72 data.code = code<<6;
73 tx[3] = LTC2756_WRITE_CODE;
74 tx[2] = data.byte[2];
75 tx[1] = data.byte[1];
76 tx[0] = data.byte[0];
77 
78 LTC2756_transfer_4bytes(LTC2756_CS, tx, rx);
79 
80 // Load tx arra with update DAC command
81 tx[3] = LTC2756_UPDATE;
82 tx[2] = 0x00;
83 tx[1] = 0x00;
84 tx[0] = 0x00;
85 
86 LTC2756_transfer_4bytes(LTC2756_CS, tx, rx);
87 
88 @endverbatim
89 
90 http://www.linear.com/product/LTC2756
91 
92 http://www.linear.com/product/LTC2756#demoboards
93 
94 Copyright 2018(c) Analog Devices, Inc.
95 
96 All rights reserved.
97 
98 Redistribution and use in source and binary forms, with or without
99 modification, are permitted provided that the following conditions are met:
100  - Redistributions of source code must retain the above copyright
101  notice, this list of conditions and the following disclaimer.
102  - Redistributions in binary form must reproduce the above copyright
103  notice, this list of conditions and the following disclaimer in
104  the documentation and/or other materials provided with the
105  distribution.
106  - Neither the name of Analog Devices, Inc. nor the names of its
107  contributors may be used to endorse or promote products derived
108  from this software without specific prior written permission.
109  - The use of this software may or may not infringe the patent rights
110  of one or more patent holders. This license does not release you
111  from the requirement that you obtain separate licenses from these
112  patent holders to use this software.
113  - Use of the software either in source or binary form, must be run
114  on or directly connected to an Analog Devices Inc. component.
115 
116 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
117 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
118 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
119 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
120 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
121 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
122 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
123 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
124 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
125 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
126 */
127 
128 /*! @file
129  @ingroup LTC2756
130  Library Header File for LTC2756: Serial 18-Bit SoftSpan IOUT DAC
131 */
132 
133 #ifndef LTC2756_H
134 #define LTC2756_H
135 
136 //! Define the CS pin
137 #ifndef LTC2756_CS
138 #define LTC2756_CS QUIKEVAL_CS //! SPI Chip Select Pin
139 #endif
140 
141 #include <SPI.h>
142 
143 //! @name LTC2756 DAC Cammands
144 //! @{
145 #define LTC2756_WRITE_SPAN 0x20
146 #define LTC2756_WRITE_CODE 0x30
147 #define LTC2756_UPDATE 0x40
148 #define LTC2756_WRITE_SPAN_UPDATE 0x60
149 #define LTC2756_WRITE_CODE_UPDATE 0x70
150 #define LTC2756_READ_INPUTE_SPAN_REG 0xA0
151 #define LTC2756_READ_INPUT_CODE_REG 0xB0
152 #define LTC2756_READ_DAC_SPAN_REG 0xC0
153 #define LTC2756_READ_DAC_CODE_REG 0xD0
154 //! @}
155 
156 //! @name LTC2756 SPAN Options
157 //! @{
158 #define LTC2756_UNIPOLAR_0_P5 0x00
159 #define LTC2756_UNIPOLAR_0_P10 0x01
160 #define LTC2756_BIPOLAR_N5_P5 0x02
161 #define LTC2756_BIPOLAR_N10_P10 0x03
162 #define LTC2756_BIPOLAR_N2_5_P2_5 0x04
163 #define LTC2756_BIPOLAR_N2_5_P7_5 0x05
164 //! @}
165 
166 //! Transfers four bytes to the LTC2756
167 //! @return void
168 void LTC2756_transfer_4bytes(uint8_t cs,
169  uint8_t *tx,
170  uint8_t *rx
171  );
172 
173 //! Converts voltage to code
174 //! @return the calculated code
175 uint32_t LTC2756_voltage_to_code(float dac_voltage,
176  float LTC2756_lsb,
177  int32_t LTC2756_offset
178  );
179 //! Calculate the LTC2756 offset and LSB voltage given two measured voltages and their corresponding codes
180 //! @returns void
181 void LTC2756_calibrate(uint32_t zero_code,
182  uint32_t fs_code,
183  float zero_voltage,
184  float fs_voltage,
185  float *LTC2756_lsb,
186  int32_t *LTC2756_offset
187  );
188 
189 #endif
void LTC2756_transfer_4bytes(uint8_t cs, uint8_t *tx, uint8_t *rx)
Transfers four bytes to the LTC2756.
Definition: LTC2756.cpp:74
uint32_t LTC2756_voltage_to_code(float dac_voltage, float LTC2756_lsb, int32_t LTC2756_offset)
Converts voltage to code.
Definition: LTC2756.cpp:81
static int32_t LTC2756_offset
static float LTC2756_lsb
void LTC2756_calibrate(uint32_t zero_code, uint32_t fs_code, float zero_voltage, float fs_voltage, float *LTC2756_lsb, int32_t *LTC2756_offset)
Calculate the LTC2756 offset and LSB voltage given two measured voltages and their corresponding code...
Definition: LTC2756.cpp:97