LTC2990 - Quad I2C Voltage, Current and Temperature Monitor

Features

  • Measures Voltage, Current and Temperature
  • Measures Two Remote Diode Temperatures
  • ±0.5°C Accuracy, 0.06°C Resolution (Typ)
  • ±1°C Internal Temperature Sensor (Typ)
  • 14-Bit ADC Measures Voltage/Current
  • 3V to 5.5V Supply Operating Voltage
  • Four Selectable Addresses
  • Internal 10ppm/°C Voltage Reference
  • 10-Lead MSOP Package

Typical Application

LTC2990 Typical Application
LTC2990 Typical Application

Description

The LTC®2990 is used to monitor system temperatures, voltages and currents. Through the I2C serial interface, the device can be configured to measure many combinations of internal temperature, remote temperature, remote voltage, remote current and internal VCC. The internal 10ppm/°C reference minimizes the number of supporting components and area required. Selectable address and configurable functionality give the LTC2990 flexibility to be incorporated in various systems needing temperature, voltage or current data. The LTC2990 fits well in systems needing sub-millivolt voltage resolution, 1% current measurement and 1°C temperature accuracy or any combination of the three.

Packaging

For complete and up to date package information and drawings, please refer to our packaging page

MS-10

LTC2990 Package Drawing

Order Info

Package Variations and Pricing

Part Number Package Pins Temp Price (1-99) Price (1k)* RoHS Data
LTC2990CMS#PBF MSOP 10 C $3.21 $2.25 View
LTC2990CMS#TRPBF MSOP 10 C $2.31 View
LTC2990IMS MSOP 10 I $3.70 $2.59 View
LTC2990IMS#PBF MSOP 10 I $3.70 $2.59 View
LTC2990IMS#TRPBF MSOP 10 I $2.65 View
Buy NowRequest Samples
* The USA list pricing shown is for BUDGETARY USE ONLY, shown in United States dollars (FOB USA per unit for the stated volume), and is subject to change. International prices may differ due to local duties, taxes, fees and exchange rates. For volume-specific price or delivery quotes, please contact your local Linear Technology sales office or authorized distributor.

Demo Boards

Linear Technology offers many demo boards free of charge to qualified customers. Contact your local sales office or distributor to inquire about a demo board. Certain demo boards are also available for sale via credit card on this website. Demo boards are for evaluation purposes only. It remains the customer’s responsibility to verify proper and reliable operation in the actual end application.

Part Number Description Price Documentation
DC1338B LTC2990 Demo Board | I2C Temperature, Current & Voltage Monitor (requires DC2026) . $50.00
Buy Now

Companion Boards

Part Number Description Price Documentation
DC2026A Linduino One Isolated Arduino-Compatible Demonstration Board $75.00
Buy Now
Click here to view our complete list of demo boards

Applications

  • Temperature Measurement
  • Supply Voltage Monitoring
  • Current Measurement
  • Remote Data Acquisition
  • Environmental Monitoring

Product Notifications

Please login to your MyLinear account for notifications of datasheet updates, new document releases and LTspice model announcements for your favorite products. If you do not have a MyLinear account you may Sign Up Now.

Forgot your password? Click here.
Need help? Email mylinear@linear.com with questions and comments.

Design Tools

Linduino

Linduino is an Arduino compatible platform for developing and distributing firmware libraries and code for SPI and I²C-compatible integrated circuits. The Linduino One board interfaces to more than 300 QuikEval demonstration cards, supporting a variety of product types including analog-to-digital converters (ADCs)digital-to-analog converters (DACs)power monitors, and more. Firmware libraries for individual devices are written in C and designed to be portable to a wide variety of processors and microcontrollers. Each library has a demonstration program that can be uploaded to the Linduino One platform to allow the circuit and software to be quickly and easily verified.

Click here for more information on Linduino

Code

Linduino is Linear Technology's Arduino compatible system for developing and distributing firmware libraries and example code for Linear Technology’s integrated circuits. The code below can be downloaded or copied and pasted into your project. Please visit the Linduino Home Page for demo board, manual and setup information.

This part is Code Supported: There is example code available for this part. The code below may rely on other drivers available in the full library.

Download LTC2990 - DC1338 Linduino.INO File

/*!
Linear Technology DC1338 Demonstration Board.
LTC2990: 14-bit ADC Quad I2C Voltage, Current, and Temperature monitor.

@verbatim

 Setup:
    Set the terminal baud rate to 115200 and select the newline terminator.
    A precision voltage source (preferably low-noise) may be used to apply a voltage
    to input terminals V1-V8. A precision voltmeter may be used to verify applied
    voltages. An oscilloscope may be used to view the PWM output. Ensure JP5, JP6
    and JP7 are in the LOW position. Refer to Demo Manual DC1338A

  Explanation of Commands:

    1 - Single-Ended Voltage - Selects the Single-Ended Voltage Menu.
             1-4: Displays the measured single-ended voltage at one of the V1-V4
                  inputs. When measuring V1 and V8, ensure jumpers are set to VOLT
                  position.
               5: Vcc - Displays the measured Vcc voltage.
              6: ALL - Displays the measured voltages at all of the V1-V8 inputs
                  and Vcc.

    2 - Differential Voltage - Selects the Differential Voltage Menu.
        Maximum full scale differential voltage is 0.300V.

             1-2: Displays the measured differential voltage across one of the V1-V4
                  input pairs. The input common-mode range is 0V to Vcc.  It is
                  easiest to ground the lower input. When measuring V1 and V4,
                  ensure jumpers are set to VOLT position.
               3: ALL - Displays the measured differential voltages at all terminals.

    3 - Temperature - Selects the Temperature Menu
        To measure temperature using on-board transistors, set JP1, JP2, JP3 and JP4
        to TEMP position.
               1: V1-V2 - Measure temperature of Q1 (mounted to demo board) when JP1
                  and JP2 are in TEMP position.
               2: V3-V4 - Measure temperature of external transistor connected to V3
                  and V4 terminals.
               3: Internal - Measure temperature using the internal temperature
                  sensor.
               4: All - Displays temperatures at all connections as well as the
                  internal temperature sensor.

    4 - Settings - Selects the Settings Menu
        Toggles temperature units between degrees Celsius or degrees Kelvin.
               1: Toggle temperature units between degrees Celsius and degrees
                  Kelvin.

USER INPUT DATA FORMAT:
 decimal : 1024
 hex     : 0x400
 octal   : 02000  (leading 0 "zero")
 binary  : B10000000000
 float   : 1024.0

@endverbatim

http://www.linear.com/product/LTC2990

http://www.linear.com/product/LTC2990#demoboards

REVISION HISTORY
$Revision: 2033 $
$Date: 2013-10-15 13:21:18 -0700 (Tue, 15 Oct 2013) $

Copyright (c) 2014, Linear Technology Corp.(LTC)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of Linear Technology Corp.

The Linear Technology Linduino is not affiliated with the official Arduino team.
However, the Linduino is only possible because of the Arduino team's commitment
to the open-source community.  Please, visit http://www.arduino.cc and
http://store.arduino.cc , and consider a purchase that will help fund their
ongoing work.
*/

