diff --git a/CMakeLists.txt b/CMakeLists.txt index 42a57e5..55fb403 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,8 @@ project(${BOARD_LIB_NAME} LANGUAGES CXX C ) -add_library(${PROJECT_NAME} STATIC) +add_library(${PROJECT_NAME} STATIC + targets/REV3-INA138/INA138_main.cpp) # Add sources target_sources(${PROJECT_NAME} PRIVATE diff --git a/include/INA138.hpp b/include/INA138.hpp index 084ff6d..908e05d 100644 --- a/include/INA138.hpp +++ b/include/INA138.hpp @@ -11,7 +11,7 @@ namespace log = EVT::core::log; namespace LVSS { /** - * class for LVSS current sensor feature + * Class for LVSS current sensor feature */ class INA138 { public: @@ -21,22 +21,21 @@ class INA138 { INA138(IO::ADC& adc0); /** - * Calculates current using the input voltage rail into the Vicor + * * Get the current detected by the INA * - * @return the current + * @return The current */ uint32_t readCurrent(IO::ADC&); private: - //ADC variable for getting input voltage + /** ADC instance for getting input voltage */ IO::ADC& ADC; ///Read INA138 datasheet page 3 //Resistor variables - static constexpr uint32_t fixedPoint = 1000; //Use fixpoint variable to multiply everything by 1k - static constexpr uint32_t rShunt = 0.05 * fixedPoint;//0.05 ohm resistor - static constexpr uint32_t r1 = 5000 * fixedPoint; //5k ohm - static constexpr uint32_t r3 = 50000; //50k ohm + static constexpr uint32_t rShunt = 0.05 * 100;//0.05 ohm resistor + static constexpr uint32_t r1 = 5000 ; //5k ohm + static constexpr uint32_t r3 = 50000; //50k ohm }; }// namespace LVSS diff --git a/src/INA138.cpp b/src/INA138.cpp index d99694b..61fdfc8 100644 --- a/src/INA138.cpp +++ b/src/INA138.cpp @@ -2,8 +2,7 @@ namespace LVSS { -INA138::INA138(IO::ADC& adc0) : ADC(adc0) { -} +INA138::INA138(IO::ADC& adc0) : ADC(adc0) {} uint32_t INA138::readCurrent(IO::ADC& adc0) { //Gets adcCounts from adc diff --git a/targets/REV3-INA138/INA138_main.cpp b/targets/REV3-INA138/INA138_main.cpp new file mode 100644 index 0000000..09951ac --- /dev/null +++ b/targets/REV3-INA138/INA138_main.cpp @@ -0,0 +1,40 @@ +/** +* This is a basic sample to show how the current sensing feature of the + * LVSS using the INA138 IC +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace IO = EVT::core::IO; +namespace DEV = EVT::core::DEV; +namespace time = EVT::core::time; +namespace log = EVT::core::log; +namespace types = EVT::core::types; +using namespace std; + +int main(){ + // Initialize system + EVT::core::platform::init(); + + // Setup UART + IO::UART& uart = IO::getUART(9600); + log::LOGGER.setUART(&uart); + log::LOGGER.setLogLevel(log::Logger::LogLevel::INFO); + + //ADC + IO::ADC& adc0 = IO::getADC(); + + LVSS::INA138 ina138(adc0); + + while(1){ + uart.printf("ADC0: %d\r\n mA", ina138.readCurrent(adc0)); + time::wait(500); + } +} \ No newline at end of file diff --git a/targets/REV3-LVSS/main.cpp b/targets/REV3-LVSS/main.cpp index 354d905..135252f 100644 --- a/targets/REV3-LVSS/main.cpp +++ b/targets/REV3-LVSS/main.cpp @@ -4,7 +4,7 @@ * enters. */ -#include "LVSS.hpp" +#include #include #include #include @@ -53,9 +53,6 @@ int main() { // initialize timer? probably don't need DEV::Timerf3xx timer(TIM2, 160); - //ADC - IO::ADC& adc0 = IO::getADC(); - LVSS::LVSS lvss(lvssEn0); types::FixedQueue canOpenQueue;