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