/*! @file
    @ingroup LTC2990
*/

#include 
#include 
#include "Linduino.h"
#include "UserInterface.h"
#include "LT_I2C.h"
#include "QuikEval_EEPROM.h"
#include "LTC2990.h"
#include 
#include 

// Function Declaration
void print_title();                     // Print the title block
void print_prompt();                    // Prompt the user for an input command

int8_t menu_1_single_ended_voltage();   // Sub-menu functions
int8_t menu_2_read_differential_voltage();
int8_t menu_3_read_temperature();
int8_t menu_4_settings();

// Global variables
static uint8_t demo_board_connected;    //!< Set to 1 if the board is connected
const uint16_t LTC2990_TIMEOUT=1000;    //!< Configures the maximum timeout allowed for an LTC2990 read.

// Calibration Variables
const float LTC2990_SINGLE_ENDED_lsb = 3.05176E-04;     //!< Typical single-ended LSB weight in volts
const float LTC2990_DIFFERENTIAL_lsb = 1.90735E-05;     //!< Typical differential LSB weight in volts
const float LTC2990_VCC_lsb = 3.05176E-04;              //!< Typical VCC LSB weight in volts
// Used for internal temperature as well as remote diode temperature measurements.
const float LTC2990_TEMPERATURE_lsb = 0.0625;           //!< Typical temperature LSB weight in degrees Celsius (and Kelvin).
// Used to readback diode voltage when in temperature measurement mode.
const float LTC2990_DIODE_VOLTAGE_lsb = 3.815E-05;      //!< Typical remote diode LSB weight in volts.

//! Initialize Linduino
void setup()
{
  char demo_name[] = "DC1338";  // Demo Board Name stored in QuikEval EEPROM
  int8_t ack=0;
  quikeval_I2C_init();          // Initializes Linduino I2C port.
  quikeval_I2C_connect();       // Connects I2C port to the QuikEval connector
  Serial.begin(115200);         // Initialize the serial port to the PC
  print_title();
  demo_board_connected = discover_demo_board(demo_name);  // Checks if correct demo board is connected.
  if (demo_board_connected)
  {
    print_prompt();
    ack |= LTC2990_register_write(LTC2990_I2C_ADDRESS, LTC2990_CONTROL_REG, LTC2990_ENABLE_ALL);   // Enables all channels
    ack |= LTC2990_register_write(LTC2990_I2C_ADDRESS, LTC2990_TRIGGER_REG, 0x01);
  }
}

//! Repeats Linduino loop
void loop()
{
  int8_t ack=0;

  uint8_t user_command;
  if (demo_board_connected)           // Does nothing if the demo board is not connected
  {
    if (Serial.available())           // Checks for user input
    {
      user_command = read_int();      // Reads the user command
      if (user_command != 'm')
        Serial.println(user_command);
      ack = 0;
      switch (user_command)           // Prints the appropriate submenu
      {
        case 1:
          ack |= menu_1_single_ended_voltage();       // Print single-ended voltage menu
          break;
        case 2:
          ack |= menu_2_read_differential_voltage();  // Differential voltage menu
          break;
        case 3:
          ack |= menu_3_read_temperature();           // Temperature menu
          break;
        case 4:
          ack |= menu_4_settings();                   // Settings menu
          break;
        default:
          Serial.println("Incorrect Option");
          break;
      }
      if (ack != 0)
      {
        Serial.print(F("Error: No Acknowledge. Check I2C Address.\n"));
      }
      print_prompt();
    }
  }
}

// Function Definitions

//! Prints the title block when program first starts.
void print_title()
{
  Serial.print(F("\n*****************************************************************\n"));
  Serial.print(F("* DC1338B Demonstration Program                                 *\n"));
  Serial.print(F("*                                                               *\n"));
  Serial.print(F("* This program demonstrates how to send and receive data from   *\n"));
  Serial.print(F("* the LTC2990 14-Bit Quad I2C Voltage, Current, and            *\n"));
  Serial.print(F("* Temperature Monitor.                                          *\n"));
  Serial.print(F("*                                                               *\n"));
  Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
  Serial.print(F("*                                                               *\n"));
  Serial.print(F("*****************************************************************\n"));
}

//! Prints main menu.
void print_prompt()
{
  Serial.print(F("\n  1-Single-Ended Voltage\n"));
  Serial.print(F("  2-Differential Voltage\n"));
  Serial.print(F("  3-Temperature\n"));
  Serial.print(F("  4-Settings\n"));
  Serial.print(F("Enter a command:"));
}

