Skip to content

Commit

Permalink
Post-Competition Release, 2.0 (#106)
Browse files Browse the repository at this point in the history
* implemented watchdog (#83)

* implemented watchdog

* fixed gpio toggle order

---------

Co-authored-by: Dylan Donahue <[email protected]>

* #72 [Compute] - Add in PWM to control fans (#84)

* regenerated IOC with timer changes

* ^

* added last timer

* Implemented #72, function to individual control fan via PWM. Wrapper function not yet created

* Minor tweaks to fan_select pwm function

* Fixing make issues

* Fixing make issues pt.2

* Fixing make issues pt.3 (forgot to save, oops)

* More build error fixes

* Safety checks for if out-of-range index is passed in

* Fixed premature return statement

* Removed wrapper function definition for now

* moved objects, setup fan init

* proper calls

* fixed enum

* nit fixes

---------

Co-authored-by: Dylan Donahue <[email protected]>
Co-authored-by: dyldonahue <[email protected]>

* #77 [GPIO Expander] - Route isoSPI to GPIO Exander (#85)

* Updated function for creating/sending I2C commands to GPIO expander. Old method commented out for reference if needed, remove after verification

* Minor syntax fix for i2c write register call within function

* adjusted ic address

* removed comment

---------

Co-authored-by: Dylan Donahue <[email protected]>

* Spi debug (#89)

* ioc change

* ioc fix

---------

Co-authored-by: Dylan Donahue <[email protected]>

* Feature/adc (#91)

* updated pins to adc in ioc

* updated for 5v ref pin

* added driver files

* implemented adc/current sensing

* added DMA to ioc

* added DMA adc checks

* ioc issues

* ^

* updated makefile to add drivers

* verified adc

---------

Co-authored-by: Dylan Donahue <[email protected]>

* Feature/segment mapping (#92)

* remapped segment

* fixed mapping

---------

Co-authored-by: Dylan Donahue <[email protected]>

* Initial compose (#90)

* initial compose

* updated dcl CAN msg (#93)

* updated dcl CAN msg

* updated subomdule hash

* fixed can IDs

---------

Co-authored-by: Dylan Donahue <[email protected]>

* updated therm map (#95)

Co-authored-by: Dylan Donahue <[email protected]>

* Changes for getting car running

* updated res to temp valc (#96)

* Feature/debug (#102)

* updated ioc

* fixed adc

* Updating fault state

* Converting to millivolts

* Adjusting current sensing algorithm

* Adjusting config values and disabling faults

* fixed faults

* called mc can msg

* linduino updates

* fixed adc hardware smoothing

* therms disabled

* add ids

* shep timing

* Add base

* submoduel hash

* Redoing some fault stuff and changing CAN message sending

* updated ioc so CAN doesnt crash

* Retrying therm mapping

* Feature/stm watchdog (#98)

* added stm watchdog

* updated can to 500kbts

* updated makefile

* Fixing watchdog

* started therm disable

* Uncommenting DCL message

* therm averaging and disabling

* Charger can (#99)

* replace msg content with msg presence for bmsdata.is_charger_connected

* charger msg timeout

* can2 is 500kb/s, ioc changes, codegen, support for extended CAN IDs, updated embedded-base

* charger send msg, charger connected timer

* ioc change for can speed

* replace msg content with msg presence for bmsdata.is_charger_connected

* charger msg timeout

* rebase

* charger send msg, charger connected timer

* ioc change for can speed

* lots

* ioc and charging merge fixes

* balancing

* removed shitty comments, compatible with extended ID, submod has extended id can

---------

Co-authored-by: Scott Abramson <[email protected]>
Co-authored-by: Scott A <[email protected]>
Co-authored-by: Jack Rubacha <[email protected]>

* send extended can

* therms mapping

* Therm averaging algo

* Update compute.c

* Fixing therm calcs

* added mapping correction for configure_balancing (#100)

* added mapping correction for configure_balancing

* added mapping correction for configure_balancing

* I think fixing it

---------

Co-authored-by: nwdepatie <[email protected]>

* re disabled therm map

* changed dcl and ccl to int16, no more packed

* Revert "changed dcl and ccl to int16, no more packed"

This reverts commit 7b98eda.

* endian swap

* can debug

* Disabling charger

* Feature/charging algo (#101)

* updated charging algo

* fixed charging param

* final charging fix

* therms debug

* fuck u matt

* algo fix

* NO MORE CHARGING

* switching can line

* lowered max voltage timer

* misc edits

* clean up

---------

Co-authored-by: nwdepatie <[email protected]>
Co-authored-by: Jack Rubacha <[email protected]>
Co-authored-by: Scott Abramson <[email protected]>
Co-authored-by: Scott A <[email protected]>

* impl and verified new (old) current sensor (#103)

* Miscellaneous FSAE changes (#104)

* Clamping voltages within a non noisy range

* Fixing DCL copy timer and clearing all faults every loop

* Copying over other thermistors from last reading

* Filtered mode works

* Disabling thermistors

* Printing cell temperatures

* inverted ccl

* Making Max Temp based on cell temps instead of thermistors

* Using continuous CCL for max CCL

* Disregarding therms if bad ADC reading

* Adding in lower bound temperature clamp

---------

Co-authored-by: nwdepatie <[email protected]>

---------

Co-authored-by: Dylan Donahue <[email protected]>
Co-authored-by: ameall <[email protected]>
Co-authored-by: Jack Rubacha <[email protected]>
Co-authored-by: nwdepatie <[email protected]>
Co-authored-by: Scott Abramson <[email protected]>
Co-authored-by: Scott A <[email protected]>
  • Loading branch information
7 people authored Jun 17, 2024
1 parent 6887e39 commit 05a9631
Show file tree
Hide file tree
Showing 129 changed files with 156,669 additions and 138,206 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
run-build:
runs-on: ubuntu-latest
container:
image: nwdepatie/ner-gcc-arm:latest
image: ghcr.io/northeastern-electric-racing/embedded-base:main
timeout-minutes: 10
steps:
- name: Checkout code
Expand All @@ -17,4 +17,4 @@ jobs:
if ! make; then
echo "The application has failed to build."
exit 1 # This will cause the workflow to fail
fi
fi
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,7 @@ types_c.taghl
ctrlp.root

#html
*.html
*.html

#OS specific
.DS_Store
50 changes: 25 additions & 25 deletions .mxproject

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions Core/Inc/analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,37 @@
#include "datastructs.h"
#include "segment.h"

// this is a simple empirical mapping of which therms are returning good data
// Only in use because we can not seem to correclty map incoming therms - this allows us to forcibley select those that we visually noticed were good
extern uint8_t THERM_DISABLE[NUM_CHIPS][NUM_THERMS_PER_CHIP];

extern const uint8_t NO_THERM;
extern const uint8_t MUX_OFFSET;

/**
* @brief Mapping the Relevant Thermistors for each cell based on cell #
* @note 0xFF indicates the end of the relevant therms
* @note Low side
*/
extern const uint8_t RELEVANT_THERM_MAP_L[NUM_CELLS_PER_CHIP][NUM_RELEVANT_THERMS];

/**
* @brief Mapping the Relevant Thermistors for each cell based on cell #
* @note 0xFF indicates the end of the relevant therms
* @note High side
*/
extern const uint8_t RELEVANT_THERM_MAP_H[NUM_CELLS_PER_CHIP][NUM_RELEVANT_THERMS];

/*
* List of therms that we actually read from, NOT reordered by cell
*/
extern const uint8_t POPULATED_THERM_LIST_L[NUM_THERMS_PER_CHIP];

/*
* List of therms that we actually read from, NOT reordered by cell
*/
extern const uint8_t POPULATED_THERM_LIST_H[NUM_THERMS_PER_CHIP];

/* We want to make sure we aren't doing useless analysis on the same set of data since we are
* backfilling segment data */
#define ANALYSIS_INTERVAL VOLTAGE_WAIT_TIME
Expand Down
33 changes: 18 additions & 15 deletions Core/Inc/bmsConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
#define BMS_CONFIG_H

// Hardware definition
#define NUM_SEGMENTS 4
#define NUM_CHIPS NUM_SEGMENTS*2
#define NUM_CELLS_PER_CHIP 9
#define NUM_SEGMENTS 6
#define NUM_CHIPS NUM_SEGMENTS* 2
#define NUM_CELLS_PER_CHIP 10
#define NUM_THERMS_PER_CHIP 32
#define NUM_RELEVANT_THERMS 5
#define NUM_RELEVANT_THERMS 3

// Firmware limits
#define MAX_TEMP 65 //degrees C
#define MIN_TEMP -15 // deg C
#define MIN_TEMP -25 // deg C
#define MAX_VOLT_MEAS 65535
#define MIN_VOLT_MEAS 0

Expand All @@ -26,12 +26,15 @@
#define MAX_DELTA_V 0.015
#define BAL_MIN_V 4.00
#define MAX_CELL_TEMP 55
#define MAX_CELL_CURR 700 // Amps per BMS cell
#define MIN_CELL_TEMP 15
#define MAX_CELL_CURR 500 // Amps per BMS cell
#define MAX_CELL_TEMP_BAL 45
#define MAX_CHG_CELL_CURR 20
#define MAX_CHG_CELL_CURR 20

// Algorithm settings
#define CHARGE_TIMEOUT 300000 // 5 minutes, may need adjustment
#define CHARGE_SETL_TIMEOUT 60000 // 1 minute, may need adjustment
#define CHARGE_SETL_TIMEUP 300000 // 5 minutes, may need adjustment
#define CHARGE_VOLT_TIMEOUT 300000 // 5 minutes, may need adjustment
#define VOLT_SAG_MARGIN 0.45 // Volts above the minimum cell voltage we would like to aim for
#define OCV_CURR_THRESH 1.5

Expand All @@ -40,18 +43,18 @@
#define MAX_STANDARD_DEV 3 // only used for standard deviation for therms calc

//Fault times
#define OVER_CURR_TIME 1500 //todo adjust these based on testing and/or counter values
#define OVER_CURR_TIME 5000 //todo adjust these based on testing and/or counter values
#define PRE_OVER_CURR_TIME 1000
#define OVER_CHG_CURR_TIME 1000
#define UNDER_VOLT_TIME 15000
#define UNDER_VOLT_TIME 45000
#define PRE_UNDER_VOLT_TIME 12000
#define OVER_VOLT_TIME 15000
#define LOW_CELL_TIME 15000
#define OVER_VOLT_TIME 45000
#define LOW_CELL_TIME 45000
#define HIGH_TEMP_TIME 60000
#define CURR_ERR_MARG 50 // in A * 10
#define CURR_ERR_MARG 1.1 // scaling factor, ie 1.1 = 10% error

#define DCDC_CURRENT_DRAW 2 // in A, this is generous
#define DCDC_CURRENT_DRAW 0 // in A, was used because our DCDC was drawing current

#define CAN_MESSAGE_WAIT 10
#define CAN_MESSAGE_WAIT 5

#endif
7 changes: 4 additions & 3 deletions Core/Inc/can_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "can.h"
#include "stm32f4xx_hal.h"
#include <stdint.h>
#include "ringbuffer.h"


#define NUM_INBOUND_CAN1_IDS 1
Expand All @@ -15,14 +16,14 @@ extern CAN_HandleTypeDef hcan2;
extern ringbuffer_t* can1_rx_queue;
extern ringbuffer_t* can2_rx_queue;

static const uint16_t can1_id_list[NUM_INBOUND_CAN1_IDS] = {
static const uint32_t can1_id_list[NUM_INBOUND_CAN1_IDS] = {
//CANID_X,
0x0000
};

static const uint16_t can2_id_list[NUM_INBOUND_CAN2_IDS] = {
static const uint32_t can2_id_list[NUM_INBOUND_CAN2_IDS] = {
//CANID_X,
0x0000
0x18FF50E5
};


Expand Down
42 changes: 33 additions & 9 deletions Core/Inc/compute.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,24 @@
#define CHARGE_DETECT 5
#define CHARGER_BAUD 250000U
#define MC_BAUD 1000000U
#define MAX_ADC_RESOLUTION 1023 // 13 bit ADC
#define MAX_ADC_RESOLUTION 4095 // 12 bit ADC



typedef enum {
FAN1,
FAN2,
FAN3,
FAN4,
FAN5,
FAN6,
FANMAX
} fan_select_t;

/**
* @brief inits the compute interface
*/
void compute_init();
uint8_t compute_init();

/**
* @brief sets safeguard bool to check whether charging is enabled or disabled
Expand All @@ -35,7 +47,7 @@ void compute_enable_charging(bool enable_charging);
*
* @return Returns a fault if we are not able to communicate with charger
*/
int compute_send_charging_message(uint16_t voltage_to_set, acc_data_t* bms_data);
int compute_send_charging_message(uint16_t voltage_to_set, uint16_t current_to_set, acc_data_t* bms_data);

/**
* @brief Returns if charger interlock is engaged, indicating charger LV connector is plugged in
Expand All @@ -56,10 +68,13 @@ bool compute_charger_connected();

/**
* @brief Sets the desired fan speed
*
* @param new_fan_speed
*
* @param new_fan_speed
* @param fan_select
*
* @return uint8_t 0 = success, 1 = fan_select is out of range, 2 = PWM channel not able to be configured
*/
void compute_set_fan_speed(uint8_t new_fan_speed);
uint8_t compute_set_fan_speed(TIM_HandleTypeDef* pwmhandle, fan_select_t fan_select, uint8_t duty_cycle);

/**
* @brief Returns the pack current sensor reading
Expand All @@ -68,13 +83,19 @@ void compute_set_fan_speed(uint8_t new_fan_speed);
*/
int16_t compute_get_pack_current();

/**
* @brief sends max discharge current to Motor Controller
*
* @param bmsdata
*/
void compute_send_mc_discharge_message(acc_data_t* bmsdata);

/**
* @brief sends max charge/discharge current to Motor Controller
*
* @param max_charge
* @param max_discharge
* @param bmsdata
*/
void compute_send_mc_message(uint16_t max_charge, uint16_t max_discharge);
void compute_send_mc_charge_message(acc_data_t* bmsdata);

/**
* @brief updates fault relay
Expand Down Expand Up @@ -168,4 +189,7 @@ void compute_send_cell_temp_message(acc_data_t* bmsdata);
*/
void compute_send_segment_temp_message(acc_data_t* bmsdata);

void compute_send_fault_message(uint8_t status, int16_t curr, int16_t in_dcl);
void compute_send_voltage_noise_message(acc_data_t* bmsdata);

#endif // COMPUTE_H
10 changes: 6 additions & 4 deletions Core/Inc/datastructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
typedef struct {
/* These are retrieved from the initial LTC comms */
uint16_t voltage_reading[NUM_CELLS_PER_CHIP]; /* store voltage readings from each chip */
uint16_t voltage[NUM_CELLS_PER_CHIP]; /* store voltage readings from each chip */
int8_t thermistor_reading[NUM_THERMS_PER_CHIP]; /* store all therm readings from each chip */
int8_t thermistor_value[NUM_THERMS_PER_CHIP];
int error_reading;
Expand All @@ -22,7 +22,8 @@ typedef struct {
float cell_resistance[NUM_CELLS_PER_CHIP];
uint16_t open_cell_voltage[NUM_CELLS_PER_CHIP];

uint8_t bad_volt_diff_count[NUM_CELLS_PER_CHIP];
uint8_t noise_reading[NUM_CELLS_PER_CHIP]; /* bool representing noise ignored read */
uint8_t consecutive_noise[NUM_CELLS_PER_CHIP]; /* count representing consecutive noisy reads */
} chipdata_t;

/**
Expand All @@ -36,8 +37,8 @@ typedef enum {

/* Orion BMS faults */
CELLS_NOT_BALANCING = 0x1,
CELL_VOLTAGE_TOO_HIGH = 0x2,
CELL_VOLTAGE_TOO_LOW = 0x4,
CELL_VOLTAGE_TOO_HIGH = 0x4,
CELL_VOLTAGE_TOO_LOW = 0x2,
PACK_TOO_HOT = 0x8,
OPEN_WIRING_FAULT = 0x10, /* cell tap wire is either weakly connected or not connected */
INTERNAL_SOFTWARE_FAULT = 0x20, /* general software fault */
Expand Down Expand Up @@ -92,6 +93,7 @@ typedef struct {
uint8_t soc;

int8_t segment_average_temps[NUM_SEGMENTS];
uint8_t segment_noise_percentage[NUM_SEGMENTS];

/**
* @brief Note that this is a 32 bit integer, so there are 32 max possible fault codes
Expand Down
7 changes: 2 additions & 5 deletions Core/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ extern "C" {

/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */

/* USER CODE END EC */

/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */

/* USER CODE END EM */

void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);

/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);

Expand All @@ -61,8 +62,6 @@ void Error_Handler(void);
#define FPGA_Reset_GPIO_Port GPIOC
#define Communication_GPIO_Pin GPIO_PIN_14
#define Communication_GPIO_GPIO_Port GPIOC
#define Communication_GPIOC15_Pin GPIO_PIN_15
#define Communication_GPIOC15_GPIO_Port GPIOC
#define Communication_GPIOC0_Pin GPIO_PIN_0
#define Communication_GPIOC0_GPIO_Port GPIOC
#define SPI_2_CS_Pin GPIO_PIN_1
Expand All @@ -79,8 +78,6 @@ void Error_Handler(void);
#define I_Sense_GPIO_Port GPIOC
#define I_SenseB0_Pin GPIO_PIN_0
#define I_SenseB0_GPIO_Port GPIOB
#define I_SenseB1_Pin GPIO_PIN_1
#define I_SenseB1_GPIO_Port GPIOB
#define I_SenseB2_Pin GPIO_PIN_2
#define I_SenseB2_GPIO_Port GPIOB
#define Debug_LEDB11_Pin GPIO_PIN_11
Expand Down
9 changes: 9 additions & 0 deletions Core/Inc/stateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,13 @@ void sm_handle_state(acc_data_t *bmsdata);
void sm_balance_cells(acc_data_t *bms_data);
void sm_broadcast_current_limit(acc_data_t *bmsdata);

/**
* @brief algorithm to calculate and set fan speed based on temperature
*
* @param bmsdata
*
*/
void calculate_pwm(acc_data_t *bmsdata);


#endif //BMS_STATES_H
6 changes: 3 additions & 3 deletions Core/Inc/stm32f4xx_hal_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#define HAL_MODULE_ENABLED

/* #define HAL_CRYP_MODULE_ENABLED */
/* #define HAL_ADC_MODULE_ENABLED */
#define HAL_ADC_MODULE_ENABLED
#define HAL_CAN_MODULE_ENABLED
/* #define HAL_CRC_MODULE_ENABLED */
/* #define HAL_CAN_LEGACY_MODULE_ENABLED */
Expand All @@ -55,15 +55,15 @@
/* #define HAL_HASH_MODULE_ENABLED */
#define HAL_I2C_MODULE_ENABLED
/* #define HAL_I2S_MODULE_ENABLED */
/* #define HAL_IWDG_MODULE_ENABLED */
#define HAL_IWDG_MODULE_ENABLED
/* #define HAL_LTDC_MODULE_ENABLED */
/* #define HAL_RNG_MODULE_ENABLED */
/* #define HAL_RTC_MODULE_ENABLED */
/* #define HAL_SAI_MODULE_ENABLED */
/* #define HAL_SD_MODULE_ENABLED */
/* #define HAL_MMC_MODULE_ENABLED */
#define HAL_SPI_MODULE_ENABLED
/* #define HAL_TIM_MODULE_ENABLED */
#define HAL_TIM_MODULE_ENABLED
#define HAL_UART_MODULE_ENABLED
/* #define HAL_USART_MODULE_ENABLED */
/* #define HAL_IRDA_MODULE_ENABLED */
Expand Down
3 changes: 3 additions & 0 deletions Core/Inc/stm32f4xx_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void DMA2_Stream0_IRQHandler(void);
void CAN2_RX0_IRQHandler(void);
void CAN2_RX1_IRQHandler(void);
/* USER CODE BEGIN EFP */

/* USER CODE END EFP */
Expand Down
Loading

0 comments on commit 05a9631

Please sign in to comment.