Skip to content
Open
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
0120745
initialize new max114x adc
songyueli Dec 13, 2025
9f35d8e
added channel mapping and corrected value bit manipulation
songyueli Jan 13, 2026
59617d1
Updated MAX114X Interface
wschotte Jan 15, 2026
e672030
Finished first version of updated MAX114X interface
wschotte Jan 15, 2026
e18f7cc
Fixed build issues in MAX114X Interface constructor and added comments
KevinLuo423 Jan 15, 2026
4b81d72
fixed header guards
wschotte Jan 15, 2026
a52518d
Co-authored-by: William Schotte <wschotte@users.noreply.github.com>
KevinLuo423 Jan 15, 2026
9339c46
Make MAX114X version a template variable to create a static assertion…
KevinLuo423 Jan 15, 2026
141614c
Fixing naming bug
KevinLuo423 Jan 15, 2026
6057b5c
Added and removed some comments
KevinLuo423 Jan 15, 2026
f2858e8
Merge resolution: Merge remote-tracking branch 'origin/main' into fea…
KevinLuo423 Jan 15, 2026
0ae0cd1
added additional comments
wschotte Jan 16, 2026
f8b6fd0
improved some comments
wschotte Jan 16, 2026
462c235
Improved print statements and verified code worked on ADC
wschotte Jan 17, 2026
25b2fa6
Shifted print statements from Interface to InterfaceTasks
akemiyu Jan 18, 2026
8af3f9f
modified debug print
wschotte Jan 18, 2026
ffef987
reformatted debug print for MAX114X
wschotte Jan 18, 2026
10ab9c2
fixed data getters (debug print on still)
wschotte Jan 18, 2026
bea950b
added only sampling two channels per call and scaling (something is w…
wschotte Jan 18, 2026
bf98300
removed loops
wschotte Jan 19, 2026
6ca600f
maybe fixed something but broke serial monitor
wschotte Jan 19, 2026
f239ebb
Fixing the differential problem
KevinLuo423 Jan 19, 2026
2f983b3
Structural changes
songyueli Jan 20, 2026
84201b4
Cleaned up all the code and fixed all the printing
KevinLuo423 Jan 20, 2026
ff8de65
fin touches
KevinLuo423 Jan 20, 2026
8c0bc82
Added rest of scales & offsets
akemiyu Jan 22, 2026
4b41d6d
Merge branch 'main' of https://github.com/hytech-racing/ACU into feat…
KevinLuo423 Jan 28, 2026
c618050
Merge branch 'main' of https://github.com/hytech-racing/ACU into feat…
KevinLuo423 Jan 28, 2026
43df491
Merge branch 'feat/max1148-adc-interface' of https://github.com/hytec…
KevinLuo423 Jan 28, 2026
54ab30f
brainrot
KevinLuo423 Jan 28, 2026
dca8e82
Made MAX114XInterface fully contained in ADCInterface
KevinLuo423 Jan 28, 2026
6c50195
Fixed the fat error it works now thank goodness I can go home
KevinLuo423 Jan 29, 2026
49163af
Fixing ADC unit testing (not done)
KevinLuo423 Feb 2, 2026
9b47092
Fixed dependency issues
akemiyu Feb 2, 2026
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
12 changes: 5 additions & 7 deletions include/ACU_Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ namespace ACUInterfaces {
constexpr int ADC0_CLK = 13;
constexpr int ADC0_SPEED = 2000000; // 1 MHz
/* ADC Versions*/
constexpr int MAX114X_VERSION = 8;
/* Channels on ADC */
constexpr int ISO_PACK_N_CHANNEL = 0;
constexpr int ISO_PACK_P_CHANNEL = 1;
Expand All @@ -49,14 +48,14 @@ namespace ACUInterfaces {
constexpr int PACK_OUT_FILTERED_CHANNEL = 7;

/* SCALE/OFFSETS on ADC */
const float ISO_PACK_N_SCALE = 1;
const float ISO_PACK_P_SCALE = 1;
const float PACK_VOLTAGE_SENSE_SCALE = 1;
const float ISO_PACK_N_SCALE = 0.0656553030302;
const float ISO_PACK_P_SCALE = 0.0656553030302;
const float PACK_VOLTAGE_SENSE_SCALE = 0.0410345643939;
const float SHUNT_CURRENT_OUT_SCALE = 0.03125;
const float SHUNT_CURRENT_P_SCALE = 0.00025;
const float SHUNT_CURRENT_N_SCALE = 0.00025;
const float TS_OUT_FILTERED_SCALE = 1;
const float PACK_OUT_FILTERED_SCALE = 1;
const float TS_OUT_FILTERED_SCALE = 0.0547254764211;
const float PACK_OUT_FILTERED_SCALE = 0.0547254764211;
const float ISO_PACK_N_OFFSET = 0;
const float ISO_PACK_P_OFFSET = 0;
const float PACK_VOLTAGE_SENSE_OFFSET = 0;
Expand Down Expand Up @@ -93,7 +92,6 @@ namespace ACUConstants
constexpr size_t NUM_CHIPS = 12;
constexpr size_t NUM_CELL_TEMPS = 48;
constexpr size_t NUM_CHIP_SELECTS = 2;
constexpr size_t NUM_MAX1148_CHANNELS = 8;

const float VALID_SHDN_OUT_MIN_VOLTAGE_THRESHOLD = 12.0F;
const uint32_t MIN_ALLOWED_INVALID_SHDN_OUT_MS = 10; // 10 ms -- requies 100 Hz samp freq.
Expand Down
2 changes: 1 addition & 1 deletion include/ACU_InterfaceTasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
using chip_type = LTC6811_Type_e;
using BMSDriverInstance_t = BMSDriverInstance<ACUConstants::NUM_CHIPS, ACUConstants::NUM_CHIP_SELECTS, chip_type::LTC6811_1>;
using BMSFaultDataManagerInstance_t = BMSFaultDataManagerInstance<ACUConstants::NUM_CHIPS>;
using MAX1148ADCInstance_t = MAX114XInterfaceInstance<ACUConstants::NUM_MAX1148_CHANNELS, ACUInterfaces::MAX114X_VERSION>;
// using MAX1148ADCInstance_t = MAX114XInterfaceInstance<ACUConstants::NUM_MAX1148_CHANNELS, ACUInterfaces::MAX114X_VERSION>;
/**
* Init Functions - to be called in setup@
*/
Expand Down
140 changes: 136 additions & 4 deletions lib/interfaces/include/ADCInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <Arduino.h>
#include "SharedFirmwareTypes.h"
#include "etl/singleton.h"
#include "MAX114XInterface.h"

using pin = size_t;

Expand All @@ -15,16 +16,27 @@ namespace adc_default_parameters

constexpr const uint32_t IMD_STARTUP_TIME = 2000;
constexpr const float TEENSY41_MAX_INPUT_VOLTAGE = 3.3F;
}

constexpr int MAX114X_VERSION = 8;
constexpr size_t NUM_MAX1148_CHANNELS = 8;
};

struct ADCPinout_s
{
pin teensy_imd_ok_pin;
pin teensy_imd_ok_pin;
pin teensy_precharge_pin;
pin teensy_shdn_out_pin;
pin teensy_ts_out_filtered_pin;
pin teensy_pack_out_filtered_pin;
pin teensy_bspd_current_pin;
pin teensy_scaled_24V_pin;

// MAX114X
pin spiPinCS;
pin spiPinSDI;
pin spiPinSDO;
pin spiPinCLK;

};

struct ADCConversions_s
Expand All @@ -48,6 +60,51 @@ struct ADCConfigs_s
{
uint32_t imd_startup_time;
float teensy41_max_input_voltage;
int spiSpeed;
};

struct ADCChannels_s
{
int iso_pack_n_channel;
int iso_pack_p_channel;
int pack_voltage_sense_channel;
int shunt_current_out_channel;
int shunt_current_p_channel;
int shunt_current_n_channel;
int ts_out_filtered_channel;
int pack_out_filtered_channel;
};

struct ADCScales_s
{
float iso_pack_n_scale;
float iso_pack_p_scale;
float pack_voltage_sense_scale;
float shunt_current_out_scale;
float shunt_current_p_scale;
float shunt_current_n_scale;
float ts_out_filtered_scale;
float pack_out_filtered_scale;
};

struct ADCOffsets_s
{
float iso_pack_n_offset;
float iso_pack_p_offset;
float pack_voltage_sense_offset;
float shunt_current_out_offset;
float shunt_current_p_offset;
float shunt_current_n_offset;
float ts_out_filtered_offset;
float pack_out_filtered_offset;
};

struct MAX114XChannels_s
{
CHANNEL_TYPE_e channelPair0;
CHANNEL_TYPE_e channelPair1;
CHANNEL_TYPE_e channelPair2;
CHANNEL_TYPE_e channelPair3;
};

struct ADCInterfaceParams_s
Expand All @@ -56,6 +113,11 @@ struct ADCInterfaceParams_s
ADCConversions_s conversions;
ADCThresholds_s thresholds;
ADCConfigs_s configs;
ADCChannels_s channels;
ADCScales_s scales;
ADCOffsets_s offsets;
MAX114XChannels_s pairs;
int spiSpeed;
float bit_resolution;
};

