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