A public repository for BMS algorithms for a NUCLEO BOARD.

Dependencies:   mbed

Hi Everyone!

Welcome to this repository from Howey's Research Group at the University of Oxford.

The code published here incorporates BMS algorithms for diagnosis functions such as SOC, SOH and Power estimation on a Kokam 53Ah Li-ion battery. This code was designed to work with a NUCLEO F401-RE board and to be tested with a dSPACE HIL Simulator. A short guide on how the set up works is available at https://bitbucket.org/ff95/bms .

The code is made up of three key parts. "Headers" and "Source" folders and the "main.cpp" file. As the code was generated by converting a Simulink model ( available on the BitBucket page), the headers and source code files generated by the conversion are in the corresponding "Headers" and "Source" folders. The "main.cpp" file sets up the ADC, the USB data transmission and starts the estimation (once a character "y" has been received by the computer it is connected to). It also transmits the data from the estimation via USB. Explanation on how to set up the communication with the board is available at BitBucket webpage, from where a MATLAB file can be downloaded which allows real time communication.

For any questions you can contact the author at federicomariaferrari@gmail.com .

The Simulink and Matlab files, together with a short guide, are all available at: https://bitbucket.org/ff95/bms.

Thanks for trying this out!

Federico

main.cpp

Committer:
fmferrari
Date:
2016-12-13
Revision:
12:bf3e3b87224e
Parent:
11:e39c490420d2
Child:
13:831eab218c33

File content as of revision 12:bf3e3b87224e:

/**
* @author Damien Frost
*
* @section LICENSE
*
*   Copyright (c) 2016 Damien Frost
*
*   Permission is hereby granted, free of charge, to any person obtaining a copy
*   of this software and associated documentation files (the "Software"), to deal
*   in the Software without restriction, including without limitation the rights
*   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
*   copies of the Software, and to permit persons to whom the Software is
*   furnished to do so, subject to the following conditions:
*
*   The above copyright notice and this permission notice shall be included in
*   all copies or substantial portions of the Software.
*
*   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
*   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
*   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
*   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
*   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
*   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
*   THE SOFTWARE.
*
* @file "main.cpp"
*
* @section DESCRIPTION
*   Simple Internet of Things main program. The device sends data every 3
*   seconds, and can receive data from a server.
*
*/

#include "mbed.h"
#include "EKF.h"



Timer OutputTimer; 
Timer OperationTimer;
Serial TRANSMIT(SERIAL_TX, SERIAL_RX);
 
AnalogIn VoltageSensor(PA_0);
AnalogIn CurrentSensor(PA_1);
DigitalOut DATATRANSMISSION(LED1);
float VoltageMeas = 0;
float CurrentMeas = 0;
float Result_V = 0;
float  Result_I = 0;
float  MinStepRes = 0;
float SocOutput = 0.0f;
float R0Output=0.0f;


float  mVoltRange  = 3300; // This is the supplay voltage of ADC (or MCU)
float  ADCres = 65536; // This is the ADC resolution



int main() {
    OperationTimer.start();
    OutputTimer.start();
    
    EKF_initialize();
    
    TRANSMIT.printf("Starting up...\n\r" );

    // Inifinite main loop:
    while(1) {
         DATATRANSMISSION=1;
        
        // Sample the ADCs:
        VoltageMeas = VoltageSensor.read_u16();
        CurrentMeas = CurrentSensor.read_u16();
      
         MinStepRes = (mVoltRange / ADCres);
        // Convert meas in Volt and put it in Result_V
        Result_V = ((MinStepRes * VoltageMeas))/1000;
        Result_I = ((MinStepRes * CurrentMeas))/1000;
        // Display the result via Virtual COM
        

        EKF_U.Voltage=Result_V;
        EKF_U.Current=Result_V/100000;
      // EKF_U.Current=Result_I;
      
         if(OperationTimer.read()>(0.00025f))
               {
              EKF_step();
              SocOutput = EKF_Y.SOC;
              R0Output=EKF_Y.R0;
              OperationTimer.reset();
       
        if(OutputTimer.read()>(2.5f)){
            DATATRANSMISSION=0;
            TRANSMIT.printf("Estimated SOC is , %f \n", EKF_Y.SOC);
            TRANSMIT.printf("Estimated R0 is, %f \n", EKF_Y.R0);
            TRANSMIT.printf("VOLTAGE is, %f \n", EKF_U.Voltage);
            TRANSMIT.printf("CURRENT is, %f \n\r", EKF_U.Current);
   
            // Reset the timer:
           OutputTimer.reset();}
             }
         }
        
    }