New option: voltagedrop for sensing ohmic sensing

This commit is contained in:
Hakan Bastedt
2025-10-08 13:29:54 +02:00
parent b867d58b15
commit b3bb88cf08
6 changed files with 139 additions and 28 deletions

View File

@@ -101,7 +101,7 @@
</DataType>
<DataType>
<Name>DT1601</Name>
<BitSize>208</BitSize>
<BitSize>240</BitSize>
<SubItem>
<SubIdx>0</SubIdx>
<Name>Max SubIndex</Name>
@@ -172,10 +172,20 @@
<Access>ro</Access>
</Flags>
</SubItem>
<SubItem>
<SubIdx>7</SubIdx>
<Name>OhmicSensingVoltageDrop</Name>
<Type>UDINT</Type>
<BitSize>32</BitSize>
<BitOffs>208</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
</DataType>
<DataType>
<Name>DT1602</Name>
<BitSize>208</BitSize>
<BitSize>240</BitSize>
<SubItem>
<SubIdx>0</SubIdx>
<Name>Max SubIndex</Name>
@@ -246,6 +256,16 @@
<Access>ro</Access>
</Flags>
</SubItem>
<SubItem>
<SubIdx>7</SubIdx>
<Name>OhmicSensingVoltageDrop</Name>
<Type>UDINT</Type>
<BitSize>32</BitSize>
<BitOffs>208</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
</DataType>
<DataType>
<Name>DT1A00</Name>
@@ -723,7 +743,7 @@
</DataType>
<DataType>
<Name>DT7001</Name>
<BitSize>184</BitSize>
<BitSize>216</BitSize>
<SubItem>
<SubIdx>0</SubIdx>
<Name>Max SubIndex</Name>
@@ -800,10 +820,21 @@
<PdoMapping>R</PdoMapping>
</Flags>
</SubItem>
<SubItem>
<SubIdx>7</SubIdx>
<Name>OhmicSensingVoltageDrop</Name>
<Type>REAL</Type>
<BitSize>32</BitSize>
<BitOffs>184</BitOffs>
<Flags>
<Access WriteRestrictions="PreOP">ro</Access>
<PdoMapping>R</PdoMapping>
</Flags>
</SubItem>
</DataType>
<DataType>
<Name>DT7002</Name>
<BitSize>184</BitSize>
<BitSize>216</BitSize>
<SubItem>
<SubIdx>0</SubIdx>
<Name>Max SubIndex</Name>
@@ -880,6 +911,17 @@
<PdoMapping>R</PdoMapping>
</Flags>
</SubItem>
<SubItem>
<SubIdx>7</SubIdx>
<Name>OhmicSensingVoltageDrop</Name>
<Type>REAL</Type>
<BitSize>32</BitSize>
<BitOffs>184</BitOffs>
<Flags>
<Access WriteRestrictions="PreOP">ro</Access>
<PdoMapping>R</PdoMapping>
</Flags>
</SubItem>
</DataType>
<DataType>
<Name>UDINT</Name>
@@ -1027,12 +1069,12 @@
<Index>#x1601</Index>
<Name>In_Unit1</Name>
<Type>DT1601</Type>
<BitSize>208</BitSize>
<BitSize>240</BitSize>
<Info>
<SubItem>
<Name>Max SubIndex</Name>
<Info>
<DefaultValue>6</DefaultValue>
<DefaultValue>7</DefaultValue>
</Info>
</SubItem>
<SubItem>
@@ -1071,6 +1113,12 @@
<DefaultValue>#x70010620</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>OhmicSensingVoltageDrop</Name>
<Info>
<DefaultValue>#x70010720</DefaultValue>
</Info>
</SubItem>
</Info>
<Flags>
</Flags>
@@ -1079,12 +1127,12 @@
<Index>#x1602</Index>
<Name>In_Unit2</Name>
<Type>DT1602</Type>
<BitSize>208</BitSize>
<BitSize>240</BitSize>
<Info>
<SubItem>
<Name>Max SubIndex</Name>
<Info>
<DefaultValue>6</DefaultValue>
<DefaultValue>7</DefaultValue>
</Info>
</SubItem>
<SubItem>
@@ -1123,6 +1171,12 @@
<DefaultValue>#x70020620</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>OhmicSensingVoltageDrop</Name>
<Info>
<DefaultValue>#x70020720</DefaultValue>
</Info>
</SubItem>
</Info>
<Flags>
</Flags>
@@ -1539,12 +1593,12 @@
<Index>#x7001</Index>
<Name>In_Unit1</Name>
<Type>DT7001</Type>
<BitSize>184</BitSize>
<BitSize>216</BitSize>
<Info>
<SubItem>
<Name>Max SubIndex</Name>
<Info>
<DefaultValue>6</DefaultValue>
<DefaultValue>7</DefaultValue>
</Info>
</SubItem>
<SubItem>
@@ -1583,6 +1637,12 @@
<DefaultValue>0</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>OhmicSensingVoltageDrop</Name>
<Info>
<DefaultValue>0</DefaultValue>
</Info>
</SubItem>
</Info>
<Flags>
</Flags>
@@ -1591,12 +1651,12 @@
<Index>#x7002</Index>
<Name>In_Unit2</Name>
<Type>DT7002</Type>
<BitSize>184</BitSize>
<BitSize>216</BitSize>
<Info>
<SubItem>
<Name>Max SubIndex</Name>
<Info>
<DefaultValue>6</DefaultValue>
<DefaultValue>7</DefaultValue>
</Info>
</SubItem>
<SubItem>
@@ -1635,6 +1695,12 @@
<DefaultValue>0</DefaultValue>
</Info>
</SubItem>
<SubItem>
<Name>OhmicSensingVoltageDrop</Name>
<Info>
<DefaultValue>0</DefaultValue>
</Info>
</SubItem>
</Info>
<Flags>
</Flags>
@@ -1705,6 +1771,13 @@
<Name>OhmicSensingVoltageLimit</Name>
<DataType>REAL</DataType>
</Entry>
<Entry>
<Index>#x7001</Index>
<SubIndex>#x7</SubIndex>
<BitLen>32</BitLen>
<Name>OhmicSensingVoltageDrop</Name>
<DataType>REAL</DataType>
</Entry>
</RxPdo>
<RxPdo Fixed="true" Mandatory="true" Sm="2">
<Index>#x1602</Index>
@@ -1751,6 +1824,13 @@
<Name>OhmicSensingVoltageLimit</Name>
<DataType>REAL</DataType>
</Entry>
<Entry>
<Index>#x7002</Index>
<SubIndex>#x7</SubIndex>
<BitLen>32</BitLen>
<Name>OhmicSensingVoltageDrop</Name>
<DataType>REAL</DataType>
</Entry>
</RxPdo>
<TxPdo Fixed="true" Mandatory="true" Sm="3">
<Index>#x1A00</Index>

