1. They can be in lock step, at the same frequency and in phase.
  2. They can be at the same frequency but out of phase.
  3. They can be at different frequencies.

For low frequencies the ECP5 may be able to use the RPI Zero's pixel clock. The pixel clock would drive the ECP5's PLL, which compensates for the delay introduced by the clock tree, aligning the ECP5's clock phase with the RPi's pixel clock. In reality, it may not be able to generate a PLL lock, but it is such a simple and low resource solution, that it is worth trying.

Option 2, same frequency but different phase is not possible, details in the sub section.

Option 3 is the traditional solution, it will work at higher frequencies, but it does consume some of the scarce resources on the 20K LUT ECP5 embedded in the ICEPi Zero. The basic idea is to run the two chips at different frequencies, but use Clock Domain Crossing FIFO queues to transmit data between the two chips. The FPGA then has to generate its own Vsync, HSync and blank signals. Such counters do not take up much space.

Shared Pixel Clock   View      

The ECPi PLL uses the RPI's pixel clock as a source, and generates both the FPGA's pixel clock and the FPGA's TMDS/DVI/HDMI clock phase aligned with the input, and compensated for the FPGA's clock distribution network.

Why does dividing increase the frequency??? For anyone who is not so good at digital electronics, the dividers are just counters. Count to 5 or 25 and change the output. The magic is all in how the analog PLL does the multiplication. It has to boost the output frequency and shift its phase until the divided and delayed feedback signal matches the input signal.

Pixel    ÷ 216
Clock    MHz    Standard modes
-------  -----  ---------------------------------------------------
 27 MHz    8    CEA 720×480p @ 59.94, 720×576p @ 50 (VIC 2/3, 17/18)
 36 MHz    6    VESA 800×600 @ 56, 640×480 @ 85
 54 MHz    4    CEA 1440×480p @ 59.94, 1440×576p @ 50 (VIC 14/15, 29/30)
                CEA 720×480p @ 119.88, 720×576p @ 100 (VIC 48/49, 42/43)
 72 MHz    3    VESA 1366×768 @ 60
108 MHz    2    VESA 1280×1024 @ 60, 1280×960 @ 60, 1600×900 @ 60,
                     1152×864 @ 75
                CEA 2880×480p @ 59.94, 2880×576p @ 50 (VIC 35/36, 37/38)

Same Frequency From a Shared Clock   View      

Generating the same frequency from a shared clock is not possible.

Instead of using a shared Pixel clock, one could transmit a proper clock signal to the FPGA. On some FPGA's, the FPGA might then generate the same frequency using the same multiplies and divides. The two same frequency clocks would be out of phase, but the delayed VSync and HSync signals could be used. The resulting Pixel clock frequency should then be as close as possible to the number specified by the VESA display standards.

When using a shared system clock, there are two relevant clocks: the oscillator and the pixel clock. The RPI0 19.2 Mhz oscillator can be published on general purpose clock ports such as pins 4, 5 and 6. For DPI signals, pin 4 is the obvious choice. It is the Least Significant Bit (LSB) for red or blue DPI colors. Ideally, it should be input into the dedicated FPGA clock input ports from which it is fed directly to the PLL. It can also be routed through the FPGA fabric, but the quality degrades. Since the IcePi Zero does not hardwire the RPI0 oscillator output port directly to the FPGA PLL input port, we would be sending the signal through the fabric.

It is possible to transmit the Raspberry Pi's 19.2 Mhz clock, and some low frequency custom clocks, but it is not
possible to use intermediate clocks. The RPI0's Pixel clock is generated off of a 216 Mhz PLLh_aux or off of a fractionally divided 500Mhz PLL_per clock, both of which are too high frequency to be transmitted between the chips. One option would be to use the DPI pixel clock, discussed in option 1 above, but then the FPGA is not generating the same frequency, it is just duplicating the same frequency. A related option is to use the pllh_aux divided by a number, that is basically the just the same frequency as the pixel clock, but probably a different phase.

