Skip to content

Commit

Permalink
LVSS current sensing
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoLHendrix committed Apr 20, 2024
1 parent 406b6bd commit 39096f4
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 36 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ add_library(${PROJECT_NAME} STATIC
# Add sources
target_sources(${PROJECT_NAME} PRIVATE
src/LVSS.cpp
src/dev/INA138.cpp
src/dev/ACS71240.cpp
)

###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion include/LVSS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <EVT/io/SPI.hpp>
#include <EVT/utils/log.hpp>
#include <LVSS.hpp>
#include <dev/INA138.hpp>
#include <dev/ACS71240.hpp>

namespace IO = EVT::core::IO;
namespace DEV = EVT::core::DEV;
Expand Down
18 changes: 7 additions & 11 deletions include/dev/INA138.hpp → include/dev/ACS71240.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef LVSS_INA138_HPP
#define LVSS_INA138_HPP
#ifndef LVSS_ACS71240_HPP
#define LVSS_ACS71240_HPP

#include <EVT/io/ADC.hpp>
#include <EVT/utils/log.hpp>
Expand All @@ -13,29 +13,25 @@ namespace LVSS {
/**
* Class for LVSS current sensor
*/
class INA138 {
class ACS71240 {
public:
/**
* Constructor for current sensing class
*/
INA138(IO::ADC& adc0);
ACS71240(IO::ADC& adc0);

/**
* Get the current detected by the INA
* Get the current detected by the ACS71240
*
* @return The current
*/
uint32_t readCurrent();
int32_t readCurrent();
uint32_t readCounts();

private:
/** ADC instance for getting input voltage */
IO::ADC& ADC;

/** Read INA138 datasheet page 3 */
/** Resistor variables */
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
21 changes: 21 additions & 0 deletions src/dev/ACS71240.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <dev/ACS71240.hpp>

namespace LVSS {

ACS71240::ACS71240(IO::ADC& adc0) : ADC(adc0) {}

int32_t ACS71240::readCurrent() {
//Gets adcCounts from adc
int32_t adcCounts = ADC.readRaw();

int32_t current = (((adcCounts-1970) * 3300) / 180);

return current;
}

uint32_t ACS71240::readCounts() {
uint32_t adcCounts = ADC.readRaw();
return adcCounts;
}

}// namespace LVSS
17 changes: 0 additions & 17 deletions src/dev/INA138.cpp

This file was deleted.

1 change: 1 addition & 0 deletions targets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Add all targets
add_subdirectory(REV3-LVSS)
add_subdirectory(REV3-ACS71240)
7 changes: 7 additions & 0 deletions targets/REV3-ACS71240/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include(${EVT_CORE_DIR}/cmake/evt-core_build.cmake)

project(REV3-ACS71240)
cmake_minimum_required(VERSION 3.15)

make_exe(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} PUBLIC ${BOARD_LIB_NAME})
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* This is a basic sample to show how the current sensing feature of the
* LVSS using the INA138 IC
* LVSS using the ACS71240 IC
*/

#include <EVT/io/UART.hpp>
Expand All @@ -25,12 +25,14 @@ int main() {
log::LOGGER.setLogLevel(log::Logger::LogLevel::INFO);

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

LVSS::INA138 ina138(adc0);
//Create ACS71240 instance
LVSS::ACS71240 acs71240(adc0);

while (1) {
uart.printf("ADC0: %d\r\n mA", ina138.readCurrent());
time::wait(500);
uart.printf("ADC0: %dmA\r\n", acs71240.readCurrent());
uart.printf("Counts: %d\r\n", acs71240.readCounts());
time::wait(1000);
}
}
}

0 comments on commit 39096f4

Please sign in to comment.