Skip to main content
NewEpisode 3a is out: Carry the conversation onWatch →

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 parts
Data & comms · 31b

EtherCAT 2: finding the tick

EtherCAT, part two: in 31a the 129,761 in the frame at 478.75 ms was taken at 479.7 ms, on tick 7. Why tick 7? It opens with the whole episode on one framework page: before the first point, the drive counts ten ticks a cycle over 50 SYNC0s; then at every SYNC0 it notes which tick window the last frame landed in, the earliest window becomes the latch, and the flag fires on the last tick before the next frame. The page: the two waits before the first point on the left, one cycle as ten windows in the middle, the ten-offset runs, one early frame and SM-synchronous mode on the right. Same bench as 31a, sil-mac/ep31; no servohub line changed. Four stops: count the ticks (every tick adds one to pl_period_cnt; bsp_adaptive_pl_period_config reads it at every SYNC0 and clears it; the first SYNC0, at 30 ms, finds 2 ticks and resets the bookkeeping; every one after finds 10; the stored total starts at 0, so every count differs, and after 50 SYNC0s the code keeps the last count without checking the 50 agree; SYNC0 number 51, at 80.0 ms, locks; until then the position loop raises no flag, and one slips out at 80.0 on tick 0 because the latch still holds its start value, 0); the stack waits too (the master asks for OP at 25 ms; with DC on, StartOutputHandler sets a count of 200 and DC_CheckWatchdog adds one every millisecond while SYNC0 keeps coming, so OP comes at 229 ms; the two waits don't know about each other, and worked out from the code, with a 5 ms cycle the drive would sit in OP for about 50 ms before its first flag); where the frame lands (the IRQ pin's handler copies the tick index into frame_pl_period_index; the frame at 80.75 ms is in window 7; the IRQ pin fires at SYNC0 too and copies 9, but the higher-priority SYNC0 pin has already read the 7); the latch (shift_max is 9 at the lock; 7 is smaller and not 0, so the latch becomes 7, and from 81.7 ms every tick 7 raises the flag; it only goes down). Why the tick before the frame: 129,761 stays in 0x607A until the next frame at 479.75, and tick 7 is the last tick before it is replaced; sent 200 µs late (landing at 478.95) it is still taken at 479.7 and the move still ends at 633.7 ms. Ten windows: windows 1 to 8 give latch 1 to 8, the point meant for SYNC0 479 is taken 0.1 ms later per window, and the command ends at 633.1 to 633.8; windows 0 and 9 both give latch 0, taken at 479.0, ending at 633.0; window 9 is the one exception, taken 0.05 ms after it lands. One frame 100 µs early (478.65, window 6): tick 7 at 478.7 already takes 129,761, so 128,451 is never taken; SYNC0 479 drops the latch to 6 and 479.6 takes 129,761 again; the velocity command swings from −225 to 1,583 rpm, the motor from 600 to 443–955, the gap between command and motor jumps from 6 to 1,305 counts; the latch stays 6 and the move ends 0.1 ms sooner. Without SYNC0 (SM-synchronous): OP at 25 ms, the lock after 50 frames at 68.8 ms, latch 0, the point taken on the first tick after the frame (0.05 ms), but only SYNC0 restarts the timer, so the ticks run on the drive's own clock; the code's TODO says a shared shift time, 0x1C33:03, would line axes up, and it isn't written. Not covered: a frame later than SYNC0 (on the bench, one takes the drive out of OP), the crystal running fast or slow, and the master going quiet → 31c. Your turn: send every frame 50 µs before SYNC0: window 9, latch 0, a wait of 0.05 ms, the command ends at 633.0.

Up next31c · EtherCAT 3: one frame missing→