//! Read single-ended voltages
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
int8_t menu_1_single_ended_voltage()
{
  int8_t ack=0;
  uint8_t user_command;
  do
  {
    // Displays the single-ended voltage menu
    Serial.print(F("\nSingle-Ended Voltage\n\n"));
    Serial.print(F("  1-V1\n"));
    Serial.print(F("  2-V2\n"));
    Serial.print(F("  3-V3\n"));
    Serial.print(F("  4-V4\n"));
    Serial.print(F("  5-Vcc\n"));
    Serial.print(F("  6-ALL\n"));
    Serial.print(F("  m-Main Menu\n"));
    Serial.print(F("\n\nEnter a command: "));

    user_command = read_int();                              // Reads the user command
    if (user_command == 'm')                                // Print m if it is entered
    {
      Serial.print(F("m\n"));
    }
    else
      Serial.println(user_command);                         // Print user command

    int16_t code;
    int8_t data_valid;
    float voltage;

    // Enable Single-Ended Mode
    ack |= LTC2990_register_set_clear_bits(LTC2990_I2C_ADDRESS, LTC2990_CONTROL_REG, LTC2990_V1_V2_V3_V4, LTC2990_VOLTAGE_MODE_MASK);


    // Reads single-ended voltage from ADC and prints it.
    switch (user_command)
    {
      case 1:
        // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
        ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V1_MSB_REG, &code, &data_valid, LTC2990_TIMEOUT);
        voltage = LTC2990_code_to_single_ended_voltage(code, LTC2990_SINGLE_ENDED_lsb);
        Serial.print(F("\n  V1: "));
        Serial.print(voltage, 4);
        Serial.print(F(" V\n"));
        break;
      case 2:
        // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
        ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V2_MSB_REG, &code, &data_valid, LTC2990_TIMEOUT);
        voltage = LTC2990_code_to_single_ended_voltage(code, LTC2990_SINGLE_ENDED_lsb);
        Serial.print(F("\n  V2: "));
        Serial.print(voltage, 4);
        Serial.print(F(" V\n"));
        break;
      case 3:
        // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
        ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V3_MSB_REG, &code, &data_valid, LTC2990_TIMEOUT);
        voltage = LTC2990_code_to_single_ended_voltage(code, LTC2990_SINGLE_ENDED_lsb);
        Serial.print(F("\n  V3: "));
        Serial.print(voltage, 4);
        Serial.print(F(" V\n"));
        break;
      case 4:
        // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
        ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V4_MSB_REG, &code, &data_valid, LTC2990_TIMEOUT);
        voltage = LTC2990_code_to_single_ended_voltage(code, LTC2990_SINGLE_ENDED_lsb);
        Serial.print(F("\n  V4: "));
        Serial.print(voltage, 4);
        Serial.print(F(" V\n"));
        break;
      case 5:
        // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
        ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_VCC_MSB_REG, &code, &data_valid, LTC2990_TIMEOUT);
        voltage = LTC2990_code_to_vcc_voltage(code, LTC2990_SINGLE_ENDED_lsb);
        Serial.print(F("\n  Vcc: "));
        Serial.print(voltage, 4);
        Serial.print(F(" V\n"));
        break;
      case 6:
        // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
        ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V1_MSB_REG, &code, &data_valid, LTC2990_TIMEOUT);
        voltage = LTC2990_code_to_single_ended_voltage(code, LTC2990_SINGLE_ENDED_lsb);
        Serial.print(F("\n  V1: "));
        Serial.print(voltage, 4);
        Serial.print(F(" V\n"));
        if (ack)
          break;
        // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
        ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V2_MSB_REG, &code, &data_valid, LTC2990_TIMEOUT);
        voltage = LTC2990_code_to_single_ended_voltage(code, LTC2990_SINGLE_ENDED_lsb);
        Serial.print(F("  V2: "));
        Serial.print(voltage, 4);
        Serial.print(F(" V\n"));
        if (ack)
          break;
        // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
        ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V3_MSB_REG, &code, &data_valid, LTC2990_TIMEOUT);
        voltage = LTC2990_code_to_single_ended_voltage(code, LTC2990_SINGLE_ENDED_lsb);
        Serial.print(F("  V3: "));
        Serial.print(voltage, 4);
        Serial.print(F(" V\n"));
        if (ack)
          break;
        // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
        ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V4_MSB_REG, &code, &data_valid, LTC2990_TIMEOUT);
        voltage = LTC2990_code_to_single_ended_voltage(code, LTC2990_SINGLE_ENDED_lsb);
        Serial.print(F("  V4: "));
        Serial.print(voltage, 4);
        Serial.print(F(" V\n"));
        if (ack)
          break;
        // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
        ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_VCC_MSB_REG, &code, &data_valid, LTC2990_TIMEOUT);
        voltage = LTC2990_code_to_vcc_voltage(code, LTC2990_SINGLE_ENDED_lsb);
        Serial.print(F("  Vcc: "));
        Serial.print(voltage, 4);
        Serial.print(F(" V\n"));
        break;
      default:
        if (user_command != 'm')
          Serial.println(" Incorrect Option");
        break;
    }
  }
  while ((user_command != 'm') && (ack != 1));
  return(ack);
}

//! Read differential voltages.
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
int8_t menu_2_read_differential_voltage()
{
  int8_t ack=0;
  uint8_t user_command;
  do
  {
    // Display differential voltage menu.
    Serial.print(F("\nDifferential Voltage\n\n"));
    Serial.print(F("  1-V1-V2\n"));
    Serial.print(F("  2-V3-V4\n"));
    Serial.print(F("  3-ALL\n"));
    Serial.print(F("  m-Main Menu\n"));
    Serial.print(F("\n\nEnter a command: "));

    user_command = read_int();                              // Reads the user command
    if (user_command == 'm')                                // Print m if it is entered
    {
      Serial.print(F("m\n"));
    }
    else
      Serial.println(user_command);                       // Print user command

    int8_t data_valid;
    int16_t code;
    float voltage;

    
    // Enables differential mode.
    ack |= LTC2990_register_set_clear_bits(LTC2990_I2C_ADDRESS, LTC2990_CONTROL_REG, LTC2990_V1V2_V3V4, LTC2990_VOLTAGE_MODE_MASK);
    // Triggers a conversion by writing any value to the trigger register
    ack |= LTC2990_register_write(LTC2990_I2C_ADDRESS, LTC2990_TRIGGER_REG, 0x00);
    
    // Flushes one reading following mode change.
    // Reads differential voltage from ADC and prints it.
    switch (user_command)
    {
      case 1:
        // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
        ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V2_MSB_REG, &code, &data_valid, LTC2990_TIMEOUT);
        voltage = LTC2990_code_to_differential_voltage(code, LTC2990_DIFFERENTIAL_lsb);
        Serial.print(F("\n  V1-V2: "));
        Serial.print(voltage, 4);
        Serial.print(F(" V\n"));
        break;
      case 2:
        // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
        ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V4_MSB_REG, &code, &data_valid, LTC2990_TIMEOUT);
        voltage = LTC2990_code_to_differential_voltage(code, LTC2990_DIFFERENTIAL_lsb);
        Serial.print(F("\n  V3-V4: "));
        Serial.print(voltage, 4);
        Serial.print(F(" V\n"));
        break;
      case 3:
        // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
        ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V2_MSB_REG, &code, &data_valid, LTC2990_TIMEOUT);
        voltage = LTC2990_code_to_differential_voltage(code, LTC2990_DIFFERENTIAL_lsb);
        Serial.print(F("\n  V1-V2: "));
        Serial.print(voltage, 4);
        Serial.print(F(" V\n"));
        if (ack)
          break;
        // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
        ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V4_MSB_REG, &code, &data_valid, LTC2990_TIMEOUT);
        voltage = LTC2990_code_to_differential_voltage(code, LTC2990_DIFFERENTIAL_lsb);
        Serial.print(F("  V3-V4: "));
        Serial.print(voltage, 4);
        Serial.print(F(" V\n"));
        break;
      default:
        if (user_command != 'm')
        {
          Serial.print(F("Incorrect Option\n"));
        }
        break;
    }
  }
  while ((user_command != 'm') && (ack != 1));
  return(ack);
}