View File

@@ -33,7 +33,7 @@
#define SM3_smc 0x20
#define SM3_act 1
#define MAX_MAPPINGS_SM2 13
#define MAX_MAPPINGS_SM2 15
#define MAX_MAPPINGS_SM3 11
#define MAX_RXPDO_SIZE 512

View File

@@ -294,6 +294,13 @@
"value": "0",
"access": "RO",
"data": "&Obj.In_Unit1.OhmicSensingVoltageLimit"
},
{
"name": "OhmicSensingVoltageDrop",
"dtype": "REAL32",
"value": "0",
"access": "RO",
"data": "&Obj.In_Unit1.OhmicSensingVoltageDrop"
}
],
"pdo_mappings": [
@@ -349,6 +356,13 @@
"value": "0",
"access": "RO",
"data": "&Obj.In_Unit2.OhmicSensingVoltageLimit"
},
{
"name": "OhmicSensingVoltageDrop",
"dtype": "REAL32",
"value": "0",
"access": "RO",
"data": "&Obj.In_Unit2.OhmicSensingVoltageDrop"
}
],
"pdo_mappings": [

View File

@@ -24,6 +24,7 @@ static const char acName1601_03[] = "LowPassFilterThresholdVoltage";
static const char acName1601_04[] = "EnableOhmicSensing";
static const char acName1601_05[] = "OhmicSensingSetupTime";
static const char acName1601_06[] = "OhmicSensingVoltageLimit";
static const char acName1601_07[] = "OhmicSensingVoltageDrop";
static const char acName1602[] = "In_Unit2";
static const char acName1602_00[] = "Max SubIndex";
static const char acName1602_01[] = "VoltageScale";
@@ -32,6 +33,7 @@ static const char acName1602_03[] = "LowPassFilterThresholdVoltage";
static const char acName1602_04[] = "EnableOhmicSensing";
static const char acName1602_05[] = "OhmicSensingSetupTime";
static const char acName1602_06[] = "OhmicSensingVoltageLimit";
static const char acName1602_07[] = "OhmicSensingVoltageDrop";
static const char acName1A00[] = "Input12";
static const char acName1A00_00[] = "Max SubIndex";
static const char acName1A00_01[] = "Input12";
@@ -99,6 +101,7 @@ static const char acName7001_03[] = "LowPassFilterThresholdVoltage";
static const char acName7001_04[] = "EnableOhmicSensing";
static const char acName7001_05[] = "OhmicSensingSetupTime";
static const char acName7001_06[] = "OhmicSensingVoltageLimit";
static const char acName7001_07[] = "OhmicSensingVoltageDrop";
static const char acName7002[] = "In_Unit2";
static const char acName7002_00[] = "Max SubIndex";
static const char acName7002_01[] = "VoltageScale";
@@ -107,6 +110,7 @@ static const char acName7002_03[] = "LowPassFilterThresholdVoltage";
static const char acName7002_04[] = "EnableOhmicSensing";
static const char acName7002_05[] = "OhmicSensingSetupTime";
static const char acName7002_06[] = "OhmicSensingVoltageLimit";
static const char acName7002_07[] = "OhmicSensingVoltageDrop";
const _objd SDO1000[] =
{
@@ -139,23 +143,25 @@ const _objd SDO1600[] =
};
const _objd SDO1601[] =
{
{0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName1601_00, 6, NULL},
{0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName1601_00, 7, NULL},
{0x01, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1601_01, 0x70010120, NULL},
{0x02, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1601_02, 0x70010220, NULL},
{0x03, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1601_03, 0x70010320, NULL},
{0x04, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1601_04, 0x70010408, NULL},
{0x05, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1601_05, 0x70010520, NULL},
{0x06, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1601_06, 0x70010620, NULL},
{0x07, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1601_07, 0x70010720, NULL},
};
const _objd SDO1602[] =
{
{0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName1602_00, 6, NULL},
{0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName1602_00, 7, NULL},
{0x01, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1602_01, 0x70020120, NULL},
{0x02, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1602_02, 0x70020220, NULL},
{0x03, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1602_03, 0x70020320, NULL},
{0x04, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1602_04, 0x70020408, NULL},
{0x05, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1602_05, 0x70020520, NULL},
{0x06, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1602_06, 0x70020620, NULL},
{0x07, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1602_07, 0x70020720, NULL},
};
const _objd SDO1A00[] =
{
@@ -244,23 +250,25 @@ const _objd SDO7000[] =
};
const _objd SDO7001[] =
{
{0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName7001_00, 6, NULL},
{0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName7001_00, 7, NULL},
{0x01, DTYPE_REAL32, 32, ATYPE_RO, acName7001_01, 0x00000000, &Obj.In_Unit1.VoltageScale},
{0x02, DTYPE_REAL32, 32, ATYPE_RO, acName7001_02, 0x00000000, &Obj.In_Unit1.VoltageOffset},
{0x03, DTYPE_REAL32, 32, ATYPE_RO, acName7001_03, 0x00000000, &Obj.In_Unit1.LowPassFilterThresholdVoltage},
{0x04, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName7001_04, 0, &Obj.In_Unit1.EnableOhmicSensing},
{0x05, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName7001_05, 0, &Obj.In_Unit1.OhmicSensingSetupTime},
{0x06, DTYPE_REAL32, 32, ATYPE_RO, acName7001_06, 0x00000000, &Obj.In_Unit1.OhmicSensingVoltageLimit},
{0x07, DTYPE_REAL32, 32, ATYPE_RO, acName7001_07, 0x00000000, &Obj.In_Unit1.OhmicSensingVoltageDrop},
};
const _objd SDO7002[] =
{
{0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName7002_00, 6, NULL},
{0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName7002_00, 7, NULL},
{0x01, DTYPE_REAL32, 32, ATYPE_RO, acName7002_01, 0x00000000, &Obj.In_Unit2.VoltageScale},
{0x02, DTYPE_REAL32, 32, ATYPE_RO, acName7002_02, 0x00000000, &Obj.In_Unit2.VoltageOffset},
{0x03, DTYPE_REAL32, 32, ATYPE_RO, acName7002_03, 0x00000000, &Obj.In_Unit2.LowPassFilterThresholdVoltage},
{0x04, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName7002_04, 0, &Obj.In_Unit2.EnableOhmicSensing},
{0x05, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName7002_05, 0, &Obj.In_Unit2.OhmicSensingSetupTime},
{0x06, DTYPE_REAL32, 32, ATYPE_RO, acName7002_06, 0x00000000, &Obj.In_Unit2.OhmicSensingVoltageLimit},
{0x07, DTYPE_REAL32, 32, ATYPE_RO, acName7002_07, 0x00000000, &Obj.In_Unit2.OhmicSensingVoltageDrop},
};
const _objectlist SDOobjects[] =
@@ -271,8 +279,8 @@ 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, 6, 0, acName1601, SDO1601},
{0x1602, OTYPE_RECORD, 6, 0, acName1602, SDO1602},
{0x1601, OTYPE_RECORD, 7, 0, acName1601, SDO1601},
{0x1602, OTYPE_RECORD, 7, 0, acName1602, SDO1602},
{0x1A00, OTYPE_RECORD, 1, 0, acName1A00, SDO1A00},
{0x1A01, OTYPE_RECORD, 5, 0, acName1A01, SDO1A01},
{0x1A02, OTYPE_RECORD, 5, 0, acName1A02, SDO1A02},
@@ -285,7 +293,7 @@ const _objectlist SDOobjects[] =
{0x6001, OTYPE_RECORD, 5, 0, acName6001, SDO6001},
{0x6002, OTYPE_RECORD, 5, 0, acName6002, SDO6002},
{0x7000, OTYPE_VAR, 0, 0, acName7000, SDO7000},
{0x7001, OTYPE_RECORD, 6, 0, acName7001, SDO7001},
{0x7002, OTYPE_RECORD, 6, 0, acName7002, SDO7002},
{0x7001, OTYPE_RECORD, 7, 0, acName7001, SDO7001},
{0x7002, OTYPE_RECORD, 7, 0, acName7002, SDO7002},
{0xffff, 0xff, 0xff, 0xff, NULL, NULL}
};

