Igh Ethercat 从机做为DC参考时钟的个人理解

/** Queues the DC reference clock drift compensation datagram for sending.
 *
 * The reference clock will by synchronized to the application time provided
 * by the last call off ecrt_master_application_time().
 */
void ecrt_master_sync_reference_clock(
        ec_master_t *master /**< EtherCAT master. */
        );

ecrt_master_sync_reference_clock这个函数将最近一次从ecrt_master_application_time传入的时间戳发送给参考时钟。

这就是官方example中除了rtai_rtdm_dc这个例子使用的默认dc同步方式,即所谓的以主站作为参考时钟的方式。

 

/** Queues the DC clock drift compensation datagram for sending.
 *
 * All slave clocks synchronized to the reference clock.
 */
void ecrt_master_sync_slave_clocks(
        ec_master_t *master /**< EtherCAT master. */
        );

这个函数其实发送了一个EtherCAT FRMW原语包

可以追溯到master/master.c的2106行

ec_datagram_frmw(&master->sync_datagram, ref ? ref->station_address : 0xffff, 0x0910, 4);

FRMW 即配置的地址物理读/多写  (Configured Read Mutiple Write)

ECT_REG_DCSYSTIME 0x0910  (DC系统时钟,只读,64位)  获取此帧到达时,SystemTime系统时间的值.

明明是只读寄存器却可写?反正我是没懂这用法。

总之这个函数的作用是将参考时钟发送给所有从站,以实现dc时钟同步。

 

要想实现以从站作为参考时钟,只需要调用ecrt_master_sync_slave_clocks就可以实现,但是因为PC主站时钟与从站参考时钟有区别,会出现主站时钟与参考时钟慢慢偏离的情况。

一种解决办法是调用ecrt_master_sync_reference_clock将主站时钟同步到参考时钟,这就是官方例子采用的,优点是实现简单,缺点是dc时钟会受主站的实时性的影响。

另一种就是根据从站参考时钟来动态调整主站时钟,可以参考rtai_rtdm_dc这个例子,但是我觉得这个例子写的太复杂,所以在之前的文章里写了我自己的办法。

 

  • 0
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值