From 8afdd5d913368d5f6fc74b4787cb20801fd02392 Mon Sep 17 00:00:00 2001 From: Shuyang Fei Date: Tue, 10 Feb 2026 19:47:31 -0600 Subject: [PATCH 1/3] ADC code in Voltage, Continuity deleted --- MIDAS/lib/ADS7138Q1/ads7138-q1.cpp | 4 +- MIDAS/src/data_logging.cpp | 2 - MIDAS/src/errors.cpp | 6 -- MIDAS/src/errors.h | 1 - MIDAS/src/hardware/Continuity.cpp | 89 ------------------------ MIDAS/src/hardware/Voltage.cpp | 92 ++++++++++++++++++++----- MIDAS/src/hardware/sensors.h | 25 ------- MIDAS/src/hilsim/sensors.h | 7 -- MIDAS/src/hilsim/sensors/Continuity.cpp | 10 --- MIDAS/src/hilsim/sensors/sensors.h | 5 -- MIDAS/src/log_format.h | 3 - MIDAS/src/rocket_state.h | 2 - MIDAS/src/sensor_data.h | 11 +-- MIDAS/src/silsim/emulated_sensors.cpp | 10 +-- MIDAS/src/silsim/emulated_sensors.h | 2 +- MIDAS/src/silsim/main.cpp | 3 +- MIDAS/src/systems.cpp | 6 +- MIDAS/src/systems.h | 3 - MIDAS/src/telemetry.cpp | 13 ++-- 19 files changed, 87 insertions(+), 207 deletions(-) delete mode 100644 MIDAS/src/hardware/Continuity.cpp delete mode 100644 MIDAS/src/hilsim/sensors/Continuity.cpp diff --git a/MIDAS/lib/ADS7138Q1/ads7138-q1.cpp b/MIDAS/lib/ADS7138Q1/ads7138-q1.cpp index a0ca81df..ef1bcb3e 100644 --- a/MIDAS/lib/ADS7138Q1/ads7138-q1.cpp +++ b/MIDAS/lib/ADS7138Q1/ads7138-q1.cpp @@ -45,7 +45,7 @@ static AdcError adc_reg_write(uint8_t address, uint8_t reg_address, uint8_t data return AdcError::NoError; } -AdcReadResult adcAnalogRead(ADCAddress pin){ +AdcReadResult adcAnalogRead(ADCAddress pin){ if(pin.pin_id < 0 || pin.pin_id >= 8){ return AdcReadResult{.value=0, .error=AdcError::InvalidPinError}; } @@ -58,7 +58,7 @@ AdcReadResult adcAnalogRead(ADCAddress pin){ } int high = WIRE.read(); int low = WIRE.read(); - uint16_t value = (high << 4) + (low >> 4); + uint16_t value = (high << 8) + low; return AdcReadResult{.value=value, .error=AdcError::NoError}; } diff --git a/MIDAS/src/data_logging.cpp b/MIDAS/src/data_logging.cpp index 36ad6202..3767be72 100644 --- a/MIDAS/src/data_logging.cpp +++ b/MIDAS/src/data_logging.cpp @@ -16,7 +16,6 @@ constexpr ReadingDiscriminant get_discriminant(); ASSOCIATE(IMU, ID_IMU) ASSOCIATE(Barometer, ID_BAROMETER) -ASSOCIATE(Continuity, ID_CONTINUITY) ASSOCIATE(Voltage, ID_VOLTAGE) ASSOCIATE(GPS, ID_GPS) ASSOCIATE(Magnetometer, ID_MAGNETOMETER) @@ -87,7 +86,6 @@ void log_data(LogSink& sink, RocketData& data) { log_from_sensor_data(sink, data.imu); log_from_sensor_data(sink, data.hw_filtered); log_from_sensor_data(sink, data.barometer); - log_from_sensor_data(sink, data.continuity); log_from_sensor_data(sink, data.voltage); log_from_sensor_data(sink, data.gps); log_from_sensor_data(sink, data.magnetometer); diff --git a/MIDAS/src/errors.cpp b/MIDAS/src/errors.cpp index bf89d168..e23aedf3 100644 --- a/MIDAS/src/errors.cpp +++ b/MIDAS/src/errors.cpp @@ -88,12 +88,6 @@ void update_error_LED(ErrorCode error) { digitalWrite(LED_ORANGE, LOW); digitalWrite(LED_RED, HIGH); break; - case ContinuityCouldNotBeInitialized: - digitalWrite(LED_BLUE, LOW); - digitalWrite(LED_GREEN, LOW); - digitalWrite(LED_ORANGE, HIGH); - digitalWrite(LED_RED, HIGH); - break; case CannotConnectBNO: digitalWrite(LED_BLUE, HIGH); digitalWrite(LED_GREEN, HIGH); diff --git a/MIDAS/src/errors.h b/MIDAS/src/errors.h index 5fe08046..dac093ca 100644 --- a/MIDAS/src/errors.h +++ b/MIDAS/src/errors.h @@ -17,7 +17,6 @@ enum ErrorCode { GyroCouldNotBeInitialized = 8, PyroGPIOCouldNotBeInitialized = 9, GPSCouldNotBeInitialized = 10, - ContinuityCouldNotBeInitialized = 11, RadioInitFailed = 12, RadioSetFrequencyFailed = 13, CannotConnectBNO = 14, diff --git a/MIDAS/src/hardware/Continuity.cpp b/MIDAS/src/hardware/Continuity.cpp deleted file mode 100644 index 920a94c7..00000000 --- a/MIDAS/src/hardware/Continuity.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include "sensors.h" -#include "ads7138-q1.h" -#include -#include - -#define PYRO_VOLTAGE_DIVIDER (5.0 / (5.0 + 20.0)) //voltage divider for pyro batt voltage, check hardware schematic -#define CONT_VOLTAGE_DIVIDER (5.0 / (5.0 + 20.0)) //voltage divider for continuity voltage, check hardware schematic - -// Reads the given register from the pyro power monitor -int read_pwr_monitor_register(int reg, int bytes) { - Wire1.beginTransmission(0x41); // I2C Address 0x41 is pyro pwr monitor - Wire1.write(reg); - if(Wire1.endTransmission()){ - Serial.println("I2C Error"); - } - - Wire1.requestFrom(0x41, bytes); - int val = 0; - - for(int i = 0; i < bytes; i++){ - int v = Wire1.read(); - if(v == -1) Serial.println("I2C Read Error"); - val = (val << 8) | v; - } - - return val; -} - -/** - * @brief Initializes ADC, returns NoError - * - * @return Error code -*/ -ErrorCode ContinuitySensor::init() { - // ADS7138Init(); // Ask AĆ’DS to init the pins, we still need to get the device to actually read - // Configure the INA745b MODE:ContTCV VBUS:1052us VSEN:1052us TCT:1052us AVG:128 - constexpr uint16_t INA_config = (0xF << 12) | (0x5 << 9) | (0x5 << 6) | (0x5 << 3) | (0x4); - - Wire1.beginTransmission(0x41); - Wire1.write(0x1); - - Wire1.write(((INA_config >> 8) & 0xFF)); - Wire1.write(((INA_config >> 0) & 0xFF)); - - if(Wire1.endTransmission()){ - Serial.println("Pyro PWR I2C Error"); - return ErrorCode::ContinuityCouldNotBeInitialized; - } - - Serial.println("Pyro PWR monitor configured"); - - return ErrorCode::NoError; -} - -/** - * @brief Reads the value of the ADC - * - * @return Continuity data packet -*/ -Continuity ContinuitySensor::read() { - Continuity continuity; - //ADC reference voltage is 3.3, returns 12 bit value - - // MIDAS 2.1 rev A ADC sense fix: - int16_t current = read_pwr_monitor_register(0x7, 2); - int voltage = read_pwr_monitor_register(0x5, 2); - - float voltage_normalized = voltage * 3.125 / 1000.0; // V - - float continuous_channels = 0.0; - float absolute_current = 0.0; - float expected_current = 0.0; - - if(voltage_normalized > 1) { - absolute_current = current * 1.2 / 1000.0; - - expected_current = (voltage_normalized - 0.2) / 470.0; // Account for diode voltage drop - continuous_channels = absolute_current / expected_current; - } - - // We don't have the granularity to determine individual voltages, so all of them will give the # of continuous channels - continuity.pins[0] = continuous_channels; // Number of continuous channels on the pyro bus - continuity.pins[1] = absolute_current; // The absolute current running through the pyro bus - continuity.pins[2] = expected_current; // Calculated expected current based on current pyro bus voltage - continuity.pins[3] = voltage_normalized; // Pyro bus voltage - - // Serial.println(continuous_channels); - return continuity; -} diff --git a/MIDAS/src/hardware/Voltage.cpp b/MIDAS/src/hardware/Voltage.cpp index aa2dd4ca..d835c3e9 100644 --- a/MIDAS/src/hardware/Voltage.cpp +++ b/MIDAS/src/hardware/Voltage.cpp @@ -39,23 +39,77 @@ ErrorCode VoltageSensor::init() { * @return The scaled voltage given by the voltage sensor */ Voltage VoltageSensor::read() { - Voltage v_battery; - int voltage = read_board_pwr_monitor_register(0x5, 2); - int16_t current = read_board_pwr_monitor_register(0x7, 2); - - float voltage_normalized = voltage * 3.125 / 1000.0; - float absolute_current = current * 1.2 / 1000.0; - - // Serial.print("Voltage: "); - // Serial.println(voltage_normalized); - // Serial.print("Current: "); - // Serial.println(current); - - v_battery.voltage = voltage_normalized; - v_battery.current = absolute_current; -// Serial.print("Raw voltage reading: "); -// Serial.print(v_battery.voltage); -// Serial.println(""); - //* 3.3f / 4095.f / VOLTAGE_DIVIDER; - return v_battery; + Voltage voltage; + + //CHECK PINS + ADCAddress pinA; + ADCAddress pinB; + ADCAddress pinC; + ADCAddress pinD; + ADCAddress pinBat; + ADCAddress pinPyro; + pinA.pin_id = 0; + pinB.pin_id = 1; + pinC.pin_id = 4; + pinD.pin_id = 5; + pinBat.pin_id = 7; + pinPyro.pin_id = 2; + + //Getting ADC values + AdcReadResult sensorA = adcAnalogRead(pinA); + AdcReadResult sensorB = adcAnalogRead(pinB); + AdcReadResult sensorC = adcAnalogRead(pinC); + AdcReadResult sensorD = adcAnalogRead(pinD); + AdcReadResult sensorBat = adcAnalogRead(pinBat); + AdcReadResult sensorPyro = adcAnalogRead(pinPyro); + + //Converts ADC value to voltage for each pin + if(sensorBat.error == AdcError::NoError){ + float Bat_value = sensorBat.value; + float Bat_voltage = (((float)Bat_value / 65535) * 3.3) * 2.0; + voltage.v_Bat = Bat_voltage; + Serial.print("VBAT: "); + Serial.println(Bat_voltage); + } + + if(sensorPyro.error == AdcError::NoError){ + float Pyro_voltage = (((float)sensorPyro.value / 65535) * 3.3)/(100.0/660); //Accounting for voltage divider on MIDAS mini + voltage.v_Pyro = Pyro_voltage; + Serial.print("PYRO: "); + Serial.println(Pyro_voltage); + } + + if(sensorA.error == AdcError::NoError){ + float A_value = sensorA.value* (100000.0/118000); //accounting for the resisters + float A_voltage = (((float)A_value / 65535) * 3.3)/(18.0/100); + voltage.continuity[0] = A_voltage; + Serial.print("A: "); + Serial.println(A_voltage); + } + + if(sensorB.error == AdcError::NoError){ + uint16_t B_value = sensorB.value* (100000.0/118000); //accounting for the resisters + float B_voltage = (((float)B_value / 65535) * 3.3)/(18.0/100); + voltage.continuity[1] = B_voltage; + Serial.print("B: "); + Serial.println(B_voltage); + } + + if(sensorC.error == AdcError::NoError){ + uint16_t C_value = sensorC.value*(100000.0/118000); //accounting for the resisters + float C_voltage = (((float)C_value / 65535) * 3.3)/(18.0/100); + voltage.continuity[2] = C_voltage; + Serial.print("C: "); + Serial.println(C_voltage); + } + + if(sensorD.error == AdcError::NoError){ + uint16_t D_value = sensorD.value*(100000.0/118000); //accounting for the resisters + float D_voltage = (((float)D_value / 65535) * 3.3)/(18.0/100); + voltage.continuity[3] = D_voltage; + Serial.print("D: "); + Serial.println(D_voltage); + } + + return voltage; } diff --git a/MIDAS/src/hardware/sensors.h b/MIDAS/src/hardware/sensors.h index df968118..bc664ae3 100644 --- a/MIDAS/src/hardware/sensors.h +++ b/MIDAS/src/hardware/sensors.h @@ -32,14 +32,6 @@ struct BarometerSensor { Barometer read(); }; -/** - * @struct Continuity interface - */ -struct ContinuitySensor { - ErrorCode init(); - Continuity read(); -}; - /** * @struct Voltage interface */ @@ -48,23 +40,6 @@ struct VoltageSensor { Voltage read(); }; -// /** -// * @struct BNO interface -// */ -// struct OrientationSensor { -// Orientation initial_orientation; -// Quaternion initial_quaternion; -// uint8_t initial_flag; - -// float prev_x = 0; -// float prev_y = 0; -// float prev_z = 0; -// float prev_tilt = 0; - -// ErrorCode init(); -// Orientation read(); -// }; - /** * @struct GPS interface */ diff --git a/MIDAS/src/hilsim/sensors.h b/MIDAS/src/hilsim/sensors.h index 812f43c2..81d4ea03 100644 --- a/MIDAS/src/hilsim/sensors.h +++ b/MIDAS/src/hilsim/sensors.h @@ -44,13 +44,6 @@ struct BarometerSensor { // LowGLSM read(); // }; -/** - * @struct Continuity interface - */ -struct ContinuitySensor { - ErrorCode init(); - Continuity read(); -}; /** * @struct Voltage interface diff --git a/MIDAS/src/hilsim/sensors/Continuity.cpp b/MIDAS/src/hilsim/sensors/Continuity.cpp deleted file mode 100644 index f18d0ab4..00000000 --- a/MIDAS/src/hilsim/sensors/Continuity.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "sensors.h" -#include "../global_packet.h" - -ErrorCode ContinuitySensor::init() { - return ErrorCode::NoError; -} - -Continuity ContinuitySensor::read() { - return Continuity{}; -} diff --git a/MIDAS/src/hilsim/sensors/sensors.h b/MIDAS/src/hilsim/sensors/sensors.h index cb4bda34..78246f8c 100644 --- a/MIDAS/src/hilsim/sensors/sensors.h +++ b/MIDAS/src/hilsim/sensors/sensors.h @@ -25,11 +25,6 @@ struct BarometerSensor { Barometer read(); }; -struct ContinuitySensor { - ErrorCode init(); - Continuity read(); -}; - struct VoltageSensor { ErrorCode init(); Voltage read(); diff --git a/MIDAS/src/log_format.h b/MIDAS/src/log_format.h index a5091c8c..70e9c1af 100644 --- a/MIDAS/src/log_format.h +++ b/MIDAS/src/log_format.h @@ -10,11 +10,9 @@ enum ReadingDiscriminant { ID_IMU = 1, ID_BAROMETER = 2, - ID_CONTINUITY = 3, ID_VOLTAGE = 4, ID_GPS = 5, ID_MAGNETOMETER = 6, - ID_ORIENTATION = 7, ID_KALMAN = 8, ID_FSM = 9, ID_PYRO = 10, @@ -43,7 +41,6 @@ struct LoggedReading { IMU imu; IMU_SFLP hw_filt; Barometer barometer; - Continuity continuity; Voltage voltage; GPS gps; Magnetometer magnetometer; diff --git a/MIDAS/src/rocket_state.h b/MIDAS/src/rocket_state.h index c3a8d2b6..ee3f5ca5 100644 --- a/MIDAS/src/rocket_state.h +++ b/MIDAS/src/rocket_state.h @@ -191,12 +191,10 @@ struct RocketData { BufferedSensorData imu; SensorData hw_filtered; BufferedSensorData barometer; - SensorData continuity; SensorData pyro; SensorData fsm_state; SensorData gps; SensorData magnetometer; - //SensorData orientation; SensorData voltage; SensorData cam_data; diff --git a/MIDAS/src/sensor_data.h b/MIDAS/src/sensor_data.h index 44e6a61a..ad0b560c 100644 --- a/MIDAS/src/sensor_data.h +++ b/MIDAS/src/sensor_data.h @@ -81,22 +81,17 @@ struct Barometer { }; /** - * @struct Continuity * * @brief data about pyro continuity -*/ -struct Continuity { - float pins[4]; -}; - /** * @struct Voltage * * @brief data about battery voltage */ struct Voltage { - float voltage = 0; - float current = 0; + float continuity[4]; + float v_Bat = 0; + float v_Pyro = 0; }; /** diff --git a/MIDAS/src/silsim/emulated_sensors.cpp b/MIDAS/src/silsim/emulated_sensors.cpp index 27c72cf0..39ffa0de 100644 --- a/MIDAS/src/silsim/emulated_sensors.cpp +++ b/MIDAS/src/silsim/emulated_sensors.cpp @@ -18,14 +18,6 @@ LowGLSM LowGLSMSensor::read() { return { .gx = 0, .gy = 0, .gz = 0, .ax = 0, .ay = 0, .az =0 }; } -ErrorCode ContinuitySensor::init() { - return ErrorCode::NoError; -} - -Continuity ContinuitySensor::read() { - return { }; -} - ErrorCode HighGSensor::init() { return ErrorCode::NoError; } @@ -68,7 +60,7 @@ ErrorCode VoltageSensor::init() { } Voltage VoltageSensor::read() { - return { .voltage = 9 }; + return { .continuity = {}, .v_Bat = 0, .v_Pyro = 0 }; } ErrorCode MagnetometerSensor::init() { diff --git a/MIDAS/src/silsim/emulated_sensors.h b/MIDAS/src/silsim/emulated_sensors.h index 0d295601..c43d012b 100644 --- a/MIDAS/src/silsim/emulated_sensors.h +++ b/MIDAS/src/silsim/emulated_sensors.h @@ -36,7 +36,7 @@ struct BarometerSensor { struct ContinuitySensor { ErrorCode init(); - Continuity read(); + Voltage read(); bool should_be_continous; }; diff --git a/MIDAS/src/silsim/main.cpp b/MIDAS/src/silsim/main.cpp index 3d552c39..c19aee12 100644 --- a/MIDAS/src/silsim/main.cpp +++ b/MIDAS/src/silsim/main.cpp @@ -1,4 +1,4 @@ -#include "silsim/emulation.h" +//#include "silsim/emulation.h" #include "systems.h" #include "FileSink.h" @@ -12,7 +12,6 @@ Sensors create_sensors_attached_to(SimulatedRocket* sim, bool should_be_continuo LowGLSMSensor { sim }, HighGSensor { sim }, BarometerSensor { sim }, - ContinuitySensor { should_be_continuous }, VoltageSensor { sim }, OrientationSensor { sim }, MagnetometerSensor { sim }, diff --git a/MIDAS/src/systems.cpp b/MIDAS/src/systems.cpp index f4661250..11846447 100644 --- a/MIDAS/src/systems.cpp +++ b/MIDAS/src/systems.cpp @@ -138,10 +138,7 @@ DECLARE_THREAD(pyro, RocketSystems* arg) { DECLARE_THREAD(voltage, RocketSystems* arg) { while (true) { - Continuity reading = arg->sensors.continuity.read(); - Voltage reading2 = arg->sensors.voltage.read();; - - arg->rocket_data.continuity.update(reading); + Voltage reading2 = arg->sensors.voltage.read(); arg->rocket_data.voltage.update(reading2); THREAD_SLEEP(100); @@ -407,7 +404,6 @@ ErrorCode init_systems(RocketSystems& systems) { //INIT_SYSTEM(systems.sensors.low_g_lsm); INIT_SYSTEM(systems.sensors.barometer); INIT_SYSTEM(systems.sensors.magnetometer); - INIT_SYSTEM(systems.sensors.continuity); INIT_SYSTEM(systems.sensors.voltage); INIT_SYSTEM(systems.sensors.pyro); INIT_SYSTEM(systems.led); diff --git a/MIDAS/src/systems.h b/MIDAS/src/systems.h index b5d83493..704de699 100644 --- a/MIDAS/src/systems.h +++ b/MIDAS/src/systems.h @@ -36,10 +36,7 @@ struct Sensors { IMUSensor imu; BarometerSensor barometer; - - ContinuitySensor continuity; VoltageSensor voltage; - //OrientationSensor orientation; MagnetometerSensor magnetometer; diff --git a/MIDAS/src/telemetry.cpp b/MIDAS/src/telemetry.cpp index c09ee044..98d86968 100644 --- a/MIDAS/src/telemetry.cpp +++ b/MIDAS/src/telemetry.cpp @@ -88,10 +88,7 @@ TelemetryPacket Telemetry::makePacket(RocketData& data) { Voltage voltage = data.voltage.getRecentUnsync(); Barometer barometer = data.barometer.getRecentUnsync(); FSMState fsm = data.fsm_state.getRecentUnsync(); - Continuity continuity = data.continuity.getRecentUnsync(); - //HighGData highg = data.high_g.getRecentUnsync(); PyroState pyro = data.pyro.getRecentUnsync(); - //Orientation orientation = data.orientation.getRecentUnsync(); KalmanData kalman = data.kalman.getRecentUnsync(); AngularKalmanData angular_kalman = data.angular_kalman_data.getRecentUnsync(); CameraData cam_data = data.cam_data.getRecentUnsync(); @@ -122,7 +119,7 @@ TelemetryPacket Telemetry::makePacket(RocketData& data) { //Serial.println(packet.tilt_fsm, 2); // Battery voltage - packet.batt_volt = inv_convert_range(voltage.voltage, MAX_TELEM_VOLTAGE_V); + packet.batt_volt = inv_convert_range(voltage.v_Bat, MAX_TELEM_VOLTAGE_V); // Roll rate float roll_rate_hz = std::clamp(std::abs(imu.angular_velocity.vx) / (2.0f*static_cast(PI)), 0.0f, MAX_ROLL_RATE_HZ); @@ -143,10 +140,10 @@ TelemetryPacket Telemetry::makePacket(RocketData& data) { //Pyro A0 | B1 | C2 | D3 // This is what we're telemetering for MIDAS mk2 - packet.pyro |= ((((uint32_t) (std::round(continuity.pins[0]))) & 0x7F) << (0 * 7)); - packet.pyro |= ((((uint32_t) (continuity.pins[1] / MAX_TELEM_CONT_I * 127)) & 0x7F) << (1 * 7)); - packet.pyro |= ((((uint32_t) (continuity.pins[2] / MAX_TELEM_CONT_I * 127)) & 0x7F) << (2 * 7)); - packet.pyro |= ((((uint32_t) (continuity.pins[3] / MAX_TELEM_VOLTAGE_V * 127)) & 0x7F) << (3 * 7)); + packet.pyro |= ((((uint32_t) (std::round(voltage.continuity[0]))) & 0x7F) << (0 * 7)); + packet.pyro |= ((((uint32_t) (voltage.continuity[1] / MAX_TELEM_CONT_I * 127)) & 0x7F) << (1 * 7)); + packet.pyro |= ((((uint32_t) (voltage.continuity[2] / MAX_TELEM_CONT_I * 127)) & 0x7F) << (2 * 7)); + packet.pyro |= ((((uint32_t) (voltage.continuity[3] / MAX_TELEM_VOLTAGE_V * 127)) & 0x7F) << (3 * 7)); // This is what we want for MIDAS mk3 // packet.pyro |= (uint8_t)inv_convert_range(pins[0], MAX_TELEM_VOLTAGE_V); From a106d2d5aa4cc18931f441f6baa473c69917e49c Mon Sep 17 00:00:00 2001 From: Thomas McManamen Date: Fri, 13 Feb 2026 18:02:26 -0600 Subject: [PATCH 2/3] cleaned up voltage.cpp --- MIDAS/src/hardware/Voltage.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/MIDAS/src/hardware/Voltage.cpp b/MIDAS/src/hardware/Voltage.cpp index d835c3e9..1be2b4a4 100644 --- a/MIDAS/src/hardware/Voltage.cpp +++ b/MIDAS/src/hardware/Voltage.cpp @@ -4,6 +4,11 @@ #include #define VOLTAGE_DIVIDER (5.0 / (5.0 + 20.0)) +#define PYRO_VOLTAGE_DIVIDER (18.0/(100.0+18.0)) +#define PYRO_BATT_VOLTAGE_DIVIDER (100.0/(100.0+560.0)) +#define BATT_VOLTAGE_DIVIDER (100.0/(100.0+100.0)) +#define VOLTAGE_SCALE 3.3 +#define VOLTAGE_REG_WIDTH (1<<16) int read_board_pwr_monitor_register(int reg, int bytes) { Wire1.beginTransmission(0x44); @@ -65,51 +70,46 @@ Voltage VoltageSensor::read() { //Converts ADC value to voltage for each pin if(sensorBat.error == AdcError::NoError){ - float Bat_value = sensorBat.value; - float Bat_voltage = (((float)Bat_value / 65535) * 3.3) * 2.0; + float Bat_voltage = ((static_cast(sensorBat.value) / VOLTAGE_REG_WIDTH) * VOLTAGE_SCALE) / BATT_VOLTAGE_DIVIDER; voltage.v_Bat = Bat_voltage; Serial.print("VBAT: "); Serial.println(Bat_voltage); } if(sensorPyro.error == AdcError::NoError){ - float Pyro_voltage = (((float)sensorPyro.value / 65535) * 3.3)/(100.0/660); //Accounting for voltage divider on MIDAS mini + float Pyro_voltage = ((static_cast(sensorPyro.value) / VOLTAGE_REG_WIDTH) * VOLTAGE_SCALE)/(PYRO_BATT_VOLTAGE_DIVIDER); //Accounting for voltage divider on MIDAS mini voltage.v_Pyro = Pyro_voltage; Serial.print("PYRO: "); Serial.println(Pyro_voltage); } if(sensorA.error == AdcError::NoError){ - float A_value = sensorA.value* (100000.0/118000); //accounting for the resisters - float A_voltage = (((float)A_value / 65535) * 3.3)/(18.0/100); + float A_voltage = ((static_cast(sensorA.value) / VOLTAGE_REG_WIDTH) * VOLTAGE_SCALE) / PYRO_VOLTAGE_DIVIDER; voltage.continuity[0] = A_voltage; Serial.print("A: "); Serial.println(A_voltage); } if(sensorB.error == AdcError::NoError){ - uint16_t B_value = sensorB.value* (100000.0/118000); //accounting for the resisters - float B_voltage = (((float)B_value / 65535) * 3.3)/(18.0/100); + float B_voltage = ((static_cast(sensorB.value) / VOLTAGE_REG_WIDTH) * VOLTAGE_SCALE) / PYRO_VOLTAGE_DIVIDER; voltage.continuity[1] = B_voltage; Serial.print("B: "); Serial.println(B_voltage); } if(sensorC.error == AdcError::NoError){ - uint16_t C_value = sensorC.value*(100000.0/118000); //accounting for the resisters - float C_voltage = (((float)C_value / 65535) * 3.3)/(18.0/100); + float C_voltage = ((static_cast(sensorC.value) / VOLTAGE_REG_WIDTH) * VOLTAGE_SCALE) / PYRO_VOLTAGE_DIVIDER; voltage.continuity[2] = C_voltage; Serial.print("C: "); Serial.println(C_voltage); } if(sensorD.error == AdcError::NoError){ - uint16_t D_value = sensorD.value*(100000.0/118000); //accounting for the resisters - float D_voltage = (((float)D_value / 65535) * 3.3)/(18.0/100); + float D_voltage = ((static_cast(sensorD.value) / VOLTAGE_REG_WIDTH) * VOLTAGE_SCALE) / PYRO_VOLTAGE_DIVIDER; voltage.continuity[3] = D_voltage; Serial.print("D: "); Serial.println(D_voltage); } return voltage; -} +} \ No newline at end of file From dc2237bd2a7075ac5b3d3f1d4ec3ae7d30d0b7f1 Mon Sep 17 00:00:00 2001 From: Thomas McManamen Date: Fri, 13 Feb 2026 18:50:51 -0600 Subject: [PATCH 3/3] removed erroneous comment --- MIDAS/src/sensor_data.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/MIDAS/src/sensor_data.h b/MIDAS/src/sensor_data.h index ad0b560c..5302e293 100644 --- a/MIDAS/src/sensor_data.h +++ b/MIDAS/src/sensor_data.h @@ -80,9 +80,7 @@ struct Barometer { Barometer(float t, float p, float a) : temperature(t), pressure(p), altitude(a) {} }; -/** - * - * @brief data about pyro continuity + /** * @struct Voltage *