ADS1014 working, in continuous mode. 0.15 ms to get value

This commit is contained in:
Hakan Bastedt
2025-02-19 11:48:16 +01:00
parent 72e861b174
commit b136a93e28
3 changed files with 49 additions and 30 deletions

View File

@@ -8,13 +8,13 @@
{ {
"name": "PlatformIO", "name": "PlatformIO",
"includePath": [ "includePath": [
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/include", "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/include",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/src", "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/src",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/MyMCP3221", "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/lib/MyMCP3221",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi", "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/lib/soes-esi",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes", "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/lib/soes",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/.pio/libdeps/genericSTM32F407VGT6/ADS1X15", "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/.pio/libdeps/genericSTM32F407VGT6/ADS1X15",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/.pio/libdeps/genericSTM32F407VGT6/MCP3X21", "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/.pio/libdeps/genericSTM32F407VGT6/MCP3X21",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/Wire/src", "C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/Wire/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/SPI/src", "C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/SPI/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/cores/arduino/avr", "C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/cores/arduino/avr",
@@ -57,13 +57,13 @@
"browse": { "browse": {
"limitSymbolsToIncludedHeaders": true, "limitSymbolsToIncludedHeaders": true,
"path": [ "path": [
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/include", "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/include",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/src", "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/src",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/MyMCP3221", "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/lib/MyMCP3221",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi", "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/lib/soes-esi",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes", "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/lib/soes",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/.pio/libdeps/genericSTM32F407VGT6/ADS1X15", "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/.pio/libdeps/genericSTM32F407VGT6/ADS1X15",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/.pio/libdeps/genericSTM32F407VGT6/MCP3X21", "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/.pio/libdeps/genericSTM32F407VGT6/MCP3X21",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/Wire/src", "C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/Wire/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/SPI/src", "C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/SPI/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/cores/arduino/avr", "C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/cores/arduino/avr",

View File

@@ -12,7 +12,7 @@
"type": "platformio-debug", "type": "platformio-debug",
"request": "launch", "request": "launch",
"name": "PIO Debug", "name": "PIO Debug",
"executable": "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/.pio/build/genericSTM32F407VGT6/firmware.elf", "executable": "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/.pio/build/genericSTM32F407VGT6/firmware.elf",
"projectEnvName": "genericSTM32F407VGT6", "projectEnvName": "genericSTM32F407VGT6",
"toolchainBinDir": "C:/Users/Hakan/.platformio/packages/toolchain-gccarmnoneeabi/bin", "toolchainBinDir": "C:/Users/Hakan/.platformio/packages/toolchain-gccarmnoneeabi/bin",
"internalConsoleOptions": "openOnSessionStart", "internalConsoleOptions": "openOnSessionStart",
@@ -26,7 +26,7 @@
"type": "platformio-debug", "type": "platformio-debug",
"request": "launch", "request": "launch",
"name": "PIO Debug (skip Pre-Debug)", "name": "PIO Debug (skip Pre-Debug)",
"executable": "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/.pio/build/genericSTM32F407VGT6/firmware.elf", "executable": "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/.pio/build/genericSTM32F407VGT6/firmware.elf",
"projectEnvName": "genericSTM32F407VGT6", "projectEnvName": "genericSTM32F407VGT6",
"toolchainBinDir": "C:/Users/Hakan/.platformio/packages/toolchain-gccarmnoneeabi/bin", "toolchainBinDir": "C:/Users/Hakan/.platformio/packages/toolchain-gccarmnoneeabi/bin",
"internalConsoleOptions": "openOnSessionStart", "internalConsoleOptions": "openOnSessionStart",
@@ -36,7 +36,7 @@
"type": "platformio-debug", "type": "platformio-debug",
"request": "launch", "request": "launch",
"name": "PIO Debug (without uploading)", "name": "PIO Debug (without uploading)",
"executable": "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/.pio/build/genericSTM32F407VGT6/firmware.elf", "executable": "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/.pio/build/genericSTM32F407VGT6/firmware.elf",
"projectEnvName": "genericSTM32F407VGT6", "projectEnvName": "genericSTM32F407VGT6",
"toolchainBinDir": "C:/Users/Hakan/.platformio/packages/toolchain-gccarmnoneeabi/bin", "toolchainBinDir": "C:/Users/Hakan/.platformio/packages/toolchain-gccarmnoneeabi/bin",
"internalConsoleOptions": "openOnSessionStart", "internalConsoleOptions": "openOnSessionStart",

View File

@@ -16,7 +16,7 @@ HardwareSerial Serial1(PA10, PA9);
uint8_t inputPin[] = {PD15, PD14, PD13, PD12, PD11, PD10, PD9, PD8, PB15, PB14, PB13, PB12}; uint8_t inputPin[] = {PD15, PD14, PD13, PD12, PD11, PD10, PD9, PD8, PB15, PB14, PB13, PB12};
uint8_t outputPin[] = {PE10, PE9, PE8, PE7}; uint8_t outputPin[] = {PE10, PE9, PE8, PE7};
const uint32_t I2C_BUS_SPEED = 100000; const uint32_t I2C_BUS_SPEED = 400000;
uint32_t I2C_restarts = 0; uint32_t I2C_restarts = 0;
#include "Wire.h" #include "Wire.h"
@@ -29,7 +29,16 @@ MyMCP3221 mcp3221_7(0x4f, &Wire2);
#endif #endif
#ifdef ADS1xxx #ifdef ADS1xxx
#include "ADS1X15.h" #include "ADS1X15.h"
ADS1115 ads1115(0x48, &Wire2); ADS1115 ads1014(0x48, &Wire2);
void ads1014_reset()
{
ads1014.reset();
ads1014.begin();
ads1014.setGain(1); // 1=4.096V
ads1014.setMode(0); // 0 continuous
ads1014.setDataRate(6); // Max for ads101x
ads1014.readADC_Differential_0_1(); // This is the value we are interested in
}
#endif #endif
#define bitset(byte, nbit) ((byte) |= (1 << (nbit))) #define bitset(byte, nbit) ((byte) |= (1 << (nbit)))
@@ -60,8 +69,8 @@ void cb_get_inputs(void) // Set Master inputs, slave outputs, last operation
int stat = mcp3221_0.ping(); int stat = mcp3221_0.ping();
#endif #endif
#ifdef ADS1xxx #ifdef ADS1xxx
int data0 = ads1115.readADC_Differential_0_1(); int data0 = ads1014.getValue();
int stat = ads1115.isConnected(); int stat = ads1014.isConnected();
#endif #endif
if (stat == 0) if (stat == 0)
{ // Read good value { // Read good value
@@ -79,6 +88,9 @@ void cb_get_inputs(void) // Set Master inputs, slave outputs, last operation
Wire2.begin(); Wire2.begin();
Wire2.setClock(I2C_BUS_SPEED); Wire2.setClock(I2C_BUS_SPEED);
I2C_restarts++; I2C_restarts++;
#ifdef ADS1xxx
ads1014_reset();
#endif
} }
Obj.Status = I2C_restarts + (stat << 28); // Put status as bits 28-31, the lower are number of restarts (restart attempts) Obj.Status = I2C_restarts + (stat << 28); // Put status as bits 28-31, the lower are number of restarts (restart attempts)
} }
@@ -134,10 +146,7 @@ void setup(void)
Wire2.begin(); Wire2.begin();
Wire2.setClock(I2C_BUS_SPEED); Wire2.setClock(I2C_BUS_SPEED);
#ifdef ADS1xxx #ifdef ADS1xxx
ads1115.begin(); ads1014_reset();
ads1115.setGain(1); // 4.096V
ads1115.setMode(1); // Single
ads1115.setDataRate(7);
#endif #endif
#ifdef ECAT #ifdef ECAT
@@ -152,27 +161,37 @@ void setup(void)
while (1) // Apply voltage over the inputs 0-11 and see response in terminal while (1) // Apply voltage over the inputs 0-11 and see response in terminal
{ {
int nDevices = 0; int nDevices = 0;
for (int i2caddr = 0; i2caddr < 127; i2caddr++) for (int i2caddr = 1; i2caddr < 127; i2caddr++)
{ {
Wire2.beginTransmission(i2caddr); Wire2.beginTransmission(i2caddr);
int stat = Wire2.endTransmission(); int stat = Wire2.endTransmission();
if (stat == 0) if (stat == 0)
{ {
Serial1.printf("I2C device found at address 0x%2x\b", i2caddr); Serial1.printf("I2C device found at address 0x%02x\n", i2caddr);
nDevices++; nDevices++;
} }
} }
Serial1.printf("Found %d devices\n", nDevices); if (!nDevices)
Serial1.printf("No devices\n");
#ifdef MCP3221 #ifdef MCP3221
Serial1.printf("I2C status=%d rawdata=%d ", mcp3221_0.ping(), mcp3221_0.getData()); Serial1.printf("I2C status=%d rawdata=%d ", mcp3221_0.ping(), mcp3221_0.getData());
#endif #endif
#ifdef ADS1xxx #ifdef ADS1xxx
Serial1.printf("I2C status=%d rawdata=%d ", ads1115.isConnected() ? 0 : -1, ads1115.readADC_Differential_0_1()); // else Serial1.printf("I2C status=%d rawdata=%d pin0=%d pin1=%d\n", ads1014.isConnected() ? 0 : -1, ads1014.readADC_Differential_0_1(), ads1014.readADC(0), ads1014.readADC(1));
// Serial1.println(ads1014.toVoltage(ads1014.readADC_Differential_0_1()), 5);
for (int i = 0; i < 10; i++)
Serial1.println(ads1014.getValue());
int dummy = 0;
uint32_t then = micros();
for (int i = 0; i < 1000; i++)
dummy += ads1014.getValue();
uint32_t now = micros();
Serial1.printf("1000 I2C readings take %d microseconds\n", now - then);
#endif #endif
for (int i = 0; i < 12; i++) for (int i = 0; i < 12; i++)
Serial1.printf("%u", digitalRead(inputPin[i])); Serial1.printf("%u", digitalRead(inputPin[i]));
Serial1.println(); Serial1.println();
delay(100); delay(1000);
} }
#endif #endif
} }