DC2343A  FW 1.0.2 / GUI 1.0.10
LTC3335 Nanopower Buck-Boost DC/DC with Integrated Coulomb Counter
 All Data Structures Namespaces Files Functions Variables Enumerations Macros Pages
LTC3335.c
Go to the documentation of this file.
1 /*
2  Linear Technology DC2343A Demonstration Board.
3  Driver File for LTC3335 Nanopower Buck-Boost DC/DC with Integrated Coulomb Counter.
4  All datasheet references in this file refer to Linear Technology document 3335p.pdf
5 
6  @verbatim
7  Demonstration Circuit DC2343A is a complete system level solution for a Nanopower Buck-Boost
8  DC/DC with Integrated Coulomb Counter. The DC2343A contains a PIC16F1459 embedded processor
9  for communication to the PC over USB and the LTC3335 via its I2C port. The GUI is capable of
10  reading and writing all the control registers on the LTC3335 as well as displaying and
11  resetting all its alarm registers. The firmware and software for the embedded system and the GUI
12  are available at the LTC3335 solutions page located at http://www.linear.com/product/LTC3335#demoboards.
13  The DC2343A uses two Analog-to-Digital Convert-er channels to sample the Battery and Output voltages.
14  The voltage samples improve the functionality of the GUI, and allow optimal software correction to the
15  measured coulombs. By adding the software correction the first order known errors are compensated
16  for over the operating range and the resultant coulomb count is accurate to within 3%.
17 
18  The DC2343A contains an LTC3335 which is a high efficiency, low quiescent current (680nA) buck-boost
19  DC/DC converter with an integrated precision cou-lomb counter which monitors accumulated battery discharge
20  in long life battery powered applications. The buck-boost can operate down to 1.8V on its input and
21  provides eight pin selectable output voltages with up to 50mA of output current. The coulomb counter
22  stores the accumulated battery discharge in an internal register accessible via an I2C interface. The
23  LTC3335 features a programmable discharge alarm threshold. When the threshold is reached, an interrupt
24  is generated at the IRQ pin. To accommodate a wide range of battery types and sizes, the peak input
25  current can be selected from as low as 5mA to as high as 250mA and the full-scale coulomb counter has a
26  range from 1.1mAh (with 5mA IPEAK) to 1793Ah (with 250mA IPEAK).
27  @endverbatim
28 
29  http://www.linear.com/product/LTC3335
30 
31  REVISION HISTORY
32  $Revision: 816 $
33  $Date: 2014-10-13 13:07:16 -0400 (Mon, 13 Oct 2014) $
34 
35  Copyright (c) 2015, Linear Technology Corp.(LTC)
36  All rights reserved.
37 
38  Redistribution and use in source and binary forms, with or without
39  modification, are permitted provided that the following conditions are met:
40 
41  1. Redistributions of source code must retain the above copyright notice, this
42  list of conditions and the following disclaimer.
43  2. Redistributions in binary form must reproduce the above copyright notice,
44  this list of conditions and the following disclaimer in the documentation
45  and/or other materials provided with the distribution.
46 
47  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
48  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
49  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
50  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
51  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
52  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
53  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
54  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
56  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 
58  The views and conclusions contained in the software and documentation are those
59  of the authors and should not be interpreted as representing official policies,
60  either expressed or implied, of Linear Technology Corp.
61 
62 */
63 
64 /*! @file
65  Firmware Driver Code File for LTC3335 Nanopower Buck-Boost DC/DC with Integrated Coulomb Counter.
66 
67  This driver was designed to provide the following services to application code:
68  1. Perform the basic register commands necessary to access the features of the LTC3335.
69  2. Minimize I2C communication in an effort to minimize power consumption.
70  3. Use the Counter Test feature of the LTC3335 to provide a real time battery current measurement.
71 
72  Software correction was not included in this driver due to Program Memory limitations in the PIC16F1459.
73  See the LTC3335.vb file in with the DC2343A GUI source code for an example of software correction of the
74  LTC3335 coulomb count.
75 */
76 
77 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
78 // Includes
79 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
80 #include "Typedefs.h"
81 #include "LTC3335.h"
82 #include "PIC16F_I2C.h" // Interface for LTC3335s on DC2343A is through PIC I2C.
83 #include "PIC16F_Counter.h" // PIC16F Counter is used for LTC3335 Counter Test.
84 #include "PIC16F_Timer.h" // PIC16F Timer is used for LTC3335 Counter Test.
85 #include "Error.h" // For reporting of Communication Errors with the LTC3335.
86 #include "Status.h" // The Comm LED is flashed every time that the LTC3335 is accessed via I2C.
87 
88 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
89 // Definitions
90 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
91 
92 // \cond
93 //! @name I2C Address Definitions
94 //! @{
95 //! I2C address and format from datasheet page 5
96 #define LTC3335_BASE_ADDRESS 0x64 //!< BASE_ADDRESS for LTC3335.
97 #define LTC3335_WRITE_BIT 0 //!< I2C R/W bit value for WRITE.
98 #define LTC3335_READ_BIT 1 //!< I2C R/W bit value for READ.
99 //! @}
100 
101 //! @name LTC3335 Register Definitions
102 //! @{
103 //! Register Map from datasheet table 3
104 #define LTC3335_REGISTER_A 01 //!< VOUT selection and prescaler selection register.
105 #define LTC3335_REGISTER_B 02 //!< Alarm threshold register.
106 #define LTC3335_REGISTER_C 03 //!< Accumulator register.
107 #define LTC3335_REGISTER_D 04 //!< Alarms register.
108 #define LTC3335_REGISTER_E 05 //!< Status register.
109 #define LTC3335_INVALID 0xFF //!< code to indicate that cached data has not be set yet.
110 //! @}
111 // \endcond
112 
113 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
114 // Global Data
115 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
116 
117 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
118 // Local Data
119 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
120 
121 //! @name Cached LTC3335 Data
122 //! @{
123 //! Cached copies of values in registers, so that they do not need to be read/modified/written each time a function is called to only set a portion of that register.
124 static uint8_t ltc3335_subaddress_last; //!< last subaddress written, so that it is not repeatedly sent when the same register is polled.
125 static LTC3335_OUTPUT_VOLTAGE_TYPE ltc3335_voltage_selection_last; //!< last voltage selected through software.
126 static bool_t ltc3335_voltage_selection_enabled_last; //!< last enable for software selected voltage.
127 static uint8_t ltc3335_prescaler_last; //!< last prescaler selected.
128 //! @}
129 
130 //! @name Counter Test Variables
131 //! Variables used to count edges per second when the Counter Test feature is turned on, providing an instantaneous measurement of the battery current.
132 static uint16_t ltc3335_hw_timer_last; //!< last value of the hardware timer accessed by LTC3335 driver.
133 static uint16_t ltc3335_hw_counter_last; //!< last value of the hardware counter accessed by LTC3335 driver.
134 static bool_t ltc3335_counter_test_last; //!< value of the counter test bit last written to the LTC3335.
135 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.
136 static uint32_t ltc3335_counter_test_time; //!< the amount of timer ticks since the Counter Test results were last cleared.
137 //! @}
138 
139 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
140 // Local Prototypes
141 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
142 static bool_t ltc3335_set_subaddress(uint8_t subaddress);
143 static bool_t ltc3335_set_register(uint8_t subaddress, uint8_t* ltc3335_data);
144 static bool_t ltc3335_get_register(uint8_t subaddress, uint8_t* ltc3335_data);
145 static uint8_t ltc3335_encode_register_a(bool_t enabled, LTC3335_OUTPUT_VOLTAGE_TYPE voltage, uint8_t prescaler);
146 static void ltc3335_decode_register_a(uint8_t register_a);
147 static void ltc3335_report_error(uint8_t subaddress, bool_t set);
148 
149 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
150 // Global Functions
151 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
152 
153 // Initializes the LTC3335 driver.
154 void LTC3335_Init(void)
155 {
156  // Turn on power to the DVCC pin so that LTC3335 can communicate.
157  LTC3335_DVCC = 1;
158 
159  // Init the local variables to INVALID, so that they will be read/modified/written upon first attempt
160  // to write to their registers. After this cached values will be used.s
161  ltc3335_subaddress_last = LTC3335_INVALID;
162  ltc3335_voltage_selection_last = LTC3335_INVALID;
163  ltc3335_prescaler_last = LTC3335_INVALID;
164  ltc3335_voltage_selection_enabled_last = false;
165 
166  // Reset Counter Test and read LTC3335 to determine if Counter Test was on when PIC woke up.
168  LTC3335_Get_Counter_Test(&ltc3335_counter_test_last);
169 
170  return;
171 }
172 
173 // Enables/Disables software control of the LTC3335 output voltage.
174 // If software control is enabled, the voltage is set to the specified setting.
175 bool_t LTC3335_Set_Voltage(bool_t enabled, LTC3335_OUTPUT_VOLTAGE_TYPE voltage)
176 {
177  bool_t success;
178  uint8_t ltc3335_data;
179 
180  // Can not set out of range.
181  if(LTC3335_NUM_OUTPUT_VOLTAGES <= voltage)
182  {
183  return false;
184  }
185 
186  // Send command to set the voltage.
187  ltc3335_data = ltc3335_encode_register_a(enabled, voltage, ltc3335_prescaler_last);
188  success = ltc3335_set_register(LTC3335_REGISTER_A, &ltc3335_data);
189 
190  return success;
191 }
192 
193 // Get whether the software control of the LTC3335 output voltage is enabled/disabled.
194 // Gets the voltage setting, if software control is enabled.
195 bool_t LTC3335_Get_Voltage(bool_t* enabled, LTC3335_OUTPUT_VOLTAGE_TYPE* voltage)
196 {
197  bool_t success = true;
198  uint8_t ltc3335_data;
199 
200  // If we haven't previously set the prescaler, then read-modify-write
201  if (ltc3335_prescaler_last == LTC3335_INVALID)
202  {
203  success = LTC3335_Get_Prescaler(&ltc3335_prescaler_last);
204  }
205 
206  success &= ltc3335_get_register(LTC3335_REGISTER_A, &ltc3335_data);
207 
208  if(success == true)
209  {
210  ltc3335_decode_register_a(ltc3335_data);
211  *voltage = ltc3335_voltage_selection_last;
212  *enabled = ltc3335_voltage_selection_enabled_last;
213  }
214 
215  return success;
216 }
217 
218 // Sets the specified prescaler setting for the LTC3335.
219 bool_t LTC3335_Set_Prescaler(uint8_t prescaler)
220 {
221  bool_t success;
222  uint8_t ltc3335_data;
223 
224  // Can not set out of range.
225  if(LTC3335_PRESCALER_MAX < prescaler)
226  {
227  return false;
228  }
229 
230  // If we haven't previously set the voltage, then read-modify-write
231  if (ltc3335_voltage_selection_last == LTC3335_INVALID)
232  {
233  success = LTC3335_Get_Voltage(&ltc3335_voltage_selection_enabled_last, &ltc3335_voltage_selection_last);
234  }
235 
236  // Send command to set the voltage.
237  ltc3335_data = ltc3335_encode_register_a(ltc3335_voltage_selection_enabled_last, ltc3335_voltage_selection_last, prescaler);
238  success = ltc3335_set_register(LTC3335_REGISTER_A, &ltc3335_data);
239 
240  return success;
241 }
242 
243 // Gets the prescaler setting from the LTC3335.
244 bool_t LTC3335_Get_Prescaler(uint8_t* prescaler)
245 {
246  bool_t success;
247  uint8_t ltc3335_data;
248 
249  success = ltc3335_get_register(LTC3335_REGISTER_A, &ltc3335_data);
250 
251  if(success == true)
252  {
253  ltc3335_decode_register_a(ltc3335_data);
254  *prescaler = ltc3335_prescaler_last;
255  }
256 
257  return success;
258 }
259 
260 // Sets the specified alarm threshold for the LTC3335.
261 bool_t LTC3335_Set_Alarm_Threshold(uint8_t threshold)
262 {
263  bool_t success = true;
264 
265  success = ltc3335_set_register(LTC3335_REGISTER_B, &threshold);
266 
267  return success;
268 }
269 
270 // Gets the alarm threshold from the LTC3335.
271 bool_t LTC3335_Get_Alarm_Threshold(uint8_t* threshold)
272 {
273  bool_t success;
274  uint8_t ltc3335_data;
275 
276  success = ltc3335_get_register(LTC3335_REGISTER_B, &ltc3335_data);
277 
278  if(success == true)
279  {
280  *threshold = ltc3335_data;
281  }
282 
283  return success;
284 }
285 
286 // Sets the specified accumulator value for the LTC3335.
287 bool_t LTC3335_Set_Accumulator(uint8_t accumulator)
288 {
289  bool_t success;
290 
291  success = ltc3335_set_register(LTC3335_REGISTER_C, &accumulator);
292 
293  return success;
294 }
295 
296 // Gets the specified accumulator value from the LTC3335.
297 bool_t LTC3335_Get_Accumulator(uint8_t* accumulator)
298 {
299  bool_t success;
300  uint8_t ltc3335_data;
301 
302  success = ltc3335_get_register(LTC3335_REGISTER_C, &ltc3335_data);
303 
304  if(success == true)
305  {
306  *accumulator = ltc3335_data;
307  }
308 
309  return success;
310 }
311 
312 // Gets the alarms active from the LTC3335.
314 {
315  bool_t success;
316  uint8_t ltc3335_data;
317 
318  success = ltc3335_get_register(LTC3335_REGISTER_D, &ltc3335_data);
319 
320  if(success == true)
321  {
322  if(ltc3335_data & MASK(1, 0))
323  {
324  alarms->ac_on_time_overflow = 1;
325  }
326  else
327  {
328  alarms->ac_on_time_overflow = 0;
329  }
330 
331  if(ltc3335_data & MASK(1, 1))
332  {
333  alarms->coulomb_counter_overflow = 1;
334  }
335  else
336  {
337  alarms->coulomb_counter_overflow = 0;
338  }
339 
340  if(ltc3335_data & MASK(1, 2))
341  {
342  alarms->alarm_trip = 1;
343  }
344  else
345  {
346  alarms->alarm_trip = 0;
347  }
348  }
349 
350  return success;
351 }
352 
353 // Sends the command to clear the INT condition.
354 // NOTE! Additional registers will also need to be rewritten in order for the INT condition
355 // to not be immediately reset.
356 bool_t LTC3335_Clear_Int(void)
357 {
358  bool_t success = true;
359  uint8_t ltc3335_data = 1;
360 
361 
362  // If currently doing a Counter Test, do not turn it off when clearing the int.
363  if(ltc3335_counter_test_last == true)
364  {
365  ltc3335_data |= 2;
366  }
367 
368  success &= ltc3335_set_register(LTC3335_REGISTER_E, &ltc3335_data);
369  ltc3335_data++;
370 
371  return success;
372 }
373 
374 // Enables/Disables the LTC3335 Counter Test feature.
375 bool_t LTC3335_Set_Counter_Test(bool_t enabled)
376 {
377  bool_t success;
378  uint8_t ltc3335_data;
379 
380  // Send command to start the test.
381  ltc3335_data = ((enabled == true) ? MASK(1, 1) : 0);
382  success = ltc3335_set_register(LTC3335_REGISTER_E, &ltc3335_data);
383 
384  // Store results of the test so that we don't need to poll the IC for that info.
385  if(success == true)
386  {
387  ltc3335_counter_test_last = enabled;
388  }
389 
390  // Initialize after the command is sent, as the first edge that occurs
391  // when the test is started should not be counted.
392  if(enabled == true)
393  {
394  // Take initial readings when test is started.
396  }
397  else
398  {
399  // Reset test results when test is stopped.
401  }
402 
403  return success;
404 }
405 
406 // Gets whether the LTC3335 Counter Test feature is Enabled/Disabled.
407 // Note that this function get the value from the LTC3335.
408 bool_t LTC3335_Get_Counter_Test(bool_t* enabled)
409 {
410  bool_t success;
411  uint8_t ltc3335_data;
412 
413  success = ltc3335_get_register(LTC3335_REGISTER_E, &ltc3335_data);
414 
415  if(success == true)
416  {
417  ltc3335_counter_test_last = ((ltc3335_data & MASK(1, 1)) == 0) ? false : true;
418  *enabled = ltc3335_counter_test_last;
419  }
420 
421  return success;
422 }
423 
424 // Gets whether the LTC3335 Counter Test feature is Enabled/Disabled.
425 // Note that this function get the cached value of what was last read from the LTC3335.
426 // Gets the number of edges and the amount of time since the Counter Test
427 // was last reset, which allows edges/sec to be calculated. The edges/sec is proportional to
428 // battery current.
429 bool_t LTC3335_Get_Counter_Test_Results(bool_t* enabled, uint32_t* edge_count, uint32_t* time)
430 {
431  bool_t success = true;
432  uint8_t ltc3335_data;
433 
434  *enabled = ltc3335_counter_test_last;
435  *edge_count = ltc3335_counter_test_edge_count;
436  *time = ltc3335_counter_test_time;
437 
438  return success;
439 }
440 
441 // Resets the number of edges and the amount of time stored for the Counter Test feature.
443 {
444  ltc3335_counter_test_edge_count = 0;
445  ltc3335_counter_test_time = 0;
446  ltc3335_hw_timer_last = PIC16F_Timer_Get16();
447  ltc3335_hw_counter_last = PIC16F_Counter_Get();
448 
449  return true;
450 }
451 
452 // Task that must be run periodically, for the edges and time to be stored for the
453 // LTC3335 Counter Test feature.
455 {
456  if (ltc3335_counter_test_last == true)
457  {
458  // Get new timer and counter values
459  uint16_t hw_timer_new = PIC16F_Timer_Get16();
460  uint16_t hw_counter_new = PIC16F_Counter_Get();
461 
462  // Add difference between last timer and counter to summations.
463  ltc3335_counter_test_edge_count += (hw_counter_new - ltc3335_hw_counter_last);
464  ltc3335_counter_test_time += (hw_timer_new - ltc3335_hw_timer_last);
465 
466  // Save new timer and counter values for next execution of task.
467  ltc3335_hw_timer_last = hw_timer_new;
468  ltc3335_hw_counter_last = hw_counter_new;
469  }
470 
471  return;
472 }
473 
474 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
475 // Local Functions
476 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
477 
478 //! Writes a register subaddress to the LTC3335, to precede a read from or write to that register.
479 static bool_t ltc3335_set_subaddress(uint8_t subaddress)
480 {
481  bool_t success;
482  uint8_t ltc3335_data[2];
483 
484  // Build command to set the voltage.
485  ltc3335_data[0] = (LTC3335_BASE_ADDRESS << 1) | LTC3335_WRITE_BIT;
486  ltc3335_data[1] = subaddress;
487 
488  success = PIC16F_I2C_Start(false);
489  success &= PIC16F_I2C_Write(ltc3335_data, sizeof(ltc3335_data));
490 
491  if (success == true)
492  {
493  ltc3335_subaddress_last = subaddress;
494  }
495 
496  return success;
497 }
498 
499 //! Writes to an LTC3335 register.
500 static bool_t ltc3335_set_register(uint8_t subaddress, uint8_t* ltc3335_data)
501 {
502  bool_t success;
503 
504  Status_LTC3335_Comm_Set();
505 
506  // Send subaddress for voltage register.
507  success = ltc3335_set_subaddress(subaddress);
508 
509  success &= PIC16F_I2C_Write(ltc3335_data, sizeof(ltc3335_data));
510  success &= PIC16F_I2C_Stop();
511 
512  if(success == false) ltc3335_report_error(subaddress, true);
513 
514  return success;
515 }
516 
517 //! Reads from a LTC3335 register.
518 static bool_t ltc3335_get_register(uint8_t subaddress, uint8_t* ltc3335_data)
519 {
520  bool_t success;
521 
522  Status_LTC3335_Comm_Set();
523 
524  // If sub-address isn't the same as the last one written, write it now.
525  if(subaddress != ltc3335_subaddress_last)
526  {
527  success = ltc3335_set_subaddress(subaddress);
528  success &= PIC16F_I2C_Start(true);
529  }
530  else
531  {
532  success = PIC16F_I2C_Start(false);
533  }
534 
535  *ltc3335_data = ((LTC3335_BASE_ADDRESS << 1) | LTC3335_READ_BIT);
536  success &= PIC16F_I2C_Write(ltc3335_data, sizeof(uint8_t));
537  success &= PIC16F_I2C_Read(ltc3335_data, sizeof(uint8_t));
538  success &= PIC16F_I2C_Stop();
539 
540  if(success == false) ltc3335_report_error(subaddress, false);
541 
542  return success;
543 }
544 
545 //! Encodes elements of register A.
546 static uint8_t ltc3335_encode_register_a(bool_t enabled, LTC3335_OUTPUT_VOLTAGE_TYPE voltage, uint8_t prescaler)
547 {
548  return ((enabled == true) ? (1 << 7) : 0) | (voltage << 4) | prescaler;
549 }
550 
551 //! Decodes elements of register A.
552 static void ltc3335_decode_register_a(uint8_t register_a)
553 {
554  ltc3335_voltage_selection_enabled_last = ((register_a & MASK(1, 7)) == MASK(1, 7));
555  ltc3335_voltage_selection_last = ((register_a & MASK(3, 4)) >> 4);
556  ltc3335_prescaler_last = register_a & MASK(4, 0);
557  return;
558 }
559 
560 //! Saves error bytes associated with a failed I2C transaction.
561 static void ltc3335_report_error(uint8_t subaddress, bool_t set)
562 {
563  uint8_t error_bytes[2];
564  error_bytes[0] = subaddress;
565  error_bytes[1] = (uint8_t) set;
566  Error_Data_Set(ERROR_CODE_LTC3335_I2C_FAIL, error_bytes, sizeof(error_bytes));
567 
568  return;
569 }
bool_t LTC3335_Set_Prescaler(uint8_t prescaler)
Sets the specified prescaler setting for the LTC3335.
Definition: LTC3335.c:219
bool_t LTC3335_Get_Voltage(bool_t *enabled, LTC3335_OUTPUT_VOLTAGE_TYPE *voltage)
Get whether the software control of the LTC3335 output voltage is enabled/disabled.
Definition: LTC3335.c:195
bool_t LTC3335_Set_Counter_Test(bool_t enabled)
Enables/Disables the LTC3335 Counter Test feature.
Definition: LTC3335.c:375
bool_t LTC3335_Get_Counter_Test_Results(bool_t *enabled, uint32_t *edge_count, uint32_t *time)
Gets whether the LTC3335 Counter Test feature is Enabled/Disabled.
Definition: LTC3335.c:429
bool_t LTC3335_Set_Voltage(bool_t enabled, LTC3335_OUTPUT_VOLTAGE_TYPE voltage)
Enables/Disables software control of the LTC3335 output voltage.
Definition: LTC3335.c:175
bool_t LTC3335_Get_Alarm_Threshold(uint8_t *threshold)
Gets the alarm threshold from the LTC3335.
Definition: LTC3335.c:271
bool_t LTC3335_Get_Alarms(LTC3335_ALARM_TYPE *alarms)
Gets the alarms active from the LTC3335.
Definition: LTC3335.c:313
unsigned ac_on_time_overflow
AC(ON) time operating fault (tAC > tFS) due to improperly chosen inductor value timing out the AC(ON)...
Definition: LTC3335.h:141
bool_t LTC3335_Get_Prescaler(uint8_t *prescaler)
Gets the prescaler setting from the LTC3335.
Definition: LTC3335.c:244
unsigned coulomb_counter_overflow
Coulomb counter operating fault due to an improperly chosen prescalar causing the ripple counter to o...
Definition: LTC3335.h:142
void LTC3335_Init(void)
Initializes the LTC3335 driver.
Definition: LTC3335.c:154
Firmware Driver Header File for LTC3335 Nanopower Buck-Boost DC/DC with Integrated Coulomb Counter...
bool_t LTC3335_Set_Alarm_Threshold(uint8_t threshold)
Sets the specified alarm threshold for the LTC3335.
Definition: LTC3335.c:261
bool_t LTC3335_Reset_Counter_Test(void)
Resets the number of edges and the amount of time stored for the Counter Test feature.
Definition: LTC3335.c:442
unsigned alarm_trip
Accumulator value has met or exceeded the alarm threshold value.
Definition: LTC3335.h:143
#define LTC3335_DVCC
DVCC pin must be high for LTC3335 to communicate.
Definition: LTC3335.h:98
bool_t LTC3335_Get_Accumulator(uint8_t *accumulator)
Gets the specified accumulator value from the LTC3335.
Definition: LTC3335.c:297
bool_t LTC3335_Clear_Int(void)
Sends the command to clear the INT condition.
Definition: LTC3335.c:356
void LTC3335_Counter_Test_Task(void)
Task that must be run periodically, for the edges and time to be stored for the LTC3335 Counter Test ...
Definition: LTC3335.c:454
The alarm conditions which cause the LTC3335 to activate the /INT pin.
Definition: LTC3335.h:140
bool_t LTC3335_Set_Accumulator(uint8_t accumulator)
Sets the specified accumulator value for the LTC3335.
Definition: LTC3335.c:287
#define LTC3335_PRESCALER_MAX
the maximum prescaler that be selected for the LTC3335.
Definition: LTC3335.h:93
bool_t LTC3335_Get_Counter_Test(bool_t *enabled)
Gets whether the LTC3335 Counter Test feature is Enabled/Disabled.
Definition: LTC3335.c:408