Skip to content

Commit

Permalink
Abox HIL and DAQ (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeOxley authored Feb 1, 2024
1 parent dc80092 commit 84d3f0b
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 50 deletions.
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
},
{ "name": "A_Box",
"cwd": "${workspaceRoot}",
"executable": "./output/precharge/precharge.elf",
"executable": "./output/a_box/a_box.elf",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
Expand All @@ -189,9 +189,9 @@
],
"debuggerArgs": [
"-d",
"${workspaceFolder}/source/precharge"
"${workspaceFolder}/source/a_box"
],
// "preLaunchTask": "build",
"preLaunchTask": "build",
"runToEntryPoint": "main"
},
{ "name": "Driveline Front",
Expand Down
12 changes: 10 additions & 2 deletions common/daq/daq_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,19 @@
},
{
"node_name":"a_box",
"includes":"#include \"orion.h\"",
"includes":"#include \"orion.h\"\n#include \"tmu.h\"\n#include \"main.h\"",
"variables": [
{"var_name":"charge_request_user", "access_phrase":"charge_request_user", "read_only": false, "type":"uint8_t", "length": 1},
{"var_name":"user_charge_current_request", "access_phrase":"user_charge_current_request", "read_only": false, "type":"uint16_t", "length": 16},
{"var_name":"user_charge_voltage_request", "access_phrase":"user_charge_voltage_request", "read_only": false, "type":"uint16_t", "length": 16}
{"var_name":"user_charge_voltage_request", "access_phrase":"user_charge_voltage_request", "read_only": false, "type":"uint16_t", "length": 16},
{"var_name":"tmu_daq_override", "access_phrase": "tmu_daq_override", "read_only": false, "type":"uint8_t", "length": 1},
{"var_name":"tmu_daq_therm", "access_phrase": "tmu_daq_therm", "read_only": false, "type": "uint8_t", "length":4},
{"var_name":"tmu_1", "access_phrase": "adc_readings.tmu_1", "read_only": true, "type": "uint16_t", "length": 12, "unit": "12-bit adc"},
{"var_name":"tmu_2", "access_phrase": "adc_readings.tmu_2", "read_only": true, "type": "uint16_t", "length": 12, "unit": "12-bit adc"},
{"var_name":"tmu_3", "access_phrase": "adc_readings.tmu_3", "read_only": true, "type": "uint16_t", "length": 12, "unit": "12-bit adc"},
{"var_name":"tmu_4", "access_phrase": "adc_readings.tmu_4", "read_only": true, "type": "uint16_t", "length": 12, "unit": "12-bit adc"},
{"var_name":"bms_daq_override", "access_phrase": "bms_daq_override", "read_only": false, "type":"uint8_t", "length": 1},
{"var_name":"bms_daq_stat", "access_phrase": "bms_daq_stat", "read_only": false, "type": "uint8_t", "length":1}
],
"files":[]
},
Expand Down
10 changes: 10 additions & 0 deletions source/a_box/daq/daq.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,23 @@

// BEGIN AUTO VAR INCLUDES
#include "orion.h"
#include "tmu.h"
#include "main.h"
// END AUTO VAR INCLUDES

// BEGIN AUTO VAR DEFS
daq_variable_t tracked_vars[NUM_VARS] = {
{.is_read_only=0, .bit_length=1, .read_var_a=&charge_request_user, .write_var_a=&charge_request_user, },
{.is_read_only=0, .bit_length=16, .read_var_a=&user_charge_current_request, .write_var_a=&user_charge_current_request, },
{.is_read_only=0, .bit_length=16, .read_var_a=&user_charge_voltage_request, .write_var_a=&user_charge_voltage_request, },
{.is_read_only=0, .bit_length=1, .read_var_a=&tmu_daq_override, .write_var_a=&tmu_daq_override, },
{.is_read_only=0, .bit_length=4, .read_var_a=&tmu_daq_therm, .write_var_a=&tmu_daq_therm, },
{.is_read_only=1, .bit_length=12, .read_var_a=&adc_readings.tmu_1, .write_var_a=NULL, },
{.is_read_only=1, .bit_length=12, .read_var_a=&adc_readings.tmu_2, .write_var_a=NULL, },
{.is_read_only=1, .bit_length=12, .read_var_a=&adc_readings.tmu_3, .write_var_a=NULL, },
{.is_read_only=1, .bit_length=12, .read_var_a=&adc_readings.tmu_4, .write_var_a=NULL, },
{.is_read_only=0, .bit_length=1, .read_var_a=&bms_daq_override, .write_var_a=&bms_daq_override, },
{.is_read_only=0, .bit_length=1, .read_var_a=&bms_daq_stat, .write_var_a=&bms_daq_stat, },
};
// END AUTO VAR DEFS

