![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
all bms comunicating with nucleo board and balancing
Dependencies: CANnucleo LTC68041 mbed
Fork of BMS_2 by
Diff: main.cpp
- Revision:
- 40:4144b3eec060
- Parent:
- 39:1e9fdc51cd65
- Child:
- 41:0b05e0109f2e
diff -r 1e9fdc51cd65 -r 4144b3eec060 main.cpp --- a/main.cpp Wed Nov 09 15:41:52 2016 +0000 +++ b/main.cpp Wed Nov 09 20:47:02 2016 +0000 @@ -9,7 +9,7 @@ uint16_t cell_codes[TOTAL_IC][12]; //uint16_t temp_codes[32]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32}; -float temp_codes[32]; +float temp_codes[32]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32}; volatile bool msgAvailable = false; volatile bool to_send = false; @@ -132,6 +132,17 @@ } data; +/* +void message_trigger() +{ + if(cells_left < 1) { + sender.detach(); + } else { + to_send = 1; + } +} +*/ + void message_trigger() { if((cells_left < 1)&&(temps_left < 1)) { @@ -141,6 +152,7 @@ } } + void check_charging_voltage() { wakeup_idle(); @@ -246,17 +258,17 @@ DigitalOut MUXB_2(PB_14); DigitalOut MUXB_3(PB_15); -/* + void check_temperatures() { int i=14; - MUXA_3=1; MUXA_2=1; MUXA_1=1; MUXA_0=0; //(escolha do NTC on board) + MUXA_3=0; MUXA_2=0; MUXA_1=0; MUXA_0=1; //(escolha do NTC on board) temp_codes[i]= MUXA_Read.read()*3300; temps_left = 32; } -*/ +/* void check_temperatures() { for (int i=0; i<32; i++){ @@ -327,19 +339,15 @@ MUXB_3=1; MUXB_2=1; MUXB_1=1; MUXB_0=1; } wait_ms(10); //tempo para a tensao á saida do mux estabilisar - - if(i<=15){ // Converts and read the analog input value (value from 0.0 to 1.0) + if(i<16){ // Converts and read the analog input value (value from 0.0 to 1.0) temp_codes[i] = MUXA_Read.read()*3300; - wait_ms(10); }else{ temp_codes[i] = MUXB_Read.read()*3300; - wait_ms(10); } } temps_left = 32; } - - +*/ void onMsgReceived() { msgAvailable = true; @@ -375,7 +383,7 @@ to_charge_or_not_to_charge=0; charging = 0; discharging = 1; - ticker.attach(&monitor, 2); + ticker.attach(&monitor, 10); LTC6804_initialize(); init_cfg(); //write configuration @@ -413,17 +421,20 @@ charging = 0; check_charging_voltage(); check_temperatures(); - sender.attach(&message_trigger,0.05); + sender.attach(&message_trigger,0.1); } if(discharging) { discharging = 0; check_discharging_voltage(); check_temperatures(); - sender.attach(&message_trigger,0.05); + sender.attach(&message_trigger,0.1); } if(to_send) { to_send=0; //-----------------1º send cell voltages + + if(cells_left>0){ + txMsg.clear(); txMsg.id = 11; //BMS1=>ID:11; BMS2=>ID:12; BMS3=>ID:13. txMsg.len = 5; @@ -439,15 +450,19 @@ cells_left++; //to_send=1; } + } //-----------------2º send cell temperatures // wait_ms(200); falha se houver aqui um delay deste tamanho + + if(temps_left>0){ + txMsg.clear(); txMsg.id = 21; //BMS1=>ID:11; BMS2=>ID:12; BMS3=>ID:13. txMsg.len = 5; - // data.f[0] = temp_codes[temps_left-1]; data.f[0] = temp_codes[temps_left-1]; + // data.f[0] = temp_codes[14]; txMsg.data[0] = data.bytes[0]; txMsg.data[1] = data.bytes[1]; @@ -460,7 +475,8 @@ pec_error(); temps_left++; //to_send=1; - } + } + } } if(msgAvailable) {