![](/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:
- 29:86e963cc5ce7
- Parent:
- 28:b7d1c8d8a2aa
- Child:
- 30:9c9f2d789153
--- a/main.cpp Tue Oct 25 12:49:57 2016 +0000 +++ b/main.cpp Tue Oct 25 17:28:01 2016 +0000 @@ -1,8 +1,7 @@ /*notes:--------------------- *-organizar codigo -*-ver como desactivar balanceamento durante leitura de correntes e comparar as tensões obtidas -* -* +*-diminuir tempos das interrupções etc +*-diminuir tempos mortos durante balanceamento * * * @@ -228,15 +227,11 @@ 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(); }/* @@ -261,9 +256,7 @@ tx_cfg[0][5] = tx_cfg[0][5] & 0b11110000; //print_cells2(); -__disable_irq(); //<---------------------------- LTC6804_wrcfg(TOTAL_IC,tx_cfg); - __enable_irq(); //<---------------------------- } void onMsgReceived() @@ -272,12 +265,10 @@ } -//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 = true; +bool discharging = false; - -/* void monitor() { led = !led; @@ -289,7 +280,6 @@ charging = 0; } } -*/ uint8_t motostate=0; @@ -302,11 +292,12 @@ led =1; wait(1); pec_error(); - // charging = 0; - // ticker.attach(&monitor, 5); //apenas serve para actualizar as variaveis charging/discharging + discharging = 1; + + ticker.attach(&monitor, 5); LTC6804_initialize(); init_cfg(); - //write configuration +//write configuration wakeup_sleep(); __disable_irq(); // Disable Interrupts LTC6804_wrcfg(TOTAL_IC,tx_cfg); @@ -337,24 +328,23 @@ 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(); + } - else - { - //charging = 1; + if(discharging) { + discharging = 0; 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. + txMsg.id = 13; //BMS1=>ID:11; BMS2=>ID:12; BMS3=>ID:13. txMsg.len = 5; data.f[0] = cell_codes[0][cells_left-1]*0.0001; txMsg.data[0] = data.bytes[0]; @@ -363,23 +353,25 @@ 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) - charging=((motostate & 0b00000010)>>1); + to_charge_or_not_to_charge=((motostate & 0b00000010)>>1); msgAvailable = false; } } } + }