Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADBMS Integration #138

Merged
merged 34 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
60650d1
133 adbms submodule
Sabramz Nov 18, 2024
89b9d97
133 more copying
Sabramz Nov 18, 2024
004e83d
133 it works
Sabramz Nov 18, 2024
fe7b35e
133 debugging
Sabramz Nov 18, 2024
331f9dd
133 working prints
Sabramz Nov 18, 2024
a7bff61
adbms functions for config registers, get rid of some LTC code, start…
Sabramz Nov 21, 2024
ccff5e0
adbms reworking code for daisy chaining
Sabramz Nov 27, 2024
d1b4701
adbms wrapper written **untested**
Sabramz Dec 8, 2024
c671679
adbms cleaning up old functions
Sabramz Dec 8, 2024
f0a2a60
adbms balancing config changes
Sabramz Dec 14, 2024
e611107
adbms add chips to acc_data_t and make functions compatible with new …
Sabramz Dec 25, 2024
6791c57
adbms changing GPIO modes and integrating balancing functions with adbms
Sabramz Dec 26, 2024
93379f0
adbms cleaning up balancing and removing LTC driver from make file
Sabramz Dec 26, 2024
5a42a6b
adbms more cleanup of 22A code and starting on analyzer for alpha and…
Sabramz Jan 1, 2025
61e424e
adbms therms cleanup and changes for alpha and beta stacks
Sabramz Jan 6, 2025
540f19b
adbms functions for configuring chips
Sabramz Jan 6, 2025
591fe50
forgot to build
Sabramz Jan 6, 2025
a0e9240
adbms debugging volts and therms
Sabramz Jan 11, 2025
8a7b085
adbms therms mapping and temperature calculation, cleanup legacy code
Sabramz Jan 14, 2025
a3d12bc
adbms cleanup, add TODOs for future work
Sabramz Jan 14, 2025
5becce5
adbms cleanup, add TODOs for future work
Sabramz Jan 14, 2025
74ae15d
Set up task and send function for debug mode per cell data
Sabramz Jan 14, 2025
a44b476
debug mode create task and CAN message functions
Sabramz Jan 17, 2025
6e34ff5
adbms S vs C ADC comparison and PEC error count
Sabramz Jan 18, 2025
eda79ab
Merge branch 'per-cell-CAN' into 133-adbms-integration
Sabramz Jan 18, 2025
0c881b1
adbms debug mode stuff
Sabramz Jan 18, 2025
6f56377
adbms change debug mode CAN messages to use bit fields
Sabramz Jan 20, 2025
3dafe3b
General changes/improvements (#151)
jr1221 Jan 25, 2025
7e75f6a
Merge branch 'develop' into 133-adbms-integration
jr1221 Jan 25, 2025
b9218f2
fixups
jr1221 Jan 25, 2025
3426aaa
fmt
jr1221 Jan 25, 2025
89db8b6
segment reboot every 45 seconds
jr1221 Jan 25, 2025
a189aa7
fmt
jr1221 Jan 25, 2025
d02da4a
fmt
jr1221 Jan 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.PAT_TOKEN }}
fetch-depth: 0
- name: Execute Make
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.PAT_TOKEN }}
- name: Run clang-format style check for C/C++ sources
uses: Northeastern-Electric-Racing/clang-format-action@main
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "Drivers/Embedded-Base"]
path = Drivers/Embedded-Base
url = https://github.com/Northeastern-Electric-Racing/Embedded-Base.git
[submodule "Drivers/adbms"]
path = Drivers/adbms
url = [email protected]:Northeastern-Electric-Racing/adbms.git
9 changes: 5 additions & 4 deletions .mxproject

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Core/Inc/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
#include <stdint.h>
extern uint32_t SystemCoreClock;
void xPortSysTickHandler(void);
#endif
#ifndef CMSIS_device_header
#define CMSIS_device_header "stm32f4xx.h"
Expand Down Expand Up @@ -164,7 +163,7 @@ standard names. */

/* IMPORTANT: After 10.3.1 update, Systick_Handler comes from NVIC (if SYS timebase = systick), otherwise from cmsis_os2.c */

#define USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION 1
#define USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION 0

/* USER CODE BEGIN Defines */
/* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */
Expand Down
238 changes: 238 additions & 0 deletions Core/Inc/adi_interaction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
#include "adBms6830Data.h"
#include "bmsConfig.h"

// --- BEGIN SET HELPERS ---

/**
* @brief Set the status of the REFON bit.
*
* @param chip Pointer to the chip to modify.
* @param state New state of the REFON bit.
*/
void set_REFON(cell_asic *chip, REFON state);

/**
* @brief Set the C-ADC vs. S-ADC comparison voltage threshold
*
* @param chip Pointer to the chip to modify.
* @param threshold Threshold to set.
*/
void set_volt_adc_comp_thresh(cell_asic *chip, CTH threshold);

