Skip to content

Commit dbd6cdc

Browse files
Merge pull request #177 from ISSUIUC/ADC_new
New ADC implementation!
2 parents 531014a + dc2237b commit dbd6cdc

File tree

19 files changed

+88
-210
lines changed

19 files changed

+88
-210
lines changed

MIDAS/lib/ADS7138Q1/ads7138-q1.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static AdcError adc_reg_write(uint8_t address, uint8_t reg_address, uint8_t data
4545
return AdcError::NoError;
4646
}
4747

48-
AdcReadResult adcAnalogRead(ADCAddress pin){
48+
AdcReadResult adcAnalogRead(ADCAddress pin){
4949
if(pin.pin_id < 0 || pin.pin_id >= 8){
5050
return AdcReadResult{.value=0, .error=AdcError::InvalidPinError};
5151
}
@@ -58,7 +58,7 @@ AdcReadResult adcAnalogRead(ADCAddress pin){
5858
}
5959
int high = WIRE.read();
6060
int low = WIRE.read();
61-
uint16_t value = (high << 4) + (low >> 4);
61+
uint16_t value = (high << 8) + low;
6262
return AdcReadResult{.value=value, .error=AdcError::NoError};
6363
}
6464

MIDAS/src/data_logging.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ constexpr ReadingDiscriminant get_discriminant();
1616

1717
ASSOCIATE(IMU, ID_IMU)
1818
ASSOCIATE(Barometer, ID_BAROMETER)
19-
ASSOCIATE(Continuity, ID_CONTINUITY)
2019
ASSOCIATE(Voltage, ID_VOLTAGE)
2120
ASSOCIATE(GPS, ID_GPS)
2221
ASSOCIATE(Magnetometer, ID_MAGNETOMETER)
@@ -87,7 +86,6 @@ void log_data(LogSink& sink, RocketData& data) {
8786
log_from_sensor_data(sink, data.imu);
8887
log_from_sensor_data(sink, data.hw_filtered);
8988
log_from_sensor_data(sink, data.barometer);
90-
log_from_sensor_data(sink, data.continuity);
9189
log_from_sensor_data(sink, data.voltage);
9290
log_from_sensor_data(sink, data.gps);
9391
log_from_sensor_data(sink, data.magnetometer);

MIDAS/src/errors.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,6 @@ void update_error_LED(ErrorCode error) {
8888
digitalWrite(LED_ORANGE, LOW);
8989
digitalWrite(LED_RED, HIGH);
9090
break;
91-
case ContinuityCouldNotBeInitialized:
92-
digitalWrite(LED_BLUE, LOW);
93-
digitalWrite(LED_GREEN, LOW);
94-
digitalWrite(LED_ORANGE, HIGH);
95-
digitalWrite(LED_RED, HIGH);
96-
break;
9791
case CannotConnectBNO:
9892
digitalWrite(LED_BLUE, HIGH);
9993
digitalWrite(LED_GREEN, HIGH);

MIDAS/src/errors.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ enum ErrorCode {
1717
GyroCouldNotBeInitialized = 8,
1818
PyroGPIOCouldNotBeInitialized = 9,
1919
GPSCouldNotBeInitialized = 10,
20-
ContinuityCouldNotBeInitialized = 11,
2120
RadioInitFailed = 12,
2221
RadioSetFrequencyFailed = 13,
2322
CannotConnectBNO = 14,

MIDAS/src/hardware/Continuity.cpp

Lines changed: 0 additions & 89 deletions
This file was deleted.

MIDAS/src/hardware/Voltage.cpp

Lines changed: 74 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
#include <Wire.h>
55

66
#define VOLTAGE_DIVIDER (5.0 / (5.0 + 20.0))
7+
#define PYRO_VOLTAGE_DIVIDER (18.0/(100.0+18.0))
8+
#define PYRO_BATT_VOLTAGE_DIVIDER (100.0/(100.0+560.0))
9+
#define BATT_VOLTAGE_DIVIDER (100.0/(100.0+100.0))
10+
#define VOLTAGE_SCALE 3.3
11+
#define VOLTAGE_REG_WIDTH (1<<16)
712

813
int read_board_pwr_monitor_register(int reg, int bytes) {
914
Wire1.beginTransmission(0x44);
@@ -39,23 +44,72 @@ ErrorCode VoltageSensor::init() {
3944
* @return The scaled voltage given by the voltage sensor
4045
*/
4146
Voltage VoltageSensor::read() {
42-
Voltage v_battery;
43-
int voltage = read_board_pwr_monitor_register(0x5, 2);
44-
int16_t current = read_board_pwr_monitor_register(0x7, 2);
45-
46-
float voltage_normalized = voltage * 3.125 / 1000.0;
47-
float absolute_current = current * 1.2 / 1000.0;
48-
49-
// Serial.print("Voltage: ");
50-
// Serial.println(voltage_normalized);
51-
// Serial.print("Current: ");
52-
// Serial.println(current);
53-
54-
v_battery.voltage = voltage_normalized;
55-
v_battery.current = absolute_current;
56-
// Serial.print("Raw voltage reading: ");
57-
// Serial.print(v_battery.voltage);
58-
// Serial.println("");
59-
//* 3.3f / 4095.f / VOLTAGE_DIVIDER;
60-
return v_battery;
61-
}
47+
Voltage voltage;
48+
49+
//CHECK PINS
50+
ADCAddress pinA;
51+
ADCAddress pinB;
52+
ADCAddress pinC;
53+
ADCAddress pinD;
54+
ADCAddress pinBat;
55+
ADCAddress pinPyro;
56+
pinA.pin_id = 0;
57+
pinB.pin_id = 1;
58+
pinC.pin_id = 4;
59+
pinD.pin_id = 5;
60+
pinBat.pin_id = 7;
61+
pinPyro.pin_id = 2;
62+
63+
//Getting ADC values
64+
AdcReadResult sensorA = adcAnalogRead(pinA);
65+
AdcReadResult sensorB = adcAnalogRead(pinB);
66+
AdcReadResult sensorC = adcAnalogRead(pinC);
67+
AdcReadResult sensorD = adcAnalogRead(pinD);
68+
AdcReadResult sensorBat = adcAnalogRead(pinBat);
69+
AdcReadResult sensorPyro = adcAnalogRead(pinPyro);
70+
71+
//Converts ADC value to voltage for each pin
72+
if(sensorBat.error == AdcError::NoError){
73+
float Bat_voltage = ((static_cast<float>(sensorBat.value) / VOLTAGE_REG_WIDTH) * VOLTAGE_SCALE) / BATT_VOLTAGE_DIVIDER;
74+
voltage.v_Bat = Bat_voltage;
75+
Serial.print("VBAT: ");
76+
Serial.println(Bat_voltage);
77+
}
78+
79+
if(sensorPyro.error == AdcError::NoError){
80+
float Pyro_voltage = ((static_cast<float>(sensorPyro.value) / VOLTAGE_REG_WIDTH) * VOLTAGE_SCALE)/(PYRO_BATT_VOLTAGE_DIVIDER); //Accounting for voltage divider on MIDAS mini
81+
voltage.v_Pyro = Pyro_voltage;
82+
Serial.print("PYRO: ");
83+
Serial.println(Pyro_voltage);
84+
}
85+
86+
if(sensorA.error == AdcError::NoError){
87+
float A_voltage = ((static_cast<float>(sensorA.value) / VOLTAGE_REG_WIDTH) * VOLTAGE_SCALE) / PYRO_VOLTAGE_DIVIDER;
88+
voltage.continuity[0] = A_voltage;
89+
Serial.print("A: ");
90+
Serial.println(A_voltage);
91+
}
92+
93+
if(sensorB.error == AdcError::NoError){
94+
float B_voltage = ((static_cast<float>(sensorB.value) / VOLTAGE_REG_WIDTH) * VOLTAGE_SCALE) / PYRO_VOLTAGE_DIVIDER;
95+
voltage.continuity[1] = B_voltage;
96+
Serial.print("B: ");
97+
Serial.println(B_voltage);
98+
}
99+
100+
if(sensorC.error == AdcError::NoError){
101+
float C_voltage = ((static_cast<float>(sensorC.value) / VOLTAGE_REG_WIDTH) * VOLTAGE_SCALE) / PYRO_VOLTAGE_DIVIDER;
102+
voltage.continuity[2] = C_voltage;
103+
Serial.print("C: ");
104+
Serial.println(C_voltage);
105+
}
106+
107+
if(sensorD.error == AdcError::NoError){
108+
float D_voltage = ((static_cast<float>(sensorD.value) / VOLTAGE_REG_WIDTH) * VOLTAGE_SCALE) / PYRO_VOLTAGE_DIVIDER;
109+
voltage.continuity[3] = D_voltage;
110+
Serial.print("D: ");
111+
Serial.println(D_voltage);
112+
}
113+
114+
return voltage;
115+
}

MIDAS/src/hardware/sensors.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ struct BarometerSensor {
3232
Barometer read();
3333
};
3434

35-
/**
36-
* @struct Continuity interface
37-
*/
38-
struct ContinuitySensor {
39-
ErrorCode init();
40-
Continuity read();
41-
};
42-
4335
/**
4436
* @struct Voltage interface
4537
*/
@@ -48,23 +40,6 @@ struct VoltageSensor {
4840
Voltage read();
4941
};
5042

51-
// /**
52-
// * @struct BNO interface
53-
// */
54-
// struct OrientationSensor {
55-
// Orientation initial_orientation;
56-
// Quaternion initial_quaternion;
57-
// uint8_t initial_flag;
58-
59-
// float prev_x = 0;
60-
// float prev_y = 0;
61-
// float prev_z = 0;
62-
// float prev_tilt = 0;
63-
64-
// ErrorCode init();
65-
// Orientation read();
66-
// };
67-
6843
/**
6944
* @struct GPS interface
7045
*/

MIDAS/src/hilsim/sensors.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ struct BarometerSensor {
4444
// LowGLSM read();
4545
// };
4646

47-
/**
48-
* @struct Continuity interface
49-
*/
50-
struct ContinuitySensor {
51-
ErrorCode init();
52-
Continuity read();
53-
};
5447

5548
/**
5649
* @struct Voltage interface

MIDAS/src/hilsim/sensors/Continuity.cpp

Lines changed: 0 additions & 10 deletions
This file was deleted.

MIDAS/src/hilsim/sensors/sensors.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ struct BarometerSensor {
2525
Barometer read();
2626
};
2727

28-
struct ContinuitySensor {
29-
ErrorCode init();
30-
Continuity read();
31-
};
32-
3328
struct VoltageSensor {
3429
ErrorCode init();
3530
Voltage read();

0 commit comments

Comments
 (0)