PS Clock Control

This notebook demonstrates how to use Clocks class to control the PL clocks.

By default, there are at most 4 PL clocks enabled in the system. They all can be reprogrammed to valid clock rates.

Whenever the overlay is downloaded, the required clocks will also be configured.

References:

https://www.xilinx.com/support/documentation/user_guides/ug585-Zynq-7000-TRM.pdf

Show All Clocks

The following example show all the current clock rates on the board.


In [1]:
from pynq import Clocks
from pynq import PL, Overlay

print(f'CPU:   {Clocks.cpu_mhz:.6f}MHz')
print(f'FCLK0: {Clocks.fclk0_mhz:.6f}MHz')
print(f'FCLK1: {Clocks.fclk1_mhz:.6f}MHz')
print(f'FCLK2: {Clocks.fclk2_mhz:.6f}MHz')
print(f'FCLK3: {Clocks.fclk3_mhz:.6f}MHz')


CPU:   650.000000MHz
FCLK0: 100.000000MHz
FCLK1: 142.857143MHz
FCLK2: 200.000000MHz
FCLK3: 100.000000MHz

Set Clock Rates

The easiest way is to set the attributes directly. Random clock rates are used in the following examples; the clock manager will set the clock rates with best effort.

If the desired frequency and the closest possible clock rate differs more than 1%, a warning will be raised.


In [2]:
Clocks.fclk0_mhz = 27.123456
Clocks.fclk1_mhz = 31.436546
Clocks.fclk2_mhz = 14.597643
Clocks.fclk3_mhz = 0.251954

print(f'CPU:   {Clocks.cpu_mhz:.6f}MHz')
print(f'FCLK0: {Clocks.fclk0_mhz:.6f}MHz')
print(f'FCLK1: {Clocks.fclk1_mhz:.6f}MHz')
print(f'FCLK2: {Clocks.fclk2_mhz:.6f}MHz')
print(f'FCLK3: {Clocks.fclk3_mhz:.6f}MHz')


CPU:   650.000000MHz
FCLK0: 27.027027MHz
FCLK1: 31.250000MHz
FCLK2: 14.492754MHz
FCLK3: 0.251953MHz

Reset Clock Rates

Recover the original clock rates. This can be done by simply reloading the overlay (overlay will be downloaded automatically after instantiation).


In [3]:
_ = Overlay(PL.bitfile_name)

print(f'FCLK0: {Clocks.fclk0_mhz:.6f}MHz')
print(f'FCLK1: {Clocks.fclk1_mhz:.6f}MHz')
print(f'FCLK2: {Clocks.fclk2_mhz:.6f}MHz')
print(f'FCLK3: {Clocks.fclk3_mhz:.6f}MHz')


FCLK0: 100.000000MHz
FCLK1: 142.857143MHz
FCLK2: 200.000000MHz
FCLK3: 100.000000MHz