FPGA PLL.

In the previous article about FPGAs we wrote a program that blinked LEDs, but learning FPGAs just to blink LEDs is an unjustified waste of time. In real life FPGAs are used either to capture and process data at high speeds, for example to read data from an ADC running at hundreds of megahertz, or where non-standard peripherals are needed, for example a dozen SPI modules. And while the second option can somehow be implemented on an MCU, reading data at high speed with an MCU is unrealistic.

To capture data at high speeds, the FPGA itself must run at a frequency several times higher than the sampling rate, and for this purpose FPGAs, like MCUs, have a PLL module. Configuring it is what we'll do in this article.

First, we open the datasheet and see what maximum frequency we can get at the PLL output.
FPGA PLL.

FPGA PLL.


We create a project in Quartus. The IP Catalog should be on the right side of the program window; if it isn't there, find IP Catalog in the Tools tab, click it, and select ALTPLL in it.
FPGA PLL.

A window will open where you need to specify the file name and the language in which it should be generated.
FPGA PLL.

Next, the PLL settings window opens, where you need to specify the frequency fed to its input; the other settings are optional.
FPGA PLL.

In the next window you can choose whether we need: a PLL reset signal, a PLL enable signal, and a signal indicating that the PLL has locked.
FPGA PLL.

I'll skip the next few steps, as I didn't change anything in them. I'll go straight to configuring the PLL output. In this window you can either set the coefficients manually or specify the desired frequency, and the wizard will calculate the coefficients itself.
FPGA PLL.

I'd like to note that the PLL in this FPGA can have up to 5 outputs, each of which can be configured to the required frequency. I'll leave a picture here for better understanding.
FPGA PLL.

But it should be noted that there is a limitation: the PLL can only output related frequencies, i.e. ones that differ by an integer factor. For example, if you specify 350MHz when configuring output C1, the wizard will say that it cannot be obtained.
FPGA PLL.

In the last window you can select the file types that the wizard generates when the configuration is complete. The two selected by default are enough for us.
FPGA PLL.


As a result, the wizard should create a pll.v file containing a module of the same name with two parameters, the input and output signals.
FPGA PLL.


Let's write code that toggles the pin state on each rising edge. Since the PLL in our project runs at 400MHz and we toggle the pin only on the rising edge, we should actually see a 200MHz signal on the oscilloscope screen.

module pll_project(input clk_50MHz, output reg pll_out);

wire wc0;

pll pll1(.inclk0( clk_50MHz ), .c0( wc0 ));

always@(posedge wc0)
begin 
	pll_out <= pll_out^1'b1;//toggle the pin state
end

endmodule

Let's assign pins to the signals, keeping in mind what we learned in the previous article: the FPGA has pins dedicated to bringing the PLL signal out.
FPGA PLL.

The picture on the oscilloscope screen shows that we did everything correctly, but I think some may be confused by the signal amplitude. There is no need to worry, because the oscilloscope bandwidth is only 100MHz, while the signal frequency is 200MHz.
FPGA PLL.