FPGA tutorial Step 4: Using a clocking wizard
The following example shows a vhdl-file and a block design for a demo using a clock. The logic counts up a counter every time the clock rises. The basys 3 runs with a 100Mhz clock natively.
A simple example without clocking wizard
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.numeric_std.all; entity Blinker is Port ( clk : in STD_LOGIC; sw : in STD_LOGIC_VECTOR (15 downto 0); led : out STD_LOGIC_VECTOR (15 downto 0)); end Blinker; architecture Behavioral of Blinker is begin process(clk) is variable X : integer range 0 to 100000000; begin if rising_edge(clk) then -- Set led light led <= std_logic_vector(to_unsigned(X / 16384, 16)); -- Count X := X + 1; if X = 100000000 then X := 0; end if; end if; end process; end Behavioral;
The result is the leds on the basys blinking slower and slower the more to the left they are placed.
IMPORTANT: Remember to specify 100mhz when you create the clk port.
Adding a clocking wizard
After talking to my ultimate FPGA mentor, Jes, I learned, that the clock signal is a very special signal and in order to have vivado to not complain about unconstrained clock signals, you should add a clocking wizard to all projects where you intend to use a clock (which is far the majority of cases). Adding a clocking wizard also enables you to adjust the frequency of the clock and have multiple output clocks with different frequencies.
Go to you block design view, right click and choose "Add IP ...":
Search for "clock" and double click the "Clocking Wizard":
After addin the IP, the design viewer looks like this:
We can adjust the clocking wizard to our needs by double clicking the Clocking Wizard box. The following screen will open:
Under "Clock Options" we can verify that the clocking wizard IP has been configured correctly to expect a 100mhz clock input which is correct when using a basys 3 board:
Now, switch to the "Output clock options". For this demo we will setup a 100mhz and a 20mhz output clock in the wizard. This leaves the configuration like this: (Note that I renamed the output to be more descriptive):
Hit the "OK" button and you will end up with this view:
Now connect the input clk port to the wizard instead of directly to the blinker module. and then connect the output clock to the blinker module. It is up to you to choose between 100mhz and 20mhz as both are now available from the clocking wizard. There is no limit on how many modules can be connected directly to the clocking wizard, so know yourself out!
I have hooked up the blinker to the 20mhz and after deploying the code, the led light blink 5 times slower than before (20mhz vs 100mhz before). The final result: