LTC2991 - Octal I2C Voltage, Current, and Temperature Monitor
Features
- Measures Voltage, Current, Temperature
- Measures Four Remote Diode Temperatures
- 0.7°C (Typ) Accuracy, 0.06°C Resolution
- 1°C (Typ) Internal Temperature Sensor
- Series Resistance Cancellation
- 14-Bit ADC Measures Voltage/Current
- PWM Temperature Output
- 3V to 5.5V Supply Operating Voltage
- Eight Selectable Addresses
- Internal 10ppm/°C Voltage Reference
- V1 to V8 Inputs ESD Rated to 6kV HBM
- 16-Lead MSOP Package
AEC-Q100 data available for specific packages
Typical Application
Description
The LTC®2991 is used to monitor system temperatures, voltages and currents. Through the I2C serial interface, the eight 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 LTC2991 flexibility to be incorporated in various systems needing temperature, voltage or current data. The LTC2991 fits well in systems needing submillivolt voltage resolution, 1% current measurement and 1°C temperature accuracy or any combination of the three.
Packaging
CAD Symbols and Footprints: The downloadable Zip file below contains the schematic symbol and PCB footprints.
For complete and up to date package information and drawings, please refer to our packaging page
| Part Number | Package | Code | Temp | Package Drawing |
RoHS |
|---|---|---|---|---|---|
| LTC2991CMS#PBF | MS-16 | MS | C | 05-08-1669 | Yes |
| LTC2991CMS#TRPBF | MS-16 | MS | C | 05-08-1669 | Yes |
| LTC2991IMS#PBF | MS-16 | MS | I | 05-08-1669 | Yes |
| LTC2991IMS#TRPBF | MS-16 | MS | I | 05-08-1669 | Yes |
Order Info
- Part numbers ending in PBF are lead free. Solder plated terminal finish (SnPb) versions are non-standard and special terms and conditions and pricing applies if available. Please contact LTC marketing for information.
- Part numbers containing TR or TRM are shipped in tape and reel or 500 unit mini tape and reel, respectively
- Please refer to our general ordering information or the product datasheet for more details
Package Variations and Pricing
| Part Number | Package | Temp | Price (1-99) |
Price (1k)* |
RoHS | |
|---|---|---|---|---|---|---|
| LTC2991CMS#PBF | MS-16 | C | $6.43 | $4.50 | Yes | |
| LTC2991CMS#TRPBF | MS-16 | C | $4.56 | Yes | ||
| LTC2991IMS#PBF | MS-16 | I | $7.39 | $5.18 | Yes | |
| LTC2991IMS#TRPBF | MS-16 | I | $5.24 | Yes | ||
| Buy Now • Request Samples | ||||||
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 |
|---|---|---|---|
| DC1785B | LTC2991 Demo board | I2C Temperature, Voltage, and Current Monitor (req. DC590 or DC2026) | $50.00 | |
| Buy Now | |||
Companion Boards
| Part Number | Description | Price | Documentation |
|---|---|---|---|
| DC2026C | Linduino One Isolated USB Demo Board: An Arduino- and QuikEval-Compatible Code Development Platform | $75.00 | |
| DC590B | Isolated USB Serial Controller for Linear Technology QuikEval-Compatible Demo Boards | $50.00 | |
| Buy Now | |||
Designed for Automotive and Transportation Applications
AEC-Q100 data is available for these specific part numbers. Please contact your local sales representative for more information regarding reliability reports or to inquire about parts that are not included. For more information, view our Automotive and Transportation page
| Part Number | Package | Temp | Price (1-99) |
Price (1k)* |
RoHS | |
|---|---|---|---|---|---|---|
| LTC2991IMS#PBF | MS-16 | I | $7.39 | $5.18 | Yes | |
| LTC2991IMS#TRPBF | MS-16 | I | $5.24 | Yes | ||
| Buy Now • Request Samples | ||||||
Applications
- Temperature Measurement
- Supply Voltage Monitoring
- Current Measurement
- Remote Data Acquisition
- Environmental Monitoring
People Who Viewed This Product Also Viewed
- LTC2990 - Quad I2C Voltage, Current and Temperature Monitor
- LTC4151 - High Voltage I2C Current and Voltage Monitor
- LTC2945 - Wide Range I2C Power Monitor
- LT3080 - Adjustable 1.1A Single Resistor Low Dropout Regulator
- LT2940 - Power and Current Monitor
- LT4320/LT4320-1 - Ideal Diode Bridge Controller
- LTC2983 - Multi-Sensor High Accuracy Digital Temperature Measurement System
- LT8705 - 80V VIN and VOUT Synchronous 4-Switch Buck- Boost DC/DC Controller
- LT1763 - 500mA, Low Noise, LDO Micropower Regulators
- LT5400 - Quad Matched Resistor Network
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.
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 LTC2991 - DC1785A Linduino .INO File
/*!
Linear Technology DC1785 Demonstration Board.
LTC2991: 14-bit ADC Octal 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 DC1785A
Explanation of Commands:
1 - Single-Ended Voltage - Selects the Single-Ended Voltage Menu.
1-8: Displays the measured single-ended voltage at one of the V1-V8
inputs. When measuring V1 and V8, ensure jumpers are set to VOLT
position.
9: Vcc - Displays the measured Vcc voltage.
10: 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-4: Displays the measured differential voltage across one of the V1-V8
input pairs. The input common-mode range is 0V to Vcc. It is
easiest to ground the lower input. When measuring V1 and V8,
ensure jumpers are set to VOLT position.
5: ALL - Displays the measured differential voltages at all terminals.
3 - Temperature - Selects the Temperature Menu
To measure temperature using onboard 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: V5-V6 - Measure temperature of external transistor connected to V5
and V6 terminals.
4: V7-V8 - Measure temperature of Q2 (mounted to demo board) when JP3
and JP4 are in TEMP position.
5: Internal - Measure temperature using the internal temperature
sensor.
6: All - Displays temperatures at all connections as well as the
internal temperature sensor.
4 - Settings - Selects the Settings Menu
Enable/disable the on-chip digital filters. Also toggle temperature units
between degrees Celsius or degrees Kelvin.
1-5: Entering these one can enable/disable various channel filters.
6: Toggle temperature units between degrees Celsius and degrees
Kelvin.
5 - PWM - Selects the PWM Menu
Generates Proportional PWM output using remote diode connected to pins 7 and
8. When JP3 and JP4 are in TEMP positions, Q2 is used as the temperature
sensing diode (mounted on demo board).
1: Set Threshold Temperature - Enter temperature corresponding to 0%
(100% in Inverted Mode) duty cycle.
2: Inverted/Non-Inverted PWM - Toggles between Inverted/Non-Inverted
modes
3: Enable/Disable - Enables or Disables PWM (Toggle)
USER INPUT DATA FORMAT:
decimal : 1024
hex : 0x400
octal : 02000 (leading 0 "zero")
binary : B10000000000
float : 1024.0
@endverbatim
http://www.linear.com/product/LTC2991
http://www.linear.com/product/LTC2991#demoboards
REVISION HISTORY
$Revision: 2033 $
$Date: 2013-10-15 13:21:18 -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 LTC2991
*/
#include <Arduino.h>
#include <stdint.h>
#include "Linduino.h"
#include "UserInterface.h"
#include "LT_I2C.h"
#include "QuikEval_EEPROM.h"
#include "LTC2991.h"
#include <Wire.h>
#include <SPI.h>
// 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();
int8_t menu_5_pwm_options();
// Global variables
static uint8_t demo_board_connected; //!< Set to 1 if the board is connected
const uint16_t LTC2991_TIMEOUT=1000; //!< Configures the maximum timeout allowed for an LTC2991 read.
//! Initialize Linduino
void setup()
{
char demo_name[] = "DC1785"; // 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 |= LTC2991_register_write(LTC2991_I2C_ADDRESS, LTC2991_CHANNEL_ENABLE_REG, LTC2991_ENABLE_ALL_CHANNELS); //! Enables all channels
ack |= LTC2991_register_write(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, 0x00); //! Sets registers to default starting values.
ack |= LTC2991_register_write(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, 0x00);
ack |= LTC2991_register_write(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_PWM_Tinternal_REG, LTC2991_REPEAT_MODE); //! Configures LTC2991 for Repeated Acquisition mode
}
}
//! 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;
case 5:
ack |= menu_5_pwm_options(); // PWM options 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("* DC1785A 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 LTC2991 14-Bit Octal 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(" 5-PWM\n\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-V5\n"));
Serial.print(F(" 6-V6\n"));
Serial.print(F(" 7-V7\n"));
Serial.print(F(" 8-V8\n"));
Serial.print(F(" 9-Vcc\n"));
Serial.print(F(" 10-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;
//! Enables single-ended mode.
//! Flushes one reading following mode change.
//! Reads single-ended voltage from ADC and prints it.
switch (user_command)
{
case 1:
// Enable Single-Ended Mode by clearing LTC2991_V1_V2_DIFFERENTIAL_ENABLE bit in LTC2991_CONTROL_V1234_REG
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, 0x00, LTC2991_V1_V2_DIFFERENTIAL_ENABLE | LTC2991_V1_V2_TEMP_ENABLE);
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V1_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_single_ended_voltage(code, LTC2991_SINGLE_ENDED_lsb);
Serial.print(F("\n V1: "));
Serial.print(voltage, 4);
Serial.print(F(" V\n"));
break;
case 2:
// Enable Single-Ended Mode by clearing LTC2991_V1_V2_DIFFERENTIAL_ENABLE bit in LTC2991_CONTROL_V1234_REG
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, 0x00, LTC2991_V1_V2_DIFFERENTIAL_ENABLE | LTC2991_V1_V2_TEMP_ENABLE);
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V2_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_single_ended_voltage(code, LTC2991_SINGLE_ENDED_lsb);
Serial.print(F("\n V2: "));
Serial.print(voltage, 4);
Serial.print(F(" V\n"));
break;
case 3:
// Enable Single-Ended Mode by clearing LTC2991_V3_V4_DIFFERENTIAL_ENABLE bit in LTC2991_CONTROL_V1234_REG
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, 0x00, LTC2991_V3_V4_DIFFERENTIAL_ENABLE | LTC2991_V1_V2_TEMP_ENABLE);
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V3_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_single_ended_voltage(code, LTC2991_SINGLE_ENDED_lsb);
Serial.print(F("\n V3: "));
Serial.print(voltage, 4);
Serial.print(F(" V\n"));
break;
case 4:
// Enable Single-Ended Mode by clearing LTC2991_V3_V4_DIFFERENTIAL_ENABLE bit in LTC2991_CONTROL_V1234_REG
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, 0x00, LTC2991_V3_V4_DIFFERENTIAL_ENABLE | LTC2991_V1_V2_TEMP_ENABLE);
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V4_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_single_ended_voltage(code, LTC2991_SINGLE_ENDED_lsb);
Serial.print(F("\n V4: "));
Serial.print(voltage, 4);
Serial.print(F(" V\n"));
break;
case 5:
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, 0x00, LTC2991_V5_V6_DIFFERENTIAL_ENABLE | LTC2991_V1_V2_TEMP_ENABLE);
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V5_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_single_ended_voltage(code, LTC2991_SINGLE_ENDED_lsb);
Serial.print(F("\n V5: "));
Serial.print(voltage, 4);
Serial.print(F(" V\n"));
break;
case 6:
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, 0x00, LTC2991_V5_V6_DIFFERENTIAL_ENABLE | LTC2991_V1_V2_TEMP_ENABLE);
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V6_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_single_ended_voltage(code, LTC2991_SINGLE_ENDED_lsb);
Serial.print(F("\n V6: "));
Serial.print(voltage, 4);
Serial.print(F(" V\n"));
break;
case 7:
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, 0x00, LTC2991_V7_V8_DIFFERENTIAL_ENABLE | LTC2991_V1_V2_TEMP_ENABLE);
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V8_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_single_ended_voltage(code, LTC2991_SINGLE_ENDED_lsb);
Serial.print(F("\n V7: "));
Serial.print(voltage, 4);
Serial.print(F(" V\n"));
break;
case 8:
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, 0x00, LTC2991_V7_V8_DIFFERENTIAL_ENABLE | LTC2991_V1_V2_TEMP_ENABLE);
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V8_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_single_ended_voltage(code, LTC2991_SINGLE_ENDED_lsb);
Serial.print(F("\n V8: "));
Serial.print(voltage, 4);
Serial.print(F(" V\n"));
break;
case 9:
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_Vcc_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_vcc_voltage(code, LTC2991_SINGLE_ENDED_lsb);
Serial.print(F("\n Vcc: "));
Serial.print(voltage, 4);
Serial.print(F(" V\n"));
break;
case 10:
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, 0x00, (LTC2991_V1_V2_DIFFERENTIAL_ENABLE | LTC2991_V3_V4_DIFFERENTIAL_ENABLE | LTC2991_V1_V2_TEMP_ENABLE | LTC2991_V3_V4_TEMP_ENABLE));
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, 0x00, (LTC2991_V5_V6_DIFFERENTIAL_ENABLE | LTC2991_V7_V8_DIFFERENTIAL_ENABLE | LTC2991_V5_V6_TEMP_ENABLE | LTC2991_V7_V8_TEMP_ENABLE));
// Reads and displays all single-ended voltages
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V1_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_single_ended_voltage(code, LTC2991_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 |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V2_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_single_ended_voltage(code, LTC2991_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 |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V3_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_single_ended_voltage(code, LTC2991_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 |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V4_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_single_ended_voltage(code, LTC2991_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 |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V5_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_single_ended_voltage(code, LTC2991_SINGLE_ENDED_lsb);
Serial.print(F(" V5: "));
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 |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V6_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_single_ended_voltage(code, LTC2991_SINGLE_ENDED_lsb);
Serial.print(F(" V6: "));
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 |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V7_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_single_ended_voltage(code, LTC2991_SINGLE_ENDED_lsb);
Serial.print(F(" V7: "));
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 |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V8_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_single_ended_voltage(code, LTC2991_SINGLE_ENDED_lsb);
Serial.print(F(" V8: "));
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 |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_Vcc_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_vcc_voltage(code, LTC2991_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-V5-V6\n"));
Serial.print(F(" 4-V7-V8\n"));
Serial.print(F(" 5-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.
//! Flushes one reading following mode change.
//! Reads differential voltage from ADC and prints it.
switch (user_command)
{
case 1:
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, LTC2991_V1_V2_DIFFERENTIAL_ENABLE, LTC2991_V1_V2_TEMP_ENABLE);
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V2_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_differential_voltage(code, LTC2991_DIFFERENTIAL_lsb);
Serial.print(F("\n V1-V2: "));
Serial.print(voltage, 4);
Serial.print(F(" V\n"));
break;
case 2:
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, LTC2991_V3_V4_DIFFERENTIAL_ENABLE, LTC2991_V3_V4_TEMP_ENABLE);
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V4_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_differential_voltage(code, LTC2991_DIFFERENTIAL_lsb);
Serial.print(F("\n V3-V4: "));
Serial.print(voltage, 4);
Serial.print(F(" V\n"));
break;
case 3:
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, LTC2991_V5_V6_DIFFERENTIAL_ENABLE, LTC2991_V5_V6_TEMP_ENABLE);
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V6_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_differential_voltage(code, LTC2991_DIFFERENTIAL_lsb);
Serial.print(F("\n V5-V6: "));
Serial.print(voltage, 4);
Serial.print(F(" V\n"));
break;
case 4:
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, LTC2991_V7_V8_DIFFERENTIAL_ENABLE, LTC2991_V7_V8_TEMP_ENABLE);
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V8_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_differential_voltage(code, LTC2991_DIFFERENTIAL_lsb);
Serial.print(F("\n V7-V8: "));
Serial.print(voltage, 4);
Serial.print(F(" V\n"));
break;
case 5:
// reads all differential voltages
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, LTC2991_V1_V2_DIFFERENTIAL_ENABLE | LTC2991_V3_V4_DIFFERENTIAL_ENABLE, LTC2991_V1_V2_TEMP_ENABLE | LTC2991_V3_V4_TEMP_ENABLE);
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, LTC2991_V5_V6_DIFFERENTIAL_ENABLE | LTC2991_V7_V8_DIFFERENTIAL_ENABLE, LTC2991_V5_V6_TEMP_ENABLE | LTC2991_V7_V8_TEMP_ENABLE);
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V2_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_differential_voltage(code, LTC2991_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 |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V4_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_differential_voltage(code, LTC2991_DIFFERENTIAL_lsb);
Serial.print(F(" V3-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 |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V6_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_differential_voltage(code, LTC2991_DIFFERENTIAL_lsb);
Serial.print(F(" V5-V6: "));
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 |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V8_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_differential_voltage(code, LTC2991_DIFFERENTIAL_lsb);
Serial.print(F(" V7-V8: "));
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-V5-V6\n"));
Serial.print(F(" 4-V7-V8\n"));
Serial.print(F(" 5-Internal\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
// Read Temperature
int8_t data_valid;
int16_t adc_code;
uint8_t reg_data;
float temperature;
//! Enables temperature mode.
//! Flushes one reading following mode change.
//! Reads temperature from ADC and prints it.
switch (user_command)
{
case 1:
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, LTC2991_V1_V2_TEMP_ENABLE, 0x00);
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V1_MSB_REG, &adc_code, &data_valid, LTC2991_TIMEOUT);
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, ®_data);
if (reg_data & LTC2991_V1_V2_KELVIN_ENABLE) isKelvin= true;
else isKelvin=false;
temperature = LTC2991_temperature(adc_code, LTC2991_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:
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, LTC2991_V3_V4_TEMP_ENABLE, 0x00);
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V3_MSB_REG, &adc_code, &data_valid, LTC2991_TIMEOUT);
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, ®_data);
if (reg_data & LTC2991_V3_V4_KELVIN_ENABLE) isKelvin=true;
else isKelvin = false;
temperature = LTC2991_temperature(adc_code, LTC2991_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:
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, LTC2991_V5_V6_TEMP_ENABLE, 0x00);
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V5_MSB_REG, &adc_code, &data_valid, LTC2991_TIMEOUT);
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, ®_data);
if (reg_data & LTC2991_V5_V6_KELVIN_ENABLE) isKelvin=true;
else isKelvin=false;
temperature = LTC2991_temperature(adc_code, LTC2991_TEMPERATURE_lsb, isKelvin);
Serial.print(F("\n V5-V6: "));
Serial.print(temperature, 2);
if (isKelvin) Serial.print(F(" K\n"));
else Serial.print(F(" C\n"));
break;
case 4:
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, LTC2991_V7_V8_TEMP_ENABLE, 0x00);
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V7_MSB_REG, &adc_code, &data_valid, LTC2991_TIMEOUT);
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, ®_data);
if (reg_data & LTC2991_V7_V8_KELVIN_ENABLE) isKelvin = true;
else isKelvin = false;
temperature = LTC2991_temperature(adc_code, LTC2991_TEMPERATURE_lsb, isKelvin);
Serial.print(F("\n V7-V8: "));
Serial.print(temperature, 2);
if (isKelvin) Serial.print(F(" K\n"));
else Serial.print(F(" C\n"));
break;
case 5:
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_T_Internal_MSB_REG, &adc_code, &data_valid, LTC2991_TIMEOUT);
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_PWM_Tinternal_REG, ®_data);
if (reg_data & LTC2991_INT_KELVIN_ENABLE) isKelvin=true;
else isKelvin=false;
temperature = LTC2991_temperature(adc_code, LTC2991_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 6:
// All Temperatures
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, LTC2991_V1_V2_TEMP_ENABLE | LTC2991_V3_V4_TEMP_ENABLE, 0x00);
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, LTC2991_V5_V6_TEMP_ENABLE | LTC2991_V7_V8_TEMP_ENABLE, 0x00);
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V1_MSB_REG, &adc_code, &data_valid, LTC2991_TIMEOUT);
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, ®_data);
if (reg_data & LTC2991_V1_V2_KELVIN_ENABLE) isKelvin = true;
else isKelvin=false;
temperature = LTC2991_temperature(adc_code, LTC2991_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 |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V3_MSB_REG, &adc_code, &data_valid, LTC2991_TIMEOUT);
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, ®_data);
if (reg_data & LTC2991_V3_V4_KELVIN_ENABLE) isKelvin = true;
else isKelvin=false;
temperature = LTC2991_temperature(adc_code, LTC2991_TEMPERATURE_lsb, isKelvin);
Serial.print(F(" 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 |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V5_MSB_REG, &adc_code, &data_valid, LTC2991_TIMEOUT);
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, ®_data);
if (reg_data & LTC2991_V5_V6_KELVIN_ENABLE) isKelvin = true;
else isKelvin=false;
temperature = LTC2991_temperature(adc_code, LTC2991_TEMPERATURE_lsb,isKelvin);
Serial.print(F(" V5-V6: "));
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 |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V7_MSB_REG, &adc_code, &data_valid, LTC2991_TIMEOUT);
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, ®_data);
if (reg_data & LTC2991_V7_V8_KELVIN_ENABLE) isKelvin = true;
else isKelvin=false;
temperature = LTC2991_temperature(adc_code, LTC2991_TEMPERATURE_lsb, isKelvin);
Serial.print(F(" V7-V8: "));
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 |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_T_Internal_MSB_REG, &adc_code, &data_valid, LTC2991_TIMEOUT);
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_PWM_Tinternal_REG, ®_data);
if (reg_data & LTC2991_INT_KELVIN_ENABLE) isKelvin = true;
else isKelvin = false;
temperature = LTC2991_temperature(adc_code, LTC2991_TEMPERATURE_lsb, isKelvin);
Serial.print(F(" 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;
do
{
Serial.print(F("\nSettings\n")); //! Displays Setting menu
Serial.print(F("************************\n"));
Serial.print(F("* Filter *\n"));
Serial.print(F("************************\n"));
Serial.print(F("* 1-V1/V2: "));
//! Displays present status of all settings by reading from LTC2991 registers.
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, ®_data);
if (reg_data & LTC2991_V1_V2_FILTER_ENABLE) Serial.print(F("Enabled *\n"));
else Serial.print(F("Disabled *\n"));
Serial.print(F("* 2-V3/V4: "));
if (reg_data & LTC2991_V3_V4_FILTER_ENABLE) Serial.print(F("Enabled *\n"));
else Serial.print(F("Disabled *\n"));
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, ®_data);
Serial.print(F("* 3-V5/V6: "));
if (reg_data & LTC2991_V5_V6_FILTER_ENABLE) Serial.print(F("Enabled *\n"));
else Serial.print(F("Disabled *\n"));
Serial.print(F("* 4-V7/V8: "));
if (reg_data & LTC2991_V7_V8_FILTER_ENABLE) Serial.print(F("Enabled *\n"));
else Serial.print(F("Disabled *\n"));
Serial.print(F("* 5-Internal: "));
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_PWM_Tinternal_REG, ®_data);
if (reg_data & LTC2991_INT_FILTER_ENABLE) Serial.print(F("Enabled *\n"));
else Serial.print(F("Disabled *\n"));
Serial.print(F("************************\n"));
Serial.print(F("* 6-Deg C/K:"));
//Only looks at the internal temperature sensor's setting for Celsius/Kelvin, but all channels should be the same in this program.
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_PWM_Tinternal_REG, ®_data);
if (reg_data & LTC2991_INT_KELVIN_ENABLE) Serial.print(F(" Kelvin *\n"));
else Serial.print(F(" Celsius*\n"));
Serial.print(F("* m-Main Menu *\n"));
Serial.print(F("************************\n\n"));
Serial.print(F("Enter a command: "));
user_command = read_int(); //! Reads the user command
if (user_command == 'm') Serial.print(F("m\n")); // Print m if it is entered
else Serial.println(user_command); // Print user command
//! Toggles the setting selected by user.
switch (user_command)
{
case 1:
// Toggle Filter bit
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, ®_data);
ack |= LTC2991_register_write(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, reg_data ^ LTC2991_V1_V2_FILTER_ENABLE);
break;
case 2:
// Toggle Filter bit
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, ®_data);
ack |= LTC2991_register_write(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, reg_data ^ LTC2991_V3_V4_FILTER_ENABLE);
break;
case 3:
// Toggle Filter bit
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, ®_data);
ack |= LTC2991_register_write(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, reg_data ^ LTC2991_V5_V6_FILTER_ENABLE);
break;
case 4:
// Toggle Filter bit
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, ®_data);
ack |= LTC2991_register_write(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, reg_data ^ LTC2991_V7_V8_FILTER_ENABLE);
break;
case 5:
// Toggle Filter bit
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_PWM_Tinternal_REG, ®_data);
ack |= LTC2991_register_write(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_PWM_Tinternal_REG, reg_data ^ LTC2991_INT_FILTER_ENABLE);
break;
case 6:
// Toggle Kelvin/Celsius bits
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, ®_data);
ack |= LTC2991_register_write(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, reg_data ^ (LTC2991_V1_V2_KELVIN_ENABLE | LTC2991_V3_V4_KELVIN_ENABLE));
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, ®_data);
ack |= LTC2991_register_write(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, reg_data ^ (LTC2991_V5_V6_KELVIN_ENABLE | LTC2991_V7_V8_KELVIN_ENABLE));
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_PWM_Tinternal_REG, ®_data);
ack |= LTC2991_register_write(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_PWM_Tinternal_REG, reg_data ^ LTC2991_INT_KELVIN_ENABLE);
break;
default:
if (user_command != 'm')
Serial.print(F("Incorrect Option\n"));
break;
}
}
while ((user_command != 'm') && (ack != 1));
return(ack);
}
//! Configure PWM options
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
int8_t menu_5_pwm_options()
{
int8_t ack=0;
uint8_t user_command;
int16_t pwm_temp = 0;
uint8_t reg_data, reg_data_msb;
do
{
Serial.print(F("\n\nPWM Settings - Select to Toggle\n\n")); //! Displays PWM Settings menu
Serial.print(F(" 1-Temp Threshold: "));
// Check if V7-V8 are configured for temperature mode
//! Print present status of all PWM settings based on LTC2991 register contents.
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, ®_data);
if (reg_data & LTC2991_V7_V8_TEMP_ENABLE)
{
// Print the configured PWM temperature threshold
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_PWM_THRESHOLD_MSB_REG, ®_data_msb);
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_PWM_Tinternal_REG, ®_data);
// Combine temperature threshold's upper 8 MSB's from LTC2991_PWM_THRESHOLD_MSB_REG with the 1 LSB in the upper bit of LTC2991_CONTROL_PWM_Tinternal_REG
pwm_temp = (int16_t)((reg_data_msb << 1) | (reg_data & LTC2991_PWM_0) >> 7);
Serial.print(pwm_temp);
//Print degrees C or K configured for V7/V8
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, ®_data);
if (reg_data & LTC2991_V7_V8_KELVIN_ENABLE) Serial.print(F(" K\n"));
else Serial.print(F(" C\n"));
}
else
{
Serial.print(F("Not Configured"));
}
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_PWM_Tinternal_REG, ®_data);
if (reg_data & LTC2991_PWM_INVERT) Serial.print(F(" 2-Inverted\n"));
else Serial.print(F(" 2-Noninverted\n"));
if (reg_data & LTC2991_PWM_ENABLE) Serial.print(F(" 3-Enabled\n"));
else Serial.print(F(" 3-Disabled\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
}
//! Modify PWM threshold or toggle a PWM setting based on user input.
switch (user_command)
{
case 1:
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, ®_data);
if (reg_data & LTC2991_V7_V8_KELVIN_ENABLE) Serial.print(F("\nEnter Temperature Threshold in Kelvin: "));
else Serial.print(F("\nEnter Temperature Threshold in Celsius: "));
pwm_temp = (int16_t)read_int(); // read the user command
Serial.println(pwm_temp);
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, LTC2991_V7_V8_TEMP_ENABLE, 0x00); // Enables V7-V8
ack |= LTC2991_register_write(LTC2991_I2C_ADDRESS, LTC2991_PWM_THRESHOLD_MSB_REG, pwm_temp >> 1);
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_PWM_Tinternal_REG, (pwm_temp & 0x01) << 7, 0x00);
break;
case 2:
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_PWM_Tinternal_REG, ®_data);
ack |= LTC2991_register_write(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_PWM_Tinternal_REG, reg_data ^ LTC2991_PWM_INVERT);
break;
case 3:
// Enable temperature mode for V7-V8 in case it was in voltage mode
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, LTC2991_V7_V8_TEMP_ENABLE, 0x00);
// Toggle PWM Enable
ack |= LTC2991_register_read(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_PWM_Tinternal_REG, ®_data);
ack |= LTC2991_register_write(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_PWM_Tinternal_REG, reg_data ^ LTC2991_PWM_ENABLE);
break;
default:
if (user_command != 'm')
Serial.println("Incorrect Option");
break;
}
}
while ((user_command != 'm') && (ack != 1));
return(ack);
}Download LTC2991 Linduino .CPP File
/*!
LTC2991: 14-bit Octal I2C Voltage, Current, and Temperature Monitor
@verbatim
The LTC2991 is used to monitor system temperatures, voltages and currents.
Through the I2C serial interface, the eight 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 LTC2991 flexibility to be incorporated in
various systems needing temperature, voltage or current data. The LTC2991 fits
well in systems needing submillivolt voltage resolution, 1% current measurement
and 1 degree Celsius temperature accuracy or any combination of the three.
@endverbatim
http://www.linear.com/product/LTC2991
http://www.linear.com/product/LTC2991#demoboards
REVISION HISTORY
$Revision: 2306 $
$Date: 2014-03-25 16:57:34 -0700 (Tue, 25 Mar 2014) $
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 LTC2991 LTC2991: 14-bit Octal I2C Voltage, Current, and Temperature Monitor
/*! @file
@ingroup LTC2991
Library for LTC2991: 14-bit Octal I2C Voltage, Current, and Temperature Monitor
*/
#include <Arduino.h>
#include <stdint.h>
#include "Linduino.h"
#include "LT_I2C.h"
#include "LTC2991.h"
#include <Wire.h>
// Reads a 14-bit adc_code from LTC2991.
int8_t LTC2991_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 LTC2991 but enforces a maximum timeout.
// Similar to LTC2991_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 LTC2991 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 LTC2991_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
for (timer_count = 0; timer_count < timeout; timer_count++)
{
if(status_bit<8){
ack |= LTC2991_register_read(i2c_address, LTC2991_STATUS_LOW_REG, ®_data); //! 1)Read status register until correct data valid bit is set
}
else {
ack |= LTC2991_register_read(i2c_address, LTC2991_STATUS_HIGH_REG, ®_data); //! 1)Read status register until correct data valid bit is set
if(status_bit==8){
status_bit =1;
}
else {
status_bit = 0;
}
}
if ((ack) || (((reg_data>>status_bit)&0x1)==1)){
break;
}
delay(1);
}
ack |= LTC2991_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){
Serial.println("Data not valid");
Serial.println(*data_valid);
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 LTC2991_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;
ack |= LTC2991_adc_read_timeout(i2c_address, msb_register_address, &(*adc_code), &(*data_valid), timeout, ((msb_register_address/2) - 0x05)); //! 1) Throw away old data
ack |= LTC2991_adc_read_timeout(i2c_address, msb_register_address, &(*adc_code), &(*data_valid), timeout, ((msb_register_address/2) - 0x05)); //! 2) Read new data
return(ack);
}
// Reads an 8-bit register from the LTC2991 using the standard repeated start format.
int8_t LTC2991_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 LTC2991 register.
// Writes to an 8-bit register inside the LTC2991 using the standard I2C repeated start format.
int8_t LTC2991_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 LTC2991_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 |= LTC2991_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 |= LTC2991_register_write(i2c_address, register_address, register_data); //! 3) Write to register with the cleared bits
return(ack);
}
// Calculates the LTC2991 single-ended input voltages
float LTC2991_code_to_single_ended_voltage(int16_t adc_code, float LTC2991_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) * LTC2991_single_ended_lsb * sign; //! 2) Convert code to voltage from lsb
return (voltage);
}
// Calculates the LTC2991 Vcc voltage
float LTC2991_code_to_vcc_voltage(int16_t adc_code, float LTC2991_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) * LTC2991_single_ended_lsb * sign) + 2.5; //! 2) Convert code to Vcc Voltage from single-ended lsb
return (voltage);
}
// Calculates the LTC2991 differential input voltage.
float LTC2991_code_to_differential_voltage(int16_t adc_code, float LTC2991_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) * LTC2991_differential_lsb * sign; //! 2) Convert code to voltage form differential lsb
return (voltage);
}
// Calculates the LTC2991 temperature
float LTC2991_temperature(int16_t adc_code, float LTC2991_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) * LTC2991_temperature_lsb; //! 3) Converts code to temperature from temperature lsb
return (temperature);
}
// Calculates the LTC2991 diode voltage
float LTC2991_code_to_diode_voltage(int16_t adc_code, float LTC2991_diode_voltage_lsb)
{
float voltage;
adc_code = (adc_code & 0x1FFF); //! 1) Removes first 3 bits
voltage = ((float) adc_code) * LTC2991_diode_voltage_lsb; //! 2) Convert code to voltage from diode voltage lsb
return (voltage);
}
Download LTC2991 Linduino Header File
/*!
LTC2991: 14-bit ADC octal I2C voltage, current, and temperature monitor.
@verbatim
The LTC2991 is used to monitor system temperatures, voltages and currents.
Through the I2C serial interface, the eight 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 LTC2991 flexibility to be incorporated in
various systems needing temperature, voltage or current data. The LTC2991 fits
well in systems needing submillivolt 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 |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, 0x00, LTC2991_V1_V2_DIFFERENTIAL_ENABLE | LTC2991_V1_V2_TEMP_ENABLE);
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V1_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_single_ended_voltage(code, LTC2991_SINGLE_ENDED_lsb); // Converts code to voltage from single-ended lsb
Read current from V3-V4.
resistor = 1; // R_sense across V3-V4 in ohms
// Enable Differential Mode
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, LTC2991_V3_V4_DIFFERENTIAL_ENABLE, LTC2991_V3_V4_TEMP_ENABLE);
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V4_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT);
voltage = LTC2991_code_to_differential_voltage(code, LTC2991_DIFFERENTIAL_lsb); // Converts code to voltage from differential lsb
current = voltage / resistor; // Calculates current
Read temperature from diode connected to V7-V8.
// Enable temperature mode.
ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, LTC2991_V7_V8_TEMP_ENABLE, 0x00);
// Flush one ADC reading in case it is stale. Then, take a new fresh reading.
ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V7_MSB_REG, &adc_code, &data_valid, LTC2991_TIMEOUT);
// Converts code to temperature from adc code and temperature lsb
temperature = LTC2991_temperature(adc_code, LTC2991_TEMPERATURE_lsb);
@endverbatim
http://www.linear.com/product/LTC2991
http://www.linear.com/product/LTC2991#demoboards
REVISION HISTORY
$Revision: 2306 $
$Date: 2014-03-25 16:57:34 -0700 (Tue, 25 Mar 2014) $
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 LTC2991
Library Header File for LTC2991: 14-bit Octal I2C Voltage, Current, and Temperature Monitor
*/
#ifndef LTC2991_H
#define LTC2991_H
#include <Wire.h>
// Calibration Variables
//! Typical single-ended LSB weight in volts
const float LTC2991_SINGLE_ENDED_lsb = 3.05176E-04;
//! Typical differential LSB weight in volts
const float LTC2991_DIFFERENTIAL_lsb = 1.90735E-05;
//! Typical VCC LSB weight in volts
const float LTC2991_VCC_lsb = 3.05176E-04;
//! Typical temperature LSB weight in degrees Celsius (and Kelvin).
//! Used for internal temperature as well as remote diode temperature measurements.
const float LTC2991_TEMPERATURE_lsb = 0.0625;
//! Typical remote diode LSB weight in volts.
//! Used to readback diode voltage when in temperature measurement mode.
const float LTC2991_DIODE_VOLTAGE_lsb = 3.815E-05;
/*! @name I2C_Addresses
@{ */
//! I2C address of the LTC2991.
//! Configured by tying the ADR0, ADR1, and ADR2 pins high or low. See Table 1 of datasheet.
//! Uncomment LTC2991_I2C_ADDRESS to match demo board configuration.
// Address assignment
// LTC2991 I2C Address // AD2 AD1 AD0
#define LTC2991_I2C_ADDRESS 0x48 // Low Low Low
// #define LTC2991_I2C_ADDRESS 0x49 // Low Low High
// #define LTC2991_I2C_ADDRESS 0x4A // Low High Low
// #define LTC2991_I2C_ADDRESS 0x4B // Low High High
// #define LTC2991_I2C_ADDRESS 0x4C // High Low Low
// #define LTC2991_I2C_ADDRESS 0x4D // High Low High
// #define LTC2991_I2C_ADDRESS 0x4E // High High Low
// #define LTC2991_I2C_ADDRESS 0x4F // High High High
//! LTC2991 Global I2C Address.
#define LTC2991_I2C_GLOBAL_ADDRESS 0x77 // Global Address
/*! @} */
/*! @name REGISTERS
@{ */
#define LTC2991_STATUS_LOW_REG 0x00 //!< Data_Valid Bits(V1 Through V8)
#define LTC2991_STATUS_HIGH_REG 0x01 //!< Data_valid bits
#define LTC2991_CHANNEL_ENABLE_REG 0x01 //!< Channel Enable, Vcc, T_internal Conversion Status, Trigger
#define LTC2991_CONTROL_V1234_REG 0x06 //!< V1, V2, V3, and V4 Control Register
#define LTC2991_CONTROL_V5678_REG 0x07 //!< V5, V6, V7, AND V8 Control Register
#define LTC2991_CONTROL_PWM_Tinternal_REG 0x08 //!< PWM Threshold and T_internal Control Register
#define LTC2991_PWM_THRESHOLD_MSB_REG 0x09 //!< PWM Threshold
#define LTC2991_V1_MSB_REG 0x0A //!< V1, or T_R1 T MSB
#define LTC2991_V1_LSB_REG 0x0B //!< V1, or T_R1 T LSB
#define LTC2991_V2_MSB_REG 0x0C //!< V2, V1-V2, or T_R2 Voltage MSB
#define LTC2991_V2_LSB_REG 0x0D //!< V2, V1-V2, or T_R2 Voltage LSB
#define LTC2991_V3_MSB_REG 0x0E //!< V3, or T_R2 T MSB
#define LTC2991_V3_LSB_REG 0x0F //!< V3, or T_R2 T LSB
#define LTC2991_V4_MSB_REG 0x10 //!< V4, V3-V4, or T_R2 Voltage MSB
#define LTC2991_V4_LSB_REG 0x11 //!< V4, V3-V4, or T_R2 Voltage LSB
#define LTC2991_V5_MSB_REG 0x12 //!< V5, or T_R3 T MSB
#define LTC2991_V5_LSB_REG 0x13 //!< V5, or T_R3 T LSB
#define LTC2991_V6_MSB_REG 0x14 //!< V6, V5-V6, or T_R3 Voltage MSB
#define LTC2991_V6_LSB_REG 0x15 //!< V6, V5-V6, or T_R3 Voltage LSB
#define LTC2991_V7_MSB_REG 0x16 //!< V7, or T_R4 T MSB
#define LTC2991_V7_LSB_REG 0x17 //!< V7, or T_R4 T LSB
#define LTC2991_V8_MSB_REG 0x18 //!< V8, V7-V8, or T_R4 Voltage MSB
#define LTC2991_V8_LSB_REG 0x19 //!< V8, V7-V8, or T_R4 Voltage LSB
#define LTC2991_T_Internal_MSB_REG 0x1A //!< T_Internal MSB
#define LTC2991_T_Internal_LSB_REG 0x1B //!< T_Internal LSB
#define LTC2991_Vcc_MSB_REG 0x1C //!< Vcc MSB
#define LTC2991_Vcc_LSB_REG 0x1D //!< Vcc LSB
/*! @} */
/*! @name LTC2991_CHANNEL_ENABLE_REG SETTINGS
Bitwise OR settings, and write to LTC2991_CHANNEL_ENABLE_REG to configure settings.
Bitwise AND with value read from LTC2991_CHANNEL_ENABLE_REG to determine present setting.
@{ */
#define LTC2991_V7_V8_TR4_ENABLE 0x80 //!< Enable V7-V8 measurements, including TR4 temperature
#define LTC2991_V5_V6_TR3_ENABLE 0x40 //!< Enable V5-V6 measurements, including TR3 temperature
#define LTC2991_V3_V4_TR2_ENABLE 0x20 //!< Enable V3-V4 measurements, including TR2 temperature
#define LTC2991_V1_V2_TR1_ENABLE 0x10 //!< Enable V1-V2 measurements, including TR1 temperature
#define LTC2991_VCC_TINTERNAL_ENABLE 0x08 //!< Enable Vcc internal voltage measurement
#define LTC2991_ENABLE_ALL_CHANNELS 0xF8 //!< Use to enable all LTC2991 channels. Equivalent to bitwise OR'ing all channel enables.
#define LTC2991_BUSY 0x04 //!< LTC2991 Busy Bit
/*! @} */
/*! @name LTC2991_CONTROL_V1234_REG SETTINGS
Bitwise OR settings, and write to LTC2991_CONTROL_V1234_REG to configure settings.
Bitwise AND with value read from LTC2991_CONTROL_V1234_REG to determine present setting.
@{ */
#define LTC2991_V3_V4_FILTER_ENABLE 0x80 //!< Enable filters on V3-V4
#define LTC2991_V3_V4_KELVIN_ENABLE 0x40 //!< Enable V3-V4 for Kelvin. Otherwise, Celsius.
#define LTC2991_V3_V4_TEMP_ENABLE 0x20 //!< Enable V3-V4 temperature mode.
#define LTC2991_V3_V4_DIFFERENTIAL_ENABLE 0x10 //!< Enable V3-V4 differential mode. Otherwise, single-ended.
#define LTC2991_V1_V2_FILTER_ENABLE 0x08 //!< Enable filters on V1-V2
#define LTC2991_V1_V2_KELVIN_ENABLE 0x04 //!< Enable V1-V2 for Kelvin. Otherwise, Celsius.
#define LTC2991_V1_V2_TEMP_ENABLE 0x02 //!< Enable V1-V2 temperature mode.
#define LTC2991_V1_V2_DIFFERENTIAL_ENABLE 0x01 //!< Enable V1-V2 differential mode. Otherwise, single-ended.
/*! @} */
/*! @name LTC2991_CONTROL_V5678_REG SETTINGS
Bitwise OR settings, and write to LTC2991_CONTROL_V5678_REG to configure settings.
Bitwise AND with value read from LTC2991_CONTROL_V5678_REG to determine present setting.
@{ */
#define LTC2991_V7_V8_FILTER_ENABLE 0x80 //!< Enable filters on V7-V8
#define LTC2991_V7_V8_KELVIN_ENABLE 0x40 //!< Enable V7-V8 for Kelvin. Otherwise, Celsius.
#define LTC2991_V7_V8_TEMP_ENABLE 0x20 //!< Enable V7-V8 temperature mode.
#define LTC2991_V7_V8_DIFFERENTIAL_ENABLE 0x10 //!< Enable V7-V8 differential mode. Otherwise, single-ended.
#define LTC2991_V5_V6_FILTER_ENABLE 0x08 //!< Enable filters on V5-V6
#define LTC2991_V5_V6_KELVIN_ENABLE 0x04 //!< Enable V5-V6 for Kelvin. Otherwise, Celsius.
#define LTC2991_V5_V6_TEMP_ENABLE 0x02 //!< Enable V5-V6 temperature mode.
#define LTC2991_V5_V6_DIFFERENTIAL_ENABLE 0x01 //!< Enable V5-V6 differential mode. Otherwise, single-ended.
/*! @} */
/*! @name LTC2991_CONTROL_PWM_Tinternal_REG SETTINGS
Bitwise OR settings, and write to LTC2991_CONTROL_PWM_Tinternal_REG to configure settings.
Bitwise AND with value read from LTC2991_CONTROL_PWM_Tinternal_REG to determine present setting.
@{ */
#define LTC2991_PWM_0 0x80 //!< PWM threshold Least Significant Bit
#define LTC2991_PWM_INVERT 0x40 //!< Invert PWM
#define LTC2991_PWM_ENABLE 0x20 //!< Enable PWM
#define LTC2991_REPEAT_MODE 0x10 //!< Enable Repeated Aquisition Mode
#define LTC2991_INT_FILTER_ENABLE 0x08 //!< Enable Internal Temperature Filter
#define LTC2991_INT_KELVIN_ENABLE 0x04 //!< Enable internal temperature for Kelvin. Otherwise, Celsius.
/*!@} */
//! Reads a 14-bit adc_code from LTC2991.
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
int8_t LTC2991_adc_read(uint8_t i2c_address, //!< I2C address of the LTC2991. 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 LTC2991 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 LTC2991 but enforces a maximum timeout.
//! Similar to LTC2991_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 LTC2991 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 LTC2991_adc_read_timeout(uint8_t i2c_address, //!< I2C address of the LTC2991. 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 LTC2991 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 millisceonds. If at any time a NACK is received the function aborts.
uint8_t status_bit //!< If the timeout is reached without valid data (*data_valid=1) the function exits.*/
);
//! 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.
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
int8_t LTC2991_adc_read_new_data(uint8_t i2c_address, //!< I2C address of the LTC2991. 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 LTC2991 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 millisceonds. If at any time a NACK is received the function aborts.
If the timeout is reached without valid data (*data_valid=1) the function exits.*/
);
//! Reads an 8-bit register from the LTC2991 using the standard repeated start format.
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
int8_t LTC2991_register_read(uint8_t i2c_address, //!< I2C address of the LTC2991. Configured by tying the ADR0, ADR1, and ADR2 pins high or low. See Table 1 of datasheet.
uint8_t register_address, //!< Address of the LTC2991 register to be read. This is also known as the "command byte".
uint8_t *register_data //!< returns 8-bit value read from the LTC2991 register.
);
//! Write one byte to an LTC2991 register.
//! Writes to an 8-bit register inside the LTC2991 using the standard I2C repeated start format.
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
int8_t LTC2991_register_write(uint8_t i2c_address, //!< I2C address of the LTC2991. Configured by tying the ADR0, ADR1, and ADR2 pins high or low. See Table 1 of datasheet.
uint8_t register_address, //!< Address of the LTC2991 register to be overwritten. This is also known as the "command byte".
uint8_t register_data //!< Value that will be written to the register.
);
//! 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.
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
int8_t LTC2991_register_set_clear_bits(uint8_t i2c_address, //!< I2C address of the LTC2991. Configured by tying the ADR0, ADR1, and ADR2 pins high or low. See Table 1 of datasheet.
uint8_t register_address, //!< Address of the LTC2991 register to be modified.
uint8_t bits_to_set, //!< bits_to_set will be bitwise OR'd with the register.
uint8_t bits_to_clear //!< bits_to_clear will be inverted and bitwise AND'd with the register
);
//! Calculates the LTC2991 single-ended input voltages
//! @return the single-ended voCalculatesltage in volts
float LTC2991_code_to_single_ended_voltage(int16_t adc_code, //!< code read from the adc (from a function such as LTC2991_adc_read)
float LTC2991_single_ended_lsb //!< single-ended LSB weight. If not calibrated, use LTC2991_SINGLE_ENDED_LSB
);
//! Calculates the LTC2991 Vcc voltage
//! @return the Vcc voltage in volts
float LTC2991_code_to_vcc_voltage(int16_t adc_code, //!< code read from the adc (from a function such as LTC2991_adc_read)
float LTC2991_single_ended_lsb //!< Vcc LSB weight. If not calibrated, use LTC2991_VCC_LSB
);
//! Calculates the LTC2991 differential input voltage.
//! @return the differential voltage in volts
float LTC2991_code_to_differential_voltage(int16_t adc_code, //!< code read from the adc (from a function such as LTC2991_adc_read)
float LTC2991_differential_lsb //!< differential LSB weight. If not calibrated, use LTC2991_DIFFERENTIAL_LSB
);
//! Calculates the LTC2991 temperature
//! @return the temperature in degrees Celsius or degrees Kevlin (dependent on mode setting).
float LTC2991_temperature(int16_t adc_code, //!< code read from the adc (from a function such as LTC2991_adc_read).
float LTC2991_temperature_lsb, //!< temperature LSB weight. If not calibrated, use LTC2991_TEMPERATURE_LSB
boolean unit //!< The temperature unit, true for Kelvin, false for Celsius
);
//! Calcultates the LTC2991 diode voltage
//! @return the diode voltage in volts.
float LTC2991_code_to_diode_voltage(int16_t adc_code, //!< code read from the adc (from a function such as LTC2991_adc_read)
float LTC2991_diode_voltage_lsb //!< diode voltage LSB weight. If not calibrated, use LTC2991_DIODE_VOLTAGE_LSB
);
#endif // LTC2991_H
Technical Support
- For immediate technical assistance, contact your local sales office or distributor or call 1-800-4-LINEAR (US customers only) or 408-432-1900.
- For less urgent requests, please complete our Technical Support Request Form. Please allow 2-3 business days for reply.
