Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board

DC2156A LTC2946: 12-Bit Wide Range Power, Charge and Energy Monitor. More...

Detailed Description

DC2156A LTC2946: 12-Bit Wide Range Power, Charge and Energy Monitor.

Setting the Alert Thresholds:
    1. Select the Alert option from the main menu.
    2. Select the desired Thresholds to be changed. Then enter the minimum and maximum
       values.
    3. Select the Enable and Disable Alert Option and Enable the desired alerts.
    4. Lastly, go back to the main menu and start reading values in Continuous Mode
       or Snapshot Mode.
       Note: Alerts only respond when conversion is done. Therefore, in continuous
       mode the alerts will constantly be updated.

Reading and Clearing an Alert:
    1. Select the Alert option from the main menu.
    2. Select the Read and Clear Alerts option. This reads all faults that occured
       and clears the alerts.

NOTES
 Setup:
 Set the terminal baud rate to 115200 and select the newline terminator.
 Requires a power supply.
 Refer to demo manual DC2156A.

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

Copyright 2018(c) Analog Devices, Inc.

All rights reserved.

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

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • 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.
  • Neither the name of Analog Devices, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
  • The use of this software may or may not infringe the patent rights of one or more patent holders. This license does not release you from the requirement that you obtain separate licenses from these patent holders to use this software.
  • Use of the software either in source or binary form, must be run on or directly connected to an Analog Devices Inc. component.

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, 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.

Definition in file DC2156.ino.

Go to the source code of this file.

Data Structures

union  eeprom_data_union
 Used to manipulate EEPROM data. More...
 
struct  eeprom_data_union::data_struct_type
 EEPROM data structure. More...
 

Functions

static void print_title ()
 Print the title block. More...
 
static void print_prompt ()
 Print the Prompt. More...
 
static void store_alert_settings ()
 Store the alert settings to the EEPROM. More...
 
static int8_t restore_alert_settings ()
 Read the alert settings from EEPROM. More...
 
static int8_t menu_1_continuous_mode (uint8_t CTRLA, uint8_t VOLTAGE_SEL, float scale)
 Continuous Mode. More...
 
static int8_t menu_2_snapshot_mode (uint8_t VOLTAGE_SEL, float scale)
 Snapshot Mode Menu. More...
 
static int8_t menu_2_snapshot_mode_menu_1_SENSE ()
 SENSE+ - Snapshot mode. More...
 
static int8_t menu_2_snapshot_mode_menu_2_ADIN (float scale)
 ADIN - Snapshot Mode. More...
 
static int8_t menu_2_snapshot_mode_menu_3_VDD ()
 VDD - Snapshot Mode. More...
 
static int8_t menu_2_snapshot_mode_menu_4_Current ()
 Current - Snapshot Mode. More...
 
static int8_t menu_3_alert (uint8_t VOLTAGE_SEL, float scale)
 Alert and Threshold Menu. More...
 
static int8_t menu_3_alert_menu_1_set_power_alerts (uint8_t VOLTAGE_SEL, float scale)
 Set Power Alert Thresholds. More...
 
static int8_t menu_3_alert_menu_2_set_current_alerts ()
 Set Current Alert Thresholds. More...
 
static int8_t menu_3_alert_menu_3_set_vin_alerts ()
 Set VIN Alert Thresholds. More...
 
static int8_t menu_3_alert_menu_4_set_adin_alerts (float scale)
 Set ADIN Alert Thresholds. More...
 
static int8_t menu_3_alert_menu_5_enable_disable_alerts ()
 Enable/Disable Alert Menu. More...
 
static int8_t menu_3_alert_menu_5_enable_disable_alerts_menu_1_ALERT1 ()
 Enable/Disable Alert in ALERT1 Register. More...
 
static int8_t menu_3_alert_menu_5_enable_disable_alerts_menu_2_ALERT2 ()
 
static int8_t menu_3_alert_menu_6_read_clear_faults ()
 Read Faults and Clear. More...
 
static int8_t menu_4_shutdown (uint8_t *CTRLB, uint8_t *shutdown)
 Toggle Shutdown Down Mode. More...
 
static int8_t menu_5_settings (uint8_t *CTRLA, uint8_t *CTRLB, uint8_t *VOLTAGE_SEL, uint8_t *GPIO_CFG, uint8_t *GPIO3_CTRL, float *scale)
 Change Settings. More...
 
