Skip to content
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
84ff3b9
Added new git branch
Ethan-Caracoglia Sep 30, 2024
213a367
Checking if commits work
Ethan-Caracoglia Sep 30, 2024
363a9c8
Ready for testing
Ethan-Caracoglia Oct 10, 2024
e2d66d2
Ready for CAN, just need it to be implemented on f4
Ethan-Caracoglia Oct 19, 2024
d115e6b
Ready for CAN, just need it to be implemented on f4
Ethan-Caracoglia Nov 5, 2024
a85fdce
added vs folder
Ethan-Caracoglia Nov 8, 2024
cc93622
Saving work with the brake until we are ready to implement it
Ethan-Caracoglia Dec 3, 2024
545394c
Should probably work now :)
Ethan-Caracoglia Dec 3, 2024
f070a6f
Working on fixes for the payload transference
Ethan-Caracoglia Jan 28, 2025
a9c7932
Need to change HIB for new ADCs
Ethan-Caracoglia Feb 7, 2025
f05b0e1
Getting things up to date
Ethan-Caracoglia Mar 12, 2025
1cd87cb
Hopefully this works
Ethan-Caracoglia Mar 31, 2025
e7d3808
ADS8689IPWR driver created, needs to be tested and verified
Ethan-Caracoglia Apr 14, 2025
bb1e415
Merge remote-tracking branch 'origin/ErrorCheckingAndPosition' into E…
Ethan-Caracoglia Apr 14, 2025
9782656
This is broken but I need to move the code
Ethan-Caracoglia Apr 22, 2025
e6f7b45
Almost done changing margin errors to a static voltage difference
Ethan-Caracoglia Apr 22, 2025
40714d9
Hopefully a fully function driver with a few interface pins missing
Ethan-Caracoglia Apr 23, 2025
464b4ea
CAN it do it? Yes it CAN!
Ethan-Caracoglia Apr 23, 2025
f4d830b
It CAN now go even faster
Ethan-Caracoglia Apr 23, 2025
d03b6fe
Attempted to fix the read issue on the ADCs
Ethan-Caracoglia May 2, 2025
404a142
Really not sure how to fix this issue
Ethan-Caracoglia May 2, 2025
122c140
I tried to prevent int overflow but that did not solve the problem
Ethan-Caracoglia May 2, 2025
4ab2d07
Beginning to change statements to logger
Ethan-Caracoglia Aug 20, 2025
00411da
Update for Oleg
Ethan-Caracoglia Sep 15, 2025
b0cdaa7
Altered Clang-Format path in the cmake file
Ethan-Caracoglia Nov 1, 2025
61d82a6
Altered Clang-Format path in the cmake file
Ethan-Caracoglia Nov 3, 2025
9b0b110
Apply suggestions from code review
Ethan-Caracoglia Nov 7, 2025
127cef7
Saving progress on dependecy refactor
Ethan-Caracoglia Jan 17, 2026
436f26c
Refactored a good deal of the code and altered the dependencies so no…
Ethan-Caracoglia Jan 24, 2026
c9adcbe
Fixed the macro and include errors for size_t
Ethan-Caracoglia Jan 24, 2026
eeecdf7
Attempting to fix build error by only building f446
Ethan-Caracoglia Jan 25, 2026
8233985
Changed the EVT-core branch back to main
Ethan-Caracoglia Jan 25, 2026
6ca79d4
Took main() out of hib namespace to avoid missing main reference
Ethan-Caracoglia Jan 25, 2026
904e7ab
Sorrowful attempt to fix IWDG compilation error
Ethan-Caracoglia Jan 25, 2026
12477c9
Sorrowful attempt to fix IWDG and timer compilation error
Ethan-Caracoglia Jan 25, 2026
80af261
Errasign timer sample
Ethan-Caracoglia Jan 25, 2026
a8be383
Fully erasing timer
Ethan-Caracoglia Jan 25, 2026
e793e35
Trying to get the build to work by converting the build back to norma…
Ethan-Caracoglia Jan 25, 2026
546606c
Reverting last change
Ethan-Caracoglia Jan 25, 2026
346257a
Chained EVT-core target
Ethan-Caracoglia Jan 25, 2026
416220c
Merge remote-tracking branch 'origin/ErrorCheckingAndPosition' into E…
Ethan-Caracoglia Jan 26, 2026
3121aa5
Updated github workflow and main to read out can connect result
Ethan-Caracoglia Jan 26, 2026
67a4416
Removed all samples to fix compile errors
Ethan-Caracoglia Jan 26, 2026
c8d49dd
Fixed namespace errors faulting on main()
Ethan-Caracoglia Jan 26, 2026
e3b4f32
Messed around with clang-format issue
Ethan-Caracoglia Jan 26, 2026
f407ffb
Applied Formatting Changes During GitHub Build
Jan 26, 2026
cc5b0a5
Ready to push (I am aware that the GPIO checking for the various Star…
Ethan-Caracoglia Feb 24, 2026
f4d4296
Applied Formatting Changes During GitHub Build
Feb 24, 2026
79d6375
Added Brake error information to the UART logging section just in cas…
Ethan-Caracoglia Feb 24, 2026
5f2d57d
Merge remote-tracking branch 'origin/ErrorCheckingAndPosition' into E…
Ethan-Caracoglia Feb 24, 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
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ if(EVT_CORE_LOG_ENABLE)
endif()

# Handle selection of the target device
option(TARGET_DEV "Target device" "STM32F334x8")
option(TARGET_DEV "Target device" "STM32F446xx")
if(NOT TARGET_DEV)
set(TARGET_DEV "STM32F334x8")
set(TARGET_DEV "STM32F446xx")
endif()

if(TARGET_DEV STREQUAL "STM32F302x8")
Expand All @@ -22,6 +22,9 @@ if(TARGET_DEV STREQUAL "STM32F302x8")
elseif(TARGET_DEV STREQUAL "STM32F334x8")
add_compile_definitions(STM32F334x8)
add_compile_definitions(STM32F3xx)
elseif(TARGET_DEV STREQUAL "STM32F446xx")
add_compile_definitions(STM32F446xx)
add_compile_definitions(STM32F4xx)
else()
message(FATAL_ERROR "The target device is not supported")
endif()
Expand Down Expand Up @@ -57,12 +60,17 @@ project(${BOARD_LIB_NAME}
LANGUAGES CXX C
)

add_library(${PROJECT_NAME} STATIC)
add_library(${PROJECT_NAME} STATIC
include/dev/ADS8689IPWR.hpp
include/dev/RedundantADC.hpp
include/HIB.hpp
)

# Add sources
target_sources(${PROJECT_NAME} PRIVATE
src/HIB.cpp
src/dev/RedundantADC.cpp
src/dev/ADS8689IPWR.cpp
)

###############################################################################
Expand Down
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ Contains notable changes there were added, fixed, or removed in each release.
* Build Board source as a library
* Template to build arbitrary number of targets
* Auto-generating documentation template

## 0.2.0

### Changes

* ADS8689IPWR driver
53 changes: 53 additions & 0 deletions include/HIB.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,66 @@
#pragma once
#include <core/io/UART.hpp>
#include <dev/ADS8689IPWR.hpp>
#include <dev/RedundantADC.hpp>
#include <sys/types.h>

namespace HIB {

/**
* Counts that when exceeded throw an error to the VC
*/
#define COMPARISON_ERROR_COUNT 1
#define PRECISION_MARGIN_ERROR_COUNT 3
#define ACCEPTABLE_MARGIN_ERROR_COUNT 5

constexpr size_t payloadLength = 5;

/**
* HIB header file
*/
class HIB {
public:
HIB(DEV::RedundantADC& throttle, DEV::RedundantADC& brake);

void process();

uint8_t payload[payloadLength];
uint32_t throttleVoltage = 0;
uint32_t brakeVoltage = 0;

// Counters for throttle errors
uint64_t acceptableThrottleMarginErrors = 0;
uint64_t precisionThrottleMarginErrors = 0;
uint64_t comparisonThrottleErrors = 0;

// Counters for brake errors
uint64_t acceptableBrakeMarginErrors = 0;
uint64_t precisionBrakeMarginErrors = 0;
uint64_t comparisonBrakeErrors = 0;

private:
void readThrottleVoltage();

void readBrakeVoltage();

DEV::RedundantADC& throttle;
DEV::RedundantADC& brake;

/**
* Payload for CAN transmission.
* Byte 0: MSB for Throttle Voltage
* Byte 1: LSB for Throttle Voltage
* Byte 2: MSB for Brake Voltage
* Byte 3: LSB for Brake Voltage
* Byte 4: Error Byte for triggering a shutdown
* Byte 4 layout: X X X X X X X X
* 7 6 5 4 3 2 1 0
* ^ ^
* | \
* ________________/ \__________________
* Brake Error Bit Throttle Error Bit
*/
uint8_t data[payloadLength];
};

}// namespace HIB
39 changes: 39 additions & 0 deletions include/dev/ADS8689IPWR.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#include <core/io/GPIO.hpp>
#include <core/io/SPI.hpp>

#define RANGE_SEL_REG 0x14 // R/W Range selection register ----
#define TWELVE_VOLT_SCALER 0b1000
#define HALF_WORD_WRITE 0b11010000
#define EMPTY_BYTE 0b00000000
#define NOP {EMPTY_BYTE, EMPTY_BYTE, EMPTY_BYTE, EMPTY_BYTE}
#define VOLTAGE_MAX 12288

namespace io = core::io;

namespace HIB::DEV {

class ADS8689IPWR {
public:
/**
* Creates a ADS8689IPWR object while configuring the range selector.
*
* @param spi SPI reference to interface with the ADC
* @param deviceNumber The number of the cs pin that the device is
*/
ADS8689IPWR(io::SPI& spi, uint8_t deviceNumber);

/**
* Reads out the voltage from the ADC with a blank command through SPI
*
* @param voltage reference to variable that is storing voltage
* @return the status of whether the transaction was successful
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't return this. It seems to return the voltage. Should be modified to return the SPIStatus and take a pointer to write the voltage.

*/
uint16_t read() const;
private:
io::SPI& spi;
const uint8_t deviceNumber;
};

}// namespace HIB::DEV
16 changes: 7 additions & 9 deletions include/dev/RedundantADC.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <EVT/io/ADC.hpp>
#include <dev/ADS8689IPWR.hpp>

namespace IO = EVT::core::IO;
namespace io = core::io;

namespace HIB::DEV {

Expand Down Expand Up @@ -33,27 +33,25 @@ class RedundantADC {
* @param[in] adc1 The second ADC instance.
* @param[in] adc2 The third ADC instance.
*/
RedundantADC(IO::ADC& adc0, IO::ADC& adc1, IO::ADC& adc2);
RedundantADC(ADS8689IPWR& adc0, ADS8689IPWR& adc1, ADS8689IPWR& adc2);

/**
* Read voltage readings from the ADCs and check for redundancy.
*
* This function reads values from three ADCs and checks for redundancy.
*
* @param[out] return_val Reference to the variable to store the value read from the ADCs
* @param[in] val2 Reference to the variable to store the value read from the second ADC.
* @param[in] val3 Reference to the variable to store the value read from the third ADC.
* @return RedundantADC::Status The status of the processing.
*/
RedundantADC::Status readVoltage(uint32_t& return_val);
RedundantADC::Status read(uint32_t& return_val);

private:
/** Reference to the first ADC. */
IO::ADC& adc0;
ADS8689IPWR& adc0;
/** Reference to the second ADC. */
IO::ADC& adc1;
ADS8689IPWR& adc1;
/** Reference to the third ADC. */
IO::ADC& adc2;
ADS8689IPWR& adc2;
};

}// namespace HIB::DEV
2 changes: 1 addition & 1 deletion libs/EVT-core
Submodule EVT-core updated 189 files
95 changes: 94 additions & 1 deletion src/HIB.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,98 @@
#include <HIB.hpp>
#include <dev/RedundantADC.hpp>

namespace HIB {

}// namespace HIB
HIB::HIB(DEV::RedundantADC& throttle, DEV::RedundantADC& brake)
: throttle(throttle), brake(brake) {
// Initialize payload to 0's
for (uint8_t i = 0; i < payloadLength; i++) {
payload[i] = 0;
}
}

// Reads the 2 sets of 3 ADCs and processes their errors while packaging them for CAN
void HIB::process() {
// Read in the voltages from the throttle
readThrottleVoltage();
readBrakeVoltage();

if (throttleVoltage < 300) {
throttleVoltage = 0;
}

if (brakeVoltage < 300) {
brakeVoltage = 0;
}

payload[0] = static_cast<uint8_t>(throttleVoltage >> 8 & 0xFF);
payload[1] = static_cast<uint8_t>(throttleVoltage & 0xFF);
payload[2] = static_cast<uint8_t>(brakeVoltage >> 8 & 0xFF);
payload[3] = static_cast<uint8_t>(brakeVoltage & 0xFF);

if (acceptableThrottleMarginErrors > ACCEPTABLE_MARGIN_ERROR_COUNT) {
acceptableThrottleMarginErrors = ACCEPTABLE_MARGIN_ERROR_COUNT + 1;
payload[4] |= 0b01;
}

if (acceptableBrakeMarginErrors > ACCEPTABLE_MARGIN_ERROR_COUNT) {
acceptableBrakeMarginErrors = ACCEPTABLE_MARGIN_ERROR_COUNT + 1;
payload[4] |= 0b10;
}

if (precisionThrottleMarginErrors > PRECISION_MARGIN_ERROR_COUNT) {
precisionThrottleMarginErrors = PRECISION_MARGIN_ERROR_COUNT + 1;
payload[4] |= 0b01;
}

if (precisionBrakeMarginErrors > PRECISION_MARGIN_ERROR_COUNT) {
precisionBrakeMarginErrors = PRECISION_MARGIN_ERROR_COUNT + 1;
payload[4] |= 0b10;
}

if (comparisonThrottleErrors > COMPARISON_ERROR_COUNT) {
comparisonThrottleErrors = COMPARISON_ERROR_COUNT + 1;
payload[4] |= 0b01;
}

if (comparisonBrakeErrors > COMPARISON_ERROR_COUNT) {
comparisonBrakeErrors = COMPARISON_ERROR_COUNT + 1;
payload[4] |= 0b10;
}
}

void HIB::readThrottleVoltage() {
const DEV::RedundantADC::Status status = throttle.read(throttleVoltage); // gets the errors and voltage from the ADC cluster

// Increment the status of each error if it is received
if (status == DEV::RedundantADC::Status::ACCEPTABLE_MARGIN_EXCEEDED) {
acceptableThrottleMarginErrors++;
}

if (status == DEV::RedundantADC::Status::PRECISION_MARGIN_EXCEEDED) {
precisionThrottleMarginErrors++;
}

if (status == DEV::RedundantADC::Status::COMPARISON_ERROR) {
comparisonThrottleErrors++;
}
}

void HIB::readBrakeVoltage() {
const DEV::RedundantADC::Status status = brake.read(brakeVoltage); // gets the errors and voltage from the ADC cluster

// Increment the status of each error if it is received
if (status == DEV::RedundantADC::Status::ACCEPTABLE_MARGIN_EXCEEDED) {
acceptableBrakeMarginErrors++;
}

if (status == DEV::RedundantADC::Status::PRECISION_MARGIN_EXCEEDED) {
precisionBrakeMarginErrors++;
}

if (status == DEV::RedundantADC::Status::COMPARISON_ERROR) {
comparisonBrakeErrors++;
}
}

}
33 changes: 33 additions & 0 deletions src/dev/ADS8689IPWR.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <core/utils/log.hpp>
#include <dev/ADS8689IPWR.hpp>

namespace HIB::DEV {

ADS8689IPWR::ADS8689IPWR(io::SPI& spi, const uint8_t deviceNumber) : spi(spi), deviceNumber(deviceNumber) {
uint8_t message[4] = {HALF_WORD_WRITE, RANGE_SEL_REG, EMPTY_BYTE, TWELVE_VOLT_SCALER};
spi.startTransmission(deviceNumber);
spi.write(message, 4);
spi.endTransmission(deviceNumber);

// Begin the conversion with a NOP command
uint8_t nop[4] = NOP;
spi.startTransmission(deviceNumber);
spi.write(nop, 4);
spi.endTransmission(deviceNumber);
}

uint16_t ADS8689IPWR::read() const {
uint8_t bytes[4];
spi.startTransmission(deviceNumber);
spi.read(bytes, 4);
spi.endTransmission(deviceNumber);

// First byte is MSB
uint32_t voltage = (bytes[0] << 8) + bytes[1];

// Normalize the received info (divide by uint16_t(MAX)) and scale accordingly
voltage = voltage * VOLTAGE_MAX / UINT16_MAX;
return voltage;
}

}
Loading
Loading