Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 5:979ff570efce
- Parent:
- 4:28919318b141
- Child:
- 6:6a98a279d987
--- a/main.cpp Sun Mar 21 22:58:15 2021 +0000 +++ b/main.cpp Mon Mar 22 01:30:41 2021 +0000 @@ -21,6 +21,9 @@ volatile bool full = false; volatile int rdLen=0; int counter = 0; +volatile int devStat = 0; +volatile int cbRun = 1; +volatile int cbDone = 0; uint8_t pFrame1[(MAXBYTES+6)*TOTALBOARDS]; @@ -98,8 +101,55 @@ } pc1.printf("\n"); } - - +void cellBalanceStart() +{ + cbRun = 1; + cbDone = 0; + WriteReg(0, CB_CONFIG, 0xFA, 1, FRMWRT_ALL_NR); // Odds then Evens, continue regardless of fault condition, 30sec, seconds + + WriteReg(0, CB_DONE_THRESHOLD, 0x5F, 1, FRMWRT_ALL_NR); // Thresh hold set to value 3.6V, CBDONE comparators enabled + //Enabling the CBDONE voltage threshold overrides the OVUV function and pauses it. + + WriteReg(0, CB_CELL1_CTRL, 0xBC, 1, FRMWRT_ALL_NR);//cell 1- 1 minute balance timer + WriteReg(0, CB_CELL2_CTRL, 0xBC, 1, FRMWRT_ALL_NR);//cell 2- 1 minute balance timer + WriteReg(0, CB_CELL3_CTRL, 0xBC, 1, FRMWRT_ALL_NR);//cell 3- 1 minute balance timer + + WriteReg(0, CONTROL2, 0x30, 1, FRMWRT_ALL_NR);//BAL_GO set to 1, and TSREF enabled + wait_us(100); + pc1.printf("Setupovano balansiranje\n"); + while (cbRun) + { + ReadReg(0, DEV_STAT, pFrame1, 1 , 0, FRMWRT_ALL_R); + wait(1); + devStat = recBuff[4]; + cbRun = (devStat & 0x10) >> 4; + wait_us(500); + if (!cbRun) + { + pc1.printf("DEV STAT = %d\n", devStat); + pc1.printf("CBRUN = %d\n", cbRun); + //wait(10); + } + } + + while(!cbDone) + { + ReadReg(0, DEV_STAT, pFrame1, 1 , 0, FRMWRT_ALL_R); + wait(1); + devStat = recBuff[4]; + cbDone = (devStat & 0x40) >> 6; + wait_us(500); + if (cbDone) + { + pc1.printf("DEV STAT = %d\n", devStat); + pc1.printf("CBDONE = %d\n", cbDone); + //wait(10); + } + } + // Cleanup + WriteReg(0, CONTROL2, 0x00, 1, FRMWRT_ALL_NR);//Reset + WriteReg(0, CB_DONE_THRESHOLD, 0x20, 1, FRMWRT_ALL_NR); +} int main(){ pc1.printf("Main ulazak\n"); bms.attach(&callback); @@ -159,6 +209,7 @@ waitFrameTemp(); + cellBalanceStart(); //slanje zahteva za GRESKAMA //ReadReg(0, 0x52, &wTemp, 2, 0); // 0ms timeout