static int8_t menu_5_settings_menu_1_configure_CTRLA_reg (uint8_t *CTRLA, uint8_t *VOLTAGE_SEL)
 Configure CTRLA Register. More...
 
static void menu_5_settings_menu_1_configure_CTRLA_reg_menu_1_ADIN_Configuration (uint8_t *CTRLA)
 Configure the ADIN reference to GND/INTVCC. More...
 
static void menu_5_settings_menu_1_configure_CTRLA_reg_menu_2_Offset_Configuration (uint8_t *CTRLA)
 Configure frequency of offset calibration. More...
 
static void menu_5_settings_menu_1_configure_CTRLA_reg_menu_3_Voltage_Configuration (uint8_t *CTRLA, uint8_t *VOLTAGE_SEL)
 Select the voltage measurement channel. More...
 
static void menu_5_settings_menu_1_configure_CTRLA_reg_menu_4_Channel_Configuration (uint8_t *CTRLA)
 Select duty cycle of measurments and channel configuration. More...
 
static int8_t menu_5_settings_menu_2_configure_CTRLB_reg (uint8_t *CTRLB)
 Configure CTRLB Register. More...
 
static int8_t menu_5_settings_menu_3_configure_GPIO (uint8_t *GPIO_CFG, uint8_t *GPIO3_CTRL)
 Configure GPIO pin States. More...
 
static void menu_5_settings_menu_4_scaling_for_ADIN (uint8_t *scale)
 Select duty cycle of measurments and channel configuration. More...
 
static int8_t menu_6_clear_min_max ()
 Clear Min/Max. More...
 
static void setup ()
 Initialize Linduino. More...
 
static void loop ()
 Repeats Linduino loop. More...
 

Macros

#define CONTINUOUS_MODE_DISPLAY_DELAY   2000
 The delay between readings. More...
 

Variables

const float resistor = .02
 resistor value on demo board More...
 
const float CLK_FREQ = 4E6
 CLK Frequency. More...
 
const float LTC2946_ADIN_lsb = 5.001221E-04
 Typical ADIN lsb weight in volts. More...
 
const float LTC2946_DELTA_SENSE_lsb = 2.5006105E-05
 Typical Delta lsb weight in volts. More...
 
const float LTC2946_VIN_lsb = 2.5006105E-02
 Typical VIN lsb weight in volts. More...
 
const float LTC2946_Power_lsb = 6.25305E-07
 Typical POWER lsb weight in V^2 VIN_lsb * DELTA_SENSE_lsb. More...
 
const float LTC2946_ADIN_DELTA_SENSE_lsb = 1.25061E-08
 Typical sense lsb weight in V^2 *ADIN_lsb * DELTA_SENSE_lsb. More...
 
const float LTC2946_INTERNAL_TIME_lsb = 4101.00/250000.00
 Internal TimeBase lsb. More...
 
static float LTC2946_TIME_lsb = 16.39543E-3
 Static variable which is based off of the default clk frequency of 250KHz. More...
 
const char ack_error [] = "Error: No Acknowledge. Check I2C Address."
 Error message. More...
 
static int8_t demo_board_connected
 Set to 1 if the board is connected. More...
 
static uint8_t alert1_code = 0
 Value stored or read from ALERT1 register. More...
 
static uint8_t alert2_code = 0
 Value stored or read from ALERT2 register. More...
 
static bool internalCLK = true
 

Function Documentation

◆ loop()

static void loop ( void  )
static

Repeats Linduino loop.

Definition at line 168 of file DC2156.ino.

◆ menu_1_continuous_mode()

static int8_t menu_1_continuous_mode ( uint8_t  CTRLA,
uint8_t  VOLTAGE_SEL,
float  scale 
)
static

Continuous Mode.

Returns
Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
Parameters
CTRLACTRLA Register sets the mode in which Continious measurements are made. Configured in "Settings" menu.
VOLTAGE_SELVOLTAGE_SEL variable represents the voltage channel selected. Scaling is done if ADIN channel is selected and resistive dividers are present.
scaleStores division ratio for resistive divider on ADIN pin. Configured inside "Settings" menu.

Definition at line 257 of file DC2156.ino.

