DC2100A  1.2.0
Bi-Directional Cell Balancer Using the LTC3300-1 and the LTC6804-2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
LTC6804-2_Config.h
Go to the documentation of this file.
1 /*
2  Linear Technology DC2100A Demonstration Board.
3  Driver Configuration Header File for LTC6804-2 Multicell Battery Monitors.
4  All datasheet references in this file refer to Linear Technology Corp. document 680412fa.pdf.
5 
6  @verbatim
7  The LTC6804 is a 3rd generation multicell battery stack
8  monitor that measures up to 12 series connected battery
9  cells with a total measurement error of less than 1.2mV. The
10  cell measurement range of 0V to 5V makes the LTC6804
11  suitable for most battery chemistries. All 12 cell voltages
12  can be captured in 290us, and lower data acquisition rates
13  can be selected for high noise reduction.
14  Multiple LTC6804 devices can be connected in series,
15  permitting simultaneous cell monitoring of long, high voltage
16  battery strings. Each LTC6804 has an isoSPI interface
17  for high speed, RF-immune, local area communications.
18  Using the LTC6804-2, multiple devices are connected in
19  a daisy-chain with one host processor connection for all
20  devices. Using the LTC6804-2, multiple devices are connected
21  in parallel to the host processor, with each device
22  individually addressed.
23  Additional features include passive balancing for each cell,
24  an onboard 5V regulator, and 5 general purpose I/O lines.
25  In sleep mode, current consumption is reduced to 4uA.
26  The LTC6804 can be powered directly from the battery,
27  or from an isolated supply.
28  @endverbatim
29 
30  http://www.linear.com/product/LTC6804
31 
32  http://www.linear.com/product/LTC6804#demoboards
33 
34  REVISION HISTORY
35  $Revision: 699 $
36  $Date: 2014-09-09 16:02:09 -0400 (Tue, 09 Sep 2014) $
37 
38  Copyright (c) 2013, Linear Technology Corp.(LTC)
39  All rights reserved.
40 
41  Redistribution and use in source and binary forms, with or without
42  modification, are permitted provided that the following conditions are met:
43 
44  1. Redistributions of source code must retain the above copyright notice, this
45  list of conditions and the following disclaimer.
46  2. Redistributions in binary form must reproduce the above copyright notice,
47  this list of conditions and the following disclaimer in the documentation
48  and/or other materials provided with the distribution.
49 
50  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
51  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
52  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
53  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
54  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
55  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
56  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
57  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 
61  The views and conclusions contained in the software and documentation are those
62  of the authors and should not be interpreted as representing official policies,
63  either expressed or implied, of Linear Technology Corp.
64 
65 */
66 
67 /*! @file
68  @ingroup LTC6804-2
69  Driver Configuration Header File for LTC6804-2 Multicell Battery Monitors.
70 */
71 
72 #ifndef __LTC6804_CONFIG_H__
73 #define __LTC6804_CONFIG_H__
74 
75 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
76 // Includes
77 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
78 #include "DC2100A.h" // HW definition for Board
79 #include "PIC18FXXJ_SPI.h" // Interface for LTC3300s on DC2100A is through SPI
80 #include "System.h" // The number and addresses of the LTC6804s are tracked by the system monitor code module.
81 #include "Error.h" // Errors are reported through Error Handler Task
82 
83 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
84 // Definitions
85 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
86 
87 //! Configures CS pin used to communicate with LTC6804-2. Note that code module directly controls CS for wakeup signals.
88 #define LT6804_CONFIG_CS PIN_A5
89 
90 //! Configures Free Running Timer used to determine if the LTC6804 needs a LTC6804_TWAKE or LTC6804_TREADY duration wakeup pulse
91 #define LTC6804_CONFIG_TIMER PIC18FXXJ_Timer_Update()
92 
93 //! Resolution of LTC6804_CONFIG_TIMER in ticks per second.
94 #define LTC6804_CONFIG_TIMER_RESOLUTION (1L*PIC18FXXJ_TIMER_TICKS_PER_SEC)
95 
96 //! Function for delaying a specified number of us. This is used to generate wakeup signals for LTC6804.
97 //! - Parameters
98 //! + us: The number of us to delay.
99 #define LTC6804_CONFIG_DELAY_US(us) delay_us(us)
100 
101 //! The number of LTC6804 addresses used in this system. This is used for loops over all available LTC6804s.
102 #define LTC6804_CONFIG_NUM_BOARDS System_Num_Boards
103 
104 //! Returns the physical address for a LTC6804 in the system given its logical address.
105 #define LTC6804_CONFIG_GET_BOARD_ADDRESS(board_num) \
106  ((board_num == LTC6804_BROADCAST) ? LTC6804_COMMAND_CODE_BROADCAST_ADDRESS : System_Address_Table[board_num] | LTC6804_COMMAND_CODE_ADDRESSED_BIT)
107 
108 //! Configures the function called to set the baud rate to the LTC6804. This is used to control the baud rate of the I2C and SPI Buses implemented with the LTC6804 GPIO
109 //! - Parameters
110 //! + baud_khz: The baud rate in kHz.
111 #define LTC6804_CONFIG_SPI_SET_BAUD(baud_khz) \
112  PIC18FXXJ_SPI_Set_Baud(baud_khz)
113 
114 //! Note - This LTC6804 driver is designed for a buffered SPI peripheral (DMA, Interrupt driven, etc) to maximize throughput.
115 //! If a simple, non-buffered SPI driver is all that's available, while loops will need to be incorporated in these #defines.
116 
117 //! Configures the function called to start receiving a string of bytes to the LTC6804.
118 //! - Parameters
119 //! + buffer: Pointer where to store the received bytes.
120 //! + num_bytes: The number of bytes to receive.
121 #define LTC6804_CONFIG_SPI_BUFFER_RECEIVE_START(buffer, num_bytes) \
122  PIC18FXXJ_SPI_Buffer_Receive_Start(buffer, num_bytes)
123 
124 //! Configures the function called to start sending a string of bytes to the LTC6804.
125 //! - Parameters
126 //! + buffer: Pointer to the bytes to send.
127 //! + num_bytes: The number of bytes to send.
128 #define LTC6804_CONFIG_SPI_BUFFER_SEND_START(buffer, num_bytes) \
129  PIC18FXXJ_SPI_Buffer_Send_Start(buffer, num_bytes)
130 
131 //! Configures the function called to check if the last SPI communication to LTC6804 is done and SPI is ready to send/receive more data.
132 #define LTC6804_CONFIG_SPI_BUFFER_DONE() \
133  PIC18FXXJ_SPI_Buffer_Done()
134 
135 //! Configures the function called to return the number of bytes received in a buffer.
136 //! - Parameters
137 //! + buffer: Pointer where the received bytes are being stored.
138 #define LTC6804_CONFIG_SPI_BUFFER_RECEIVE_BYTES_AVAILABLE(buffer) \
139  PIC18FXXJ_SPI_Buffer_Receive_Bytes_Available(buffer)
140 
141 //! Configures interface through which LTC6804-2 driver module reports its CRC errors.
142 //! - Parameters
143 //! + address: The logical address for the PCB containing this LTC6804-2 IC.
144 //! + command: LTC6804 Command which generated CRC error.
145 //! + data_ptr: Pointer to bytes read from LTC6804-2.
146 //! + num_bytes: Number of bytes to be read via SPI.
147 //! - Usage Examples
148 //! + Example 1: If DC2100A Error.c/.h code module is defined for a system, framing the data and passing to that error reporting module would be here.
149 //! + Example 2: if stdout is defined for a system, this macro would format the data into a printf() statement.
150 //! + Example 3: If LTC6804-2 CRC errors are to be ignored, this macro could be defined as blank.
151 #define LTC6804_CONFIG_ERROR_CRC(address, command, data_ptr, num_bytes) \
152  { \
153  int8 temp_data[ERROR_DATA_SIZE]; \
154  int8 byte_num; \
155  temp_data[0] = address; \
156  temp_data[1] = UPPER_BYTE(command); \
157  temp_data[2] = LOWER_BYTE(command); \
158  for (byte_num = 3; byte_num < MIN(num_bytes + 3, ERROR_DATA_SIZE); byte_num++) \
159  { \
160  temp_data[byte_num] = data_ptr[byte_num - 3]; \
161  } \
162  Error_Data_Set(ERROR_CODE_LTC6804_CRC, temp_data, num_bytes + 3); \
163  }
164 
165 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
166 // Global Data
167 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
168 
169 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
170 // Global Prototypes
171 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
172 
173 #endif