Skip to main content

DC configuration

Master-level DC configuration. Call it directly through master.

Methods​

CategoryMethodTypeR/WDescription
DC configurationconfigureDCAll(int sync0Ns, int sync1Ns)intWrite-onlyConfigures SYNC0/SYNC1 for all DC slaves; returns the number of slaves that landed and were accepted = armed + PreOp ready (never equivalent to the armed count); <0 = failure
setMasterDCCycleTime(int timeNs)voidWrite-onlySets the master DC cycle time (nanoseconds)
autoCalculateDCShift()intWrite-onlyAutomatically calculates the phase shift of each slave
Drift compensationenableDriftCompensation(boolean, int, int)voidWrite-onlyStarts or stops drift compensation (threshold + gain)
enableContinuousMeasurement(boolean, int)voidWrite-onlyStarts or stops continuous propagation delay measurement (ETG.1500 5.13.2)
setDCAutoShiftEnabled(boolean) / getDCAutoShiftEnabled()void / booleanRead-writeAutomatic shift switch
Sync windowmaxSyncDifference()intRead-onlyMaximum time deviation (nanoseconds); -1 on failure
isAllSlavesInSync()booleanRead-onlyWhether all SYNC0 DC slaves are inside the sync window
resetAllSyncWindowStats()voidWrite-onlyResets the sync window statistics
maxPropagationDelay()intRead-onlyMaximum propagation delay (nanoseconds)
DC time queriesgetMasterDCTime()longRead-onlyDC time retrieved in the most recent PDO cycle (nanoseconds)
getReferenceClockSlaveIndex()intRead-onlyReference clock slave index (1-based, 0 = none)

configureDCAll​

public int configureDCAll(int sync0Ns, int sync1Ns)

Configures DC synchronization for all DC slaves. All parameters are in nanoseconds (ns). The following is done automatically by default:

  1. Propagation delay measurement — reads the receive time of each port and computes the delay
  2. Phase calculation — resolves each slave's phase in the order ESI explicit / user explicit / default 70% (phase only; the propagation delay is corrected by the ESC in hardware per 0x0928 and is not merged into the phase)
  3. Applying DC — writes the SYNC0/SYNC1 cycle and the start time to each slave

Parameters:

  • sync0Ns (int) — SYNC0 cycle (nanoseconds); 0 disables DC
  • sync1Ns (int) — SYNC1 delta time (nanoseconds); 0 means SYNC0 only

Return value:

  • int — number of DC slaves that landed and were accepted = armed + PreOp ready (never equivalent to the armed count); <0 = failure

Example:

master.configureDCAll(1_000_000, 0);           // SYNC0 = 1ms
master.configureDCAll(1_000_000, 500_000); // SYNC0 = 1ms, SYNC1 = 500 µs
Recommended configuration

125 µs high-performance configuration (recommended for the real-time driver):

master.config().loopCycle(125_000);    // PDO exchange cycle 125 µs
master.configureDCAll(125_000, 0); // SYNC0 = 125 µs

1ms standard configuration (general scenarios):

master.config().loopCycle(1_000_000);  // PDO exchange cycle 1ms
master.configureDCAll(1_000_000, 0); // SYNC0 = 1ms
  • SYNC0 and LoopCycle — keep them identical or make the former an integer multiple of the latter
  • Automatic phase (recommended) — the master resolves the phase by precedence; the propagation delay is measured as usual and written to 0x0928
About SYNC1

SYNC1 is a delta time relative to SYNC0. For example SYNC0=1,000,000ns, SYNC1=500,000ns means SYNC1 fires 500 µs after each SYNC0.

note

The DC synchronization mode is configured explicitly by the user. After restoring a snapshot, slaves that need DC should confirm they have entered DcSynchron / DcSynchron01.

setMasterDCCycleTime​

public void setMasterDCCycleTime(int timeNs)

Sets the master DC cycle time (nanoseconds).

Parameters:

  • timeNs (int) — DC cycle time (nanoseconds)

autoCalculateDCShift​

public int autoCalculateDCShift()

Automatically resolves the DC phase of each slave (phase only: ESI explicit / user explicit / default 70%). The propagation delay is corrected by the ESC in hardware per 0x0928 and is not merged into the phase.

Return value:

  • int — calculation result

enableDriftCompensation​

public void enableDriftCompensation(boolean enable, int thresholdNs, int gain)

Enables or disables DC drift compensation. Drift compensation continuously corrects the deviation between the system clock and the DC reference clock on the master side, preventing synchronization accuracy from degrading over long runs.

Parameters:

  • enable (boolean) — true enables, false disables
  • thresholdNs (int) — deviation threshold that triggers compensation (nanoseconds); no correction is applied below this value
  • gain (int) — compensation gain, which controls the correction rate (a larger value corrects faster but may introduce oscillation)

Example:

// Enable drift compensation with the recommended parameters
master.enableDriftCompensation(true, 1000, 512);

// Custom parameters: 500ns threshold, lower gain (smoother correction)
master.enableDriftCompensation(true, 500, 256);

// Disable drift compensation
master.enableDriftCompensation(false, 0, 0);
Recommendation

For systems that run for a long time (>24 hours), enable drift compensation. The default parameters suit most scenarios; adjust the threshold and gain only when you need finer control.

enableContinuousMeasurement​

public void enableContinuousMeasurement(boolean enable, int intervalSec)

Enables or disables continuous propagation delay measurement (ETG.1500 5.13.2). Once enabled, the master re-measures the propagation delay at a fixed interval, which suits scenarios where temperature drift and similar effects change the delay.

