Merge branch 'EaserCAT-7000'

This commit is contained in:
Hakan Bastedt
2025-02-20 14:07:52 +01:00
93 changed files with 202190 additions and 11364 deletions

4
Cards/.gitignore vendored
View File

@@ -32,3 +32,7 @@ fp-info-cache
# Exported BOM files
*.xml
*.csv
*.step
*.stp
*.stl
.~lock.*

View File

@@ -37148,7 +37148,7 @@
(descr "Resistor SMD 0603 (1608 Metric), square (rectangular) end terminal, IPC_7351 nominal, (Body size source: IPC-SM-782 page 72, https://www.pcb-3d.com/wordpress/wp-content/uploads/ipc-sm-782a_amendment_1_and_2.pdf), generated with kicad-footprint-generator")
(tags "resistor")
(property "Reference" "R17"
(at 2.794 -2.032 0)
(at 2.667 0 0)
(layer "F.SilkS")
(uuid "8945efae-ad9c-4778-8c4a-99349011cd53")
(effects
@@ -39314,7 +39314,7 @@
(descr "Capacitor SMD 0603 (1608 Metric), square (rectangular) end terminal, IPC_7351 nominal, (Body size source: IPC-SM-782 page 76, https://www.pcb-3d.com/wordpress/wp-content/uploads/ipc-sm-782a_amendment_1_and_2.pdf), generated with kicad-footprint-generator")
(tags "capacitor")
(property "Reference" "C28"
(at -2.667 -2.032 180)
(at -2.667 0 180)
(layer "F.SilkS")
(uuid "86dc7c93-9ddb-4a93-9b73-ed6d70f07ef7")
(effects

View File

@@ -0,0 +1,139 @@
//
// !!! WARNING !!! AUTO-GENERATED FILE!
// PLEASE DO NOT MODIFY IT AND USE "platformio.ini":
// https://docs.platformio.org/page/projectconf/section_env_build.html#build-flags
//
{
"configurations": [
{
"name": "PlatformIO",
"includePath": [
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/include",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/src",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/lib/MyMCP3221",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/lib/soes-esi",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/lib/soes",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/.pio/libdeps/genericSTM32F407VGT6/ADS1X15",
"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/SPI/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/cores/arduino/avr",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/cores/arduino/stm32",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/SrcWrapper/inc",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/SrcWrapper/inc/LL",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/USBDevice/inc",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/VirtIO/inc",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/Drivers/STM32F4xx_HAL_Driver/Inc",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/Drivers/STM32F4xx_HAL_Driver/Src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/STM32F4xx",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/Middlewares/OpenAMP",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/Middlewares/OpenAMP/open-amp/lib/include",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/Middlewares/OpenAMP/libmetal/lib/include",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/Middlewares/OpenAMP/virtual_driver",
"C:/Users/Hakan/.platformio/packages/framework-cmsis/CMSIS/Core/Include",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/Drivers/CMSIS/Device/ST/STM32F4xx/Include",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc",
"C:/Users/Hakan/.platformio/packages/framework-cmsis/CMSIS/DSP/Include",
"C:/Users/Hakan/.platformio/packages/framework-cmsis/CMSIS/DSP/PrivateInclude",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/cores/arduino",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/variants/STM32F4xx/F407V(E-G)T_F417V(E-G)T",
"C:/Users/Hakan/.platformio/lib/RunningAverage",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/CMSIS_DSP/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/EEPROM/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/IWatchdog/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/Keyboard/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/Mouse/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/RGB_LED_TLC59731/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/Servo/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/SoftwareSerial/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/SrcWrapper/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/SubGhz/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/USBDevice/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/VirtIO/src",
""
],
"browse": {
"limitSymbolsToIncludedHeaders": true,
"path": [
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/include",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/src",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/lib/MyMCP3221",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/lib/soes-esi",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/lib/soes",
"Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/.pio/libdeps/genericSTM32F407VGT6/ADS1X15",
"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/SPI/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/cores/arduino/avr",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/cores/arduino/stm32",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/SrcWrapper/inc",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/SrcWrapper/inc/LL",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/USBDevice/inc",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/VirtIO/inc",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/Drivers/STM32F4xx_HAL_Driver/Inc",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/Drivers/STM32F4xx_HAL_Driver/Src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/STM32F4xx",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/Middlewares/OpenAMP",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/Middlewares/OpenAMP/open-amp/lib/include",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/Middlewares/OpenAMP/libmetal/lib/include",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/Middlewares/OpenAMP/virtual_driver",
"C:/Users/Hakan/.platformio/packages/framework-cmsis/CMSIS/Core/Include",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/Drivers/CMSIS/Device/ST/STM32F4xx/Include",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/system/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc",
"C:/Users/Hakan/.platformio/packages/framework-cmsis/CMSIS/DSP/Include",
"C:/Users/Hakan/.platformio/packages/framework-cmsis/CMSIS/DSP/PrivateInclude",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/cores/arduino",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/variants/STM32F4xx/F407V(E-G)T_F417V(E-G)T",
"C:/Users/Hakan/.platformio/lib/RunningAverage",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/CMSIS_DSP/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/EEPROM/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/IWatchdog/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/Keyboard/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/Mouse/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/RGB_LED_TLC59731/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/Servo/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/SoftwareSerial/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/SrcWrapper/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/SubGhz/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/USBDevice/src",
"C:/Users/Hakan/.platformio/packages/framework-arduinoststm32/libraries/VirtIO/src",
""
]
},
"defines": [
"PLATFORMIO=60117",
"STM32F407xx",
"STM32F4",
"ECAT",
"ADC_MCP3221",
"STM32F4xx",
"ARDUINO=10808",
"ARDUINO_ARCH_STM32",
"NDEBUG",
"ARDUINO_GENERIC_F407VGTX",
"BOARD_NAME=\"GENERIC_F407VGTX\"",
"HAL_UART_MODULE_ENABLED",
"USE_HAL_DRIVER",
"USE_FULL_LL_DRIVER",
"VARIANT_H=\"variant_generic.h\"",
"VECT_TAB_OFFSET=0x0",
""
],
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"compilerPath": "C:/Users/Hakan/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc.exe",
"compilerArgs": [
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
""
]
}
],
"version": 4
}

View File

@@ -0,0 +1,47 @@
// AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY
//
// PlatformIO Debugging Solution
//
// Documentation: https://docs.platformio.org/en/latest/plus/debugging.html
// Configuration: https://docs.platformio.org/en/latest/projectconf/sections/env/options/debug/index.html
{
"version": "0.2.0",
"configurations": [
{
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug",
"executable": "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/.pio/build/genericSTM32F407VGT6/firmware.elf",
"projectEnvName": "genericSTM32F407VGT6",
"toolchainBinDir": "C:/Users/Hakan/.platformio/packages/toolchain-gccarmnoneeabi/bin",
"internalConsoleOptions": "openOnSessionStart",
"svdPath": "C:/Users/Hakan/.platformio/platforms/ststm32/misc/svd/STM32F40x.svd",
"preLaunchTask": {
"type": "PlatformIO",
"task": "Pre-Debug"
}
},
{
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug (skip Pre-Debug)",
"executable": "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/.pio/build/genericSTM32F407VGT6/firmware.elf",
"projectEnvName": "genericSTM32F407VGT6",
"toolchainBinDir": "C:/Users/Hakan/.platformio/packages/toolchain-gccarmnoneeabi/bin",
"internalConsoleOptions": "openOnSessionStart",
"svdPath": "C:/Users/Hakan/.platformio/platforms/ststm32/misc/svd/STM32F40x.svd"
},
{
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug (without uploading)",
"executable": "Z:/src/MyOwnEtherCATDevice/Cards/EaserCAT-7000-DIO+I2C/Firmware/.pio/build/genericSTM32F407VGT6/firmware.elf",
"projectEnvName": "genericSTM32F407VGT6",
"toolchainBinDir": "C:/Users/Hakan/.platformio/packages/toolchain-gccarmnoneeabi/bin",
"internalConsoleOptions": "openOnSessionStart",
"svdPath": "C:/Users/Hakan/.platformio/platforms/ststm32/misc/svd/STM32F40x.svd",
"loadMode": "manual"
}
]
}

View File

@@ -0,0 +1,22 @@
{
"files.associations": {
"ecat_slv.h": "c",
"compare": "cpp",
"*.tpp": "cpp",
"*.tcc": "cpp",
"deque": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"system_error": "cpp",
"numeric": "cpp",
"ostream": "cpp",
"cmath": "cpp",
"cstddef": "cpp",
"array": "cpp",
"string_view": "cpp",
"initializer_list": "cpp"
},
"C_Cpp.errorSquiggles": "disabled",
"cmake.configureOnOpen": false
}

View File

@@ -0,0 +1,285 @@
/*==============================================================================================================*
@file MyMCP3221.cpp
@author Nadav Matalon
@license MIT (c) 2016 Nadav Matalon
MCP3221 Driver (12-BIT Single Channel ADC with I2C Interface)
Ver. 1.0.0 - First release (16.10.16)
*==============================================================================================================*
LICENSE
*==============================================================================================================*
The MIT License (MIT)
Copyright (c) 2016 Nadav Matalon
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without
limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*==============================================================================================================*/
#include "MyMCP3221.h"
/*==============================================================================================================*
CONSTRUCTOR
*==============================================================================================================*/
MyMCP3221::MyMCP3221(
byte devAddr,
TwoWire *Wire,
unsigned int vRef,
unsigned int res1,
unsigned int res2,
unsigned int alpha,
voltage_input_t voltageInput,
smoothing_t smoothingMethod,
byte numSamples) :
_Wire(Wire),
_devAddr(devAddr),
_vRef(vRef),
_alpha(alpha),
_voltageInput(voltageInput),
_smoothing(smoothingMethod),
_numSamples(numSamples)
{
memset(_samples, 0, sizeof(_samples));
if (((res1 != 0) && (res2 != 0)) && (_voltageInput == VOLTAGE_INPUT_12V)) {
_res1 = res1;
_res2 = res2;
} else if (_voltageInput == VOLTAGE_INPUT_5V) {
_res1 = 0;
_res2 = 0;
} else {
_res1 = DEFAULT_RES_1;
_res2 = DEFAULT_RES_2;
}
_comBuffer = COM_SUCCESS;
}
/*==============================================================================================================*
DESTRUCTOR
*==============================================================================================================*/
MyMCP3221::~MyMCP3221() {}
/*==============================================================================================================*
PING (0 = SUCCESS / 1, 2, ... = ERROR CODE)
*==============================================================================================================*/
// See meaning of I2C Error Code values in README
byte MyMCP3221::ping() {
_Wire->beginTransmission(_devAddr);
return _comBuffer = _Wire->endTransmission();
}
/*==============================================================================================================*
GET VOLTAGE REFERENCE (2700mV - 5500mV)
*==============================================================================================================*/
unsigned int MyMCP3221::getVref() {
return _vRef;
}
/*==============================================================================================================*
GET VOLTAGE DIVIDER RESISTOR 1 (Ω)
*==============================================================================================================*/
unsigned int MyMCP3221::getRes1() {
return _res1;
}
/*==============================================================================================================*
GET VOLTAGE DIVIDER RESISTOR 2 (Ω)
*==============================================================================================================*/
unsigned int MyMCP3221::getRes2() {
return _res2;
}
/*==============================================================================================================*
GET ALPHA (RELEVANT ONLY FOR EMAVG SMOOTHING METHOD, RANGE: 1 - 256)
*==============================================================================================================*/
unsigned int MyMCP3221::getAlpha() {
return _alpha;
}
/*==============================================================================================================*
GET NUMBER OF SAMPLES (RELEVANT ONLY FOR ROLLING-AVAREGE SMOOTHING METHOD, RANGE: 1-20 SAMPLES)
*==============================================================================================================*/
byte MyMCP3221::getNumSamples() {
return _numSamples;
}
/*==============================================================================================================*
GET VOLTAGE INPUT (0 = VOLTAGE_INPUT_5V / 1 = VOLTAGE_INPUT_12V)
*==============================================================================================================*/
byte MyMCP3221::getVinput() {
return _voltageInput;
}
/*==============================================================================================================*
GET SMOOTHING METHOD (0 = NONE / 1 = ROLLING-AVAREGE / 2 = EMAVG)
*==============================================================================================================*/
byte MyMCP3221::getSmoothing() {
return _smoothing;
}
/*==============================================================================================================*
GET DATA
*==============================================================================================================*/
unsigned int MyMCP3221::getData() {
return (_smoothing == NO_SMOOTHING) ? getRawData() : smoothData(getRawData());
}
/*==============================================================================================================*
GET VOLTAGE (Vref 4.096V: 2700 - 4096mV)
*==============================================================================================================*/
unsigned int MyMCP3221::getVoltage() {
if (_voltageInput == VOLTAGE_INPUT_5V) return round((_vRef / (float)DEFAULT_VREF) * getData());
else return round(getData() * ((float)(_res1 + _res2) / _res2));
}
/*==============================================================================================================*
GET LATEST I2C COMMUNICATION RESULT (0 = OK / 1, 2, ... = ERROR)
*==============================================================================================================*/
byte MyMCP3221::getComResult() {
return _comBuffer;
}
/*==============================================================================================================*
SET REFERENCE VOLTAGE (2700mV - 5500mV)
*==============================================================================================================*/
void MyMCP3221::setVref(unsigned int newVref) { // PARAM RANGE: 2700-5500
newVref = constrain(newVref, MIN_VREF, MAX_VREF);
_vRef = newVref;
}
/*==============================================================================================================*
SET VOLTAGE DIVIDER RESISTOR 1 (Ω)
*==============================================================================================================*/
void MyMCP3221::setRes1(unsigned int newRes1) {
_res1 = newRes1;
}
/*==============================================================================================================*
SET VOLTAGE DIVIDER RESISTOR 2 (Ω)
*==============================================================================================================*/
void MyMCP3221::setRes2(unsigned int newRes2) {
_res2 = newRes2;
}
/*==============================================================================================================*
SET ALPHA (RELEVANT ONLY FOR EMAVG SMOOTHING METHOD)
*==============================================================================================================*/
void MyMCP3221::setAlpha(unsigned int newAlpha) { // PARAM RANGE: 1-256
newAlpha = constrain(newAlpha, MIN_ALPHA, MAX_ALPHA);
_alpha = newAlpha;
}
/*==============================================================================================================*
SET NUMBER OF SAMPLES (RELEVANT ONLY FOR ROLLING-AVAREGE SMOOTHING METHOD)
*==============================================================================================================*/
void MyMCP3221::setNumSamples(byte newNumSamples) { // PARAM RANGE: 1-20
newNumSamples = constrain(newNumSamples, MIN_NUM_SAMPLES, MAX_NUM_SAMPLES);
_numSamples = newNumSamples;
for (byte i=0; i<MAX_NUM_SAMPLES; i++) _samples[i] = 0;
}
/*==============================================================================================================*
SET VOLTAGE INPUT (NOTE: 12V INPUT READINGS REQUIRE A HARDWARE VOLTAGE DIVIDER)
*==============================================================================================================*/
void MyMCP3221::setVinput(voltage_input_t newVoltageInput) { // PARAMS: VOLTAGE_INPUT_5V / VOLTAGE_INPUT_12V
_voltageInput = newVoltageInput;
if (newVoltageInput == VOLTAGE_INPUT_12V) {
if (!_res1) _res1 = DEFAULT_RES_1;
if (!_res2) _res2 = DEFAULT_RES_2;
}
}
/*==============================================================================================================*
SET SMOOTHING METHOD
*==============================================================================================================*/
void MyMCP3221::setSmoothing(smoothing_t newSmoothing) { // PARAMS: NO_SMOOTHING / ROLLING / EMAVG
_smoothing = newSmoothing;
}
/*==============================================================================================================*
RESET
*==============================================================================================================*/
void MyMCP3221::reset() {
setVref(DEFAULT_VREF);
setAlpha(DEFAULT_ALPHA);
setVinput(VOLTAGE_INPUT_5V);
setSmoothing(EMAVG);
setRes1(0);
setRes2(0);
setNumSamples(DEFAULT_NUM_SAMPLES);
}
/*==============================================================================================================*
GET RAW DATA
*==============================================================================================================*/
unsigned int MyMCP3221::getRawData() {
unsigned int rawData = 0;
_Wire->requestFrom(_devAddr, DATA_BYTES);
if (_Wire->available() == DATA_BYTES) rawData = (_Wire->read() << 8) | (_Wire->read());
else ping();
return rawData;
}
/*==============================================================================================================*
SMOOTH DATA
*==============================================================================================================*/
unsigned int MyMCP3221::smoothData(unsigned int rawData) {
unsigned int smoothedData;
if (_smoothing == EMAVG) { // Exmponential Moving Average
unsigned int emAvg = rawData;
emAvg = (_alpha * (unsigned long)rawData + (MAX_ALPHA - _alpha) * (unsigned long)emAvg) / MAX_ALPHA;
smoothedData = emAvg;
} else { // Rolling-Average
unsigned long sum = 0;
if (_samples[_numSamples - 1] != 0) {
for (byte i = 1; i<_numSamples; i++) _samples[i - 1] = _samples[i]; // drop last reading & rearrange array
_samples[_numSamples - 1] = rawData; // add a new sample at the end of array
for (byte j=0; j<_numSamples; j++) sum += _samples[j]; // aggregate all samples
smoothedData = sum / _numSamples; // calculate average
} else {
for (byte i = 0; i<_numSamples; i++) _samples[i] = rawData;
smoothedData = rawData;
}
}
return smoothedData;
}

View File

@@ -0,0 +1,207 @@
/*==============================================================================================================*
@file MyMCP3221.h
@author Nadav Matalon
@license MIT (c) 2016 Nadav Matalon
MCP3221 Driver (12-BIT Single Channel ADC with I2C Interface)
Ver. 1.0.0 - First release (16.10.16)
*===============================================================================================================*
INTRODUCTION
*===============================================================================================================*
The MCP3221 is a 12-Bit Single Channel ADC with hardware I2C interface.
This library contains a complete driver for the MCP3221 allowing the user to get raw conversion data,
smoothed conversion data (Rollong-Average or EMAVG), or voltage readings ranging 0-5V or 0-12V (the latter
requires a voltage divider setup).
*===============================================================================================================*
DEVICE HOOKUP
*===============================================================================================================*
MCP3221
-------
VCC --| • |-- SCL
| |
GND --| |
| |
AIN --| |-- SDA
-------
PIN 1 (VCC/VREF) - Serves as both Power Supply input and Voltage Reference for the ADC. Connect to the Arduino
5V Output or any other equivalent power source (5.5V max). If using an external power source,
remember to connect all GND's together
PIN 2 (GND) - connect to Arduino GND
PIN 3 (AIN) - Connect to Arduino's 3.3V Output or the middle pin of a 10K potentiometer (other two pins go to 5V & GND)
PIN 4 (SDA) - Connect to Arduino's PIN A4 with a 2K2 (400MHz I2C Bus speed) or 10K (100MHz I2C Bus speed) pull-up resistor
PIN 5 (SCL) - Connect to Arduino's PIN A5 with a 2K2 (400MHz I2C Bus speed) or 10K (100MHz I2C Bus speed) pull-up resistor
DECOUPING: Minimal decoupling consists of a 0.1uF Ceramic Capacitor between the VCC & GND PINS. For improved
performance, add a 1uF and a 10uF Ceramic Capacitors as well across these pins
*===============================================================================================================*
VOLTAGE DIVIDER HOOKUP (OPTIONAL: FOR 12V READINGS)
*===============================================================================================================*
12V
| MCP3221
| -------
R1 | | | |
| | | |
| AIN | |
|-----------| |
| | |
| | -------
R2 | |
|
|
GND
R1 - 10K Resistor
R2 - 4K7 Resistor
*===============================================================================================================*
I2C ADDRESSES
*===============================================================================================================*
Each MCP3221 has 1 of 8 possible I2C addresses (factory hardwired & recognized by its specific
part number & top marking on the package itself):
PART DEVICE I2C ADDRESS PART
NUMBER (BIN) (HEX) (DEC) MARKING
MCP3221A0T-E/OT 01001000 0x48 72 GE
MCP3221A1T-E/OT 01001001 0x49 73 GH
MCP3221A2T-E/OT 01001010 0x4A 74 GB
MCP3221A3T-E/OT 01001000 0x4B 75 GC
MCP3221A4T-E/OT 01001100 0x4C 76 GD
MCP3221A5T-E/OT 01001101 0x4D 77 GA
MCP3221A6T-E/OT 01001110 0x4E 78 GF
MCP3221A7T-E/OT 01001111 0x4F 79 GG
*===============================================================================================================*
DEVICE SETTING DEFAULTS
*===============================================================================================================*
VOLTAGE REFERENCE: 4096mV // this value is equal to the voltage fed to VCC
VOLTAGE INPUT: 5V // direct measurment of voltage at AIN pin (hw setup without voltage divider)
VOLTAGE DIVIDER RESISTOR 1: 0R // value used when measuring voltage of up to 12V at AIN pin
VOLTAGE DIVIDER RESISTOR 2: 0R // value used when measuring voltage of up to 12V at AIN pin
NUMBER OF SAMPLES: 10 // used by Rolling-Average smoothing method (range: 1-20 Samples)
ALPHA 178 // factor used by EMAVG smoothing method (range: 1-256)
*===============================================================================================================*
BUG REPORTS
*===============================================================================================================*
Please report any bugs/issues/suggestions at the Github Repo of this library at:
https://github.com/nadavmatalon/MCP3221
*===============================================================================================================*
LICENSE
*===============================================================================================================*
The MIT License (MIT)
Copyright (c) 2016 Nadav Matalon
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without
limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*==============================================================================================================*/
#ifndef MyMCP3221_h
#define MyMCP3221_h
#include <Arduino.h>
#include <Wire.h>
//#include "utility/MCP3221_PString.h"
namespace Mymcp3221 {
const byte DATA_BYTES = 2; // number of data bytes requested from the device
const byte MIN_CON_TIME = 15; // single conversion time with a small overhead (in uS)
const byte COM_SUCCESS = 0; // I2C communication success Code (No Error)
const unsigned int MIN_VREF = 2700; // minimum Voltage Reference value in mV (same as VCC)
const unsigned int MAX_VREF = 5500; // minimum Voltage Reference value in mV (same as VCC)
const unsigned int DEFAULT_VREF = 4096; // default Voltage Reference value in mV (same as VCC)
const unsigned int DEFAULT_RES_1 = 10000; // default Resistor 1 value (in Ω) of voltage divider for 12V readings
const unsigned int DEFAULT_RES_2 = 4700; // default Resistor 2 value (in Ω) of voltage divider for 12V readings
const unsigned int MIN_ALPHA = 1; // minimum value of alpha (slowest change) (for EMAVG)
const unsigned int MAX_ALPHA = 256; // maximum value of alpha (raw change/no filter) (for EMAVG)
const unsigned int DEFAULT_ALPHA = 178; // default value of alpha (for EMAVG)
const byte MIN_NUM_SAMPLES = 1; // minimum number of samples (for Rolling-Average smoothing)
const byte MAX_NUM_SAMPLES = 20; // maximum number of samples (for Rolling-Average smoothing)
const byte DEFAULT_NUM_SAMPLES = 10; // default number of samples (for Rolling-Average smoothing)
typedef enum:byte {
VOLTAGE_INPUT_5V = 0, // default
VOLTAGE_INPUT_12V = 1
} voltage_input_t;
typedef enum:byte {
NO_SMOOTHING = 0,
ROLLING_AVG = 1,
EMAVG = 2 // Default
} smoothing_t;
class MyMCP3221 {
public:
MyMCP3221(
byte devAddr,
TwoWire *Wire,
unsigned int vRef = DEFAULT_VREF,
unsigned int res1 = DEFAULT_RES_1,
unsigned int res2 = DEFAULT_RES_2,
unsigned int alpha = DEFAULT_ALPHA,
voltage_input_t voltageInput = VOLTAGE_INPUT_5V,
smoothing_t smoothingMethod = EMAVG,
byte numSamples = DEFAULT_NUM_SAMPLES
);
~MyMCP3221();
byte ping();
unsigned int getVref();
unsigned int getRes1();
unsigned int getRes2();
unsigned int getAlpha();
byte getNumSamples();
byte getVinput();
byte getSmoothing();
unsigned int getData();
unsigned int getVoltage();
byte getComResult();
void setVref(unsigned int newVref);
void setRes1(unsigned int newRes1);
void setRes2(unsigned int newRes2);
void setAlpha(unsigned int newAlpha);
void setNumSamples(byte newNumSamples);
void setVinput(voltage_input_t newVinput);
void setSmoothing(smoothing_t newSmoothing);
void reset();
private:
TwoWire *_Wire;
byte _devAddr, _voltageInput, _smoothing, _numSamples, _comBuffer;
unsigned int _vRef, _res1, _res2, _alpha;
unsigned int _samples[MAX_NUM_SAMPLES];
unsigned int getRawData();
unsigned int smoothData(unsigned int rawData);
// friend MyMCP3221_PString MyMCP3221ComStr(const MyMCP3221&);
// friend MyMCP3221_PString MyMCP3221InfoStr(const MyMCP3221&);
};
}
using namespace Mymcp3221;
#endif

View File

@@ -0,0 +1,954 @@
<?xml version="1.0" encoding="UTF-8"?>
<EtherCATInfo>
<Vendor>
<Id>3502166480</Id>
<Name LcId="1033">MetalMusings</Name>
</Vendor>
<Descriptions>
<Groups>
<Group>
<Type>MachineControl</Type>
<Name LcId="1033">Plasma cutter</Name>
</Group>
</Groups>
<Devices>
<Device Physics="YY ">
<Type ProductCode="#x7000" RevisionNo="#x2">EaserCAT 7000</Type>
<Name LcId="1033">MetalMusings EaserCAT 7000</Name>
<GroupType>MachineControl</GroupType>
<Profile>
<ProfileNo>5001</ProfileNo>
<AddInfo>0</AddInfo>
<Dictionary>
<DataTypes>
<DataType>
<Name>DT1018</Name>
<BitSize>144</BitSize>
<SubItem>
<SubIdx>0</SubIdx>
<Name>Max SubIndex</Name>
<Type>USINT</Type>
<BitSize>8</BitSize>
<BitOffs>0</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
<SubItem>
<SubIdx>1</SubIdx>
<Name>Vendor ID</Name>
<Type>UDINT</Type>
<BitSize>32</BitSize>
<BitOffs>16</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
<SubItem>
<SubIdx>2</SubIdx>
<Name>Product Code</Name>
<Type>UDINT</Type>
<BitSize>32</BitSize>
<BitOffs>48</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
<SubItem>
<SubIdx>3</SubIdx>
<Name>Revision Number</Name>
<Type>UDINT</Type>
<BitSize>32</BitSize>
<BitOffs>80</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
<SubItem>
<SubIdx>4</SubIdx>
<Name>Serial Number</Name>
<Type>UDINT</Type>
<BitSize>32</BitSize>
<BitOffs>112</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
</DataType>
<DataType>
<Name>DT1600</Name>
<BitSize>48</BitSize>
<SubItem>
<SubIdx>0</SubIdx>
<Name>Max SubIndex</Name>
<Type>USINT</Type>
<BitSize>8</BitSize>
<BitOffs>0</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
<SubItem>
<SubIdx>1</SubIdx>
<Name>Output4</Name>
<Type>UDINT</Type>
<BitSize>32</BitSize>
<BitOffs>16</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
</DataType>
<DataType>
<Name>DT1601</Name>
<BitSize>48</BitSize>
<SubItem>
<SubIdx>0</SubIdx>
<Name>Max SubIndex</Name>
<Type>USINT</Type>
<BitSize>8</BitSize>
<BitOffs>0</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
<SubItem>
<SubIdx>1</SubIdx>
<Name>VoltageScale</Name>
<Type>UDINT</Type>
<BitSize>32</BitSize>
<BitOffs>16</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
</DataType>
<DataType>
<Name>DT1602</Name>
<BitSize>48</BitSize>
<SubItem>
<SubIdx>0</SubIdx>
<Name>Max SubIndex</Name>
<Type>USINT</Type>
<BitSize>8</BitSize>
<BitOffs>0</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
<SubItem>
<SubIdx>1</SubIdx>
<Name>VoltageOffset</Name>
<Type>UDINT</Type>
<BitSize>32</BitSize>
<BitOffs>16</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
</DataType>
<DataType>
<Name>DT1A00</Name>
<BitSize>48</BitSize>
<SubItem>
<SubIdx>0</SubIdx>
<Name>Max SubIndex</Name>
<Type>USINT</Type>
<BitSize>8</BitSize>
<BitOffs>0</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
<SubItem>
<SubIdx>1</SubIdx>
<Name>Input12</Name>
<Type>UDINT</Type>
<BitSize>32</BitSize>
<BitOffs>16</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
</DataType>
<DataType>
<Name>DT1A01</Name>
<BitSize>48</BitSize>
<SubItem>
<SubIdx>0</SubIdx>
<Name>Max SubIndex</Name>
<Type>USINT</Type>
<BitSize>8</BitSize>
<BitOffs>0</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
<SubItem>
<SubIdx>1</SubIdx>
<Name>RawData</Name>
<Type>UDINT</Type>
<BitSize>32</BitSize>
<BitOffs>16</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
</DataType>
<DataType>
<Name>DT1A02</Name>
<BitSize>48</BitSize>
<SubItem>
<SubIdx>0</SubIdx>
<Name>Max SubIndex</Name>
<Type>USINT</Type>
<BitSize>8</BitSize>
<BitOffs>0</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
<SubItem>
<SubIdx>1</SubIdx>
<Name>CalculatedVoltage</Name>
<Type>UDINT</Type>
<BitSize>32</BitSize>
<BitOffs>16</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
</DataType>
<DataType>
<Name>DT1A03</Name>
<BitSize>48</BitSize>
<SubItem>
<SubIdx>0</SubIdx>
<Name>Max SubIndex</Name>
<Type>USINT</Type>
<BitSize>8</BitSize>
<BitOffs>0</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
<SubItem>
<SubIdx>1</SubIdx>
<Name>Status</Name>
<Type>UDINT</Type>
<BitSize>32</BitSize>
<BitOffs>16</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
</DataType>
<DataType>
<Name>DT1C00ARR</Name>
<BaseType>USINT</BaseType>
<BitSize>32</BitSize>
<ArrayInfo>
<LBound>1</LBound>
<Elements>4</Elements>
</ArrayInfo>
</DataType>
<DataType>
<Name>DT1C00</Name>
<BitSize>48</BitSize>
<SubItem>
<SubIdx>0</SubIdx>
<Name>Max SubIndex</Name>
<Type>USINT</Type>
<BitSize>8</BitSize>
<BitOffs>0</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
<SubItem>
<Name>Elements</Name>
<Type>DT1C00ARR</Type>
<BitSize>32</BitSize>
<BitOffs>16</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
</DataType>
<DataType>
<Name>DT1C12ARR</Name>
<BaseType>UINT</BaseType>
<BitSize>48</BitSize>
<ArrayInfo>
<LBound>1</LBound>
<Elements>3</Elements>
</ArrayInfo>
</DataType>
<DataType>
<Name>DT1C12</Name>
<BitSize>64</BitSize>
<SubItem>
<SubIdx>0</SubIdx>
<Name>Max SubIndex</Name>
<Type>USINT</Type>
<BitSize>8</BitSize>
<BitOffs>0</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
<SubItem>
<Name>Elements</Name>
<Type>DT1C12ARR</Type>
<BitSize>48</BitSize>
<BitOffs>16</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
</DataType>
<DataType>
<Name>DT1C13ARR</Name>
<BaseType>UINT</BaseType>
<BitSize>64</BitSize>
<ArrayInfo>
<LBound>1</LBound>
<Elements>4</Elements>
</ArrayInfo>
</DataType>
<DataType>
<Name>DT1C13</Name>
<BitSize>80</BitSize>
<SubItem>
<SubIdx>0</SubIdx>
<Name>Max SubIndex</Name>
<Type>USINT</Type>
<BitSize>8</BitSize>
<BitOffs>0</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
<SubItem>
<Name>Elements</Name>
<Type>DT1C13ARR</Type>
<BitSize>64</BitSize>
<BitOffs>16</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
</DataType>
<DataType>
<Name>UDINT</Name>
<BitSize>32</BitSize>
</DataType>
<DataType>
<Name>STRING(26)</Name>
<BitSize>208</BitSize>
</DataType>
<DataType>
<Name>STRING(5)</Name>
<BitSize>40</BitSize>
</DataType>
<DataType>
<Name>USINT</Name>
<BitSize>8</BitSize>
</DataType>
<DataType>
<Name>UINT</Name>
<BitSize>16</BitSize>
</DataType>
<DataType>
<Name>DINT</Name>
<BitSize>32</BitSize>
</DataType>
<DataType>
<Name>REAL</Name>
<BitSize>32</BitSize>
</DataType>
</DataTypes>
<Objects>
<Object>
<Index>#x1000</Index>
<Name>Device Type</Name>
<Type>UDINT</Type>
<BitSize>32</BitSize>
<Info>
<DefaultValue>5001</DefaultValue>
</Info>
<Flags>
<Access>ro</Access>
<Category>m</Category>
</Flags>
</Object>
<Object>
<Index>#x1008</Index>
<Name>Device Name</Name>
<Type>STRING(26)</Type>
<BitSize>208</BitSize>
<Info>
<DefaultString>MetalMusings EaserCAT 7000</DefaultString>
</Info>
<Flags>
<Access>ro</Access>
</Flags>
</Object>
<Object>
<Index>#x1009</Index>
<Name>Hardware Version</Name>
<Type>STRING(5)</Type>
<BitSize>40</BitSize>
<Info>
<DefaultString>0.0.1</DefaultString>
</Info>
<Flags>
<Access>ro</Access>
<Category>o</Category>
</Flags>
</Object>
<Object>
<Index>#x100A</Index>
<Name>Software Version</Name>
<Type>STRING(5)</Type>
<BitSize>40</BitSize>
<Info>
<DefaultString>0.0.1</DefaultString>
</Info>
<Flags>
<Access>ro</Access>
</Flags>
</Object>
<Object>
<Index>#x1018</Index>
<Name>Identity Object</Name>
<Type>DT1018</Type>
<BitSize>144</BitSize>
<Info>
<SubItem>
<Name>Max SubIndex</Name>
<Info>
<DefaultValue>4</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>Vendor ID</Name>
<Info>
<DefaultValue>3502166480</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>Product Code</Name>
<Info>
<DefaultValue>28672</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>Revision Number</Name>
<Info>
<DefaultValue>2</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>Serial Number</Name>
<Info>
<DefaultValue>1</DefaultValue>
</Info>
</SubItem>
</Info>
<Flags>
</Flags>
</Object>
<Object>
<Index>#x1600</Index>
<Name>Output4</Name>
<Type>DT1600</Type>
<BitSize>48</BitSize>
<Info>
<SubItem>
<Name>Max SubIndex</Name>
<Info>
<DefaultValue>1</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>Output4</Name>
<Info>
<DefaultValue>#x70000008</DefaultValue>
</Info>
</SubItem>
</Info>
<Flags>
</Flags>
</Object>
<Object>
<Index>#x1601</Index>
<Name>VoltageScale</Name>
<Type>DT1601</Type>
<BitSize>48</BitSize>
<Info>
<SubItem>
<Name>Max SubIndex</Name>
<Info>
<DefaultValue>1</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>VoltageScale</Name>
<Info>
<DefaultValue>#x70010020</DefaultValue>
</Info>
</SubItem>
</Info>
<Flags>
</Flags>
</Object>
<Object>
<Index>#x1602</Index>
<Name>VoltageOffset</Name>
<Type>DT1602</Type>
<BitSize>48</BitSize>
<Info>
<SubItem>
<Name>Max SubIndex</Name>
<Info>
<DefaultValue>1</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>VoltageOffset</Name>
<Info>
<DefaultValue>#x70020020</DefaultValue>
</Info>
</SubItem>
</Info>
<Flags>
</Flags>
</Object>
<Object>
<Index>#x1A00</Index>
<Name>Input12</Name>
<Type>DT1A00</Type>
<BitSize>48</BitSize>
<Info>
<SubItem>
<Name>Max SubIndex</Name>
<Info>
<DefaultValue>1</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>Input12</Name>
<Info>
<DefaultValue>#x60000020</DefaultValue>
</Info>
</SubItem>
</Info>
<Flags>
</Flags>
</Object>
<Object>
<Index>#x1A01</Index>
<Name>RawData</Name>
<Type>DT1A01</Type>
<BitSize>48</BitSize>
<Info>
<SubItem>
<Name>Max SubIndex</Name>
<Info>
<DefaultValue>1</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>RawData</Name>
<Info>
<DefaultValue>#x60010020</DefaultValue>
</Info>
</SubItem>
</Info>
<Flags>
</Flags>
</Object>
<Object>
<Index>#x1A02</Index>
<Name>CalculatedVoltage</Name>
<Type>DT1A02</Type>
<BitSize>48</BitSize>
<Info>
<SubItem>
<Name>Max SubIndex</Name>
<Info>
<DefaultValue>1</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>CalculatedVoltage</Name>
<Info>
<DefaultValue>#x60020020</DefaultValue>
</Info>
</SubItem>
</Info>
<Flags>
</Flags>
</Object>
<Object>
<Index>#x1A03</Index>
<Name>Status</Name>
<Type>DT1A03</Type>
<BitSize>48</BitSize>
<Info>
<SubItem>
<Name>Max SubIndex</Name>
<Info>
<DefaultValue>1</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>Status</Name>
<Info>
<DefaultValue>#x60030008</DefaultValue>
</Info>
</SubItem>
</Info>
<Flags>
</Flags>
</Object>
<Object>
<Index>#x1C00</Index>
<Name>Sync Manager Communication Type</Name>
<Type>DT1C00</Type>
<BitSize>48</BitSize>
<Info>
<SubItem>
<Name>Max SubIndex</Name>
<Info>
<DefaultValue>4</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>Communications Type SM0</Name>
<Info>
<DefaultValue>1</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>Communications Type SM1</Name>
<Info>
<DefaultValue>2</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>Communications Type SM2</Name>
<Info>
<DefaultValue>3</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>Communications Type SM3</Name>
<Info>
<DefaultValue>4</DefaultValue>
</Info>
</SubItem>
</Info>
<Flags>
</Flags>
</Object>
<Object>
<Index>#x1C12</Index>
<Name>Sync Manager 2 PDO Assignment</Name>
<Type>DT1C12</Type>
<BitSize>64</BitSize>
<Info>
<SubItem>
<Name>Max SubIndex</Name>
<Info>
<DefaultValue>3</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>PDO Mapping</Name>
<Info>
<DefaultValue>#x1600</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>PDO Mapping</Name>
<Info>
<DefaultValue>#x1601</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>PDO Mapping</Name>
<Info>
<DefaultValue>#x1602</DefaultValue>
</Info>
</SubItem>
</Info>
<Flags>
</Flags>
</Object>
<Object>
<Index>#x1C13</Index>
<Name>Sync Manager 3 PDO Assignment</Name>
<Type>DT1C13</Type>
<BitSize>80</BitSize>
<Info>
<SubItem>
<Name>Max SubIndex</Name>
<Info>
<DefaultValue>4</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>PDO Mapping</Name>
<Info>
<DefaultValue>#x1A00</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>PDO Mapping</Name>
<Info>
<DefaultValue>#x1A01</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>PDO Mapping</Name>
<Info>
<DefaultValue>#x1A02</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>PDO Mapping</Name>
<Info>
<DefaultValue>#x1A03</DefaultValue>
</Info>
</SubItem>
</Info>
<Flags>
</Flags>
</Object>
<Object>
<Index>#x2000</Index>
<Name>I2C_devicetype</Name>
<Type>USINT</Type>
<BitSize>8</BitSize>
<Info>
<DefaultValue>0</DefaultValue>
</Info>
<Flags>
<Access>rw</Access>
</Flags>
</Object>
<Object>
<Index>#x2001</Index>
<Name>I2C_address</Name>
<Type>USINT</Type>
<BitSize>8</BitSize>
<Info>
<DefaultValue>0</DefaultValue>
</Info>
<Flags>
<Access>rw</Access>
</Flags>
</Object>
<Object>
<Index>#x6000</Index>
<Name>Input12</Name>
<Type>DINT</Type>
<BitSize>32</BitSize>
<Info>
<DefaultValue>0</DefaultValue>
</Info>
<Flags>
<Access>ro</Access>
<PdoMapping>T</PdoMapping>
</Flags>
</Object>
<Object>
<Index>#x6001</Index>
<Name>RawData</Name>
<Type>DINT</Type>
<BitSize>32</BitSize>
<Info>
<DefaultValue>0</DefaultValue>
</Info>
<Flags>
<Access>ro</Access>
<PdoMapping>T</PdoMapping>
</Flags>
</Object>
<Object>
<Index>#x6002</Index>
<Name>CalculatedVoltage</Name>
<Type>REAL</Type>
<BitSize>32</BitSize>
<Info>
<DefaultValue>0</DefaultValue>
</Info>
<Flags>
<Access>ro</Access>
<PdoMapping>T</PdoMapping>
</Flags>
</Object>
<Object>
<Index>#x6003</Index>
<Name>Status</Name>
<Type>USINT</Type>
<BitSize>8</BitSize>
<Info>
<DefaultValue>0</DefaultValue>
</Info>
<Flags>
<Access>ro</Access>
<PdoMapping>T</PdoMapping>
</Flags>
</Object>
<Object>
<Index>#x7000</Index>
<Name>Output4</Name>
<Type>USINT</Type>
<BitSize>8</BitSize>
<Info>
<DefaultValue>0</DefaultValue>
</Info>
<Flags>
<Access>ro</Access>
<PdoMapping>R</PdoMapping>
</Flags>
</Object>
<Object>
<Index>#x7001</Index>
<Name>VoltageScale</Name>
<Type>REAL</Type>
<BitSize>32</BitSize>
<Info>
<DefaultValue>0</DefaultValue>
</Info>
<Flags>
<Access>ro</Access>
<PdoMapping>R</PdoMapping>
</Flags>
</Object>
<Object>
<Index>#x7002</Index>
<Name>VoltageOffset</Name>
<Type>REAL</Type>
<BitSize>32</BitSize>
<Info>
<DefaultValue>0</DefaultValue>
</Info>
<Flags>
<Access>ro</Access>
<PdoMapping>R</PdoMapping>
</Flags>
</Object>
</Objects>
</Dictionary>
</Profile>
<Fmmu>Outputs</Fmmu>
<Fmmu>Inputs</Fmmu>
<Fmmu>MBoxState</Fmmu>
<Sm DefaultSize="512" StartAddress="#x1000" ControlByte="#x26" Enable="1">MBoxOut</Sm>
<Sm DefaultSize="512" StartAddress="#x1200" ControlByte="#x22" Enable="1">MBoxIn</Sm>
<Sm StartAddress="#x1600" ControlByte="#x24" Enable="1">Outputs</Sm>
<Sm StartAddress="#x1A00" ControlByte="#x20" Enable="1">Inputs</Sm>
<RxPdo Fixed="true" Mandatory="true" Sm="2">
<Index>#x1600</Index>
<Name>Output4</Name>
<Entry>
<Index>#x7000</Index>
<SubIndex>#x0</SubIndex>
<BitLen>8</BitLen>
<Name>Output4</Name>
<DataType>USINT</DataType>
</Entry>
</RxPdo>
<RxPdo Fixed="true" Mandatory="true" Sm="2">
<Index>#x1601</Index>
<Name>VoltageScale</Name>
<Entry>
<Index>#x7001</Index>
<SubIndex>#x0</SubIndex>
<BitLen>32</BitLen>
<Name>VoltageScale</Name>
<DataType>REAL</DataType>
</Entry>
</RxPdo>
<RxPdo Fixed="true" Mandatory="true" Sm="2">
<Index>#x1602</Index>
<Name>VoltageOffset</Name>
<Entry>
<Index>#x7002</Index>
<SubIndex>#x0</SubIndex>
<BitLen>32</BitLen>
<Name>VoltageOffset</Name>
<DataType>REAL</DataType>
</Entry>
</RxPdo>
<TxPdo Fixed="true" Mandatory="true" Sm="3">
<Index>#x1A00</Index>
<Name>Input12</Name>
<Entry>
<Index>#x6000</Index>
<SubIndex>#x0</SubIndex>
<BitLen>32</BitLen>
<Name>Input12</Name>
<DataType>DINT</DataType>
</Entry>
</TxPdo>
<TxPdo Fixed="true" Mandatory="true" Sm="3">
<Index>#x1A01</Index>
<Name>RawData</Name>
<Entry>
<Index>#x6001</Index>
<SubIndex>#x0</SubIndex>
<BitLen>32</BitLen>
<Name>RawData</Name>
<DataType>DINT</DataType>
</Entry>
</TxPdo>
<TxPdo Fixed="true" Mandatory="true" Sm="3">
<Index>#x1A02</Index>
<Name>CalculatedVoltage</Name>
<Entry>
<Index>#x6002</Index>
<SubIndex>#x0</SubIndex>
<BitLen>32</BitLen>
<Name>CalculatedVoltage</Name>
<DataType>REAL</DataType>
</Entry>
</TxPdo>
<TxPdo Fixed="true" Mandatory="true" Sm="3">
<Index>#x1A03</Index>
<Name>Status</Name>
<Entry>
<Index>#x6003</Index>
<SubIndex>#x0</SubIndex>
<BitLen>8</BitLen>
<Name>Status</Name>
<DataType>USINT</DataType>
</Entry>
</TxPdo>
<Mailbox DataLinkLayer="true">
<CoE SdoInfo="true" PdoAssign="false" PdoConfig="false" PdoUpload="true" CompleteAccess="false" />
</Mailbox>
<Dc>
<OpMode>
<Name>SM-Synchron</Name>
<Desc>SM-Synchron</Desc>
<AssignActivate>#x000</AssignActivate>
</OpMode>
<OpMode>
<Name>DC</Name>
<Desc>DC-Synchron</Desc>
<AssignActivate>#x300</AssignActivate>
</OpMode>
</Dc>
<Eeprom>
<ByteSize>2048</ByteSize>
<ConfigData>80060344640000</ConfigData>
</Eeprom>
</Device>
</Devices>
</Descriptions>
</EtherCATInfo>

View File

@@ -33,8 +33,8 @@
#define SM3_smc 0x20
#define SM3_act 1
#define MAX_MAPPINGS_SM2 1
#define MAX_MAPPINGS_SM3 3
#define MAX_MAPPINGS_SM2 3
#define MAX_MAPPINGS_SM3 4
#define MAX_RXPDO_SIZE 512
#define MAX_TXPDO_SIZE 512

View File

@@ -36,12 +36,21 @@
"sdo": {
"2000": {
"otype": "VAR",
"name": "VoltageScale",
"access": "RO",
"dtype": "REAL32",
"value": "1",
"name": "I2C_devicetype",
"access": "RW",
"dtype": "UNSIGNED8",
"value": "0",
"isSDOitem": true,
"data": "&Obj.VoltageScale"
"data": "&Obj.I2C_devicetype"
},
"2001": {
"otype": "VAR",
"name": "I2C_address",
"access": "RW",
"dtype": "UNSIGNED8",
"value": "0",
"isSDOitem": true,
"data": "&Obj.I2C_address"
},
"A": {
"otype": "RECORD",
@@ -83,25 +92,36 @@
},
"6001": {
"otype": "VAR",
"name": "ArcVoltage",
"name": "RawData",
"access": "RO",
"pdo_mappings": [
"txpdo"
],
"dtype": "REAL32",
"dtype": "INTEGER32",
"value": "0",
"data": "&Obj.ArcVoltage"
"data": "&Obj.RawData"
},
"6002": {
"otype": "VAR",
"name": "Voltage",
"name": "CalculatedVoltage",
"access": "RO",
"pdo_mappings": [
"txpdo"
],
"dtype": "REAL32",
"value": "0",
"data": "&Obj.Voltage"
"data": "&Obj.CalculatedVoltage"
},
"6003": {
"otype": "VAR",
"name": "Status",
"access": "RO",
"pdo_mappings": [
"txpdo"
],
"dtype": "UNSIGNED8",
"value": "0",
"data": "&Obj.Status"
}
},
"rxpdo": {
@@ -116,6 +136,28 @@
"value": "0",
"data": "&Obj.Output4"
},
"7001": {
"otype": "VAR",
"name": "VoltageScale",
"access": "RO",
"pdo_mappings": [
"rxpdo"
],
"dtype": "REAL32",
"value": "0",
"data": "&Obj.VoltageScale"
},
"7002": {
"otype": "VAR",
"name": "VoltageOffset",
"access": "RO",
"pdo_mappings": [
"rxpdo"
],
"dtype": "REAL32",
"value": "0",
"data": "&Obj.VoltageOffset"
},
"60664": {
"otype": "VAR",
"name": "ActualPosition",

View File

@@ -16,15 +16,24 @@ static const char acName1018_04[] = "Serial Number";
static const char acName1600[] = "Output4";
static const char acName1600_00[] = "Max SubIndex";
static const char acName1600_01[] = "Output4";
static const char acName1601[] = "VoltageScale";
static const char acName1601_00[] = "Max SubIndex";
static const char acName1601_01[] = "VoltageScale";
static const char acName1602[] = "VoltageOffset";
static const char acName1602_00[] = "Max SubIndex";
static const char acName1602_01[] = "VoltageOffset";
static const char acName1A00[] = "Input12";
static const char acName1A00_00[] = "Max SubIndex";
static const char acName1A00_01[] = "Input12";
static const char acName1A01[] = "ArcVoltage";
static const char acName1A01[] = "RawData";
static const char acName1A01_00[] = "Max SubIndex";
static const char acName1A01_01[] = "ArcVoltage";
static const char acName1A02[] = "Voltage";
static const char acName1A01_01[] = "RawData";
static const char acName1A02[] = "CalculatedVoltage";
static const char acName1A02_00[] = "Max SubIndex";
static const char acName1A02_01[] = "Voltage";
static const char acName1A02_01[] = "CalculatedVoltage";
static const char acName1A03[] = "Status";
static const char acName1A03_00[] = "Max SubIndex";
static const char acName1A03_01[] = "Status";
static const char acName1C00[] = "Sync Manager Communication Type";
static const char acName1C00_00[] = "Max SubIndex";
static const char acName1C00_01[] = "Communications Type SM0";
@@ -34,16 +43,23 @@ static const char acName1C00_04[] = "Communications Type SM3";
static const char acName1C12[] = "Sync Manager 2 PDO Assignment";
static const char acName1C12_00[] = "Max SubIndex";
static const char acName1C12_01[] = "PDO Mapping";
static const char acName1C12_02[] = "PDO Mapping";
static const char acName1C12_03[] = "PDO Mapping";
static const char acName1C13[] = "Sync Manager 3 PDO Assignment";
static const char acName1C13_00[] = "Max SubIndex";
static const char acName1C13_01[] = "PDO Mapping";
static const char acName1C13_02[] = "PDO Mapping";
static const char acName1C13_03[] = "PDO Mapping";
static const char acName2000[] = "VoltageScale";
static const char acName1C13_04[] = "PDO Mapping";
static const char acName2000[] = "I2C_devicetype";
static const char acName2001[] = "I2C_address";
static const char acName6000[] = "Input12";
static const char acName6001[] = "ArcVoltage";
static const char acName6002[] = "Voltage";
static const char acName6001[] = "RawData";
static const char acName6002[] = "CalculatedVoltage";
static const char acName6003[] = "Status";
static const char acName7000[] = "Output4";
static const char acName7001[] = "VoltageScale";
static const char acName7002[] = "VoltageOffset";
const _objd SDO1000[] =
{
@@ -74,6 +90,16 @@ const _objd SDO1600[] =
{0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName1600_00, 1, NULL},
{0x01, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1600_01, 0x70000008, NULL},
};
const _objd SDO1601[] =
{
{0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName1601_00, 1, NULL},
{0x01, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1601_01, 0x70010020, NULL},
};
const _objd SDO1602[] =
{
{0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName1602_00, 1, NULL},
{0x01, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1602_01, 0x70020020, NULL},
};
const _objd SDO1A00[] =
{
{0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName1A00_00, 1, NULL},
@@ -89,6 +115,11 @@ const _objd SDO1A02[] =
{0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName1A02_00, 1, NULL},
{0x01, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1A02_01, 0x60020020, NULL},
};
const _objd SDO1A03[] =
{
{0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName1A03_00, 1, NULL},
{0x01, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1A03_01, 0x60030008, NULL},
};
const _objd SDO1C00[] =
{
{0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName1C00_00, 4, NULL},
@@ -99,19 +130,26 @@ const _objd SDO1C00[] =
};
const _objd SDO1C12[] =
{
{0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName1C12_00, 1, NULL},
{0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName1C12_00, 3, NULL},
{0x01, DTYPE_UNSIGNED16, 16, ATYPE_RO, acName1C12_01, 0x1600, NULL},
{0x02, DTYPE_UNSIGNED16, 16, ATYPE_RO, acName1C12_02, 0x1601, NULL},
{0x03, DTYPE_UNSIGNED16, 16, ATYPE_RO, acName1C12_03, 0x1602, NULL},
};
const _objd SDO1C13[] =
{
{0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName1C13_00, 3, NULL},
{0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName1C13_00, 4, NULL},
{0x01, DTYPE_UNSIGNED16, 16, ATYPE_RO, acName1C13_01, 0x1A00, NULL},
{0x02, DTYPE_UNSIGNED16, 16, ATYPE_RO, acName1C13_02, 0x1A01, NULL},
{0x03, DTYPE_UNSIGNED16, 16, ATYPE_RO, acName1C13_03, 0x1A02, NULL},
{0x04, DTYPE_UNSIGNED16, 16, ATYPE_RO, acName1C13_04, 0x1A03, NULL},
};
const _objd SDO2000[] =
{
{0x0, DTYPE_REAL32, 32, ATYPE_RO, acName2000, 0x3f800000, &Obj.VoltageScale},
{0x0, DTYPE_UNSIGNED8, 8, ATYPE_RW, acName2000, 0, &Obj.I2C_devicetype},
};
const _objd SDO2001[] =
{
{0x0, DTYPE_UNSIGNED8, 8, ATYPE_RW, acName2001, 0, &Obj.I2C_address},
};
const _objd SDO6000[] =
{
@@ -119,16 +157,28 @@ const _objd SDO6000[] =
};
const _objd SDO6001[] =
{
{0x0, DTYPE_REAL32, 32, ATYPE_RO | ATYPE_TXPDO, acName6001, 0x00000000, &Obj.ArcVoltage},
{0x0, DTYPE_INTEGER32, 32, ATYPE_RO | ATYPE_TXPDO, acName6001, 0, &Obj.RawData},
};
const _objd SDO6002[] =
{
{0x0, DTYPE_REAL32, 32, ATYPE_RO | ATYPE_TXPDO, acName6002, 0x00000000, &Obj.Voltage},
{0x0, DTYPE_REAL32, 32, ATYPE_RO | ATYPE_TXPDO, acName6002, 0x00000000, &Obj.CalculatedVoltage},
};
const _objd SDO6003[] =
{
{0x0, DTYPE_UNSIGNED8, 8, ATYPE_RO | ATYPE_TXPDO, acName6003, 0, &Obj.Status},
};
const _objd SDO7000[] =
{
{0x0, DTYPE_UNSIGNED8, 8, ATYPE_RO | ATYPE_RXPDO, acName7000, 0, &Obj.Output4},
};
const _objd SDO7001[] =
{
{0x0, DTYPE_REAL32, 32, ATYPE_RO | ATYPE_RXPDO, acName7001, 0x00000000, &Obj.VoltageScale},
};
const _objd SDO7002[] =
{
{0x0, DTYPE_REAL32, 32, ATYPE_RO | ATYPE_RXPDO, acName7002, 0x00000000, &Obj.VoltageOffset},
};
const _objectlist SDOobjects[] =
{
@@ -138,16 +188,23 @@ const _objectlist SDOobjects[] =
{0x100A, OTYPE_VAR, 0, 0, acName100A, SDO100A},
{0x1018, OTYPE_RECORD, 4, 0, acName1018, SDO1018},
{0x1600, OTYPE_RECORD, 1, 0, acName1600, SDO1600},
{0x1601, OTYPE_RECORD, 1, 0, acName1601, SDO1601},
{0x1602, OTYPE_RECORD, 1, 0, acName1602, SDO1602},
{0x1A00, OTYPE_RECORD, 1, 0, acName1A00, SDO1A00},
{0x1A01, OTYPE_RECORD, 1, 0, acName1A01, SDO1A01},
{0x1A02, OTYPE_RECORD, 1, 0, acName1A02, SDO1A02},
{0x1A03, OTYPE_RECORD, 1, 0, acName1A03, SDO1A03},
{0x1C00, OTYPE_ARRAY, 4, 0, acName1C00, SDO1C00},
{0x1C12, OTYPE_ARRAY, 1, 0, acName1C12, SDO1C12},
{0x1C13, OTYPE_ARRAY, 3, 0, acName1C13, SDO1C13},
{0x1C12, OTYPE_ARRAY, 3, 0, acName1C12, SDO1C12},
{0x1C13, OTYPE_ARRAY, 4, 0, acName1C13, SDO1C13},
{0x2000, OTYPE_VAR, 0, 0, acName2000, SDO2000},
{0x2001, OTYPE_VAR, 0, 0, acName2001, SDO2001},
{0x6000, OTYPE_VAR, 0, 0, acName6000, SDO6000},
{0x6001, OTYPE_VAR, 0, 0, acName6001, SDO6001},
{0x6002, OTYPE_VAR, 0, 0, acName6002, SDO6002},
{0x6003, OTYPE_VAR, 0, 0, acName6003, SDO6003},
{0x7000, OTYPE_VAR, 0, 0, acName7000, SDO7000},
{0x7001, OTYPE_VAR, 0, 0, acName7001, SDO7001},
{0x7002, OTYPE_VAR, 0, 0, acName7002, SDO7002},
{0xffff, 0xff, 0xff, 0xff, NULL, NULL}
};

View File

@@ -14,16 +14,20 @@ typedef struct
/* Inputs */
int32_t Input12;
float ArcVoltage;
float Voltage;
int32_t RawData;
float CalculatedVoltage;
uint8_t Status;
/* Outputs */
uint8_t Output4;
float VoltageScale;
float VoltageOffset;
/* Parameters */
float VoltageScale;
uint8_t I2C_devicetype;
uint8_t I2C_address;
} _Objects;
extern _Objects Obj;

View File

@@ -15,10 +15,11 @@ board = genericSTM32F407VGT6
upload_protocol = stlink
debug_tool = stlink
debug_build_flags = -O0 -g -ggdb
monitor_port = COM15
monitor_port = COM19
monitor_filters = send_on_enter, time, colorize, log2file
monitor_speed = 115200
build_flags = -Wl,--no-warn-rwx-segment -DECAT
build_flags = -Wl,--no-warn-rwx-segment -DECAT -DADC_MCP3221
lib_deps =
SPI
robtillaart/ADS1X15@^0.5.1
pilotak/MCP3X21@^1.0.1
robtillaart/ADS1X15@^0.5.2

View File

@@ -16,11 +16,30 @@ HardwareSerial Serial1(PA10, PA9);
uint8_t inputPin[] = {PD15, PD14, PD13, PD12, PD11, PD10, PD9, PD8, PB15, PB14, PB13, PB12};
uint8_t outputPin[] = {PE10, PE9, PE8, PE7};
const uint32_t I2C_BUS_SPEED = 400000;
uint32_t I2C_restarts = 0;
#include "Wire.h"
TwoWire Wire2(PB11, PB10);
#ifdef ADC_MCP3221
#include "MyMCP3221.h"
MyMCP3221 mcp3221_0(0x48, &Wire2);
//MyMCP3221 mcp3221_7(0x4f, &Wire2);
#endif
#ifdef ADS1xxx
#include "ADS1X15.h"
ADS1115 ADS(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
#define bitset(byte, nbit) ((byte) |= (1 << (nbit)))
#define bitclear(byte, nbit) ((byte) &= ~(1 << (nbit)))
@@ -38,15 +57,43 @@ void cb_set_outputs(void) // Get Master outputs, slave inputs, first operation
void cb_get_inputs(void) // Set Master inputs, slave outputs, last operation
{
static float validData0 = 0.0, validVoltage0 = 0.0;
for (int i = 0; i < sizeof(inputPin); i++)
Obj.Input12 = digitalRead(inputPin[i]) == HIGH ? bitset(Obj.Input12, i) : bitclear(Obj.Input12, i);
float scale = Obj.VoltageScale;
if (scale == 0.0)
scale = 1.0;
float ADCvoltage = ADS.toVoltage(ADS.getValue());
Obj.ArcVoltage = scale * ADCvoltage; // * ADCvoltage; // Scaled voltage, to give Plasma arc voltage
Obj.Voltage = ADCvoltage; // Raw voltage, read by ADC
#ifdef ADC_MCP3221
int data0 = mcp3221_0.getData();
int stat = mcp3221_0.ping();
#endif
#ifdef ADS1xxx
int data0 = ads1014.getValue();
int stat = ads1014.isConnected();
#endif
if (stat == 0)
{ // Read good value
Obj.CalculatedVoltage = scale * data0 + Obj.VoltageOffset; //
Obj.RawData = data0; // Raw voltage, read by ADC
validVoltage0 = Obj.CalculatedVoltage;
validData0 = data0;
}
else
{ // Didn't read a good value. Return a hopefully useful value and restart the I2C bus
Obj.CalculatedVoltage = validVoltage0; // Use value from previous call
Obj.RawData = validData0;
// Reset wire here
Wire2.end();
Wire2.begin();
Wire2.setClock(I2C_BUS_SPEED);
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 = Obj.I2C_devicetype + Obj.I2C_address;
}
void ESC_interrupt_enable(uint32_t mask);
@@ -87,30 +134,67 @@ void setup(void)
pinMode(outputPin[i], OUTPUT);
digitalWrite(outputPin[i], LOW);
}
#if 0
// Debug leds
pinMode(PB4, OUTPUT);
pinMode(PB5, OUTPUT);
pinMode(PB6, OUTPUT);
pinMode(PB7, OUTPUT);
digitalWrite(PB4, HIGH);
digitalWrite(PB5, HIGH);
digitalWrite(PB6, HIGH);
digitalWrite(PB7, HIGH);
#endif
digitalWrite(PB4, LOW);
digitalWrite(PB5, LOW);
digitalWrite(PB6, LOW);
digitalWrite(PB7, LOW);
Wire2.begin();
ADS.begin();
ADS.setGain(0); // 0 = 6.144 volt, 1 = 4.096 V
ADS.setDataRate(7); // 0 = slow 4 = medium 7 = fast
ADS.setMode(0); // continuous mode
ADS.setWireClock(400000UL); // 400 kHz
ADS.readADC(0); // first read to trigger settings
Wire2.setClock(I2C_BUS_SPEED);
#ifdef ADS1xxx
ads1014_reset();
#endif
#ifdef ECAT
ecat_slv_init(&config);
#endif
#if 0 // Uncomment for commissioning tests
digitalWrite(outputPin[0], HIGH); // All four output leds should go high
digitalWrite(outputPin[1], HIGH);
digitalWrite(outputPin[2], HIGH);
digitalWrite(outputPin[3], HIGH);
while (1) // Apply voltage over the inputs 0-11 and see response in terminal
{
int nDevices = 0;
for (int i2caddr = 1; i2caddr < 127; i2caddr++)
{
Wire2.beginTransmission(i2caddr);
int stat = Wire2.endTransmission();
if (stat == 0)
{
Serial1.printf("I2C device found at address 0x%02x\n", i2caddr);
nDevices++;
}
}
if (!nDevices)
Serial1.printf("No devices\n");
#ifdef ADC_MCP3221
Serial1.printf("I2C status=%d rawdata=%d ", mcp3221_0.ping(), mcp3221_0.getData());
#endif
#ifdef ADS1xxx
// 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
for (int i = 0; i < 12; i++)
Serial1.printf("%u", digitalRead(inputPin[i]));
Serial1.println();
delay(1000);
}
#endif
}
void loop(void)
@@ -128,21 +212,7 @@ void loop(void)
dTime = longTime.extendTime(micros()) - irqTime;
if (dTime > 5000) // Not doing interrupts - handle free-run
ecat_slv();
#else
Serial1.print("TIC ");
int tot = 0;
uint32_t before = millis();
for (int i = 0; i < 10000; i++)
{
int16_t raw = ADS.getValue();
tot += raw;
}
uint32_t after = millis();
int16_t value = ADS.getValue();
float fval = ADS.toVoltage(value);
Serial1.printf("Time för 10000=%d värdet=", after - before);
Serial1.println(fval);
#endif
}

View File

@@ -36825,7 +36825,7 @@
(descr "Resistor SMD 0603 (1608 Metric), square (rectangular) end terminal, IPC_7351 nominal, (Body size source: IPC-SM-782 page 72, https://www.pcb-3d.com/wordpress/wp-content/uploads/ipc-sm-782a_amendment_1_and_2.pdf), generated with kicad-footprint-generator")
(tags "resistor")
(property "Reference" "R19"
(at 2.794 -2.032 0)
(at 2.54 0 0)
(layer "F.SilkS")
(uuid "8945efae-ad9c-4778-8c4a-99349011cd53")
(effects
@@ -38991,7 +38991,7 @@
(descr "Capacitor SMD 0603 (1608 Metric), square (rectangular) end terminal, IPC_7351 nominal, (Body size source: IPC-SM-782 page 76, https://www.pcb-3d.com/wordpress/wp-content/uploads/ipc-sm-782a_amendment_1_and_2.pdf), generated with kicad-footprint-generator")
(tags "capacitor")
(property "Reference" "C27"
(at -2.667 -2.032 180)
(at -2.54 0 180)
(layer "F.SilkS")
(uuid "86dc7c93-9ddb-4a93-9b73-ed6d70f07ef7")
(effects

View File

@@ -0,0 +1,83 @@
{
"board": {
"active_layer": 0,
"active_layer_preset": "All Layers",
"auto_track_width": true,
"hidden_netclasses": [],
"hidden_nets": [],
"high_contrast_mode": 0,
"net_color_mode": 1,
"opacity": {
"images": 0.6,
"pads": 1.0,
"tracks": 1.0,
"vias": 1.0,
"zones": 0.6
},
"selection_filter": {
"dimensions": true,
"footprints": true,
"graphics": true,
"keepouts": true,
"lockedItems": false,
"otherItems": true,
"pads": true,
"text": true,
"tracks": true,
"vias": true,
"zones": true
},
"visible_items": [
0,
1,
2,
3,
4,
5,
8,
9,
10,
11,
12,
13,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
32,
33,
34,
35,
36,
39,
40
],
"visible_layers": "fffffff_ffffffff",
"zone_display_mode": 0
},
"git": {
"repo_password": "",
"repo_type": "",
"repo_username": "",
"ssh_key": ""
},
"meta": {
"filename": "EaserCAT-7000.kicad_prl",
"version": 3
},
"project": {
"files": []
}
}

View File

@@ -479,7 +479,7 @@
},
"schematic": {
"annotate_start_num": 0,
"bom_export_filename": "",
"bom_export_filename": "EaserCAT-7000.csv",
"bom_fmt_presets": [],
"bom_fmt_settings": {
"field_delimiter": ",",
@@ -529,11 +529,95 @@
"label": "DNP",
"name": "${DNP}",
"show": true
},
{
"group_by": false,
"label": "#",
"name": "${ITEM_NUMBER}",
"show": false
},
{
"group_by": false,
"label": "Availability",
"name": "Availability",
"show": false
},
{
"group_by": false,
"label": "Check_prices",
"name": "Check_prices",
"show": false
},
{
"group_by": false,
"label": "MANUFACTURER",
"name": "MANUFACTURER",
"show": false
},
{
"group_by": false,
"label": "MAXIMUM_PACKAGE_HEIGHT",
"name": "MAXIMUM_PACKAGE_HEIGHT",
"show": false
},
{
"group_by": false,
"label": "MF",
"name": "MF",
"show": false
},
{
"group_by": false,
"label": "MP",
"name": "MP",
"show": false
},
{
"group_by": false,
"label": "PARTREV",
"name": "PARTREV",
"show": false
},
{
"group_by": false,
"label": "Package",
"name": "Package",
"show": false
},
{
"group_by": false,
"label": "Price",
"name": "Price",
"show": false
},
{
"group_by": false,
"label": "Purchase-URL",
"name": "Purchase-URL",
"show": false
},
{
"group_by": false,
"label": "STANDARD",
"name": "STANDARD",
"show": false
},
{
"group_by": false,
"label": "SnapEDA_Link",
"name": "SnapEDA_Link",
"show": false
},
{
"group_by": false,
"label": "Description",
"name": "Description",
"show": false
}
],
"filter_string": "",
"group_symbols": true,
"name": "Grouped By Value",
"name": "",
"sort_asc": true,
"sort_field": "Reference"
},

View File

@@ -0,0 +1 @@
0

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

9503
Cards/THTIC/Kicad/THTIC.kicad_pcb Executable file → Normal file

File diff suppressed because it is too large Load Diff

4
Cards/THTIC/Kicad/THTIC.kicad_pro Executable file → Normal file
View File

@@ -431,7 +431,7 @@
"pinned_symbol_libs": []
},
"meta": {
"filename": "THCIC.kicad_pro",
"filename": "THTIC.kicad_pro",
"version": 1
},
"net_settings": {
@@ -469,7 +469,7 @@
"plot": "Gerbers/",
"pos_files": "",
"specctra_dsn": "THCIC.dsn",
"step": "",
"step": "THTIC.step",
"svg": "",
"vrml": ""
},

2269
Cards/THTIC/Kicad/THTIC.kicad_sch Executable file → Normal file

File diff suppressed because it is too large Load Diff

98680
Cards/THTIC/Kicad/fp-info-cache Executable file

File diff suppressed because it is too large Load Diff

0
Cards/THTIC2/Kicad/THTIC2.kicad_pcb Executable file → Normal file
View File

2
Cards/THTIC2/Kicad/THTIC2.kicad_pro Executable file → Normal file
View File

@@ -469,7 +469,7 @@
"plot": "Gerbers/",
"pos_files": "",
"specctra_dsn": "THCIC.dsn",
"step": "",
"step": "THTIC2.step",
"svg": "",
"vrml": ""
},

2
Cards/THTIC2/Kicad/THTIC2.kicad_sch Executable file → Normal file
View File

@@ -3753,7 +3753,7 @@
)
)
)
(property "Value" "1k27"
(property "Value" "2k1"
(at 52.324 82.296 90)
(effects
(font

98680
Cards/THTIC2/Kicad/fp-info-cache Executable file

File diff suppressed because it is too large Load Diff