//! Read temperatures
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
int8_t menu_3_read_temperature()
{
  int8_t ack=0;
  boolean isKelvin = false;     // Keeps track of the unit of measurement
  uint8_t user_command;
  do
  {
    // Displays temperature menu
    Serial.print(F("\nTemperature\n\n"));
    Serial.print(F("  1-V1-V2\n"));
    Serial.print(F("  2-V3-V4\n"));
    Serial.print(F("  3-Internal\n"));
    Serial.print(F("  4-ALL\n"));
    Serial.print(F("  m-Main Menu\n"));
    Serial.print(F("\n\nEnter a command: "));
    user_command = read_int();                                  // Reads the user command
    if (user_command == 'm')                                    // Print m if it is entered
    {
      Serial.print(F("m\n"));
    }
    else
      Serial.println(user_command);                             // Print user command

    // Read Temperature
    int8_t data_valid = 0;
    int16_t adc_code;
    uint8_t reg_data;
    float temperature;
    
    // Enables temperature mode
    ack |= LTC2990_register_set_clear_bits(LTC2990_I2C_ADDRESS, LTC2990_CONTROL_REG, LTC2990_TR1_TR2, LTC2990_VOLTAGE_MODE_MASK);
    // Triggers a conversion by writing any value to the trigger register
    ack |= LTC2990_register_write(LTC2990_I2C_ADDRESS, LTC2990_TRIGGER_REG, 0x01);
    // Flushes one reading following mode change.
    ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V1_MSB_REG, &adc_code, &data_valid, LTC2990_TIMEOUT);
    //ack |= LTC2990_register_write(LTC2990_I2C_ADDRESS, LTC2990_TRIGGER_REG, 0x01);
    //delay(165); //Wait max conversion time
    
    // Reads temperature from ADC and prints it.
    switch (user_command)
    {
      case 1:
        // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
        ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V1_MSB_REG, &adc_code, &data_valid, LTC2990_TIMEOUT);
        ack |= LTC2990_register_read(LTC2990_I2C_ADDRESS, LTC2990_CONTROL_REG, ®_data);
        if (reg_data & LTC2990_KELVIN_ENABLE) isKelvin= true;
        else isKelvin=false;   
        temperature = LTC2990_temperature(adc_code, LTC2990_TEMPERATURE_lsb, isKelvin);
        Serial.print(F("\n  V1-V2: "));
        Serial.print(temperature, 2);  
        if (isKelvin) Serial.print(F(" K\n"));
        else Serial.print(F(" C\n"));
        break;
      case 2:
        // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
        ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V3_MSB_REG, &adc_code, &data_valid, LTC2990_TIMEOUT);
        ack |= LTC2990_register_read(LTC2990_I2C_ADDRESS, LTC2990_CONTROL_REG, ®_data);
        if (reg_data & LTC2990_KELVIN_ENABLE) isKelvin=true;
        else isKelvin = false;
        temperature = LTC2990_temperature(adc_code, LTC2990_TEMPERATURE_lsb, isKelvin);
        Serial.print(F("\n  V3-V4: "));
        Serial.print(temperature, 2);
        if (isKelvin) Serial.print(F(" K\n"));
        else Serial.print(F(" C\n"));
        break;
      case 3:
        // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
        ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_TINT_MSB_REG, &adc_code, &data_valid, LTC2990_TIMEOUT);
        ack |= LTC2990_register_read(LTC2990_I2C_ADDRESS, LTC2990_CONTROL_REG, ®_data);
        if (reg_data & LTC2990_KELVIN_ENABLE) isKelvin=true;
        else isKelvin=false;
        temperature = LTC2990_temperature(adc_code, LTC2990_TEMPERATURE_lsb,isKelvin);
        Serial.print(F("\n  Internal: "));
        Serial.print(temperature, 2);
        if (isKelvin) Serial.print(F(" K\n"));
        else Serial.print(F(" C\n"));
        break;
      case 4:
        // All Temperatures
        // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
        ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V1_MSB_REG, &adc_code, &data_valid, LTC2990_TIMEOUT);
        ack |= LTC2990_register_read(LTC2990_I2C_ADDRESS, LTC2990_CONTROL_REG, ®_data);
        if (reg_data & LTC2990_KELVIN_ENABLE) isKelvin= true;
        else isKelvin=false;   
        temperature = LTC2990_temperature(adc_code, LTC2990_TEMPERATURE_lsb, isKelvin);
        Serial.print(F("\n  V1-V2: "));
        Serial.print(temperature, 2);  
        if (isKelvin) Serial.print(F(" K\n"));
        else Serial.print(F(" C\n"));
        if (ack)
          break;
                
        // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
        ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V3_MSB_REG, &adc_code, &data_valid, LTC2990_TIMEOUT);
        ack |= LTC2990_register_read(LTC2990_I2C_ADDRESS, LTC2990_CONTROL_REG, ®_data);
        if (reg_data & LTC2990_KELVIN_ENABLE) isKelvin=true;
        else isKelvin = false;
        temperature = LTC2990_temperature(adc_code, LTC2990_TEMPERATURE_lsb, isKelvin);
        Serial.print(F("\n  V3-V4: "));
        Serial.print(temperature, 2);
        if (isKelvin) Serial.print(F(" K\n"));
        else Serial.print(F(" C\n"));
        if (ack)
          break;
                
        // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
        ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_TINT_MSB_REG, &adc_code, &data_valid, LTC2990_TIMEOUT);
        ack |= LTC2990_register_read(LTC2990_I2C_ADDRESS, LTC2990_CONTROL_REG, ®_data);
        if (reg_data & LTC2990_KELVIN_ENABLE) isKelvin=true;
        else isKelvin=false;
        temperature = LTC2990_temperature(adc_code, LTC2990_TEMPERATURE_lsb,isKelvin);
        Serial.print(F("\n  Internal: "));
        Serial.print(temperature, 2);
        if (isKelvin) Serial.print(F(" K\n"));
        else Serial.print(F(" C\n"));
        break;
      default:
        if (user_command != 'm')
          Serial.println("Incorrect Option");
        break;
    }
  }
  while ((user_command != 'm') && (ack == 0));
  return(ack);
}

