![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Ultima versão da banca de ensaios BMS Fev2017
Dependencies: CANnucleo LTC68041 mbed
Fork of BMS_4 by
Diff: main.cpp
- Revision:
- 32:a52605800210
- Parent:
- 31:1fab4bb4e9ee
- Child:
- 33:54861cd567cd
--- a/main.cpp Fri Oct 28 15:47:39 2016 +0000 +++ b/main.cpp Sat Oct 29 00:38:17 2016 +0000 @@ -1,24 +1,8 @@ -/*notes:--------------------- -*-organizar codigo -*-diminuir tempos das interrupções etc -*-diminuir tempos mortos durante balanceamento -* -* -* -* ------------------------------*/ - - - - #include "CANnucleo.h" #include "mbed.h" #include "LTC68041.h" - - uint8_t const TOTAL_IC = 1;//!<number of ICs in the daisy chain - uint8_t rx_cfg[TOTAL_IC][8]; uint8_t tx_cfg[TOTAL_IC][6]; uint16_t aux_codes[TOTAL_IC][6]; @@ -29,6 +13,7 @@ CANnucleo::CANMessage rxMsg; CANnucleo::CANMessage txMsg; DigitalOut led(PA_5); + /*!*********************************** \brief Initializes the configuration array **************************************/ @@ -131,7 +116,6 @@ wait(0.2); } } - char cells_left=0; Ticker ticker; Ticker sender; @@ -151,24 +135,17 @@ } } - - - - void check_charging_voltage() { wakeup_idle(); LTC6804_adcv(); - wait_ms(10); wakeup_idle(); err = LTC6804_rdcv(0, TOTAL_IC,cell_codes); if (err == -1) { pec_error(); } - cells_left = 12; - for (int current_ic = 0 ; current_ic < TOTAL_IC; current_ic++) { for (int i=0; i<12; i++) { if(cell_codes[current_ic][i]*0.0001 > 3.6) { @@ -220,15 +197,10 @@ LTC6804_wrcfg(TOTAL_IC,tx_cfg); } - - - - void check_discharging_voltage() { wakeup_idle(); LTC6804_adcv(); - wait_ms(10); wakeup_idle(); err = LTC6804_rdcv(0, TOTAL_IC,cell_codes); @@ -251,11 +223,9 @@ }*/ //print_cells2(); cells_left = 12; - -tx_cfg[0][4] = tx_cfg[0][4] & 0b00000000; //para desactivar balanceamento durante a descarga -tx_cfg[0][5] = tx_cfg[0][5] & 0b11110000; - -//print_cells2(); + tx_cfg[0][4] = tx_cfg[0][4] & 0b00000000; //para desactivar balanceamento durante a descarga + tx_cfg[0][5] = tx_cfg[0][5] & 0b11110000; + //print_cells2(); LTC6804_wrcfg(TOTAL_IC,tx_cfg); } @@ -287,7 +257,6 @@ int main() { data data; - //printf("starting\n\r"); led =1; wait(1); @@ -295,8 +264,7 @@ to_charge_or_not_to_charge=0; charging = 0; discharging = 1; - - ticker.attach(&monitor, 5); + ticker.attach(&monitor, 2); LTC6804_initialize(); init_cfg(); //write configuration @@ -314,7 +282,6 @@ pec_error(); } wait(0.5); - wakeup_idle(); __disable_irq(); LTC6804_adcv(); @@ -342,11 +309,9 @@ sender.attach(&message_trigger,0.1); } 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]; @@ -360,20 +325,15 @@ cells_left++; //to_send=1; } - } - if(msgAvailable) { int len = can.read(rxMsg); 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); msgAvailable = false; } } } - }