◆ menu_2_snapshot_mode()

static int8_t menu_2_snapshot_mode ( uint8_t  VOLTAGE_SEL,
float  scale 
)
static

Snapshot Mode Menu.

Returns
Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
Parameters
VOLTAGE_SELVOLTAGE_SEL variable represents the voltage channel selected. Scaling is done if ADIN channel is selected and resistive dividers are present.
scaleStores division ratio for resistive divider on ADIN pin. Configured inside "Settings" menu.

Definition at line 453 of file DC2156.ino.

◆ menu_2_snapshot_mode_menu_1_SENSE()

static int8_t menu_2_snapshot_mode_menu_1_SENSE ( )
static

SENSE+ - Snapshot mode.

Returns
Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.

Definition at line 527 of file DC2156.ino.

◆ menu_2_snapshot_mode_menu_2_ADIN()

static int8_t menu_2_snapshot_mode_menu_2_ADIN ( float  scale)
static

ADIN - Snapshot Mode.

Returns
Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.

Definition at line 554 of file DC2156.ino.

◆ menu_2_snapshot_mode_menu_3_VDD()

static int8_t menu_2_snapshot_mode_menu_3_VDD ( )
static

VDD - Snapshot Mode.

Returns
Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.

Definition at line 581 of file DC2156.ino.

◆ menu_2_snapshot_mode_menu_4_Current()

static int8_t menu_2_snapshot_mode_menu_4_Current ( )
static

Current - Snapshot Mode.

Returns
Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.

Definition at line 608 of file DC2156.ino.

◆ menu_3_alert()

static int8_t menu_3_alert ( uint8_t  VOLTAGE_SEL,
float  scale 
)
static

Alert and Threshold Menu.

Returns
Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
Parameters
VOLTAGE_SELVoltage Selection Variable.
scaleStores division ratio for resistive divider on ADIN pin. Configured inside "Settings" menu.

Definition at line 636 of file DC2156.ino.

◆ menu_3_alert_menu_1_set_power_alerts()

static int8_t menu_3_alert_menu_1_set_power_alerts ( uint8_t  VOLTAGE_SEL,
float  scale 
)
static

Set Power Alert Thresholds.

Returns
Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
Parameters
VOLTAGE_SELChoose whether power multiplier uses ADIN pin or SENSE pin as voltage input (A0 bit in CONTROL Register A)
scaleScale value based on resistive divider on the ADIN pin.

Definition at line 703 of file DC2156.ino.

◆ menu_3_alert_menu_2_set_current_alerts()

static int8_t menu_3_alert_menu_2_set_current_alerts ( )
static

Set Current Alert Thresholds.

Returns
Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.

Definition at line 738 of file DC2156.ino.

◆ menu_3_alert_menu_3_set_vin_alerts()

static int8_t menu_3_alert_menu_3_set_vin_alerts ( )
static

Set VIN Alert Thresholds.

Returns
Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.

Definition at line 766 of file DC2156.ino.

◆ menu_3_alert_menu_4_set_adin_alerts()

static int8_t menu_3_alert_menu_4_set_adin_alerts ( float  scale)
static

Set ADIN Alert Thresholds.

Returns
Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
Parameters
scaleScale value based on resistive divider on the ADIN pin.

Definition at line 793 of file DC2156.ino.

◆ menu_3_alert_menu_5_enable_disable_alerts()

static int8_t menu_3_alert_menu_5_enable_disable_alerts ( )
static

Enable/Disable Alert Menu.

Returns
Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.

Definition at line 822 of file DC2156.ino.

◆ menu_3_alert_menu_5_enable_disable_alerts_menu_1_ALERT1()

static int8_t menu_3_alert_menu_5_enable_disable_alerts_menu_1_ALERT1 ( )
static

Enable/Disable Alert in ALERT1 Register.

Returns
Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.

Definition at line 858 of file DC2156.ino.

◆ menu_3_alert_menu_5_enable_disable_alerts_menu_2_ALERT2()

static int8_t menu_3_alert_menu_5_enable_disable_alerts_menu_2_ALERT2 ( )
static
Returns
Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.

Definition at line 984 of file DC2156.ino.

◆ menu_3_alert_menu_6_read_clear_faults()

static int8_t menu_3_alert_menu_6_read_clear_faults ( )
static

Read Faults and Clear.