//! Configure settings
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
int8_t menu_4_settings()
{
  uint8_t user_command;
  int8_t ack=0;
  uint8_t reg_data;

  Serial.println(F("\nSettings:"));
  Serial.println(F("0-Celsius"));
  Serial.println(F("1-Kelvin"));
  Serial.print(F("\nEnter a command: "));
  user_command = read_int();
  Serial.println(user_command);
  
  if(user_command)
  {
    // Set to Kelvin mode
    ack |= LTC2990_register_set_clear_bits(LTC2990_I2C_ADDRESS, LTC2990_CONTROL_REG, LTC2990_KELVIN_ENABLE, LTC2990_TEMP_FORMAT_MASK);
    Serial.println(F("The LTC2990 is in Kelvin Mode"));
  }
  else
  {
    // Set to Celsius mode
    ack |= LTC2990_register_set_clear_bits(LTC2990_I2C_ADDRESS, LTC2990_CONTROL_REG, LTC2990_CELSIUS_ENABLE, LTC2990_TEMP_FORMAT_MASK);
    Serial.println(F("The LTC2990 is in Celsius Mode"));
  }
  return(ack);
}

Download LTC2990 - Linduino Header File

/*!
LTC2990: 14-bit ADC Quad I2C voltage, current, and temperature monitor.

@verbatim

The LTC2990 is used to monitor system temperatures, voltages and currents. 
Through the I2C serial interface, the four monitors can individually measure 
supply voltages and can be paired for differential measurements of current sense 
resistors or temperature sensing transistors. Additional measurements include 
internal temperature and internal VCC. The internal 10ppm reference minimizes 
the number of supporting components and area required. Selectable address and 
configurable functionality give the LTC2990 flexibility to be incorporated in 
various systems needing temperature, voltage or current data. The LTC2990 fits 
well in systems needing sub-millivolt voltage resolution, 1% current measurement 
and 1 degree Celsius temperature accuracy or any combination of the three. 

I2C DATA FORMAT (MSB FIRST);

Data Out:
Byte #1                                     Byte #2                    Byte #3

START  SA6 SA5 SA4 SA3 SA2 SA1 SA0 W SACK   X X X X C3 C2 C1 C0 SACK   D7 D6 D5 D4 D3 D2 D1 D0 SACK STOP

Data In:
Byte #1                                     Byte #2                                  Byte #3

START  SA6 SA5 SA4 SA3 SA2 SA1 SA0 W SACK   X X X X C3 C2 C1 C0 SACK   REPEAT START  SA6 SA5 SA4 SA3 SA2 SA1 SA0 R SACK

Byte #4                              Byte #5
MSB                                  LSB
D15 D14 D13 D12 D11 D10 D9 D8 MACK   D7 D6 D5 D4 D3 D2 D1 D0 MNACK STOP

START        : I2C Start
REPEAT Start : I2C Repeat Start
STOP         : I2C Stop
SACK         : I2C Slave Generated Acknowledge (Active Low)
MACK         : I2C Master Generated Acknowledge (Active Low)
MNACK        : I2C Master Generated Not Acknowledge
SAx  : I2C Address
W    : I2C Write (0)
R    : I2C Read  (1)
Cx   : Command Code
Dx   : Data Bits
X    : Don't care


Example Code:

Read single-ended voltage from V1.
    
    // Enable Single-Ended Mode
    ack |= LTC2990_register_set_clear_bits(LTC2990_I2C_ADDRESS, LTC2990_CONTROL_REG, LTC2990_V1_V2_V3_V4, LTC2990_VOLTAGE_MODE_MASK);
    
    // Triggers a conversion by writing any value to the trigger register
    ack |= LTC2990_register_write(LTC2990_I2C_ADDRESS, LTC2990_TRIGGER_REG, 0x00);
    
    // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
    ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V1_MSB_REG, &code, &data_valid, LTC2990_TIMEOUT);
    
    voltage = LTC2990_code_to_single_ended_voltage(code, LTC2990_SINGLE_ENDED_lsb);
     
Read current from V3-V4.

    resistor = 1; // R_sense across V3-V4 in ohms
    
    // Enables differential mode.
    ack |= LTC2990_register_set_clear_bits(LTC2990_I2C_ADDRESS, LTC2990_CONTROL_REG, LTC2990_V1V2_V3V4, LTC2990_VOLTAGE_MODE_MASK);
    
    // Triggers a conversion by writing any value to the trigger register
    ack |= LTC2990_register_write(LTC2990_I2C_ADDRESS, LTC2990_TRIGGER_REG, 0x00);
    
    // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
    ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V2_MSB_REG, &code, &data_valid, LTC2990_TIMEOUT);
    
    voltage = LTC2990_code_to_differential_voltage(code, LTC2990_DIFFERENTIAL_lsb);
    
    current = voltage / resistor; // Calculates current

Read temperature from diode connected to V1-V2.

    // Enables temperature mode
    ack |= LTC2990_register_set_clear_bits(LTC2990_I2C_ADDRESS, LTC2990_CONTROL_REG, LTC2990_TR1_TR2, LTC2990_VOLTAGE_MODE_MASK);
    
    // Triggers a conversion by writing any value to the trigger register
    ack |= LTC2990_register_write(LTC2990_I2C_ADDRESS, LTC2990_TRIGGER_REG, 0x00);
    
    
    // Flush one ADC reading in case it is stale.  Then, take a new fresh reading.
    ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V1_MSB_REG, &adc_code, &data_valid, LTC2990_TIMEOUT);
    
    // Check which temperature mode the LTC2990 in currently in
    ack |= LTC2990_register_read(LTC2990_I2C_ADDRESS, LTC2990_CONTROL_REG, ®_data);
    if (reg_data & LTC2990_KELVIN_ENABLE) isKelvin= true;
    else isKelvin=false;   
    
    temperature = LTC2990_temperature(adc_code, LTC2990_TEMPERATURE_lsb, isKelvin);

@endverbatim

http://www.linear.com/product/LTC2990

http://www.linear.com/product/LTC2990#demoboards

REVISION HISTORY
$Revision: 2034 $
$Date: 2013-10-15 13:50:14 -0700 (Tue, 15 Oct 2013) $

Copyright (c) 2013, Linear Technology Corp.(LTC)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of Linear Technology Corp.

The Linear Technology Linduino is not affiliated with the official Arduino team.
However, the Linduino is only possible because of the Arduino team's commitment
to the open-source community.  Please, visit http://www.arduino.cc and
http://store.arduino.cc , and consider a purchase that will help fund their
ongoing work.

*/
/*! @file
    @ingroup LTC2990
    Library Header File for LTC2990: 14-bit Quad I2C Voltage, Current, and Temperature Monitor
*/

