Code to run on the charger board (used to charge the car from the mains).

Dependencies:   mbed CUER_CAN

Committer:
DasSidG
Date:
Thu Jul 27 21:00:52 2017 +0000
Revision:
3:a7626dffb64a
Parent:
1:0c77e20b4d4c
Child:
5:756fae795d37
Code is now theoretically finished; completely untested however.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DasSidG 3:a7626dffb64a 1 #ifndef CHARGER_H
DasSidG 3:a7626dffb64a 2 #define CHARGER_H
DasSidG 3:a7626dffb64a 3
drajan 0:6d930d0d13a1 4 #include "mbed.h"
drajan 0:6d930d0d13a1 5
DasSidG 1:0c77e20b4d4c 6 #define MAX_VOLTAGE 155000.0
DasSidG 1:0c77e20b4d4c 7 #define MAX_CURRENT 10000.0
DasSidG 1:0c77e20b4d4c 8 #define RISING_BALANCE_THRESHOLD 154000.0 //DUMMY VALUE FOR NOW, THINK ABOUT THE ACTUAL VALUE
DasSidG 1:0c77e20b4d4c 9 #define KI_CHARGE 2500.0
DasSidG 1:0c77e20b4d4c 10 #define KI_BALANCE 600.0
drajan 0:6d930d0d13a1 11 #define TIME_STEP 500
drajan 0:6d930d0d13a1 12 #define TEMP_RAMP_START -5.0
drajan 0:6d930d0d13a1 13 #define TEMP_RAMP_FINISH -1.5
drajan 0:6d930d0d13a1 14
DasSidG 1:0c77e20b4d4c 15 #define CHARGER_MSG_TIMEOUT_MS 6000
DasSidG 1:0c77e20b4d4c 16 #define BMS_MSG_TIMEOUT_MS 2000
DasSidG 1:0c77e20b4d4c 17
DasSidG 1:0c77e20b4d4c 18
DasSidG 1:0c77e20b4d4c 19 #define CAN_BUFFER_SIZE 255 //Setting this to be quite large, should be equal to max # of ids expected to receive
drajan 0:6d930d0d13a1 20
DasSidG 1:0c77e20b4d4c 21 // CAN pins
DasSidG 1:0c77e20b4d4c 22 #define CAR_CAN_WRITE_PIN p29
DasSidG 1:0c77e20b4d4c 23 #define CAR_CAN_READ_PIN p30
drajan 0:6d930d0d13a1 24
DasSidG 1:0c77e20b4d4c 25 #define CHARGER_CAN_WRITE_PIN p10
DasSidG 1:0c77e20b4d4c 26 #define CHARGER_CAN_READ_PIN p9
drajan 0:6d930d0d13a1 27
DasSidG 1:0c77e20b4d4c 28 DigitalOut green_led(p21); //charging LED
DasSidG 1:0c77e20b4d4c 29 DigitalOut yellow_led(p22); //timeout LED
DasSidG 1:0c77e20b4d4c 30 DigitalOut red_led(p23); //error LED
DasSidG 1:0c77e20b4d4c 31
drajan 0:6d930d0d13a1 32 void calculate_current(float voltage_error, float temp_margin, float *current, float *voltage);
drajan 0:6d930d0d13a1 33
DasSidG 1:0c77e20b4d4c 34 uint8_t charger_status; //status packet given by charger, see Elcon CAN Specification in google drive
DasSidG 1:0c77e20b4d4c 35 bool comms_timeout;
DasSidG 1:0c77e20b4d4c 36 bool charger_failure;
drajan 0:6d930d0d13a1 37 bool charge_finished;
DasSidG 1:0c77e20b4d4c 38 bool bms_error;
drajan 0:6d930d0d13a1 39
drajan 0:6d930d0d13a1 40
DasSidG 1:0c77e20b4d4c 41 float voltage_error=0; //mV, this is the rising balance threshold minus the max cell voltage, need to try and bring this to 0
DasSidG 1:0c77e20b4d4c 42 float temp_margin = 0; //degrees C, this is the max cell temperature minus max cell temperature limit, need to avoid this hitting 0
DasSidG 1:0c77e20b4d4c 43 float discharge_error; //mV, not currently used
DasSidG 1:0c77e20b4d4c 44 float pack_capacity; //Ah, not currently used
drajan 0:6d930d0d13a1 45
DasSidG 1:0c77e20b4d4c 46 float min_cell_voltage; //mV
DasSidG 1:0c77e20b4d4c 47 float max_cell_voltage;//mV
drajan 0:6d930d0d13a1 48
DasSidG 1:0c77e20b4d4c 49 float charger_current; //mA
DasSidG 1:0c77e20b4d4c 50 float charger_voltage; //mV
drajan 0:6d930d0d13a1 51
DasSidG 1:0c77e20b4d4c 52 float desired_current = 0; //mA
DasSidG 1:0c77e20b4d4c 53 float desired_voltage = MAX_VOLTAGE; //mV
drajan 0:6d930d0d13a1 54
DasSidG 1:0c77e20b4d4c 55 uint8_t charger_control = 1; //0 or 1, 0 means start charging, 1 means stop charging
DasSidG 3:a7626dffb64a 56
DasSidG 3:a7626dffb64a 57 #endif
drajan 0:6d930d0d13a1 58