95 #define REFRESH_INTERVAL 1000 96 #define CURRENT_REFRESH_INTERVAL 5000
113 #if LTC3335_USE_CURRENT_MEASUREMENT == true 115 #endif // #if LTC3335_USE_CURRENT_MEASUREMENT == true 116 #if LTC3335_USE_SOFTWARE_CORRECTION == true 118 #endif // #if LTC3335_USE_CURRENT_MEASUREMENT == true 124 void print_separator();
126 void print_data_header();
139 Serial.begin(115200);
164 uint16_t time_new = millis();
170 #if LTC3335_USE_SOFTWARE_CORRECTION == false 174 #endif // LTC3335_USE_SOFTWARE_CORRECTION == false 178 #if LTC3335_USE_CURRENT_MEASUREMENT == true 179 #if LTC3335_USE_SOFTWARE_CORRECTION == false 183 #endif // LTC3335_USE_SOFTWARE_CORRECTION == false 184 #endif // #if LTC3335_USE_CURRENT_MEASUREMENT == true 200 #if LTC3335_USE_CURRENT_MEASUREMENT == true 210 #endif // #if LTC3335_USE_CURRENT_MEASUREMENT == true 213 if (Serial.available())
230 #define MV_PER_V 1000 231 #define MA_PER_A 1000 232 #define UA_PER_MA 1000 233 #define SEC_PER_HR 3600 234 #define MS_PER_SEC 1000 237 #define PRINT_PICK_DEC(v) Serial.print(v, v >= 1 ? 3 : 6); 240 void print_separator()
242 Serial.println(F(
"=========================================================================================="));
248 Serial.println(F(
"Initialization of LTC3335 failed."));
249 Serial.println(F(
"Ensure Linduino is connected correctly to DC2343A, "));
250 Serial.println(F(
"DC2343A is connected to VBAT between 1.8V and 5.5V,"));
251 Serial.println(F(
"and that EN jumper is in the ON position."));
260 Serial.println(F(
"Sample application for LTC3335 Nanopower Buck-Boost DC/DC with Integrated Coulomb Counter."));
264 Serial.print(F(
"Capacity = "));
266 Serial.print(F(
"mAs ("));
268 Serial.print(F(
"Ah), IPeak = "));
270 Serial.print(F(
"mA, Output Voltage = "));
271 #if LTC3335_OUTPUT_VOLTAGE == LTC3335_OUTPUT_VOLTAGE_1_8V 272 Serial.print(1.8, 1);
273 #elif LTC3335_OUTPUT_VOLTAGE == LTC3335_OUTPUT_VOLTAGE_2_5V 274 Serial.print(2.5, 1);
275 #elif LTC3335_OUTPUT_VOLTAGE == LTC3335_OUTPUT_VOLTAGE_2_8V 276 Serial.print(2.8, 1);
277 #elif LTC3335_OUTPUT_VOLTAGE == LTC3335_OUTPUT_VOLTAGE_3_0V 278 Serial.print(3.0, 1);
279 #elif LTC3335_OUTPUT_VOLTAGE == LTC3335_OUTPUT_VOLTAGE_3_3V 280 Serial.print(3.3, 1);
281 #elif LTC3335_OUTPUT_VOLTAGE == LTC3335_OUTPUT_VOLTAGE_3_6V 282 Serial.print(3.6, 1);
283 #elif LTC3335_OUTPUT_VOLTAGE == LTC3335_OUTPUT_VOLTAGE_4_5V 284 Serial.print(4.5, 1);
285 #elif LTC3335_OUTPUT_VOLTAGE == LTC3335_OUTPUT_VOLTAGE_5_0V 286 Serial.print(5.0, 1);
288 Serial.println(F(
"V."));
292 #if LTC3335_USE_SOFTWARE_CORRECTION == true 295 Serial.println(F(
"LTC3335_CORRECTION_FACTOR_TYP in LTC3335_Config.h not set to value returned as LTC3335_Get_Software_Correction_Factor(LTC3335_VBAT_TYP)"));
296 Serial.print(F(
"LTC3335_CORRECTION_FACTOR_TYP = "));
298 Serial.print(F(
", LTC3335_VBAT_TYP = "));
300 Serial.println(F(
"V."));
301 Serial.print(F(
"LTC3335_Get_Software_Correction_Factor(LTC3335_VBAT_TYP) = "));
305 #endif // #if LTC3335_USE_SOFTWARE_CORRECTION == true 307 Serial.print(F(
"Prescaler Set to "));
309 Serial.print(F(
" for a maximum accumulator range of "));
311 Serial.print(F(
"mAs ("));
313 Serial.print(F(
"Ah)"));
314 #if LTC3335_USE_SOFTWARE_CORRECTION == false 315 Serial.println(F(
"."));
316 Serial.println(F(
"LTC3335_USE_SOFTWARE_CORRECTION not enabled"));
318 Serial.println(F(
","));
319 Serial.print(F(
"assuming an average battery voltage of "));
321 Serial.println(F(
"V,"));
322 Serial.print(F(
"resulting in an average correction of "));
324 Serial.println(F(
"%."));
325 #endif // #if LTC3335_USE_SOFTWARE_CORRECTION == false 330 #if LTC3335_USE_SOFTWARE_CORRECTION == false 336 #endif // #if LTC3335_USE_SOFTWARE_CORRECTION == false 337 Serial.print(F(
"Alarm Register Set to "));
338 Serial.print(alarm_mas);
339 Serial.print(F(
"mAs ("));
340 PRINT_PICK_DEC(1.0 * alarm_mas / (1.0 * MA_PER_A * SEC_PER_HR));
341 Serial.println(F(
"Ah),"));
342 Serial.print(F(
"which is "));
344 Serial.println(F(
"% of the battery capacity."));
347 #if LTC3335_USE_CURRENT_MEASUREMENT == true 348 Serial.println(F(
"Counter Test mode used to measure battery current with nIRQ pin."));
350 #endif // #if LTC3335_USE_CURRENT_MEASUREMENT == false 352 Serial.println(F(
"Send any character to send a Clear Int command to the LTC3335."));
357 void print_data_header()
359 printf(F(
"Test Time (s), "));
360 printf(F(
"Discharged Capacity (mAs), "));
361 #if LTC3335_USE_CURRENT_MEASUREMENT == true 362 printf(F(
"Battery Current (mA), "));
363 #endif // #if LTC3335_USE_CURRENT_MEASUREMENT == true 364 printf(F(
"Alarm Trip Alarm, "));
365 printf(F(
"Coulomb Counter Overflow Alarm, "));
366 printf(F(
"AC On Time Overflow Alarm, "));
367 printf(F(
"PGOOD, "));
368 printf(F(
"nIRQ\r\n"));
376 #if LTC3335_USE_CURRENT_MEASUREMENT == true 377 printf(F(
"%21.3f,"), 1.0 *
current / MA_PER_A);
378 #endif // #if LTC3335_USE_CURRENT_MEASUREMENT == true
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 LTC3335_Get_Alarms(LTC3335_ALARM_TYPE *alarms)
Gets the alarms active from the LTC3335.
static uint32_t data_point_counter
counts the number of datapoints output to terminal screen.
Header File for Linduino Libraries and Demo Code.
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
static uint16_t refresh_time_last
Variable to schedule LTC3335 polling and data output at REFRESH_INTERVAL.
#define LTC3335_RANGE(p)
Macro to retrieve the LTC3335 coulomb count range with a given prescaler.
static void setup()
Initialize Linduino.
#define LTC3335_CAPACITY
in mAh, capacity of the battery
int8_t LTC3335_Init(void)
Verify that battery capacity isn't so gigantic that it would overflow a 32 bit number.
static void loop()
Repeats Linduino Loop.
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...
LTC3335_ALARM_TYPE alarms
active alarms read from the LTC3335.
#define CURRENT_REFRESH_INTERVAL
LTC3335: Nanopower Buck-Boost DC/DC with Integrated Coulomb Counter.
#define LTC3335_NIRQ_READ()
#define LTC3335_USE_CURRENT_MEASUREMENT
Set to true to use the /IRQ pin to measure the battery current real time.
static uint16_t current_refresh_time_last
Variable to schedule LTC3335 current measurement averaging at CURRENT_REFRESH_INTERVAL.
int8_t LTC3335_Get_Counter_Test_Current(uint16_t *microamps)
Gets the battery current in uA.
static void print_config()
Prints the configuration data that is going to be written to the LTC6803 to the serial port...
#define LTC3335_PGOOD_READ()
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.
LT_I2C: Routines to communicate with ATmega328P's hardware I2C port.
#define LTC3335_PRESCALER
Macro to select the optimal prescaler for the specified battery capacity at compile time...
unsigned alarm_trip
Accumulator value has met or exceeded the alarm threshold value.
#define LTC3335_IPEAK_MA
mA = 100mA, used in calculations of coulomb count and current.
static uint16_t current
the current measurement from the LTC3335's counter test mode.
#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.
The alarm conditions which cause the LTC3335 to activate the /INT pin.
#define LTC3335_ALARM_CAPACITY
in mAh, the capacity at which the alarm should be activated.