| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LTC2642.cpp
Go to the documentation of this file.
1 /*!
2 LTC2642: 16-/14-/12-Bit VOUT DAC with SPI Interface
3 LTC2641: 16-/14-/12-Bit VOUT DAC with SPI Interface
4
5 @verbatim
6
7 The LTC2641/LTC2642 are families of 16-,14 and 12-bit unbuffered voltage output
8 DACs. These DACs operate from 2.7V to 5.5V supply and are monotonic over
9 temperature.
10
11 Both the LTC2641 and LTC2642 feature a reference input range of 2V to VDD. VOUT
12 swings from 0V to VREF . For bipolar operation, the LTC2642 includes matched scaling
13 resistors for use with an external precision op amp (such as the LT1678), generating
14 a ±VREF output swing at RFB.
15
16 They communicate via SPI interface. 16 bits of data are loaded through DIN
17 after a high-to-low transition of CS (MSB first). After 16 data bits have
18 been loaded into the serial input register, a low-to-high transition on CS
19 transfers the data to the 16-bit DAC latch, updating the DAC output.
20
21 For the 14-bit DACs, (LTC2641-14/LTC2642-14), the MSB remains in the same
22 (left-justified) position in the input 16-bit data word. Therefore, two
23 “don’t-care” bits must be loaded after the LSB, to make up the required
24 16 data bits. Similarly, for the 12-bit family members(LTC2641-12/LTC2642-12)
25 four “don’t-care” bits must follow the LSB.
26
27 @endverbatim
28
29 http://www.linear.com/product/LTC2642
30 http://www.linear.com/product/LTC2641
31
32 http://www.linear.com/product/LTC2642#demoboards
33 http://www.linear.com/product/LTC2641#demoboards
34
35 Copyright 2018(c) Analog Devices, Inc.
36
37 All rights reserved.
38
39 Redistribution and use in source and binary forms, with or without
40 modification, are permitted provided that the following conditions are met:
41 - Redistributions of source code must retain the above copyright
42 notice, this list of conditions and the following disclaimer.
43 - Redistributions in binary form must reproduce the above copyright
44 notice, this list of conditions and the following disclaimer in
45 the documentation and/or other materials provided with the
46 distribution.
47 - Neither the name of Analog Devices, Inc. nor the names of its
48 contributors may be used to endorse or promote products derived
49 from this software without specific prior written permission.
50 - The use of this software may or may not infringe the patent rights
51 of one or more patent holders. This license does not release you
52 from the requirement that you obtain separate licenses from these
53 patent holders to use this software.
54 - Use of the software either in source or binary form, must be run
55 on or directly connected to an Analog Devices Inc. component.
56
57 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
58 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
59 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
60 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
61 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
62 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
63 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
64 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
65 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
66 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 */
68
69 //! @ingroup Digital_to_Analog_Converters
70 //! @{
71 //! @defgroup LTC2642 LTC2642: 16-/14-/12-Bit VOUT DAC with SPI Interface
72 //! @}
73
74 /*! @file
75 @ingroup LTC2642
76 Library for LTC2642 16-/14-/12-Bit VOUT DAC with SPI Interface
77 */
78
79 #include <SPI.h>
80 #include "LT_SPI.h"
81 #include "Linduino.h"
82 #include "LTC2642.h"
83
84 // Writes 16 bit data into serial input register
85 void LTC2642_write(uint8_t cs, uint16_t data)
86 {
87 uint16_t rx;
88 spi_transfer_word(cs, data, &rx);
89 }
90
91 // Calculates the 16 bit data code from voltage
92 uint16_t LTC2642_voltage_to_code(float voltage, float reference_voltage, uint8_t range)
93 {
94 uint16_t code;
95 if (range == UNIPOLAR)
96 {
97 code = voltage / reference_voltage * 0xFFFF ;
98 }
99 else
100 {
101 code = (voltage * 0x7FFF)/reference_voltage + 0x7FFF;
102 }
103 return code;
104 }
105
106 // Calculates the output voltage from the given digital code and reference voltage
107 float LTC2642_code_to_voltage(uint16_t code, float reference_voltage, uint8_t range)
108 {
109 float voltage;
110 if (range == UNIPOLAR)
111 {
112 voltage = code * reference_voltage / 0xFFFF ;
113 }
114 else
115 {
116 code = (int16_t)code;
117 voltage = (((float)code/0x7FFF) - 1) * reference_voltage;
118 }
119 return voltage;
120 }
Linduino.h
Header File for Linduino Libraries and Demo Code.
UNIPOLAR
#define UNIPOLAR
Definition: LTC2642.h:77
data
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
LTC2642_voltage_to_code
uint16_t LTC2642_voltage_to_code(float voltage, float reference_voltage, uint8_t range)
Calculates the 16 bit data code from voltage.
Definition: LTC2642.cpp:92
spi_transfer_word
void spi_transfer_word(uint8_t cs_pin, uint16_t tx, uint16_t *rx)
Reads and sends a word.
Definition: LT_SPI.cpp:98
range
static uint8_t range
Definition: DC1096B.ino:111
LT_SPI.h
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
LTC2642_code_to_voltage
float LTC2642_code_to_voltage(uint16_t code, float reference_voltage, uint8_t range)
Calculates the output voltage from the given digital code and reference voltage.
Definition: LTC2642.cpp:107
LTC2642.h
LTC2642: 16-/14-/12-Bit VOUT DAC with SPI Interface LTC2641: 16-/14-/12-Bit VOUT DAC with SPI Interfa...
reference_voltage
static float reference_voltage
The reference voltage range, set to 5v through JP2 and JP3 by default.
Definition: _24xx_iso_spi_delay.ino:72
voltage
static float voltage
Definition: DC2289AA.ino:71
LTC2642_write
void LTC2642_write(uint8_t cs, uint16_t data)
Writes the 16-bit data into the DAC.
Definition: LTC2642.cpp:85