void set_diagnostic_flags(cell_asic *chip, FLAG_D config);

/**
* @brief Set the discharge state of a cell.
*
* @param chip Pointer to chip with cell to modify.
* @param cell ID of cell to modify. Cell indexes start are from 1-16 (NOT ZERO INDEXED).
* @param discharge Cell discharge state. true to discharge, false to disable discharge.
*/
void set_cell_discharge(cell_asic *chip, uint8_t cell, bool discharge);

/**
* @brief Set the state of the SOAKON bit to either enable or disable soak times.
*
* @param chip Pointer to chip to configure
* @param state Enable or disable SOAKON
*/
void set_soak_on(cell_asic *chip, SOAKON state);

/**
* @brief Set the soak time range.
*
* @param chip Pointer to chip to configure
* @param range The range of time over which to soak for aux and aux2
*/
void set_aux_soak_range(cell_asic *chip, OWRNG range);

/**
* @brief Set the open wire soak time. See data sheet for formula.
*
* @param chip Pointer to chip configuration
* @param time The amount of time to soak for. Higher OWA is a higher soak time.
*/
void set_open_wire_soak_time(cell_asic *chip, OWA time);

/**
* @brief Set the pull of a GPIO pin on an ADBMS8630.
*
* @param chip ADBMS6830 chip
* @param gpio Number of the GPIO pin to change (1-10)
* @param input True is no pull down, False is pull down.
*/
void set_gpio_pull(cell_asic *chip, uint8_t gpio, bool input);

/**
* @brief Set the corner frequency of the IIR filter.
*
* @param chip Pointer to chip config
* @param freq Corner frequency (see IIR_FPA enum for frequencies)
*/
void set_iir_corner_freq(cell_asic *chip, IIR_FPA freq);

/**
* @brief Configure a chip as a break in the isoSPI daisy chain.
*
* @param chip Pointer to chip config
* @param is_break True if chip is break, false if chip is not break
*/
void set_comm_break(cell_asic *chip, bool is_break);

/**
* @brief Enable/disable discharging through the mute discharge bit.
*
* @param chip Pointer to chip config
* @param disable_discharge True to disable discharge, false to enable discharge.
*/
void set_mute_state(cell_asic *chip, bool disable_discharge);

/**
* @brief Set whether or not this chip is taking a snapshot. The chip will not begin reading new values unless the snapshot bit is cleared.
*
* @param chip Pointer to chip config
* @param take_snapshot True to take a snapshot, false to end the snapshot
*/
void set_snapshot(cell_asic *chip, bool take_snapshot);

/**
* @brief Enable/disable the discharge timer monitor.
*
* @param chip Pointer to chip config
* @param enabled True if discharge timer monitor is enabled, false if otherwise
*/
void set_discharge_timer_monitor(cell_asic *chip, bool enabled);

/**
* @brief Configure the discharge timer range, which affects the resolution.
*
* @param chip Pointer to chip config
* @param large True for large range, False for small range
*/
void set_discharge_timer_range(cell_asic *chip, bool large);

/**
* @brief Set the discharge monitor timeout, which is dependent on the discharge timer range.
*
* @param chip Pointer to chip config
* @param timeout Base for timeout multiplicaiton. Must be below six bits.
*/
void set_discharge_timeout(cell_asic *chip, uint8_t timeout);

// --- END SET HELPERS ---

// --- BEGIN WRITE COMMANDS ---

/**
* @brief Soft reset all chips, then re-wake them
*
* @param chips
*/
void soft_reset_chips(cell_asic chips[NUM_CHIPS]);

/**
* @brief Write config registers. Wakes chips before writing.
*
* @param chips Array of chips to write config registers of.
*/
void write_config_regs(cell_asic chips[NUM_CHIPS]);

/**
* @brief Clears all status regster C flags except the CS FLT
*
* @param chips
*/
void write_clear_flags(cell_asic chips[NUM_CHIPS]);

// --- END WRITE COMMANDS ---

// --- BEGIN READ COMMANDS ---

/**
* @brief Read all filtered voltage results. IIR must be on and ADC must be continous
*
* @param chips The chips to read voltages from
*/
void read_filtered_voltage_registers(cell_asic chips[NUM_CHIPS]);

/**
* @brief Read every register connected to the AUX ADC.
*
* @param chips Array of chips to get voltage readings of.
*/
void adc_and_read_aux_registers(cell_asic chips[NUM_CHIPS]);

/**
* @brief Read voltages in every register connected to AUX2 ADC.
*
* @param chips Array of chips to get voltages of.
*/
void adc_and_read_aux2_registers(cell_asic chips[NUM_CHIPS]);

/**
* @brief Read status registers.
*
* @param chips Array of chips to read.
*/
void read_status_registers(cell_asic chips[NUM_CHIPS]);

