Skip to content

Commit

Permalink
LVSS current sensing
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoLHendrix committed Mar 19, 2024
1 parent 8da414f commit 6ced744
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions include/INA138.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/INA138.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions targets/REV3-INA138/INA138_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* This is a basic sample to show how the current sensing feature of the
* LVSS using the INA138 IC
*/

#include <EVT/io/CANopen.hpp>
#include <EVT/io/GPIO.hpp>
#include <EVT/io/UART.hpp>
#include <EVT/io/pin.hpp>
#include <EVT/manager.hpp>
#include <EVT/utils/log.hpp>
#include <EVT/utils/time.hpp>
#include <LVSS.hpp>

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<IO::Pin::UART_TX, IO::Pin::UART_RX>(9600);
log::LOGGER.setUART(&uart);
log::LOGGER.setLogLevel(log::Logger::LogLevel::INFO);

//ADC
IO::ADC& adc0 = IO::getADC<IO::Pin::PA_1>();

LVSS::INA138 ina138(adc0);

while(1){
uart.printf("ADC0: %d\r\n mA", ina138.readCurrent(adc0));
time::wait(500);
}
}
5 changes: 1 addition & 4 deletions targets/REV3-LVSS/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* enters.
*/

#include "LVSS.hpp"
#include <LVSS.hpp>
#include <EVT/io/CANopen.hpp>
#include <EVT/io/GPIO.hpp>
#include <EVT/io/UART.hpp>
Expand Down Expand Up @@ -53,9 +53,6 @@ int main() {
// initialize timer? probably don't need
DEV::Timerf3xx timer(TIM2, 160);

//ADC
IO::ADC& adc0 = IO::getADC<IO::Pin::PA_1>();

LVSS::LVSS lvss(lvssEn0);

types::FixedQueue<CANOPEN_QUEUE_SIZE, IO::CANMessage> canOpenQueue;
Expand Down

0 comments on commit 6ced744

Please sign in to comment.