CUER
/
charger_code
Code to run on the charger board (used to charge the car from the mains).
charger.h@0:6d930d0d13a1, 2017-05-06 (annotated)
- Committer:
- drajan
- Date:
- Sat May 06 20:28:22 2017 +0000
- Revision:
- 0:6d930d0d13a1
- Child:
- 1:0c77e20b4d4c
CAN stuff still needs to be implemented.
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 | |
drajan | 0:6d930d0d13a1 | 3 | #define MAX_VOLTAGE 155.0 |
drajan | 0:6d930d0d13a1 | 4 | #define MAX_CURRENT 10.0 |
drajan | 0:6d930d0d13a1 | 5 | #define KI_CHARGE 2.5 |
drajan | 0:6d930d0d13a1 | 6 | #define KI_BALANCE 0.6 |
drajan | 0:6d930d0d13a1 | 7 | #define TIME_STEP 500 |
drajan | 0:6d930d0d13a1 | 8 | #define TEMP_RAMP_START -5.0 |
drajan | 0:6d930d0d13a1 | 9 | #define TEMP_RAMP_FINISH -1.5 |
drajan | 0:6d930d0d13a1 | 10 | |
drajan | 0:6d930d0d13a1 | 11 | #define CHARGER_MSG_TIMEOUT 6000 //ms |
drajan | 0:6d930d0d13a1 | 12 | #define BMS_MSG_TIMEOUT 2000 //ms |
drajan | 0:6d930d0d13a1 | 13 | |
drajan | 0:6d930d0d13a1 | 14 | //change to whichever pins LEDs are connected to. |
drajan | 0:6d930d0d13a1 | 15 | DigitalOut green_led(p21); |
drajan | 0:6d930d0d13a1 | 16 | DigitalOut yellow_led(p22); |
drajan | 0:6d930d0d13a1 | 17 | DigitalOut red_led(p23); |
drajan | 0:6d930d0d13a1 | 18 | |
drajan | 0:6d930d0d13a1 | 19 | Timer chargerboard_timer; |
drajan | 0:6d930d0d13a1 | 20 | |
drajan | 0:6d930d0d13a1 | 21 | void get_charger_data(void); |
drajan | 0:6d930d0d13a1 | 22 | void get_voltage_data(void); |
drajan | 0:6d930d0d13a1 | 23 | void get_bms_data(void); |
drajan | 0:6d930d0d13a1 | 24 | void calculate_current(float voltage_error, float temp_margin, float *current, float *voltage); |
drajan | 0:6d930d0d13a1 | 25 | |
drajan | 0:6d930d0d13a1 | 26 | int chrg_status_recv_time; |
drajan | 0:6d930d0d13a1 | 27 | int bms_minmax_cell_volts_recv_time; |
drajan | 0:6d930d0d13a1 | 28 | int bms_pack_status_recv_time; |
drajan | 0:6d930d0d13a1 | 29 | bool bms_timeout; |
drajan | 0:6d930d0d13a1 | 30 | bool charger_timeout; |
drajan | 0:6d930d0d13a1 | 31 | bool charge_finished; |
drajan | 0:6d930d0d13a1 | 32 | |
drajan | 0:6d930d0d13a1 | 33 | |
drajan | 0:6d930d0d13a1 | 34 | float voltage_error=0; //(V) |
drajan | 0:6d930d0d13a1 | 35 | float temp_margin = 0; |
drajan | 0:6d930d0d13a1 | 36 | float discharge_error; |
drajan | 0:6d930d0d13a1 | 37 | float capacity; |
drajan | 0:6d930d0d13a1 | 38 | |
drajan | 0:6d930d0d13a1 | 39 | float min_cell_voltage; //(V) |
drajan | 0:6d930d0d13a1 | 40 | float max_cell_voltage;//(V) |
drajan | 0:6d930d0d13a1 | 41 | |
drajan | 0:6d930d0d13a1 | 42 | float rising_voltage_threshold; //(V) |
drajan | 0:6d930d0d13a1 | 43 | float falling_voltage_threshold;//(V) |
drajan | 0:6d930d0d13a1 | 44 | int bms_status; |
drajan | 0:6d930d0d13a1 | 45 | |
drajan | 0:6d930d0d13a1 | 46 | float charger_current, charger_voltage; |
drajan | 0:6d930d0d13a1 | 47 | |
drajan | 0:6d930d0d13a1 | 48 | float desired_current = 0, desired_voltage = MAX_VOLTAGE; |
drajan | 0:6d930d0d13a1 | 49 |