Returns
Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.

Definition at line 1109 of file DC2156.ino.

◆ menu_4_shutdown()

static int8_t menu_4_shutdown ( uint8_t *  CTRLB,
uint8_t *  shutdown 
)
static

Toggle Shutdown Down Mode.

Returns
Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.

Definition at line 1143 of file DC2156.ino.

◆ menu_5_settings()

static int8_t menu_5_settings ( uint8_t *  CTRLA,
uint8_t *  CTRLB,
uint8_t *  VOLTAGE_SEL,
uint8_t *  GPIO_CFG,
uint8_t *  GPIO3_CTRL,
float *  scale 
)
static

Change Settings.

Returns
Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
Parameters
CTRLALocal Copy of Configuration in CTRLA Register.
CTRLBLocal Copy of Configuration in CTRLB Register.
VOLTAGE_SELLocal Copy of Voltage Selection Channel.
GPIO_CFGLocal Copy of GPIO_CFG Register. Allows Configuration of GPIO1 and GPIO2 Pin states.
GPIO3_CTRLLocal Copy of GPIO3_CTRL Register. Allows Configuration of GPIO3 Pin
scaleStores division ratio for resistive divider on ADIN pin.

Definition at line 1169 of file DC2156.ino.

◆ menu_5_settings_menu_1_configure_CTRLA_reg()

static int8_t menu_5_settings_menu_1_configure_CTRLA_reg ( uint8_t *  CTRLA,
uint8_t *  VOLTAGE_SEL 
)
static

Configure CTRLA Register.

Returns
Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
Parameters
CTRLALocal Copy of CTRLA Register.
VOLTAGE_SELLocal Copy of VOLTAGE_SEL. Indicates which voltage channel has been selected for power measurement.

Definition at line 1216 of file DC2156.ino.

◆ menu_5_settings_menu_1_configure_CTRLA_reg_menu_1_ADIN_Configuration()

static void menu_5_settings_menu_1_configure_CTRLA_reg_menu_1_ADIN_Configuration ( uint8_t *  CTRLA)
static

Configure the ADIN reference to GND/INTVCC.

Definition at line 1268 of file DC2156.ino.

◆ menu_5_settings_menu_1_configure_CTRLA_reg_menu_2_Offset_Configuration()

static void menu_5_settings_menu_1_configure_CTRLA_reg_menu_2_Offset_Configuration ( uint8_t *  CTRLA)
static

Configure frequency of offset calibration.

Definition at line 1296 of file DC2156.ino.

◆ menu_5_settings_menu_1_configure_CTRLA_reg_menu_3_Voltage_Configuration()

static void menu_5_settings_menu_1_configure_CTRLA_reg_menu_3_Voltage_Configuration ( uint8_t *  CTRLA,
uint8_t *  VOLTAGE_SEL 
)
static

Select the voltage measurement channel.

Parameters
CTRLALocal copy of CTRLA register.
VOLTAGE_SELVoltage selection variable.

Definition at line 1337 of file DC2156.ino.

◆ menu_5_settings_menu_1_configure_CTRLA_reg_menu_4_Channel_Configuration()

static void menu_5_settings_menu_1_configure_CTRLA_reg_menu_4_Channel_Configuration ( uint8_t *  CTRLA)
static

Select duty cycle of measurments and channel configuration.

Parameters
CTRLALocal copy of CTRLA Register

Definition at line 1378 of file DC2156.ino.

◆ menu_5_settings_menu_2_configure_CTRLB_reg()

static int8_t menu_5_settings_menu_2_configure_CTRLB_reg ( uint8_t *  CTRLB)
static

Configure CTRLB Register.

Returns
Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
Parameters
CTRLBLocal copy of CTRLB register.

Definition at line 1440 of file DC2156.ino.

◆ menu_5_settings_menu_3_configure_GPIO()

static int8_t menu_5_settings_menu_3_configure_GPIO ( uint8_t *  GPIO_CFG,
uint8_t *  GPIO3_CTRL 
)
static

Configure GPIO pin States.

Returns
Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
Parameters
GPIO_CFGLocal copy of GPIO_CFG register.
GPIO3_CTRLLocal copy of GPIO3_CTRL register.

Definition at line 1582 of file DC2156.ino.

◆ menu_5_settings_menu_4_scaling_for_ADIN()

