Author Topic: Phase sync two same frequency input's ?  (Read 3813 times)

0 Members and 1 Guest are viewing this topic.

Offline sunilshaTopic starter

  • Newbie
  • Posts: 1
  • Country: in
Phase sync two same frequency input's ?
« on: December 13, 2023, 04:44:59 pm »
I am trying to implement a phase correction verilog module for two clock inputs coming into my cycloneiv fpga.

My module has
Two clock signals, clock_1 and clock_2 with frequency 8Khz from different clock sources that are input to the fpga pins, and a ref_clk 25Mhz to sample the signals. I have an output of the module phase_sycned_out.

Requirement:
I need to come up with a verilog logic which preserve's the phase information of clock_1 and then uses the standalone clock_2 to delay clock_2 by the necessary cycles so as to match the clock_1's phase. This delayed clock_2 is to can be further output on phase_synced_out of the fpga. This is the 1st step of my problem.

Regards
-sunilsha
 

Offline Rainwater

  • Contributor
  • Posts: 36
  • Country: us
Re: Phase sync two same frequency input's ?
« Reply #1 on: February 20, 2024, 11:45:07 am »
Would measuring phase difference between two digital inputs of he same frequency would be as simple as measuring the time between rising edges or am I missing something?
"You can't do that" - challenge accepted
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2803
  • Country: nz
Re: Phase sync two same frequency input's ?
« Reply #2 on: February 20, 2024, 11:02:13 pm »
The easiest way I could see is a 4096 x 1 bit memory - that allows for up to 163us of delay.

A free-running write counter in the 25MHz domain is used to write the reference signal to the memory.

An offset behind the write counter is used to read the memory, and send to the output.

You have a phase comparator comparing the input and output, and use that to adjust the offset

Code: [Select]
   on a clock_25MHz
        ram[wr_addr] <= ref_input;
        ref_output <= ref_input;
        tracking_output <= ram[wr_addr - delay/64];
        # Rising edge of ref clock
        if ref_output = '0' and ref_input = '1' then
            if tracking_output = 1 then
               #we are leading, so increase the delay
               delay++;
            if tracking_output = '0' then
               #we are lagging, so decrease the delay
               delay--;
      wr_addr++;

Note that such a thing will only work if both of the slow clocks come from the same reference - if not, eventually you will need to skip / insert an extra cycle to keep synced.

You could code it a lot more subtilly than this, but as a 0th approximation it should be workable.
« Last Edit: February 20, 2024, 11:05:28 pm by hamster_nz »
Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf