86 #define DATALOG_ENABLED 1 87 #define DATALOG_DISABLED 0 169 bool DCCBITS_A[12] = {
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false};
179 Serial.begin(115200);
183 for (uint8_t current_ic = 0; current_ic<
TOTAL_IC;current_ic++)
198 if (Serial.available())
202 if(user_command==
'm')
208 Serial.println(user_command);
222 uint32_t conv_time = 0;
475 for (uint8_t current_ic = 0; current_ic<
TOTAL_IC;current_ic++)
500 for (uint8_t current_ic = 0; current_ic<
TOTAL_IC;current_ic++)
537 for (uint8_t current_ic = 0; current_ic<
TOTAL_IC;current_ic++)
564 for (uint8_t current_ic = 0; current_ic<
TOTAL_IC;current_ic++)
591 for (uint8_t current_ic = 0; current_ic<
TOTAL_IC;current_ic++)
607 for (uint8_t current_ic = 0; current_ic<
TOTAL_IC;current_ic++)
636 for (uint8_t current_ic = 0; current_ic<
TOTAL_IC;current_ic++)
650 char str_error[]=
"Incorrect Option \n";
665 Serial.println(F(
"Transmit 'm' to quit"));
669 if (Serial.available() > 0)
736 Serial.println(F(
"List of 6811 Commands: "));
737 Serial.println(F(
"Write and Read Configuration: 1 |Loop measurements with data-log output: 12 |Set Discharge: 23"));
738 Serial.println(F(
"Read Configuration: 2 |Clear Registers: 13 |Clear Discharge: 24"));
739 Serial.println(F(
"Start Cell Voltage Conversion: 3 |Read CV,AUX and ADSTAT Voltages: 14 |Write and Read of PWM: 25"));
740 Serial.println(F(
"Read Cell Voltages: 4 |Run Mux Self Test: 15 |Write and Read of S control: 26"));
741 Serial.println(F(
"Start Aux Voltage Conversion: 5 |Run ADC Self Test: 16 |Clear S control register: 27"));
742 Serial.println(F(
"Read Aux Voltages: 6 |ADC overlap Test : 17 |SPI Communication: 28"));
743 Serial.println(F(
"Start Stat Voltage Conversion: 7 |Run Digital Redundancy Test: 18 |I2C Communication Write to Slave: 29"));
744 Serial.println(F(
"Read Stat Voltages: 8 |Open Wire Test for single cell detection: 19 |I2C Communication Read from Slave:30"));
745 Serial.println(F(
"Start Combined Cell Voltage and GPIO1, GPIO2 Conversion: 9 |Open Wire Test for multiple cell detection: 20 |Set or Reset the GPIO pins: 31 "));
746 Serial.println(F(
"Start Cell Voltage and Sum of cells : 10 |Print PEC Counter: 21 |"));
747 Serial.println(F(
"Loop Measurements: 11 |Reset PEC Counter: 22 | \n "));
749 Serial.println(F(
"Print 'm' for menu"));
750 Serial.println(F(
"Please enter command: \n"));
762 Serial.println(F(
"Written Configuration: "));
763 for (
int current_ic = 0; current_ic<
TOTAL_IC; current_ic++)
765 Serial.print(F(
"CFGA IC "));
766 Serial.print(current_ic+1,DEC);
767 for(
int i = 0;
i<6;
i++)
769 Serial.print(F(
", 0x"));
772 Serial.print(F(
", Calculated PEC: 0x"));
773 cfg_pec =
pec15_calc(6,&BMS_IC[current_ic].config.tx_data[0]);
775 Serial.print(F(
", 0x"));
777 Serial.println(
"\n");
788 Serial.println(F(
"Received Configuration "));
789 for (
int current_ic=0; current_ic<
TOTAL_IC; current_ic++)
791 Serial.print(F(
"CFGA IC "));
792 Serial.print(current_ic+1,DEC);
793 for(
int i = 0;
i < 6;
i++)
795 Serial.print(F(
", 0x"));
798 Serial.print(F(
", Received PEC: 0x"));
800 Serial.print(F(
", 0x"));
802 Serial.println(
"\n");
812 for (
int current_ic = 0 ; current_ic <
TOTAL_IC; current_ic++)
816 Serial.print(
" IC ");
817 Serial.print(current_ic+1,DEC);
821 Serial.print(
i+1,DEC);
823 Serial.print(BMS_IC[current_ic].cells.c_codes[
i]*0.0001,4);
830 Serial.print(
" Cells :");
833 Serial.print(BMS_IC[current_ic].cells.c_codes[
i]*0.0001,4);
838 Serial.println(
"\n");
848 for (
int current_ic =0 ; current_ic <
TOTAL_IC; current_ic++)
852 Serial.print(
" IC ");
853 Serial.print(current_ic+1,DEC);
856 for (
int i=0;
i < 5;
i++)
858 Serial.print(F(
" GPIO-"));
859 Serial.print(
i+1,DEC);
861 Serial.print(BMS_IC[current_ic].aux.a_codes[
i]*0.0001,4);
864 Serial.print(F(
" Vref2"));
866 Serial.print(BMS_IC[current_ic].aux.a_codes[5]*0.0001,4);
871 Serial.print(
"AUX ");
872 Serial.print(
" IC ");
873 Serial.print(current_ic+1,DEC);
876 for (
int i=0;
i < 6;
i++)
878 Serial.print(BMS_IC[current_ic].aux.a_codes[
i]*0.0001,4);
883 Serial.println(
"\n");
893 for (uint8_t current_ic =0 ; current_ic <
TOTAL_IC; current_ic++)
895 Serial.print(F(
" IC "));
896 Serial.print(current_ic+1,DEC);
897 Serial.print(F(
": "));
898 Serial.print(F(
" SOC:"));
899 Serial.print(BMS_IC[current_ic].stat.stat_codes[0]*0.0001*20,4);
900 Serial.print(F(
","));
901 Serial.print(F(
" Itemp:"));
902 itmp = (double)((BMS_IC[current_ic].stat.stat_codes[1] * (0.0001 / 0.0075)) - 273);
903 Serial.print(itmp,4);
904 Serial.print(F(
","));
905 Serial.print(F(
" VregA:"));
906 Serial.print(BMS_IC[current_ic].stat.stat_codes[2]*0.0001,4);
907 Serial.print(F(
","));
908 Serial.print(F(
" VregD:"));
909 Serial.print(BMS_IC[current_ic].stat.stat_codes[3]*0.0001,4);
911 Serial.print(F(
" Flags:"));
912 Serial.print(F(
" 0x"));
914 Serial.print(F(
", 0x"));
916 Serial.print(F(
", 0x"));
918 Serial.print(F(
" Mux fail flag:"));
919 Serial.print(F(
" 0x"));
921 Serial.print(F(
" THSD:"));
922 Serial.print(F(
" 0x"));
924 Serial.println(
"\n");
934 for (
int current_ic =0 ; current_ic <
TOTAL_IC; current_ic++)
936 Serial.print(F(
" IC "));
937 Serial.print(current_ic+1,DEC);
938 Serial.print(F(
": "));
939 Serial.print(F(
" SOC:"));
940 Serial.print(BMS_IC[current_ic].stat.stat_codes[0]*0.0001*20,4);
941 Serial.print(F(
","));
943 Serial.println(
"\n");
955 Serial.print(
" IC ");
956 Serial.println(ic+1,DEC);
957 if (BMS_IC[ic].stat.mux_fail[0] != 0) error++;
959 if (error==0) Serial.println(F(
"Mux Test: PASS \n"));
960 else Serial.println(F(
"Mux Test: FAIL \n"));
972 Serial.println(
"Cell ");
976 Serial.println(
"Aux ");
980 Serial.println(
"Stat ");
982 Serial.print(error, DEC);
983 Serial.println(F(
" : errors detected in Digital Filter and Memory \n"));
992 if (error==0) Serial.println(F(
"Overlap Test: PASS \n"));
993 else Serial.println(F(
"Overlap Test: FAIL \n"));
1004 Serial.println(
"Aux ");
1008 Serial.println(
"Stat ");
1011 Serial.print(error, DEC);
1012 Serial.println(F(
" : errors detected in Measurement \n"));
1021 for (
int current_ic =0 ; current_ic <
TOTAL_IC; current_ic++)
1023 if (BMS_IC[current_ic].system_open_wire == 65535)
1025 Serial.print(
"No Opens Detected on IC ");
1026 Serial.println(current_ic+1, DEC);
1030 Serial.print(F(
"There is an open wire on IC "));
1031 Serial.print(current_ic + 1,DEC);
1032 Serial.print(F(
" Channel: "));
1033 Serial.println(BMS_IC[current_ic].system_open_wire);
1035 Serial.println(
"\n");
1045 for (
int current_ic=0; current_ic<
TOTAL_IC; current_ic++)
1048 Serial.print(BMS_IC[current_ic].crc_count.pec_count,DEC);
1049 Serial.print(F(
" : PEC Errors Detected on IC"));
1050 Serial.println(current_ic+1,DEC);
1052 Serial.println(
"\n");
1061 int8_t read_s_pin=0;
1063 Serial.print(F(
"Please enter the Spin number: "));
1065 Serial.println(read_s_pin);
1078 Serial.println(F(
"Written PWM Configuration: "));
1079 for (uint8_t current_ic = 0; current_ic<
TOTAL_IC; current_ic++)
1081 Serial.print(F(
"IC "));
1082 Serial.print(current_ic+1,DEC);
1083 for(
int i = 0;
i < 6;
i++)
1085 Serial.print(F(
", 0x"));
1088 Serial.print(F(
", Calculated PEC: 0x"));
1089 pwm_pec =
pec15_calc(6,&BMS_IC[current_ic].pwm.tx_data[0]);
1091 Serial.print(F(
", 0x"));
1093 Serial.println(
"\n");
1104 Serial.println(F(
"Received pwm Configuration:"));
1105 for (uint8_t current_ic=0; current_ic<
TOTAL_IC; current_ic++)
1107 Serial.print(F(
"IC "));
1108 Serial.print(current_ic+1,DEC);
1109 for(
int i = 0;
i < 6;
i++)
1111 Serial.print(F(
", 0x"));
1114 Serial.print(F(
", Received PEC: 0x"));
1116 Serial.print(F(
", 0x"));
1118 Serial.println(
"\n");
1130 Serial.println(F(
"Written Data in Sctrl register: "));
1131 for (
int current_ic = 0; current_ic<
TOTAL_IC; current_ic++)
1133 Serial.print(F(
" IC: "));
1134 Serial.print(current_ic+1,DEC);
1135 Serial.print(F(
" Sctrl register group:"));
1136 for(
int i = 0;
i < 6;
i++)
1138 Serial.print(F(
", 0x"));
1142 Serial.print(F(
", Calculated PEC: 0x"));
1143 sctrl_pec =
pec15_calc(6,&BMS_IC[current_ic].sctrl.tx_data[0]);
1145 Serial.print(F(
", 0x"));
1147 Serial.println(
"\n");
1158 Serial.println(F(
"Received Data:"));
1159 for (
int current_ic=0; current_ic<
TOTAL_IC; current_ic++)
1161 Serial.print(F(
" IC "));
1162 Serial.print(current_ic+1,DEC);
1164 for(
int i = 0;
i < 6;
i++)
1166 Serial.print(F(
", 0x"));
1170 Serial.print(F(
", Received PEC: 0x"));
1172 Serial.print(F(
", 0x"));
1174 Serial.println(
"\n");
1186 Serial.println(F(
"Written Data in COMM Register: "));
1187 for (
int current_ic = 0; current_ic<
TOTAL_IC; current_ic++)
1189 Serial.print(F(
" IC- "));
1190 Serial.print(current_ic+1,DEC);
1192 for(
int i = 0;
i < 6;
i++)
1194 Serial.print(F(
", 0x"));
1197 Serial.print(F(
", Calculated PEC: 0x"));
1198 comm_pec =
pec15_calc(6,&BMS_IC[current_ic].com.tx_data[0]);
1200 Serial.print(F(
", 0x"));
1202 Serial.println(
"\n");
1213 Serial.println(F(
"Received Data in COMM register:"));
1214 for (
int current_ic=0; current_ic<
TOTAL_IC; current_ic++)
1216 Serial.print(F(
" IC- "));
1217 Serial.print(current_ic+1,DEC);
1219 for(
int i = 0;
i < 6;
i++)
1221 Serial.print(F(
", 0x"));
1224 Serial.print(F(
", Received PEC: 0x"));
1226 Serial.print(F(
", 0x"));
1228 Serial.println(
"\n");
1238 uint16_t m_factor=1000;
1240 Serial.print(F(
"Conversion completed in:"));
1241 Serial.print(((
float)conv_time/m_factor), 1);
1242 Serial.println(F(
"ms \n"));
1253 Serial.println(F(
"A PEC error was detected in the received data"));
1263 Serial.println(data);
1275 Serial.print((byte)data,HEX);
1278 Serial.print((byte)data,HEX);
1286 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F' 1294 '0',
'x',
'0',
'0',
'\0' 1326 while (Serial.available() <= 0);
1327 return(Serial.read());
const uint8_t PRINT_PEC
This is to ENABLED or DISABLED printing the PEC Error Count in a continuous loop. ...
void LTC6811_reset_crc_count(uint8_t total_ic, cell_asic *ic)
Helper Function that resets the PEC error counters.
void LTC6811_clrsctrl()
Clears the LTC6811 Sctrl registers.
static void check_mux_fail(void)
char hex_to_byte_buffer[5]
int8_t LTC6811_rdsctrl(uint8_t total_ic, uint8_t sctrl_reg, cell_asic *ic)
Reads sctrl registers of a LTC6811 daisy chain.
static void print_cells(uint8_t datalog_en)
static void print_rxconfig(void)
bool DCCBITS_A[12]
Discharge cell switch //Dcc 1,2,3,4,5,6,7,8,9,10,11,12.
const uint8_t ADC_DCP
Discharge Permitted.
void LTC6811_clraux()
Clears the LTC6811 Auxiliary registers.
const uint8_t WRITE_CONFIG
This is to ENABLED or DISABLED writing into to configuration registers in a continuous loop...
static void print_selftest_errors(uint8_t adc_reg, int8_t error)
unsigned char user_command
uint8_t tx_data[6]
Stores data to be transmitted.
static void print_wrconfig(void)
#define CELL_CH_ALL
CH Dec Channels to convert 0000 All Cells 0011 Cell 1 and Cell 7 0102 Cell 2 and Cell 8 0113 Cell 3 ...
int8_t LTC6811_rdstat(uint8_t reg, uint8_t total_ic, cell_asic *ic)
Reads and parses the LTC6811 stat registers.
const uint8_t ADC_OPT
ADC Mode option bit.
bool DCTOBITS[4]
Discharge time value // Dcto 0,1,2,3 // Programed for 4 min.
void LTC6811_clrcell()
Clears the LTC6811 cell voltage registers.
const uint8_t MEASURE_STAT
This is to ENABLED or DISABLED reading the status registers in a continuous loop. ...
const uint8_t MEASURE_AUX
This is to ENABLED or DISABLED reading the auxiliary registers in a continuous loop.
static void check_error(int error)
const uint8_t READ_CONFIG
This is to ENABLED or DISABLED reading the configuration registers in a continuous loop...
void LTC6811_clrstat()
Clears the LTC6811 Stat registers.
Header File for Linduino Libraries and Demo Code.
const uint8_t AUX_CH_TO_CONVERT
Channel Selection for ADC conversion.
const uint8_t ADC_CONVERSION_MODE
ADC Mode.
int8_t LTC6811_rdcomm(uint8_t total_ic, cell_asic *ic)
Reads comm registers of a LTC6811 daisy chain.
#define AUX_CH_ALL
CHG Dec Channels to convert 000 0 All GPIOS and 2nd Ref 001 1 GPIO 1 010 2 GPIO 2 011 3 GPIO 3 100 4...
static void run_command(uint32_t cmd)
void spi_enable(uint8_t spi_clock_divider)
Setup the processor for hardware SPI communication.
uint32_t LTC6811_pollAdc()
This function will block operation until the ADC has finished it's conversion.
const uint16_t UV_THRESHOLD
Under voltage threshold ADC Code.
static void print_pec_error_count(void)
static int8_t select_s_pin(void)
static void measurement_loop(uint8_t datalog_en)
const uint8_t SEL_ALL_REG
Register Selection.
int8_t LTC6811_rdaux(uint8_t reg, uint8_t total_ic, cell_asic *ic)
Reads and parses the LTC6811 auxiliary registers.
void LTC6811_adax(uint8_t MD, uint8_t CHG)
Start a GPIO and Vref2 Conversion.
void LTC6811_wrcfg(uint8_t total_ic, cell_asic *ic)
Write the LTC6811 configuration register.
uint8_t LTC6811_rdcv(uint8_t reg, uint8_t total_ic, cell_asic *ic)
Reads and parses the LTC6811 cell voltage registers.
static uint16_t UV
Under-voltage Comparison Voltage.
void LTC6811_set_cfgr(uint8_t nIC, cell_asic *ic, bool refon, bool adcopt, bool gpio[5], bool dcc[12], bool dcto[4], uint16_t uv, uint16_t ov)
Helper function to set appropriate bits in CFGR register based on bit function.
void LTC6811_run_openwire_multi(uint8_t total_ic, cell_asic *ic)
Helper function that runs open wire for multiple cell and two consecutive cells detection.
void LTC6811_adcvsc(uint8_t MD, uint8_t DCP)
Starts cell voltage and SOC conversion.
union LT_union_int32_4bytes data
int16_t LTC6811_run_cell_adc_st(uint8_t adc_reg, uint8_t total_ic, cell_asic *ic, uint8_t md, bool adcopt)
Helper function that runs the ADC Self Tests.
void LTC6811_diagn()
Starts the Mux Decoder diagnostic self test Running this command will start the Mux Decoder Diagnosti...
const uint8_t STAT_CH_TO_CONVERT
Channel Selection for ADC conversion.
void LTC6811_run_openwire_single(uint8_t total_ic, cell_asic *ic)
Helper function that runs the data sheet open wire algorithm for single cell detection.
static uint16_t OV
Over-voltage Comparison Voltage.
const uint8_t MEASURE_CELL
This is to ENABLED or DISABLED measuring the cell voltages in a continuous loop.
static void print_rxpwm(void)
void LTC6811_adcv(uint8_t MD, uint8_t DCP, uint8_t CH)
Starts cell voltage conversion.
const uint16_t OV_THRESHOLD
Over voltage threshold ADC Code.
int8_t LTC6811_rdcfg(uint8_t total_ic, cell_asic *ic)
Reads configuration registers of a LTC6811.
const uint16_t MEASUREMENT_LOOP_TIME
Loop Time in milliseconds(ms)
static void print_sumofcells(void)
#define input(pin)
Return the state of pin "pin".
static void print_wrsctrl(void)
uint8_t cell_channels
Number of Cell channels.
static void print_menu(void)
void LTC6811_init_reg_limits(uint8_t total_ic, cell_asic *ic)
Initialize the Register limits.
void LTC6811_wrpwm(uint8_t total_ic, uint8_t pwmReg, cell_asic *ic)
Write the LTC6811 PWM register.
void LTC6811_stcomm(uint8_t len)
Issues a stcomm command and clocks data out of the COMM register.
bool GPIOBITS_A[5]
GPIO Pin Control // Gpio 1,2,3,4,5.
static void print_digital_redundancy_errors(uint8_t adc_reg, int8_t error)
void LTC6811_adstat(uint8_t MD, uint8_t CHST)
Start a Status ADC Conversion.
static void serial_print_hex(uint8_t data)
uint16_t pec15_calc(uint8_t len, uint8_t *data)
void LTC6811_stsctrl()
Start Sctrl data communication This command will start the sctrl pulse communication over the spins...
void LTC6811_init_cfg(uint8_t total_ic, cell_asic *ic)
Helper Function to initialize the CFGR data structures.
static void print_wrcomm(void)
LT_SPI: Routines to communicate with ATmega328P's hardware SPI port.
void LTC6811_wrsctrl(uint8_t total_ic, uint8_t sctrl_reg, cell_asic *ic)
Write the LTC6811 Sctrl register.
bool REFON
Reference Powered Up Bit.
bool ADCOPT
ADC Mode option bit.
static void serial_print_text(char data[])
const uint8_t SEL_REG_B
Register Selection.
int16_t LTC6811_run_adc_redundancy_st(uint8_t adc_mode, uint8_t adc_reg, uint8_t total_ic, cell_asic *ic)
Helper function that runs the ADC Digital Redundancy commands and checks output for errors...
uint16_t LTC6811_run_adc_overlap(uint8_t total_ic, cell_asic *ic)
Helper Function that runs the ADC Overlap test.
void LTC6811_wrcomm(uint8_t total_ic, cell_asic *ic)
Writes to the LTC6811 COMM register.
LT_I2C: Routines to communicate with ATmega328P's hardware I2C port.
char byte_to_hex_buffer[3]
static void print_wrpwm(void)
const uint8_t TOTAL_IC
Number of ICs in the daisy chain.
int8_t LTC6811_rdpwm(uint8_t total_ic, uint8_t pwmReg, cell_asic *ic)
Reads pwm registers of a LTC6811 daisy chain.
void quikeval_SPI_connect()
Connect SPI pins to QuikEval connector through the Linduino MUX. This will disconnect I2C...
static void print_rxsctrl(void)
static void print_overlap_results(int8_t error)
static void print_aux(uint8_t datalog_en)
LTC6811: Multicell Battery Monitors.
const uint8_t SEL_REG_A
Register Selection.
static void print_rxcomm(void)
void LTC6811_adcvax(uint8_t MD, uint8_t DCP)
Starts cell voltage and GPIO 1&2 conversion.
static void print_stat(void)
void LTC6811_set_discharge(int Cell, uint8_t total_ic, cell_asic *ic)
Helper function to set discharge bit in CFG register.
static void print_conv_time(uint32_t conv_time)
cell_asic BMS_IC[TOTAL_IC]
Global Battery Variable.
static void print_open_wires(void)
void LTC6811_clear_discharge(uint8_t total_ic, cell_asic *ic)
Clears all of the DCC bits in the configuration registers.
const uint8_t CELL_CH_TO_CONVERT
Channel Selection for ADC conversion.