#ifndef LTC2990_H
#define LTC2990_H

#include 

/*! @name I2C_Addresses
@{ */

//! I2C address of the LTC2990.
//! Configured by tying the ADR0, ADR1, and ADR2 pins high or low. See Table 1 of datasheet.
//! Uncomment LTC2990_I2C_ADDRESS to match demo board configuration.
//  Address assignment
// LTC2990 I2C Address                //       AD1       AD0
#define LTC2990_I2C_ADDRESS 0x4C      //       Low       Low
// #define LTC2990_I2C_ADDRESS 0x4D    //      Low       High
// #define LTC2990_I2C_ADDRESS 0x4E    //      High      Low
// #define LTC2990_I2C_ADDRESS 0x4F    //      High      High


//! LTC2990 Global I2C Address.
#define LTC2990_I2C_GLOBAL_ADDRESS 0x77  //  Global Address

/*! @} */
/*! @name REGISTERS
@{ */

#define LTC2990_STATUS_REG                  0x00    //!< Indicates BUSY state and conversion status
#define LTC2990_CONTROL_REG                 0x01    //!< Controls Mode, Single/Repeat, Celsius/Kelvin
#define LTC2990_TRIGGER_REG                 0x02    //!< Triggers a conversion
#define LTC2990_TINT_MSB_REG                0x04    //!< Internal Temperature MSB
#define LTC2990_TINT_LSB_REG                0x05    //!< Internal Temperature LSB
#define LTC2990_V1_MSB_REG                  0x06    //!< V1, V1-V2, or T_R1 T MSB
#define LTC2990_V1_LSB_REG                  0x07    //!< V1, V1-V2, or T_R1 T LSB
#define LTC2990_V2_MSB_REG                  0x08    //!< V2, V1-V2, or T_R2 Voltage MSB
#define LTC2990_V2_LSB_REG                  0x09    //!< V2, V1-V2, or T_R2 Voltage LSB
#define LTC2990_V3_MSB_REG                  0x0A    //!< V3, V3-V4, or T_R2 T MSB
#define LTC2990_V3_LSB_REG                  0x0B    //!< V3, V3-V4, or T_R2 T LSB
#define LTC2990_V4_MSB_REG                  0x0C    //!< V4, V3-V4, or T_R2 Voltage MSB
#define LTC2990_V4_LSB_REG                  0x0D    //!< V4, V3-V4, or T_R2 Voltage LSB
#define LTC2990_VCC_MSB_REG                 0x0E    //!< Vcc MSB
#define LTC2990_VCC_LSB_REG                 0x0F    //!< Vcc LSB

/*! @} */
/*! @name LTC2990_CONTROL_REG SETTINGS
    Bitwise OR settings, and write to LTC2990_CONTROL_REG to configure settings.
    Bitwise AND with value read from LTC2990_CONTROL_REG to determine present setting.
@{ */

#define LTC2990_KELVIN_ENABLE                 0x80 //!< Enable for Kelvin. 
#define LTC2990_CELSIUS_ENABLE                0x00 //!< Enable for Celsius.
#define LTC2990_TEMP_FORMAT_MASK              0x80 //!< Use mask when changing temp formats

#define LTC2990_SINGLE_ENABLE                 0x40 //!< Enable for Single Acquisition
#define LTC2990_REPEATED_ENABLE               0x00 //!< Enable for Repeated Acquisition Mode
#define LTC2990_ACQUISITION_MASK              0x40 //!< Use mask when changing acquisition settings


/*! @} */
/*! @name LTC2990_CONTROL_REG ENABLE
    Bitwise AND 0xE7 then Bitwise OR settings, and write to LTC2990_CONTROL_REG to configure enable settings.
    Bitwise AND with value read from LTC2990_CONTROL_REG to determine present enable setting.
@{ */

#define LTC2990_ENABLE_INT_TEMPERATURE        0x00 //!< Read only Internal Temperature
#define LTC2990_ENABLE_V1                     0x08 //!< Tr1, V1 or V1-V2 per Mode are enabled
#define LTC2990_ENABLE_V2                     0x10 //!< Tr2, V3 or V3-V4 per Mode are enabled
#define LTC2990_ENABLE_ALL                    0x18 //!< All measurements per Mode are enabled 
#define LTC2990_TEMP_MEAS_MODE_MASK           0x18 //!< Use mask when changing temp meas modes