View File

@@ -42,6 +42,7 @@ typedef struct
uint8_t EnableOhmicSensing;
uint32_t OhmicSensingSetupTime;
float OhmicSensingVoltageLimit;
float OhmicSensingVoltageDrop;
} In_Unit1;
struct
{
@@ -51,6 +52,7 @@ typedef struct
uint8_t EnableOhmicSensing;
uint32_t OhmicSensingSetupTime;
float OhmicSensingVoltageLimit;
float OhmicSensingVoltageDrop;
} In_Unit2;
/* Parameters */

View File

@@ -46,7 +46,8 @@ void ads1014_reset(ADS1014 *ads) {
class OhmicSensing {
public:
void handle(uint8_t voltageState, float inVoltage, float limitVoltage,
uint32_t setupTime, uint8_t enabled, uint8_t &sensed);
float voltageDropLimit, uint32_t setupTime, uint8_t enabled,
uint8_t &sensed);
private:
enum OhmicStates { OHMIC_IDLE, OHMIC_SETUP, OHMIC_PROBE };
@@ -128,11 +129,13 @@ void cb_get_inputs(void) // Set Master inputs, slave outputs, last operation
Ohm1.handle(
stat_1, Obj.Out_Unit1.CalculatedVoltage,
Obj.In_Unit1.OhmicSensingVoltageLimit, Obj.In_Unit1.OhmicSensingSetupTime,
Obj.In_Unit1.OhmicSensingVoltageLimit,
Obj.In_Unit1.OhmicSensingVoltageDrop, Obj.In_Unit1.OhmicSensingSetupTime,
Obj.In_Unit1.EnableOhmicSensing, Obj.Out_Unit1.OhmicSensingSensed);
Ohm2.handle(
stat_2, Obj.Out_Unit2.CalculatedVoltage,
Obj.In_Unit2.OhmicSensingVoltageLimit, Obj.In_Unit2.OhmicSensingSetupTime,
Obj.In_Unit2.OhmicSensingVoltageLimit,
Obj.In_Unit2.OhmicSensingVoltageDrop, Obj.In_Unit2.OhmicSensingSetupTime,
Obj.In_Unit2.EnableOhmicSensing, Obj.Out_Unit2.OhmicSensingSensed);
}
@@ -427,8 +430,9 @@ void lowpassFilter(float &oldLowPassGain,
}
void OhmicSensing::handle(uint8_t voltageState, float inVoltage,
float limitVoltage, uint32_t setupTime,
uint8_t enabled, uint8_t &sensed) {
float limitVoltage, float voltageDropLimit,
uint32_t setupTime, uint8_t enabled,
uint8_t &sensed) {
sensed = 0;
if (enabled && voltageState == 0) {
if (ohmicState == OHMIC_IDLE && inVoltage > limitVoltage) {
@@ -446,8 +450,11 @@ void OhmicSensing::handle(uint8_t voltageState, float inVoltage,
voltages.push(inVoltage);
#define N_VOLTAGES 3
while (voltages.size() > N_VOLTAGES) voltages.pop(); // Only N_VOLTAGES
if (inVoltage <= limitVoltage || oldVoltage - inVoltage >= 1.0 ||
voltages.front() - voltages.back() > 2.0) {
if (inVoltage <= limitVoltage || // Below threshold
(abs(voltageDropLimit) > 1e-3 && // Immediate drop
oldVoltage - inVoltage >= voltageDropLimit) ||
(abs(voltageDropLimit) > 1e-3 && // Drop over 3 cycles
voltages.front() - voltages.back() > voltageDropLimit)) {
sensed = 1;
}
oldVoltage = inVoltage;