| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LTC2657.cpp
Go to the documentation of this file.
1 /*!
2 LTC2657: Octal I2C 16-/12-Bit Rail-to-Rail DACs with 10ppm/C Max Reference
3
4 @verbatim
5
6 The LTC2657 is a family of octal 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 LTC2657-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 LTC2657-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 a 2-wire I2C compatible serial interface. The LTC2657 operates in
16 both the standard mode (maximum clock rate of 100kHz) and the fast mode (maximum
17 clock rate of 400kHz). The LTC2657 incorporates a power-on reset circuit that is
18 controlled by the PORSEL pin. If PORSEL is tied to GND the DACs reset to
19 zero-scale at power-up. If PORSEL is tied to VCC, the DACs reset to mid-scale at
20 power-up.
21
22 @endverbatim
23
24 http://www.linear.com/product/LTC2657
25
26 http://www.linear.com/product/LTC2657#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 LTC2657 LTC2657: Octal I2C 16-/12-Bit Rail-to-Rail DACs with 10ppm/C Max Reference
66 //! @}
67
68 /*! @file
69 @ingroup LTC2657
70 Library for LTC2657 Octal 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 "LTC2657.h"
79
80 // Write a 16-bit dac_code to the LTC2657.
81 // The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
82 int8_t LTC2657_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 LTC2657 DAC code given the desired output voltage and DAC address (0-7)
91 uint16_t LTC2657_voltage_to_code(float dac_voltage, float LTC2657_lsb, int16_t LTC2657_offset)
92 {
93 int32_t dac_code;
94 float float_code;
95 float_code = dac_voltage / LTC2657_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 - LTC2657_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 LTC2657 DAC output voltage given the DAC code and DAC address (0-7)
104 float LTC2657_code_to_voltage(uint16_t dac_code, float LTC2657_lsb, int16_t LTC2657_offset)
105 {
106 float dac_voltage;
107 dac_voltage = ((float)(dac_code + LTC2657_offset)* LTC2657_lsb); //! 1) Calculates the dac_voltage
108 return (dac_voltage);
109 }
110
111 // Calculate the LTC2657 offset and LSB voltage given two measured voltages and their corresponding codes
112 void LTC2657_calibrate(uint16_t dac_code1, uint16_t dac_code2, float voltage1, float voltage2, float *LTC2657_lsb, int16_t *LTC2657_offset)
113 {
114 float temp_offset;
115 *LTC2657_lsb = (voltage2 - voltage1) / ((float) (dac_code2 - dac_code1)); //! 1) Calculate the LSB
116 temp_offset = voltage1/(*LTC2657_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 *LTC2657_offset = (int16_t)temp_offset; //! 4) Cast as int16_t
119 }
i2c_address
uint8_t i2c_address
LTC2657_voltage_to_code
uint16_t LTC2657_voltage_to_code(float dac_voltage, float LTC2657_lsb, int16_t LTC2657_offset)
Calculate a LTC2657 DAC code given the desired output voltage and DAC address (0-3) ...
Definition: LTC2657.cpp:91
Linduino.h
Header File for Linduino Libraries and Demo Code.
LTC2657_calibrate
void LTC2657_calibrate(uint16_t dac_code1, uint16_t dac_code2, float voltage1, float voltage2, float *LTC2657_lsb, int16_t *LTC2657_offset)
Calculate the LTC2657 offset and LSB voltages given two measured voltages and their corresponding cod...
Definition: LTC2657.cpp:112
i2c_write_word_data
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
LTC2657_offset
static int16_t LTC2657_offset[9]
DAC offset - index 8 for "all DACs".
Definition: DC1529A.ino:163
LTC2657_write
int8_t LTC2657_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 LTC2657.
Definition: LTC2657.cpp:82
LT_I2C.h
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
LTC2657_lsb
static float LTC2657_lsb[9]
The LTC2657 lsb - index 8 for "all DACs".
Definition: DC1529A.ino:164
LTC2657_code_to_voltage
float LTC2657_code_to_voltage(uint16_t dac_code, float LTC2657_lsb, int16_t LTC2657_offset)
Calculate the LTC2657 DAC output voltage given the DAC code, offset, and LSB value.
Definition: LTC2657.cpp:104
LTC2657.h
LTC2657: Octal I2C 16-/12-Bit Rail-to-Rail DACs with 10ppm/C Max Reference.