Is there circuit to make two square waveforms of different frequency be in sync with each other at all times as shown and not drift over time?
In the general case, it's called frequency synthesis.
You make a second frequency as a rational fraction of the first.
In your particular case, if you take the blue waveform as Fin, you could create the green waveform by clocking a divide-by-2 latch on the falling edge of Fin. If you wanted to use the green waveform as Fin, you might use a frequency doubler by closing a Phase Locked Loop around a divide-by-2 circuit, or you could double the frequency directly with logic or RF components.
The subject is vast, and this answer barely scratches the surface. There's a lot of technology (aka knowhow) about the hardware used to make multipliers and dividers, their noise performance, the permissible sizes of num and den and whether they can adjusted in real time. Most FPGAs now contain several dedicated frequency synthesis blocks to manipulate their clock signals, and you can buy complete Direct Digital Synthesis ICs for a few dollars from several manufacturers.
Yes, you can. What you want is called phase locking. You need to make the two frequencies based on the same source, otherwise you will never completely get rid of some drift even with the best frequency sources.
There are different ways to get what you want. In your case where one frequency is an integer multiple of the other one, it's as simple as feeding one frequency into a frequency divider circuit (can be some flip-flops or counters) to get the second frequency.
If the frequencies are a rationale number apart you have several possibilities again:
- You can take a higher frequency as your source (in lab equipment you have a 10MHz input somewhere for exactly that) and feed two frequency divider circuits to generate your desired frequencies.
- You can use a PLL (phase locked loop) that you feed one frequency and set the multiplier and divider so that you get your desired other frequency.
- You can take a common source frequency and use two PLLs to create your desired frequencies. Since you're using a common source, the phases of your two frequencies will be locked automatically.