CUER
/
charger_code
Code to run on the charger board (used to charge the car from the mains).
Diff: charger.h
- Revision:
- 5:756fae795d37
- Parent:
- 3:a7626dffb64a
- Child:
- 7:70cf5bff23f9
--- a/charger.h Thu Jul 27 21:21:32 2017 +0000 +++ b/charger.h Sun Jul 30 22:59:37 2017 +0000 @@ -3,56 +3,34 @@ #include "mbed.h" +#define DEBUG 1 + #define MAX_VOLTAGE 155000.0 #define MAX_CURRENT 10000.0 -#define RISING_BALANCE_THRESHOLD 154000.0 //DUMMY VALUE FOR NOW, THINK ABOUT THE ACTUAL VALUE -#define KI_CHARGE 2500.0 -#define KI_BALANCE 600.0 +#define RISING_BALANCE_THRESHOLD 4150 //DUMMY VALUE FOR NOW, THINK ABOUT THE ACTUAL VALUE +#define KI_CHARGE 2.5 +#define KI_BALANCE 0.6 #define TIME_STEP 500 -#define TEMP_RAMP_START -5.0 -#define TEMP_RAMP_FINISH -1.5 +#define PACK_CAPACITY 24 //in Ah +//#define TEMP_RAMP_START -5.0 +//#define TEMP_RAMP_FINISH -1.5 #define CHARGER_MSG_TIMEOUT_MS 6000 #define BMS_MSG_TIMEOUT_MS 2000 +//Macros for charging to avoid confusion and potentioal errors +#define START_CHARGING 0 +#define STOP_CHARGING 1 #define CAN_BUFFER_SIZE 255 //Setting this to be quite large, should be equal to max # of ids expected to receive // CAN pins #define CAR_CAN_WRITE_PIN p29 #define CAR_CAN_READ_PIN p30 - #define CHARGER_CAN_WRITE_PIN p10 #define CHARGER_CAN_READ_PIN p9 -DigitalOut green_led(p21); //charging LED -DigitalOut yellow_led(p22); //timeout LED -DigitalOut red_led(p23); //error LED -void calculate_current(float voltage_error, float temp_margin, float *current, float *voltage); - -uint8_t charger_status; //status packet given by charger, see Elcon CAN Specification in google drive -bool comms_timeout; -bool charger_failure; -bool charge_finished; -bool bms_error; - - -float voltage_error=0; //mV, this is the rising balance threshold minus the max cell voltage, need to try and bring this to 0 -float temp_margin = 0; //degrees C, this is the max cell temperature minus max cell temperature limit, need to avoid this hitting 0 -float discharge_error; //mV, not currently used -float pack_capacity; //Ah, not currently used - -float min_cell_voltage; //mV -float max_cell_voltage;//mV - -float charger_current; //mA -float charger_voltage; //mV - -float desired_current = 0; //mA -float desired_voltage = MAX_VOLTAGE; //mV - -uint8_t charger_control = 1; //0 or 1, 0 means start charging, 1 means stop charging #endif \ No newline at end of file