static void menu_5_settings_menu_4_scaling_for_ADIN ( uint8_t *  scale)
static

Select duty cycle of measurments and channel configuration.

Parameters
scaleStores division ratio for resistive divider on ADIN pin.

Definition at line 1737 of file DC2156.ino.

◆ menu_6_clear_min_max()

static int8_t menu_6_clear_min_max ( )
static

Clear Min/Max.

Returns
Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.

Definition at line 1753 of file DC2156.ino.

◆ print_prompt()

static void print_prompt ( )
static

Print the Prompt.

Definition at line 245 of file DC2156.ino.

◆ print_title()

static void print_title ( void  )
static

Print the title block.

Definition at line 232 of file DC2156.ino.

◆ restore_alert_settings()

static int8_t restore_alert_settings ( )
static

Read the alert settings from EEPROM.

Returns
Return 1 if successful, 0 if not

Definition at line 1793 of file DC2156.ino.

◆ setup()

static void setup ( void  )
static

Initialize Linduino.

Definition at line 146 of file DC2156.ino.

◆ store_alert_settings()

static void store_alert_settings ( )
static

Store the alert settings to the EEPROM.

Definition at line 1832 of file DC2156.ino.

Macro Definition Documentation

◆ CONTINUOUS_MODE_DISPLAY_DELAY

#define CONTINUOUS_MODE_DISPLAY_DELAY   2000

The delay between readings.

Definition at line 120 of file DC2156.ino.

Variable Documentation

◆ ack_error

const char ack_error[] = "Error: No Acknowledge. Check I2C Address."

Error message.

Definition at line 137 of file DC2156.ino.

◆ alert1_code

uint8_t alert1_code = 0
static

Value stored or read from ALERT1 register.

Shared between loop() and restore_alert_settings()

Definition at line 141 of file DC2156.ino.

◆ alert2_code

uint8_t alert2_code = 0
static

Value stored or read from ALERT2 register.

Shared between loop() and restore_alert_settings()

Definition at line 142 of file DC2156.ino.

◆ CLK_FREQ

const float CLK_FREQ = 4E6

CLK Frequency.

Definition at line 123 of file DC2156.ino.

◆ demo_board_connected

int8_t demo_board_connected
static

Set to 1 if the board is connected.

Definition at line 140 of file DC2156.ino.

◆ internalCLK

bool internalCLK = true
static

Definition at line 143 of file DC2156.ino.

◆ LTC2946_ADIN_DELTA_SENSE_lsb

const float LTC2946_ADIN_DELTA_SENSE_lsb = 1.25061E-08

Typical sense lsb weight in V^2 *ADIN_lsb * DELTA_SENSE_lsb.

Definition at line 131 of file DC2156.ino.

◆ LTC2946_ADIN_lsb

const float LTC2946_ADIN_lsb = 5.001221E-04

Typical ADIN lsb weight in volts.

Definition at line 127 of file DC2156.ino.

◆ LTC2946_DELTA_SENSE_lsb

const float LTC2946_DELTA_SENSE_lsb = 2.5006105E-05

Typical Delta lsb weight in volts.

Definition at line 128 of file DC2156.ino.

◆ LTC2946_INTERNAL_TIME_lsb

const float LTC2946_INTERNAL_TIME_lsb = 4101.00/250000.00

Internal TimeBase lsb.

Use LTC2946_TIME_lsb if an external CLK is used. See Settings menu for how to calculate Time LSB.

Definition at line 132 of file DC2156.ino.

◆ LTC2946_Power_lsb

const float LTC2946_Power_lsb = 6.25305E-07

Typical POWER lsb weight in V^2 VIN_lsb * DELTA_SENSE_lsb.

Definition at line 130 of file DC2156.ino.

◆ LTC2946_TIME_lsb

float LTC2946_TIME_lsb = 16.39543E-3
static

Static variable which is based off of the default clk frequency of 250KHz.

Definition at line 134 of file DC2156.ino.

◆ LTC2946_VIN_lsb

const float LTC2946_VIN_lsb = 2.5006105E-02

Typical VIN lsb weight in volts.

Definition at line 129 of file DC2156.ino.

◆ resistor

const float resistor = .02

resistor value on demo board

Definition at line 122 of file DC2156.ino.