/*! @} */
/*! @name LTC2990_CONTROL_REG MODE
    Bitwise AND 0xF8 then Bitwise OR settings, and write to LTC2990_CONTROL_REG to configure enable settings.
    Bitwise AND with value read from LTC2990_CONTROL_REG to determine present enable setting.
@{ */

#define LTC2990_V1_V2_TR2                   0x00 //!< Read V1, V2 and TR2
#define LTC2990_V1V2_TR2                    0x01 //!< Read V1-V2 and TR2
#define LTC2990_V1V2_V3_V4                  0x02 //!< Read V1-V2, V3 and V4
#define LTC2990_TR1_V3_V4                   0x03 //!< Read TR1, V3 and V4
#define LTC2990_TR1_V3V4                    0x04 //!< Read TR1 and V3-V4
#define LTC2990_TR1_TR2                     0x05 //!< Read TR1 and TR2
#define LTC2990_V1V2_V3V4                   0x06 //!< Read V1-V2 and V3-V4 
#define LTC2990_V1_V2_V3_V4                 0x07 //!< Read V1, V2, V3 and V4
#define LTC2990_VOLTAGE_MODE_MASK           0x07 //!< Use mode mask when changing modes



/*!@} */

//! Reads a 14-bit adc_code from LTC2990.
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
int8_t LTC2990_adc_read(uint8_t i2c_address,    //!< I2C address of the LTC2990. Configured by tying the ADR0, ADR1, and ADR2 pins high or low. See Table 1 of datasheet.
                        uint8_t msb_register_address,   /*!< Address of the LTC2990 MSB register to be read. This is also known as the "command byte".
                                                             Two sequential 8-bit registers are read, starting with the msb_register_address.*/
                        int16_t *adc_code,      //!< returns 14-bit value read from the ADC
                        int8_t *data_valid      //!< returns the status of the DATA_VALID bit. *data_valid=0 indicates stale data
                       );

