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

Dependencies:   mbed CUER_CAN

charger.h

Committer:
DasSidG
Date:
2017-07-06
Revision:
1:0c77e20b4d4c
Parent:
0:6d930d0d13a1
Child:
3:a7626dffb64a

File content as of revision 1:0c77e20b4d4c:

#include "mbed.h"

#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_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

// 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