/**
* @brief Read status and aux registers in one command.
*
* @param chips Array of chips to read.
*/
void read_status_aux_registers(cell_asic chips[NUM_CHIPS]);

/**
* @brief Read the serial ID of the chip.
*
* @param chips Array of chips to read.
*/
void read_serial_id(cell_asic chips[NUM_CHIPS]);

// --- END READ COMMANDS ---

// --- BEGIN ADC POLL ---

/**
* @brief Get voltage readings from the C-ADCs. Takes a single shot measurement.
*
* @param chips Array of chips to get voltage readings from.
*/
void get_c_adc_voltages(cell_asic chips[NUM_CHIPS]);

/**
* @brief Get voltages from the S-ADCs. Makes a single shot measurement.
*
* @param chip Array of chips to get voltage readings from.
*/
void get_s_adc_voltages(cell_asic chips[NUM_CHIPS]);

/**
* @brief Get the avgeraged cell voltages.
*
* @param chip Array of chips to get voltage readings of.
*/
void get_avgd_cell_voltages(cell_asic chips[NUM_CHIPS]);

/**
* @brief Get the filtered cell volrages.
*
* @param chip Array of chips to get voltage readings of.
*/
void get_filtered_cell_voltages(cell_asic chips[NUM_CHIPS]);

/**
* @brief Get the c and s adc voltages. Does this with RDCSALL command.
*
* @param chips Array of chips to get voltage readings of.
*/
void get_c_and_s_adc_voltages(cell_asic chips[NUM_CHIPS]);

/**
* @brief Starts a continous c ADC conversion with S redundancy
*
*/
void start_c_adc_conv();

// --- END ADC POLL ---
25 changes: 8 additions & 17 deletions Core/Inc/analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,6 @@ 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
*/
Expand All @@ -44,6 +27,14 @@ extern const uint8_t POPULATED_THERM_LIST_H[NUM_THERMS_PER_CHIP];

//#define MAX_SIZE_OF_HIST_QUEUE 300000U //bytes

/**
* @brief Get the number of cells on a chip.
*
* @param chip_data Pointer to struct containing chip data.
* @return uint8_t The number of cells in the chip.
*/
uint8_t get_num_cells(chipdata_t *chip_data);

/**
* @brief Calculate thermistor values and cell temps using thermistors.
*
Expand Down
17 changes: 12 additions & 5 deletions Core/Inc/bmsConfig.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
#ifndef BMS_CONFIG_H
#define BMS_CONFIG_H

#define DEBUG_MODE_ENABLED true
#define DEBUG_STATS

// Hardware definition
#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 3
#define NUM_SEGMENTS 1
#define NUM_CHIPS 1 //NUM_SEGMENTS * 2
#define NUM_CELLS_ALPHA 14
#define NUM_CELLS_BETA 11
#define NUM_CELLS_SEG NUM_CELLS_ALPHA + NUM_CELLS_BETA
#define NUM_CELLS \
((NUM_CELLS_ALPHA * (NUM_CHIPS / 2.0)) + \
(NUM_CELLS_BETA * (NUM_CHIPS / 2.0)))
#define NUM_THERMS_PER_CHIP 14

// Firmware limits
#define MAX_TEMP 65 //degrees C
Expand Down
41 changes: 38 additions & 3 deletions Core/Inc/can_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,44 @@
#define NOISE_CANID 0x88
#define NOISE_SIZE 6
#define DEBUG_CANID 0x702
#define DEBUG_SIZE 8
#define FAULT_TIMER_CANID 0x6FF
#define FAULT_TIMER_SIZE 4

#define ALPHA_CELL_CANID 0x6FA
#define BETA_CELL_CANID 0x6FB
#define CELL_MSG_SIZE 7
#define BETA_STAT_A_CANID 0x6FD
#define BETA_STAT_A_SIZE 8
#define BETA_STAT_B_CANID 0x6FE
#define BETA_STAT_B_SIZE 8
#define ALPHA_STAT_A_CANID 0x6FC
#define ALPHA_STAT_A_SIZE 7
#define ALPHA_STAT_B_CANID 0x6FF
#define ALPHA_STAT_B_SIZE 7

typedef struct {
uint32_t prev_tick;
uint32_t msg_rate; /* in milliseconds */
} rl_data_t;

typedef enum {
CHARGE,
DISCHARGE,
ACC_STATUS,
BMS_STATUS,
SHUTDOWN_CTRL,
CELL_DATA,
CELL_VOLTAGE,
CURRENT,
CELL_TEMP,
SEGMENT_TEMP,
FAULT,
NOISE,
DEBUG,
RL_MSG_COUNT
} rate_lim_t;

#define DEBUG_SIZE 8
#define FAULT_TIMER_CANID 0x6FF
#define FAULT_TIMER_SIZE 4

void can_receive_callback(CAN_HandleTypeDef *hcan);

Expand Down
Loading
Loading