CUER
/
charger_code
Code to run on the charger board (used to charge the car from the mains).
charger.h@1:0c77e20b4d4c, 2017-07-06 (annotated)
- Committer:
- DasSidG
- Date:
- Thu Jul 06 21:27:26 2017 +0000
- Revision:
- 1:0c77e20b4d4c
- Parent:
- 0:6d930d0d13a1
- Child:
- 3:a7626dffb64a
Code majorly changed:; ; Structure changed significantly; All of the CAN-related functions, structures etc. added (but not yet tested); Still need to add some of the main program logic in terms of deciding when/when not to charge etc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
drajan | 0:6d930d0d13a1 | 1 | #include "mbed.h" |
drajan | 0:6d930d0d13a1 | 2 | |
DasSidG | 1:0c77e20b4d4c | 3 | #define MAX_VOLTAGE 155000.0 |
DasSidG | 1:0c77e20b4d4c | 4 | #define MAX_CURRENT 10000.0 |
DasSidG | 1:0c77e20b4d4c | 5 | #define RISING_BALANCE_THRESHOLD 154000.0 //DUMMY VALUE FOR NOW, THINK ABOUT THE ACTUAL VALUE |
DasSidG | 1:0c77e20b4d4c | 6 | #define KI_CHARGE 2500.0 |
DasSidG | 1:0c77e20b4d4c | 7 | #define KI_BALANCE 600.0 |
drajan | 0:6d930d0d13a1 | 8 | #define TIME_STEP 500 |
drajan | 0:6d930d0d13a1 | 9 | #define TEMP_RAMP_START -5.0 |
drajan | 0:6d930d0d13a1 | 10 | #define TEMP_RAMP_FINISH -1.5 |
drajan | 0:6d930d0d13a1 | 11 | |
DasSidG | 1:0c77e20b4d4c | 12 | #define CHARGER_MSG_TIMEOUT_MS 6000 |
DasSidG | 1:0c77e20b4d4c | 13 | #define BMS_MSG_TIMEOUT_MS 2000 |
DasSidG | 1:0c77e20b4d4c | 14 | |
DasSidG | 1:0c77e20b4d4c | 15 | |
DasSidG | 1:0c77e20b4d4c | 16 | #define CAN_BUFFER_SIZE 255 //Setting this to be quite large, should be equal to max # of ids expected to receive |
drajan | 0:6d930d0d13a1 | 17 | |
DasSidG | 1:0c77e20b4d4c | 18 | // CAN pins |
DasSidG | 1:0c77e20b4d4c | 19 | #define CAR_CAN_WRITE_PIN p29 |
DasSidG | 1:0c77e20b4d4c | 20 | #define CAR_CAN_READ_PIN p30 |
drajan | 0:6d930d0d13a1 | 21 | |
DasSidG | 1:0c77e20b4d4c | 22 | #define CHARGER_CAN_WRITE_PIN p10 |
DasSidG | 1:0c77e20b4d4c | 23 | #define CHARGER_CAN_READ_PIN p9 |
drajan | 0:6d930d0d13a1 | 24 | |
DasSidG | 1:0c77e20b4d4c | 25 | DigitalOut green_led(p21); //charging LED |
DasSidG | 1:0c77e20b4d4c | 26 | DigitalOut yellow_led(p22); //timeout LED |
DasSidG | 1:0c77e20b4d4c | 27 | DigitalOut red_led(p23); //error LED |
DasSidG | 1:0c77e20b4d4c | 28 | |
drajan | 0:6d930d0d13a1 | 29 | void calculate_current(float voltage_error, float temp_margin, float *current, float *voltage); |
drajan | 0:6d930d0d13a1 | 30 | |
DasSidG | 1:0c77e20b4d4c | 31 | uint8_t charger_status; //status packet given by charger, see Elcon CAN Specification in google drive |
DasSidG | 1:0c77e20b4d4c | 32 | bool comms_timeout; |
DasSidG | 1:0c77e20b4d4c | 33 | bool charger_failure; |
drajan | 0:6d930d0d13a1 | 34 | bool charge_finished; |
DasSidG | 1:0c77e20b4d4c | 35 | bool bms_error; |
drajan | 0:6d930d0d13a1 | 36 | |
drajan | 0:6d930d0d13a1 | 37 | |
DasSidG | 1:0c77e20b4d4c | 38 | 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 | 39 | 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 | 40 | float discharge_error; //mV, not currently used |
DasSidG | 1:0c77e20b4d4c | 41 | float pack_capacity; //Ah, not currently used |
drajan | 0:6d930d0d13a1 | 42 | |
DasSidG | 1:0c77e20b4d4c | 43 | float min_cell_voltage; //mV |
DasSidG | 1:0c77e20b4d4c | 44 | float max_cell_voltage;//mV |
drajan | 0:6d930d0d13a1 | 45 | |
DasSidG | 1:0c77e20b4d4c | 46 | float charger_current; //mA |
DasSidG | 1:0c77e20b4d4c | 47 | float charger_voltage; //mV |
drajan | 0:6d930d0d13a1 | 48 | |
DasSidG | 1:0c77e20b4d4c | 49 | float desired_current = 0; //mA |
DasSidG | 1:0c77e20b4d4c | 50 | float desired_voltage = MAX_VOLTAGE; //mV |
drajan | 0:6d930d0d13a1 | 51 | |
DasSidG | 1:0c77e20b4d4c | 52 | uint8_t charger_control = 1; //0 or 1, 0 means start charging, 1 means stop charging |
drajan | 0:6d930d0d13a1 | 53 |