Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LTC2752.cpp
Go to the documentation of this file.
1 /*!
2 LTC2752: Dual Serial 16-Bit SoftSpan IOUT DAC
3 
4 @verbatim
5 
6 The LTC2752 is a dual, current-output, serial-input precision multiplying DAC
7 with selectable output ranges. Ranges can either be programmed in software for
8 maximum flexibility (each of the DACs can be programmed to any one of six output
9 ranges) or hardwired through pin-strapping. Two unipolar ranges are available
10 (0V to 5V and 0V to 10V), and four bipolar ranges (±2.5V, ±5V, ±10V and –2.5V
11 to 7.5V). These ranges are obtained when an external precision 5V reference is
12 used. The output ranges for other reference voltages are easy to calculate by
13 observing that each range is a multiple of the external reference voltage. The
14 ranges can then be expressed: 0 to 1×, 0 to 2×, ±0.5×, ±1×, ±2×, and –0.5× to 1.5×.
15 
16 @endverbatim
17 
18 http://www.linear.com/product/LTC2752
19 
20 http://www.linear.com/product/LTC2752#demoboards
21 
22 
23 Copyright 2018(c) Analog Devices, Inc.
24 
25 All rights reserved.
26 
27 Redistribution and use in source and binary forms, with or without
28 modification, are permitted provided that the following conditions are met:
29  - Redistributions of source code must retain the above copyright
30  notice, this list of conditions and the following disclaimer.
31  - Redistributions in binary form must reproduce the above copyright
32  notice, this list of conditions and the following disclaimer in
33  the documentation and/or other materials provided with the
34  distribution.
35  - Neither the name of Analog Devices, Inc. nor the names of its
36  contributors may be used to endorse or promote products derived
37  from this software without specific prior written permission.
38  - The use of this software may or may not infringe the patent rights
39  of one or more patent holders. This license does not release you
40  from the requirement that you obtain separate licenses from these
41  patent holders to use this software.
42  - Use of the software either in source or binary form, must be run
43  on or directly connected to an Analog Devices Inc. component.
44 
45 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
46 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
47 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
48 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
49 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
50 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
51 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
52 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
53 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
54 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 */
56 
57 //! @ingroup Digital_to_Analog_Converters
58 //! @{
59 //! @defgroup LTC2752 LTC2752: Dual Serial 16-Bit SoftSpan IOUT DAC
60 //! @}
61 
62 /*! @file
63  @ingroup LTC2752
64  Library for LTC2752 Dual Serial 16-Bit SoftSpan IOUT DAC
65 */
66 
67 #include <Arduino.h>
68 #include <stdint.h>
69 #include "LT_SPI.h"
70 #include "UserInterface.h"
71 #include "LT_I2C.h"
72 #include "QuikEval_EEPROM.h"
73 #include "Linduino.h"
74 #include <SPI.h>
75 
76 // Transmits 24 bit input stream: 4-bit command + 4-bit don't-care + 16-bit data
77 void LTC2752_write(uint8_t cs, uint8_t dac_command, uint8_t dac_address, uint16_t data)
78 {
79  output_low(cs);
80  spi_write(dac_command|dac_address);
81  spi_write((uint8_t)((data >> 8) & 0xFF)); // D15:D8
82  spi_write((uint8_t)(data & 0xFF)); // D7:D0
83  output_high(cs);
84 }
85 // Calculate the LTC2752 DAC output voltage given the DAC code and and the minimum / maximum
86 // outputs for a given softspan range.
87 float LTC2752_code_to_voltage(uint16_t dac_code, float min_output, float max_output)
88 {
89  float dac_voltage;
90  dac_voltage = (((float) dac_code / 65535.0) * (max_output - min_output)) + min_output; // Calculate the dac_voltage
91  return (dac_voltage);
92 }
93 
94 // Calculate a LTC2752 DAC code given the desired output voltage and the minimum / maximum
95 // outputs for a given softspan range.
96 uint16_t LTC2752_voltage_to_code(float dac_voltage, float min_output, float max_output)
97 {
98  uint16_t dac_code;
99  float float_code;
100  float_code = 65535.0 * (dac_voltage - min_output) / (max_output - min_output); // Calculate the DAC code
101  float_code = (float_code > (floor(float_code) + 0.5)) ? ceil(float_code) : floor(float_code); // Round
102  if (float_code < 0.0) float_code = 0.0;
103  if (float_code > 65535.0) float_code = 65535.0;
104  dac_code = (uint32_t) (float_code); // Convert to unsigned integer
105  return (dac_code);
106 }
#define output_high(pin)
Set "pin" high.
Definition: Linduino.h:75
Header File for Linduino Libraries and Demo Code.
void spi_write(int8_t data)
Write a data byte using the SPI hardware.
Definition: LT_SPI.cpp:176
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
void LTC2752_write(uint8_t cs, uint8_t dac_command, uint8_t dac_address, uint16_t data)
Transmits 24 bit input stream: 4-bit command + 4-bit don&#39;t-care + 16-bit data.
Definition: LTC2752.cpp:77
uint16_t LTC2752_voltage_to_code(float dac_voltage, float min_output, float max_output)
Calculate a LTC2752 DAC code given the desired output voltage and the minimum / maximum outputs for a...
Definition: LTC2752.cpp:96
#define output_low(pin)
Set "pin" low.
Definition: Linduino.h:72
QuikEval EEPROM Library.
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
float LTC2752_code_to_voltage(uint16_t dac_code, float min_output, float max_output)
Calculate the LTC2752 DAC output voltage given the DAC code and and the minimum / maximum outputs for...
Definition: LTC2752.cpp:87