Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LTC1592.cpp
Go to the documentation of this file.
1 /*!
2 LTC1592: 16-bit SoftSpan DAC with Programmable Output Range
3 
4 @verbatim
5 
6 The LTC1592 is a 16-bit serial input DAC that operates on a single 5V supply.
7 It can be software-programmed for either unipolar or bipolar mode. It can
8 also be programmed for different output voltage ranges - two output ranges in
9 unipolar mode and four output ranges in bipolar mode.
10 
11 The device includes an internal deglitcher circuit that reduces the glitch
12 impulse to less than 2nV-s (typ).
13 
14 When the CS/LD is brought to a logic low, the data on the SDI input is loaded
15 into the shift register on the rising edge of the clock. A 4-bit command word
16 (C3 C2 C1 C0), followed by four “don’t care” bits and 16 data bits(MSB-first)
17 is the minimum loading sequence required. When the CS/LD is brought to a logic
18 high, the clock is disabled internally and the command word is executed.
19 
20 SPI DIN FORMAT (MSB First):
21 
22 Byte #1 Byte #2 Byte #3
23 C3 C2 C1 C0 X X X X D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
24 
25 @endverbatim
26 
27 http://www.linear.com/product/LTC1592
28 
29 http://www.linear.com/product/LTC1592#demoboards
30 
31 Copyright 2018(c) Analog Devices, Inc.
32 
33 All rights reserved.
34 
35 Redistribution and use in source and binary forms, with or without
36 modification, are permitted provided that the following conditions are met:
37  - Redistributions of source code must retain the above copyright
38  notice, this list of conditions and the following disclaimer.
39  - Redistributions in binary form must reproduce the above copyright
40  notice, this list of conditions and the following disclaimer in
41  the documentation and/or other materials provided with the
42  distribution.
43  - Neither the name of Analog Devices, Inc. nor the names of its
44  contributors may be used to endorse or promote products derived
45  from this software without specific prior written permission.
46  - The use of this software may or may not infringe the patent rights
47  of one or more patent holders. This license does not release you
48  from the requirement that you obtain separate licenses from these
49  patent holders to use this software.
50  - Use of the software either in source or binary form, must be run
51  on or directly connected to an Analog Devices Inc. component.
52 
53 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
54 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
55 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
56 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
57 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
59 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
60 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
61 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 */
64 
65 //! @ingroup Digital_to_Analog_Converters
66 //! @{
67 //! @defgroup LTC1592 LTC1592: 16-bit SoftSpan DAC with Programmable Output Range
68 //! @}
69 
70 /*! @file
71  @ingroup LTC1592
72  Library for LTC1592: 16-bit SoftSpan DAC with Programmable Output Range
73 */
74 
75 #include "LT_SPI.h"
76 #include "Linduino.h"
77 #include <SPI.h>
78 
79 // Transmits 24 bit input stream: 4-bit command + 4-bit don't-care + 16-bit data
80 void LTC1592_write(uint8_t cs, uint8_t dac_command, uint16_t data)
81 {
82  output_low(cs);
83  delay(100);
84  spi_write(dac_command);
85  spi_write((uint8_t)(data >> 8)); //D15:D8
86  spi_write((uint8_t)data); //D7:D0
87  delay(100);
88  output_high(cs);
89 }
90 
91 // Calculates the voltage from ADC output data depending on the channel configuration
92 float LTC1592_code_to_voltage(uint16_t data, float RANGE_HIGH, float RANGE_LOW)
93 {
94  float voltage;
95  voltage = (RANGE_HIGH - RANGE_LOW) * data / 0xFFFF + RANGE_LOW;
96  return voltage;
97 }
98 
99 // Calculates the 16 bit data code from voltage
100 uint16_t LTC1592_voltage_to_code(float voltage, float RANGE_HIGH, float RANGE_LOW)
101 {
102  float code;
103  code = (voltage - RANGE_LOW) * (0xFFFF / (RANGE_HIGH - RANGE_LOW));
104  return code;
105 }
float LTC1592_code_to_voltage(uint16_t data, float RANGE_HIGH, float RANGE_LOW)
Calculates the voltage from ADC output data depending on the channel configuration.
Definition: LTC1592.cpp:92
#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
void LTC1592_write(uint8_t cs, uint8_t dac_command, uint16_t data)
Transmits 24 bit input stream: 4-bit command + 4-bit don&#39;t-care + 16-bit data.
Definition: LTC1592.cpp:80
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
#define output_low(pin)
Set "pin" low.
Definition: Linduino.h:72
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
static float voltage
Definition: DC2289AA.ino:71
uint16_t LTC1592_voltage_to_code(float voltage, float RANGE_HIGH, float RANGE_LOW)
Calculates the 16 bit data code from voltage.
Definition: LTC1592.cpp:100