CUER
/
charger_code
Code to run on the charger board (used to charge the car from the mains).
Diff: charger.h
- Revision:
- 1:0c77e20b4d4c
- Parent:
- 0:6d930d0d13a1
- Child:
- 3:a7626dffb64a
--- a/charger.h Sat May 06 20:28:22 2017 +0000 +++ b/charger.h Thu Jul 06 21:27:26 2017 +0000 @@ -1,49 +1,53 @@ #include "mbed.h" -#define MAX_VOLTAGE 155.0 -#define MAX_CURRENT 10.0 -#define KI_CHARGE 2.5 -#define KI_BALANCE 0.6 +#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 TIME_STEP 500 #define TEMP_RAMP_START -5.0 #define TEMP_RAMP_FINISH -1.5 -#define CHARGER_MSG_TIMEOUT 6000 //ms -#define BMS_MSG_TIMEOUT 2000 //ms +#define CHARGER_MSG_TIMEOUT_MS 6000 +#define BMS_MSG_TIMEOUT_MS 2000 + + +#define CAN_BUFFER_SIZE 255 //Setting this to be quite large, should be equal to max # of ids expected to receive -//change to whichever pins LEDs are connected to. -DigitalOut green_led(p21); -DigitalOut yellow_led(p22); -DigitalOut red_led(p23); +// CAN pins +#define CAR_CAN_WRITE_PIN p29 +#define CAR_CAN_READ_PIN p30 -Timer chargerboard_timer; +#define CHARGER_CAN_WRITE_PIN p10 +#define CHARGER_CAN_READ_PIN p9 -void get_charger_data(void); -void get_voltage_data(void); -void get_bms_data(void); +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); -int chrg_status_recv_time; -int bms_minmax_cell_volts_recv_time; -int bms_pack_status_recv_time; -bool bms_timeout; -bool charger_timeout; +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; //(V) -float temp_margin = 0; -float discharge_error; -float capacity; +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; //(V) -float max_cell_voltage;//(V) +float min_cell_voltage; //mV +float max_cell_voltage;//mV -float rising_voltage_threshold; //(V) -float falling_voltage_threshold;//(V) -int bms_status; +float charger_current; //mA +float charger_voltage; //mV -float charger_current, charger_voltage; +float desired_current = 0; //mA +float desired_voltage = MAX_VOLTAGE; //mV -float desired_current = 0, desired_voltage = MAX_VOLTAGE; +uint8_t charger_control = 1; //0 or 1, 0 means start charging, 1 means stop charging \ No newline at end of file