Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LTC2655.cpp
Go to the documentation of this file.
1 /*!
2 LTC2655: Quad I2C 16-/12-Bit Rail-to-Rail DACs with 10ppm/C Max Reference
3 
4 @verbatim
5 
6 The LTC2655 is a family of Quad I2C 16-/12-Bit Rail-to-Rail DACs with
7 integrated 10ppm/C max reference. The DACs have built-in high performance,
8 rail-to-rail, output buffers and are guaranteed monotonic. The LTC2655-L has a
9 full-scale output of 2.5V with the integrated reference and operates from a
10 single 2.7V to 5.5V supply. The LTC2655-H has a full-scale output of 4.096V with
11 the integrated reference and operates from a 4.5V to 5.5V supply. Each DAC can
12 also operate with an external reference, which sets the full-scale output to 2
13 times the external reference voltage.
14 
15 The parts use the 2-wire I2C compatible serial interface. The LTC2655 operates
16 in both the standard mode (maximum clock rate of 100kHz) and the fast mode
17 (maximum clock rate of 400kHz). The LTC2655 incorporates a power-on reset
18 circuit that is controlled by the PORSEL pin. If PORSEL is tied to GND the DACs
19 power-on reset to zero-scale. If PORSEL is tied to VCC, the DACs power-on reset
20 to mid-scale.
21 
22 @endverbatim
23 
24 http://www.linear.com/product/LTC2655
25 
26 http://www.linear.com/product/LTC2655#demoboards
27 
28 
29 Copyright 2018(c) Analog Devices, Inc.
30 
31 All rights reserved.
32 
33 Redistribution and use in source and binary forms, with or without
34 modification, are permitted provided that the following conditions are met:
35  - Redistributions of source code must retain the above copyright
36  notice, this list of conditions and the following disclaimer.
37  - Redistributions in binary form must reproduce the above copyright
38  notice, this list of conditions and the following disclaimer in
39  the documentation and/or other materials provided with the
40  distribution.
41  - Neither the name of Analog Devices, Inc. nor the names of its
42  contributors may be used to endorse or promote products derived
43  from this software without specific prior written permission.
44  - The use of this software may or may not infringe the patent rights
45  of one or more patent holders. This license does not release you
46  from the requirement that you obtain separate licenses from these
47  patent holders to use this software.
48  - Use of the software either in source or binary form, must be run
49  on or directly connected to an Analog Devices Inc. component.
50 
51 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
52 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
53 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
54 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
55 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
57 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
58 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
59 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61  */
62 
63 //! @ingroup Digital_to_Analog_Converters
64 //! @{
65 //! @defgroup LTC2655 LTC2655: Quad I2C 16-/12-Bit Rail-to-Rail DACs with 10ppm/C Max Reference
66 //! @}
67 
68 /*! @file
69  @ingroup LTC2655
70  Library for LTC2655: Quad I2C 16-/12-Bit Rail-to-Rail DACs with 10ppm/C Max Reference
71 */
72 
73 #include <Arduino.h>
74 #include <stdint.h>
75 #include <math.h>
76 #include "Linduino.h"
77 #include "LT_I2C.h"
78 #include "LTC2655.h"
79 
80 // Write the dac_command byte and 16-bit dac_code to the LTC2655.
81 // The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
82 int8_t LTC2655_write(uint8_t i2c_address, uint8_t dac_command, uint8_t dac_address, uint16_t dac_code)
83 {
84  int8_t ack;
85 
86  ack = i2c_write_word_data(i2c_address, dac_command | dac_address, dac_code);
87  return(ack);
88 }
89 
90 // Calculate a LTC2655 DAC code given the desired output voltage and DAC address (0-3)
91 uint16_t LTC2655_voltage_to_code(float dac_voltage, float LTC2655_lsb, int16_t LTC2655_offset)
92 {
93  int32_t dac_code;
94  float float_code;
95  float_code = dac_voltage / LTC2655_lsb; //! 1) Calculate the DAC code
96  float_code = (float_code > (floor(float_code) + 0.5)) ? ceil(float_code) : floor(float_code); //! 2) Round
97  dac_code = (int32_t)float_code - LTC2655_offset; //! 3) Subtract offset
98  if (dac_code < 0) //! 4) If DAC code < 0, Then DAC code = 0
99  dac_code = 0;
100  return ((uint16_t)dac_code); //! 5) Cast DAC code as uint16_t
101 }
102 
103 // Calculate the LTC2655 DAC output voltage given the DAC code and DAC address (0-3)
104 float LTC2655_code_to_voltage(uint16_t dac_code, float LTC2655_lsb, int16_t LTC2655_offset)
105 {
106  float dac_voltage;
107  dac_voltage = ((float)(dac_code + LTC2655_offset)* LTC2655_lsb); //! 1) Calculates the dac_voltage
108  return (dac_voltage);
109 }
110 
111 // Calculate the LTC2655 offset and LSB voltage given two measured voltages and their corresponding codes
112 void LTC2655_calibrate(uint16_t dac_code1, uint16_t dac_code2, float voltage1, float voltage2, float *LTC2655_lsb, int16_t *LTC2655_offset)
113 {
114  float temp_offset;
115  *LTC2655_lsb = (voltage2 - voltage1) / ((float) (dac_code2 - dac_code1)); //! 1) Calculate the LSB
116  temp_offset = (voltage1/(*LTC2655_lsb) - (float)dac_code1); //! 2) Calculate the offset
117  temp_offset = (temp_offset > (floor(temp_offset) + 0.5)) ? ceil(temp_offset) : floor(temp_offset); //! 3) Round offset
118  *LTC2655_offset = (int16_t)temp_offset; //! 4) Cast as int16_t
119 }
LTC2655: Quad I2C 16-/12-Bit Rail-to-Rail DACs with 10ppm/C Max Reference.
uint8_t i2c_address
static float LTC2655_lsb[5]
The LTC2655 lsb - index 4 for "all DACs." If part is calibrated, then index 0 is stored to "all DACs...
Definition: DC1703A.ino:167
void LTC2655_calibrate(uint16_t dac_code1, uint16_t dac_code2, float voltage1, float voltage2, float *LTC2655_lsb, int16_t *LTC2655_offset)
Calculate the LTC2655 offset and LSB voltages given two measured voltages and their corresponding cod...
Definition: LTC2655.cpp:112
Header File for Linduino Libraries and Demo Code.
static int16_t LTC2655_offset[5]
DAC offset - index 4 for "all DACs." If part is calibrated, then index 0 is stored to "all DACs...
Definition: DC1703A.ino:166
uint16_t LTC2655_voltage_to_code(float dac_voltage, float LTC2655_lsb, int16_t LTC2655_offset)
Calculate a LTC2655 DAC code given the desired output voltage.
Definition: LTC2655.cpp:91
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
int8_t LTC2655_write(uint8_t i2c_address, uint8_t dac_command, uint8_t dac_address, uint16_t dac_code)
Write a 16-bit dac_code to the LTC2655.
Definition: LTC2655.cpp:82
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
float LTC2655_code_to_voltage(uint16_t dac_code, float LTC2655_lsb, int16_t LTC2655_offset)
Calculate the LTC2655 DAC output voltage given the DAC code, offset, and LSB value.
Definition: LTC2655.cpp:104