//! Reads a 14-bit adc_code from the LTC2990 but enforces a maximum timeout.
//! Similar to LTC2990_adc_read except it repeats until the data_valid bit is set, it fails to receive an I2C acknowledge, or the timeout (in milliseconds)
//! expires. It keeps trying to read from the LTC2990 every millisecond until the data_valid bit is set (indicating new data since the previous
//! time this register was read) or until it fails to receive an I2C acknowledge (indicating an error on the I2C bus).
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
int8_t LTC2990_adc_read_timeout(uint8_t i2c_address,    //!< I2C address of the LTC2990. Configured by tying the ADR0, ADR1, and ADR2 pins high or low. See Table 1 of datasheet.
                                uint8_t msb_register_address,   /*!< Address of the LTC2990 MSB register to be read. This is also known as the "command byte".
                                                                     Two sequential 8-bit registers will be read, starting with the msb_register_address.*/
                                int16_t *adc_code,      //!< returns 14-bit value read from the ADC
                                int8_t *data_valid,     //!< returns the status of the DATA_VALID bit. *data_valid=0 indicates stale data
                                uint16_t timeout,        /*!< maximum timeout in milliseconds. If at any time a NACK is received the function aborts.*/
                                uint8_t status_bit                            //

Download LTC2990 - Linduino.CPP File

/*!
LTC2990: 14-bit Quad I2C Voltage, Current, and Temperature Monitor

@verbatim

The LTC2990 is used to monitor system temperatures, voltages and currents. 
Through the I2C serial interface, the four monitors can individually measure 
supply voltages and can be paired for differential measurements of current sense 
resistors or temperature sensing transistors. Additional measurements include 
internal temperature and internal VCC. The internal 10ppm reference minimizes 
the number of supporting components and area required. Selectable address and 
configurable functionality give the LTC2990 flexibility to be incorporated in 
various systems needing temperature, voltage or current data. The LTC2990 fits 
well in systems needing sub-millivolt voltage resolution, 1% current measurement 
and 1 degree Celsius temperature accuracy or any combination of the three. 

@endverbatim

http://www.linear.com/product/LTC2990

http://www.linear.com/product/LTC2990#demoboards

REVISION HISTORY
$Revision: 2034 $
$Date: 2013-10-15 13:50:14 -0700 (Tue, 15 Oct 2013) $

Copyright (c) 2013, Linear Technology Corp.(LTC)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of Linear Technology Corp.

The Linear Technology Linduino is not affiliated with the official Arduino team.
However, the Linduino is only possible because of the Arduino team's commitment
to the open-source community.  Please, visit http://www.arduino.cc and
http://store.arduino.cc , and consider a purchase that will help fund their
ongoing work.
*/

//! @defgroup LTC2990 LTC2990: 14-bit Quad I2C Voltage, Current, and Temperature Monitor

/*! @file
    @ingroup LTC2990
    Library for LTC2990: 14-bit Quad I2C Voltage, Current, and Temperature Monitor
*/

#include 
#include 
#include "Linduino.h"
#include "LT_I2C.h"
#include "LTC2990.h"
#include 

// Reads a 14-bit adc_code from LTC2990.
int8_t LTC2990_adc_read(uint8_t i2c_address, uint8_t msb_register_address, int16_t *adc_code, int8_t *data_valid)
{
  int8_t ack = 0;
  uint16_t code;
  ack = i2c_read_word_data(i2c_address, msb_register_address, &code);
  
  *data_valid = (code >> 15) & 0x01;   // Place Data Valid Bit in *data_valid
  
  *adc_code = code & 0x7FFF;  // Removes data valid bit to return proper adc_code value
  
  return(ack);
}

// Reads a 14-bit adc_code from the LTC2990 but enforces a maximum timeout.
// Similar to LTC2990_adc_read except it repeats until the data_valid bit is set, it fails to receive an I2C acknowledge, or the timeout (in milliseconds)
// expires. It keeps trying to read from the LTC2990 every millisecond until the data_valid bit is set (indicating new data since the previous
// time this register was read) or until it fails to receive an I2C acknowledge (indicating an error on the I2C bus).
int8_t LTC2990_adc_read_timeout(uint8_t i2c_address, uint8_t msb_register_address, int16_t *adc_code, int8_t *data_valid, uint16_t timeout, uint8_t status_bit)
{
  int8_t ack = 0;
  uint8_t reg_data;
  uint16_t timer_count;  // Timer count for data_valid
  *data_valid = 0; 
 
  for (timer_count = 0; timer_count < timeout; timer_count++)
  {
    
    ack |=  LTC2990_register_read(i2c_address, LTC2990_STATUS_REG, ®_data); //! 1)Read status register until correct data valid bit is set
    
    if ((ack) || (((reg_data>>status_bit)&0x1)==1)){
        break;
    }
    delay(1);
  }
  ack |= LTC2990_adc_read(i2c_address, msb_register_address, &(*adc_code), &(*data_valid));   //! 2) It's either valid or it's timed out, we read anyways
  if(*data_valid  !=1){
    return (1); 
  }
  return(ack);
}

// Reads new data (even after a mode change) by flushing old data and waiting for the data_valid bit to be set.
// This function simplifies adc reads when modes are changing.  For example, if V1-V2 changes from temperature mode
// to differential voltage mode, the data in the register may still correspond to the temperature reading immediately
// after the mode change.  Flushing one reading and waiting for a new reading guarantees fresh data is received.
// If the timeout is reached without valid data (*data_valid=1) the function exits.
int8_t LTC2990_adc_read_new_data(uint8_t i2c_address, uint8_t msb_register_address, int16_t *adc_code, int8_t *data_valid, uint16_t timeout)
{
  int8_t ack = 0; 
  uint8_t status_bit; 
  status_bit  = msb_register_address/2-1;
  ack |= LTC2990_adc_read_timeout(i2c_address, msb_register_address, adc_code, data_valid, timeout, status_bit); //! 1)  Throw away old data
 
  ack |= LTC2990_adc_read_timeout(i2c_address, msb_register_address, adc_code, data_valid, timeout,status_bit); //! 2) Read new data
  
  return(ack);
}

// Reads an 8-bit register from the LTC2990 using the standard repeated start format.
int8_t LTC2990_register_read(uint8_t i2c_address, uint8_t register_address, uint8_t *register_data)
{
  int8_t ack = 0;

  ack = i2c_read_byte_data(i2c_address, register_address, register_data);
  return(ack);
}

// Write one byte to an LTC2990 register.
// Writes to an 8-bit register inside the LTC2990 using the standard I2C repeated start format.
int8_t LTC2990_register_write(uint8_t i2c_address, uint8_t register_address, uint8_t register_data)
{
  int8_t ack = 0;
  
  ack = i2c_write_byte_data(i2c_address, register_address, register_data);
  return(ack);
}

// Used to set and clear bits in a control register.  bits_to_set will be bitwise OR'd with the register.
// bits_to_clear will be inverted and bitwise AND'd with the register so that every location with a 1 will result in a 0 in the register.
int8_t LTC2990_register_set_clear_bits(uint8_t i2c_address, uint8_t register_address, uint8_t bits_to_set, uint8_t bits_to_clear)
{
  uint8_t register_data;
  int8_t ack = 0;
    
  ack |= LTC2990_register_read(i2c_address, register_address, ®ister_data);  //! 1) Read register
  register_data = register_data & (~bits_to_clear); //! 2) Clear bits that were set to be cleared
  register_data = register_data | bits_to_set;
  ack |= LTC2990_register_write(i2c_address, register_address, register_data);  //! 3) Write to register with the cleared bits
  return(ack);
}

// Calculates the LTC2990 single-ended input voltages
float LTC2990_code_to_single_ended_voltage(int16_t adc_code, float LTC2990_single_ended_lsb)
{
  float voltage;
  int16_t sign = 1;
  if (adc_code >> 14)
  {
    adc_code = (adc_code ^ 0x7FFF) + 1;                 //! 1) Converts two's complement to binary
    sign = -1;
  }
  adc_code = (adc_code & 0x3FFF);
  voltage = ((float) adc_code) * LTC2990_single_ended_lsb * sign;   //! 2) Convert code to voltage from lsb
  return (voltage);
}

// Calculates the LTC2990 Vcc voltage
float LTC2990_code_to_vcc_voltage(int16_t adc_code, float LTC2990_single_ended_lsb)
{
  float voltage;
  int16_t sign = 1;
  if (adc_code >> 14)
  {
    adc_code = (adc_code ^ 0x7FFF) + 1;                 //! 1) Converts two's complement to binary
    sign = -1;
  }
  
  voltage = (((float) adc_code) * LTC2990_single_ended_lsb * sign) + 2.5; //! 2) Convert code to Vcc Voltage from single-ended lsb
  return (voltage);
}

// Calculates the LTC2990 differential input voltage.
float LTC2990_code_to_differential_voltage(int16_t adc_code, float LTC2990_differential_lsb)
{
  float voltage;
  int16_t sign = 1;
  if (adc_code >> 14)
  {
    adc_code = (adc_code ^ 0x7FFF) + 1;                 //! 1)Converts two's complement to binary
    sign = -1;
  }
  voltage = ((float) adc_code) * LTC2990_differential_lsb * sign;   //! 2) Convert code to voltage form differential lsb
  return (voltage);
}

// Calculates the LTC2990 temperature
float LTC2990_temperature(int16_t adc_code, float LTC2990_temperature_lsb, boolean unit)
{
  float temperature;
  adc_code = (adc_code & 0x1FFF);                               //! 1) Removes first 3 bits
  if(!unit){                                                     //! 2)Checks to see if it's Kelvin
    if(adc_code >>12)
    {
        adc_code = (adc_code | 0xE000);                         //! Sign extend if it's not Kelvin (Celsius)
    }
  }
  temperature = ((float) adc_code) * LTC2990_temperature_lsb;   //! 3) Converts code to temperature from temperature lsb
  
  return (temperature);
}

//  Calculates the LTC2990 diode voltage
float LTC2990_code_to_diode_voltage(int16_t adc_code, float LTC2990_diode_voltage_lsb)
{
  float voltage;
  adc_code = (adc_code & 0x1FFF);                               //! 1) Removes first 3 bits
  voltage = ((float) adc_code) * LTC2990_diode_voltage_lsb;     //! 2) Convert code to voltage from diode voltage lsb
  return (voltage);
}

Technical Support