Expand All @@ -64,6 +126,11 @@ class ADCInterface
public:
ADCInterface(ADCPinout_s pinout,
ADCConversions_s conversions,
ADCChannels_s channels,
ADCScales_s scales,
ADCOffsets_s offsets,
MAX114XChannels_s pairs,
int spiSpeed,
float bit_resolution,
ADCThresholds_s thresholds = {
.teensy41_min_digital_read_voltage_thresh = adc_default_parameters::TEENSY41_MIN_DIGITAL_READ_VOLTAGE_THRESH,
Expand All @@ -87,14 +154,58 @@ class ADCInterface
}(),
thresholds,
configs,
bit_resolution} {}
channels,
scales,
offsets,
pairs,
spiSpeed,
bit_resolution},
_max114x_instance(
_adc_parameters.pinout.spiPinCS,
_adc_parameters.pinout.spiPinSDI,
_adc_parameters.pinout.spiPinSDO,
_adc_parameters.pinout.spiPinCLK,
_adc_parameters.spiSpeed,
std::array<float, adc_default_parameters::NUM_MAX1148_CHANNELS> {
_adc_parameters.scales.iso_pack_n_scale,
_adc_parameters.scales.iso_pack_p_scale,
_adc_parameters.scales.pack_voltage_sense_scale,
_adc_parameters.scales.shunt_current_out_scale,
_adc_parameters.scales.shunt_current_p_scale,
_adc_parameters.scales.shunt_current_n_scale,
_adc_parameters.scales.ts_out_filtered_scale,
_adc_parameters.scales.pack_out_filtered_scale,
}.data(),
std::array<float, adc_default_parameters::NUM_MAX1148_CHANNELS> {
_adc_parameters.offsets.iso_pack_n_offset,
_adc_parameters.offsets.iso_pack_p_offset,
_adc_parameters.offsets.pack_voltage_sense_offset,
_adc_parameters.offsets.shunt_current_out_offset,
_adc_parameters.offsets.shunt_current_p_offset,
_adc_parameters.offsets.shunt_current_n_offset,
_adc_parameters.offsets.ts_out_filtered_offset,
_adc_parameters.offsets.pack_out_filtered_offset,
}.data(),
std::array<CHANNEL_TYPE_e, adc_default_parameters::NUM_MAX1148_CHANNELS / 2> {
_adc_parameters.pairs.channelPair0,
_adc_parameters.pairs.channelPair1,
_adc_parameters.pairs.channelPair2,
_adc_parameters.pairs.channelPair3
}
)
{}

