| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LTC2605.cpp
Go to the documentation of this file.
1 /*!
2 LTC2605: Octal 16-/14-/12-Bit Rail-to Rail DACs in 16-Lead SSOP
3
4 @verbatim
5
6 The LTC2605/LTC2615/LTC2625 are octal 16-, 14- and 12-bit, 2.7V to 5.5V
7 rail-to-rail voltage-output DACs in 16-lead narrow SSOP packages. They have
8 built-in high performance output buffers and are guaranteed monotonic.
9
10 These parts establish new board-density benchmarks for 16-/14-bit DACs and
11 advance performance standards for output drive, crosstalk and load regulation
12 in single supply, voltage-output multiples.
13
14
15 @endverbatim
16
17
18 http://www.linear.com/product/LTC2605
19
20 http://www.linear.com/product/LTC2605#demoboards
21
22
23
24 Copyright 2018(c) Analog Devices, Inc.
25
26 All rights reserved.
27
28 Redistribution and use in source and binary forms, with or without
29 modification, are permitted provided that the following conditions are met:
30 - Redistributions of source code must retain the above copyright
31 notice, this list of conditions and the following disclaimer.
32 - Redistributions in binary form must reproduce the above copyright
33 notice, this list of conditions and the following disclaimer in
34 the documentation and/or other materials provided with the
35 distribution.
36 - Neither the name of Analog Devices, Inc. nor the names of its
37 contributors may be used to endorse or promote products derived
38 from this software without specific prior written permission.
39 - The use of this software may or may not infringe the patent rights
40 of one or more patent holders. This license does not release you
41 from the requirement that you obtain separate licenses from these
42 patent holders to use this software.
43 - Use of the software either in source or binary form, must be run
44 on or directly connected to an Analog Devices Inc. component.
45
46 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
47 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
48 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
49 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
50 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
52 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
53 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
55 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 */
57
58 //! @ingroup Digital_to_Analog_Converters
59 //! @{
60 //! @defgroup LTC2605 LTC2605: Octal 16-/14-/12-Bit Rail-to Rail DACs in 16-Lead SSOP
61 //! @}
62
63 /*! @file
64 @ingroup LTC2605
65 Library for LTC2605: Octal 16-/14-/12-Bit Rail-to Rail DACs in 16-Lead SSOP
66 */
67 #include <Arduino.h>
68 #include <stdint.h>
69 #include <math.h>
70 #include "Linduino.h"
71 #include "LT_I2C.h"
72 #include "LTC2605.h"
73
74 // Write the dac_command byte and 16-bit dac_code to the LTC2605.
75 // The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
76 int8_t LTC2605_write(uint8_t i2c_address, uint8_t dac_command, uint8_t dac_address, uint16_t dac_code)
77 {
78 int8_t ack;
79
80 ack = i2c_write_word_data(i2c_address, dac_command | dac_address, dac_code);
81 return(ack);
82 }
83
84 // Calculate a LTC26505 DAC code given the desired output voltage and DAC address (0-3)
85 uint16_t LTC2605_voltage_to_code(float dac_voltage, float LTC2605_lsb, int16_t LTC2605_offset)
86 {
87 int32_t dac_code;
88 float float_code;
89 float_code = dac_voltage / LTC2605_lsb; //! 1) Calculate the DAC code
90 float_code = (float_code > (floor(float_code) + 0.5)) ? ceil(float_code) : floor(float_code); //! 2) Round
91 dac_code = (int32_t)float_code - LTC2605_offset; //! 3) Subtract offset
92 if (dac_code < 0) //! 4) If DAC code < 0, Then DAC code = 0
93 dac_code = 0;
94 return ((uint16_t)dac_code); //! 5) Cast DAC code as uint16_t
95 }
96
97 // Calculate the LTC2605 DAC output voltage given the DAC code and DAC address (0-3)
98 float LTC2605_code_to_voltage(uint16_t dac_code, float LTC2605_lsb, int16_t LTC2605_offset)
99 {
100 float dac_voltage;
101 dac_voltage = ((float)(dac_code + LTC2605_offset)* LTC2605_lsb); //! 1) Calculates the dac_voltage
102 return (dac_voltage);
103 }
i2c_address
uint8_t i2c_address
LTC2605_offset
static int16_t LTC2605_offset
DAC offset.
Definition: DC935A.ino:128
Linduino.h
Header File for Linduino Libraries and Demo Code.
LTC2605_voltage_to_code
uint16_t LTC2605_voltage_to_code(float dac_voltage, float LTC2605_lsb, int16_t LTC2605_offset)
Calculate a LTC2605 DAC code given the desired output voltage.
Definition: LTC2605.cpp:85
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
LTC2605_lsb
static float LTC2605_lsb
Definition: DC935A.ino:129
LT_I2C.h
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
LTC2605_write
int8_t LTC2605_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 LTC2605.
Definition: LTC2605.cpp:76
LTC2605_code_to_voltage
float LTC2605_code_to_voltage(uint16_t dac_code, float LTC2605_lsb, int16_t LTC2605_offset)
Calculate the LTC2605 DAC output voltage given the DAC code, offset, and LSB value.
Definition: LTC2605.cpp:98
LTC2605.h
LTC2605: Octal 16-/14-/12-Bit Rail-to Rail DACs in 16-Lead SSOP.