90 #define NBITS2(n) ((n&2)?1:0) 91 #define NBITS4(n) ((n&(0xC))?(2+NBITS2(n>>2)):(NBITS2(n))) 92 #define NBITS8(n) ((n&0xF0)?(4+NBITS4(n>>4)):(NBITS4(n))) 93 #define NBITS16(n) ((n&0xFF00)?(8+NBITS8(n>>8)):(NBITS8(n))) 94 #define NBITS32(n) ((n&0xFFFF0000)?(16+NBITS16(n>>16)):(NBITS16(n))) 95 #define NBITS(n) (n==0?0:NBITS32(1L*n)+1) 98 #define MASK(size, shift) (((1LL << (size)) - 1) << (shift)) 101 #define MV_PER_V 1000 102 #define MA_PER_A 1000 103 #define UA_PER_MA 1000 104 #define SEC_PER_HR 3600 105 #define MS_PER_SEC 1000 111 #define LTC3335_BAUD_RATE 400 112 #define LTC3335_PRESCALER_MAX 15
113 #define LTC3335_TFS (11.74e-6)
114 #define LTC3335_IQ (680e-9)
121 #define LTC3335_OUTPUT_VOLTAGE_1_8V 0 122 #define LTC3335_OUTPUT_VOLTAGE_2_5V 1 123 #define LTC3335_OUTPUT_VOLTAGE_2_8V 2 124 #define LTC3335_OUTPUT_VOLTAGE_3_0V 3 125 #define LTC3335_OUTPUT_VOLTAGE_3_3V 4 126 #define LTC3335_OUTPUT_VOLTAGE_3_6V 5 127 #define LTC3335_OUTPUT_VOLTAGE_4_5V 6 128 #define LTC3335_OUTPUT_VOLTAGE_5_0V 7 129 #define LTC3335_NUM_OUTPUT_VOLTAGES 8 140 #define LTC3335_IPEAK_CONFIGURATION_5MA 0 141 #define LTC3335_IPEAK_CONFIGURATION_10MA 1 142 #define LTC3335_IPEAK_CONFIGURATION_15MA 2 143 #define LTC3335_IPEAK_CONFIGURATION_25MA 3 144 #define LTC3335_IPEAK_CONFIGURATION_50MA 4 145 #define LTC3335_IPEAK_CONFIGURATION_100MA 5 146 #define LTC3335_IPEAK_CONFIGURATION_150MA 6 147 #define LTC3335_IPEAK_CONFIGURATION_250MA 7 148 #define LTC3335_NUM_IPEAK 8 161 #define LTC3335_TIMER_COUNTS_PER_IQ_MAS ((uint32_t)(LTC3335_TIMER_COUNTS_PER_SEC/(LTC3335_IQ * MA_PER_A))) 164 #define LTC3335_MIN_CURRENT_TASK_RATE ((1LL << LTC3335_COUNTER_SIZE) * 2 * LTC3335_TFS) 167 #if LTC3335_IPEAK_CONFIGURATION == LTC3335_IPEAK_CONFIGURATION_5MA 168 #define LTC3335_IPEAK_MA 5 169 #elif LTC3335_IPEAK_CONFIGURATION == LTC3335_IPEAK_CONFIGURATION_10MA
170 #define LTC3335_IPEAK_MA 10 171 #elif LTC3335_IPEAK_CONFIGURATION == LTC3335_IPEAK_CONFIGURATION_15MA
172 #define LTC3335_IPEAK_MA 15 173 #elif LTC3335_IPEAK_CONFIGURATION == LTC3335_IPEAK_CONFIGURATION_25MA
174 #define LTC3335_IPEAK_MA 25 175 #elif LTC3335_IPEAK_CONFIGURATION == LTC3335_IPEAK_CONFIGURATION_50MA
176 #define LTC3335_IPEAK_MA 50 177 #elif LTC3335_IPEAK_CONFIGURATION == LTC3335_IPEAK_CONFIGURATION_100MA
178 #define LTC3335_IPEAK_MA 100 179 #elif LTC3335_IPEAK_CONFIGURATION == LTC3335_IPEAK_CONFIGURATION_150MA
180 #define LTC3335_IPEAK_MA 150 181 #elif LTC3335_IPEAK_CONFIGURATION == LTC3335_IPEAK_CONFIGURATION_250MA
182 #define LTC3335_IPEAK_MA 250 184 #error Must configure firmware for IPEAK value. 188 #define LTC3335_PRESCALER (LTC3335_PRESCALER_MAX - NBITS( (uint32_t)(1L*LTC3335_CAPACITY*SEC_PER_HR/LTC3335_RANGE(LTC3335_PRESCALER_MAX)) ) ) 191 #if LTC3335_USE_SOFTWARE_CORRECTION == true 192 #define LTC3335_RANGE(p) ((uint32_t)(255LL * LTC3335_RESOLUTION(p) * ((1LL << 16) + LTC3335_CORRECTION_FACTOR_TYP) / (1L << 16))) 194 #define LTC3335_RANGE(p) ((uint32_t)(255LL * LTC3335_RESOLUTION(p))) 198 #define LTC3335_RESOLUTION(p) ((uint32_t)(LTC3335_IPEAK_MA * LTC3335_TFS * (1LL << (42 - 1 - p)) / 255 + 0.5)) 201 #if LTC3335_CAPACITY*SEC_PER_HR > ((1LL << 32) - 1) 202 #error Battery Capacity is larger than 32 bit number. Change 32bit capacity variables into 64bit. 206 #if LTC3335_CAPACITY*SEC_PER_HR < ((1L << 8) * 100 / 2) 207 #error Battery Capacity is so small that units of mAs result in more than 1% discretization error. Change code units to uAs. 245 #if LTC3335_USE_SOFTWARE_CORRECTION == false 256 #endif // LTC3335_USE_SOFTWARE_CORRECTION == false 258 #if LTC3335_USE_CURRENT_MEASUREMENT == true 259 #if LTC3335_USE_SOFTWARE_CORRECTION == false 270 #endif // LTC3335_USE_SOFTWARE_CORRECTION == false 280 #endif // LTC3335_USE_CURRENT_MEASUREMENT == true 282 #if LTC3335_USE_SOFTWARE_CORRECTION == true 288 #endif // LTC3335_USE_SOFTWARE_CORRECTION == true int8_t LTC3335_Get_Counter_Test_Current(uint16_t *microamps)
Gets the battery current in uA.
LTC3335_OUTPUT_VOLTAGE_TYPE
int8_t LTC3335_Get_Discharged_Capacity(uint32_t *discharged_capacity)
Gets the discharged capacity from the battery in mAs.
LTC3335_IPEAK_CONFIGURATION_TYPE
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
LTC3335: Nanopower Buck-Boost DC/DC with Integrated Coulomb Counter.
int8_t LTC3335_Init(void)
Verify that battery capacity isn't so gigantic that it would overflow a 32 bit number.
static uint16_t vbat
battery voltage, optimally measured with an adc, set to a constant in this sketch ...
int8_t LTC3335_Set_Counter_Test(boolean enabled)
Enables/Disables the LTC3335 Counter Test feature.
unsigned coulomb_counter_overflow
Coulomb counter operating fault due to an improperly chosen prescalar causing the ripple counter to o...
LTC3335_ALARM_TYPE alarms
active alarms read from the LTC3335.
int8_t LTC3335_Reset_Counter_Test_Current(void)
Resets the number of edges and the amount of time stored for the Counter Test feature.
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.
int8_t LTC3335_Get_Alarms(LTC3335_ALARM_TYPE *alarms)
Gets the alarms active from the LTC3335.
unsigned alarm_trip
Accumulator value has met or exceeded the alarm threshold value.
int8_t LTC3335_Set_Voltage(boolean enabled, LTC3335_OUTPUT_VOLTAGE_TYPE voltage)
Enables/Disables software control of the LTC3335 output voltage.
int8_t LTC3335_Clear_Int(LTC3335_ALARM_TYPE *alarms)
Sends the command to clear the INT condition.
The alarm conditions which cause the LTC3335 to activate the /INT pin.
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 ...