| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LTM2893.cpp
Go to the documentation of this file.
1 /*!
2 LTM2893-1: 100MHz ADC SPI Isolator
3
4 @verbatim
5
6 @endverbatim
7
8 http://www.linear.com/product/LTM2893
9
10 http://www.linear.com/product/LTM2893#demoboards
11
12
13
14 Copyright 2018(c) Analog Devices, Inc.
15
16 All rights reserved.
17
18 Redistribution and use in source and binary forms, with or without
19 modification, are permitted provided that the following conditions are met:
20 - Redistributions of source code must retain the above copyright
21 notice, this list of conditions and the following disclaimer.
22 - Redistributions in binary form must reproduce the above copyright
23 notice, this list of conditions and the following disclaimer in
24 the documentation and/or other materials provided with the
25 distribution.
26 - Neither the name of Analog Devices, Inc. nor the names of its
27 contributors may be used to endorse or promote products derived
28 from this software without specific prior written permission.
29 - The use of this software may or may not infringe the patent rights
30 of one or more patent holders. This license does not release you
31 from the requirement that you obtain separate licenses from these
32 patent holders to use this software.
33 - Use of the software either in source or binary form, must be run
34 on or directly connected to an Analog Devices Inc. component.
35
36 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
37 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
38 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
39 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
40 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
42 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
43 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 */
47
48 //! @ingroup Analog_to_Digital_Converters
49 //! @{
50 //! @defgroup LTM2893 LTM2893: Isolator for 1Msps ADC
51 //! @}
52
53 /*! @file
54 @ingroup LTM2893
55 Library for LTM2893: Isolator for 16/18-Bit 1Msps ADC
56 */
57
58 #include <Arduino.h>
59 #include <stdint.h>
60 #include "Linduino.h"
61 #include "LT_SPI.h"
62 #include "LTM2893.h"
63 #include <SPI.h>
64
65
66 // Reads from a SPI LTM2893-XX device that has no configuration word and a 20 bit output word in 2's complement format.
67 void LTM2893_read(uint8_t cs, int32_t *ptr_adc_code)
68 {
69 LT_union_int16_2bytes command; // LTM2893 data and command
70 command.LT_uint16 = 0; // Set to zero, not necessary but avoids
71 // random data in scope shots.
72
73 //Form a four byte object to hold four bytes of data
74 LT_union_int32_4bytes data; //instantiate the union
75 data.LT_byte[3] = 0;
76 data.LT_byte[2] = 0;
77 data.LT_byte[1] = 0;
78 data.LT_byte[0] = 0;
79
80 spi_transfer_block(cs,command.LT_byte,data.LT_byte,3); // read 3 bytes 2893 is setup as 24 bits. overreading will cause a fault.
81
82 *ptr_adc_code = data.LT_int32;
83
84 return;
85 }
86
87 void LTM2893_config(uint8_t user_config)
88 {
89 uint8_t *rx_data;
90 spi_transfer_byte(LTM2893_CSC_PIN,user_config,rx_data);
91 }
92
93
94 // Calculates the voltage corresponding to an adc code in 2's complement, given the reference voltage (in volts)
95 /*
96 float LTM2893_code_to_voltage(int32_t adc_code, float vref)
97 {
98 float voltage;
99 if (adc_code >= pow(2,23)) {
100 voltage = (float)adc_code - pow(2,23);
101 voltage = voltage / (pow(2,22)-1); //! 2) This calculates the input as a fraction of the reference voltage (dimensionless)
102 voltage = voltage * -vref - (vref/pow(2,23)); //! 3) Multiply fraction by Vref to get the actual voltage at the input (in volts)
103 }
104 else {
105 voltage = (float)adc_code;
106 voltage = voltage / (pow(2,22)-1); //! 2) This calculates the input as a fraction of the reference voltage (dimensionless)
107 voltage = voltage * vref; //! 3) Multiply fraction by Vref to get the actual voltage at the input (in volts)
108 }
109 return(voltage);
110 }
111 */
112 float LTM2893_code_to_voltage(int32_t adc_code, float vref)
113 {
114 float voltage;
115 if (adc_code >= pow(2,23))
116 {
117 voltage = (float)adc_code - pow(2,24);
118 voltage = voltage / (pow(2,23)-1); //! 2) This calculates the input as a fraction of the reference voltage (dimensionless)
119 voltage = voltage * vref; //! 3) Multiply fraction by Vref to get the actual voltage at the input (in volts)
120 }
121 else
122 {
123 voltage = (float)adc_code;
124 voltage = voltage / (pow(2,23)-1); //! 2) This calculates the input as a fraction of the reference voltage (dimensionless)
125 voltage = voltage * vref; //! 3) Multiply fraction by Vref to get the actual voltage at the input (in volts)
126 }
127 return(voltage);
128 }
LT_union_int32_4bytes::LT_byte
uint8_t LT_byte[4]
4 bytes (unsigned 8-bit integers) to be converted to a 32-bit signed or unsigned integer ...
Definition: Linduino.h:112
Linduino.h
Header File for Linduino Libraries and Demo Code.
data
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
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_union_int32_4bytes::LT_int32
int32_t LT_int32
32-bit signed integer to be converted to four bytes
Definition: Linduino.h:110
LTM2893_CSC_PIN
#define LTM2893_CSC_PIN
Definition: LTM2893.h:72
LT_SPI.h
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
LT_union_int32_4bytes
This union splits one int32_t (32-bit signed integer) or uint32_t (32-bit unsigned integer) four uint...
Definition: Linduino.h:108
LTM2893_code_to_voltage
float LTM2893_code_to_voltage(int32_t adc_code, float vref)
Calculates the LTM2893 input voltage given the binary data and lsb weight.
Definition: LTM2893.cpp:112
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
LTM2893_config
void LTM2893_config(uint8_t user_config)
Definition: LTM2893.cpp:87
spi_transfer_byte
void spi_transfer_byte(uint8_t cs_pin, uint8_t tx, uint8_t *rx)
Reads and sends a byte.
Definition: LT_SPI.cpp:87
LTM2893_read
void LTM2893_read(uint8_t cs, int32_t *ptr_adc_code)
Reads the LTM2893 and returns 32-bit data in 2&#39;s complement format.
Definition: LTM2893.cpp:67
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
voltage
static float voltage
Definition: DC2289AA.ino:71
vref
float vref
Definition: LTC2492_Thermocouple_Meter.ino:129
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
LTM2893.h
LTM2893-1: 100MHz ADC SPI Isolator.
adc_code
static uint32_t adc_code
Definition: DC2071AA.ino:113