So I have a simple 2 bit counter that moves from one state to the next on a button press. However, the only clock I have access to runs at 125MHz, which is too fast for the button press, so I need to divide the clock down to a more reasonable speed. I've seen a few examples of clock dividers on this site, however what I can't figure out is:
- How do I add the clock divider to existing VHDL code, do I just add the divided clock as a new output or input port? and how do I set it up so the state change will only occur following the divided clock?
In the constraint file, how do I include the divided clock? I think I use generated clock as part of the statement, but does it have to be assigned to its own seperate pin? Right now I have the main clock assigned as:
set_property PACKAGE_PIN L16 [get_ports clk]
set_property IOSTANDARD LVCMOS33 [get_ports clk]
create_clock -period 10.000 -name clk -waveform {0.000 5.000} [get_ports clk]
Here is the VHDL code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity des_src is
Port ( clk : in STD_LOGIC;
BTN_0 : in STD_LOGIC;
LED_1 : out STD_LOGIC;
LED_0 : out STD_LOGIC);
end des_src;
architecture Behavioral of des_src is
TYPE statetype IS (Start, One, Two, Three);
SIGNAL currentstate, nextstate : statetype;
begin
fsm1: PROCESS (currentstate, BTN_0)
BEGIN
CASE currentstate IS
WHEN Start =>
LED_1 <= '0';
LED_0 <= '0';
CASE BTN_0 IS
WHEN '1' =>
nextstate <= One;
WHEN OTHERS =>
nextstate <= Start;
END CASE;
WHEN One =>
LED_1 <= '0';
LED_0 <= '1';
CASE BTN_0 IS
WHEN '1' =>
nextstate <= Two;
WHEN OTHERS =>
nextstate <= One;
END CASE;
WHEN Two =>
LED_1 <= '1';
LED_0 <= '0';
CASE BTN_0 IS
WHEN '1' =>
nextstate <= Three;
WHEN OTHERS =>
nextstate <= Two;
END CASE;
WHEN Three =>
LED_1 <= '1';
LED_0 <= '1';
CASE BTN_0 IS
WHEN '1' =>
nextstate <= Start;
WHEN OTHERS =>
nextstate <= Three;
END CASE;
END CASE;
END PROCESS;
fsm2: PROCESS (clk)
BEGIN
IF (clk'EVENT) AND (clk = '1') THEN
currentstate <= nextstate;
END IF;
END PROCESS;
end Behavioral;
I'm programming for the ZYBO using Vivado 2015.2 Any and All help is appreciated, Thanks!