Expand Down
10 changes: 9 additions & 1 deletion source/a_box/daq/daq.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@
#define DAQ_UPDATE_PERIOD 15 // ms

// BEGIN AUTO VAR COUNT
#define NUM_VARS 3
#define NUM_VARS 11
// END AUTO VAR COUNT

// BEGIN AUTO VAR IDs
#define DAQ_ID_CHARGE_REQUEST_USER 0
#define DAQ_ID_USER_CHARGE_CURRENT_REQUEST 1
#define DAQ_ID_USER_CHARGE_VOLTAGE_REQUEST 2
#define DAQ_ID_TMU_DAQ_OVERRIDE 3
#define DAQ_ID_TMU_DAQ_THERM 4
#define DAQ_ID_TMU_1 5
#define DAQ_ID_TMU_2 6
#define DAQ_ID_TMU_3 7
#define DAQ_ID_TMU_4 8
#define DAQ_ID_BMS_DAQ_OVERRIDE 9
#define DAQ_ID_BMS_DAQ_STAT 10
// END AUTO VAR IDs

// BEGIN AUTO FILE STRUCTS
Expand Down
25 changes: 17 additions & 8 deletions source/a_box/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ GPIOInitConfig_t gpio_config[] = {
GPIO_INIT_CANTX_PA12,

// Status and HV Monitoring
GPIO_INIT_OUTPUT(BMS_STATUS_GPIO_Port, BMS_STATUS_Pin, GPIO_OUTPUT_LOW_SPEED),
GPIO_INIT_OUTPUT_OPEN_DRAIN(BMS_STATUS_GPIO_Port, BMS_STATUS_Pin, GPIO_OUTPUT_LOW_SPEED),
GPIO_INIT_INPUT(IMD_HS_PWM_GPIO_Port, IMD_HS_PWM_Pin, GPIO_INPUT_OPEN_DRAIN),
GPIO_INIT_INPUT(IMD_LS_PWM_GPIO_Port, IMD_LS_PWM_Pin, GPIO_INPUT_OPEN_DRAIN),
GPIO_INIT_INPUT(IMD_STATUS_GPIO_Port, IMD_STATUS_Pin, GPIO_INPUT_OPEN_DRAIN),
Expand All @@ -48,10 +48,10 @@ GPIOInitConfig_t gpio_config[] = {
GPIO_INIT_OUTPUT(MUX_B_Port, MUX_B_Pin, GPIO_OUTPUT_LOW_SPEED),
GPIO_INIT_OUTPUT(MUX_C_Port, MUX_C_Pin, GPIO_OUTPUT_LOW_SPEED),
GPIO_INIT_OUTPUT(MUX_D_Port, MUX_D_Pin, GPIO_OUTPUT_LOW_SPEED),
GPIO_INIT_ANALOG(MUX_1_OUT_Port, MUX_1_OUT_Pin),
GPIO_INIT_ANALOG(MUX_2_OUT_Port, MUX_2_OUT_Pin),
GPIO_INIT_ANALOG(MUX_3_OUT_Port, MUX_3_OUT_Pin),
GPIO_INIT_ANALOG(MUX_4_OUT_Port, MUX_4_OUT_Pin),
GPIO_INIT_ANALOG(TMU_1_Port, TMU_1_Pin),
GPIO_INIT_ANALOG(TMU_2_Port, TMU_2_Pin),
GPIO_INIT_ANALOG(TMU_3_Port, TMU_3_Pin),
GPIO_INIT_ANALOG(TMU_4_Port, TMU_4_Pin),

// Board Temp Measurement
GPIO_INIT_ANALOG(BOARD_TEMP_Port, BOARD_TEMP_Pin),
Expand Down Expand Up @@ -88,6 +88,9 @@ extern uint8_t orion_error;
q_handle_t q_tx_can;
q_handle_t q_rx_can;

bool bms_daq_override = false;
bool bms_daq_stat = false;


void PHAL_FaultHandler();
extern void HardFault_Handler();
Expand Down Expand Up @@ -179,6 +182,9 @@ int main (void)
initCANParse(&q_rx_can);
orionInit();

bms_daq_override = false;
bms_daq_stat = false;

if (daqInit(&q_tx_can))
HardFault_Handler();

Expand Down Expand Up @@ -221,7 +227,7 @@ void preflightChecks(void)
switch (state++)
{
case 0 :
if (!initTMU(&tmu)) {
if (initTMU(&tmu)) {
PHAL_FaultHandler();
}

Expand Down Expand Up @@ -296,12 +302,15 @@ void monitorStatus()

// PHAL_writeGPIO(BMS_STATUS_GPIO_Port, BMS_STATUS_Pin, !bms_err);

PHAL_writeGPIO(ERROR_LED_GPIO_Port, ERROR_LED_Pin, bms_err);
if (bms_daq_override | tmu_daq_override) PHAL_toggleGPIO(ERROR_LED_GPIO_Port, ERROR_LED_Pin);
else PHAL_writeGPIO(ERROR_LED_GPIO_Port, ERROR_LED_Pin, bms_err);
readTemps(&tmu);

setFault(ID_IMD_FAULT, imd_err);

PHAL_writeGPIO(BMS_STATUS_GPIO_Port, BMS_STATUS_Pin, bms_err | imd_err);
uint8_t stat = bms_err | imd_err;
if (bms_daq_override) stat = bms_daq_stat;
PHAL_writeGPIO(BMS_STATUS_GPIO_Port, BMS_STATUS_Pin, stat);
}

void monitorTherm() {
Expand Down
47 changes: 19 additions & 28 deletions source/a_box/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,13 @@
#define FAULT_NODE_NAME NODE_A_BOX


// SPI Accel
#define SPI_SCLK_GPIO_Port (GPIOA)
#define SPI_SCLK_Pin (5)
#define SPI_MISO_GPIO_Port (GPIOA)
#define SPI_MISO_Pin (6)
#define SPI_MOSI_GPIO_Port (GPIOA)
#define SPI_MOSI_Pin (7)
#define SPI_CS_ACEL_GPIO_Port (GPIOA)
#define SPI_CS_ACEL_Pin (3)
#define SPI_CS_GYRO_GPIO_Port (GPIOA)
#define SPI_CS_GYRO_Pin (2)
#define SPI_CS_TMU_GPIO_Port (GPIOD)
#define SPI_CS_TMU_GPIO_Pin (15)


// Current Sense
#define I_SENSE_CH1_GPIO_Port (GPIOA) // ADC12_IN5
#define I_SENSE_CH1_GPIO_Port (GPIOA)
#define I_SENSE_CH1_Pin (0)
#define I_SENSE_CH2_GPIO_Port (GPIOA) // ADC12_IN6
#define I_SENSE_CH1_ADC_CHNL (0)
#define I_SENSE_CH2_GPIO_Port (GPIOA)
#define I_SENSE_CH2_Pin (1)
#define I_SENSE_CH2_ADC_CHNL (1)


// BMS Status
Expand All @@ -43,9 +30,9 @@

// IMD Data
#define IMD_HS_PWM_GPIO_Port (GPIOB)
#define IMD_HS_PWM_Pin (6)
#define IMD_LS_PWM_GPIO_Port (GPIOB)
#define IMD_LS_PWM_Pin (7)
#define IMD_HS_PWM_Pin (3)
#define IMD_LS_PWM_GPIO_Port (GPIOA)
#define IMD_LS_PWM_Pin (15)
#define IMD_STATUS_GPIO_Port (GPIOB)
#define IMD_STATUS_Pin (5)

Expand All @@ -70,14 +57,14 @@
#define MUX_D_Pin (6)

//TMU Mux Output Pins
#define MUX_1_OUT_Port (GPIOC)
#define MUX_1_OUT_Pin (0)
#define MUX_2_OUT_Port (GPIOC)
#define MUX_2_OUT_Pin (1)
#define MUX_3_OUT_Port (GPIOC)
#define MUX_3_OUT_Pin (2)
#define MUX_4_OUT_Port (GPIOC)
#define MUX_4_OUT_Pin (3)
#define TMU_1_Port (GPIOC)
#define TMU_1_Pin (0)
#define TMU_2_Port (GPIOC)
#define TMU_2_Pin (1)
#define TMU_3_Port (GPIOC)
#define TMU_3_Pin (2)
#define TMU_4_Port (GPIOC)
#define TMU_4_Pin (3)

// Board Temp
#define BOARD_TEMP_Port (GPIOB)
Expand All @@ -86,6 +73,7 @@
// 5V Monitoring
#define VSENSE_5V_Port (GPIOA)
#define VSENSE_5V_Pin (7)
#define VSENSE_5V_ADC_CHNL (7)

// ADC Channels
#define TMU_1_ADC_CHANNEL (10)
Expand All @@ -105,4 +93,7 @@ typedef struct
}__attribute__((packed)) ADCReadings_t;
volatile extern ADCReadings_t adc_readings;

extern bool bms_daq_override;
extern bool bms_daq_stat;

#endif
22 changes: 14 additions & 8 deletions source/a_box/tmu/tmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ extern q_handle_t q_tx_can;
//uint8_t curr_therm;
uint8_t num_bad1, num_bad2, num_bad3, num_bad4;
bool overtemp = false;
bool tmu_daq_override = false;
uint8_t tmu_daq_therm = 0;

//Function defs not needed by any other file
void resistance_to_temp(float resistance, uint16_t *temp);
Expand All @@ -25,10 +27,12 @@ bool initTMU(tmu_handle_t *tmu) {
num_bad2 = 0;
num_bad3 = 0;
num_bad4 = 0;
PHAL_writeGPIO(MUX_1_OUT_Port, MUX_1_OUT_Pin, 0);
PHAL_writeGPIO(MUX_2_OUT_Port, MUX_2_OUT_Pin, 0);
PHAL_writeGPIO(MUX_3_OUT_Port, MUX_3_OUT_Pin, 0);
PHAL_writeGPIO(MUX_4_OUT_Port, MUX_4_OUT_Pin, 0);
tmu_daq_override = false;
tmu_daq_therm = 0;
PHAL_writeGPIO(MUX_A_Port, MUX_A_Pin, 0);
PHAL_writeGPIO(MUX_B_Port, MUX_B_Pin, 0);
PHAL_writeGPIO(MUX_C_Port, MUX_C_Pin, 0);
PHAL_writeGPIO(MUX_D_Port, MUX_D_Pin, 0);
return false;
}

Expand Down Expand Up @@ -185,10 +189,12 @@ void readTemps(tmu_handle_t *tmu) {
}


PHAL_writeGPIO(MUX_1_OUT_Port, MUX_1_OUT_Pin, (curr_therm & 0x1));
PHAL_writeGPIO(MUX_2_OUT_Port, MUX_2_OUT_Pin, (curr_therm & 0x2));
PHAL_writeGPIO(MUX_3_OUT_Port, MUX_3_OUT_Pin, (curr_therm & 0x4));
PHAL_writeGPIO(MUX_4_OUT_Port, MUX_4_OUT_Pin, (curr_therm & 0x8));
uint8_t therm = curr_therm;
if (tmu_daq_override) therm = tmu_daq_therm;
PHAL_writeGPIO(MUX_A_Port, MUX_A_Pin, (therm & 0x1));
PHAL_writeGPIO(MUX_B_Port, MUX_B_Pin, (therm & 0x2));
PHAL_writeGPIO(MUX_C_Port, MUX_C_Pin, (therm & 0x4));
PHAL_writeGPIO(MUX_D_Port, MUX_D_Pin, (therm & 0x8));

}

Expand Down
3 changes: 3 additions & 0 deletions source/a_box/tmu/tmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ typedef struct {
int16_t tmu3[16];
int16_t tmu4[16];
} tmu_handle_t;
extern bool tmu_daq_override;
extern uint8_t tmu_daq_therm;

void readTemps(tmu_handle_t *tmu);
bool initTMU(tmu_handle_t *tmu);

Expand Down

0 comments on commit 84d3f0b

Please sign in to comment.