/**
* @pre constructor called and instance created
* @post Pins on Teensy configured and written as IN/OUT
*/
void init(uint32_t init_millis);

/**
* Samples from MAX114X adc
*/
void tick();

/**
* @return the state of the IMD, HIGH = NO FAULT
*/
Expand Down Expand Up @@ -144,7 +255,27 @@ class ADCInterface
* @return shdn out voltage
*/
volt read_shdn_out_voltage();


/**
* @return ISO Pack Differential
*/
float read_iso_pack();

/**
* @return pack voltage sense
*/
float read_pack_voltage_sense();

/**
* @return shunt current single channel
*/
float read_shunt_current();

/**
* @return shunt current differential channels
*/
float read_differential_shunt_current();

/**
* @return ADC parameters
*/
Expand All @@ -157,6 +288,7 @@ class ADCInterface

private:
const ADCInterfaceParams_s _adc_parameters = {};
MAX114XInterface<adc_default_parameters::NUM_MAX1148_CHANNELS, adc_default_parameters::MAX114X_VERSION> _max114x_instance;

/**
* @brief true while within the IMD startup window (set in init())
Expand Down
1 change: 0 additions & 1 deletion lib/interfaces/include/MAX114XInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define MAX114XINTERFACE_H

#include "AnalogSensorsInterface.h"

#include <SPI.h>

/**
Expand Down
21 changes: 20 additions & 1 deletion lib/interfaces/src/ADCInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ void ADCInterface::init(uint32_t init_millis) {
_in_imd_startup_period = true;
}

void ADCInterface::tick() {
_max114x_instance.tick();
}

bool ADCInterface::read_imd_ok(uint32_t curr_millis) {
if (_in_imd_startup_period) {
if ((curr_millis - _init_millis) >= _adc_parameters.configs.imd_startup_time) { // give 2 seconds for IMD to startup
_in_imd_startup_period = false;
}
return true;
}
//
return static_cast<float>(analogRead(_adc_parameters.pinout.teensy_imd_ok_pin)) * (_adc_parameters.configs.teensy41_max_input_voltage / _adc_parameters.bit_resolution) > _adc_parameters.thresholds.teensy41_min_digital_read_voltage_thresh; // idk if this would actually work, like if a LOW is a threshold or smth
}

Expand Down Expand Up @@ -74,6 +77,22 @@ volt ADCInterface::read_global_lv_value() {
return data;
}

float ADCInterface::read_iso_pack() {
return _max114x_instance.getLastSampleConverted(_adc_parameters.channels.iso_pack_n_channel);
}

float ADCInterface::read_pack_voltage_sense() {
return _max114x_instance.getLastSampleConverted(_adc_parameters.channels.pack_voltage_sense_channel);
}

float ADCInterface::read_shunt_current() {
return _max114x_instance.getLastSampleConverted(_adc_parameters.channels.shunt_current_out_channel);
}

float ADCInterface::read_differential_shunt_current() {
return _max114x_instance.getLastSampleConverted(_adc_parameters.channels.shunt_current_p_channel);
}

const ADCInterfaceParams_s& ADCInterface::get_adc_params() const {
return _adc_parameters;
}
Expand Down
5 changes: 3 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ lib_deps =
blemasle/MCP23017@^2.0.0
https://github.com/FabioBatSilva/ArduinoFake.git
https://github.com/eranpeer/FakeIt.git

https://github.com/hytech-racing/shared_firmware_interfaces.git#5baf17a0f6d83d0a9d571d6bf56f409d2c8ad98a

[env:teensy41]
test_framework=googletest
; including only the current main file for compiling to keep old main still around for now while
Expand Down Expand Up @@ -97,7 +98,7 @@ build_src_filter =
-<main_can_test.cpp>
+<main_spi_test.cpp>
+<ACU_Constants.cpp>

build_unflags = -std=gnu++11
build_flags =
-std=c++17
Expand Down
Loading
Loading