I2C THTIC is working on a patched EaserCAT-4000., EaserCAT-7000 tested, STM32 and LAN9252 works.

This commit is contained in:
Hakan Bastedt
2025-02-15 22:29:54 +01:00
parent f070ea592c
commit 0a66626fe4
12 changed files with 733 additions and 20 deletions

1
Cards/.gitignore vendored
View File

@@ -34,3 +34,4 @@ fp-info-cache
*.csv
*.step
*.stp
.~lock.*

View File

@@ -108,7 +108,7 @@
"PLATFORMIO=60117",
"STM32F407xx",
"STM32F4",
"ECAT",
"NOECAT",
"STM32F4xx",
"ARDUINO=10808",
"ARDUINO_ARCH_STM32",

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

@@ -99,6 +99,54 @@
</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>
@@ -230,15 +278,15 @@
<DataType>
<Name>DT1C12ARR</Name>
<BaseType>UINT</BaseType>
<BitSize>16</BitSize>
<BitSize>48</BitSize>
<ArrayInfo>
<LBound>1</LBound>
<Elements>1</Elements>
<Elements>3</Elements>
</ArrayInfo>
</DataType>
<DataType>
<Name>DT1C12</Name>
<BitSize>32</BitSize>
<BitSize>64</BitSize>
<SubItem>
<SubIdx>0</SubIdx>
<Name>Max SubIndex</Name>
@@ -252,7 +300,7 @@
<SubItem>
<Name>Elements</Name>
<Type>DT1C12ARR</Type>
<BitSize>16</BitSize>
<BitSize>48</BitSize>
<BitOffs>16</BitOffs>
<Flags>
<Access>ro</Access>
@@ -435,6 +483,52 @@
<Access>ro</Access>
</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>
<Access>ro</Access>
</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>
<Access>ro</Access>
</Flags>
</Object>
<Object>
<Index>#x1A00</Index>
<Name>Input12</Name>
@@ -572,12 +666,12 @@
<Index>#x1C12</Index>
<Name>Sync Manager 2 PDO Assignment</Name>
<Type>DT1C12</Type>
<BitSize>32</BitSize>
<BitSize>64</BitSize>
<Info>
<SubItem>
<Name>Max SubIndex</Name>
<Info>
<DefaultValue>1</DefaultValue>
<DefaultValue>3</DefaultValue>
</Info>
</SubItem>
<SubItem>
@@ -586,6 +680,18 @@
<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>
<Access>ro</Access>
@@ -638,7 +744,7 @@
<Type>REAL</Type>
<BitSize>32</BitSize>
<Info>
<DefaultValue>1</DefaultValue>
<DefaultValue>0</DefaultValue>
</Info>
<Flags>
<Access>ro</Access>
@@ -721,6 +827,32 @@
<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>
@@ -742,6 +874,28 @@
<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>

View File

@@ -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

View File

@@ -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",

View File

@@ -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}
};

View File

@@ -21,6 +21,8 @@ typedef struct
/* Outputs */
uint8_t Output4;
float VoltageScale;
float VoltageOffset;
/* Parameters */

View File

@@ -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

View File

@@ -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();

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": ""
},