This part is for members
Membership opens soon. Leave your email and we'll tell you the day it does. Founding members get the launch price.
Keep watching the free partsEtherCAT 3: one frame missing
EtherCAT, part three: what happens when a frame doesn't come? It opens with the whole episode on one framework page: at every SYNC0 the stack checks that a frame came since the last one; a miss adds 3, a frame takes 1 off, and at 4 the drive leaves OP with code 0x1A. Nothing in servohub's motor code hears about it: the drive stays enabled on the last target. The page: the counting rule in run order on the left, three runs side by side in the middle (the master goes quiet, one frame comes late, the same late frame with one byte changed), the drive's crystal against the DC clock on the right. Same bench as 31a, sil-mac/ep31, with a new --log-count that prints the stack's counters. Four stops: one SYNC0, one frame (u16SmSync0Counter counts SYNC0s since the last frame; the frame's PDI_Isr sets it to 0 and Sync0_Isr adds 1; the allowed number, u16SmSync0Value, is 1 in DC mode with SYNC0 only; on the bench it goes 1, then 2 at 477.0, because Sync0_Isr runs twice per SYNC0, the same reason 31a wrote 0x607A three times); the master goes quiet (the frame at 477.75 carries 128,451, then nothing; at 479.0 the count is 2, more than the 1 allowed, so Sync0_Isr adds 3 to the missed counter 0x1C32:11, and the second call adds 3 more: 6; each frame takes 1 off; the limit is 0x10F1:02, starting at MAX_SM_EVENT_MISSED = 4); the 1 ms check (TIM7 runs ECAT_CheckTimer, which calls DC_CheckWatchdog: 6 is not below 4, so bSmSyncSequenceValid goes false; the main loop's CheckIfEcatError asks for SAFEOP, and at 480.0 ms the AL status reads 0x14 with code 0x1A; leaving OP on its own error also turns off SyncManager 2); why twice (road one: the board's SYNC0 pin, where ECAT_SYNC_IRQ_TASK calls Sync0_Isr; road two: the ESI's ConfigData sets register 0x151 to 0xCC, whose bit 3 maps SYNC0 into the AL event; on the way to SAFEOP the stack reads that bit and unmasks SYNC0, so PDI_Isr calls Sync0_Isr again; the rule assumed one call per SYNC0, and with two, a normal cycle already ends at 2, so the first SYNC0 without a fresh frame adds 3 twice). What the motor does: APPL_StopOutputHandler just returns 0 and no code outside the stack reads the EtherCAT state; APPL_Application replays 128,451 into 0x607A at every SYNC0; by 481.7 all four CSP slots hold 128,451, the command bends up to 826 rpm and stops dead, the motor still at 682 rpm overshoots to 129,552 at 483.2 ms (1,101 counts, about 3 degrees) and swings back to 128,451; the statusword stays 0x1237. One late frame: the frame carrying 129,761 lands 500 µs late, at 479.25, after its SYNC0; the missed counter goes 3, 6, the late frame takes it to 5, the on-time next frame to 4, and the check at 480.0 finds 4 not below 4: SAFEOP, 0x1A; every frame after comes back with working counter 0, the target freezes at 131,072, and the two-turn move stops after one. The fix, one byte (the fork's branch fix/ecat-sync0-called-twice sets 0x151 to 0xC4 in the ESI, bit 3 off, no code changes; labelled as the patched ESI on screen): the same late frame leaves the missed counter at 0, the drive stays in OP and finishes at 262,144; a quiet master is still caught, 0 at 479, 3 at 480, 6 at 481, SAFEOP at 481.0; the rule as the stack meant it is one missed SYNC0 free, two in a row cost 3, three in a row stop the drive; 0x607A is written twice per cycle; drives already built need their EEPROM written from the new ESI. The crystal against DC: the board restarts TIM5 at every SYNC0, so an error never piles up past one cycle; 10 ppm slow still gives 10 ticks; 1 ppm fast on the zero-delay bench puts tick 10 just before SYNC0 and the lock counts 11, but the latch stays 7 and the move is unchanged; as a model with estimated interrupt delays (300 ns for the SYNC0 pin, 200 ns for TIM5), 499 ppm fast gives 10 ticks and 501 gives 11, while crystals are off by tens of ppm. Skipped: the process-data watchdog 0x1B (100 ms here, so the sync check fires first), input-only devices and SYNC1, and how the master acknowledges the error and returns to OP. Your turn: drop two frames in a row; with 0xCC the drive goes to SAFEOP at 480.0, with 0xC4 the missed counter goes 3, 2, 1, 0 and it stays in OP.