Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LTC2607.cpp
Go to the documentation of this file.
1 /*!
2 LTC2607: 16-Bit, Dual Rail-to-Rail DACs with I2C Interface.
3 LTC2609: Quad 16-/14-/12-Bit Rail-to-Rail DACs with I²C Interface.
4 LTC2606: 16-Bit Rail-to-Rail DACs with I²C Interface.
5 
6 @verbatim
7 
8 The LTC2607/LTC2617/LTC2627 are dual 16-, 14- and 12-bit, 2.7V to 5.5V
9 rail-to-rail voltage output DACs in a 12-lead DFN package. They have built-in
10 high performance output buffers and are guaranteed monotonic.
11 
12 These parts establish new board-density benchmarks for 16- and 14-bit DACs and
13 advance performance standards for output drive and load regulation in single-
14 supply, voltage-output DACs.
15 
16 The parts use a 2-wire, I2C compatible serial interface. The
17 LTC2607/LTC2617/LTC2627 operate in both the standard mode (clock rate of 100kHz)
18 and the fast mode (clock rate of 400kHz). An asynchronous DAC update pin (LDAC)
19 is also included.
20 
21 The LTC2607/LTC2617/LTC2627 incorporate a power-on reset circuit. During power-
22 up, the voltage outputs rise less than 10mV above zero scale; and after power-
23 up, they stay at zero scale until a valid write and update take place. The
24 power-on reset circuit resets the LTC2607-1/LTC2617-1/ LTC2627-1 to mid-scale.
25 The voltage outputs stay at midscale until a valid write and update takes place.
26 
27 @endverbatim
28 
29 http://www.linear.com/product/LTC2607
30 http://www.linear.com/product/LTC2609
31 http://www.linear.com/product/LTC2606
32 
33 http://www.linear.com/product/LTC2607#demoboards
34 http://www.linear.com/product/LTC2609#demoboards
35 http://www.linear.com/product/LTC2606#demoboards
36 
37 
38 Copyright 2018(c) Analog Devices, Inc.
39 
40 All rights reserved.
41 
42 Redistribution and use in source and binary forms, with or without
43 modification, are permitted provided that the following conditions are met:
44  - Redistributions of source code must retain the above copyright
45  notice, this list of conditions and the following disclaimer.
46  - Redistributions in binary form must reproduce the above copyright
47  notice, this list of conditions and the following disclaimer in
48  the documentation and/or other materials provided with the
49  distribution.
50  - Neither the name of Analog Devices, Inc. nor the names of its
51  contributors may be used to endorse or promote products derived
52  from this software without specific prior written permission.
53  - The use of this software may or may not infringe the patent rights
54  of one or more patent holders. This license does not release you
55  from the requirement that you obtain separate licenses from these
56  patent holders to use this software.
57  - Use of the software either in source or binary form, must be run
58  on or directly connected to an Analog Devices Inc. component.
59 
60 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
61 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
62 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
63 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
64 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
65 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
66 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
67 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
68 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
69 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
70 */
71 
72 //! @ingroup Digital_to_Analog_Converters
73 //! @{
74 //! @defgroup LTC2607 LTC2607: 16-Bit, Dual Rail-to-Rail DACs with I2C Interface
75 //! @}
76 
77 /*! @file
78  @ingroup LTC2607
79  Library for LTC2607: 16-Bit, Dual Rail-to-Rail DACs with I2C Interface
80 */
81 
82 #include <Arduino.h>
83 #include <stdint.h>
84 #include <math.h>
85 #include "Linduino.h"
86 //#include "LT_I2C.h"
87 #include "LTC2607.h"
88 #include <Wire.h>
89 
90 #include "USE_WIRE.h"
91 
92 #ifdef USEWIRE
93 #include "LT_I2C_Wire.h"
94 #else
95 #include "LT_I2C.h"
96 #endif
97 
98 // Writes command, DAC address, and DAC code to the LTC2607.
99 // Configures command (write, update, power down, etc.), address (DAC A, DAC B, or BOTH), and 16-bit dac_code for output voltage.
100 int8_t LTC2607_write(uint8_t i2c_address, uint8_t dac_command, uint8_t dac_address, uint16_t dac_code)
101 {
102  int8_t ack;
103 
104  ack = i2c_write_word_data(i2c_address, (dac_command | dac_address), dac_code);
105  return(ack);
106 }
107 
108 // Calculates an LTC2607 DAC code for the desired output voltage.
109 // Based on the desired output voltage, the offset, and lsb parameters, return the corresponding DAC code that should be written to the LTC2607.
110 uint16_t LTC2607_voltage_to_code(float dac_voltage, float LTC2607_lsb, int32_t LTC2607_offset)
111 {
112  int32_t dac_code;
113  float float_code;
114  float_code = dac_voltage / LTC2607_lsb - LTC2607_offset; //! 1) Calculate the DAC code
115  float_code = (float_code > (floor(float_code) + 0.5)) ? ceil(float_code) : floor(float_code); //! 2) Round
116  dac_code = (uint16_t) (float_code); //! 3) Convert to unsigned integer
117  if (dac_code > 65535)
118  dac_code = 65535;
119  if (dac_code < 0)
120  dac_code = 0;
121  return ((uint16_t)dac_code);
122 }
123 
124 // Calculates the LTC2607 offset and lsb voltage given two measured voltages and their corresponding DAC codes.
125 // Prior to calling this function, write two DAC codes to the LTC2607, and measure the output voltage for each DAC code.
126 // When passed the DAC codes and measured voltages as parameters, this function calculates the calibrated lsb and offset values.
127 void LTC2607_calibrate(uint16_t dac_code1, uint16_t dac_code2, float voltage1, float voltage2, float *LTC2607_lsb, int32_t *LTC2607_offset)
128 {
129  float temp_offset;
130  *LTC2607_lsb = (voltage2 - voltage1) / ((float) (dac_code2 - dac_code1)); //! 1) Calculate the LSB
131  temp_offset = voltage1/(*LTC2607_lsb) - dac_code1; //! 2) Calculate the offset
132  temp_offset = (temp_offset > (floor(temp_offset) + 0.5)) ? ceil(temp_offset) : floor(temp_offset); //! 3) Round
133  *LTC2607_offset = (int32_t)temp_offset; //! 4) Cast as int32_t
134 }
static int32_t LTC2607_offset[3]
The LTC2422 offset variable.
Definition: DC934A.ino:139
uint8_t i2c_address
uint16_t LTC2607_voltage_to_code(float dac_voltage, float LTC2607_lsb, int32_t LTC2607_offset)
Calculates an LTC2607 DAC code for the desired output voltage.
Definition: LTC2607.cpp:110
void LTC2607_calibrate(uint16_t dac_code1, uint16_t dac_code2, float voltage1, float voltage2, float *LTC2607_lsb, int32_t *LTC2607_offset)
Calculates the LTC2607 offset and lsb voltage given two measured voltages and their corresponding DAC...
Definition: LTC2607.cpp:127
static float LTC2607_lsb[3]
The LTC2607 least significant bit value with 5V full-scale.
Definition: DC934A.ino:131
Header File for Linduino Libraries and Demo Code.
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
int8_t i2c_write_word_data(uint8_t address, uint8_t command, uint16_t value)
Write a 16-bit word of data to register specified by "command".
Definition: LT_I2C.cpp:216
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
LTC2607: 16-Bit, Dual Rail-to-Rail DACs with I2C Interface.
int8_t LTC2607_write(uint8_t i2c_address, uint8_t dac_command, uint8_t dac_address, uint16_t dac_code)
Writes command, DAC address, and DAC code to the LTC2607.
Definition: LTC2607.cpp:100