OpenEtherCATsociety / SOEM

Simple Open Source EtherCAT Master
Other
1.36k stars 688 forks source link

What does DCTime correspond to #45

Closed jespersmith closed 8 years ago

jespersmith commented 8 years ago

I'm trying to wrap my head around DC clocks and I was wondering what the context->DCtime variable corresponds to. From testing it seems to get changed when ecx_receive_processdata is called, but it seems to correspond to the execution of the ecx_send_processdata call.

The question is, what is the corresponding time on the PC?

A) Moment the datagram gets send by ecx_send_processdata call (aka master clock compensated by transmission delays). B) Moment the datagram reaches the master clock (aka no compensation for transmission delay) C) something else

The goal is to synchronize the DC Sync0 pulse to to SYNC moment in the following psuedocode

while(true)
{
       wait for next period
       SYNC
       ecx_send_processdata
       ecx_processdata_receive
       do control, non-deterministic execution time < cycle time

}
ghost commented 8 years ago

DCtime variable is populated by the reference clock (typically EcSlave #1), so when EcMaster (SOEM) receives the PDO message its value changed, unless you configure the EcMaster to be the reference clock (or if DC isn't used).

Edit: so really, DCtime can be different than the PC's (EcMaster's) time, if the EtherCAT Reference Clock is not synchronised with the PC.

jespersmith commented 8 years ago

So the master creates and sends a datagram to slave 1, which (if it's the DC ref clock) will populate the field with its time.

So for pretty decent synchronization I can assume that the moment I call ecx_processdata_send is a few microseconds before the value of DCTime. I probably want to call send about 50-100us after the DC sync pulse to know that I have the data from the last pulse.