94 #define LTC3335_BASE_ADDRESS 0x64 95 #define LTC3335_WRITE_BIT 0
96 #define LTC3335_READ_BIT 1
102 #define LTC3335_REGISTER_A 01 103 #define LTC3335_REGISTER_B 02
104 #define LTC3335_REGISTER_C 03
105 #define LTC3335_REGISTER_D 04
106 #define LTC3335_REGISTER_E 05
107 #define LTC3335_INVALID 0xFF
131 #if LTC3335_USE_CURRENT_MEASUREMENT == true 136 #endif // #if LTC3335_USE_CURRENT_MEASUREMENT == true 141 #if LTC3335_USE_SOFTWARE_CORRECTION == true 145 #endif // #if LTC3335_USE_SOFTWARE_CORRECTION == true 165 uint8_t ltc3335_data;
183 #if LTC3335_USE_SOFTWARE_CORRECTION == false 187 #endif // #if LTC3335_USE_SOFTWARE_CORRECTION == false 193 #if LTC3335_USE_SOFTWARE_CORRECTION == true 199 #endif // #if LTC3335_USE_SOFTWARE_CORRECTION == true 209 uint8_t ltc3335_data;
228 uint8_t ltc3335_data;
235 if (ltc3335_data & MASK(1, 0))
244 if (ltc3335_data & MASK(1, 1))
253 if (ltc3335_data & MASK(1, 2))
271 uint8_t ltc3335_data;
304 #if LTC3335_USE_SOFTWARE_CORRECTION == false 308 int8_t result =
true;
309 uint8_t ltc3335_data;
327 uint8_t ltc3335_data;
338 mAs += ((mAs * temp16 + (1L << 15)) >> 16) | (temp16 < 0 ? 0xFFFF0000LL : 0);
356 #endif // LTC3335_USE_SOFTWARE_CORRECTION == false 363 uint8_t ltc3335_data;
366 ltc3335_data = ((enabled ==
true) ? MASK(1, 1) : 0);
375 #if LTC3335_USE_CURRENT_MEASUREMENT == true 394 #if LTC3335_USE_CURRENT_MEASUREMENT == true 429 #if LTC3335_USE_SOFTWARE_CORRECTION == false 440 if (uAs >= (1L << 16))
442 *microamps = (1L << 16) - 1;
446 *microamps = (uint16_t) uAs;
472 uAs += ((uAs * temp16 + (1L << 15)) >> 16) | (temp16 < 0 ? 0xFFFF000000000000LL : 0);
475 if (uAs >= (1L << 16))
477 *microamps = (1L << 16) - 1;
481 *microamps = (uint16_t) uAs;
495 #endif // #if LTC3335_USE_SOFTWARE_CORRECTION == false 496 #endif // #if LTC3335_USE_CURRENT_MEASUREMENT == true 519 result |=
i2c_read_byte(LTC3335_BASE_ADDRESS, ltc3335_data_ptr);
526 return ((enabled ==
true) ? (1 << 7) : 0) | (voltage << 4) | prescaler;
int8_t LTC3335_Reset_Counter_Test_Current(void)
Resets the number of edges and the amount of time stored for the Counter Test feature.
void LTC3335_Counter_Test_Current_Task(void)
Task that must be run periodically, for the edges and time to be stored for the LTC3335 Counter Test ...
#define LTC3335_VBAT_TYP
in mV, the nominal battery voltage expected for the majority of the battery discharge.
int8_t i2c_write_byte(uint8_t address, uint8_t value)
Write "value" byte to device at "address".
static uint16_t ltc3335_hw_timer_last
last value of the hardware timer accessed by LTC3335 driver.
int8_t LTC3335_Get_Alarms(LTC3335_ALARM_TYPE *alarms)
Gets the alarms active from the LTC3335.
LTC3335_OUTPUT_VOLTAGE_TYPE
#define LTC3335_MICRO_INIT()
unsigned ac_on_time_overflow
AC(ON) time operating fault (tAC > tFS) due to improperly chosen inductor value timing out the AC(ON)...
static uint32_t discharged_capacity
in mAs, the discharged capacity calculated from the LTC3335 accumulator and
#define LTC3335_TIMER_GET()
static void ltc3335_decode_register_a(uint8_t register_a)
static uint32_t ltc3335_discharged_capacity
static uint32_t ltc3335_counter_test_edge_count
the number of rising edges on the /IRQ pin since the Counter Test results were last cleared...
int8_t LTC3335_Set_Counter_Test(boolean enabled)
Enables/Disables the LTC3335 Counter Test feature.
int8_t LTC3335_Init(void)
Verify that battery capacity isn't so gigantic that it would overflow a 32 bit number.
static uint8_t ltc3335_subaddress_last
last subaddress written, so that it is not repeatedly sent when the same register is polled...
static uint16_t vbat
battery voltage, optimally measured with an adc, set to a constant in this sketch ...
int8_t LTC3335_Get_Discharged_Capacity(uint32_t *discharged_capacity)
Gets the discharged capacity from the battery in mAs.
#define LTC3335_RESOLUTION(p)
Macro to retrieve the LTC3335 coulomb count resolution with a given prescaler.
unsigned coulomb_counter_overflow
Coulomb counter operating fault due to an improperly chosen prescalar causing the ripple counter to o...
#define LTC3335_COUNTER_GET()
LTC3335_ALARM_TYPE alarms
active alarms read from the LTC3335.
static boolean ltc3335_voltage_selection_enabled_last
last enable for software selected voltage.
#define LTC3335_TIMER_COUNTS_PER_SEC
int8_t i2c_write_byte_data(uint8_t address, uint8_t command, uint8_t value)
Write a byte of data to register specified by "command".
static uint16_t ltc3335_hw_counter_last
last value of the hardware counter accessed by LTC3335 driver.
LTC3335: Nanopower Buck-Boost DC/DC with Integrated Coulomb Counter.
#define LTC3335_USE_CURRENT_MEASUREMENT
Set to true to use the /IRQ pin to measure the battery current real time.
static uint32_t ltc3335_quiescent_current_timer
int8_t LTC3335_Get_Counter_Test_Current(uint16_t *microamps)
Gets the battery current in uA.
int8_t LTC3335_Set_Voltage(boolean enabled, LTC3335_OUTPUT_VOLTAGE_TYPE voltage)
Enables/Disables software control of the LTC3335 output voltage.
#define LTC3335_TFS
in s, full scale ON time from page 15 of datasheet.
int16_t LTC3335_Get_Software_Correction_Factor(uint16_t vbat)
Returns the software correction factor for a specified LTC3335_IPEAK_CONFIGURATION, LTC3335_OUTPUT_VOLTAGE, and battery voltage.
static uint8_t ltc3335_encode_register_a(boolean enabled, LTC3335_OUTPUT_VOLTAGE_TYPE voltage, uint8_t prescaler)
#define LTC3335_OUTPUT_VOLTAGE
VOUT setting from LTC3335_NUM_OUTPUT_VOLTAGES in LTC3335.h.
static int8_t ltc3335_set_register(uint8_t subaddress, uint8_t *ltc3335_data)
#define LTC3335_PRESCALER
Macro to select the optimal prescaler for the specified battery capacity at compile time...
static uint8_t ltc3335_prescaler_last
last prescaler selected.
#define LTC3335_TIMER_COUNTS_PER_IQ_MAS
counts for iq current to accumulate to 1 mAs
static uint32_t ltc3335_counter_test_time
the amount of timer ticks since the Counter Test results were last cleared.
unsigned alarm_trip
Accumulator value has met or exceeded the alarm threshold value.
static boolean ltc3335_counter_test_last
value of the counter test bit last written to the LTC3335.
#define LTC3335_IPEAK_MA
mA = 100mA, used in calculations of coulomb count and current.
static LTC3335_OUTPUT_VOLTAGE_TYPE ltc3335_voltage_selection_last
last voltage selected through software.
#define LTC3335_NUM_OUTPUT_VOLTAGES
#define LTC3335_CORRECTION_FACTOR_TYP
Value of LTC3335_Software_Correction_Table[VBAT_TO_TABLE_INDEX(LTC3335_VBAT_TYP)].
int8_t LTC3335_Clear_Int(LTC3335_ALARM_TYPE *alarms)
Sends the command to clear the INT condition.
static uint8_t ltc3335_accumulator_last
static int8_t ltc3335_get_register(uint8_t subaddress, uint8_t *ltc3335_data)
The alarm conditions which cause the LTC3335 to activate the /INT pin.
int8_t i2c_read_byte(uint8_t address, uint8_t *value)
Read a byte, store in "value".
#define LTC3335_ALARM_CAPACITY
in mAh, the capacity at which the alarm should be activated.