diff --git a/Cards/.gitignore b/Cards/.gitignore index dcac726..2ed550b 100644 --- a/Cards/.gitignore +++ b/Cards/.gitignore @@ -34,3 +34,4 @@ fp-info-cache *.csv *.step *.stp +.~lock.* diff --git a/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/.vscode/c_cpp_properties.json b/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/.vscode/c_cpp_properties.json index b563010..04b9344 100755 --- a/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/.vscode/c_cpp_properties.json +++ b/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/.vscode/c_cpp_properties.json @@ -108,7 +108,7 @@ "PLATFORMIO=60117", "STM32F407xx", "STM32F4", - "ECAT", + "NOECAT", "STM32F4xx", "ARDUINO=10808", "ARDUINO_ARCH_STM32", diff --git a/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/MyMCP3221/MyMCP3221.cpp b/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/MyMCP3221/MyMCP3221.cpp new file mode 100755 index 0000000..b1c71c9 --- /dev/null +++ b/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/MyMCP3221/MyMCP3221.cpp @@ -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; irequestFrom(_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; + } + \ No newline at end of file diff --git a/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/MyMCP3221/MyMCP3221.h b/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/MyMCP3221/MyMCP3221.h new file mode 100755 index 0000000..48e8b8c --- /dev/null +++ b/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/MyMCP3221/MyMCP3221.h @@ -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 + #include + //#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 \ No newline at end of file diff --git a/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi/MetalMusings_EaserCAT_7000.xml b/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi/MetalMusings_EaserCAT_7000.xml index 49724fd..6aa5a7e 100755 --- a/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi/MetalMusings_EaserCAT_7000.xml +++ b/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi/MetalMusings_EaserCAT_7000.xml @@ -99,6 +99,54 @@ + + DT1601 + 48 + + 0 + Max SubIndex + USINT + 8 + 0 + + ro + + + + 1 + VoltageScale + UDINT + 32 + 16 + + ro + + + + + DT1602 + 48 + + 0 + Max SubIndex + USINT + 8 + 0 + + ro + + + + 1 + VoltageOffset + UDINT + 32 + 16 + + ro + + + DT1A00 48 @@ -230,15 +278,15 @@ DT1C12ARR UINT - 16 + 48 1 - 1 + 3 DT1C12 - 32 + 64 0 Max SubIndex @@ -252,7 +300,7 @@ Elements DT1C12ARR - 16 + 48 16 ro @@ -435,6 +483,52 @@ ro + + #x1601 + VoltageScale + DT1601 + 48 + + + Max SubIndex + + 1 + + + + VoltageScale + + #x70010020 + + + + + ro + + + + #x1602 + VoltageOffset + DT1602 + 48 + + + Max SubIndex + + 1 + + + + VoltageOffset + + #x70020020 + + + + + ro + + #x1A00 Input12 @@ -572,12 +666,12 @@ #x1C12 Sync Manager 2 PDO Assignment DT1C12 - 32 + 64 Max SubIndex - 1 + 3 @@ -586,6 +680,18 @@ #x1600 + + PDO Mapping + + #x1601 + + + + PDO Mapping + + #x1602 + + ro @@ -638,7 +744,7 @@ REAL 32 - 1 + 0 ro @@ -721,6 +827,32 @@ R + + #x7001 + VoltageScale + REAL + 32 + + 0 + + + ro + R + + + + #x7002 + VoltageOffset + REAL + 32 + + 0 + + + ro + R + + @@ -742,6 +874,28 @@ USINT + + #x1601 + VoltageScale + + #x7001 + #x0 + 32 + VoltageScale + REAL + + + + #x1602 + VoltageOffset + + #x7002 + #x0 + 32 + VoltageOffset + REAL + + #x1A00 Input12 diff --git a/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi/ecat_options.h b/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi/ecat_options.h index eb45c8c..3700c45 100755 --- a/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi/ecat_options.h +++ b/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi/ecat_options.h @@ -33,7 +33,7 @@ #define SM3_smc 0x20 #define SM3_act 1 -#define MAX_MAPPINGS_SM2 1 +#define MAX_MAPPINGS_SM2 3 #define MAX_MAPPINGS_SM3 4 #define MAX_RXPDO_SIZE 512 diff --git a/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi/esi.json b/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi/esi.json index a82feec..faf9995 100755 --- a/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi/esi.json +++ b/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi/esi.json @@ -39,7 +39,7 @@ "name": "Scale", "access": "RO", "dtype": "REAL32", - "value": "1", + "value": "0", "isSDOitem": true, "data": "&Obj.Scale" }, @@ -136,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", diff --git a/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi/objectlist.c b/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi/objectlist.c index 78118d7..b6e0a7a 100755 --- a/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi/objectlist.c +++ b/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi/objectlist.c @@ -16,6 +16,12 @@ 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"; @@ -37,6 +43,8 @@ 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"; @@ -50,6 +58,8 @@ 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[] = { @@ -80,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}, @@ -110,8 +130,10 @@ 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[] = { @@ -123,7 +145,7 @@ const _objd SDO1C13[] = }; const _objd SDO2000[] = { - {0x0, DTYPE_REAL32, 32, ATYPE_RO, acName2000, 0x3f800000, &Obj.Scale}, + {0x0, DTYPE_REAL32, 32, ATYPE_RO, acName2000, 0x00000000, &Obj.Scale}, }; const _objd SDO2001[] = { @@ -149,6 +171,14 @@ 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[] = { @@ -158,12 +188,14 @@ 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}, + {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}, @@ -172,5 +204,7 @@ const _objectlist SDOobjects[] = {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} }; diff --git a/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi/utypes.h b/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi/utypes.h index 786e4ff..ed13654 100755 --- a/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi/utypes.h +++ b/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/lib/soes-esi/utypes.h @@ -21,6 +21,8 @@ typedef struct /* Outputs */ uint8_t Output4; + float VoltageScale; + float VoltageOffset; /* Parameters */ diff --git a/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/platformio.ini b/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/platformio.ini index 7ab797c..9cc9234 100755 --- a/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/platformio.ini +++ b/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/platformio.ini @@ -15,10 +15,10 @@ board = genericSTM32F407VGT6 upload_protocol = stlink debug_tool = stlink debug_build_flags = -O0 -g -ggdb -monitor_port = COM17 +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 -DNOECAT lib_deps = SPI robtillaart/ADS1X15@^0.5.1 diff --git a/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/src/main.cpp b/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/src/main.cpp index 9440ce4..28d2bf0 100755 --- a/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/src/main.cpp +++ b/Cards/EaserCAT-7000-DIO+THCAD+I2C/Firmware/src/main.cpp @@ -43,13 +43,13 @@ void cb_get_inputs(void) // Set Master inputs, slave outputs, last operation 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.Scale; + float scale = Obj.VoltageScale; if (scale == 0.0) scale = 1.0; int data0 = mcp3221_0.getData(); if ((Obj.Status = mcp3221_0.ping()) == 0) { // Read good value - Obj.CalculatedVoltage = scale * data0 + Obj.Offset; // + Obj.CalculatedVoltage = scale * data0 + Obj.VoltageOffset; // Obj.RawData = data0; // Raw voltage, read by ADC validVoltage0 = Obj.CalculatedVoltage; validData0 = data0; @@ -100,7 +100,7 @@ void setup(void) pinMode(outputPin[i], OUTPUT); digitalWrite(outputPin[i], LOW); } -#if 0 +#if 1 // Debug leds pinMode(PB4, OUTPUT); pinMode(PB5, OUTPUT); @@ -110,6 +110,14 @@ void setup(void) digitalWrite(PB5, HIGH); digitalWrite(PB6, HIGH); digitalWrite(PB7, HIGH); + digitalWrite(PB4, LOW); + digitalWrite(PB5, LOW); + digitalWrite(PB6, LOW); + digitalWrite(PB7, LOW); + digitalWrite(outputPin[0], HIGH); + digitalWrite(outputPin[1], HIGH); + digitalWrite(outputPin[2], HIGH); + digitalWrite(outputPin[3], HIGH); #endif Wire2.begin(); diff --git a/Cards/THTIC/Kicad/THTIC.kicad_pro b/Cards/THTIC/Kicad/THTIC.kicad_pro index ff4af95..34a08f1 100644 --- a/Cards/THTIC/Kicad/THTIC.kicad_pro +++ b/Cards/THTIC/Kicad/THTIC.kicad_pro @@ -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": "" },