So it is possible to share the oscillator, but it is not possible to then generate the same frequencies from the PLLs. PLLs work by first multiplying the frequency and then dividing it. The problem is that the RPI PLL reaches much higher freuencies. The RPI0 PLL works by first multiplying the oscillator frequency up to many GigaHz, and then dividing it. It can be divided 3 times. The ECP5 FPGA PLL is more limited than the RPI PLL. The Lattice FPGA PLL documentations says that it also multiplies the oscillator frequency by a number but only by integers from 1 to 128. The resulting signal should not exceed 800 Mhz. That signal is then divided by a number between 1 and 128. To keep the two pixel clocks synchronised, we need to use the same multiply and divide frequencies. But the RPI OS and GPU set most of the multiply and divide numbers.

One other problem is that the FPGA has integer clock dividers, and the RPI Zero has fractional clock dividers. So for many display sizes the RPi Zero uses fractional dividers which work by shifting between frequencies, which generates jitter.

Clock oddness

Another problem is that the RPI Zero's GPU is not well documented. The code driving it is closed source. One can poke at it, and generate some frequencies, but other options may be possible.

One last problem is that we only have 28 signal pins between the two chips, and so one bit would have to be dropped from the DPI signal to accomodate the RPi Oscillator signal.

We also have to configure the pins. The newest release of Raspberry Pi Linux has a DPI 24 bit overlay.

Name:   dpi24
Info:   Overlay for a generic 24-bit DPI display
        This uses GPIOs 0-27 (so no I2C, uart etc.), and activates the output
        2-3 seconds after the kernel has started.
Load:   dtoverlay=dpi24
Params: <None>

Here is the dpi white paper.

Here is the DPI24 overlay code. We can edit it to delete one. of the pins.

Here are the detailed technical documents for pin assignments

The system clock can be on pins 4, 5, or 6. The dpi can be RGB888, or BGR888. Meaning pin 4 can be Red LSB, or Blue LSB, but not Green LSB. Which is good because humans are more sensitive to green.

The RPI clock is 19.2Mhz.

This tool shows us that if we multiply by 21 and divide by 16, we get a frequency of 25.2 Mhz. Quite close to 25.175 Mhz. It is quite confusing because they call them frequency dividers, they are dividing each square wave into multiple square waves, but they actually increase the frequency.

The good news is that we can set the RPI display frequency (page 5) to be a legal FPGA frequency, and it should generate the correct multiplies and divides. We can then query what the frequency is. Of course elsewhere the internet says that you cannot actually reliably control the RPi GPU pixel clock frequency.

Bottom Line

I really need to probe the RPi Zero to see what frequencies it actually generates and how much jitter there is in the signal. Advanced oscilliscopes can plut a histogram of pulse widths, which will show if the RPi GPU is really switching between frequencies.

Notes

The ULX3S ECP5 VHDL DVI RTL also provides some hacks if the default PLL values do not work. I wonder why those hacks work.

Details about the clock frequencies. https://elinux.org/RPiconfig#Clocks_relationship


Clock Domain Crossing   View      

The most reliable communication between the Raspberry Pi Zero and the ECP5 would be using Clock Domain Crossing FIFO circuitry. But it also takes the most resources.

The basic idea is that the RPI Zero writes data to a FIFO queue on the FPGA using its pixel clock, and the FPGA reads from it. They both use the same dual port block RAMs, but with different clock drivers. Gray coding is used to transmit the most recent write address between the two clock domains. Multiple open source libraries exist for this purpose. The FPGA then needs to calculate its own HSync, VSync, and Blank signals.


Clock Reference Materials   View      

Links to various documents which were helpful in this project.

This page describes the different standard HDMI screen sizes, the pixel format and the required pixel clock frequencies.

A 640 * 480 HDMI has a pixel clock of 25.175 Mhz. Look at the Discrete Monitor Timings (DMT) column.

If you are not sure what are the legal pixel clocks, here is the video timing calculator.

ECP5 FPGA Clock Generation



Built with the Forest WIki.
User contributed content is licensed under a Creative Commons CC By 4.0 License.