Parameters:

  • enable (boolean) — true enables, false disables
  • intervalSec (int) — measurement interval (seconds); 0 means the default interval

Example:

master.enableContinuousMeasurement(true, 60);  // Re-measure every 60 seconds
master.enableContinuousMeasurement(false, 0); // Disable
note

By default the DC shift is computed once, in configureDCAll(). Enable this feature only for long runs with large ambient temperature changes.

Sync window monitoring​

The master automatically checks the time deviation of each DC slave once per second. When a slave's deviation exceeds the syncWindowThreshold threshold, a DCSyncLost event fires.

// Threshold: 1000ns by default, adjustable
master.diagnostics().setSyncWindowThreshold(500); // Set to 500ns

// Event: fires once when a slave goes from "in sync" to "out of sync"
master.events().addDCSyncLostListener((masterIdx, slaveIdx, diffNs) ->
System.out.println("从站 " + slaveIdx + " DC 同步丢失: 偏差 " + diffNs + "ns")); // Slave {slaveIdx} DC sync lost: deviation {diffNs}ns

maxSyncDifference​

public int maxSyncDifference()

Gets the maximum time deviation across all DC slaves (nanoseconds).

Return value:

  • int — maximum time deviation (nanoseconds); returns -1 on failure

Example:

int maxDiff = master.maxSyncDifference();
System.out.println("最大同步偏差: " + maxDiff + "ns"); // Maximum sync deviation: {maxDiff}ns

isAllSlavesInSync​

public boolean isAllSlavesInSync()

Checks whether all slaves with SYNC0 DC enabled are inside the sync window (deviation <= syncWindowThreshold). All-slave FreeRun is not "DC synchronized".

Return value:

  • boolean — returns true when all SYNC0 DC slaves are inside the window; FreeRun must not be interpreted as synchronized

Example:

if (!master.isAllSlavesInSync()) {
System.out.println("存在从站同步偏差过大"); // Some slaves have excessive sync deviation
}

resetAllSyncWindowStats​

public void resetAllSyncWindowStats()

Resets the sync window statistics of all slaves (maximum/minimum time difference, number of out-of-sync events, and so on).

maxPropagationDelay​

public int maxPropagationDelay()

Gets the maximum propagation delay (nanoseconds).

DC time queries​

Used to read the current DC system time of the bus and the reference clock slave index. The master reads the DC time back from the reference clock slave over FRMW in every PDO cycle; this API returns the most recently cached value.

getMasterDCTime​

public long getMasterDCTime()

Gets the 64-bit DC system time retrieved by the master in the most recent PDO cycle. The unit is nanoseconds, with 2000-01-01 00:00:00 UTC as the epoch (defined by the ETG specifications).

Return value:

  • long — DC time (nanoseconds). 0 means DC is not active or there is no DC slave

Example:

long dcNs = master.getMasterDCTime();
if (dcNs == 0) {
System.out.println("DC 未激活"); // DC not active
} else {
// 2000-01-01 to 1970-01-01 = 946_684_800 seconds
long epochMs = dcNs / 1_000_000L + 946_684_800_000L;
System.out.println("DC 时间: " + new java.util.Date(epochMs)); // DC time: {new java.util.Date(epochMs)}
}

getReferenceClockSlaveIndex​

public int getReferenceClockSlaveIndex()

Gets the current reference clock slave index (1-based). The reference clock is the first slave in the DC network with DC activated (real SYNC0) (couplers that support DC but run in FreeRun are skipped); when no slave has DC activated it falls back to the first DC-capable slave in the chain, and every other DC slave synchronizes its time to it.

Return value:

  • int — reference clock slave index (1-based); 0 means the bus has no DC-capable slave

Example:

int refIdx = master.getReferenceClockSlaveIndex();
if (refIdx > 0) {
System.out.printf("参考时钟从站: Slave[%d]%n", refIdx); // Reference clock slave: Slave[%d]%n
} else {
System.out.println("总线上没有 DC 能力从站"); // There are no DC-capable slaves on the bus
}

DC automatic shift​

master.setDCAutoShiftEnabled(true);
boolean enabled = master.getDCAutoShiftEnabled();

Once enabled, the master computes the optimal shift automatically during DC configuration.

Full example​

125 µs high performance (real-time driver)​

try (EtherCATMaster master = EtherCATMaster.create()) {
master.setNetwork("\\Device\\NPF_{...}");

// 1. Configure the cycle — 125 µs (recommended value for the real-time driver)
master.config().loopCycle(125_000);

// 2. Switch to SafeOp
master.setState(EcState.SAFE_OP);

// 3. Configure DC (automatic shift) — keep SYNC0 identical to LoopCycle
master.configureDCAll(125_000, 0);

Thread.sleep(1000);

// 4. Switch to Op
master.setState(EcState.OP);
master.start();

// Listen for DC sync lost events
master.events().addDCSyncLostListener((masterIdx, slaveIdx, diffNs) ->
System.out.println("从站 " + slaveIdx + " DC 同步丢失: 偏差 " + diffNs + "ns")); // Slave {slaveIdx} DC sync lost: deviation {diffNs}ns
}

Continuous measurement and sync monitoring​

// Long runs: enable continuous propagation delay measurement (temperature drift compensation)
master.enableContinuousMeasurement(true, 60);

// Drift compensation
master.enableDriftCompensation(true, 500, 256);

// Sync window monitoring
if (!master.isAllSlavesInSync()) {
int maxDiff = master.maxSyncDifference();
System.out.println("同步偏差过大: " + maxDiff + "ns"); // Sync deviation too large: {maxDiff}ns
}

// Reset statistics
master.resetAllSyncWindowStats();