| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

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