Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LTC2640.h
Go to the documentation of this file.
1 /*!
2 LTC2640: Single 12-/10-/8-Bit Rail-to-Rail DACs with 10ppm/C Reference.
3 LTC2630: Single 12-/10-/8-Bit Rail-to-Rail DACs with Integrated Reference in SC70.
4 
5 @verbatim
6 
7 The LTC2640 is a family of 12-, 10-, and 8-bit voltage-output DACs with an
8 integrated, high-accuracy, low-drift reference in an 8-lead TSOT-23 package. It
9 has a rail-to-rail output buffer that is guaranteed monotonic.
10 
11 The LTC2640-L has a full-scale output of 2.5V, and operates from a single 2.7V
12 to 5.5V supply. The LTC2640-H has a full-scale output of 4.096V, and operates
13 from a 4.5V to 5.5V supply. A 10 ppm/C reference output is available at the REF
14 pin.
15 
16 Each DAC can also operate in External Reference mode, in which a voltage
17 supplied to the REF pin sets the full- scale output. The LTC2640 DACs use a
18 SPI/MICROWIRE compatible 3-wire serial interface which operates at clock rates
19 up to 50 MHz.
20 
21 The LTC2640 incorporates a power-on reset circuit. Options are available for
22 Reset to Zero Scale or Reset to Midscale after power-up.
23 
24 SPI DATA FORMAT (MSB First):
25 
26  Byte #1 Byte #2 Byte #3
27 (LTC2640-12)
28 Data In : C3 C2 C1 C0 X X X X D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 X X X X
29 (LTC2640-10)
30 Data In : C3 C2 C1 C0 X X X X D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 X X X X X X
31 (LTC2640-8)
32 Data In : C3 C2 C1 C0 X X X X D7 D6 D5 D4 D3 D2 D1 D0 X X X X X X X X
33 
34 Cx : DAC Command Code
35 Dx : Data Bits
36 X : Don't care
37 
38 Example Code:
39 
40 Set DAC to 1V for 12-bit DAC.
41 
42 
43  shift_count = 4; // Set shift count for 12-bit DAC
44 
45  dac_voltage = 1.0; // Set dac voltage variable to 1V;
46  dac_code = LTC2640_voltage_to_code(dac_voltage, LTC2640_lsb, LTC2640_offset); // Calculates DAC code from desired voltage
47 
48  LTC2640_write(LTC2640_CS, LTC2640_CMD_WRITE_UPDATE, dac_code << shift_count);
49 
50 @endverbatim
51 
52 http://www.linear.com/product/LTC2640
53 http://www.linear.com/product/LTC2630
54 
55 http://www.linear.com/product/LTC2640#demoboards
56 http://www.linear.com/product/LTC2630#demoboards
57 
58 
59 Copyright 2018(c) Analog Devices, Inc.
60 
61 All rights reserved.
62 
63 Redistribution and use in source and binary forms, with or without
64 modification, are permitted provided that the following conditions are met:
65  - Redistributions of source code must retain the above copyright
66  notice, this list of conditions and the following disclaimer.
67  - Redistributions in binary form must reproduce the above copyright
68  notice, this list of conditions and the following disclaimer in
69  the documentation and/or other materials provided with the
70  distribution.
71  - Neither the name of Analog Devices, Inc. nor the names of its
72  contributors may be used to endorse or promote products derived
73  from this software without specific prior written permission.
74  - The use of this software may or may not infringe the patent rights
75  of one or more patent holders. This license does not release you
76  from the requirement that you obtain separate licenses from these
77  patent holders to use this software.
78  - Use of the software either in source or binary form, must be run
79  on or directly connected to an Analog Devices Inc. component.
80 
81 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
82 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
83 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
84 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
85 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
86 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
87 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
88 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
89 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
90 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
91  */
92 
93 /*! @file
94  @ingroup LTC2640
95  Header for LTC2640 Single 12-/10-/8-Bit Rail-to-Rail DACs with 10ppm/C Reference
96 */
97 
98 #ifndef LTC2640_H
99 #define LTC2640_H
100 
101 #include <SPI.h>
102 
103 //! Define the SPI CS pin
104 #ifndef LTC2640_CS
105 #define LTC2640_CS QUIKEVAL_CS //! SPI Chip Select Pin
106 #endif
107 
108 //! @name LTC2640 Command Codes (C3-C0)
109 //! @{
110 #define LTC2640_CMD_WRITE 0x00 // Write to input register
111 #define LTC2640_CMD_UPDATE 0x10 // Update (power up) DAC register
112 #define LTC2640_CMD_WRITE_UPDATE 0x30 // Write to and update (power up) the DAC register
113 #define LTC2640_CMD_POWER_DOWN 0x40 // Power down
114 #define LTC2640_CMD_INTERNAL_REFERENCE 0x60 // Select internal reference (default at power up)
115 #define LTC2640_CMD_EXTERNAL_REFERENCE 0x70 // Select the supply as the reference
116 //! @}
117 
118 //! Write the dac_command and 16-bit dac_code to the LTC2640. The dac_code
119 //! must be left aligned before calling this function.
120 //! @return Void
121 void LTC2640_write(uint8_t cs, //!< Chip Select Pin
122  uint8_t dac_command, //!< Command code nibble
123  uint16_t dac_code //!< 12-bit DAC code, left justified
124  );
125 
126 //! Calculate the LTC2640 DAC code given the desired output voltage
127 //! @return Code to send to DAC
128 uint16_t LTC2640_voltage_to_code(float dac_voltage, //!< Voltage to send to DAC
129  float LTC2640_lsb, //!< LSB value (volts)
130  int16_t LTC2640_offset //!< Offset (volts)
131  );
132 
133 //! Calculate the LTC2640 DAC output voltage given the DAC code, offset, and LSB value
134 //! @return Calculated voltage
135 float LTC2640_code_to_voltage(uint16_t dac_code, //!< DAC code
136  float LTC2640_lsb, //!< LSB value (volts)
137  int16_t LTC2640_offset //!< Offset (volts)
138  );
139 
140 //! Calculate the LTC2640 offset and LSB voltages given two measured voltages and their corresponding codes
141 //! @return Void
142 void LTC2640_calibrate(uint16_t dac_code1, //!< First DAC code
143  uint16_t dac_code2, //!< Second DAC code
144  float voltage1, //!< First voltage
145  float voltage2, //!< Second voltage
146  float *LTC2640_lsb, //!< Returns resulting LSB (volts)
147  int16_t *LTC2640_offset //!< Returns resulting Offset (volts)
148  );
149 
150 #endif // LTC2640_H
void LTC2640_calibrate(uint16_t dac_code1, uint16_t dac_code2, float voltage1, float voltage2, float *LTC2640_lsb, int16_t *LTC2640_offset)
Calculate the LTC2640 offset and LSB voltages given two measured voltages and their corresponding cod...
Definition: LTC2640.cpp:123
float LTC2640_code_to_voltage(uint16_t dac_code, float LTC2640_lsb, int16_t LTC2640_offset)
Calculate the LTC2640 DAC output voltage given the DAC code, offset, and LSB value.
Definition: LTC2640.cpp:115
uint16_t LTC2640_voltage_to_code(float dac_voltage, float LTC2640_lsb, int16_t LTC2640_offset)
Calculate the LTC2640 DAC code given the desired output voltage.
Definition: LTC2640.cpp:101
static float LTC2640_lsb
DAC lsb.
Definition: DC1333A.ino:169
static int16_t LTC2640_offset
DAC offset.
Definition: DC1333A.ino:170
void LTC2640_write(uint8_t cs, uint8_t dac_command, uint16_t dac_code)
Write the dac_command and 16-bit dac_code to the LTC2640.
Definition: LTC2640.cpp:87