![](/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:
- 28:b7d1c8d8a2aa
- Parent:
- 27:db96e99e37c9
- Child:
- 29:86e963cc5ce7
diff -r db96e99e37c9 -r b7d1c8d8a2aa main.cpp --- a/main.cpp Tue Oct 25 08:24:58 2016 +0000 +++ b/main.cpp Tue Oct 25 12:49:57 2016 +0000 @@ -1,7 +1,8 @@ /*notes:--------------------- *-organizar codigo -*-diminuir tempos das interrupções etc -*-diminuir tempos mortos durante balanceamento +*-ver como desactivar balanceamento durante leitura de correntes e comparar as tensões obtidas +* +* * * * @@ -227,11 +228,15 @@ void check_discharging_voltage() { wakeup_idle(); + __disable_irq(); //<--------- LTC6804_adcv(); - +__enable_irq(); //<--------- wait_ms(10); wakeup_idle(); + __disable_irq(); + //<--------- err = LTC6804_rdcv(0, TOTAL_IC,cell_codes); + __enable_irq(); //<--------- if (err == -1) { pec_error(); }/* @@ -256,7 +261,9 @@ tx_cfg[0][5] = tx_cfg[0][5] & 0b11110000; //print_cells2(); +__disable_irq(); //<---------------------------- LTC6804_wrcfg(TOTAL_IC,tx_cfg); + __enable_irq(); //<---------------------------- } void onMsgReceived() @@ -265,10 +272,12 @@ } -bool to_charge_or_not_to_charge=false; // false = discharge +//bool to_charge_or_not_to_charge=false; // false = discharge bool charging = false; -bool discharging = false; +//bool discharging = true; + +/* void monitor() { led = !led; @@ -280,6 +289,7 @@ charging = 0; } } +*/ uint8_t motostate=0; @@ -292,12 +302,11 @@ led =1; wait(1); pec_error(); - discharging = 1; - - ticker.attach(&monitor, 5); + // charging = 0; + // ticker.attach(&monitor, 5); //apenas serve para actualizar as variaveis charging/discharging LTC6804_initialize(); init_cfg(); -//write configuration + //write configuration wakeup_sleep(); __disable_irq(); // Disable Interrupts LTC6804_wrcfg(TOTAL_IC,tx_cfg); @@ -328,20 +337,21 @@ can.frequency(1000000); // set bit rate to 1Mbps can.attach(&onMsgReceived); //print_cells2(); + sender.attach(&message_trigger,0.1); while(1) { - if(charging) { - charging = 0; + if(charging) + { + //charging = 0; check_charging_voltage(); - } - if(discharging) { - discharging = 0; + else + { + //charging = 1; check_discharging_voltage(); - sender.attach(&message_trigger,0.1); + //sender.attach(&message_trigger,0.1); } - if(to_send) { - - + if(to_send) + { to_send=0; txMsg.clear(); txMsg.id = 11; //BMS1=>ID:11; BMS2=>ID:12; BMS3=>ID:13. @@ -353,25 +363,23 @@ txMsg.data[3] = data.bytes[3]; txMsg.data[4] = cells_left; cells_left--; - if(!(can.write(txMsg))) { //se nao conseguiu transmitir continua a tentar transmitir a tensão dessa celula + if(!(can.write(txMsg))) + { //se nao conseguiu transmitir continua a tentar transmitir a tensão dessa celula pec_error(); cells_left++; //to_send=1; } - } - - if(msgAvailable) { + if(msgAvailable) + { int len = can.read(rxMsg); - if(rxMsg.id==9){ - - motostate = rxMsg.data[0]; - + if(rxMsg.id==9) + { + motostate = rxMsg.data[0]; //motostate: (0|0|0|0|0|0|to_charge_or_not_to_charge|key_switch) - to_charge_or_not_to_charge=((motostate & 0b00000010)>>1); + charging=((motostate & 0b00000010)>>1); msgAvailable = false; } } } - }