Mirjana Radosavljevic
/
BMS_LV
Battery Management System LV - 2020/2021
Revision 3:4dc457ed63d5, committed 2021-03-20
- Comitter:
- minamax
- Date:
- Sat Mar 20 17:54:12 2021 +0000
- Parent:
- 2:03a6da61d834
- Commit message:
- This works
Changed in this revision
bq79606.cpp | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/bq79606.cpp Wed Dec 23 21:41:03 2020 +0000 +++ b/bq79606.cpp Sat Mar 20 17:54:12 2021 +0000 @@ -15,7 +15,7 @@ extern DigitalOut bmsWakeUp; void sendUART(int length, uint8_t * data){ - pc1.printf("SENDING TO BOARD"); + pc1.printf("SENDING TO BOARD\n"); for(int i = 0; i < length; i++) { //pc1.putc(data[i]); bms.putc(data[i]); @@ -27,8 +27,16 @@ bmsWakeUp = 1; wait_ms(50); bmsWakeUp = 0; - wait_ms(10); + wait_ms(50); //bmsWakeUp = 1; + + //NMOS TRANSISTOR LOGIC + + /*bmsWakeUp = 0; + wait_ms(50); + bmsWakeUp = 1; + wait_ms(50); + bmsWakeUp = 0;*/ } void AutoAddress() @@ -277,14 +285,18 @@ WriteReg(0, UV_THRESH, 0x53, 1, FRMWRT_ALL_NR); //sets cell UV to 2.8V WriteReg(0, OV_THRESH, 0x5B, 1, FRMWRT_ALL_NR); //sets cell OV to 4.3V + WriteReg(0, GPIO_ADC_CONF, 0x3F, 1, FRMWRT_ALL_NR); //configure GPIO as AUX voltage (absolute voltage, set to 0 for ratiometric) + WriteReg(0, AUX_ADC_CONF, 0x08, 1, FRMWRT_ALL_NR); //1MHz AUX sample rate, 128 decimation ratio WriteReg(0, CELL_ADC_CONF1, 0x67, 1, FRMWRT_ALL_NR); //256 decimation ratio, 1MHz sample. 1.2 Hz LPF WriteReg(0, CELL_ADC_CONF2, 0x00, 1, FRMWRT_ALL_NR); //single conversion WriteReg(0, CONTROL2, 0x01, 1, FRMWRT_ALL_NR); //CELL_ADC_GO = 1 ///enable continuous sampling. Otherwise, single conversions with CONTROL2[CELL_ADC_GO] //WriteReg(0,CELL_ADC_CONF2, 0x0A,1,FRMWRT_ALL_NR);//continuous sampling with 5ms interval - //WriteReg(0, CONTROL2, 0x10, 1, FRMWRT_ALL_NR);// enable TSREF to give enough settling time - //wait_ms(2); // provides settling time for TSREF + WriteReg(0, CONTROL2, 0x10, 1, FRMWRT_ALL_NR);// enable TSREF to give enough settling time + wait_ms(2); // provides settling time for TSREF + + WriteReg(0, DIAG_CTRL2, 0x41, 1, FRMWRT_ALL_NR); //set AUX ADC to measure cell 1
--- a/main.cpp Wed Dec 23 21:41:03 2020 +0000 +++ b/main.cpp Sat Mar 20 17:54:12 2021 +0000 @@ -72,6 +72,25 @@ pc1.printf("\n"); } + + +void waitFrameTemp(){ + while(!full); + //wait(2); + full=false; + pc1.printf("\n%d\n", rdLen); + for(int i = 0;i<rdLen;i++){ + pc1.printf("%X ",recBuff[i]); + } + + + int voltage = recBuff[5]; //LSB + voltage |= (recBuff[4]) << 8; //MSB + double vol = voltage*0.0001907349; + //double vol = ((double)voltage)/65536.0 * 5.0; + pc1.printf("temp1 = %6.2f V\n", vol); + +} void waitFrameResponse(){ while(!full); full = false; @@ -115,6 +134,8 @@ WriteReg(0, CONTROL2, 0x01, 1, FRMWRT_ALL_NR); //CELL_ADC_GO = 1 wait_ms(5);*/ + bmsWakeUp = 0; + while (1) { pc1.printf("Main Code \n"); @@ -124,11 +145,16 @@ wait(2); - while(bms.readable()) bms.getc(); - int rdLen = ReadReg(0, VCELL1H , pFrame1, 6 , 0, FRMWRT_ALL_R); //12 bajtova jer cita od adrese VCELL1H po dva bajta za svaki kanal (ima 6 kanala) + //while(bms.readable()) bms.getc(); + int rdLen = ReadReg(0, VCELL1H , pFrame1, 6 , 0, FRMWRT_ALL_R); //6 bajtova jer cita od adrese VCELL1H po dva bajta za svaki kanal (ima 3 kanala) + + waitFrame(); + //ReadReg(0, AUX_GPIO1H, pFrame1, 2 , 0, FRMWRT_ALL_R); + + //waitFrameTemp(); //slanje zahteva za GRESKAMA