Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frequency correction of timestamp events #6

Closed
pyuxiang opened this issue Feb 7, 2024 · 5 comments
Closed

Frequency correction of timestamp events #6

pyuxiang opened this issue Feb 7, 2024 · 5 comments

Comments

@pyuxiang
Copy link
Collaborator

pyuxiang commented Feb 7, 2024

Issue by franciumxzf
Monday Jan 30, 2023 at 09:29 GMT
Originally opened as franciumxzf/fpfind#6


  1. frequency correction done on rawevents instead of epochs
  2. pfind will find the frequency differency: if it is large, will perform the frequency correction on rawevents before chopper
  3. store the frequency difference in the units of 1e-12
  4. how to apply the frequency correction in integer multiplication
@pyuxiang
Copy link
Collaborator Author

pyuxiang commented Feb 7, 2024

Comment by pyuxiang
Wednesday Feb 01, 2023 at 14:28 GMT
Originally commented as franciumxzf/fpfind#6 (comment)


The equation to compute for each timestamp $t_i$ is,

$$ (t_i - T_{\text{start}}) ( 1 + \Delta{}f) + T_{\text{start}} = t_i + (t_i - T_{\text{start}}) \Delta{}f $$

Some observations first:

  1. The pfind algorithm is currently hardcoded to terminate when the frequency offset correction is < 1e-10 (or 2^-34)
  2. Frequency differences larger than 250ppm cannot be used as an input to the PLL in the clock chip (or 2^-12)
    • The range of accepted frequency offsets thus encompasses only 22 bits (excl. 1 sign bit)
  3. The timestamp is 54-bits wide in units of 4ps, and thus cycles every 20 hours

To avoid expensive multiplication with a floating point, we express $\Delta{}f$ as a signed integer.

Assume we use units of 1e-12 (or 2^-40) for the $\Delta{}f$, and consider two different offsets, (1) 2^-40 (or 1-bit) and (2) 2^-12 (or 28 bits). We enumerate the two cases,

  1. Only the 54 - 40 = 14 MSb timestamp will have a direct impact on the timing correction
  2. The required resolution is 54 - 12 = 42 MSb timestamp.

The minimum required timing correction is thus at most on the order of 28 + 42 = 70 bits (excl. sign bit).
A naive implementation suggests we simply use a 128-bit integer to hold the multiplication result of $(t_i - T_{\text{start}}) \Delta{}f$, before the 40-bit right-shift.

@pyuxiang
Copy link
Collaborator Author

pyuxiang commented Feb 7, 2024

Comment by pyuxiang
Wednesday Feb 01, 2023 at 14:37 GMT
Originally commented as franciumxzf/fpfind#6 (comment)


In considering a possible optimization, maybe easier if we think of it in base-10?
Suppose the timestamp is 987656789 and the offset is 989 in units of 1e-6.

A full multiplication yields 976792.564321, with the unnecessary fractional part.
A representative multiplication is 9876567 * 989 * 1e-4 = 976792.4763, since the remainder (89 * 989 / 1e6) < 10^6 / 1e6 = 1 is entirely fractional.

In other words, the larger the multiplied value, the smaller the irrelevant part. In the worst case scenario with a 2^-12 (or 28-bit) offset in units of 2^-40, only 40-28-1=11 bits of the timestamp can be cut out, i.e. the maximum size of the resulting multiplication that must be performed is actually 28 + (54 - 11) = 71 bits (again excluding a sign bit), which has the following algorithm:

$$ \left( \left[ (t_i - T_{\text{start}}) \gg 11 \right] \times \Delta{}f \right) \gg (40-11) $$

This size can be reformulated as (40-12) + (54 - (40-(40-12)-1)) = (40-12) + (54 - 12 + 1) = 55 + 40 - 2*12 = 31 + 40 = 71 bits.

@pyuxiang
Copy link
Collaborator Author

pyuxiang commented Feb 7, 2024

Comment by pyuxiang
Wednesday Feb 01, 2023 at 14:46 GMT
Originally commented as franciumxzf/fpfind#6 (comment)


To fit everything into a 64-bit signed multiplication result is then clear: if the maximum frequency difference is 2^-12, then the finest frequency offset resolution we can accept is 32 bits.

Alternatively, we can have a maximum $\Delta{}f$ of 2^-13 = 122 ppm, and still support a frequency resolution of 34 bits = 0.6e-10. In this scheme, we finally have

$$ \left( \left[ (t_i - T_{\text{start}}) \gg 12 \right] \times \Delta{}f \right) \gg 22 $$

where $\Delta{}f$ is in units of 2^-34. Whew!

@pyuxiang
Copy link
Collaborator Author

pyuxiang commented Feb 7, 2024

Comment by pyuxiang
Wednesday Feb 01, 2023 at 14:50 GMT
Originally commented as franciumxzf/fpfind#6 (comment)


One small note, due to the overflow of the timestamp after every 20 hours, the timestamp correction will become erroneous within 20 hours. We might need to consider a fix to this as well.

@pyuxiang
Copy link
Collaborator Author

pyuxiang commented Feb 7, 2024

Comment by pyuxiang
Friday Feb 03, 2023 at 00:45 GMT
Originally commented as franciumxzf/fpfind#6 (comment)


Closed with commit franciumxzf/fpfind@82b84bd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant