Skip to content

Commit 24810c5

Browse files
committed
Updated variable names, comments, and struct declarations
1 parent 59b1669 commit 24810c5

7 files changed

Lines changed: 83 additions & 72 deletions

File tree

include/LVSS.hpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,24 @@ namespace time = core::time;
5050
namespace LVSS {
5151

5252
static constexpr uint8_t POWER_SWITCHES_SIZE = 3;
53-
5453
/**
5554
* This is the main board class for the LVSS.
5655
* Updates the power switch temperature, current, and fault values.
5756
*/
5857
class LVSS : public CANDevice {
5958
public:
60-
static constexpr uint8_t NODE_ID = 1;
61-
static constexpr uint8_t VCU_NODE_ID = 0;
62-
static constexpr uint8_t TPDO_NODE_ID = 1;
59+
static constexpr uint8_t NODE_ID = 1;
60+
static constexpr uint8_t TPDO_NODE_ID = 1;
61+
static constexpr uint8_t VCU_NODE_ID = 0;
62+
static constexpr io::Pin vicorFaultPin = io::Pin::PB_4;
63+
static constexpr io::Pin vicorSNS = io::Pin::PA_4;
6364

65+
/** Vicor fault pin */
6466
io::GPIO& vicorFT;
65-
static constexpr io::Pin vicorFaultPin = io::Pin::PB_4;
66-
static constexpr io::Pin vicorSNS = io::Pin::PA_4;
6767
io::GPIO::State VICOR_FAULT_ACTIVE_STATE = io::GPIO::State::HIGH;
6868

6969
/** Union bit field to hold a bit representing which boards are on/off */
70-
union BoardPowerState_u {
70+
typedef union {
7171
uint16_t val;
7272
struct {
7373
// Power Switch 0
@@ -81,11 +81,11 @@ class LVSS : public CANDevice {
8181
// Power Switch 2
8282
uint8_t gub : 1;
8383
uint8_t acc : 1;
84-
};
85-
};
84+
} __attribute__((packed));
85+
} BoardPowerState_u;
8686

8787
/** Struct to hold the data for individual boards */
88-
union switchData_u {
88+
typedef union {
8989
uint16_t battCurrent;
9090
uint16_t hibCurrent;
9191
uint16_t tmsCurrent;
@@ -96,9 +96,9 @@ class LVSS : public CANDevice {
9696
int16_t switch0Temp;
9797
int16_t switch1Temp;
9898
int16_t switch2Temp;
99-
};
99+
} switchData_u;
100100

101-
union switchFaults_u {
101+
typedef union {
102102
uint16_t val;
103103
struct {
104104
// Power Switch 0
@@ -110,14 +110,14 @@ class LVSS : public CANDevice {
110110
uint16_t hudlCurrentFault : 1;
111111

112112
// Power Switch 2
113-
uint16_t accCurrentFault : 1;
114-
uint16_t gubCurrentFault : 1;
113+
uint16_t accCurrentFault : 1;
114+
uint16_t gubCurrentFault : 1;
115115

116116
uint16_t switch0TempFault : 1;
117117
uint16_t switch1TempFault : 1;
118118
uint16_t switch2TempFault : 1;
119-
};
120-
};
119+
} __attribute__((packed));
120+
} switchFaults_u;
121121

122122
/** FSM State declaration */
123123
enum class State {
@@ -128,9 +128,9 @@ class LVSS : public CANDevice {
128128
/**
129129
* Constructor for the LVSS class, takes a pointer to an array of power switches
130130
*
131-
* @param powerSwitches an array of pointers to power switches
132-
* @param vicorFT fault status pin of the vicor
133-
* @param acs71240 vicor current sensing IC
131+
* @param powerSwitches[in] an array of pointers to power switches
132+
* @param vicorFT[in] fault status pin of the vicor
133+
* @param acs71240[in] vicor current sensing IC
134134
*/
135135
explicit LVSS(TPS2HB35BQ* powerSwitches[POWER_SWITCHES_SIZE], io::GPIO& vicorFT, ACS71240 acs71240);
136136

include/dev/ACS71240.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ namespace log = core::log;
1111
namespace LVSS {
1212

1313
/**
14-
* Class for LVSS current sensor
14+
* This class is used to control ACS71240 temperature sensor.
15+
* The ACS71240 is a current sensing IC used to sense the current going across the LVSS and Vicor.
1516
*/
1617
class ACS71240 {
1718
public:
@@ -29,9 +30,10 @@ class ACS71240 {
2930

3031
private:
3132
/** ADC instance for getting input voltage */
32-
int16_t voltIn = 3300; //millivolts
33-
int16_t sensitivity = 44; //millivolts / amp
34-
int16_t avgAdcCount = 1970; //Background Noise
33+
int16_t adcVoltage = 3300; // ADC voltage in millivolts
34+
int16_t sensitivity = 44; // millivolts / amp
35+
int16_t scaledCurrent = 180; // Sensitivity multiplied by ADC resolution (4096 * 0.044)
36+
int16_t avgAdcCount = 1970; // Background Noise
3537
io::ADC& ADC;
3638
};
3739

include/dev/TPS2HB35BQ.hpp

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ class TPS2HB35BQ {
3030
TPS2HB35BQ(io::GPIO& en1, io::GPIO& en2, io::GPIO& latch, io::GPIO& diagEn, io::GPIO& diagSelect1,
3131
io::GPIO& diagSelect2, io::ADC& senseOut, uint32_t rsns = 330);
3232

33+
/**
34+
* diagMode::OFF: Sets diagnostics pin low, along with both diag select pins.
35+
* diagMode::FAULT_STATUS: Get the fault status of the power switch
36+
* diagMode::CH1CURRENT: Get the channel 1 current of the power switch
37+
* diagMode::CH2CURRENT: Get the channel 2 current of the power switch
38+
* diagMode::TEMP: Get the temperature of the power switch
39+
*/
3340
enum DiagMode {
3441
OFF = 0x00,
3542
FAULT_STATUS = 0x01,
@@ -38,38 +45,48 @@ class TPS2HB35BQ {
3845
TEMP = 0x04
3946
};
4047

48+
/**
49+
* Sets the latch mode for the power switches
50+
*/
4151
enum LatchMode {
4252
LATCHED = 0x00, // If there is a fault the power switch will shut off and stay off
4353
AUTO_RETRY = 0x01 // If there is a fault the power switch will shut off and try to turn back on until there is
4454
// no longer a fault
4555
};
4656

57+
/**
58+
* Sets the power switch channel output to high or low.
59+
*
60+
* @param powerSwitchOneEnabled State of power switch channel 1
61+
* @param powerSwitchTwoEnabled State of power switch channel 2
62+
*/
4763
void setPowerSwitchStates(bool powerSwitchOneEnabled, bool powerSwitchTwoEnabled);
4864

4965
/**
50-
* Get the current of the power switch
51-
* A fault is detected if the current is somewhere between 4 and 5.3 mA
66+
* Get the current of the power switch.
67+
* A fault is detected if the current is somewhere between 4 and 5.3 mA.
5268
*
69+
* @param channelSelect The channel to sense the current from
5370
* @return The current of the power switch in milli amps
5471
*/
5572
uint32_t getCurrentAndFault(uint8_t channelSelect);
5673

5774
/**
5875
* Get the temperature of the power switch.
5976
*
60-
* @return The temperature of the power switch in Celsius
77+
* @return The temperature of the power switch in millicelcius
6178
*/
6279
int32_t getTemperature();
6380

6481
/**
65-
* Set the latch mode of the power switch
82+
* Set the latch mode of the power switch.
6683
*
6784
* @param mode The latch mode to set
6885
*/
6986
void setLatch(LatchMode mode);
7087

7188
/**
72-
* Set the limits for the power switches
89+
* Set the limits for the power switches at which they shut down.
7390
*
7491
* @param ohms The resistance value of the sense resistor
7592
* @param ratio The current sense ratio
@@ -78,14 +95,6 @@ class TPS2HB35BQ {
7895
*/
7996
void setLimits(uint32_t ohms, uint32_t ratio, uint32_t milliamps, int32_t millicelsius);
8097

81-
/**
82-
* diagMode::OFF: Sets diagnostics pin low, along with both diag select pins.
83-
* diagMode::FAULT_STATUS: Get the fault status of the power switch
84-
* diagMode::CH1CURRENT: Get the channel 1 current of the power switch
85-
* diagMode::CH2CURRENT: Get the channel 2 current of the power switch
86-
* diagMode::TEMP: Get the temperature of the power switch
87-
*/
88-
8998
private:
9099
io::GPIO& en1;
91100
io::GPIO& en2;
@@ -95,14 +104,16 @@ class TPS2HB35BQ {
95104
io::GPIO& diagSelect2;
96105
io::ADC& senseOut;
97106

98-
uint32_t counts = 0; // ADC Counts
99-
uint32_t adcVoltage = 3300; // ADC Voltage
100-
uint32_t rsns = 360; // Resistor that sets the current limit
101-
uint32_t kcl = 140; // Current Limit Ratio
102-
uint32_t icl = 9000; // Current Limit Value in milliamps
103-
int32_t TemperatureLimit = 135000; // Temperature Limit of 135 C in millicelsius
104-
uint32_t dIsnst = 11; // Coefficient 0.011 mA/C in microamps
105-
uint32_t resistanceOnJunctionTemp = 25000; // 25 C in millicelsius
107+
uint32_t counts = 0; // ADC Counts
108+
uint32_t rsns = 360; // Resistor that sets the current limit
109+
uint32_t kcl = 140; // Current Limit Ratio
110+
uint32_t icl = 9000; // Current Limit Value in milliamps
111+
int32_t TemperatureLimit = 135000; // Temperature Limit of 135 C in millicelsius
112+
113+
static constexpr uint32_t adcVoltage = 3300; // ADC Voltage
114+
static constexpr uint32_t dIsnst = 11; // Coefficient 0.011 mA/C in microamps
115+
static constexpr uint32_t resistanceOnJunctionTemp = 25000; // 25 C in millicelsius
116+
static constexpr uint32_t adcResolution = 4096; // 25 C in millicelsius
106117

107118
/**
108119
* Controls the diagnostic enable pin
@@ -114,7 +125,7 @@ class TPS2HB35BQ {
114125
/**
115126
* Read the sense out of the power switch
116127
*
117-
* @param senseOut The sense out value
128+
* @return senseOut The sense out value
118129
*/
119130
uint32_t readSenseOut();
120131

src/dev/ACS71240.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ uint16_t ACS71240::readCurrent() {
88
// Gets adcCounts from adc
99
int16_t adcCounts = ADC.readRaw();
1010

11-
//(((adcCounts - average adc counts) * inputVoltage) / (sensitivity * 2^12)/100)
12-
int16_t current = (((adcCounts - avgAdcCount) * voltIn) / (sensitivity << 12)/100);
11+
// (((adcCounts - average adc counts) * 3.3) / (4096 * 0.044)) * 1000
12+
int16_t rawCurrent = (((adcCounts - avgAdcCount) * adcVoltage) / scaledCurrent);
1313

14-
return current;
14+
return rawCurrent;
1515
}
1616

1717
} // namespace LVSS

src/dev/TPS2HB35BQ.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ uint32_t TPS2HB35BQ::getCurrentAndFault(uint8_t channelSelect) {
8787
}
8888

8989
/* volts = (ADC Counts * 3300 kilovolts) / 4096 */
90-
uint32_t milliVolts = (counts * adcVoltage) / 4096; // Turn ADC counts into milli volts
90+
uint32_t milliVolts = (counts * adcVoltage) / adcResolution; // Turn ADC counts into milli volts
9191
uint32_t microAmps = (milliVolts * 1000) / rsns; // Turn milli volts into micro amps
9292

9393
/* If current is greater than the current limit latch the sns pin */
@@ -109,7 +109,7 @@ int32_t TPS2HB35BQ::getTemperature() {
109109
setLatch(LatchMode::LATCHED); // Latch power switches
110110
}
111111

112-
uint32_t milliVolts = (counts * adcVoltage) / 4096; // Turn ADC counts into milli volts
112+
uint32_t milliVolts = (counts * adcVoltage) / adcResolution; // Turn ADC counts into milli volts
113113
int32_t microAmps = (milliVolts * 1000) / rsns; // Turn milli volts into micro amps
114114

115115
/* ( Isns (mA) - 0.85 mA ) / (dIsnst/dT) + 25 celsius */

targets/REV3-LVSS/main.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ namespace types = core::types;
3030
*
3131
* @param message[in] The passed in CAN message that was read.
3232
*/
33-
// create a can interrupt handler
3433
void canInterrupt(io::CANMessage& message, void* priv) {
3534
auto* queue = reinterpret_cast<types::FixedQueue<CANOPEN_QUEUE_SIZE, io::CANMessage>*>(priv);
3635

@@ -39,6 +38,26 @@ void canInterrupt(io::CANMessage& message, void* priv) {
3938
}
4039
}
4140

41+
io::GPIO& lvssPowerSwitch0Enable0 = io::getGPIO<io::Pin::PC_14>(io::GPIO::Direction::OUTPUT); // hib
42+
io::GPIO& lvssPowerSwitch0Enable1 = io::getGPIO<io::Pin::PD_2>(io::GPIO::Direction::OUTPUT); // battery
43+
io::GPIO& lvssPowerSwitch0Latch = io::getGPIO<io::Pin::PC_10>(io::GPIO::Direction::OUTPUT); // latch
44+
45+
io::GPIO& lvssPowerSwitch1Enable0 = io::getGPIO<io::Pin::PF_1>(io::GPIO::Direction::OUTPUT); // hudl
46+
io::GPIO& lvssPowerSwitch1Enable1 = io::getGPIO<io::Pin::PA_0>(io::GPIO::Direction::OUTPUT); // tms
47+
io::GPIO& lvssPowerSwitch1Latch = io::getGPIO<io::Pin::PC_3>(io::GPIO::Direction::OUTPUT); // latch
48+
49+
io::GPIO& lvssPowerSwitch2Enable0 = io::getGPIO<io::Pin::PA_1>(io::GPIO::Direction::OUTPUT); // gub
50+
io::GPIO& lvssPowerSwitch2Enable1 = io::getGPIO<io::Pin::PC_8>(io::GPIO::Direction::OUTPUT); // acc
51+
io::GPIO& lvssPowerSwitch2Latch = io::getGPIO<io::Pin::PB_14>(io::GPIO::Direction::OUTPUT); // latch
52+
53+
io::GPIO& diagEnable = io::getGPIO<io::Pin::PC_13>(io::GPIO::Direction::OUTPUT); // diag enable
54+
io::GPIO& diagSelect1 = io::getGPIO<io::Pin::PC_15>(io::GPIO::Direction::OUTPUT); // diag select 1
55+
io::GPIO& diagSelect2 = io::getGPIO<io::Pin::PF_0>(io::GPIO::Direction::OUTPUT); // diag select 2
56+
57+
io::ADC& lvssPowerSwitch0SenseOut = io::getADC<io::Pin::PC_1>();
58+
io::ADC& lvssPowerSwitch1SenseOut = io::getADC<io::Pin::PC_2>();
59+
io::ADC& lvssPowerSwitch2SenseOut = io::getADC<io::Pin::PC_0>();
60+
4261
int main() {
4362
// Initialize system
4463
core::platform::init();
@@ -48,26 +67,6 @@ int main() {
4867
log::LOGGER.setUART(&uart);
4968
log::LOGGER.setLogLevel(log::Logger::LogLevel::DEBUG);
5069

51-
io::GPIO& lvssPowerSwitch0Enable0 = io::getGPIO<io::Pin::PC_14>(io::GPIO::Direction::OUTPUT); // hib
52-
io::GPIO& lvssPowerSwitch0Enable1 = io::getGPIO<io::Pin::PD_2>(io::GPIO::Direction::OUTPUT); // battery
53-
io::GPIO& lvssPowerSwitch0Latch = io::getGPIO<io::Pin::PC_10>(io::GPIO::Direction::OUTPUT); // latch
54-
55-
io::GPIO& lvssPowerSwitch1Enable0 = io::getGPIO<io::Pin::PF_1>(io::GPIO::Direction::OUTPUT); // hudl
56-
io::GPIO& lvssPowerSwitch1Enable1 = io::getGPIO<io::Pin::PA_0>(io::GPIO::Direction::OUTPUT); // tms
57-
io::GPIO& lvssPowerSwitch1Latch = io::getGPIO<io::Pin::PC_3>(io::GPIO::Direction::OUTPUT); // latch
58-
59-
io::GPIO& lvssPowerSwitch2Enable0 = io::getGPIO<io::Pin::PA_1>(io::GPIO::Direction::OUTPUT); // gub
60-
io::GPIO& lvssPowerSwitch2Enable1 = io::getGPIO<io::Pin::PC_8>(io::GPIO::Direction::OUTPUT); // acc
61-
io::GPIO& lvssPowerSwitch2Latch = io::getGPIO<io::Pin::PB_14>(io::GPIO::Direction::OUTPUT); // latch
62-
63-
io::GPIO& diagEnable = io::getGPIO<io::Pin::PC_13>(io::GPIO::Direction::OUTPUT); // diag enable
64-
io::GPIO& diagSelect1 = io::getGPIO<io::Pin::PC_15>(io::GPIO::Direction::OUTPUT); // diag select 1
65-
io::GPIO& diagSelect2 = io::getGPIO<io::Pin::PF_0>(io::GPIO::Direction::OUTPUT); // diag select 2
66-
67-
io::ADC& lvssPowerSwitch0SenseOut = io::getADC<io::Pin::PC_1>();
68-
io::ADC& lvssPowerSwitch1SenseOut = io::getADC<io::Pin::PC_2>();
69-
io::ADC& lvssPowerSwitch2SenseOut = io::getADC<io::Pin::PC_0>();
70-
7170
LVSS::TPS2HB35BQ powerSwitch0 = LVSS::TPS2HB35BQ(lvssPowerSwitch0Enable0,
7271
lvssPowerSwitch0Enable1,
7372
lvssPowerSwitch0Latch,

targets/REV3-TPS2HB35BQ/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ using namespace std;
2727
*
2828
* @param message[in] The passed in CAN message that was read.
2929
*/
30-
// create a can interrupt handler
3130
void canInterrupt(io::CANMessage& message, void* priv) {
3231
auto* queue = reinterpret_cast<types::FixedQueue<CANOPEN_QUEUE_SIZE, io::CANMessage>*>(priv);
3332

0 commit comments

Comments
 (0)