![Altera Cyclone V Device Handbook Download Page 864](http://html1.mh-extra.com/html/altera/cyclone-v/cyclone-v_device-handbook_2910791864.webp)
Hence, if the reference clock (clk_ptp_ref_i) is, for example, 66 MHz, this ratio is calculated as 66 MHz / 50
MHz = 1.32. Hence, the default addend value to be set in the register is 232 / 1.32, 0xC1F07C1F.
If the reference clock drifts lower, to 65 MHz for example, the ratio is 65 / 50, or 1.3 and the value to set in
the addend register is 232 / 1.30, or 0xC4EC4EC4. If the clock drifts higher, to 67 MHz for example, the
addend register must be set to 0xBF0B7672. When the clock drift is nil, the default addend value of
0xC1F07C1F (232 / 1.32) must be programmed.
†
In the above figure, the constant value used to accumulate the sub-second register is decimal 43, which
achieves an accuracy of 20 ns in the system time (in other words, it is incremented in 20-ns steps).
The software must calculate the drift in frequency based on the Sync messages and update the Addend
register accordingly.
†
Initially, the slave clock is set with FreqCompensationValue0 in the Addend register. This value is as follows:
†
FreqCompensationValue
0
= 232 / FreqDivisionRatio
†
If MasterToSlaveDelay is initially assumed to be the same for consecutive sync messages, the algorithm
described below must be applied. After a few sync cycles, frequency lock occurs. The slave clock can then
determine a precise MasterToSlaveDelay value and re-synchronize with the master using the new value.
†
The algorithm is as follows:
†
• At time MasterSyncTime
n
the master sends the slave clock a sync message. The slave receives this message
when its local clock is SlaveClockTime
n
and computes MasterClockTime
n
as:
†
MasterClockTime
n
= MasterSyncTime
n
+
MasterToSlaveDelay
n
†
• The master clock count for current sync cycle, MasterClockCount
n
is given by:
†
MasterClockCount
n
= MasterClockTime
n
–
MasterClockTime
n-1
(assuming that MasterToSlaveDelay is the same
for
sync cycles n and n – 1)
†
• The slave clock count for current sync cycle, SlaveClockCount
n
is given by:
†
SlaveClockCount
n
= SlaveClockTime
n
–
SlaveClockTime
n-1
†
• The difference between master and slave clock counts for current sync cycle, ClockDiffCount
n
is given
by:
†
ClockDiffCount
n
= MasterClockCount
n
–
SlaveClockCount
n
†
Altera Corporation
Ethernet Media Access Controller
17-15
System Time Register Module
cv_54017
2013.12.30